//  GetElementById
function GetElementById(elementId) {
    if (document.getElementById) {
        return document.getElementById(elementId);
    }
    else if (document.all) {
        return document.all[elementId];
    }
    else return null;
}

// clickHandler
function clickHandler(srcElement, depth, img1, img2) {
    var targetId, srcElement, targetElement;

    if (srcElement.className == "menutreeviewimg") {
        targetId = srcElement.id + "d";
        targetElement = GetElementById(targetId);
        if (targetElement.style.display == "none") {
            targetElement.style.display = "";
            srcElement.src = depth + "images/menu/" + img2 + ".gif";
        }
        else {
            targetElement.style.display = "none";
            srcElement.src = depth + "images/menu/" + img1 + ".gif";
        }
    }
}

// Set Language
function SetLanguage(pagename) {
    if (window.location.href != 'undefined' && window.location.href != null) {
        var pageurl = GetPageUrlFromPageName(pagename);
        window.location.href = pageurl;
    } 
}

function GetPageUrlFromPageName(pagename) {
    var pageurl = pagename;
    var currenturl = window.location.href;
    if (currenturl.indexOf("?") > -1 || currenturl.indexOf("#") > -1) {
        var loc = currenturl.indexOf(".aspx");
        if (loc > -1) pageurl = pagename + currenturl.substr(loc + 5, currenturl.length - (loc + 5));
    }
    if (pageurl.substr(pageurl.length - 1, 1) == "#") pageurl = pageurl.substr(0, pageurl.length - 1);
    return pageurl;                
}

function ShowGoogleLanguageBox(el1, el2, pagelang) {
    var googleElement = GetElementById(el1);
    var langElement = GetElementById(el2);

    if (googleElement != null && langElement != null) {
        googleElement.style.display = "";
        langElement.style.display = "none";
        
        var pageElement = GetElementById("page");
        pageElement.style.marginTop = "22px";
        
        try { new google.translate.TranslateElement({ pageLanguage: pagelang }, 'google_translate_element'); }
        catch(e) 
        {}
    }
}

function HideGoogleLanguageBox(pagename) {
    // Only way is to refresh page.
    var pageurl = GetPageUrlFromPageName(pagename);
    window.location.href = pageurl;
}

function googleTranslateElementInit(pagelang) {
    // Leave this blank otherwise always executed by google's element.js.
}

// Set SetFontSize
function SetFontSize(direction) {
    var size = "100%";
    var newsize = null;

    var content = document.getElementById("pagecontent"); // document.getElementsByTagName("body")[0].style.fontSize
    if (content != null) {
        if (content.style.fontSize != "") size = content.style.fontSize;
        if (direction == "up") {
            newsize = (parseInt(size.substring(0, size.length - 1)) + 10).toString() + "%";
        }
        else {
            newsize = (parseInt(size.substring(0, size.length - 1)) - 10).toString() + "%";
        }
        if (newsize) content.style.fontSize = newsize;
    }
}

// Set Bookmark
function setBookmark(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, ""); // Mozilla Firefox Bookmark	
    }
    else if (window.external) {
        window.external.AddFavorite(url, title); // IE Favorite
    }
    else if (window.opera && window.print) {
        return true; // Opera Hotlist
    }
}

// Show Dialog
function ShowDialog(dlgurl, dlgscroll, dlgwidth, dlgheight) {
    var settings = "";
    var args = "";
    var popup;

    settings = "resizable=0,toolbar=0,directories=0,status=0,location=no,scrollbars=" + dlgscroll + ",width=" + (parseInt(dlgwidth) + 40).toString() + ",height=" + (parseInt(dlgheight) + 20).toString() + ",top=200,left=100";
    popup = window.open(dlgurl, "Dialog", settings);

    /*
    if (document.all) {
        settings = "dialogWidth=" + (parseInt(dlgwidth) + 40).toString() + "px;dialogHeight=" + (parseInt(dlgheight) + 20).toString() + "px;scrollbars=auto;border=thin;help=no;";
        popup = window.showModalDialog(dlgurl, args, settings);
    }
    else {
        settings = "resizable=0,toolbar=0,directories=0,status=0,location=no,scrollbars=" + dlgscroll + ",width=" + (parseInt(dlgwidth) + 40).toString() + ",height=" + (parseInt(dlgheight) + 20).toString() + ",top=200,left=100";
        popup = window.open(dlgurl, "Dialog", settings);
        //popup.dialogArguments = args;
    }
    */
}

// Show AudioDialog
function ShowNewWindow(dlgurl, dlgscroll, dlgwidth, dlgheight) {
    //var settings = "dialogWidth=" + dlgwidth + "px;dialogHeight=" + dlgheight + "px;scrollbars=auto;border=thin;help=no;";
    //var popup = window.showModelessDialog(dlgurl, label, settings);
    var settings = "resizable=0,toolbar=0,directories=0,status=0,location=no,scrollbars=" + dlgscroll + ",width=" + dlgwidth + ",height=" + dlgheight + ",top=200,left=100";
    var popup = window.open(dlgurl, "Audio", settings);
}

//  Trim
function trim(text) {
    return text.replace(/^\s+|\s+$/g, "");
}

// ==========================================
// FP Functions
// v1.0
// ==========================================

function FP_swapImg() {
    var doc = document, args = arguments, elm, n;
    doc.$imgSwaps = new Array();
    for (n = 2; n < args.length; n += 2) {
        elm = FP_getObjectByID(args[n]);
        if (elm) {
            doc.$imgSwaps[doc.$imgSwaps.length] = elm;
            elm.$src = elm.src;
            elm.src = args[n + 1];
        }
    }
}

function FP_getObjectByID(id, o) {
    var c, el, els, f, m, n;
    if (!o) o = document;
    if (o.getElementById) el = o.getElementById(id);
    else if (o.layers) c = o.layers;
    else if (o.all) el = o.all[id];
    if (el) return el;
    if (o.id == id || o.name == id) return o;
    if (o.childNodes) c = o.childNodes;
    if (c) for (n = 0; n < c.length; n++) { el = FP_getObjectByID(id, c[n]); if (el) return el; }
    f = o.forms;
    if (f) for (n = 0; n < f.length; n++) {
        els = f[n].elements;
        for (m = 0; m < els.length; m++) {
            el = FP_getObjectByID(id, els[n]);
            if (el) return el;
        }
    }
    return null;
}

