var GlobalDateFormat = "dd/MM/yyyy";

//Declare the variable for InviteFriend Login//
var Email = "";
var Password = "";

//Declare the variable for InviteFriend ChangePassword//
var OldPassword = "";
var NewPassword = "";
var ConfirmPassword = "";
var LoginEmail = "";
var TB_L_Password = "";


jQuery(document).ready(function() {

    jQuery(".tab:not(:first)").hide();
    //to fix u know who
    jQuery(".tab:first").show();
    $("img[src$='/App_Themes/Images/calendar.gif']").mouseover(function() {
        $(this).css('cursor', 'hand');
    });
    jQuery(".htabs a").click(function() {
        stringref = jQuery(this).attr("href").split('#')[1];

        jQuery('.tab:not(#' + stringref + ')').hide();

        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            jQuery('.tab#' + stringref).show();
        }
        else
            jQuery('.tab#' + stringref).fadeIn();

        return false;
    });

    /*****************************************************************/
    jQuery(".tab2:not(:first)").hide();
    //to fix u know who
    jQuery(".tab2:first").show();

    jQuery(".htabs2 a").click(function() {
        stringref = jQuery(this).attr("href").split('#')[1];

        jQuery('.tab2:not(#' + stringref + ')').hide();

        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            jQuery('.tab2#' + stringref).show();
        }
        else
            jQuery('.tab2#' + stringref).fadeIn();

        return false;
    });

    /*****************************************************************/
    jQuery(".tab3:not(:first)").hide();
    //to fix u know who
    jQuery(".tab3:first").show();

    jQuery(".htabs3 a").click(function() {
        stringref = jQuery(this).attr("href").split('#')[1];

        jQuery('.tab3:not(#' + stringref + ')').hide();

        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            jQuery('.tab3#' + stringref).show();
        }
        else
            jQuery('.tab3#' + stringref).fadeIn();

        return false;
    });



});
function InitializeSingleDtCalender(Txt_DateClientId) {
    $(function() {
        //$('#' + Txt_DateClientId).datepicker();
        $('#' + Txt_DateClientId).datepicker({ dateFormat: "dd/mm/yy",
            gotoCurrent: true,
            showOn: 'button',
            minDate: new Date(),
            //maxDate: new Date(),
            nextText: '',
            prevText: '',
            buttonImage: '/App_Themes/Images/calendar.gif',
            buttonImageOnly: true
        });
    });
}
function InitializeSingleDtCalenderForReports(Txt_DateClientId) {
    $(function() {

        //$('#' + Txt_DateClientId).datepicker();
        $('#' + Txt_DateClientId).datepicker({ dateFormat: "dd/mm/yy",
            gotoCurrent: true,
            showOn: 'button',

            //minDate:'',
            maxDate: new Date(),
            nextText: '',
            prevText: '',
            buttonImage: '/App_Themes/Images/calendar.gif',
            buttonImageOnly: true
        });
    });
}


function InitializeSingleDtCalenderForDOB(Txt_DateClientId) {
    $(function() {
        //$('#' + Txt_DateClientId).datepicker();
        $('#' + Txt_DateClientId).datepicker({ dateFormat: "dd/mm/yy",
            gotoCurrent: true,
            showOn: 'button',
            // minDate: new Date(),
            nextText: '',
            prevText: '',
            buttonImage: '/App_Themes/Images/calendar.gif',
            buttonImageOnly: true
        });
    });
}

/***************************************************/
//Email Validation for NewsLetter email id


function ValidateEmail(xiNewsLetterEmail) {

    var NewsLetterEmail = document.getElementById(xiNewsLetterEmail).value;
    var EmailFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

    if (NewsLetterEmail == "") {
        alert("Please Enter Email Address");
        document.getElementById(xiNewsLetterEmail).value = "";
        return false;
    }
    if (EmailFilter.test(NewsLetterEmail)) {
        return true;
    }
    else {
        alert("Please enter valid Email Address");
        document.getElementById(xiNewsLetterEmail).value = "";
        document.getElementById(xiNewsLetterEmail).focus();
        return false;
    }
    return true;
}

function setFocustoEmailTxtBox(xiEmail) {

    document.getElementById(xiEmail).focus();

}
function ValidateEmailWithoutAlert(xiEmail) {
    var NewsLetterEmail = document.getElementById(xiEmail).value;
    var EmailFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

    if (NewsLetterEmail != "" && EmailFilter.test(NewsLetterEmail)) {
        return true;
    }
    else {
        return false;
    }
    return true;
}



function numbersonly(e, decimal) {
    var key;
    var keychar;

    if (window.event) {
        key = window.event.keyCode;
    }
    else if (e) {
        key = e.which;
    }
    else {
        return true;
    }
    keychar = String.fromCharCode(key);

    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) || (key == 41) || (key == 40) || (key == 43) || (key == 32)) {
        return true;
    }
    else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;
    }
    else if (decimal && (keychar == ".")) {
        return true;
    }
    else
        return false;
}


var SearchDestinationName;
var HoldingPageTypeId = 0;

function BodyOnBeforeUnload() {
    ShowHoldingDiv();
}

function LoadHoldingImages() {
    var AllImages = $("#SP_SearchHolding img");
    for (var i = 0; i < AllImages.length; i++) {
        var imagesrc = AllImages[i].src;
        AllImages[i].src = imagesrc;
    }
    
}

function ShowHoldingDiv() {
    if (HoldingPageTypeId == 1) {//General search holding
        $('#DIV_SearchHoldingDestinationName').append(SearchDestinationName)

        $("#SP_SearchHolding").css({ "display": "block" });

        $("#SP_AvailablityCheckHolding").css({ "display": "none" });
        $("#SP_GeneralHolding").css({ "display": "none" });

        //Added by manju on the 19/01/2012 for Rotating iamges
        /*holding page */

        $('.buttonYellow').click(function() {
            if ($.browser.msie && parseInt($.browser.version) >= 7) {
                $('.holdingPageLoaderIe').css("display", "block");
                $('.holdingPageLoaderAll').css("display", "none");
            }
            else {
                $('.holdingPageLoaderIe').css("display", "none");
            }
        });
        /*holding page end*/

        setTimeout('LoadHoldingImages()', 200);
        //setTimeout('document.getElementById("IMG_SearchHolding").src = "/App_Themes/Images/holdingPageLoader.gif"', 210);


        //setTimeout('document.images["IMG_SearchHolding"].src = "/App_Themes/Images/holdingPageLoader.gif"', 200);
        //==========================End=================================//

        //        //For IE add Animated image here
        //        if ($.browser.msie) {
        //            $('#Div_SearchHoldingClock').empty();
        //            $("#Div_SearchHoldingClock").append("<img src='/App_Themes/Images/holdingPageClock.gif' width='119' height='120' alt='' title=''  />");
        //        }
    }
    else if (HoldingPageTypeId == 2) {//Availablity Page Search

        $("#SP_SearchHolding").css({ "display": "none" });

        $("#SP_AvailablityCheckHolding").css({ "display": "block" });
        $(".paymentHoldingPage").css({ "display": "block" });
        $("#DIV_HoldingPage").css({ "display": "block" });


        $("#SP_GeneralHolding").css({ "display": "none" });

        //For IE add Animated image here


        //        //For IE add Animated image here
        //        if ($.browser.msie) {
        //            $('#Div_AvailablityHoldingClock').empty();
        //            $("#Div_AvailablityHoldingClock").append("<img src='/App_Themes/Images/holdingPageClock.gif' width='119' height='120' alt='' title=''  />");
        //        }
    }
    else { //General postback
        $("#DIV_HoldingPage").css({ "width": "200px", "text-align": "center" });
        // $("#DIV_HoldingPaymentPage").css({ "width": "200px", "text-align": "center" });

        $("#SP_SearchHolding").css({ "display": "none" });
        $("#SP_AvailablityCheckHolding").css({ "display": "none" });
        $("#SP_GeneralHolding").css({ "display": "" });

        //For IE add Animated image here
        if ($.browser.msie) {
            $("#SP_GeneralHolding").empty();
            $("#SP_GeneralHolding").append("<img src='/App_Themes/Images/LGTLoading.gif' alt='Loading please wait......' />");
        }
    }

    //Hide Search Holding Div and Show General Div
    centerholdingPagePopup();
    $(".backgroundWrapper").css({ "opacity": "0.7" });
    $(".backgroundWrapper").fadeIn("slow");
    // below two lines of code will show white background for processing
    $(".bgWrapperWhite").css({ "opacity": "0.7" });
    $(".bgWrapperWhite").fadeIn("slow");
    $(".holdingPage").fadeIn("slow");

    HoldingPageTypeId = 0;
    SearchDestinationName = ''
}

function centerholdingPagePopup() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    // alert("windowHeight" + document.documentElement.clientHeight);

    var paymentHoldingPHeight = $(".paymentHoldingPage").height();
    var paymentHoldingPWidth = $(".paymentHoldingPage").width();

    //paymentHoldingPage page popup centering
    $(".paymentHoldingPage").css({
        "position": "fixed",
        "top": windowHeight / 2 - paymentHoldingPHeight / 2,
        "left": windowWidth / 2 - paymentHoldingPWidth / 2
    });

    var HoldingPHeight = $(".holdingPage").height();
    var HoldingPWidth = $(".holdingPage").width();
    //    var paymentHoldingPHeight = $(".paymentHoldingPage").height();
    //    var paymentHoldingPWidth = $(".paymentHoldingPage").width();
    //    
    //Holding page popup centering
    $(".holdingPage").css({
        "position": "fixed",
        "top": windowHeight / 2 - HoldingPHeight / 2,
        "left": windowWidth / 2 - HoldingPWidth / 2
    });
    //    //paymentHolding page popup centering
    //    $(".paymentHoldingPage").css({
    //        "position": "fixed",
    //        "top": windowHeight / 2 - paymentHoldingPHeight / 2,
    //        "left": windowWidth / 2 - paymentHoldingPWidth / 2
    //    });


};

function ConfirmMessage(message) {
    if (confirm(message)) {
        return true;
    }
    else {
        return false;
    }
}


function ReadXML(data, XMLNode, TagName) {
    var price = 0;
    if (typeof (data) != String) {
        var rows = data.getElementsByTagName("string");
        var xmlDoc;
        var xmlTextContent;
        if (rows[0].textContent) {
            xmlTextContent = rows[0].textContent;
        }
        else {
            xmlTextContent = rows[0].text;
        }

        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(xmlTextContent, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(xmlTextContent);
        }
        if (xmlDoc) {

            var ListOfAreaData = xmlDoc.getElementsByTagName(XMLNode);

            try {
                price = ListOfAreaData[0].selectSingleNode("./" + TagName).text;
            }
            catch (e) {
                price = ListOfAreaData[0].getElementsByTagName(TagName)[0].textContent;
            }

        }
    }
    return price;
}

function openWin(aURL, myWin) {
    var myWindow = window.open(aURL + "NewsLetter/Default.aspx", 'myWin', 'width = 800, height = 600, left =250, top =150, scrollbars = yes');
    myWindow.location.href = aURL + "NewsLetter/Default.aspx";
    myWindow.focus();
}

/*Round up decimal number as per requirment*/
function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
function LoadHoldingPageorAirline() {
    HoldingPageTypeId = 1;
    BodyOnBeforeUnload();
}

//Function For Login Invite Friend on 03/05/2011

function CheckForEmptyString(objstring) {
    var strTemp = objstring;
    if (strTemp == "")
        return false;
    else {
        if (!/\S/.test(strTemp))
            return false;
    }
    return true;
}

function ValidateInviteFriendLoginDetail() {

    var EmailFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    if (document.getElementById(LoginEmail)) {
        if (!CheckForEmptyString(document.getElementById(LoginEmail).value)) {
            alert('Email must be Entered');
            document.getElementById(LoginEmail).focus();
            return false;
        }
    } if (document.getElementById(LoginEmail)) {
        if (!EmailFilter.test(document.getElementById(LoginEmail).value)) {
            alert(document.getElementById(LoginEmail).value);
            alert('Please enter valid Email address');
            document.getElementById(LoginEmail).focus();
            return false;
        }
    }

    if (document.getElementById(TB_L_Password)) {
        if (!CheckForEmptyString(document.getElementById(TB_L_Password).value)) {
            alert('Password must be entered');
            document.getElementById(TB_L_Password).focus();
            return false;
        }
    }
    if (document.getElementById(TB_L_Password)) {
        if (document.getElementById(TB_L_Password).value.length < 6 || document.getElementById(TB_L_Password).value.length > 10) {
            alert('Your password must contain 6-10 characters');
            document.getElementById(TB_L_Password).focus();
            return false;
        }
    }
    return true;
}

//Function For Change Pasword Invite Friend on 03/05/2011

function ValidateInviteFriendChangePasswordDetail() {
    //alert(OldPassword);
    if (document.getElementById(OldPassword)) {
        if (!CheckForEmptyString(document.getElementById(OldPassword).value)) {
            alert('Old password must be entered');
            document.getElementById(OldPassword).focus();
            return false;
        }
    }
    if (document.getElementById(OldPassword)) {
        if (document.getElementById(OldPassword).value.length < 6 || document.getElementById(OldPassword).value.length > 10) {
            alert('Old password must contain 6-10 characters.');
            document.getElementById(NewPassword).focus();
            return false;
        }
    }
    if (document.getElementById(NewPassword)) {
        if (!CheckForEmptyString(document.getElementById(NewPassword).value)) {
            alert('New password must be entered');
            document.getElementById(NewPassword).focus();
            return false;
        }
    }
    if (document.getElementById(NewPassword)) {
        if (document.getElementById(NewPassword).value.length < 6 || document.getElementById(NewPassword).value.length > 10) {
            alert('Your password must contain 6-10 characters.');
            document.getElementById(NewPassword).focus();
            return false;
        }
    }
    if (document.getElementById(ConfirmPassword)) {
        if (!CheckForEmptyString(document.getElementById(ConfirmPassword).value)) {
            alert('Confirm password must be entered');
            document.getElementById(ConfirmPassword).focus();
            return false;
        }
    }
    if (document.getElementById(ConfirmPassword) && document.getElementById(NewPassword)) {
        if (document.getElementById(ConfirmPassword).value != "" && document.getElementById(NewPassword).value != "") {
            if (document.getElementById(ConfirmPassword).value != document.getElementById(NewPassword).value) {
                alert('Confirm Passwords do not match with New password');
                document.getElementById(ConfirmPassword).focus();
                return false;
            }
        }

    }

}

function ChangePasswordAlert() {
    alert("Password Saved Succesfully!");
    return true;
}
function ForgotPasswordAlert(Email) {
    alert("Your password has been sent to your email address");
    return true;
}
function AlreadyExistAlert() {
    alert("Your contact details already exist");
    return false;
}
function OldPAsswordAlert() {
    alert("Please enter correct Old Password");
    return false;
}
function OpenHolidayCallBackDiv() {
    $("#FreeCallBack").css({ "display": "" });
    $("#EmailEnquiry").css({ "display": "none" });
    return false;
}
function OpenEmailenquiryDivDiv() {
    $("#EmailEnquiry").css({ "display": "" });
    $("#FreeCallBack").css({ "display": "none" });
    return false;
}

