
var validOutDate=1;
var validInDate=1;
var signInExistingUser="notused";
var eventCancelled = false;

var searchDisplayValidation = "Off";

function CommonKeyPress(buttonToClick)
{
	if (event.keyCode == 13)
	{
		if(ReturnUserValidation())
		{
			document.forms[0].elements[buttonToClick].click();
		}	
	}
	eventCancelled = true;
}

function ReturnUserValidation()
{
	var EmailAddress = document.getElementById("txtReturnUserEmailExist").value;
	
	if(EmailAddress!="")
	{
		document.getElementById('returnUserNameEmptyLbl').style.display = "None";
			
		if(!isEmailAddr(EmailAddress) || !emailCheck(EmailAddress))
		{
			document.getElementById('returnUserInvalidEmailIDLbl').style.display = "Inline";
			return false;
		}
		else
		{
			document.getElementById('returnUserInvalidEmailIDLbl').style.display = "None";
		}
	}
	else
	{
		document.getElementById('returnUserNameEmptyLbl').style.display = "Inline";
		return false;
	}
	
	var Password = document.getElementById("txtReturnUserPasswordExist").value;	
	var strPassword = new String(Password);
	
	if(strPassword.length <  4 || strPassword.length>35)
	{
		document.getElementById('returnUserInvalidPwdFormLbl').style.display = "Inline";
		return false;
	}
	else
	{
		document.getElementById('returnUserInvalidPwdFormLbl').style.display = "None";
	}
	__doPostBack('btnReturningUserLogin','');
	
	return false;
}

function NewUserValidation()
{
	var controlName = "ctlNewUserEmail_";
	
	var EmailAddress = document.getElementById(controlName+"txtEmailAddress_new").value;
	
	if(EmailAddress!="")
	{
		document.getElementById('newUserNameEmptyLbl').style.display = "None";
			
		if(!isEmailAddr(EmailAddress) || !emailCheck(EmailAddress))
		{
			document.getElementById('newUserInvalidEmailIDLbl').style.display = "Inline";
			return false;
		}
		else
		{
			document.getElementById('newUserInvalidEmailIDLbl').style.display = "None";
		}
	}
	else
	{
		document.getElementById('newUserNameEmptyLbl').style.display = "Inline";
		return false;
	}
	
	var Password = document.getElementById(controlName+"txtPassword_new").value;
	var strPassword = new String(Password);
	
	if(strPassword.length <  4 || strPassword.length>35)
	{
		document.getElementById('newUserInvalidPwdFormLbl').style.display = "Inline";
		return false;
	}
	else
	{
		document.getElementById('newUserInvalidPwdFormLbl').style.display = "None";
	}		
	
	var ConfirmPassword		= document.getElementById(controlName+"txtPassword2_new").value;
	if(Password != ConfirmPassword)
	{
		document.getElementById('newUserPwdNotMatched').style.display = "Inline";
		return false;
	}
	else
	{
		document.getElementById('newUserPwdNotMatched').style.display = "None";
	}
	
	__doPostBack('newLogin$btnNewUserLogin','');
}
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+2))
	result = true;
  }
  return result;
}
function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return false
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	// the address must end in a two letter or three letter word.
	return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

var submitFlag=true;		

var CitySelectedFromList = false;

function trim(s) 
{ 
	s = s.replace( /^\s*/, "" );  
	return s.replace( /\s*$/, "" );  
}

function doNothing()
	{
		return;
	}
	
function isNum(argvalue) {
	argvalue = argvalue.toString();

	if (argvalue.length == 0)
	return false;

	for (var n = 0; n < argvalue.length; n++)
	if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
	return false;

	return true;
}

function ValidCreditCardNumber(sender, args)
{
	var result = false;
	//var FormName=document.forms[0].name;	
	var cardNum=document.getElementById('ctlCardInfo_txtCCNum').value;
	
	if(cardNum=="")
	{
		args.IsValid=true;
		return;
	}
	
	if(!isNum(cardNum))
	{
		args.IsValid=false;
		return;
	}
	
	cardType=document.getElementById('ctlCardInfo_selCCType').value;
	cardType = cardType.toUpperCase();
	
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);

	switch (cardType)
	{
		case "VI":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "MC":
		case "CA":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "DS":
			result = (cardLen == 16) && (first4digs == "6011");
			break;
		case "DC":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "AX":
			var validNums = "068";
			result = (firstdig == 3) && ((seconddig==4) || (seconddig==7));
			break;
	}
	if(result)
	{
		args.IsValid=true;
	}
	else
	{
		args.IsValid=false;
	}
}

function ValidCreditCardExpDate(sender, args)
{
	var today = new Date();
	var todayYear=today.getFullYear();
	var todayMonth = today.getMonth()+1;
	
	//var FormName=document.forms[0].name;	
	var cardType=document.getElementById('ctlCardInfo_selCCType').value;
	var expMonth=document.getElementById('ctlCardInfo_selCCExpMonth').value;
	var expYear=document.getElementById('ctlCardInfo_selCCExpYear').value;
	
	if(expYear > todayYear)
	{
		args.IsValid=true;
	}	
	else if((expYear == todayYear) && (expMonth >= todayMonth))
	{
		args.IsValid=true;
	}
	else
	{
		args.IsValid=false;
	}
}


function OpenPriceLine()
{
	var win = window.open('Join.aspx','OTPriceLine');
}

function popupSecureShop(url)
{ 
	SecureShopWindow = window.open(url,'SecureShopWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=500'); 
	window.SecureShopWindow.focus();
}
function popupDebtCard(url)
{
	DebtCardWindow = window.open(url,'DebtCardWindow','width=425,height=150');
	window.DebtCardWindow.focus();
}
function PopUpWindow(url,PopUpWindow) 
{
	PopUpWindow = window.open(url,'HelpWindow','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=800,height=500'); 
	PopUpWindow.focus();
}
function show_print(url){
	ShowPrintWindow = window.open(url,'ShowPrintWindow','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=yes,resizable=1,width=780,height=450,top=50,left=50');
	ShowPrintWindow.focus();
}
function PopUpWindowemail(url,email) 
{
	email = window.open(url,'email','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=300,height=225'); 
	email.focus();
}
function CurrencyConvert(url){
	var CCurl = url + "?Module=WWW&Action=CurrencyConvert";
	window.open(CCurl, "CCwin", "width=306,height=400,resizeable=no,scrollbars=no");
}


function GetInsuranceMessage(checkbox)
{
	if (checkbox.checked == true)
	{
		document.getElementById('ctlInsuranceSummary_divDenyInsurance').style.display = 'none';
		document.getElementById('ctlInsuranceSummary_divAcceptInsurance').style.display = 'inline';
		//alert(document.getElementById('ctlInsuranceSummary_lblTotalInsurance'));
		document.getElementById('ctlInsuranceSummary_lblTotalInsurance').innerHTML = document.getElementById('ctlInsuranceSummary_totalInsurance').value;
		document.getElementById('ctlInsuranceSummary_lblGrandTotal').innerHTML = document.getElementById('ctlInsuranceSummary_grandTotal').value;
		//alert(document.getElementById('ctlInsuranceSummary_totalInsurance').value);
	}
	else
	{
		document.getElementById('ctlInsuranceSummary_divAcceptInsurance').style.display = 'none';
		document.getElementById('ctlInsuranceSummary_divDenyInsurance').style.display = 'inline';
		document.getElementById('ctlInsuranceSummary_lblTotalInsurance').innerHTML = "0.00USD";
		document.getElementById('ctlInsuranceSummary_lblGrandTotal').innerHTML = document.getElementById('ctlInsuranceSummary_totalFare').value;
	}
}


function lostPW(pwURL){
	window.open(pwURL, "pwdWin", "width=400,height=210,resizeable=no,scrollbars=no");
}

// the following 3 functions are for the airport codes
function PopupAirCodesLookup(url,name) { PopUp = window.open(url,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=320,height=350'); window.PopUp.focus(); }

function PopupTaxFeeDetails(url,name)
{
	PopUp = window.open(url,name, 'scrolbars=no,menubar=no,statusbar=no,location=no,width=350,height=350');
}
function PopupRentalRules(url,name)
{
	PopUp = window.open(url,name, 'scrolbars=no,menubar=no,statusbar=no,location=no,width=650,height=500');
}

function PopupRentalRuleDetails(url,name)
{
	PopUp = window.open(url,name, 'scrolbars=no,menubar=no,statusbar=no,location=no,width=625,height=500');
}


  //Switch The Dates On The Car Search Page
  function SwitchCarDates()
  {
	var thisdate_month = document.getElementById('Depart_Month_genericDropDownList').value;
	
	thisdate_month--;
	var thisdate_day = document.getElementById('Depart_Day_genericDropDownList').value;
	var thisdate_year = document.getElementById('Depart_Year').value;
	
	
	var thisdate_obj = new Date(thisdate_year,thisdate_month,(parseInt(thisdate_day)+10));
	
	var nextdate_year = thisdate_obj.getFullYear();
    var nextdate_month = thisdate_obj.getMonth();
    nextdate_month++;
    var nextdate_day = thisdate_obj.getDate();
          
    document.getElementById('Arrive_Day_genericDropDownList').value = nextdate_day;
	document.getElementById('Arrive_Month_genericDropDownList').value = nextdate_month;
	document.getElementById('Arrive_Year').value = nextdate_year;
  }
  
  //Switch The Side Search Control Dates
  function SwitchSideSearchCarDates()
  {
	var thisdate_month = document.getElementById('ctlSideSearch_ctlPickupMonth_genericDropDownList').value;
	
	thisdate_month--;
	var thisdate_day = document.getElementById('ctlSideSearch_ctlPickupDay_genericDropDownList').value;
	var thisdate_year = document.getElementById('ctlSideSearch_hidPickupYear').value;
	
	
	var thisdate_obj = new Date(thisdate_year,thisdate_month,(parseInt(thisdate_day)+10));
	
	var nextdate_year = thisdate_obj.getFullYear();
    var nextdate_month = thisdate_obj.getMonth();
    nextdate_month++;
    var nextdate_day = thisdate_obj.getDate();
          
    document.getElementById('ctlSideSearch_ctlDropOffDay_genericDropDownList').value = nextdate_day;
	document.getElementById('ctlSideSearch_ctlDropOffMonth_genericDropDownList').value = nextdate_month;
	document.getElementById('ctlSideSearch_hidDropOffYear').value = nextdate_year;
  }
  
  