var d_i_m = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var w_d_n = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

function go(loc) 
{
   window.location.href = loc;
}

function closeWindow()
{
   self.close();
}

function printNow()
{
   if(window.print)
   {
      window.print();
   }
   else
   {
      alert("Please press the 'Print' button in your browser to print this page!");
   }
}

var formSubmitted = false;

function submitForm()
{
  if(formSubmitted)
  {
    alert ("Please wait until the system responds...");
    return false;
  }
  else
  {
    formSubmitted = true;
    return true;
  }
}



function processButtonClick(form_idx,button)
{
   var sbmt = document.forms[form_idx]._submit;
   sbmt.value = button;
   document.forms[form_idx].submit();
}



function processInputFocus(obj)
{
   obj.className = 'form_input_selected';
   processShowInfo(obj);
}


function processInputBlur(obj)
{
   obj.className = 'form_input';
   processShowInfo(null);
}


function processSelectFocus(obj)
{
   obj.className = 'form_select_selected';
   processShowInfo(obj);
}


function processSelectBlur(obj)
{
   obj.className = 'form_select';
   processShowInfo(null);
}


function processTextareaFocus(obj)
{
   obj.className = 'form_textarea_selected';
   processShowInfo(obj);
}


function processTextareaBlur(obj)
{
   obj.className = 'form_textarea';
   processShowInfo(null);
}


function processShowInfo(obj,override_idx)
{
   var el = document.getElementById('info_message_div');
   var idx = (obj == null) ? 'default' : obj.id;
   if(typeof override_idx != 'undefined') idx = override_idx;
   el.innerHTML = info_messages[idx];
}



function registerDirClick(id)
{
   var url = '/ajax/record_dir_click.ajax.php?id='+id;
   ajaxRequest(url, true);
}

function submitAvailabilityForm()
{
  var _e1 = document.getElementById('booking_from_day').value;
  var _e2 = document.getElementById('booking_from_month').value;
  var _e3 = document.getElementById('booking_from_year').value;
  var _e4 = document.getElementById('booking_to_day').value;
  var _e5 = document.getElementById('booking_to_month').value;
  var _e6 = document.getElementById('booking_to_year').value;
  if(_e1 == 0 || _e2 == 0 || _e3 == 0 || _e4 == 0 || _e5 == 0 || _e6 == 0)
  {
     alert("Please select a date range above by clicking on your preferred check-in date\nand your preferred check-out date in order to get a price for your holiday.");
     return false;
  }
  

  if(formSubmitted)
  {
    alert ("Please wait until the system responds...");
    return false;
  }
  else
  {
    formSubmitted = true;
    return true;
  }
}



function _P7_Snap() { //v2.67 by PVII
 var g,x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=_P7_Snap.arguments;a=parseInt(a);
 if(document.layers||window.opera){pa='';}for(k=0;k<(args.length);k+=4){
 if((g=MM_findObj(args[k]))!=null){if((el=MM_findObj(args[k+1]))!=null){
 a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 da="document.all['"+args[k]+"']";if(document.getElementById){
 d="document.getElementsByName('"+args[k]+"')[0]";if(!eval(d)){
 d="document.getElementById('"+args[k]+"')";if(!eval(d)){d=da;}}
 }else if(document.all){d=da;}if(document.all||document.getElementById){while(tx==1){
 p+=".offsetParent";if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 }else{tx=0;}}ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;}}}
}

function _GetXmlHttpObject()
{
   var xmlHttp;
   try
   {
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

var _c_ovr_str = '';
var cell_width = 26;
var cell_height = 25;
_bgcolor_AVA = [3,2]; 
_bgcolor_OVR = [1,7];  
function _ovr(obj_name)
{
	var obj = document.getElementById(obj_name);
	_c_ovr_str = obj.style.backgroundPosition;
	_setBackgroundPositionCSS(_bgcolor_OVR,obj);
}

function _out(obj_name)
{
	if(_c_ovr_str != '')
		document.getElementById(obj_name).style.backgroundPosition = _c_ovr_str;  
}

function _setBackgroundPositionCSS(point,obj)
{
	obj.style.backgroundPosition = (-cell_width*point[0])+'px '+(-cell_height*point[1])+'px';
}

var current_calendar = '';
function _openCalendar(type,from_objs_prefix,to_objs_prefix,callback_prefix)
{
   month_src = (type == 'checkin') ? from_objs_prefix+'month' : to_objs_prefix+'month';
   year_src = (type == 'checkin') ? from_objs_prefix+'year' : to_objs_prefix+'year';
   
	var month = document.getElementById(month_src).value;
	var year = document.getElementById(year_src).value;
	
	if(type == 'checkout')
	{
	   // check-in date selected
	   var checkin_month = document.getElementById(from_objs_prefix+'month').value;
	   var checkin_year = document.getElementById(from_objs_prefix+'year').value;
	   
	   // if check-in after check-out, may as well show further down the line
	   if((checkin_month > month && checkin_year == year) ||
	      (checkin_year > year))
	   {
	      month = checkin_month;
	      year = checkin_year;
		}
	}
	
	// Show calendar
	if(current_calendar != callback_prefix+'_'+type)
	{
	   _panCalendar(type,month,year,callback_prefix);
	   current_calendar = callback_prefix+'_'+type;
	}
	else
	{
      _closeCalendar();
      current_calendar = '';
	}
}

function _closeCalendar()
{
	var calendar_obj = document.getElementById('calendar_div');  
	calendar_obj.style.display = 'none';	
	current_calendar = '';
}

function _panCalendar(type,month,year,callback_prefix)
{
	// Show calendar
	var url = '/ajax/get_calendar.ajax.php?month='+month+'&year='+year+'&type='+type+'&callback_prefix='+callback_prefix;
	xmlHttp=_GetXmlHttpObject();
	if (xmlHttp!=null)
	{
		var url_index = url.indexOf('?');
		var url_to_post_to = url.substring(0,url_index);
		var qs = url.substring(url_index+1);
		xmlHttp.open("POST",url_to_post_to,false);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", qs.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(qs);
		rc = xmlHttp.responseText;
		var calendar_obj = document.getElementById('calendar_div');  
		calendar_obj.innerHTML = rc;
		var snap_to_img = callback_prefix+'_calendar_'+type+'_img';
		_P7_Snap(snap_to_img,'calendar_div',25,0);
		calendar_obj.style.display = '';
	}
}

function _panDualCalendar(type,month,year,callback_prefix)
{
    // Show calendar
    var current_day = '';
    if(callback_prefix == 'search_box_form')
    {
       if(type == 'checkin') current_day = Date.UTC(parseInt(document.getElementById('search_from_year').value),parseInt(document.getElementById('search_from_month').value)-1,parseInt(document.getElementById('search_from_day').value));  
       else if(type == 'checkout') current_day = Date.UTC(parseInt(document.getElementById('search_to_year').value),parseInt(document.getElementById('search_to_month').value)-1,parseInt(document.getElementById('search_to_day').value));
    }
    else if(callback_prefix == 'nav' || callback_prefix == 'sum')
    {
       if(type == 'checkin') current_day = Date.UTC(parseInt(document.getElementById('from_year').value),parseInt(document.getElementById('from_month').value)-1,parseInt(document.getElementById('from_day').value));  
       else if(type == 'checkout') current_day = Date.UTC(parseInt(document.getElementById('to_year').value),parseInt(document.getElementById('to_month').value)-1,parseInt(document.getElementById('to_day').value));
    }
    else if(callback_prefix == 'book' || callback_prefix == 'test')
    {
       if(type == 'checkin') current_day = Date.UTC(parseInt(document.getElementById('booking_from_year').value),parseInt(document.getElementById('booking_from_month').value)-1,parseInt(document.getElementById('booking_from_day').value));  
       else if(type == 'checkout') current_day = Date.UTC(parseInt(document.getElementById('booking_to_year').value),parseInt(document.getElementById('booking_to_month').value)-1,parseInt(document.getElementById('booking_to_day').value));
    }    
    var url = '/ajax/get_dual_calendar.ajax.php?month='+month+'&year='+year+'&type='+type+'&callback_prefix='+callback_prefix+'&current_day='+(current_day/1000);
    var rc = ajaxRequest(url, false);
    var calendar_obj = document.getElementById('calendar_div');  
    calendar_obj.innerHTML = rc;
    var snap_to_img = callback_prefix+'_calendar_'+type+'_img';
    var offset = (callback_prefix == 'combo') ? -420 : 25;
    _P7_Snap(snap_to_img,'calendar_div',offset,0);
    calendar_obj.style.display = '';
}

function _openDualCalendar(type,from_objs_prefix,to_objs_prefix,callback_prefix)
{
   month_src = (type == 'checkin') ? from_objs_prefix+'month' : to_objs_prefix+'month';
   year_src = (type == 'checkin') ? from_objs_prefix+'year' : to_objs_prefix+'year';
   
    var month = document.getElementById(month_src).value;
    var year = document.getElementById(year_src).value;
    
    if(type == 'checkout')
    {
       // check-in date selected
       var checkin_month = document.getElementById(from_objs_prefix+'month').value;
       var checkin_year = document.getElementById(from_objs_prefix+'year').value;
       
       // if check-in after check-out, may as well show further down the line
       if((checkin_month > month && checkin_year == year) ||
          (checkin_year > year))
       {
          month = checkin_month;
          year = checkin_year;
        }
    }
    
    // Show calendar
    if(current_calendar != callback_prefix+'_'+type)
    {
       _panDualCalendar(type,month,year,callback_prefix);
       current_calendar = callback_prefix+'_'+type;
    }
    else
    {
      _closeCalendar();
      current_calendar = '';
    }
}

function navSelectDateCheckIn(d,m,y)
{
   // set dates to flexible
   if(document.getElementById('flexible_any').checked == true)
   {
      document.getElementById('flexible_no').checked = true;
      enableNavDates();
	}
	
   from_day_obj = document.getElementById('from_day');
   from_month_obj = document.getElementById('from_month');
   from_year_obj = document.getElementById('from_year');
   to_day_obj = document.getElementById('to_day');
   to_month_obj = document.getElementById('to_month');
   to_year_obj = document.getElementById('to_year');
      
	from_day_obj.value = d;
	from_month_obj.value = m;   
	from_year_obj.value = y;   	
	_closeCalendar();
	_setNavDate(d,m,y,'checkin');
	
	var fromDate = new Date();
	var toDate = new Date();
   fromDate.setFullYear(y,m-1,d); 
   toDate.setFullYear(to_year_obj.value,to_month_obj.value-1,to_day_obj.value); 
   
	// if to date before from date, set to date = from date + 1 week
	if(toDate < fromDate)
	{
      toDate.setFullYear(y,m-1,d);  
      toDate.setDate(toDate.getDate()+7);
	   _setNavDate(toDate.getDate(),toDate.getMonth()+1,toDate.getFullYear(),'checkout');
	}
}

function navSelectDateCheckOut(d,m,y)
{
   // set dates to flexible
   if(document.getElementById('flexible_any').checked == true)
   {
      document.getElementById('flexible_no').checked = true;
      enableNavDates();
	}
	
	document.getElementById('to_day').value = d;
	document.getElementById('to_month').value = m;   
	document.getElementById('to_year').value = y;   	
	_closeCalendar();
	_setNavDate(d,m,y,'checkout');
}	

function _setNavDate(d,m,y,type)
{
   var year_target = (type == 'checkin') ? 'from_year' : 'to_year';
   var month_target = (type == 'checkin') ? 'from_month' : 'to_month'; 
   var day_target = (type == 'checkin') ? 'from_day' : 'to_day'; 
   year_target_obj = document.getElementById(year_target);
   month_target_obj = document.getElementById(month_target);
   day_target_obj = document.getElementById(day_target);
   
   var year_is_valid = false;
   for(i = 0; i < year_target_obj.options.length; i++)
   {
      if(year_target_obj.options[i].value == y)
	  {
         year_is_valid = true;
	  }
   }
   if(year_is_valid)
   {
      year_target_obj.value = y;
      month_target_obj.value = m;
      adjustDays(month_target,day_target,year_target);
      day_target_obj.value = d;
   }
   else
   {
      alert("Date cannot be selected as it is too far in the future");
      return;
   }
}	

		

function openCalendar(daySrc,monthSrc,yearSrc,formName)
{
   var month = eval("document.forms[formName]."+monthSrc).value;
   var year = eval("document.forms[formName]."+yearSrc).value;
   var width = 255, height = 240;
   var cal = window.open("/calendar.php?daySrc="+daySrc+"&monthSrc="+monthSrc+"&yearSrc="+yearSrc+"&month="+month+"&year="+year+"&form="+formName,'Calendar','width=' + width + ',height=' + height);
   cal.focus();
}


function enableNavDates()
{
  if(document.getElementById('flexible_any').checked)
  {
     document.getElementById('from_day').disabled = true;
     document.getElementById('from_month').disabled = true; 
     document.getElementById('from_year').disabled = true; 
     document.getElementById('to_day').disabled = true; 
     document.getElementById('to_month').disabled = true; 
     document.getElementById('to_year').disabled = true; 
     positionNavScreenDiv();
  }
  else
  {
     document.getElementById('from_day').disabled = false;
     document.getElementById('from_month').disabled = false; 
     document.getElementById('from_year').disabled = false; 
     document.getElementById('to_day').disabled = false; 
     document.getElementById('to_month').disabled = false; 
     document.getElementById('to_year').disabled = false; 
     removeNavScreenDiv(); 
  }  
}

function openImageSet(address)
{
   var width = 670, height = 570;
   var ois = window.open("/"+address,'Images','width='+width+',height='+height);
   ois.focus();
}

function setDate(d,m,y,daySrc,monthSrc,yearSrc,formName)
{
   var year_target = eval("document.forms[formName]."+yearSrc);
   var month_target = eval("document.forms[formName]."+monthSrc);
   var day_target = eval("document.forms[formName]."+daySrc);
   var year_is_valid = false;
   for(i = 0; i < year_target.options.length; i++)
   {
      if(year_target.options[i].value == y)
	  {
         year_is_valid = true;
	  }
   }
   if(year_is_valid)
   {
      year_target.value = y;
      month_target.value = m;
      adjustDays(monthSrc,daySrc,yearSrc);
      day_target.value = d;
   }
   else
   {
      alert("Date cannot be selected as it is too far in the future");
      return;
   }
   if(monthSrc.toString().indexOf("from") != -1 && !startDateIsBeforeEndDate(daySrc,monthSrc,yearSrc,formName))
   {
      setDate(d,m,y,daySrc.toString().replace("from","to"),monthSrc.toString().replace("from","to"),yearSrc.toString().replace("from","to"),formName);
   }
   if(daySrc.toString().indexOf("from")!=-1 && MM_findObj('booking_from_dow'))
   {
      setDayOfWeek(daySrc,monthSrc,yearSrc,'booking_from_dow');
   }
   if(daySrc.toString().indexOf("to")!=-1 && MM_findObj('booking_to_dow'))
   {
      setDayOfWeek(daySrc,monthSrc,yearSrc,'booking_to_dow');
   }
}

function setDayOfWeek(d,m,y,dow)
{
   var dt = new Date();
   dt.setFullYear(MM_findObj(y).value,(MM_findObj(m).value-1),MM_findObj(d).value);
   MM_findObj(dow).innerHTML = w_d_n[dt.getDay()];
}

function padout(number) { return (number < 10) ? '0' + number : number; }

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function startDateIsBeforeEndDate(daySrc,monthSrc,yearSrc,formName)
{
    startdayobj = eval("document.forms['"+formName+"']."+daySrc);
    startmonthobj = eval("document.forms['"+formName+"']."+monthSrc);
    startyearobj = eval("document.forms['"+formName+"']."+yearSrc);
    enddayobj = eval("document.forms['"+formName+"']."+daySrc.toString().replace("from","to"));
    endmonthobj = eval("document.forms['"+formName+"']."+monthSrc.toString().replace("from","to"));
    endyearobj = eval("document.forms['"+formName+"']."+yearSrc.toString().replace("from","to"));
    
    var startday = startdayobj.options[startdayobj.selectedIndex].value;
    var startmonth = startmonthobj.options[startmonthobj.selectedIndex].value;
    var startyear = startyearobj.options[startyearobj.selectedIndex].value;
    var endday = enddayobj.options[enddayobj.selectedIndex].value;
    var endmonth = endmonthobj.options[endmonthobj.selectedIndex].value;
    var endyear = endyearobj.options[endyearobj.selectedIndex].value; 
    var startdate = new Date(startyear-0,startmonth-1,startday-0);
    var enddate = new Date(endyear-0,endmonth-1,endday-0);

    starttime = Date.UTC(y2k(startdate.getYear()),startdate.getMonth(),startdate.getDate(),0,0,0);
    endtime = Date.UTC(y2k(enddate.getYear()),enddate.getMonth(),enddate.getDate(),0,0,0);

    if (starttime < endtime) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}



function adjustDays(month_field,day_field,year_field)
{
   obj = MM_findObj(month_field);
   target = MM_findObj(day_field);
   yearSrc = MM_findObj(year_field);
   d_i_m[1] = 28;
   var n_y = yearSrc.value;
   if(n_y % 4 == 0) {d_i_m[1] = 29;}
   var v = obj.value;
   var existing_value_in_target = target.value;
   target.options.length = 0;
   for(i = 1; i <= d_i_m[v-1]; i++)
   {
      target.options[i-1] = new Option(i,i);
   }
   if(existing_value_in_target < target.options.length) {target.selectedIndex = existing_value_in_target-1;} 
   else {target.selectedIndex = target.options.length-1;}
}

function adjustDaysAdmin(month_field,day_field)
{
   obj = MM_findObj(month_field);
   target = MM_findObj(day_field);
   d_i_m[1] = 29;
   var v = obj.value;
   var existing_value_in_target = target.value;
   target.options.length = 0;
   for(i = 1; i <= d_i_m[v-1]; i++)
   {
      target.options[i-1] = new Option(i,i);
   }
   if(existing_value_in_target < target.options.length) {target.selectedIndex = existing_value_in_target-1;} 
   else {target.selectedIndex = target.options.length-1;}
   d_i_m[1] = 28;
}


function repopulate(region_obj_name, area_obj_name)
{
   document.getElementById('nav_select_area_div').innerHTML = ajaxRequest('/ajax/get_sub_menu.ajax.php?area_obj_name='+area_obj_name+'&area_id='+document.getElementById(region_obj_name).value, false);
}

// Used by the sub-footer to re-populate the list of property types
// It takes three layers, the current tab, the tab to change to and
// the content (or tab pane) to fill

var active_sub_footer_tab = 1;

function change_property_list(new_tab)
{
   var current_tab_obj = MM_findObj('current');
   var new_tab_obj = MM_findObj('sub_footer_prop_li_'+new_tab);
   var current_content_obj = MM_findObj('sub_footer_prop_layer_content_'+active_sub_footer_tab);
   var new_content_obj = MM_findObj('sub_footer_prop_layer_content_'+new_tab);
   
   // Set style of original tab
   current_tab_obj.id = "sub_footer_prop_li_"+active_sub_footer_tab;

   // Set style of new tab
   new_tab_obj.id = "current";
   
   // Set visibility of content layer
   current_content_obj.style.display = 'none';
   new_content_obj.style.display = '';
   
   active_sub_footer_tab = new_tab;
   


}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}


function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  }
}



function updateNavCheckout()
{
   var sd = document.getElementById("from_day").value;  
   var sm = document.getElementById("from_month").value;
   var sy = document.getElementById("from_year").value;
   var fd = document.getElementById("to_day").value;
   var fm = document.getElementById("to_month").value;
   var fy = document.getElementById("to_year").value;
   var sdate = new Date();
   var fdate = new Date();
   sdate.setDate(sd);
   sdate.setMonth(sm-1);
   sdate.setFullYear(sy);
   fdate.setDate(fd);
   fdate.setMonth(fm-1);
   fdate.setFullYear(fy);
   var _sdate = Date.UTC(sy,sm-1,sd,0,0,0,0);
   var _fdate = Date.UTC(fy,fm-1,fd,0,0,0,0); 
   if(_fdate < _sdate)
   {
      var nfdate = sdate;
      nfdate.setDate(sdate.getDate()+7);
      document.getElementById("to_month").value = nfdate.getMonth()+1;
      document.getElementById("to_year").value = nfdate.getFullYear();
      adjustDays('to_month','to_day','to_year');
      document.getElementById("to_day").value = nfdate.getDate();
   }
}




function validateNav()
{
   if(document.getElementById('flexible_any').checked) return true;
   else
   {
	   var sd = document.getElementById("from_day").value;  
	   var sm = document.getElementById("from_month").value;
	   var sy = document.getElementById("from_year").value;
	   var fd = document.getElementById("to_day").value;
	   var fm = document.getElementById("to_month").value;
	   var fy = document.getElementById("to_year").value;
	   var sdate = Date.UTC(sy,sm-1,sd,0,0,0,0);
	   var fdate = Date.UTC(fy,fm-1,fd,0,0,0,0); 
	   var today = new Date();
	   var threshold = new Date();
	   threshold.setDate(threshold.getDate()+1);
	   today = Date.UTC(today.getFullYear(),today.getMonth(),today.getDate(),0,0,0,0);
	   threshold = Date.UTC(threshold.getFullYear(),threshold.getMonth(),threshold.getDate(),0,0,0,0);
	   if(sdate > fdate)
	   {
	      alert('There was a problem with the dates you specified. Check-In date must be before Check-Out date. Please adjust the dates and try again. Alternatively, you can click on \'Holiday Rentals\' in the main menu to view all properties throughout the region.');
	      return false;
	   }
	   else if(sdate == fdate)
	   {
	      alert('There was a problem with the dates you specified. Check-In and Check-Out date cannot be the same. Please adjust the dates and try again. Alternatively, you can click on \'Holiday Rentals\' in the main menu to view all properties throughout the region.');
	      return false;
	   }
	   else if(sdate < today)
	   {
	      alert('There was a problem with the dates you specified. Check-In date is before today. Please adjust the dates and try again. Alternatively, you can click on \'Holiday Rentals\' in the main menu to view all properties throughout the region.');
	      return false;
	   }
	   else if(sdate < threshold)
	   {
	      alert('There was a problem with the dates you specified. Please make sure your check-in day is not today. If you require a last minute reservation, please don\'t hesitate to contact us directly');
	      return false;
	   }
	   else
	   {
	      return true;
	   }
	}
}

function submitRequestCallback(request_callback_online)
{
	 var name = document.getElementById('callback_name').value;
	 var telephone = document.getElementById('callback_telephone').value;
	 if(telephone.substring(0,1) == '+') telephone = telephone.substring(1);
	 if(name == '' || name == 'Your Name' || telephone == '' || telephone == 'Phone Number')
	 {
	    alert('Please provide your name and telephone number and we will give you a call back.'); 
	 }
	 else if(isNaN(telephone) || telephone.length < 6)
	 {
	    alert('Please provide a numeric telephone number (including your country/area code) which is at least 6 digits long.');
	 }
	 else
	 {
	    var _url = document.getElementById('callback_url').value;
	    var qs = 'name='+encodeURIComponent(name)+'&telephone='+encodeURIComponent('+'+telephone)+'&url='+encodeURIComponent(_url);
	    var url = '/ajax/send_request_callback.ajax.php?'+qs;
	    var rc = ajaxRequest(url, false); 
	    if(rc == '00')
	    {
	       if(request_callback_online == '1')
	       {
	          alert('Thank you, we will contact you by telephone very shortly.');
			 }
			 else
			 {
			    alert('Thank you, we will contact you by telephone within 24 hours.');
			 }
			 document.getElementById('callback_name').value = 'Your Name';
			 document.getElementById('callback_telephone').value = 'Phone Number';
		 }
		 else
		 {
		    alert('There was a problem sending your request, please try again.');
		 }
	 }
}



function handleNavScreenClick()
{
   if(document.getElementById('flexible_any').checked)
   {
      document.getElementById('flexible_no').checked = true;
      enableNavDates();
   } 
   removeNavScreenDiv();
}

function removeNavScreenDiv()
{
   if(document.getElementById('nav_click_screen_div'))
   {
      document.getElementById('nav_click_screen_div').style.left = '-300px';    
   }
}

function positionNavScreenDiv()
{
   if(document.getElementById('nav_click_screen_div'))
   {
      _P7_Snap('nav_calendar_checkin_img','nav_click_screen_div',-155,0);
   }
   if(document.getElementById('mmh_header'))
   {
      initMMHHeader();
   }
}

function appendOnLoadEvent(event)
{
   var w_onload = window.onload;
   window.onload = function()
   {
	   if(w_onload)
	   {
         w_onload();
	   }
	   eval(event+'();'); 
	}
}
	 
function ajaxRequest(url, async, callback)
{
	xmlHttp=_GetXmlHttpObject();
	if(xmlHttp!=null)
	{
        if(typeof server_b !== 'undefined') url += '&_b='+server_b;
		var url_index = url.indexOf('?');
		var url_to_post_to = url.substring(0,url_index);
		var qs = url.substring(url_index+1);
        
		if(typeof callback !== 'undefined' && callback)
		{
		   eval('xmlHttp.onreadystatechange='+callback); 
		}
		if(url.length<2048 && url.indexOf("\r") == -1 && url.indexOf("\n"))
		{     
		   xmlHttp.open("GET",url,async);    
		   xmlHttp.setRequestHeader("Connection", "close");
		   xmlHttp.send(null);
		}
		else
		{
		   xmlHttp.open("POST",url_to_post_to,async);
		   xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		   xmlHttp.setRequestHeader("Content-length", qs.length);
		   xmlHttp.setRequestHeader("Connection", "close");
		   xmlHttp.send(qs);
		}
		
		if(callback) return '';
		else return xmlHttp.responseText;
	}
	return '';
}

function ajaxRequestAlt(url, async, callback)
{
	xmlHttpAlt=_GetXmlHttpObject();
	if(xmlHttpAlt!=null)
	{
	    if(typeof server_b !== 'undefined') url += '&_b='+server_b;
        var url_index = url.indexOf('?');
		var url_to_post_to = url.substring(0,url_index);
		var qs = url.substring(url_index+1);
		if(typeof callback !== 'undefined' && callback)
		{
		   eval('xmlHttpAlt.onreadystatechange='+callback); 
		}
		if(url.length<2048 && url.indexOf("\r") == -1 && url.indexOf("\n"))
		{
		   xmlHttpAlt.open("GET",url,async);
		   xmlHttpAlt.setRequestHeader("Connection", "close");
		   xmlHttpAlt.send(null);
		}
		else
		{
		   xmlHttpAlt.open("POST",url_to_post_to,async);
		   xmlHttpAlt.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		   xmlHttpAlt.setRequestHeader("Content-length", qs.length);
		   xmlHttpAlt.setRequestHeader("Connection", "close");
		   xmlHttpAlt.send(qs);
		}		
		if(callback) return '';
		else return xmlHttpAlt.responseText;
	}
	return '';
}



var active_context_menu_idx = -1;
function showContextMenu(idx,bShow,bFromShow)
{
   var obj = document.getElementById('context_menu_idx_'+idx);
   obj.className = (bShow) ? 'mmh_cell_active' : 'mmh_cell';
   if(!bFromShow)
   {
      obj = document.getElementById('mmh_context_menu_overlay');
      obj.innerHTML = document.getElementById('mmh_context_menu_overlay_slide_'+idx).innerHTML;
      obj.className = (bShow) ? 'mmh_context_menu_overlay_active' : 'mmh_context_menu_overlay';
      doOverlay(bShow);
   }
   if(active_context_menu_idx != -1 && active_context_menu_idx != idx) 
   {
   	   showContextMenu(active_context_menu_idx, false, true);
   }
   active_context_menu_idx = (bShow) ? idx : -1;   
   //setMMHSlide(0);
}

function hideContextMenu()
{
   if(active_context_menu_idx != -1)
   {
      showContextMenu(active_context_menu_idx, false, false);
   }	
}

var doc_height;
function doOverlay(bShow)
{
	var obj = document.getElementById('grey_overlay');
	obj.style.display = (bShow) ? '' : 'none';
	if(typeof doc_height == 'undefined') doc_height = getDocHeight();
	obj.style.height = doc_height+'px';
}

function getDocHeight() 
{
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

 var mmh_timeouts = [];
 var current_mmh_idx = 1;
 var seconds_per_slide = 5;
 var bMMHSlideRunning = true;
 
 function initMMHHeader()
 {
    if(do_init_mmh)
    {
	   mmh_timeouts[mmh_timeouts.length] = setTimeout(nextMMHSlide, seconds_per_slide*1000);
	}
 }
 
 function nextMMHSlide(bInstant)
 {
	if(typeof bInstant != 'undefined' && bInstant)
	{
		__setMMHDetails(current_mmh_idx,themes[current_mmh_idx][0],themes[current_mmh_idx][1],themes[current_mmh_idx][2],themes[current_mmh_idx][3]);
	}
	else
	{
		__FadeOut('mmh_header_theme_img');
		mmh_timeouts[mmh_timeouts.length] = setTimeout("__setMMHDetails("+current_mmh_idx+",'"+themes[current_mmh_idx][0]+"','"+themes[current_mmh_idx][1]+"','"+themes[current_mmh_idx][2]+"','"+themes[current_mmh_idx][3]+"');",8*100);
		mmh_timeouts[mmh_timeouts.length] = setTimeout("__FadeIn('mmh_header_theme_img');",9*100);
		mmh_timeouts[mmh_timeouts.length] = setTimeout(nextMMHSlide, (seconds_per_slide+1)*1000);
		current_mmh_idx++;
		if(current_mmh_idx >= themes.length) current_mmh_idx = 0;  
	}
 }
 
 function cancelMMHSlide()
 {
	for(var i = 0; i < mmh_timeouts.length; i++)
	{
	   clearTimeout(mmh_timeouts[i]);
	}	 
 }
 
 function setMMHSlide(idx)
 {
	cancelMMHSlide();
	current_mmh_idx = idx;
	nextMMHSlide(true); 	 
 }
 
 function __setMMHDetails(idx, x1, x2, x3, x4)
 {
	document.getElementById('mmh_header_theme_img').style.backgroundImage = 'url('+x3+')';	 
	document.getElementById('mmh_header_theme_text').innerHTML = x1;
	document.getElementById('mmh_header_theme_link').href = x2;
	document.getElementById('mmh_header_theme_link').title = x4;
	document.getElementById('mmh_circle_'+idx).className = 'mmh_circle_active';
	for(var i = 0; i < themes.length; i++)
	{
	   document.getElementById('mmh_circle_'+i).className = (i == idx) ? 'mmh_circle_active' : 'mmh_circle';   
	}
 }
 
function __FadeIn($WhichDiv) {
   __setOpac($WhichDiv,0);
   for( var i = 0 ; i <= 100 ; i++ ) 
   {
		  (function(opacity)
		  {
			 mmh_timeouts[mmh_timeouts.length] = setTimeout(function() { __setOpac($WhichDiv,opacity); } , 8 * i );
		  })(i);          
   }
}

function __FadeOut($WhichDiv) {
   for( var i = 0 ; i <= 100 ; i++ ) 
   {
		  (function(opacity)
		  {
			 mmh_timeouts[mmh_timeouts.length] = setTimeout(function() { __setOpac($WhichDiv,100 - opacity); } , 8 * i );
		  })(i);          
   }
}

function __setOpac( $WhichDiv, value ) {
	  if(document.getElementById($WhichDiv))
	  {
		 document.getElementById($WhichDiv).style.opacity = value / 100;
		 document.getElementById($WhichDiv).style.filter = 'alpha(opacity=' + value + ')';
	  }
}	

function mmhExpandCollapse()
{
   var obj = document.getElementById('mmh_collapse_expand_div');	
   var bShow = (obj.style.display == 'none') ? true : false;
   if(!bShow) cancelMMHSlide();
   else nextMMHSlide();
   obj.style.display = (bShow) ? '' : 'none';
   obj = document.getElementById('mmh_collapse_expand_div_block');
   obj.style.height = (bShow) ? '445px' : '150px';
   document.getElementById('breadcrumb_iframe').contentWindow.document.getElementById('mmh_expand_collapse_txt').innerHTML = (bShow) ? 'Collapse' : 'Expand';
   document.getElementById('breadcrumb_iframe').contentWindow.document.getElementById('mmh_expand_collapse_img').src = (bShow) ? '/images/collapse.png' : '/images/expand.png';
   var url = '/ajax/mmh_state_cookie.ajax.php?bShow='+((bShow) ? 1 : 0);
   ajaxRequest(url, true);
}



function logError(msg, file_loc, line_no)
{
	xmlHttp=_GetXmlHttpObject();
	if (xmlHttp!=null)
	{
      xmlHttp.open("GET",'/ajax/log_error.ajax.php?msg='+msg+'&file_loc='+file_loc+'&line_no='+line_no+'&ua='+navigator.userAgent+'&os='+navigator.platform,true);
      xmlHttp.send(null);
	} 
	return true;
}

window.onerror = logError;
appendOnLoadEvent('positionNavScreenDiv');    

 


