function checkfields() {
	var error=0;
    var now = new Date();
    var curMonth = (now.getMonth()+1);
    var lstChildAges = "";
    var elements = document.getElementsByTagName("select");
    
    if (document.formHO.dateLeavingMonth.value < curMonth)
       {theyear = now.getFullYear()+1;}
    else if (document.formHO.dateLeavingMonth.value >= curMonth)
       {theyear = now.getFullYear();}
    if (document.formHO.dateReturningMonth.value < curMonth)
       {thedepyear = now.getFullYear()+1;}
    else if (document.formHO.dateReturningMonth.value >= curMonth)
       {thedepyear = now.getFullYear();}
	document.formHO.checkin.value=document.formHO.dateLeavingMonth.value+'/'+document.formHO.dateLeavingDay.value+'/'+theyear;
	document.formHO.checkout.value=document.formHO.dateReturningMonth.value+'/'+document.formHO.dateReturningDay.value+'/'+thedepyear;

     SystemType=document.formHO.system.value;
     URLVars='id='+document.formHO.accomid.value+'&checkin='+document.formHO.checkin.value+'&checkout='+document.formHO.checkout.value+'&adults='+document.formHO.adults.value+'&children='+document.formHO.children.value+'&rooms='+document.formHO.rooms.value+'&refLoc='+document.formHO.JSrefLoc.value+'&bookedOnrefLoc='+document.formHO.JSbookedOnrefLoc.value;//+'&tollfree='+document.formHO.JStollfree.value
     //if (document.formHO.JStollfree) URLVars += '&tollfree=' + document.formHO.JStollfree.value;
     if (typeof document.formHO.JStollfree != 'undefined' && document.formHO.JStollfree != ''){
		URLVars = URLVars + '&tollfree=' + document.formHO.JStollfree.value;
	 }
     
     if (typeof document.formHO.selRoomType != 'undefined'){
	 	//pass selected room id if it's defined and is an integer
	 	if (!isNaN(parseInt(document.formHO.selRoomType.value))){
	 		URLVars = URLVars + '&selroomid=' + parseInt(document.formHO.selRoomType.value);
	 	}
	 }
	 
	 
	// add the child selectors to the urlVars
	for(i=0;i<=elements.length-1;i++){
		if(elements[i].name == 'slChildAges'){
			lstChildAges = lstChildAges + elements[i].value + ',';						
		}
	}
	URLVars = URLVars + '&lstChildAges=' + lstChildAges;
	 
	 if (SystemType == '1')
	   {window.open('https://secure.guestdesk.com/rooms/?'+URLVars,'RoomReservations','toolbar=no,scrollbars=auto,location=no,resizable=no,directories=no,status=yes,menubar=no,width=790,height=490,screenX=1,screenY=1,top=1,left=1')}
	 else if (SystemType == '2')
	   {window.open('https://secure.guestdesk.com/specials/?'+URLVars,'SpecialsReservations','toolbar=no,scrollbars=auto,location=no,resizable=no,directories=no,status=yes,menubar=no,width=790,height=490,screenX=1,screenY=1,top=1,left=1')}
	 else if (SystemType == '3')
	   {window.open('https://secure.guestdesk.com/golf/?siteID=resvbox&'+URLVars,'GolfPackageReservations','toolbar=no,scrollbars=auto,location=no,resizable=no,directories=no,status=yes,menubar=no,width=790,height=450,screenX=1,screenY=1,top=1,left=1')}
	 else if (SystemType == '4'){ //condo interface
	 	if (document.formHO.lodgingTypes.value == 'All' && document.formHO.propertyTypes.value == 'All'){
			alert("Please choose Location or Property");
		}
		else{
			document.formHO.action=document.formHO.submitPath.value+'&'+URLVars+'&bedrooms='+document.formHO.bedrooms.value+'&lodgingTypes='+document.formHO.lodgingTypes.value+'&propertyTypes='+document.formHO.propertyTypes.value; document.formHO.submit();
		}
	 }
}

function checkfields_V3() {
	var error=0;
    var now = new Date();
    var curMonth = (now.getMonth()+1);
    var lstChildAges = "";
    var elements = document.getElementsByTagName("select");

    
    if (document.formHO.dateLeavingMonth.value < curMonth)
       {theyear = now.getFullYear()+1;}
    else if (document.formHO.dateLeavingMonth.value >= curMonth)
       {theyear = now.getFullYear();}
    if (document.formHO.dateReturningMonth.value < curMonth)
       {thedepyear = now.getFullYear()+1;}
    else if (document.formHO.dateReturningMonth.value >= curMonth)
       {thedepyear = now.getFullYear();}
	document.formHO.checkin.value=document.formHO.dateLeavingMonth.value+'/'+document.formHO.dateLeavingDay.value+'/'+theyear;
	document.formHO.checkout.value=document.formHO.dateReturningMonth.value+'/'+document.formHO.dateReturningDay.value+'/'+thedepyear;

     SystemType=document.formHO.system.value;
     URLVars='id='+document.formHO.accomid.value+'&checkin='+document.formHO.checkin.value+'&checkout='+document.formHO.checkout.value+'&adults='+document.formHO.adults.value+'&children='+document.formHO.children.value+'&rooms='+document.formHO.rooms.value+'&refLoc='+document.formHO.JSrefLoc.value+'&bookedOnrefLoc='+document.formHO.JSbookedOnrefLoc.value;
     //if (document.formHO.JStollfree) URLVars += '&tollfree=' + document.formHO.JStollfree.value;
     if (typeof document.formHO.JStollfree != 'undefined' && document.formHO.JStollfree != '' && document.formHO.JStollfree != 0){
		URLVars = URLVars + '&tollfree=' + document.formHO.JStollfree.value;
	 }

	 if (typeof document.formHO.selRoomType != 'undefined'){
	 	//pass selected room id if it's defined and is an integer
	 	if (!isNaN(parseInt(document.formHO.selRoomType.value))){
	 		URLVars = URLVars + '&selroomid=' + parseInt(document.formHO.selRoomType.value);
	 	}
	 }

	
	// add the child selectors to the urlVars
	for(i=0;i<=elements.length-1;i++){
		if(elements[i].name == 'slChildAges'){
			lstChildAges = lstChildAges + elements[i].value + ',';						
		}
	}
	URLVars = URLVars + '&lstChildAges=' + lstChildAges;
	
	 if (SystemType == '1')
	   {document.formHO.action='https://secure.guestdesk.com/reservations/?'+URLVars; document.formHO.submit();}
	 else if (SystemType == '2')
	   {document.formHO.action='https://secure.guestdesk.com/reservations/?'+URLVars+'&systemType=2'; document.formHO.submit();}
	 else if (SystemType == '3')
	   {window.open('https://secure.guestdesk.com/golf/?siteID=resvbox&'+URLVars,'GolfPackageReservations','toolbar=no,scrollbars=auto,location=no,resizable=no,directories=no,status=yes,menubar=no,width=790,height=450,screenX=1,screenY=1,top=1,left=1')}
	 else if (SystemType == '4') //condo interface
	   {document.formHO.action=document.formHO.submitPath.value; document.formHO.submit();}
}

function addChildren(intChildren){
	var rowChildAges = document.getElementById("gd_childAgeSelectRow");
	var colChildAges = document.getElementById("gd_childAgeSelectCol");
	var strChildSelectHTML = "";
	
	// if there are no children selected, do not display the row to allow for selection
	if(intChildren == 0){
		rowChildAges.style.display = 'none';
		colChildAges.style.display = 'none';

	}else{
		
		rowChildAges.innerHTML = "Select the age of each child";
		rowChildAges.style.display = 'block';
		colChildAges.style.display = 'block';
		
		colChildAges.innerHTML = '';	
		
		for(i=0; i<=intChildren-1;i++){
			strChildSelectHTML = '<select name="slChildAges" id="slChildAges">';
			for(j=0;j<=17;j++){
				//strChildSelectHTML = strChildSelectHTML + "<option>" + i + "</option>";
				strChildSelectHTML = strChildSelectHTML + "<option value=" + j + ">" + j + "</option>";		
			}
			strChildSelectHTML = strChildSelectHTML + "</select> ";
		  	colChildAges.innerHTML = colChildAges.innerHTML + strChildSelectHTML;
		}
	}	
}
	
function rePositionCal (e) {
  var theCoodinates=checkwhere(e);
  var coodinateArray=theCoodinates.split(":");
  var Xcoodinate=parseInt(coodinateArray[0]);
  var Ycoodinate=parseInt(coodinateArray[1]);
  var ifr = 
    document.all ? document.all['iframeCal'] : 
      document.getElementById('iframeCal');
  ifr.style.top=Ycoodinate+'px';
  ifr.style.left=Xcoodinate+'px';
  //ifr.style.visibility='hidden';
}

function checkwhere(e) {
  // returns the mouse x and y coodinates to position the calendar
    var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

  return (posx+':'+posy)
}

function specialCodeWindow() {
    if (document.specCodeForm.specialsCode.value == '')
       {alert('Please enter the special code'); return false;}
    else
       {URLVars='id='+document.formHO.accomid.value+'&specialCode='+escape(document.specCodeForm.specialsCode.value)+'&refLoc='+document.formHO.JSrefLoc.value+'&bookedOnrefLoc='+document.formHO.JSbookedOnrefLoc.value;
	    window.open('https://secure.guestdesk.com/specials/?'+URLVars,'SpecialsReservations','toolbar=no,scrollbars=auto,location=no,resizable=no,directories=no,status=yes,menubar=no,width=790,height=490,screenX=1,screenY=1,top=1,left=1');
		return false;
	   }
}

function specialCodeWindow_V3() {
    if (document.specCodeForm.specialsCode.value == '')
       {alert('Please enter the special code'); return false;}
    else
       {URLVars='id='+document.formHO.accomid.value+'&specialCode='+escape(document.specCodeForm.specialsCode.value)+'&refLoc='+document.formHO.JSrefLoc.value+'&bookedOnrefLoc='+document.formHO.JSbookedOnrefLoc.value;
	   document.formHO.action='https://secure.guestdesk.com/reservations/?'+URLVars+'&systemType=2'; document.formHO.submit();
		return false;
	   }
}

// Used on www.hhi-vr.com only - sets the date select boxes to the current date
function setInitialDates() {
    var now = new Date();
	var nowPlus2Days=new Date(now.getTime() + 2*24*60*60*1000);
    var curMonth = (nowPlus2Days.getMonth()+1);
	document.formHO.monthToSend.value=curMonth;
	document.formHO.yearToSend.value=nowPlus2Days.getYear();
    document.formHO.dateLeavingMonth.selectedIndex=nowPlus2Days.getMonth();
    document.formHO.dateLeavingDay.selectedIndex=nowPlus2Days.getDate()-1;
	adjDate(document.formHO);
}


