/*
Google Tracking for Form QR
Author: D. Siriwardana
Company: eBeyonds
Create Date:24.04.2008
Modify Date:21.07.2008
Edited By: D. Siriwardana
*/


this.months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
this.monthsnum=[1,2,3,4,5,6,7,8,9,10,11,12];

/*function to replace spaces after using escape() (this is a must, without parsing data through this, iHotelier will not accept params)*/
function remSpaces(variable){
	var temp=variable;
	for(var i=0; i<temp.length;i++){
		temp=temp.replace(/%20/,"+");
	}
	return temp;
}

/*this function formats the url string to be compatible with istay*/
function remSpacesiStay(variable){
	var temp=variable;
	for(var i=0; i<temp.length;i++){
		temp=temp.replace(/%20/,""); //%20=space character
		temp=temp.replace(/%2C/,"%2F");//%2C=,	%2F=/
	}
		
	return temp;
}

/*this function will format the date to a istay compatible date format*/
function iStayDate(variable){
	var temp=variable;
	for(var i=0; i<temp.length;i++){
		temp=temp.replace(/%20/,"");
	}
	var temparr=temp.split("%2C");
	for(var i=0;i<months.length;i++){
		if (temparr[1] == months[i]) {
			temparr[1] = monthsnum[i];
		}
	}
	temp=temparr[1]+"%2C"+temparr[0]+"%2C"+temparr[2];
	
	return temp;	
}

/*this funtion will get all values from form fields*/
function getData(){
	var data="";
	var date="&DateIn="+iStayDate(escape(document.getElementById('DateIn').value));	
	var length="&Length="+escape(document.getElementById('SelectLength').value);
	var adults="&Adults="+escape(document.getElementById('adl').value);
	var children="&Children="+escape(document.getElementById('child').value);
	var rooms="&Rooms="+escape(document.getElementById('room').value);
	data=date+length+adults+children+rooms;
	data=remSpacesiStay(data);
	return data;
}

/*funtion to append all values to the address and utmLink it*/
function sendData(val){
	var url="https://booking.ihotelier.com/istay/istay.jsp?hotelid=6310&languageid=1"+val;
	document.forms[0].action=_gaq.push(['_link',url]);

	/*	window.location=url;*/
	return false;		
}