﻿// Cybercom Group North - 2008
//
// Function to jump to top url of current page
//
function gotoTopPage() {

    // Get current document URL
    var strTopPage = document.URL;

    // Find first occurence of '://'
    var iFirstSlashGrp = strTopPage.indexOf("://");
    if (iFirstSlashGrp != -1) { // If found

        // Find next slash after current found
        var iNextSlashGrp = strTopPage.indexOf("/", iFirstSlashGrp + 4);
        if (iNextSlashGrp != -1) {  // If found

            // Clip string of page URL
            strTopPage = strTopPage.substr(0, iNextSlashGrp);
        }
    }

    window.location = strTopPage;
}

// Use this function to change the backgroundimage of a tag
//
function setBackgroundImage(tagID, imageURL) {

    // If no args or empty args then return
    if (imageURL == "" || imageURL == null)
        return;

    // If browser supports layers, change layer background source
    if (document.layers) {
        document[tagID].background.src = imageURL == 'none' ? null : imageURL;
    }
    // If older browser, change background images
    else if (document.all) {
        document.all[tagID].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
    }
    // If newer browser, change background image
    else if (document.getElementById) {
        document.getElementById(tagID).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
    }
    return;
}

function DOMCall(name) {
    //Checks the DOM features available   
    if (document.layers)
    //checks document.layers        
        return document.layers[name];
    else if (document.all)
    //checks document.all        
        return document.all[name];
    else if (document.getElementById)
    //checks getElementById        
        return document.getElementById(name);
}

///
// Needed to setup right callback in Masterpage
function doresize_div() {
    resize_div("StageArea");
}

/// 
function resize_div(divTagName) {
    h = document.body.clientHeight - 107;
    if (divTagName != '') {

        var pageElement = DOMCall("Page");
        var stageElement = DOMCall(divTagName);

        //stageElement.style.width = pageElement.scrollLeft + pageElement.clientWidth + "px";

        if (h>0) {
            DOMCall(divTagName).style.height = h + "px";
        }
        if (typeof (nFlashHeight) != 'undefined') {

            var flashElement = DOMCall("FlashArea");

            if (h <= nFlashHeight) {

                if (h > 0) {
                    // Set height of flashArea
                    flashElement.style.height = h + "px";

                    // Turn on scroll (auto); needed for Firefox/Opera
                    flashElement.style["overflow"] = "auto";

                    // Show vertical scroll
                    flashElement.style["overflow-y"] = "scroll";
                    flashElement.style.overflowY = "scroll";

                    // Hide horizontal scroll
                    flashElement.style["overflow-x"] = "hidden";
                    flashElement.style.overflowX = "hidden";

                    flashElement.style.zIndex = 2000;
                }
                
            }
            else {
            
                // Set height to flashAreas height
                flashElement.style.height = nFlashHeight + "px";

                // Turn on scroll (auto) needed for Firefox/Opera
                flashElement.style["overflow"] = "hidden";

                // Hide vertical scroll
                //flashElement.style["overflow-y"] = "hidden";
                flashElement.style.overflowY = "hidden";

                // Hide horizontal scroll
                flashElement.style["overflow-x"] = "hidden";
                flashElement.style.overflowX = "hidden";

                flashElement.style.zIndex = 0;
            }
        }
    }
}


function openPrintoutWindow(iRecipeID) {
    // Get current document URL
    var strTopPage = document.URL;

    // Find first occurence of '://'
    var iFirstSlashGrp = strTopPage.indexOf("://");
    if (iFirstSlashGrp != -1) { // If found

        // Find next slash after current found
        var iNextSlashGrp = strTopPage.indexOf("/", iFirstSlashGrp + 4);
        if (iNextSlashGrp != -1) {  // If found

            // Clip string of page URL
            strTopPage = strTopPage.substr(0, iNextSlashGrp);
        }
    }

    window.open(strTopPage + "/Templates/Pages/PrintoutRecipe.aspx?ReceptID=" + iRecipeID, "RecipeWindow", "scrollbars=yes, status=no, toolbar=no, location=no, menubar=no, directories=no, resizable=yes, height=600, width=900");
}

function printPage() {
    window.print();
}
