var Status = new Boolean(true)
var SingleFlight =  new Boolean(false)
var goToRow 
var DateValid = 'M/d/y'
var DateValidText = 'mm/dd/yyyy'
//var DateValid = 'd/M/y'
//var DateValidText = 'dd/mm/yyyy'

//var pl = 3
//var pt = new Boolean(true)
//var ptv = new Boolean(false)

var pl = 1
var pt = new Boolean(false)
var ptv = new Boolean(false)

var eMsg = new Array();
eMsg[0]	= 'il numero dei neonati non può essere superiore al numero degli adulti!';
eMsg[1]	= 'Attenzione! La data di rientro non può essere antecedente alla data di partenza.';
eMsg[2]	= 'Please supply a valid Passenger Name.';
eMsg[3]	= 'Please supply a valid date of birth ';
eMsg[4]	= 'Si prega di controllare il nome del passeggero nr. ';
eMsg[5]	= 'Please supply a valid Date of Birth at line ';
eMsg[6]	= 'Si prega di controllare il contatto telefonico.';
eMsg[7]	= 'Please supply a valid Email Address.';
eMsg[8]	= 'Si prega di controllare l\'indirizzo .';
eMsg[9]	= 'Per procedere si prega di accettare le Condizioni Generali di Trasporto';
eMsg[10]= 'Please supply a valid Passport Number at line ';
eMsg[11]= 'Please supply a valid Issue Place at line ';
eMsg[12]= 'Please supply a valid date Expiry Date at line ';
eMsg[13]= 'Please supply a valid date Issue Date at line ';

//SetAutoFocus()

if (document.getElementById('myBooking') != null){
	HideGroup('myBooking','none')
}
if (document.getElementById('webCheckIn') != null){
	HideGroup('webCheckIn','none')
}

if (goToRow != null){
	document.getElementById(goToRow).scrollIntoView(true);
}

if (document.getElementById('CvvForm') != null){
	if (document.getElementById('ctrBooking_ctrPassengerInfosBase_CtlPaymentsBase_CtlPaymentCreditCard') != null){
		ShowCvvCode('ctrBooking_ctrPassengerInfosBase_CtlPaymentsBase_CtlPaymentCreditCard')
	}
	else if (document.getElementById('ctrBooking_ctrBookingSummery_CtrPaymentsBase_CtlPaymentCreditCard') != null){
		ShowCvvCode('ctrBooking_ctrBookingSummery_CtrPaymentsBase_CtlPaymentCreditCard')
	}
}

if (document.getElementById('ctrHome_ctrFlightSearchBase_cmbOrigin')  != null ){
	document.getElementById('ctrHome_ctrFlightSearchBase_cmbOrigin').selectedIndex = getSubCookie('OriginCookie',getCookie('tikAero') + '&');
	Anthem_FireEvent('ctrHome_ctrFlightSearchBase_cmbOrigin','',function(){},null,true,true)
}

if(document.getElementById('ctrHome_ctrFlightAvailabilityBase_ctrFlightSearchBase_tboPromotionCode') != null ){
	ShowHideButton('ctrHome_ctrFlightAvailabilityBase_ctrFlightSearchBase');
}

if (document.getElementById('ctrHome_ctrFlightSearchBase_rdoOneway') != null ) {
	if (document.getElementById('ctrHome_ctrFlightSearchBase_rdoOneway').checked == true) {
		HideGroup('FlightSearch','none')
	}
}

if (document.getElementById('ctrHome_ctrFlightSearchLeft_rdoOneway') != null ) {
	if (document.getElementById('ctrHome_ctrFlightSearchLeft_rdoOneway').checked == true) {
		HideGroup('FlightSearchHome','none')
	}
}

//if (CcPreselect.length > 0){
//	ShowCvvCode(CcPreselect)
//}

function HideGroup(Name,Action){
	var NN4 = document.layers? true : false;
	var IE4 = document.all? true : false;
	var FF 	= document.getElementById? true : false;
	if (IE4){
		if(navigator.appName == 'Opera') IE4 = false;
	}
	if(Action == 'none') {
		if (Name == 'FlightSearch') SingleFlight = true;
		if (IE4) {
			document.all[Name].style.visibility = "hidden";
			if (Name == 'FlightSearch') document.all['LowestOut'].style.visibility = "hidden";
		} else if(NN4) {
			document.layers[Name].visibility = "hidden";
			if (Name == 'FlightSearch') document.layers['LowestOut'].visibility = "hidden";
		} else if(FF) {
			document.getElementById(Name).style.display = "none";
//			document.getElementById(Name).style.visibility = "hidden";
			if (Name == 'FlightSearch') document.getElementById('LowestOut').style.visibility = "hidden";
		} else {
			alert('Unknown browser category.');
		}
	} else {
		if (Name == 'FlightSearch') SingleFlight = false;
		if (IE4) {
			document.all[Name].style.visibility = "visible";
			if (Name == 'FlightSearch') document.all['LowestOut'].style.visibility = "visible";
		} else if(NN4) {
			document.layers[Name].visibility = "show";
			if (Name == 'FlightSearch') document.layers['LowestOut'].visibility = "show";
		} else if(FF) {
			document.getElementById(Name).style.display = "";
//			document.getElementById(Name).style.visibility = "visible";
			if (Name == 'FlightSearch') document.getElementById('LowestOut').style.visibility = "visible";
		} else {
			alert('Unknown browser category.');
		}
	}
/*	
	var col = document.getElementsByName(Name)
	for (var i=0;i <= col.length - 1;i++){
		col[i].style.visibility = (Action == 'none') ? 'hidden' : 'visible';
		SingleFlight = (Action == 'none') ? true : false;
	}
*/
}

function CheckAdultInfant(o){
	var iA = document.getElementById(o + '_cmbAdult').options[document.getElementById(o + '_cmbAdult').selectedIndex].value
	var iI = document.getElementById(o + '_cmbInfant').options[document.getElementById(o + '_cmbInfant').selectedIndex].value
	if (iA<iI){
		alert('il numero dei neonati non può essere superiore al numero degli adulti!')
		document.getElementById(o + '_cmbInfant').selectedIndex = 0
	}
}

function ValidSDate(o){
	Status =  true;
	if (SingleFlight == false) {
		if (LibDaysDiff(GetCalenderDate(o + '_ctlReturnDate'),GetCalenderDate(o + '_ctlDepatureDate')) < 0){
			alert('Attenzione! La data di rientro non può essere antecedente alla data di partenza.')
			Status =  false;
		}
	}
}
	
function GetCalenderDate(o){
	var od = document.getElementById(o+'_cmbDay')
	var ot = document.getElementById(o+'_cmbMonthYear')
	var y = ot.options[ot.selectedIndex].value.slice(0,4)
	var m = ot.options[ot.selectedIndex].value.slice(4,6)
	var d = od.options[od.selectedIndex].value 
	return new Date(y,m-1,d,0,0,0)
}

function CopyFirstPassenger(o,m){
	if (document.getElementById(m + '_cboFirstPassenger').checked){
		var i = 1
		var l = trim(document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_LastName').value)
		var f = trim(document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_FirstName').value)
		if (l > 2 || f > 1){
			document.getElementById(m + '_tboNameOnCard').value = strim(document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_FirstName').value) + ' ' +  strim(document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_LastName').value)
		}
		else{
			document.getElementById(m + '_cboFirstPassenger').checked = false
		}	
	}
	else {
		document.getElementById(m + '_tboNameOnCard').value = ''
	}
}

function ValidPassengerGrid(o){
	Status =  true
	var e = ''
	var l = trim(document.getElementById(o + '_LastName').value)
	var f = trim(document.getElementById(o + '_FirstName').value)
	var d = document.getElementById(o + '_DateOfBirth').value
	if (l < 2 || f < 1){
		Status =  false;
		e += 'Please supply a valid Passenger Name ;\r'
	}
	if (trim(d) > 0 && Date.isValid(d,DateValid) == false){
		Status =  false;
		e += 'Please supply a valid date of birth ' + DateValidText + ' \r'	
	}
	if (e.length > 0) {
		alert(e)
	}
}

function CheckPhones(o){
	var pm = document.getElementById(o+'_ctlPassengerContactInfo_phone_mobile')
	var ph = document.getElementById(o+'_ctlPassengerContactInfo_phone_home')
	var pb = document.getElementById(o+'_ctlPassengerContactInfo_phone_business')
	if (goToRow != null){
		var p = trim(pm.value) + trim(ph.value) + trim(pb.value)
			if (p==0){
			pm.className = 'error'
			ph.className = 'error'
			pb.className = 'error'
		}
		else{
			pm.className = ''
			ph.className = ''
			pb.className = ''
		}
	}
}

function IfAlphaOnly(s){
	var i
	if (s.length != 0){
		for (i=0;i < s.length;i++){
			var c = s.charCodeAt(i);
			if (c > 47 && c < 58){
				return false;
			}
			else if (((c > 96 && c < 123) || (c > 64 && c < 91))  == false){
				return false;
			}
		}
		return true
	}
	else{
			return false;
	}
}

function ValidUpdatePayment(o){	
	Status 	= true
	var e 	= ''	
	var noc = document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboNameOnCard');
	var cdn	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboDocumentNumber');
	var cvv	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboCvvCode');
	var ad1	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboStreet');
	var cty	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboCity');
	var pc 	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboZipCode');
	var st 	= document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_tboState');
	var ctr = document.getElementById(o+'_CtrPaymentsBase_CtlPaymentCreditCard_cmbCountryRcd');

	if(document.getElementById('formCC').style.display != 'none'){	
		//--->  Name On Card
		if (trim(noc.value) == 0){
			Status =  false;
			e += "<li>Si prega di controllare l'intestatario della Carta</li>"
			noc.className = 'error';
		}else{
			noc.className = '';
		}
		//--->  Credit Card Number
		if (trim(cdn.value) == 0){
			Status =  false;
			e += "<li>Si prega di controllare il numero della carta di credito</li>"
			cdn.className = 'error';
		}else{
			cdn.className = '';
		}
		//--->  CVV
		if (trim(cvv.value) == 0){
			Status =  false;
			e += "<li>Si prega di controllare il cvv</li>"
			cvv.className = 'error';
		}else{
			cvv.className = '';
		}
		//--->  Address 1
		if (trim(ad1.value) == 0){
			Status =  false;
			e += "<li>Please supply a valid Street 1</li>"
			ad1.className = 'error';
		}else{
			ad1.className = '';
		}
		//--->  Town/City
		if (trim(cty.value) == 0){
			Status =  false;
			e += "<li>Si prega di controllare il comune/città</li>"
			cty.className = 'error';
		}else{
			cty.className = '';
		}
		//--->  Postal Code
		if (trim(pc.value) == 0){
			Status =  false;
			e += "<li>Si prega di controllare il CAP</li>"
			pc.className = 'error';
		}else{
			pc.className = '';
		}
		//--->  County
		//if (trim(st.value) == 0){
		//	Status =  false;
		//	e += "<li>Please supply a valid County</li>"
		//	st.className = 'error';
		//}else{
		//	st.className = '';
		//}
		//--->  Country
		if (trim(ctr.options[ctr.selectedIndex].value)==0){
			Status =  false;
			e += "<li>Si prega di controllare il Paese</li>"
			ctr.className = 'error';
		}else{
			ctr.className = '';
		}
	
		if (e.length > 0) {		
			Container = document.getElementById(o+'_ctlErrorContainer_ErrorContainer');
			Container.innerHTML = 	'<ul>' + e + '</ul>';
		}
		else{
			ContainerBase = document.getElementById('ContainerPayment');
			ContainerBase.style.visibility = 'hidden';
			ContainerPageHeader = document.getElementById('PageHeader');
			ContainerPageHeader.style.visibility = 'hidden';
			CvvForms = document.getElementById('CvvForm');
			CvvForms.style.visibility = 'hidden';
			CvvLabels = document.getElementById('CvvLabel');
			CvvLabels.style.visibility = 'hidden';
			var IssueNumberLabel = document.getElementById('IssueNumberLabel');
			IssueNumberLabel.style.visibility = 'hidden';
			var IssueNumberForm = document.getElementById('IssueNumberForm');
			IssueNumberForm.style.visibility = 'hidden';
			var IssueDateLabel = document.getElementById('IssueDateLabel');
			IssueDateLabel.style.visibility = 'hidden';
			var IssueDateForm = document.getElementById('IssueDateForm');
			IssueDateForm.style.visibility = 'hidden';
			Container = document.getElementById(o+'_ctlErrorContainer_ErrorContainer');
			Container.innerHTML = '';
			Container = document.getElementById('PaymentCommentContainer');
			Container.style.display = 'block';
			var bStepBackPayment = document.getElementById('StepBackPayment');
			var bCancelPayment = document.getElementById('CancelPayment');
			bStepBackPayment.style.display = 'none';
			bCancelPayment.style.display = 'none';
		}
	}
}

function ValidRegistration(o){
	Status =  true
	var e = ''
	var pty	= document.getElementsByName('PaymentTabs_Value').value
	var pm = document.getElementById(o+'_ctlPassengerContactInfo_phone_mobile')
	var ph = document.getElementById(o+'_ctlPassengerContactInfo_phone_home')
	var pb = document.getElementById(o+'_ctlPassengerContactInfo_phone_business')
	var p = trim(pm.value) + trim(ph.value) + trim(pb.value)
	var m = trim(document.getElementById(o+'_ctlPassengerContactInfo_contact_email').value)
		var il = (document.getElementById('PassengerList').rows.length - pl) / 2
	
	for (i=1;i<=il ;i++){
		var ln = document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_Lastname')
		var l = trim(ln.value)
		var fn = document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_Firstname')
		var f = trim(fn.value)
		//var dn = document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_DateOfBirth')
		//var d = dn.value
		if (l < 2 || f < 1){
			Status =  false;
			e += '<li>Si prega di controllare il nome del passeggero nr. ' + (i)+ '</li>'
			ln.className = (l < 2) ? 'error' : '';
			fn.className = (f < 2) ? 'error' : '';
		}
		else if(IfAlphaOnly(ln.value) == false || IfAlphaOnly(fn.value) == false){
			Status =  false;
			e += '<li>Si prega di controllare il nome del passeggero nr. ' + (i)+ '</li>'
			ln.className = (IfAlphaOnly(ln.value)) ? '' : 'error';
			fn.className = (IfAlphaOnly(fn.value)) ? '' : 'error';
		}
		else{
			ln.className = ''
			fn.className = ''
		}
		//if (trim(d) > 0 && Date.isValid(d,DateValid) == false){
		//	Status =  false;
		//	e += '<li>Please supply a valid date of birth at line ' + (i)+ ' ' + DateValidText + '</li>'
		//	dn.className = 'error'
		//}
		//else{
		//	dn.className = ''
		//}
	}
	if (pt == true){
		for (i=1;i<=il ;i++){
			var p0	= document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_passport_number')
			var p0i = trim(p0.value)
			var p1	= document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_passport_issue_place')
			var p1i = trim(p1.value)
			var p2	= document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_passport_expiry_date')
			var	p2v	= p2.value
			var p3	= document.getElementById(o+'_ctlPassengerList_PassengerList__ctl' + i + '_passport_issue_date')
			var	p3v	= p3.value
			if (ptv == true && p0i < 1){
				Status =  false;
				e += '<li>Please supply a valid Passport Number at line ' + (i)+ '</li>'
				p0.className = (p0i < 1) ? 'error' : '';
			}
			else{
				p0.className = ''
			}
			if (ptv == true && p1i < 1){
				Status =  false;
				e += '<li>Please supply a valid Issue Place at line ' + (i)+ '</li>'
				p1.className = (p1i < 1) ? 'error' : '';
			}
			else{
				p1.className = ''
			}
			if ((ptv == true || trim(p2v) > 0) && Date.isValid(p2v,DateValid) == false){
				Status =  false;
				e += '<li>' + eMsg[12] + (i -1)+ ' ' + DateValidText + '</li>'
				p2.className = 'error'
			}
			else{
				p2.className = ''
			}
			if ((ptv == true || trim(p3v) > 0) && Date.isValid(p3v,DateValid) == false){
				Status =  false;
				e += '<li>' + eMsg[13] + (i -1)+ ' ' + DateValidText + '</li>'
				p3.className = 'error'
			}
			else{
				p3.className = ''
			}
		}
	}
	if (p==0){
		Status =  false;
		e += "<li>Si prega di controllare il contatto telefonico;</li>"
		pm.className = 'error'
		ph.className = 'error'
		pb.className = 'error'
	}
	else{
		pm.className = ''
		ph.className = ''
		pb.className = ''
	}
	if (m==0){
		Status =  false;
		e += "<li>Please supply a valid email address.</li>"
		document.getElementById(o+'_ctlPassengerContactInfo_contact_email').className = 'error'
	}
	else{
		document.getElementById(o+'_ctlPassengerContactInfo_contact_email').className = ''
	}
//	if (CcValidation.length > 0 && pty == 'CC') {
//		var CcStatus =  true;
//		var st = document.getElementById(CcValidation + '_tboStreet')
//		var cy = document.getElementById(CcValidation + '_tboCity')
//		var sa = document.getElementById(CcValidation + '_tboState')
//		var zi = document.getElementById(CcValidation + '_tboZipCode')
//		if (trim(st.value) == 0){
//			CcStatus =  false;
//			st.className = 'error'
//		}
//		else{
//			st.className = ''
//		}
//		if (trim(cy.value) == 0){
//			CcStatus =  false;
//			cy.className = 'error'	
//		}
//		else{
//			cy.className = ''		
//		}
//		if (trim(sa.value) == 0){
//			CcStatus =  false;
//			sa.className = 'error'
//		}
//		else{
//			sa.className = ''	
//		}
//		if (trim(zi.value) == 0){
//			CcStatus =  false;
//			zi.className = 'error'
//		}
//		else{
//			zi.className = ''	
//		}
//		if (!CcStatus){
//			Status =  false;
//			e += "<li>Si prega di controllare l'indirizzo </li>"
//		}
//	}	
	if (document.getElementById(o+'_cboConfirm').checked == false){
		Status =  false;
		e += "<li>Please accept terms and Conditions</li>"
	}
	if (e.length > 0) {
		Container = document.getElementById(o+'_ctlErrorContainer_ErrorContainer')
		Container.innerHTML = 	'<ul>' + e + '</ul>'
	}
	else{
		Container = document.getElementById(o+'_ctlErrorContainer_ErrorContainer')
		Container.innerHTML = 	''
		Container = document.getElementById('PaymentCommentContainer')
		var b = document.getElementById(o+'_btmSubmitBooking')
		b.style.visibility = 'hidden'
		Container.style.display = 'block'
	}
}

function trim(s)
{

	return s.replace(/^\s*|\s*$/g,"").length;
}	

function strim(s)
{
	return s.replace(/^\s*|\s*$/g,"");
}	

function OnSubmit(){
	if (Status){
		return true;
	}
	else
	{
		Status = true
		return false;
	}

}

function GetSelectFlight(s,j){
	var o = document.getElementById(s)
	for (i=1;i<=o.rows.length-1;i++){
		if (o.rows(i).cells(o.rows(i).cells.length-1).children(0).type == 'radio'){
			if (o.rows(i).cells(o.rows(i).cells.length-1).children(0).checked){
				var s = o.rows(i).cells(o.rows(i).cells.length-1).children(1).name.split('|');
				var d = s[j].split(',')
				//	d[0] is Year (value is yyyy)
				//	d[1] is Month (value is 0-11) ** That's why must be minus 1
				//	d[2] is Day (value is 1-31)
				return new Date(d[0],d[1]-1,d[2],d[3],d[4],0)
			}else{
				//return "";
			}
		}else{
			//return "";
		}
	}
}

function LibDaysDiff(d1,d2) {
	var z = Date.UTC(Liby2k(d1.getYear()),d1.getMonth(),d1.getDate(),d1.getHours(),d1.getMinutes(),0) - Date.UTC(Liby2k(d2.getYear()),d2.getMonth(),d2.getDate(),d2.getHours(),d2.getMinutes(),0);
	return z/1000/60/60/24;
}
function Liby2k(number) { return (number < 1000) ? number + 1900 : number; }
if (document.getElementById('ctrHome_ctrFlightSearchBase_ctlDepatureDate_cmbDay')!=null) {
	ChangeCalender('ctrHome_ctrFlightSearchBase_ctlDepatureDate')
	ChangeCalender('ctrHome_ctrFlightSearchBase_ctlReturnDate')
}

function SetAutoFocus(){

	if (document.getElementById(AutoFocus) != null){
		document.getElementById(AutoFocus).focus();
	}
}

function isCreditCard(st) {
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

}

function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}

function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

}

function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

}

function isDinersClub(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 14) && (firstdig == 3) &&
      ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
    return isCreditCard(cc);
  return false;
}

function isCarteBlanche(cc)
{
  return isDinersClub(cc);
}

function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} 

function isEnRoute(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 15) &&
      ((first4digs == "2014") ||
       (first4digs == "2149")))
    return isCreditCard(cc);
  return false;
}

function isJCB(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) &&
      ((first4digs == "3088") ||
       (first4digs == "3096") ||
       (first4digs == "3112") ||
       (first4digs == "3158") ||
       (first4digs == "3337") ||
       (first4digs == "3528")))
    return isCreditCard(cc);
  return false;

} 

function isAnyCard(cc)
{
  if (!isCreditCard(cc))
    return false;
  if (!isMasterCard(cc) && !isVisa(cc) && !isAmericanExpress(cc) && !isDinersClub(cc) &&
      !isDiscover(cc) && !isEnRoute(cc) && !isJCB(cc)) {
    return false;
  }
  return true;

} 
function isCardMatch (cardType, cardNumber)
{
	cardType = cardType.toUpperCase();
	var doesMatch = true;

	if ((cardType == "VISA") && (!isVisa(cardNumber)))
		doesMatch = false;
	if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
		doesMatch = false;
	if ( ( (cardType == "AMERICANEXPRESS") || (cardType == "AMEX") )
                && (!isAmericanExpress(cardNumber))) doesMatch = false;
	if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
		doesMatch = false;
	if ((cardType == "JCB") && (!isJCB(cardNumber)))
		doesMatch = false;
	if ((cardType == "DINERS") && (!isDinersClub(cardNumber)))
		doesMatch = false;
	if ((cardType == "CARTEBLANCHE") && (!isCarteBlanche(cardNumber)))
		doesMatch = false;
	if ((cardType == "ENROUTE") && (!isEnRoute(cardNumber)))
		doesMatch = false;
	return doesMatch;
} 

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function getSubCookie(name,parent) {
  var dc = parent;
  var prefix = name + "=";
  var begin = dc.indexOf("&" + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 1;
  var end = parent.indexOf("&", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function CreatePopup(l,p){
	if (p == 'f'){
		CreateWnd('html/FareCode/' + l + '.html', 300, 400, false);
		dgItemLock = true
	}
}

function GetCardSubType(CcNumber){
	var l = new Number(CcNumber.slice(0,6))
	var iA = document.getElementById(CcPreselect + '_cbmFormOfPaymentSubtype').options[document.getElementById(CcPreselect + '_cbmFormOfPaymentSubtype').selectedIndex].value.split('|')
	SelectedCardType = iA[0]
	if 	(
			(l >= 413733 && l <= 413737 ) || 
			(l >= 446200 && l <= 446299 ) || 
			(l >= 453978 && l <= 453979) || 
			(l == 454313 ) ||
			(l >= 454432 && l <= 446299 ) || 
			(l == 454742) ||
			(l >= 456725 && l <= 456745 ) || 
			(l >= 465830 && l <= 465879 ) ||
			(l >= 465901 && l <= 465950 ) ||
			(l >= 475110 && l <= 475159 ) ||
			(l >= 475710 && l <= 475759 ) ||
			(l >= 476220 && l <= 476269 ) ||
			(l >= 476340 && l <= 476389 ) ||
			(l >= 484409 && l <= 484410 ) ||
			(l >= 490960 && l <= 490979 ) ||
			(l >= 492181 && l <= 492182 ) ||
			(l == 498824)
		)
	{
		CardType = "VISADRUK"
	}
	else if
		(
			(l  == 424519) ||
			(l >= 424962 && l <= 424963 ) ||
			(l == 450875) ||
			(l >= 484406 && l <= 484408 ) ||
			(l >= 484411 && l <= 484455 ) ||
			(l >= 491730 && l <= 491759 ) ||
			(l == 491880)
		)
	{
		CardType = "VISAELUK"
	}
	else if
		(
			(l >= 448400 && l <= 448699 ) ||
			(l >= 471500 && l <= 471599 )
		)
	{
		CardType = "VISAPU"
	}
	else if
		(
			(l == 490303) ||
			(l == 493698) ||
			(l == 633311) ||
			(l >= 675900 && l <= 675999)
		)
	{
		CardType = "MAESTROUK"
	}
	else if
		(
			(l >= 510000 && l <= 559999)
		)
	{
		CardType = "MC"
	}
	else if
		(
			(l >= 676700 && l <= 676799)
		)
	{
		CardType = "SOLO"
	}
	else if
		(
			(l >= 6180000 && l <= 180099) ||
			(l >= 6213100 && l <= 213199)
		)
	{
		CardType = "JCB"
	}
	else if
		(
			(l >= 352800 && l <= 358999)
		)
	{
		if (SelectedCardType == "DC"){
			CardType = "DC"}
		else if (SelectedCardType == "AMEX"){
			CardType = "AMEX"}
		else{
			CardType = "JCB"
		}
	}
	else if
		(
			(l >= 300000 && l <= 369999)
		)
	{
		if (SelectedCardType == "AMEX"){
			CardType =  "AMEX"}
		else{
			CardType = "DC"
		}
	}
	else if
		(
			(l >= 340000 && l <= 379999)
		)
	{
		if (SelectedCardType == "AMEX"){
			CardType =  "AMEX"}
		else{
			CardType = "JCB"
		}
	}
	else if
		(
			(l >= 300000 && l <= 399999)
		)
	{
		CardType =  "JCB"
	}
	else if
		(
			(l >= 500000 && l <= 509999) ||
			(l >= 560000 && l <= 589999) ||
			(l >= 600000 && l <= 699999)
		)
	{
		CardType = "MAESTRO"
	}
	else if
		(
			(l >= 400000 && l <= 499999) 
		)
	{
		CardType = "VISA"
	}
	else
	{
		CardType = ""
	}
	
	var FeeAmmount = new Number(0)
	for (i=0;i < FeesRcd.length ;i++){
		if (CardType.toUpperCase() == FeesRcd[i].toUpperCase()){
			FeeAmmount = FeesAmmount[i]
		}
	}
	if (CardType != "" && FeeAmmount > 0){
		var Total = (CcTotalValue + FeeAmmount)
		document.getElementById('CcMessage').innerHTML = 'Your credit card will be charged with ' + FeeAmmount.toFixed(2) + ' ' + CcCurrency + ' Service ' + Total.toFixed(2) + ' ' + CcCurrency
	}
	else
	{
		document.getElementById('CcMessage').innerHTML = ''
	}
	return CardType
}


Date.$VERSION = 1.01;
Date.LZ = function(x){return(x<0||x>9?"":"0")+x};Date.monthNames = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');Date.monthAbbreviations = new Array('Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic');Date.dayNames = new Array('Dom','Lun','Mar','Mer','Gio','Ven','Sab');Date.dayAbbreviations = new Array('Dom','Lun','Mar','Mer','Gio','Ven','Sab');Date.preferAmericanFormat = true;if(!Date.prototype.getFullYear){Date.prototype.getFullYear = function(){var yy=this.getYear();return(yy<1900?yy+1900:yy);}}
Date.parseString = function(val, format){if(typeof(format)=="undefined" || format==null || format==""){var generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','MMM-d','d-MMM');var monthFirst=new Array('M/d/y','M-d-y','M.d.y','M/d','M-d');var dateFirst =new Array('d/M/y','d-M-y','d.M.y','d/M','d-M');var checkList=new Array(generalFormats,Date.preferAmericanFormat?monthFirst:dateFirst,Date.preferAmericanFormat?dateFirst:monthFirst);for(var i=0;i<checkList.length;i++){var l=checkList[i];for(var j=0;j<l.length;j++){var d=Date.parseString(val,l[j]);if(d!=null){return d;}}}return null;}
this.isInteger = function(val){for(var i=0;i < val.length;i++){if("1234567890".indexOf(val.charAt(i))==-1){return false;}}return true;};
this.getInt = function(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length < minlength){return null;}if(this.isInteger(token)){return token;}}return null;};val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var year=new Date().getFullYear();var month=1;var date=1;var hh=0;var mm=0;var ss=0;var ampm="";while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(token=="yyyy" || token=="yy" || token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=this.getInt(val,i_val,x,y);if(year==null){return null;}i_val += year.length;if(year.length==2){if(year > 70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM" || token=="NNN"){month=0;var names =(token=="MMM"?(Date.monthNames.concat(Date.monthAbbreviations)):Date.monthAbbreviations);for(var i=0;i<names.length;i++){var month_name=names[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){month=(i%12)+1;i_val += month_name.length;break;}}if((month < 1)||(month>12)){return null;}}else if(token=="EE"||token=="E"){var names =(token=="EE"?Date.dayNames:Date.dayAbbreviations);for(var i=0;i<names.length;i++){var day_name=names[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val += day_name.length;break;}}}else if(token=="MM"||token=="M"){month=this.getInt(val,i_val,token.length,2);if(month==null||(month<1)||(month>12)){return null;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=this.getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return null;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return null;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23)){return null;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return null;}i_val+=hh.length;hh++;}else if(token=="kk"||token=="k"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return null;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=this.getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return null;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=this.getInt(val,i_val,token.length,2);if(ss==null||(ss<0)||(ss>59)){return null;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return null;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return null;}else{i_val+=token.length;}}}if(i_val != val.length){return null;}if(month==2){if( ((year%4==0)&&(year%100 != 0) ) ||(year%400==0) ){if(date > 29){return null;}}else{if(date > 28){return null;}}}if((month==4)||(month==6)||(month==9)||(month==11)){if(date > 30){return null;}}if(hh<12 && ampm=="PM"){hh=hh-0+12;}else if(hh>11 && ampm=="AM"){hh-=12;}return new Date(year,month-1,date,hh,mm,ss);}
Date.isValid = function(val,format){return(Date.parseString(val,format) != null);}
Date.prototype.isBefore = function(date2){if(date2==null){return false;}return(this.getTime()<date2.getTime());}
Date.prototype.isAfter = function(date2){if(date2==null){return false;}return(this.getTime()>date2.getTime());}
Date.prototype.equals = function(date2){if(date2==null){return false;}return(this.getTime()==date2.getTime());}
Date.prototype.equalsIgnoreTime = function(date2){if(date2==null){return false;}var d1 = new Date(this.getTime()).clearTime();var d2 = new Date(date2.getTime()).clearTime();return(d1.getTime()==d2.getTime());}
Date.prototype.format = function(format){format=format+"";var result="";var i_format=0;var c="";var token="";var y=this.getYear()+"";var M=this.getMonth()+1;var d=this.getDate();var E=this.getDay();var H=this.getHours();var m=this.getMinutes();var s=this.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length < 4){y=""+(+y+1900);}value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=Date.LZ(M);value["MMM"]=Date.monthNames[M-1];value["NNN"]=Date.monthAbbreviations[M-1];value["d"]=d;value["dd"]=Date.LZ(d);value["E"]=Date.dayAbbreviations[E];value["EE"]=Date.dayNames[E];value["H"]=H;value["HH"]=Date.LZ(H);if(H==0){value["h"]=12;}else if(H>12){value["h"]=H-12;}else{value["h"]=H;}value["hh"]=Date.LZ(value["h"]);value["K"]=value["h"]-1;value["k"]=value["H"]+1;value["KK"]=Date.LZ(value["K"]);value["kk"]=Date.LZ(value["k"]);if(H > 11){value["a"]="PM";}else{value["a"]="AM";}value["m"]=m;value["mm"]=Date.LZ(m);value["s"]=s;value["ss"]=Date.LZ(s);while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(value[token] != null){result=result + value[token];}else{result=result + token;}}return result;}
Date.prototype.getDayName = function(){return Date.dayNames[this.getDay()];}
Date.prototype.getDayAbbreviation = function(){return Date.dayAbbreviations[this.getDay()];}
Date.prototype.getMonthName = function(){return Date.monthNames[this.getMonth()];}
Date.prototype.getMonthAbbreviation = function(){return Date.monthAbbreviations[this.getMonth()];}
Date.prototype.clearTime = function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);
return this;}
Date.prototype.add = function(interval, number){if(typeof(interval)=="undefined" || interval==null || typeof(number)=="undefined" || number==null){
return this;}number = +number;if(interval=='y'){this.setFullYear(this.getFullYear()+number);}else if(interval=='M'){this.setMonth(this.getMonth()+number);}else if(interval=='d'){this.setDate(this.getDate()+number);}else if(interval=='w'){var step =(number>0)?1:-1;while(number!=0){this.add('d',step);while(this.getDay()==0 || this.getDay()==6){this.add('d',step);}number -= step;}}else if(interval=='h'){this.setHours(this.getHours() + number);}else if(interval=='m'){this.setMinutes(this.getMinutes() + number);}else if(interval=='s'){this.setSeconds(this.getSeconds() + number);}
return this;}

function ChangeCalenderMonth(o,r,ix){
	ChangeCalender(o,r,ix)
	//RefreshPopup()
}

	
function ShowHideButton(o){
	if(document.getElementById(o + '_btmSearchf') != null ){												
		if(document.getElementById(o + '_tboPromotionCode').value == "" ){
			document.getElementById(o + '_btmSearchf').style.visibility = "";
		}
		else{
			document.getElementById(o + '_btmSearchf').style.visibility = "hidden";
		}
	}
	if(document.getElementById(o + '_btmSearchlf') != null ){
		if(document.getElementById(o + '_tboPromotionCode').value == "" ){
			document.getElementById(o + '_btmSearchlf').style.visibility = "";
		}
		else{
			document.getElementById(o + '_btmSearchlf').style.visibility = "hidden";
		}
	}	
/*	if(document.getElementById('OnewayPart') != null){		
		if(document.getElementById(o + '_tboPromotionCode').value == "" ){			
			document.getElementById('OnewayPart').style.visibility = "";
		}
		else{
			document.getElementById(o + '_rdoReturn').checked = "checked";
			HideGroup('FlightSearch','block');
			document.getElementById('OnewayPart').style.visibility = "hidden";
		}		
	}*/
}
 
function DisableEnter(){
	if (event.keyCode == 13) event.returnValue = false;
}

function ConfirmCancelFlight_Refund(){
	return confirm('Are you sure you want to cancel this flight? Your booking will be cancelled and your credit card refunded.');
}
function ConfirmCancelFlight_NoneRefund(){
	return confirm('Are you sure you want to cancel this flight?');
}