﻿var xHttp;
function customRange(a) {
var b = new Date();
var c = new Date(b.getFullYear(), b.getMonth(), b.getDate());
    if (a.id == 'FRetDateDDMMYY') {
        if ($('#FDptDateDDMMYY').datepicker('getDate') != null) {
            c = $('#FDptDateDDMMYY').datepicker('getDate');
        }}
        return {minDate: c = new Date(c.getFullYear(), c.getMonth(), c.getDate() + 1)}}
function fixdto(a) {
    var b = new Date();
    var c = new Date(b.getFullYear(), b.getMonth(), b.getDate());
    if ($('#FDptDateDDMMYY').datepicker('getDate') != null) {
        c = $('#FDptDateDDMMYY').datepicker('getDate');
    }
    c = new Date(c.getFullYear(), c.getMonth(), c.getDate() + 3);
    $('#FRetDateDDMMYY').datepicker("setDate", new Date(c));
}
function fixdep() {
    var b = new Date(); 
    var c = new Date(b.getFullYear(), b.getMonth(), b.getDate());
    c = new Date(c.getFullYear(), c.getMonth(), c.getDate() + 3);
    $('#FDptDateDDMMYY').datepicker("setDate", new Date(c));
}
function fixret() {
    var b = new Date();
    var c = new Date(b.getFullYear(), b.getMonth(), b.getDate());
        if ($('#FDptDateDDMMYY').datepicker('getDate') != null) {
            c = $('#FDptDateDDMMYY').datepicker('getDate');
        }
    c = new Date(c.getFullYear(), c.getMonth(), c.getDate() + 3);
    $('#FRetDateDDMMYY').datepicker("setDate", new Date(c));
}
function setReturnDate(depdate) {

    var ctrl = document.getElementById("FRetDateDDMMYY");
    if (ctrl != null) {
        ctrl.value = depdate.value;
    }
}
function focusdptdate(ctrl) {
    $("#" + ctrl).focus();
    return false;
}
var str = new String(window.location);
var lPosition = str.indexOf("fpowertest");
var lPosition1 = str.indexOf("SearchEngine");
var nmon1;
nmon1=1;
if(lPosition1>0){nmon1=1}else{nmon1=2}
$(document).ready(function () {
    $('#FDptDateDDMMYY').datepicker({ minDate: -0, maxDate: '+11M', numberOfMonths: nmon1, dateFormat: 'dd-M-yy',changeMonth:true,changeYear:true,  onClose: fixdto });
    
    try {
     if (lPosition > 0) { } else { fixdep(); 
    }
    } catch (e) { };
});

$(document).ready(function () {
    $('#FRetDateDDMMYY').datepicker({ minDate: -0, maxDate: '+11M', numberOfMonths: nmon1, dateFormat: 'dd-M-yy',changeMonth:true,changeYear:true,  beforeShow: customRange });
    try {
      if (lPosition > 0) { } else { fixret();init_fun(); }
    } catch (e) { };
   
});
function init_fun()
{

$(document).ready(function (){classtype(0);$("#FJrnType").val(0);//changeJryhome(0);
if (lPosition > 0) { } else {$("#FDestTo").val("Enter Arrival Airport");}
})
}
function changeJryhome(nom){if(nom==0){$("#FJrnType").val(0);$("#Round").attr("src", "pics/round_trip_check.jpg"); $("#Oneway").attr("src", "pics/one_way.jpg"); $("#FRetDateDDMMYY").removeAttr("disabled"); $("#retimg").show();};
if(nom==1){$("#FJrnType").val(1);$("#Round").attr("src", "pics/round_trip.jpg");$("#Oneway").attr("src", "pics/one_way_check.jpg");$("#FRetDateDDMMYY").attr("disabled", "disabled");$("#retimg").hide();}};

function changeJry(nom){if(nom==0){$("#FJrnType").val(0);$("#Round").attr("src", "images/roundtrp_left_chk.jpg"); $("#Oneway").attr("src", "images/oneway_lft.jpg"); $("#FRetDateDDMMYY").removeAttr("disabled"); $("#retimg").show();};
if(nom==1){$("#FJrnType").val(1);$("#Round").attr("src", "images/roundtrp_left.jpg");$("#Oneway").attr("src", "images/oneway_lft_chk.jpg");$("#FRetDateDDMMYY").attr("disabled", "disabled");$("#retimg").hide();}};
function setclasstype(){classtype(document.getElementById("class").value);}
function chkjed(){var my_str=$("#FDestTo").val(); var is__ok=my_str.indexOf('JEDDAH');if(is__ok==-1){}else{alert("*** Important Notice – Umrah Bookings ***\nIf you are travelling for Umrah and wish to fly with British Midland,\nplease call us to book as the online fares are unavailable for this purpose. ");}}
//ajaxobj
function GetXmlHttpObject() { var xmlHttp = null; try { xmlHttp = new XMLHttpRequest(); } catch (e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
function servervariable(urln,ref,count)//iptrace
{if(urln==0&&urln==""){document.getElementById("").innerHTML="";return;}xmlHttp=GetXmlHttpObject();if(xmlHttp==null){return;}
var url;if(count==1){url="Ip_Common.aspx";}else{url="../Ip_Common.aspx"}url=url+"?urln="+urln;url=url+"&ref="+ref;xmlHttp.open("GET",url,true);xmlHttp.send(null);}//end
function MM_openBrWindow(theURL, winName, features) { //v2.0
window.open(theURL, winName, features);
}
function classtype(c){
try{if(c=="0"){$("#classTypeRequest").val("ECONOMY");$("#classTypeRequestIndex").val("0");}
if(c=="1"){$("#classTypeRequest").val("BUSINESS");$("#classTypeRequestIndex").val("1");}
if(c=="2"){$("#classTypeRequest").val("FIRST");$("#classTypeRequestIndex").val("2");}
if(c=="3"){$("#classTypeRequest").val("PREMIUM");$("#classTypeRequestIndex").val("3");}}catch(e){}}

function classtypeResult(c){try{if(c=="0"){document.FlightSearch.classTypeRequest.value="ECONOMY";document.FlightSearch.classTypeRequestIndex.value="0";document.FlightSearch.classRequestE.checked=true;}
        if(c=="1"){document.FlightSearch.classTypeRequest.value="BUSINESS";document.FlightSearch.classTypeRequestIndex.value="1";document.FlightSearch.classRequestB.checked=true;}
		if(c=="2"){document.FlightSearch.classTypeRequest.value="FIRST";document.FlightSearch.classTypeRequestIndex.value="2";document.FlightSearch.classRequestF.checked=true;}
		if(c=="3"){document.FlightSearch.classTypeRequest.value="PREMIUM";document.FlightSearch.classTypeRequestIndex.value="3";document.FlightSearch.classRequestP.checked=true;}}catch(e){}}

function setsearch(){if ( document.getElementById("CalenderSeach").checked==true ){$("#flexcalender").val("1");}else{$("#flexcalender").val("0");}}
function nonstopFH(){if (document.FltHtlSearch.FHNonStop.checked){document.FltHtlSearch.FHNonStop.value="1";}else{document.FltHtlSearch.FHNonStop.value="0";}}
function getFAirLineIndex(){$("#hFAirLineIndex").val(document.getElementById("FAirLine").selectedIndex);}

function changeJrynew(nom)
{if(nom==0){$("#Round").attr("src", "../images/roundtrp_left_chk.jpg");$("#Oneway").attr("src", "../images/oneway_lft.jpg");$("#FJrnType").val(0);$("#JType").val(0);$("#FRetDateDDMMYY").removeAttr("disabled"); $("#retimg").show();}
 if(nom==1){$("#FJrnType").val(1);$("#JType").val(1);$("#Round").attr("src", "../images/roundtrp_left.jpg");$("#Oneway").attr("src", "../images/oneway_lft_chk.jpg");$("#FRetDateDDMMYY").attr("disabled", "disabled");$("#retimg").hide();}};
function valdF(sr_type)
{
if(sr_type=="F")
{
    if($("#FDestFrom").val()=="Enter Departure Airport"||$("#FDestFrom").val()==""||$("#FDestFrom").val().length<3)
    { alert("Please Enter Atleast Three Characters of Departure Airport Code Or Name.");
    $("#FDestFrom").focus();
    return false;
    }
    else if($("#FDestTo").val()=="Enter Arrival Airport"||$("#FDestTo").val()==""||$("#FDestTo").val().length<3)
    {
    alert("Please Enter Atleast Three Characters of Arrival Airport Code Or Name.");
    $("#FDestTo").focus();
    return false;
    }
    else if($("#FDestFrom").val().toLowerCase()==$("#FDestTo").val().toLowerCase())
    {
    alert("Departure Airport and Arrival Airport can't be same");
	$("#FDestTo").focus();
    return false;
    }
    else
    {
    return srch_Datevalid("#FDptDateDDMMYY", "#FRetDateDDMMYY", "F")
    }
}//fi

}//m 
function GetMonthNumber2(mon) {switch (mon.toUpperCase()) {case "JAN": return "1"; break;case "FEB": return "2"; break;case "MAR": return "3"; break;case "APR": return "4"; break;case "MAY": return "5"; break;case "JUN": return "6"; break;case "JUL": return "7"; break;case "AUG": return "8"; break;case "SEP": return "9"; break;case "OCT": return "10"; break;case "NOV": return "11"; break;case "DEC": return "12";}}
function srch_Datevalid(ctrl_dep, ctrl_ret, s_T) {
    var cr_d, dep_d, ret_d;
    cr_d = new Date();
    dep_d = new Date(parseInt($(ctrl_dep).val().substr(7, 4), 10), parseInt(GetMonthNumber2($(ctrl_dep).val().substr(3, 3)), 10) - 1, parseInt($(ctrl_dep).val().substr(0, 2), 10));
    ret_d = new Date(parseInt($(ctrl_ret).val().substr(7, 4), 10), parseInt(GetMonthNumber2($(ctrl_ret).val().substr(3, 3)), 10) - 1, parseInt($(ctrl_ret).val().substr(0, 2), 10));

    if (new Date(cr_d.getFullYear(), cr_d.getMonth(), cr_d.getDate() + 1) >= dep_d) {
        alert("IF DEPARTURE IS WITHIN 48 HOURS,\n PLEASE CONTACT OUR RESERVATIONS DEPARTMENT \nON 020 8518 9702");
        return false;
    }

    if (s_T == "FH" || s_T == "H") {
        if (ret_d <= dep_d) {
            if (s_T == "H") {
                alert("CheckOut Date must be greater than CheckIn Date");
            }
            else {
                alert("Return Date must be greater than Departure Date");
            }
            return false;
        }
    }
    else if ($('#FJrnType').val()=="0") {
            if (ret_d <= dep_d) {
            alert("Return Date must be greater than Departure Date");
            return false;
            }
            else if ($('#flexcalender').val()=="1")
            {
                var one_day=1000*60*60*24;
                var strdiff=Math.ceil((ret_d.getTime()-dep_d.getTime())/(one_day))
                if(strdiff<7) 
                  {
                  alert("The minimum difference between the dates should be 7 days.\nIf you want to search less than 7 days,please uncheck the 'My dates are flexible'")
                  return false;
                  } 
            }}
         
    if (s_T == "F") {
        var tot_pass;
        tot_pass = parseInt($("#FAdult").val(), 10) + parseInt($("#FChild").val(), 10) + parseInt($("#FInfant").val(), 10);
        if (tot_pass > 9) {
            alert("Total no of person should not be more than 9");
            return false;
        }
        else if ($("#FInfant").val() > $("#FAdult").val()) {
            alert("Number of infants should be equal to or less then number of adults");
            $("#FInfant").focus();
            return false;
        }}
 }
function nonstop() {
    try {
        if (document.getElementById("FNonStop").checked == false) { document.getElementById("Fnstop").value = 0; }
        else { document.getElementById("Fnstop").value = 1; }
    }
    catch (e) { }
}
function selectDropDownVal(Val, ddlNameId) {
    var F;
    try {
        for (F = 0; F < document.getElementById(ddlNameId).length; F++) {
            if (document.getElementById(ddlNameId).options[F].value == Val.toUpperCase()) {
                document.getElementById(ddlNameId).options[F].selected = true;
                break;
            }
        }
    } catch (e) { document.getElementById(ddlNameId).options[0].selected = true; }
}
function sethiddenfld(fieldId, ddlNameId) { document.getElementById(fieldId).value = document.getElementById(ddlNameId).options[document.getElementById(ddlNameId).selectedIndex].text; }
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
//availpage
function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}
var idnew;
var xmlHttp = null;
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);
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_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
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 cirMovement() {
    MM_showHideLayers('flight', '', 'hide', 'hotel', '', 'hide', 'flthtl', '', 'show');
    actionType(0);
    MM_showHideLayers('flight', '', 'hide', 'hotel', '', 'show', 'flthtl', '', 'hide');
    actionType(2);
    MM_showHideLayers('flight', '', 'show', 'hotel', '', 'hide', 'flthtl', '', 'hide');
    actionType(1);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);
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_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_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]; }
}
function subscribeme(emailadd) {
    if (emailadd == "") {
        alert("Plz Enter a valid Email Address");
        return;
    }
    else {
        if (emailCheck(emailadd)) {
            var address = "emailaddress.aspx";
            address = address + "?emailid=" + emailadd;
            window.open(address, '', 'width=500,height=180,toolbar=no,location=no,status=no,menubar=no,scrollbars=no');
            document.getElementById("txtmail").value = "Enter Email Address";
        }
        else {
            document.getElementById("txtmail").focus;
            return
        }
    }
}
function emailCheck(emailStr) {
    var checkTLD = 1;
    var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    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 + ")*$");
    var matchArray = emailStr.match(emailPat);
    if (matchArray == null) {
        alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    var user = matchArray[1];
    var domain = matchArray[2];
    for (i = 0; i < user.length; i++) {
        if (user.charCodeAt(i) > 127) {
            alert("Ths username contains invalid characters.");
            return false;
        }
    }
    for (i = 0; i < domain.length; i++) {
        if (domain.charCodeAt(i) > 127) {
            alert("Ths domain name contains invalid characters.");
            return false;
        }
    }
    if (user.match(userPat) == null) {
        alert("The username doesn't seem to be valid.");
        return false;
    }
    var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                alert("Destination IP address is invalid!");
                return false;
            }
        }
        return true;
    }
    var atomPat = new RegExp("^" + atom + "$");
    var domArr = domain.split(".");
    var len = domArr.length;
    for (i = 0; i < len; i++) {
        if (domArr[i].search(atomPat) == -1) {
            alert("The domain name does not seem to be valid.");
            return false;
        }
    }
    if (checkTLD && domArr[domArr.length - 1].length != 2 &&
domArr[domArr.length - 1].search(knownDomsPat) == -1) {
        alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }
    if (len < 2) {
        alert("This address is missing a hostname!");
        return false;
    }
    return true;
}
function LowerCase(Textboxid) {
    var txtval = Textboxid
    var abc
    abc = document.getElementById(txtval).value.toLowerCase()
    document.getElementById(txtval).value = document.getElementById(txtval).value.toLowerCase()
}
function setposisearch(){if (document.getElementById("LeftSearch").style.display=="block"){document.getElementById("LeftSearch").style.display="none";document.getElementById("modifysearch").setAttribute("src","../pics/search_up.jpg");}else{document.getElementById("LeftSearch").style.display="block";document.getElementById("modifysearch").setAttribute("src","../pics/search_down.jpg");}}
function setsrch(f,t,d,r,a,n,ci,jt,srceng,flex)
{var i=0;
$("#FDestTo").val(t);
$("#FDestFrom").val(f);
$("#FDptDateDDMMYY").val(d);
$("#FRetDateDDMMYY").val(r);
i=a;
try{document.getElementById("FAirLine").options[i].selected=true;$("#hFAirLineIndex").val(i);}
catch (ex){document.getElementById("FAirLine").options[0].selected=true;}
i=n;
if(i!="1")
{$("#FNonStop").val(0);document.FlightSearch.FNonStop.checked=false;}
    else{document.FlightSearch.FNonStop.checked=true;$("#FNonStop").val(1);}
classtypeResult(ci);changeJrynew(jt);
try{if(srceng=="True"){$("#notresult").hide();setposisearch();}}catch(e){}
try{if(flex=="1"){document.getElementById("CalenderSeach").checked=true;}setsearch();}catch(e){}
}
 function popUp(text, textBoxNo,inout) {			
				txtBox = text;
				textBoxId = textBoxNo;
				if (inout==1)
				{
				URL = "FindCity.aspx?no="+textBoxId
				}
				else
				{
				URL = "../FindCity.aspx?no="+textBoxId
				}
				win = open(URL, 'FindCity', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=420,height=570,left = 340,top = 150');
			}
