/* GLOBAL JAVASCRIPT FUNCTIONS */

function fnPlaceData(url, nType, sName) {
    try {
        var xmlDoc = dbsRequest(url);
        if (xmlDoc != null) {
            var sHTML = ""
            for (var nFields = 0; nFields < xmlDoc.childNodes.length; nFields++) {
                if (nType == 5) {
                    sHTML += "<option value=\"" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "\">" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "</option>"
                }

                else if (nType == 4) {
                    if (nFields > 0)
                        sHTML += " &nbsp;";
                    sHTML += "<input style=\"height:15px;\" type=\"checkbox\" name=\"" + sName + "\" value=\"" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "\" id=\"fld" + nType + "" + nFields + "\"><label for=\"fld" + nType + "" + nFields + "\">" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "</label>";
                }

                else if (nType == 3) {
                    if (nFields > 0)
                        sHTML += " &nbsp;";
                    sHTML += "<input style=\"height:15px;\" type=\"radio\" name=\"" + sName + "\" value=\"" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "\" id=\"fld" + nType + "" + nFields + "\"><label for=\"fld" + nType + "" + nFields + "\">" + dbsGetNodeText(xmlDoc.childNodes[nFields].childNodes[0]) + "</label>";
                }
            }
            document.write(sHTML);
        }
    } catch (e) {
    }
}

function expand_bar(bar_Id) {
    var bar = document.getElementById("bar_" + bar_Id);
    if (bar != null) {
        bar.style.display = ("block" == bar.style.display ? "none" : "block");
    }
}

function changeClass(obj, opr) {
    if (opr == 1) {
        obj.style.font = "bold 12px";
        obj.style.color = "#ff9393";
    }
    else {
        obj.style.font = "bold 12px";
        obj.style.color = "#000000";
    }
}

function fnSetQuickNavAction(oSelect) {
    var sOpts = document.getElementById(oSelect).options;
    var sValue = sOpts[sOpts.selectedIndex].value;
    if (sValue != "-1") {
        var saValue = sValue.split("||");
        if (saValue[0] == "1")
            window.open(saValue[1], "_blank");
        else
            window.location = saValue[1];
    }
    else {
        sOpts.selectedIndex = 0;
    }
    return;
}

function OLD_fnSetQuickNavAction(oSelect) {
    var sValue = oSelect[oSelect.selectedIndex].value;
    if (sValue != "-1") {
        var saValue = sValue.split("||");
        if (saValue[0] == "1")
            window.open(saValue[1], "_blank");
        else
            window.location = saValue[1];
    }
    else {
        oSelect.selectedIndex = 0;
    }
    return;
}


function fnShowFullImg(sFile) {
    if (sFile.toLowerCase().indexOf("/_cut/") != -1) {
        var sFileTemp = sFile.toLowerCase().replace("_cut/", "");
        var nPos = sFileTemp.lastIndexOf("/");
        var sFileName = sFileTemp.substr(nPos + 1, sFile.length - nPos);
        if (sFileName.length > 13) {
            sFileName = sFileName.substr(13, sFileName.length - 13);
            var sFilePath = sFile.substr(0, nPos + 1);
            sFile = sFilePath + sFileName;
        }
    }
    window.open(sAppDomain + "/ViewImage.aspx?Image=" + sFile, "image", "top=50,left=50,width=" + (screen.availWidth - 100) + ",height=" + (screen.availHeight - 100) + ",scrollbars");
}

function fnShowGalleryFullImg(sFile, nID, nCategoryID) {
    window.open(sAppDomain + "/ViewGalleryImage.aspx?ArticleID=" + nID + "&CategoryID=" + nCategoryID + "&Image=" + sFile, "image", "fullscreen=1,scrollbars,scrollbars");
}

function fnShowGallery(iCatID, iArticleID) {
    window.open(sAppDomain + "/ViewGallery.aspx?CategoryID=" + iCatID + "&ArticleID=" + iArticleID, "gallery", "top=50,left=50,width=" + (screen.availWidth - 100) + ",height=" + (screen.availHeight - 100) + ",scrollbars=no");
}

function dbsSetURL(sName) {
    window.location.hash = sName.replace("#", "");
}

function dbsMail(box, server) {
    window.location = "mailto:" + box + "@" + server;
}

function fnSetQuickNavState(sCatID) {
    try {
        var selQuickNav = document.getElementById("ctlQuickNav");
        for (var i = 0; i < selQuickNav.options.length; i++) {
            if (selQuickNav.options[i].id == "opt" + sCatID) {
                selQuickNav.options[i].selected = true;
                break;
            }
        }
    } catch (e) { }
}

function fnTalkBack(nCategoryID, nArticleID, sTitle) {
    window.open(sAppDomain + "/TalkBacks/Talkback.aspx?CategoryID=" + nCategoryID + "&ArticleID=" + nArticleID + "&Title=" + sTitle, "talkback", "top=60,left=30,width=440,height=450,scrolling=\"no\"")
}

function fnSendFriend(nCategoryID, sUrl, sTitle) {
    window.open(sAppDomain + "/TalkBacks/SendFriend.aspx?CategoryID=" + nCategoryID + "&ArticleUrl=" + escape(sUrl) + "&Title=" + sTitle, "sendfriend", "top=60,left=30,width=400,height=436,scrolling=\"no\"")
}

/******************************** Fixing Flash Problemi in IE *********************************/
// Universal event handler
// Please don't use "onload = functionName" etc
// use instead this "addEvent(window, 'load', functionName);"
function addEvent(obj, strEvent, objFunction) {
    if (obj.addEventListener) {
        obj.addEventListener(strEvent, objFunction, true);
        return true;
    }
    else if (obj.attachEvent) {
        var returnValue = obj.attachEvent("on" + strEvent, objFunction);
        return returnValue;
    }
    else return false;
}

function removeEvent(obj, strEvent, objFunction) {
    if (obj.addEventListener) {
        obj.removeEventListener(strEvent, objFunction, true)
    }
    else if (obj.attachEvent) {
        obj.detachEvent("on" + strEvent, objFunction);
    }
}

function fnPrintFlash(sFileURL, nWidth, nHeight, id) {
    if (window.ActiveXObject)
        document.write("<object type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\">");
    else
        document.write("<object type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\" data=\"" + sFileURL + "\">");
    document.write("<param name=\"movie\" value=\"" + sFileURL + "\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("</object>");
}

function fnPrintFlashHTML(html) {
    document.write(html);
}

function fnPrintFlashAdv(sFileURL, nWidth, nHeight, id, sFVars) {
    fnPrintFlashAdv1(sFileURL, nWidth, nHeight, id, sFVars, true);
}

function fnPrintFlashAdv1(sFileURL, nWidth, nHeight, id, sFVars, bTransparent) {
    if (window.ActiveXObject)
        document.write("<object type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\">");
    else
        document.write("<object FlashVars=\"" + sFVars + "\" type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\" data=\"" + sFileURL + "\">");
    document.write("<param name=\"movie\" value=\"" + sFileURL + "\">");
    document.write("<param name=\"quality\" value=\"high\">");
    if (bTransparent)
        document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("<param name=\"FlashVars\" value=\"" + sFVars + "\">");
    document.write("</object>");
}

//// Cache Ratings images
//var dbsRatingStar = new Image();
//dbsRatingStar.src = "_Pics/RatingStar.gif";
//var dbsRatingFullStar = new Image();
//dbsRatingFullStar.src = "_Pics/RatingFullStar.gif";

function fnFilterStates(nCountryID, nStateID, ctlID) {
    var ctlStates = document.getElementById(ctlID);
    if (ctlStates != null) {
        var xmlDoc = dbsRequest("_Subscription/GetStates.asp?CountryID=" + nCountryID);
        if (xmlDoc != null) {
            ctlStates.options.length = 0;
            if (xmlDoc.hasChildNodes()) {
                var oStates = xmlDoc.getElementsByTagName("state");
                for (var nStates = 0; nStates < oStates.length; nStates++) {
                    var sStateID = dbsGetAttributeText(oStates[nStates], 0);
                    var sStateTitle = dbsGetAttributeText(oStates[nStates], 1);
                    var bSelected = (nStateID.toString() == dbsGetAttributeText(oStates[nStates], 0));

                    var oOption = new Option(sStateTitle, sStateID);
                    ctlStates.options.length++;
                    ctlStates.options[ctlStates.options.length - 1] = oOption;
                    ctlStates.options[ctlStates.options.length - 1].selected = bSelected;
                }
                ctlStates.disabled = false;
            }
            else {
                ctlStates.disabled = true;
                var oOption = new Option("none", "");
                ctlStates.options.length++;
                ctlStates.options[ctlStates.options.length - 1] = oOption;
            }
        }
    }
}


function fnSetDefaultFormData(oFrm) {
    try {
        var xmlDoc = dbsRequest(sAppDomain + "/Forms/GetUserDetails.ashx");
        for (var nAttributes = 0; nAttributes < xmlDoc.attributes.length; nAttributes++) {
            if (document.getElementById(xmlDoc.attributes[nAttributes].name)) {
                if (dbsGetAttributeText(xmlDoc, nAttributes) != "")
                    document.getElementById(xmlDoc.attributes[nAttributes].name).value = dbsGetAttributeText(xmlDoc, nAttributes);
            }
        }
    } catch (e) {
    }
}

function fnPrintWin(URL) {
    window.open(URL, "_blank");
}

function fnShowSelectElemByClass(sClassName) {
    if (dbsBrowserType == "ie") {
        var colList = document.getElementsByTagName("SELECT");
        for (var i = 0; i < colList.length; i++) {
            if (colList[i].className.toLowerCase() == sClassName.toLowerCase() || sClassName == "") {
                colList[i].style.visibility = "visible";
            }
        }
    }
}

function fnHideSelectElemByClass(sClassName) {
    if (dbsBrowserType == "ie") {
        var colList = document.getElementsByTagName("SELECT");
        for (var i = 0; i < colList.length; i++) {
            if (colList[i].className.toLowerCase() == sClassName.toLowerCase() || sClassName == "") {
                colList[i].style.visibility = "hidden";
            }
        }
    }
}

function fnSetDir(ctl) {
    var pat = "[\u0000- !-@[-`{-\u00bf\u00d7\u00f7\u02b9-\u02ff\u2000-\u2bff]";
    var ltrRegEx = new RegExp("^" + pat + "*([0-9]" + pat + "*$|[A-Za-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02b8\u0300-\u0590\u0800-\u1fff\u2c00-\ufb1c\ufdfe-\ufe6f\ufefd-\uffff])");
    var rtlRegEx = new RegExp("^" + pat + "*$");

    var val = ctl.value;
    ctl.style.direction = ltrRegEx.test(val) ? "ltr" : (rtlRegEx.test(val) ? "" : "rtl")
}

function fnSetAction(oFrm, sAction) {
    oFrm.action = sAction;
}

function fnSetWizardAction(oFrm, nFormID) {
    oFrm.action = "Forms/SubmitForm.aspx?CategoryID=" + sCurrentCat + "&FormID=" + nFormID;
}

function fnPrintFlashPlaceHolder(width, height) {
    return;
}

function dbsWarpAsSoap(content) {
    return "<?xml version='1.0' encoding='utf-8'?>" +
        "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
        "<soap:Body>" + content + "</soap:Body></soap:Envelope>";
}
function fnSelectChanged(osrc, groupName) {
    osrc.name = groupName;
}
