// JavaScript Document
function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	//the e-mail address can be blank
	if (emailStr == '') {return false;}
	
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	return true;
}
/*
Improved version for send function
More Generic.
@Attribute Email is the email to send
*/
function sendToArgusRentals(country,affId,email){	
	if (emailCheck(email)) {	
		var nWidth = 330;
		var nHeight = 150;
		var nTop = (screen.height - nHeight) / 2;
		var nLeft = (screen.width - nWidth) / 2;
		var sPref = 'toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=yes,copyhistory=no,width=' + nWidth + ',height=' + nHeight + ',screenX=' + nLeft + ',screenY=' + nTop + ',top=' + nTop + ',left=' + nLeft;		
		window.open("http://www.argusrentals.com/email/multilingual/email2.asp?country=" + country.toString() +"&id="+ affId.toString() +"&ad="+ email.toString(),"_blank",sPref.toString());
	}	
}

/*
* Compare to dates, format: ddmmyy 
* @param {string} dat1 Max offers to display (rows)
* @param {string} dat2 String with the corrent language for the word 
* @return true when dat1 is smaller than dat2
* @return false when dat1 is bigger than dat2 
* */
function compareDates(dat1,dat2){
d1 = new Number(dat1.substr(0,2));
m1 = new Number(dat1.substr(2,2));
y1 = new Number(dat1.substr(4,5));	

d2 = new Number(dat2.substr(0,2));
m2 = new Number(dat2.substr(2,2));
y2 = new Number(dat2.substr(4,5));	
if(y1 > y2)return false;
else if( m1 > m2 && y1 >= y2){return false;}
else if (d1>d2 && m1 >= m2 && y1 >= y2 )return false;
return true;
}
/*/ configYCalendar /
*  This function set the limits dates to choose a flight.
*  1 year from the current date
*  The configuration returned is JSON object. This is used for the Calendar constructor
*  @return: JSON object.
*/
function configYCalendar() {
   var _pagedate,_mindate,_maxdate;   
   date = new Date();  
   _pagedate = (date.getMonth() + 1) + "/" + date.getFullYear();
   _mindate = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
   _maxdate = (date.getMonth() + 1) + "/" + date.getDate() + "/" + (date.getFullYear() + 1);   
   return {pagedate: _pagedate.toString() ,mindate:_mindate.toString() ,maxdate:_maxdate.toString(),title:"Choose a date:",close:true};
}
/*
Function used by the form sign-up on:
car-hire.php
hotels.php
flights.php
*/
function sendEMail(){
return sendToArgusRentals('GB','26853',document.getElementById('sign-up-email').value);
}

function cleanInput(obj){obj.value=""}

/*function Change engine*/
function changeEngine(cntryID,locID)
{
	var i=new Number(0),
	_option=abeOption.get("countryList");
	with(ctOTAEngine)
	{
		setCountryID(cntryID);
		setPickupID(locID);
		setReturnID(locID);
	}
	while(_option[i].value!=ctOTAEngine.countryID){i++;}
	_option[i].selected=true;
	ctOTAEngine.step1Container.pickup.populate();
}
