﻿// function for changing active tab
function activateTab(index, stateFieldId, eventArg) {
    for (var i in tabHeads) {
        var tempObjectHead = document.getElementById(tabHeads[i]);
        var tempObjectContent = document.getElementById(tabContent[i]);
        var stateFieldObj = document.getElementById(stateFieldId);

        if (tempObjectHead != null && tempObjectContent != null) {
            if (i == index) {
                tempObjectHead.className = "selected";
                tempObjectContent.className = "blockDisplay";
                stateFieldObj.value = i
                var argObject = new Object(); // global event handler argument object
                argObject.Tab = eventArg;
                Feratel.Website.Tosc.GlobalEventHandler.getPageInstance().raiseEvent("activateTab", argObject);
            } else {
                tempObjectHead.className = "";
                tempObjectContent.className = "noDisplay";
            }
        }
    }

}

// function for changing active tab
function activateInfoTab(index, stateFieldId, sufix) {
    var Heads = eval("tabInfoHeads" + sufix);
    var Content = eval("tabInfoContent" + sufix);
    for (var i in Heads) {
        var tempObjectHead = document.getElementById(Heads[i]);
        var tempObjectContent = document.getElementById(Content[i]);
        var stateFieldObj = document.getElementById(stateFieldId);
        if (tempObjectHead != null && tempObjectContent != null) {
            if (i == index) {
                tempObjectHead.className = "selected";
                tempObjectContent.className = "blockDisplay";
                stateFieldObj.value = i
            } else {
                tempObjectHead.className = "";
                tempObjectContent.className = "noDisplay";
            }
        }
    }
}
// function for generating the url in case of language change
function generateNewLanguagePageUrl(langSelectorID, currentLang) {
    var langSelectorObject = document.getElementById(langSelectorID);
    var newLangCode;
    var newUrl;
    var lang;
    if (langSelectorObject != null) {
        var newLangCode = langSelectorObject.control.get_value();
        if (newLangCode != null) {
            newUrl = window.location.href;
            if (newUrl.indexOf("/" + currentLang + "/") > 0) {
                newUrl = newUrl.replace("/" + currentLang + "/", "/" + newLangCode + "/");
            } else {
                newUrl = addReplaceURLStringParameter(newUrl, "lang", newLangCode);
            }
        }
    }
    return newUrl;
}

// function for generating the url in case of language change
function generateNewCurrencyPageUrl() {
    var newUrl;
    newUrl = window.location.href;
    newUrl = removeURLStringParameter(newUrl, "CR");

    return newUrl;
}

// function for changing pages (accommodation list/search result/brochures/etc)
function changePageNumber(newPage) {
    var newUrl = window.location.href;
    newUrl = addReplaceURLStringParameter(newUrl, "page", newPage);
    window.location.href = newUrl;
}


//function for printing the current page
function printPage() {
    this.window.print();
}


function openProductDetails(anchorObj, rowId, progressId, imageId, openImage, closeImage) {

    var rowObject = $get(rowId);
    var progressObject = $get(progressId);
    var imageObject = $get(imageId);
    var isOpen = "";

    if (rowObject.className == "") {
        rowObject.className = "noDisplay"
        imageObject.src = openImage;
        isOpen = "";
    } else {
        rowObject.className = "";
        imageObject.src = closeImage;
        isOpen = "1";
    }


    if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
    }

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showUpdateProgress);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hideUpdateProgress);

    function showUpdateProgress(sender, args) {
        progressObject.style.display = 'block';
    }

    function hideUpdateProgress(sender, args) {
        if (args.get_response().get_aborted()) {
            // reset the conteiner state
            rowObject.className = "noDisplay";
            progressObject.style.display = 'none';
            imageObject.src = openImage;
        } else {
            progressObject.style.display = 'none';
        }
        Sys.WebForms.PageRequestManager.getInstance().remove_beginRequest(showUpdateProgress);
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(hideUpdateProgress);

    }
    // make post back with apropriate arguments
    var id = anchorObj.id.replace(/_/g, "$");
    __doPostBack(id, isOpen);
}

//function to open a page in lytebox window
function openLyteBoxSize1(url) {
    var a = document.createElement("a");
    a.href = url;
    a.rel = "lyteframe";
    //a.title = title;
    a.rev = "width: 480px; height: 300px; scrolling: no;";
    myLytebox.start(a, false, true);
}
function openLyteBox(url, width, height) {
    var a = document.createElement("a");
    a.href = url;
    a.rel = "lyteframe";
    a.rev = "width: " + width + "px; height: " + height + "px; scrolling: no;";
    myLytebox.start(a, false, true);
}

function openPopupSize1(url) {
    openPopup(url, 480, 300);
}
function openPopup(url, width, height) {
    window.open(url, url, "width=" + width + ",height=" + height + ",location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0", true);
}

function showDayOfWeekName(containerId, dayOfWeekIndex) {

    var containerObj = document.getElementById(containerId);
    containerObj.innerHTML = DaysOfWeekArray[dayOfWeekIndex];
}


function OnDateSelected(sender, e) {
    var date = e.get_newDate();
    var firstDayOfWeek = sender.get_calendar()._firstDayOfWeek
    if (date != null) {
        dayIndex = date.getDay()
        showDayOfWeekName(sender.get_dayOfWeekControlID(), dayIndex);
    }
}

function onCheckBoxClick(chk, ddlId, cbxName, dlsName, lblName) {

    var combo = $find(ddlId);
    //prevent second combo from closing
    cancelDropDownClosing = true;
    //holds the text of all checked items
    var text = "";
    //holds the values of all checked items
    var values = "";
    //get the collection of all items
    var items = combo.get_items();
    //enumerate all items
    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var lp = 0;
        var chkNum = "00";
        var chk1, lbl;
        do {
            chk1 = $get(combo.get_id() + "_i" + i + "_" + dlsName + "_ctl" + chkNum + "_" + cbxName);
            if (chk1 != null) {
                if (chk1.checked) {
                    //var lbl = $get(combo.get_id() + "_i" + i + "_" + dlsName + "_ctl" + chkNum + "_" + lblName);
                    var lbl = $get("_rfdSkinned" + combo.get_id() + "_i" + i + "_" + dlsName + "_ctl" + chkNum + "_" + cbxName);
                    if (lbl != null) {
                        text += lbl.innerHTML + ",";
                    }
                }
                lp = lp + 1;
                chkNum = pad(lp);
            }

        } while (chk1 != null);
    }
    //remove the last comma from the string
    text = removeLastComma(text);

    if (text.length > 0) {
        //set the text of the combobox
        combo.set_text(text);
    }
    else {
        //all checkboxes are unchecked
        //so reset the control
        combo.set_text("");
    }
}

//this method removes the ending comma from a string
function removeLastComma(str) {
    return str.replace(/,$/, "");
}

function pad(int) {
    return int = (int < 10) ? '0' + int : int;
}

// function to prevent closing of telerik dropdown control
function stopPropagation(e) {
    e.cancelBubble = true;
    if (e.stopPropagation) {
        e.stopPropagation();
    }
}


function openAccommodationSearchDetailPanel(anchorObj, rowId, progressId, imageId, openImage, closeImage) {

    var rowObject = $get(rowId);
    var imageObject = $get(imageId);
    var isOpen = "";

    if (rowObject.className == "") {
        imageObject.src = openImage;
        rowObject.className = "noDisplay"
        isOpen = "";
    } else {
        imageObject.src = closeImage;
        rowObject.className = "";
        isOpen = "1";
    }
    var progressObject = $get(progressId);


    if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
    }

    if (isOpen == "1") {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showUpdateProgress);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hideUpdateProgress);
    }

    function showUpdateProgress(sender, args) {
        progressObject.style.display = 'block';
    }

    function hideUpdateProgress(sender, args) {
        if (args.get_response().get_aborted()) {
            // reset the conteiner state
            rowObject.className = "noDisplay";
            progressObject.style.display = 'none';
            imageObject.src = openImage;
        } else {
            progressObject.style.display = 'none';
        }
        Sys.WebForms.PageRequestManager.getInstance().remove_beginRequest(showUpdateProgress);
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(hideUpdateProgress);

    }
    // make post back with apropriate arguments
    var id = anchorObj.id.replace(/_/g, "$");
    __doPostBack(id, isOpen);
}

function highlightItems(sender, eventArgs) {
    sender.highlightAllMatches(sender.get_text());
}

function cancelLocationOpening(sender, eventArgs) {
    if (sender.get_text().length < 0) {
        eventArgs.set_cancel(true);
    }
}

function addHandler(obj, type, fn) {
    if (obj.attachEvent) {
        obj['e' + type + fn] = fn;
        obj[type + fn] = function() { obj['e' + type + fn](window.event); }
        obj.attachEvent('on' + type, obj[type + fn]);
    } else
        obj.addEventListener(type, fn, false);
}

function removeHandler(obj, type, fn) {
    if (obj.detachEvent) {
        obj.detachEvent('on' + type, obj[type + fn]);
        obj[type + fn] = null;
    } else
        obj.removeEventListener(type, fn, false);
}
function hideActivTooltip() {
    var activeToolTip = Telerik.Web.UI.RadToolTip.getCurrent();
    if (activeToolTip) activeToolTip.hide();
}



function DateEqual(date1, date2)
{
    return (date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate())                
}