//builds query string to booking engine and adds some Google Analytics variables also
function OnSubmitForm2009()
{
    var form = document.DateSelect;
    // check if length of stay is greater than 0
    if(checkDates()){
        var hotel = form.hotel.value;
        var arrivalDay = form.arriveDate.value;
        var arrivalMonth = form.arriveMonth.value;
        var arrivalYear = form.arriveYear.value;
        var departureDay = form.departDate.value;
        var departureMonth = form.departMonth.value;
        var departureYear = form.departYear.value;
        var numAdults = form.numberAdults.value;
		var numChilds = form.numberChilds.value;
		var roomNums = form.roomNums.value;
		var whatLanguage = form.whatLanguage.value;
		if(!form.promo_code.value){
			var promo = "";
		}
		else{
			var promo = "&promo=" + form.promo_code.value;
		}
        document.DateSelect.action=" https://gc.synxis.com/rez.aspx?Hotel="+hotel+"&Chain=5182&altdest=THNAV&locale="+whatLanguage+"&arrive="+arrivalDay+"/"+arrivalMonth+"/"+arrivalYear+"&depart="+departureDay+"/"+departureMonth+"/" + departureYear +""+ promo +"&Adult="+numAdults+"&child=" + numChilds +"&rooms=" + roomNums + "&start=81";
        //return true;
        //__utmLinkPost(document.DateSelect);
		_gaq.push(['_link', document.DateSelect]);
        pageTracker._trackEvent('form', 'submit');
        pageTracker._linkByPost(document.DateSelect)
    }else{
        alert("Please check the selected dates.");
        return false;
    }
}
function OnSubmitFormEdResExternal()
{
    var form = document.DateSelect;
    // check if length of stay is greater than 0
    if(checkDates()){
        var hotel = form.hotel.value;
        var arrivalDay = form.arriveDate.value;
        var arrivalMonth = form.arriveMonth.value;
        var arrivalYear = form.arriveYear.value;
        var departureDay = form.departDate.value;
        var departureMonth = form.departMonth.value;
        var departureYear = form.departYear.value;
        var numAdults = form.numberAdults.value;
		var numChilds = form.numberChilds.value;
		var roomNums = form.roomNums.value;
		var whatLanguage = form.whatLanguage.value;
		if(!form.promo_code.value){
			var promo = "";
		}
		else{
			var promo = "&promo=" + form.promo_code.value;
		}
        document.DateSelect.action=" https://gc.synxis.com/rez.aspx?Hotel="+hotel+"&Chain=5182&shell=GCO2&Dest=THNAV&arrive="+arrivalMonth+"/"+arrivalDay+"/"+arrivalYear+"&depart="+departureMonth+"/"+departureDay+"/" + departureYear +"&Adult="+numAdults+"&child=" + numChilds +"&rooms=" + roomNums;
        //return true;
        //__utmLinkPost(document.DateSelect);
		_gaq.push(['_link', document.DateSelect]);
        pageTracker._trackEvent('form', 'submit');
        pageTracker._linkByPost(document.DateSelect)
    }else{
        alert("Please check the selected dates.");
        return false;
    }
}
function specialOffers_departureDateCalc()
{
	var form = document.DateSelect;
	var d = new Date(parseInt(form.arriveMonth.value,10)+"/"+parseInt(form.arriveDate.value,10)+"/"+parseInt(form.arriveYear.value,10));
	d.setDate(d.getDate()+ parseInt(form.lengthStay.value,10));
	//document.getElementById('endDate').style.display="none";
	
	form.departDate.value = d.getDate();
	form.departMonth.value = (d.getMonth()+1);
	form.departYear.value = d.getYear();
}

function blthswood_special(){
	var form = document.DateSelect;
	if(document.getElementById("blyth_special")){
		var d = new Date(parseInt(form.arriveMonth.value,10)+"/"+parseInt(form.arriveDate.value,10)+"/"+parseInt(form.arriveYear.value,10));
		var LD = new Date(parseInt(form.departMonth.value,10)+"/"+parseInt(form.departDate.value,10)+"/"+parseInt(form.departYear.value,10));

		if((LD.getYear() == "109") || (LD.getYear() == "2009")){
			if((LD.getMonth()+1) <= 11){
				if(((LD.getDate() < 10) && (LD.getMonth()+1) == "11") || ((LD.getMonth()+1) < 11)){

					document.getElementById("endDate").value = "10-Nov-2009";
					form.departDate.value = 10;
					form.departMonth.value = 11;
					form.departYear.value =2009;
					form.lengthStay.value = 1;
				}
			}
		}

		if((d.getYear() == "109") || (d.getYear() == "2009")){
			if((d.getMonth()+1) <= 11){
				if(((d.getDate() < 9) && (d.getMonth()+1) == "11") || ((d.getMonth()+1) < 11)){

					document.getElementById("startDate").value = "9-Nov-2009";
					form.arriveDate.value = 9;
					form.arriveMonth.value = 11;
					form.arriveYear.value = 2009;
					form.lengthStay.value = 1;
				}
			}
		}
	}
}
//builds query string to booking engine and adds some Google Analytics variables also
function OnSubmitForm()
{
    var form = document.DateSelect;
    // check if length of stay is greater than 0
    if(checkDates()){
        var hotel = form.hotel.value;
        var arrivalDay = form.arriveDate.value;
        var arrivalMonth = form.arriveMonth.value;
        var arrivalYear = form.arriveYear.value;
        var departureDay = form.departDate.value;
        var departureMonth = form.departMonth.value;
        var departureYear = form.departYear.value;
        var numAdults = form.numberAdults.value;
		
        document.DateSelect.action=" https://reservations.synxis.com/gc/rez.aspx?Hotel="+hotel+"&Chain=5182&altdest=THNAV&lang=1&locale=en-gb&arrive="+arrivalDay+"/"+arrivalMonth+"/"+arrivalYear+"&depart="+departureDay+"/"+departureMonth+"/"+departureYear+"&Adult="+numAdults;
        //return true;
        //__utmLinkPost(document.DateSelect);
        pageTracker._trackEvent('form', 'submit');
        pageTracker._linkByPost(document.DateSelect)
    }else{
        alert("Please check the selected dates.");
        return false;
    }
}

function checkDates() {
	d1 = new Date(document.DateSelect.arriveYear.value, document.DateSelect.arriveMonth.value-1, document.DateSelect.arriveDate.value);
	d2 = new Date(document.DateSelect.departYear.value, document.DateSelect.departMonth.value-1, document.DateSelect.departDate.value);
	
	if ((d1.getTime()/1000) < (d2.getTime()/1000)){
		return true;	
	}else{
		return false;
	}
	

}

//adds Google Analytics code to all booking engine links which have been manually added via WMS external links
//also adds '&start=1' to any links on page that do not already have it -to set booking engine start page
//ignores links with rel=stage_one - which can be set in WMS
window.onload= function (){

var linksOnPage = document.getElementsByTagName("A");

for(i=0; i<linksOnPage.length; i++){

		var a_link = linksOnPage[i].toString();
		var soughtBookingLink="synxis.com";
		var lowercase_a_link = a_link.toLowerCase();
		var a_link_rel = linksOnPage[i].rel;

		if((lowercase_a_link.indexOf(soughtBookingLink)!=-1) && (a_link_rel!="stage_one")){

			if(lowercase_a_link.indexOf("&start=1")==-1){
				a_link += "&start=1"; 
			}

			linksOnPage[i].href=a_link;
			linksOnPage[i].onclick= function() { pageTracker._link(this.href); return false; };
		}
	}
}



   
  function getChoice2(){
var searchFor = document.getElementById('whichSearch').selectedIndex;

  
if(searchFor==1){   
    document.getElementById('searchFor_Extra').value = "inurl:townhousecompany";
}
else if(searchFor==2){
    document.getElementById('searchFor_Extra').value = "inurl:channings";
}
else if(searchFor==3){
    document.getElementById('searchFor_Extra').value = "inurl:the_howard";
}
else if(searchFor==4){
    document.getElementById('searchFor_Extra').value = "inurl:thebonham";
}
else if(searchFor==5){
    document.getElementById('searchFor_Extra').value = "inurl:theedinburghresidence";
}
else if(searchFor==6){
    document.getElementById('searchFor_Extra').value = "inurl:blythswoodsquare";
}
else{document.getElementById('searchFor_Extra').value = "";}

 document.getElementById('search form').action =   document.getElementById('whichSearch').value;
}




function SocialTags(URL) { 
  
  var currentURL = window.location.href;
  
  if(URL=="http://www.facebook.com/share.php")
  {
    newWindow = window.open(URL + "?u="+currentURL + "&amp;title=");
  }
  else if(URL=="http://twitter.com/home")
  {
	 newWindow = window.open(URL + "?status="+currentURL + "&amp;title=");
  }
  else{
     newWindow = window.open(URL + "?url="+currentURL + "&amp;title=");
  }
  if (window.focus) {newWindow.focus()}      

} 

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=278,height=426,left = 1230,top = 670');");
}


