
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//General function for hiding control, pass the Server Control ID
function VisDisp(objID,n)
{obj=MM_findObj(objID); 
switch(n){
case 0:obj.style.visibility='visible';break;
case 1:obj.style.visibility='hidden';break;
case 2:obj.style.display='block';break;
case 3:obj.style.display='none';break;
case 4:obj.style.visibility='visible';obj.style.display='block';break;
case 5:obj.style.visibility='hidden';obj.style.display='none';break;
}}
function showPopupMessage()
{		
MM_findObj("wrapper").style.visibility = 'hidden';		
MM_findObj("wrapper").style.display = 'none';		
MM_findObj("PLayer").style.visibility = 'visible';
MM_findObj("PLayer").style.display = 'block';				
}
//if dt1 is greater than dt2 then this function will return false
//format for parameters is dd-MMM-yy
function CompareDate(dt1,dt2)
{
var m1= dt1.substr(3,3);
var m2= dt2.substr(3,3);
for(var i=0;i<12;i++)
{	if(m1 == monthArrayShort[i])m1=i;
if(m2 == monthArrayShort[i])m2=i;}
var cdt1=new Date(20+dt1.substr(7,2),m1,dt1.substr(0,2));
var cdt2=new Date(20+dt2.substr(7,2),m2,dt2.substr(0,2));
if (cdt1>cdt2)
return false;
else return true;
}
function Trim(s) 
{
// Remove leading spaces and carriage returns
while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
{ 
s = s.substring(1,s.length); 
}     
// Remove trailing spaces and carriage returns
while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
{ 
s = s.substring(0,s.length-1); 
}     
return s;
}
function isValidFF(parm,crcode)
{
var fb=true;
var s1=parm.substr(0,2);
if (crcode=='CO')
{
fb=isValid(s1,upr+lwr);
if (fb==true) 
{
s1=parm.substr(2);
fb=isValid(s1,numb);
}
}
else
{
fb=isValid(parm,numb);
}
return fb;
}
var numb = '0123456789';
var floatNumb = '0123456789.';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var space = ' ';
var splChar1 = '_-@.';
var splChar2 = '-/#&()[]';
function isValid(parm,val) 
{
if (parm == "") return true;
for (j=0; j<parm.length; j++) 
{
if (val.indexOf(parm.charAt(j),0) == -1) return false;
}
return true;
}
function isLower(parm){return isValid(parm,lwr);}
function isUpper(parm){return isValid(parm,upr);}
//Appendix 6.1.1
function isAlphaSpace(parm){return isValid(parm,lwr+upr+space);}
//Appendix 6.1.2
function isAlpha(parm){return isValid(parm,lwr+upr);}
//Appendix 6.1.3
function isNum(parm){return isValid(parm,numb);}
//added for currency
function isFloat(parm){return isValid(parm,floatNumb);}
//Appendix 6.1.5
function isAlphanumSpace(parm){return isValid(parm,lwr+upr+numb+space);}
//Appendix 6.1.6
function isAlphanum(parm){return isValid(parm,lwr+upr+numb);}
//Appendix 6.1.7
function isAlphanumSP1(parm){return isValid(parm,lwr+upr+numb+splChar1);}
//Appendix 6.1.8
function isAlphaSP1(parm){return isValid(parm,lwr+upr+splChar1);}
//Appendix 6.1.9
function isAlphanumSP2(parm){return isValid(parm,lwr+upr+numb+splChar2+space);}
//Change first latter to Caps
function changeFirstLetterToCaps(obj) {
var vParam = obj.value;
obj.value = vParam.substr(0,1).toUpperCase() + vParam.substr(1);
}
function isValidCreditCard(type, ccnum)  // Modified as per 13 digit Visa card No
{
// Array to hold the permitted card characteristics
var cards = new Array();

// Define the cards we support. You may add addtional card types.

//  Name:      As in the selection box of the form - must be same as user's
//  Length:    List of possible valid lengths of the card number for the card
//  prefixes:  List of possible prefixes for the card
//  checkdigit Boolean to say whether there is a check digit

cards [0] = {name: "VISA", 
length: "13,16", 
prefixes: "4",
checkdigit: true};
cards [1] = {name: "MAST", 
length: "16", 
prefixes: "51,52,53,54,55",
checkdigit: true};
cards [2] = {name: "DINERS", 
length: "14,16", 
prefixes: "300,301,302,303,304,305,36,38,55",
checkdigit: true};
cards [3] = {name: "CarteBlanche", 
length: "14", 
prefixes: "300,301,302,303,304,305,36,38",
checkdigit: true};
cards [4] = {name: "AMEX", 
length: "15", 
prefixes: "34,37",
checkdigit: true};
cards [5] = {name: "Disc", 
length: "16", 
prefixes: "6011,650",
checkdigit: true};
cards [6] = {name: "JCB", 
length: "15,16", 
prefixes: "3,1800,2131",
checkdigit: true};
cards [7] = {name: "enRoute", 
length: "15", 
prefixes: "2014,2149",
checkdigit: true};
cards [8] = {name: "Solo", 
length: "16,18,19", 
prefixes: "4,5,6,6334,6767",
checkdigit: true};
cards [9] = {name: "Switch", 
length: "16,18,19", 
prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
checkdigit: true};
cards [10] = {name: "Maestro", 
length: "16,18", 
prefixes: "5,6",
checkdigit: true};
cards [11] = {name: "VISAELEC", 
length: "16", 
prefixes: "4",
checkdigit: true};
cards [12] = {name: "CarteBleue", 
length: "16", 
prefixes: "581784,6,4,5",
checkdigit: true};  
cards [13] = {name: "CarteBleueVisa", 
length: "16", 
prefixes: "581784,6,4,5",
checkdigit: true};  

// Establish card type
var cardType = -1;
for (var i=0; i<cards.length; i++) {

// See if it is this card (ignoring the case of the string)
//if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
if (type.toLowerCase () == cards[i].name.toLowerCase()) {    
cardType = i;
break;
}
}

// If card type not found, report an error
if (cardType == -1) {
ccErrorNo = 0;
return false; 
}

// Ensure that the user has provided a credit card number
if (ccnum.length == 0)  {
ccErrorNo = 1;
return false; 
}

// Now remove any spaces from the credit card number
cardnumber = ccnum.replace (/\s/g, "");

// Check that the number is numeric
var cardNo = cardnumber
var cardexp = /^[0-9]{13,19}$/;
if (!cardexp.exec(cardNo))  {
ccErrorNo = 2;
return false; 
}

// Now check the modulus 10 check digit - if required
if (cards[cardType].checkdigit) {
var checksum = 0;                                  // running checksum total
var mychar = "";                                   // next char to process
var j = 1;                                         // takes value of 1 or 2

// Process each digit one by one starting at the right
var calc;
for (i = cardNo.length - 1; i >= 0; i--) {

// Extract the next digit and multiply by 1 or 2 on alternative digits.
calc = Number(cardNo.charAt(i)) * j;

// If the result is in two digits add 1 to the checksum total
if (calc > 9) {
checksum = checksum + 1;
calc = calc - 10;
}

// Add the units element to the checksum total
checksum = checksum + calc;

// Switch the value of j
if (j ==1) {j = 2} else {j = 1};
} 

// All done - if checksum is divisible by 10, it is a valid modulus 10.
// If not, report an error.
if (checksum % 10 != 0)  {
ccErrorNo = 3;
return false; 
}
}  

// The following are the card-specific checks we undertake.
var LengthValid = false;
var PrefixValid = false; 
var undefined; 

// We use these for holding the valid lengths and prefixes of a card type
var prefix = new Array ();
var lengths = new Array ();

// Load an array with the valid prefixes for this card
prefix = cards[cardType].prefixes.split(",");

// Now see if any of them match what we have in the card number
for (i=0; i<prefix.length; i++) {
var exp = new RegExp ("^" + prefix[i]);
if (exp.test (cardNo)) PrefixValid = true;
}

// If it isn't a valid prefix there's no point at looking at the length
if (!PrefixValid) {
ccErrorNo = 3;
return false; 
}

// See if the length is valid for this card
lengths = cards[cardType].length.split(",");
for (j=0; j<lengths.length; j++) {
if (cardNo.length == lengths[j]) LengthValid = true;
}

// See if all is OK by seeing if the length was valid. We only check the 
// length if all else was hunky dory.
if (!LengthValid) {
ccErrorNo = 4;
return false; 
};   

// The credit card is in the required format.
return true;
}
function isValidCreditCardOld(type, ccnum) 
{
//if (type == "Visa") 
if (type == "VISA") 
{
// Visa: length 16, prefix 4, dashes optional.
var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
} 
//else if (type == "MC") 
else if (type == "MAST") 
{
// Mastercard: length 16, prefix 51-55, dashes optional.
var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
} 
else if (type == "Disc")         
{
// Discover: length 16, prefix 6011, dashes optional.
var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
} 
//else if (type == "AmEx") 
else if (type == "AMEX") 
{
// American Express: length 15, prefix 34 or 37.
var re = /^3[4,7]\d{13}$/;
} 
//else if (type == "Diners") 
else if (type == "DINERS")
{
// Diners: length 14, prefix 30, 36, or 38.
var re = /^3[0,6,8]\d{12}$/;
}
if(re)
{
if (!re.test(ccnum)) return false;
}
else
{
return false;
}
// Remove all dashes for the checksum checks to eliminate negative numbers
ccnum = ccnum.split("-").join("");
// Checksum ("Mod 10")
// Add even digits in even length strings or odd digits in odd length strings.
var checksum = 0;
for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) 
{
checksum += parseInt(ccnum.charAt(i-1));
}
// Analyze odd digits in even length strings or even digits in odd length strings.
for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) 
{
var digit = parseInt(ccnum.charAt(i-1)) * 2;
if (digit < 10) 
{ 
checksum += digit; 
} else 
{ 
checksum += (digit-9); 
}
}
if ((checksum % 10) == 0) return true; else return false;
}
function isEmail(string)
{
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!= -1)
return true;
else
return false;
}
function GoToIbeHome()
{   
window.location = "../IBE.aspx";
return false;
}
function openWindow(optionId,curr,amt)
{       
if (optionId == -1)
{
mywindow = window.open("./CurrencyConverter.aspx?curr="+curr+"&amt="+amt, "CurrencyConverter", "top=100,left=200,title=0,location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=755,height=500");
}    
else
{        
mywindow = window.open("./FareBreakUp.aspx?oid="+optionId, "FareBreakUp", "top=100,left=200, title=0,location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=755,height=420");
}    
//mywindow.moveTo(225,100);    

return false;
}


// SSL Layer
function openCurrSSL(curr,amt)
{   
mywindow = window.open("../IBE/CurrencyConverter.aspx?curr="+curr+"&amt="+amt, "CurrencyConverter", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=755,height=500");
return false;
}
function openFareCondn(oid,sb,ItinDel, APId, RNo,CU)
{ 
//mywindow = window.open("./FareCondition.aspx?rb="+ItinDel+"&aId="+APId+"&rNo="+RNo+"&cu="+CU, "Fare_Condition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
mywindow = window.open("./FareCondition.aspx?oid="+oid+"&sb="+sb+"&rb="+ItinDel+"&aId="+APId+"&rNo="+RNo+"&cu="+CU, "Fare_Condition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openFareCondnSSL(oid,sb,ItinDel, APId, RNo,CU)
{ 
mywindow = window.open("../IBE/FareCondition.aspx?oid="+oid+"&sb="+sb+"&rb="+ItinDel+"&aId="+APId+"&rNo="+RNo+"&cu="+CU, "Fare", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openFareCondnPDFSSL(objP, objSession)
{ 
mywindow = window.open("../IBE/FareConditionPDF.aspx?RequestSessionID=" + objSession + "&o=" + objP , "Fare_Condition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openFareCondnPDF(objP, objSession)
{ 

mywindow = window.open("./FareConditionPDF.aspx?RequestSessionID=" + objSession + "&o=" + objP , "Fare", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openFareRuleSSL()
{ 
mywindow = window.open("../IBE/FareRuleRedeem.aspx", "Fare_Condition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}

// End SSL Layer
function openEarnMiles(resultBy,optionId,ItinDel)
{     
mywindow = window.open("./EarnMiles.aspx?rb="+resultBy+"&id="+optionId+"&itn="+ItinDel, "EM", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=450");
return false;
}
function openFareRuleRedeem()
{ 
mywindow = window.open("./FareRuleRedeem.aspx", "Fare_Redeem", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openFlightInfo(airLegId,flightType,FlightNo)
{ 
mywindow = window.open("/IBE/FlightInfo.aspx?al="+airLegId+"&ft="+flightType+"&fn="+FlightNo, "Flight_Info", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=700,height=200");
return false;
}
function fnDefault()
{
return false;
}
function IsCouNumber(parm)
{
var fb=false;
var s1=parm.substr(0,1);
if (s1=="+" || isNum(s1))
{
s1=parm.substr(1);
fb=isNum(s1);
}   
return fb; 
}
function promoCondn()
{
mywindow = window.open("../IBE/PromotionalCondn.aspx", "Promotional_Condn", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");   
return false;
}

function OpenSSlashwindow(FlightNo,FlightDate,Host,DeptCode,ArrCode)
{    
window.open("/MYB/MYBFlightDetails.aspx?fl='" + FlightNo + "'&dt='" + FlightDate + "'&ht='" + Host + "'&dac=" + DeptCode + "&aac=" + ArrCode, "_new", "menubar=0,width=750,height=250,scrollbars=1");
return false;
}

function IsCaValid(ctl,snx)
{        
var txtSN = MM_findObj(snx);        

var errMsg='';  
if(Trim(txtSN.value)=='') { errMsg='Account Number cannot be blank';}
var chkRA = MM_findObj(ctl);
if(chkRA.checked==false)
{        
if( errMsg=='') { errMsg='Please Check the Read Agreement';}
else { errMsg = errMsg + '\n' + 'Please Check the Read Agreement'; }
}
if(errMsg!='') { alert(errMsg); return false; }
else { return true; }
}

function openSmeWindow(optionId,curr,amt)
{       
if (optionId == -1)
{
mywindow = window.open("../../IBE/CurrencyConverter.aspx?curr="+curr+"&amt="+amt, "CurrencyConverter", "top=100,left=200,title=0,location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=615,height=500");
}    
else
{        
mywindow = window.open("../../IBE/FareBreakUp.aspx?oid="+optionId, "FareBreakUp", "top=100,left=200, title=0,location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=615,height=570");
}    
//mywindow.moveTo(225,100);    

return false;
}

function openSmeFareCondn(ItinDel, APId, RNo,CU)
{ 
mywindow = window.open("../../IBE/FareCondition.aspx?rb="+ItinDel+"&aId="+APId+"&rNo="+RNo+"&cu="+CU, "Fare_Condition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}

function CheckBRP()
{

if(MM_findObj('ctl00_txtBRP').value=="1")
{    
history.go(1);
}

}
function IsValidDate(d,m,y)
{
var yl=1901; // least year to consider
var ym=9999; // most year to consider
if (!isNum(d)) return(false);
if (!isNum(m)) return(false);
if (!isNum(y)) return(false);
if (m<1 || m>12) return(false);
if (d<1 || d>31) return(false);
if (y<yl || y>ym) return(false);
if (m==4 || m==6 || m==9 || m==11)
if (d==31) return(false);
if (m==2)
{
var b=parseInt(y/4);
if (isNaN(b)) return(false);
if (d>29) return(false);
if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
}             
return(true);
}
function getDateObject(dateString,dateSeperator)
{
//This function return a date object after accepting 
//a date string ans dateseparator as arguments
var curValue=dateString;
var sepChar=dateSeperator;
var curPos=0;
var cDate,cMonth,cYear;

//extract day portion
curPos=dateString.indexOf(sepChar);
cDate=dateString.substring(0,curPos);

//extract month portion				
endPos=dateString.indexOf(sepChar,curPos+1);			
cMonth=dateString.substring(curPos+1,endPos);

//extract year portion				
curPos=endPos;
endPos=curPos+5;			
cYear=curValue.substring(curPos+1,endPos);

//Create Date Object
dtObject=new Date(cYear,cMonth,cDate);	
return dtObject;
}

function isitToday(dateString,dateType) {
/*
function isitToday 
parameters: dateString dateType
returns: boolean

dateString is a date passed as a string in the following
formats:

type 1 : 19970529
type 2 : 970529
type 3 : 29/05/1997
type 4 : 29/05/97

dateType is a numeric integer from 1 to 4, representing
the type of dateString passed, as defined above.

Returns true if the date passed is equal to todays date
Returns false if the date passed is NOT equal to todays
date or if dateType is not 1 to 4.
*/


var now = new Date();
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
if (dateType == 1)
var date = new Date(dateString.substring(0,4),
dateString.substring(4,6)-1,
dateString.substring(6,8));
else if (dateType == 2)
var date = new Date(dateString.substring(0,2),
dateString.substring(2,4)-1,
dateString.substring(4,6));
else if (dateType == 3)

var date = new Date(dateString.substring(6,10),
dateString.substring(3,5)-1,
dateString.substring(0,2));
else if (dateType == 4)
var date = new Date(dateString.substring(6,8),
dateString.substring(3,5)-1,
dateString.substring(0,2));
else
return false;
if (date > today)
return true;
else
return false;
}
//SKYUpgrades Begin
function openMilesBreakdown()
{ 
mywindow = window.open("../MYB/MilesBreakdown.aspx", "MilesBreakdown", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function openUpgradeFareCondition()
{ 
mywindow = window.open("../MYB/UpgradeFareCondition.aspx", "UpgradeFareCondition", "top=100,left=200,title=0,location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=631,height=600");
return false;
}
function shn_check_all(ctrlnm,status) {
var checkItems = document.getElementsByTagName('input');
var val=ctrlnm.checked;
for(var i=0;i<checkItems.length;i++)
{
if(checkItems.item(i).type=="checkbox" && checkItems.item(i).disabled == false)
{ 
if(status==0)
checkItems[i].checked=Boolean(val);
else if(status==1)
checkItems[i].checked=!Boolean(val);
}
}
}
function IsCheckBoxChecked()
{    
var checkItems = document.getElementsByTagName('input');
var val = "";
for(var i=0;i<checkItems.length;i++)
{
if(checkItems.item(i).type=="checkbox")
{
if(checkItems[i].checked == true)
{
val = "1";
return true;
}
else
{
val="0";
}
}
}
if(val == "0")
{
alert('Please select atleast one flight segment to upgrade');
return false;
}
else
{
return true;
}
}
//SKYUpgrades End
