// ONLY ON-DOM-LOAD code (pouzit defer atribut pro IE)
// 2009-06-24 LS MOD - obsah domready z matesione (k domready vubec nedoslo) presunut do initOnDomLoaded()
/*
// Home Search BOX // 
function hp_search_refresh(new_action_button, post) {
            var button_id = "hp_" + new_action_button + "_search";
            var content = CMN.gE('forms');            
            ajax({          
                  url: "ajax.php",
                  type: "html",
                  method: "POST",
                  data: "action=get_hp_" + post + "_form",
                  onSuccess: function(html){
                    content.innerHTML = html;
                    CMN.gE(button_id).onclick = function() {
                      if(post == "advanced"){
                        hp_search_refresh("advanced", "basic");
                      } else {
                        hp_search_refresh("basic", "advanced");                       
                      }
                      return false;                      
                    };
                  }
            });
} 

*/

function initOnDomLoaded() { // 2.0 LS
// domready z matesione.js
    var targetblanks=className("targetblank");for(var i=0;i<targetblanks.length;i++){targetblanks[i].onclick=function(){if(typeof(window.open(this.href))=="object")return false;}}
    var default_border="1px solid #808080";var check_val=function()
    {var go_thru=true;var go_thru_mail=true;var go_thru_phone=true;var go_thru_zipcode=true;var go_thru_mail_or=true;var go_thru_phone_or=true;var inputs=this.getElementsByTagName("input");for(var z=0;z<inputs.length;z++)
    {var classRegular=new RegExp("(^|\\s)"+"check-is-blank"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border=default_border;if(inputs[z].value=="")
    {go_thru=false;inputs[z].style.border="1px solid red";}}
    var classRegular=new RegExp("(^|\\s)"+"check-is-checked"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border="none";if(inputs[z].checked!=true)
    {go_thru=false;inputs[z].style.border="1px solid red";}}
    var classRegular=new RegExp("(^|\\s)"+"check-is-mail"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border=default_border;if(!(isMail(inputs[z].value)))
    {go_thru_mail=false;inputs[z].style.border="1px solid red";}}
    var classRegular=new RegExp("(^|\\s)"+"check-is-phone"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border=default_border;if(!(isPhone(inputs[z].value)))
    {go_thru_phone=false;inputs[z].style.border="1px solid red";}}
    var classRegular=new RegExp("(^|\\s)"+"try-is-mail-or"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border=default_border;if(!(isMail(inputs[z].value)))
    {go_thru_mail_or=false;inputs[z].style.border="1px solid red";}
    for(var q=0;q<inputs.length;q++)
    {var classRegular=new RegExp("(^|\\s)"+"try-is-phone-or"+"(\\s|$)");if(classRegular.test(inputs[q].className))
    {inputs[q].style.border=default_border;if(!((go_thru_mail_or==true)&&(inputs[q].value=='')))
    {if(!(isPhone(inputs[q].value)))
    {go_thru_phone_or=false;inputs[q].style.border="1px solid red";}}
    if((go_thru_mail_or==false)&&(inputs[z].value==''))
    {if(!(isPhone(inputs[q].value)))
    {go_thru_phone_or=false;inputs[q].style.border="1px solid red";}
    else
    {inputs[z].style.border=default_border;go_thru_mail_or=true;}}}}}
    var classRegular=new RegExp("(^|\\s)"+"check-is-zipcode"+"(\\s|$)");if(classRegular.test(inputs[z].className))
    {inputs[z].style.border=default_border;if(!(isZipcode(inputs[z].value)))
    {go_thru_zipcode=false;inputs[z].style.border="1px solid red";}}}
    var select=this.getElementsByTagName("select");for(var z=0;z<select.length;z++)
    {var classRegular=new RegExp("(^|\\s)"+"check-is-selected-first"+"(\\s|$)");if(classRegular.test(select[z].className))
    {select[z].style.background="#ffffff";if(select[z].options[0].selected==true)
    {go_thru=false;select[z].style.background="red";}}}
    var textareas=this.getElementsByTagName("textarea");for(var z=0;z<textareas.length;z++)
    {var classRegular=new RegExp("(^|\\s)"+"check-is-blank"+"(\\s|$)");if(classRegular.test(textareas[z].className))
    {textareas[z].style.border=default_border;if(textareas[z].value=="")
    {go_thru=false;textareas[z].style.border="1px solid red";}}}
    var message="";if(go_thru_phone_or==false&&go_thru_mail_or==false)message+="Insert E-mail or Phone!! \n";else if(go_thru_phone_or==true&&go_thru_mail_or==false)message+="Insert E-mail in regular form!! \n";else if(go_thru_phone_or==false&&go_thru_mail_or==true)message+="Insert Phone in regular form!! \n";if(go_thru_mail==false)message+="Insert E-mail in regular form!! \n";if(go_thru_phone==false)message+="Insert Phone in regular form!! \n";if(go_thru_zipcode==false)message+="Insert ZIP code in regular form!! \n";if(go_thru==false)message+="Fields marked * are mandatory!! \n";if(message=="")
    {return true;}
    else
    {alert(message);return false;}};var forms=document.getElementsByTagName("form");for(var x=0;x<forms.length;x++)
    {var classRegular=new RegExp("(^|\\s)"+"form-validation"+"(\\s|$)");if(classRegular.test(forms[x].className))
    {forms[x].onsubmit=check_val;}}
// END matesione

// calendar -> input change //
  var tmp = CMN.gE('c_arrival_day');
  if(tmp && tmp.id){ // IE bug, najde 'c_arrival_day' i kdyz tam neni :))), proto kontrola na ID
    if (!day_chosen) {
    	monthDays('c_arrival_day');
	}
    CMN.gE('c_arrival_month').onchange = function() {
      monthDays('c_arrival_day', this.value);
    }; 
  }

//alert(CMN.gE('f_arrival_day').selectedIndex);
  if (!day_chosen && CMN.gE('f_arrival_day')) {
    monthDays('f_arrival_day');
    CMN.gE('f_arrival_month').onchange = function() {
      monthDays('f_arrival_day', this.value);
    }; 
  }

  if(CMN.gE('f_advanced_arrival_day')){
    monthDays('f_advanced_arrival_day'); 
    CMN.gE('f_advanced_arrival_month').onchange = function() {
      monthDays('f_advanced_arrival_day', this.value);
    }; 
  }
  
  // alert(CMN.gE('f_arrival_day2').value);
  if(!day_chosen && CMN.gE('f_arrival_day2')) {
      CMN.gE('f_arrival_day2').value = new Date().getUTCDate();
  }

// Root Search BOX //  
  if(CMN.gE('special_wishes_click')){
      CMN.gE('special_wishes_click').onclick = function() {
        show(CMN.gE('special_wishes'));
        hide(CMN.gE('special_wishes_click'));
        return false;
      };
  }
  if(CMN.gE('f_special_wishes')){
    CMN.gE('f_special_wishes').onclick = function() {
      if(CMN.gE('f_special_wishes').value == "Write us what you want and we find it. The more specific you will be the better offer we can find."){
        CMN.gE('f_special_wishes').value = "";
      }
    };
  }
  if(CMN.gE('f_special_wishes_name')){
    CMN.gE('f_special_wishes_name').onclick = function() {
      if(CMN.gE('f_special_wishes_name').value == "Name"){
        CMN.gE('f_special_wishes_name').value = "";
      }
    };
  }
  if(CMN.gE('f_special_wishes_phone')){
    CMN.gE('f_special_wishes_phone').onclick = function() {
      if(CMN.gE('f_special_wishes_phone').value == "Telephone"){
        CMN.gE('f_special_wishes_phone').value = "";
      }
    };
  }
  if(CMN.gE('f_special_wishes_email')){
    CMN.gE('f_special_wishes_email').onclick = function() {
      if(CMN.gE('f_special_wishes_email').value == "E-mail"){
        CMN.gE('f_special_wishes_email').value = "";
      }
    };
  }
  
  if(CMN.gE('advanced_search_click')){
    show(CMN.gE('advanced_search_click'));    
    CMN.gE('advanced_search_click').onclick = function() {
      if(hasClass(CMN.gE(this.id), "advanced")){
        hide(CMN.gE('advanced_search'));
        removeClass(CMN.gE(this.id), "advanced");
      } else {
        show(CMN.gE('advanced_search'));
        addClass(CMN.gE(this.id), "advanced");     
      }
      var temp = this.rel;
      this.rel = this.innerHTML;
      this.innerHTML = temp;
      return false;  
    };
  }

// Home Search BOX // 
  if(CMN.gE('hp_advanced_search')){
    CMN.gE('hp_advanced_search').onclick = function() {
      show(className("hp_advanced_search_box")[0]);
      hide(className("hp_basic_search_box")[0]);
      return false;        
    };
  }  
  if(CMN.gE('hp_basic_search')){
    CMN.gE('hp_basic_search').onclick = function() {
      hide(className("hp_advanced_search_box")[0]);
      show(className("hp_basic_search_box")[0]);
      return false;        
    };
  }

/*
  if(CMN.gE('hp_advanced_search')){
    CMN.gE('hp_advanced_search').onclick = function() {
      hp_search_refresh("basic", "advanced");
      return false;        
    };
  }   
*/


// Accommodation detail SWITCH (photos & overview)//   
  if(CMN.gE('accommodation_photos')){
    CMN.gE('accommodation_overview_click').onclick = function() {
      hide(CMN.gE('accommodation_overview'));
      hide(CMN.gE('accommodation_gallery'));
      show(CMN.gE('accommodation_photos'));
      return false;
    };
    CMN.gE('accommodation_photos_click').onclick = function() {
      hide(CMN.gE('accommodation_photos'));
      show(CMN.gE('accommodation_gallery'));      
      show(CMN.gE('accommodation_overview'));
      return false;
    };
  }
  if(CMN.gE('accommodation_gallery_click')){
      CMN.gE('accommodation_gallery_click').onclick = function() {
      hide(CMN.gE('accommodation_overview'));
      hide(CMN.gE('accommodation_gallery'));
      show(CMN.gE('accommodation_photos'));
      return false;
    };
  }
  tmp = CMN.gE('spec_submit');
  if(tmp && tmp.id){
    tmp.onclick = function() {
       var mysak = CMN.gE('frm-mysak');
       var formik = CMN.gE('frm-specwish');
       if(formik && mysak) {
           formik.c_arrival_month.value = mysak.f_arrival_month.value;
           formik.c_arrival_day.value = mysak.f_arrival_day.value;
           formik.c_nights.value = mysak.f_nights.value;
           formik.c_location_id.value = mysak.f_location_name.value;
       }
    }
  }
}

function isDomLoaded() {
	(/loaded|complete/.test(document.readyState) ? initOnDomLoaded() : setTimeout(arguments.callee, 10));
}
if(document.addEventListener) {
	document.addEventListener('DOMContentLoaded', initOnDomLoaded, false);// firefox, opera9.02
	if((window.opera && window.opera.version() < 9.02) || /WebKit|Khtml/i.test(navigator.userAgent)) { // opera<9.02, safari, konqueror
		isDomLoaded();
	}
} else { // ie5,6,7
	initOnDomLoaded();
}
