// JavaScript Document
function checkfields_V1() {
	 var error=0;
     var curYear = parseInt(document.formHOV1.currYear.value);
     var curMonth = parseInt(document.formHOV1.currMonth.value);
     
   
     if (document.formHOV1.dateLeavingMonth.value < curMonth)
        {theyear = curYear+1;}
     else if (document.formHOV1.dateLeavingMonth.value >= curMonth)
        {theyear = curYear;}
     if (document.formHOV1.dateReturningMonth.value < curMonth)
        {thedepyear = curYear+1;}
     else if (document.formHOV1.dateReturningMonth.value >= curMonth)
        {thedepyear = curYear;}

	 document.formHOV1.checkin.value=document.formHOV1.dateLeavingMonth.value+'/'+document.formHOV1.dateLeavingDay.value+'/'+theyear;
	 document.formHOV1.checkout.value=document.formHOV1.dateReturningMonth.value+'/'+document.formHOV1.dateReturningDay.value+'/'+thedepyear;
     
    
	 // find the site ID in the URL and set up URL params for a user bookmark
	 var siteIDstring='';
	 if (location.search != "")
	 {
		var x = location.search.substr(1).split("&")
		for (var i=0; i<x.length; i++)
		{
			var y = x[i].split("=");
			casechanged=y[0].toLowerCase();
			if (casechanged == 'siteid')
				{siteIDstring=y[1];}
		}
	 }	

	// uses its own URL, redirect accordingly
	var subDirLoc='';
	if (location.hostname=='www.travel-journeypod.com' || location.hostname=='www.travel-gocorporateaccess.com' || location.hostname=='travel-journeypod.com' || location.hostname=='travel-gocorporateaccess.com') {
		//var currLoc=left(location.href,43);
		//var currLoc2=left(location.href,39);
		var str=location.href
		var currLoc=str.substring(0,43);
		var currLoc2=str.substring(0,39);
		var currLoc3=str.substring(0,51);
		var currLoc4=str.substring(0,47);
		if (currLoc == 'http://www.travel-journeypod.com/?siteID=40' || currLoc2 == 'http://travel-journeypod.com/?siteID=40' || currLoc3 == 'http://www.travel-gocorporateaccess.com/?siteID=139' || currLoc4 == 'http://travel-gocorporateaccess.com/?siteID=139')
			{subDirLoc='hotelsearch/';}
	}
 
 	if (location.hostname=='www.corporateaccessllc.com' || location.hostname=='corporateaccessllc.com' || location.hostname=='www.gocorporateaccess.com' || location.hostname=='gocorporateaccess.com') {
		siteIDstring=139;
		subDirLoc='http://www.travel-gocorporateaccess.com/hotelsearch/';
	}

	if (siteIDstring != '41') {
		 document.formHOV1.action=subDirLoc+'processing.cfm?siteID='+siteIDstring+'&checkin='+document.formHOV1.checkin.value+'&checkout='+document.formHOV1.checkout.value+'&adults='+document.formHOV1.adults.value+'&children='+document.formHOV1.children.value+'&rooms='+document.formHOV1.rooms.value;
	}
	document.formHOV1.submit();
}




function checkfields() {
 var error=0;
	if (typeof guestdeskWidgetGlobalHook == 'function'){
		try{
			guestdeskWidgetGlobalHook();
		} catch(e) {}
	}
    var now = new Date();
    var curMonth = (now.getMonth()+1);
    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;
	if (document.formHO.property.value == 0) {
		if (typeof guestdeskWidgetAdditionalURLVars == 'string'){
			try{
				document.formHO.action = document.formHO.action + guestdeskWidgetAdditionalURLVars;
			} catch(e) {}
		}
		try{  
		   pageTracker._linkByPost(document.formHO);
		} catch(e) {}
		document.formHO.submit();}
	else {
		//Property selected from the multiple property dropdown
		URLVars='id='+document.formHO.property.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 (typeof guestdeskWidgetAdditionalURLVars == 'string'){
			try{
				URLVars = URLVars + guestdeskWidgetAdditionalURLVars;
			} catch(e) {}
		}
		document.formHO.action='https://secure.guestdesk.com/reservations/?'+URLVars; document.formHO.submit(); }
}

function specialCodeWindow_V3() {
    if (document.specCodeForm.specialsCode.value == '')
       {alert('Please enter the special code'); return false; }
    else
       {  URLVars='id='+document.specCodeForm.siteID.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;
	   }
}

//new function for global search special code
function specialCodeWindow_V4() {
    if (document.specCodeForm.specialsCode.value == '')
       {alert('Please enter the special code'); return false;}
    else
       {
	   	if(document.specCodeForm.siteID.value > 0){
			URLVars='id='+document.specCodeForm.siteID.value+'&specialCode='+escape(document.specCodeForm.specialsCode.value);
	   		document.formHO.action='https://secure.guestdesk.com/globalSearch/specialGlobalSearch.cfm?'+URLVars; document.formHO.submit();
			return false;
		}
		else{}
		
		
	   }
}

/*
function rePositionCal () {
  var theCoodinates=checkwhere();
  var coodinateArray=theCoodinates.split(":");
  var Xcoodinate=parseInt(coodinateArray[0])-50;
  var Ycoodinate=parseInt(coodinateArray[1])+10;
  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
        if (document.layers){
        xCoord = e.x;
        yCoord = e.y;
}
        else if (document.all){
        xCoord = event.clientX;
        yCoord = event.clientY;
}
        else if (document.getElementById){
        xCoord = e.clientX;
        yCoord = e.clientY;
}
   return (xCoord+':'+yCoord)
}
*/
function rePositionCal (e) {
  var theCoodinates=checkwhere(e);
  var coodinateArray=theCoodinates.split(":");
  var Xcoodinate=parseInt(coodinateArray[0])-5;//parseInt(document.formHO.offsetX.value
  var Ycoodinate=parseInt(coodinateArray[1])+parseInt(document.formHO.offsetY.value);
  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 openArrivalCal(theEvent) {
	window.calendar.openCal(theEvent,'HO_from','HO_cal');
	adjDate(document.formHO);
	rePositionCal();
}
function openDepartureCal(theEvent) {
	window.calendar.openCal(theEvent,'HO_to','HO_cal');
	b_stopBit = 1;
	rePositionCal();
}
