﻿//function PrepareSummary()
//{
//    if(BookingXml)
//    {
//        var myDiv = document.getElementById("divBookingSummary");
//        
//        var xml = new JKL.ParseXML( BookingXml );
//        var objSummary = xml.parse();        

//        var sb = new StringBuilder();
//        
//        var arrayFlightItinerary = objSummary.SummaryData.Flight.FlightItineraries.FlightItinerary;
//        if(arrayFlightItinerary.length>0)
//        {
//            for(i=0;i<arrayFlightItinerary.length;i++)
//            {
//                sb.append(arrayFlightItinerary[i].From, "<br>");        
//                sb.append(arrayFlightItinerary[i].To, "<br>");
//                sb.append(arrayFlightItinerary[i].DepartureDate, "<br>");
//                sb.append(arrayFlightItinerary[i].ArrivalDate, "<br>");
//                sb.append("<br>");
//            }
//        }
//        
//        myDiv.innerHTML = sb.toString();
//    }
//}

function ImgErr(img, errorImage) {
    img.onerror = null;

    if (errorImage) {
        img.src = errorImage;
    }
    else {
        img.src = '" + img.ErrorImage + "';
    }
}

var Trace = "";
function SetTrace(Location) {
    if (Location) {
        var NowTime = "";
        var NowDate = new Date();
        NowTime = NowDate.getHours();
        NowTime += ":" + NowDate.getMinutes();
        NowTime += ":" + NowDate.getSeconds();

        NowTime += " - " + NowDate.getTime().toString().substring(7);

        Trace += Location + " --> " + NowTime + " <br>\r\n";
    }
    else {
        window.open().document.write(Trace);
    }
}

function GetScrollTopPos() {
    var ScrollPos = 0;
    if (isIE) {
        ScrollPos = document.body.scrollTop;
    }
    else {
        ScrollPos = window.pageYOffset;
    }

    return ScrollPos;
}

function StopEvent(evt) {
    evt = evt || window.event;
    if (evt.cancelBubble != undefined) {
        evt.returnValue = false;
        evt.cancelBubble = true;
    }
    if (evt.stopPropagation != undefined) {
        evt.stopPropagation();
        evt.preventDefault();
    }
}

function DumpButtonHTML(id, css, TemplateName, onclientclick, isDefaultButton, text, width, enabled, target, themeName) {
    try {

        HTML = "<span id=\"{id}\" {disabled} {onclickFromDefaultButton} style=\"display:inline-block;{tamkapla}\"><table {tableid} onMouseOut=\"this.className='{css}';\" border=\"0\" {width} Class=\"{css}\" cellPadding=\"0\" onclick=\"{onclick}\" onMouseOver=\"this.className='{css}Over';\" {handstyle} cellSpacing=\"0\"><tr><td width=\"1\"><img src='I.axd?t=b&th={themename}&p={TemplateName}/left.gif'></td><td width=\"100%\" align=\"Center\" nowrap=\"nowrap\" background=\"I.axd?t=b&amp;th={themename}&amp;p={TemplateName}/back.gif\">{text}</td> <td width=\"1\"><img src='I.axd?t=b&th={themename}&p={TemplateName}/right.gif'></td></tr></table></span>";

        var strtamkapla = "";
        //Quick search ekranındaki butonların tam kaplaması için yapıldı. [BySerkan]
        if (css == 'QSearchButton' || css == 'QSearchSelectedButton') {
            strtamkapla = "width:100%;";
        }
        HTML = HTML.replace("{tamkapla}", strtamkapla);

        if (enabled == "True") {
            HTML = HTML.replace("{handstyle}", "style=\"cursor:pointer;cursor:hand;\"");
        }
        else {
            HTML = HTML.replace("{disabled}", "disabled=\"disabled\"");
        }

        if (width.length > 0) {
            HTML = HTML.replace("{width}", "width=\"" + width + "\"");
        }

        if (isDefaultButton == "True") {
            onclientclick += "StopEvent(event);";
            HTML = HTML.replace("{onclickFromDefaultButton}", "onclick=\"document.getElementById('{id}_Table').onclick();StopEvent(event)\"");
            HTML = HTML.replace("{tableid}", "id=\"{id}_Table\"");
        }

        HTML = HTML.replace("{handstyle}", "");
        HTML = HTML.replace("{width}", "");
        HTML = HTML.replace("{onclickFromDefaultButton}", "");
        HTML = HTML.replace("{tableid}", "");
        HTML = HTML.replace("{disabled}", "");

        HTML = ReplaceAll(HTML, "{themename}", themeName);
        HTML = ReplaceAll(HTML, "{id}", id);
        HTML = ReplaceAll(HTML, "{css}", css);
        HTML = ReplaceAll(HTML, "{TemplateName}", TemplateName);
        HTML = ReplaceAll(HTML, "{onclick}", onclientclick);
        HTML = ReplaceAll(HTML, "{text}", text);

        document.write(HTML);
    } catch (e) { alert("butondan:" + e.name + " - " + e.message + " - " + e.description); }
}

function ReplaceAll(str, strFind, StrChange) {
    str = str.replace(new RegExp(strFind, "gi"), StrChange);
    return str;
}

function SetLocked(objID, lockStatus) {
    document.getElementById(objID).onkeydown = function () { return lockStatus; };
    document.getElementById(objID).onselectstart = function () { return lockStatus; };
}

function HideDDLs() {
    var DDls = document.getElementsByTagName('SELECT');
    for (i = 0; i < DDls.length; i++) {
        DDls[i].style.visibility = "hidden";
    }
}

function ShowDDLs() {
    var DDls = document.getElementsByTagName('SELECT');
    for (i = 0; i < DDls.length; i++) {
        DDls[i].style.visibility = "visible";
    }
}

function GetQueryStringValue(Key) {
    try {
        var s = new String();
        s = window.document.location;

        var r = new RegExp('([?&]' + Key + '=)([^&^?]*)');

        return r.exec(s)[2];
    }
    catch (ex) {
        return null;
    }
}

function PopupOpen(OpenPage, PopupName, Properties) {

    window.open(OpenPage, PopupName, Properties);

}

function PopupOpenCenter(OpenPage, PopupName, Width, Height, Properties) {
    Left = (screen.availWidth - Width) / 2;

    Top = (screen.availHeight - Height) / 2;

    window.open(OpenPage, PopupName, Properties + ',top=' + Top + ',left=' + Left + ',width=' + Width + ',height=' + Height);

}

function RadioCheck(parentid, id) {
    RadioList = document.getElementsByTagName("Input");

    for (i = 0; i < RadioList.length; i++) {
        if (RadioList[i].id.indexOf(parentid) > -1 && RadioList[i].id != id) {
            if (RadioList[i].checked) {
                RadioList[i].checked = false;
            }
        }
    }
}

function CheckedRadioIsBanned()
{
    RadioList = document.getElementsByTagName("Input");
    for (i = 0; i < RadioList.length; i++) {

        if (RadioList[i].checked && RadioList[i].getAttribute("IsBanned")) {

            return true;
        }
    }

    return false;
}

function clearDD(oDropDown) {
    if (oDropDown == null)
        return;
    var oOptions = oDropDown.options;
    for (var i = oOptions.length; i >= 0; i--) {
        oOptions[i] = null;
    }
}

function getDDValue(oDropDown) {
    return oDropDown.options[oDropDown.selectedIndex].value;
}

function getMinValue(p_Value1, p_Value2) {
    if (p_Value1 > p_Value2)
    { return p_Value2; }
    else
    { return p_Value1; }
}

function PageIsValid(ValidationGroup) {
    var validationResult = true;

    if (typeof (Page_ClientValidate) == 'function') {
        validationResult = Page_ClientValidate(ValidationGroup);
    }

    return validationResult;
}

function GetLoadingParametersHTML(valueArray) {
    var strHTML = "";

    strHTML += "<table width='400px' height='100px' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF' class='LoadingParametersTable'><tr><td align='center'>";

    strHTML += valueArray[0];
    if (valueArray[1] != "") {
        strHTML += " -> " + valueArray[1];
    }
    strHTML += " <br><br> " + valueArray[2];
    if (valueArray.length > 3 && valueArray[3] != "") {
        strHTML += " - " + valueArray[3];
    }
    strHTML += "</td></tr></table>";

    return strHTML;
}

function Loading(isValid, SplashScreenId, ImagePath, Parameters) {
    if (!SplashScreenId) { return; }
    if (isValid) {
        window.setTimeout("ShowLoading('" + SplashScreenId + "','" + ImagePath + "','" + Parameters + "')", 200);
    }
}

function ShowLoading(SplashScreenId, ImagePath, Parameters) {
    var valueArray = new Array();
    if (Parameters && Parameters != "undefined") {
        var ParametersColl = Parameters.split(";");
        for (i = 0; i < ParametersColl.length; i++) {
            if (ParametersColl[i].length > 0) {
                var obj = document.getElementById(ParametersColl[i]);
                if (obj) {
                    valueArray.push(obj.value);
                }
                else {
                    valueArray.push("");
                }
            }
            else {
                valueArray.push("");
            }
        }
    }

    var HTML
    dc = document;
    SplashFrame = dc.frames ? dc.frames[SplashScreenId] : dc.getElementById(SplashScreenId);
    dc = SplashFrame.document || SplashFrame.contentWindow.document;
    HTML = dc.getElementsByTagName("body")[0].innerHTML;

    HTML = ReplaceAll(HTML, '{imagepath}', ImagePath + '/');
    HTML = ReplaceAll(HTML, '%7Bimagepath%7D', ImagePath + '/');
    var strParameters = "";
    if (valueArray.length > 0)
        strParameters = GetLoadingParametersHTML(valueArray);
    HTML = ReplaceAll(HTML, '{Parameters}', strParameters);
    if (document.all["loadingPanel"])
    { document.getElementById("loadingPanel").innerHTML = HTML; }
    else
    { document.body.innerHTML = HTML; }
}

function ReplaceIFrameHTML(IFrameID, ImagePath) {
    var HTML
    dc = document;
    SplashFrame = dc.frames ? dc.frames[IFrameID] : dc.getElementById(IFrameID);
    dc = SplashFrame.document || SplashFrame.contentWindow.document;
    HTML = dc.getElementsByTagName("body")[0].innerHTML;

    HTML = ReplaceAll(HTML, '{imagepath}', ImagePath + '/');
    HTML = ReplaceAll(HTML, '%7Bimagepath%7D', ImagePath + '/');

    dc.getElementsByTagName("body")[0].innerHTML = HTML;
}

function findObj(n, d) {
    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 = findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function swapImage(imgId, url) {
    if ((x = findObj(imgId)) != null) {
        try {
            x.style.filter = "blendTrans(duration=1)";
            x.style.filter = "blendTrans(duration=1)";
            x.filters.blendTrans.Apply();

            x.src = url;

            x.filters.blendTrans.Play();
        }
        catch (exc) {
            x.src = url;
        }
    }
}

function wrapContainer(ContainerID) {
    Container = document.getElementById(ContainerID);

    if (Container.style.display == "") {
        Container.style.display = "block";
    }
    if (Container.style.display == "none") {
        Container.style.display = "block";
    }
    else if (Container.style.display == "block") {
        Container.style.display = "none";
    }
}

function wrap(HiddenStatusID, ContainerID, ImageID, MinimizeImage, RestoreImage) {
    HiddenStatus = document.getElementById(HiddenStatusID);
    Container = document.getElementById(ContainerID);

    if (Container.style.display == "") {
        Container.style.display = "block";
    }

    if (Container.style.display == "none") {
        Container.style.display = "block";
        swapImage(ImageID, MinimizeImage);
        HiddenStatus.value = "Opened";
    }
    else if (Container.style.display == "block") {
        Container.style.display = "none";
        swapImage(ImageID, RestoreImage);
        HiddenStatus.value = "Closed";
    }

}

function changeCulture(cultureCode) {
    var CurrentCultureStr = GetQueryStringValue("Culture");
    var pathStr = window.location.href;
    var newPath = pathStr;
    var strToReplace = "?";
    if (CurrentCultureStr != null && CurrentCultureStr != '')
    { newPath = pathStr.replace("Culture=" + CurrentCultureStr, "Culture=" + cultureCode); }
    else if (pathStr.indexOf("?") > 0)
    { newPath = pathStr.replace("?", "?Culture=" + cultureCode + "&"); }
    else
    { newPath = pathStr + "?Culture=" + cultureCode }
    var r = new RegExp('&$');
    try {
        if ((r.exec(newPath)) != null) {
            newPath = newPath.substring(0, newPath.length - 1);
        }

    }
    catch (ex)
	{ }
    try {
        if (SR) //Arama Sonuc sayfasi ise
        {
            newPath = newPath.replace("FlightFareSearch.aspx", "FlightFareResult.aspx")
        }
    }
    catch (ex)
	{ }
    document.location.href = newPath;
}

var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;

function fadein(obj, x, y) {
    var self = arguments.callee;

    if (!self.opac) self.opac = x;
    var el = document.getElementById(obj);
    if (self.opac < y) {
        self.opac += 20;
        el.style.display = "block";
        if (typeof (el.style.filter) != 'undefined') { // IE5.5+
            el.style.zoom = 1;
            el.style.filter = 'alpha(opacity:' + self.opac + ')';
        } else {
            el.style.opacity = el.style.MozOpacity = self.opac / 100;
        }
        setTimeout('fadein("' + obj + '",' + self.opac + ',' + y + ')', 2);
    }
    else {
        self.opac = undefined;
    }
}

function fadeout(obj, x, y) {
    var self = arguments.callee;

    if (!self.opac) self.opac = x;
    var el = document.getElementById(obj);
    if (self.opac > y) {
        self.opac -= 20;
        if (typeof (el.style.filter) != 'undefined') { // IE5.5+
            el.style.zoom = 1;
            el.style.filter = 'alpha(opacity:' + self.opac + ')';
        } else {
            el.style.opacity = el.style.MozOpacity = self.opac / 100;
        }
        setTimeout('fadeout("' + obj + '",' + self.opac + ',' + y + ')', 2);
    }
    else {
        self.opac = undefined;
        el.style.display = "none";
    }
}

Array.prototype.findVal = function (obj) {
    var len = this.length;
    for (var i = 0; i < len; i++) {
        if (this[i].val) {// eğer val diye bir propertysi varsa onu eşleştir.
            if (this[i].val == obj) {
                return this[i];
            }
        }
    }
    return null;
};
Array.prototype.indexOf = function (obj) {
    var len = this.length;
    for (var i = 0; i < len; i++) {
        if (this[i] == obj) {
            return i;
        }
    }
    return -1;
};

function StringBuilder(value) {
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function () {
    for (argumentsCounter = 0; argumentsCounter < arguments.length; argumentsCounter++) {
        this.strings.push(arguments[argumentsCounter]);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function () {
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function () {
    return this.strings.join("");
}

var HotelImagesArray = null;
var HotelDescriptionArray = null;
var HotelImagesArraySelectedIndex = 0;
var HotelImagesViewMode = "Automatic";
var HotelImagesTimeOut = null;
function FillHotelImages(p_Images, p_Descriptions) {
    HotelImagesArray = p_Images.split("|");
    HotelDescriptionArray = p_Descriptions.split("|");
    HotelImagesArraySelectedIndex = 0;

    document.getElementById("objHotelImage").src = HotelImagesArray[0];
    document.getElementById("HotelImageDesc").innerHTML = HotelDescriptionArray[0];
    HotelImagesTimeOut = setTimeout("ChangeSelectedHotelImage('Next')", 2000);
}

function ChangeHotelImagesViewMode(Mode) {
    if (Mode) {
        HotelImagesViewMode = Mode;
    }
    else {
        HotelImagesViewMode = HotelImagesViewMode == "Automatic" ? "Manuel" : "Automatic";
    }

    clearTimeout(HotelImagesTimeOut);
    if (HotelImagesViewMode == "Automatic") {
        HotelImagesTimeOut = setTimeout("ChangeSelectedHotelImage('Next')", 1000);
    }
    else {
        document.getElementById("imgHotelImagesViewModePlay").style.display = "block";
        document.getElementById("imgHotelImagesViewModePause").style.display = "none";
    }
}

function ChangeSelectedHotelImage(ChangeWay) {
    if (ChangeWay == "Back") {
        if (HotelImagesArraySelectedIndex == 0) {
            HotelImagesArraySelectedIndex = HotelImagesArray.length - 1;
        }
        else {
            HotelImagesArraySelectedIndex -= 1;
        }
    }
    else if (ChangeWay == "Next") {
        if (HotelImagesArraySelectedIndex == HotelImagesArray.length - 1) {
            HotelImagesArraySelectedIndex = 0;
        }
        else {
            HotelImagesArraySelectedIndex += 1;
        }
    }

    document.getElementById("HotelImageDesc").innerHTML = HotelDescriptionArray[HotelImagesArraySelectedIndex];
    swapImage('objHotelImage', HotelImagesArray[HotelImagesArraySelectedIndex]);

    if (HotelImagesViewMode == "Automatic") {
        document.getElementById("imgHotelImagesViewModePause").style.display = "block";
        document.getElementById("imgHotelImagesViewModePlay").style.display = "none";
        clearTimeout(HotelImagesTimeOut);
        HotelImagesTimeOut = setTimeout("ChangeSelectedHotelImage('Next')", 2000);
    }
}

window.size = function () {
    var w = 0;
    var h = 0;

    //IE
    if (!window.innerWidth) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
        }
        //quirks mode
        else {
            w = document.body.clientWidth;
            h = document.body.clientHeight;
        }
    }
    //w3c
    else {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    return { width: w, height: h };
}

window.center = function (objWidth, objHeight) {
    objWidth = (objWidth != null) ? objWidth : 0;
    objHeight = (objHeight != null) ? objHeight : 0;

    var _x = 0;
    var _y = 0;
    var offsetX = 0;
    var offsetY = 0;

    //IE
    if (!window.pageYOffset) {
        //strict mode
        if (!(document.documentElement.scrollTop == 0)) {
            offsetY = document.documentElement.scrollTop;
            offsetX = document.documentElement.scrollLeft;
        }
        //quirks mode
        else {
            offsetY = document.body.scrollTop;
            offsetX = document.body.scrollLeft;
        }
    }
    //w3c
    else {
        offsetX = window.pageXOffset;
        offsetY = window.pageYOffset;
    }

    _x = ((this.size().width - objWidth) / 2) + offsetX;
    _y = ((this.size().height - objHeight) / 2) + offsetY;

    return { x: _x, y: _y };
}

function addThousandSeperator(strToFormat) {
    var s = ('' + strToFormat).split(decimalSeperator);
    s[0] = s[0].split('').reverse().join('').match(/\d{1,3}/gi).join(thousandSeperator).split('').reverse().join('');
    return s.join(decimalSeperator);
}

function convertToFloat(strToConvert) {
    strToConvert = strToConvert.replace(thousandSeperator, "");
    return parseFloat(strToConvert)
}

function calculateVPValue(p_Amount) {
    return Math.round((convertToFloat(p_Amount) / exchangeRate / ValueablePoint) / 1000) * 1000;
}

function calculateWPValue(p_Amount) {
    return Math.round(convertToFloat(p_Amount) / WorldPuan / 1000) * 1000;
}

function createAjaxRequest() {
    var AWAjaxRequest
    try {
        AWAjaxRequest = new XMLHttpRequest();
    }
    catch (tryMS) {
        try {
            AWAjaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (otherMS) {
            try {
                AWAjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (failed) {
                AWAjaxRequest = null;
            }
        }
    }
    return AWAjaxRequest;
}

function OpenHidePanelForCheckBox(chkID, pnlID) {
    chk = document.getElementById(chkID);
    pnl = document.getElementById(pnlID);

    if (chk) {
        if (chk.checked) {
            pnl.style.display = "block"
        }
        else {
            pnl.style.display = "none"
        }
    }
}

//linkScript
//AirlineImageURL
//PriceString
//DepartureDate
//DepartureTime
//ArrivalDate
//ArrivalTime

var newDiv = document.createElement("div");

newDiv.style.width = 150;
newDiv.style.height = 110;
newDiv.style.position = "absolute";
newDiv.style.backgroundImage = "url(I.axd?th=1&t=i&p=Balloon/calendarBalloon.png)";
newDiv.style.backgroundRepeat = "no-repeat";

function CalendarCellOver(objCell) {
    
    //newDiv.setAttribute('id', id);
    newDiv.style.display = "block";

    var str = new StringBuilder();
    str.append("<table style=\"position:relative;left:10px\" width=\"120\" cellpadding=\"0\" cellspacing=\"0\" height=\"100\" border=\"0\">");
    str.append("<tr><td align=\"center\" style=\"border:none;font-weight:bold\">");
    str.append("<img border=\"0\" src=\"" + objCell.getAttribute("AirlineImageURL") + "\" align=\"absmiddle\"/></td><td style=\"border:none;font-weight:bold\">"+objCell.getAttribute("AirlineName")+"</td></tr>");
    str.append("<tr><td colspan=\"2\" style=\"color:#000000;font-size:9px;border:none\">");
    str.append(objCell.getAttribute("DepartureDate") + " " + objCell.getAttribute("DepartureTime") + "</td></tr>");
    str.append("<tr><td colspan=\"2\" style=\"color:#000000;font-size:9px;border:none\">");
    str.append(objCell.getAttribute("ArrivalDate") + " " + objCell.getAttribute("ArrivalTime") + "</td></tr>");
    str.append("</table>");
    
    newDiv.innerHTML = str;
    objCell.appendChild(newDiv);
    
    

}

function CalendarCellOut(objCell) {
    newDiv.style.display = "none";
    
}