﻿function parseBinary(v) { return parseInt(v,2); }
function parseDecimal(v) { return parseInt(v,10); }
function parseHexaecimal(v) { return parseInt(v,16); }

//Retreives a reference to a given object on a page by it's ID tag name.
function getElementFromID() {
    var objDocument;
    var idName;

    switch (arguments.length) {
        case 0:
            return null;
        case 1:
            objDocument = document;
            idName = arguments[0];
            break;
        case 2:
            objDocument = arguments[0];
            idName = arguments[1];
            break;
    }

    if (objDocument.getElementById)
        return objDocument.getElementById(idName);
    else if (objDocument.all)
        return objDocument.all[idName];
    else if (objDocument.layers)
        return objDocument.layers[idName];

    return null;
}

//Redirect to a URL
function GoTo(url) {
    if (browserInfo.ie4) window.location.href = url;
    else window.location = url;
}

//Redirect to a URL, replacing the current URL within history
function GoToR(url) {
    window.location.replace(url);
}

//Redirect a specified Frame to a URL
function GoToFrame(Frame, url) {
    if (browserInfo.ie4) Frame.location.href = url;
    else Frame.location = url;

}

//Redirect a specified Frame to a URL, replacing the current URL within history
function GoToFrameR(Frame, url) {
    Frame.location.replace(url);
}

//Open a new window @ 30,30 and size of 755,510 with nothing but a scrollbar
function OpenWindowNone(url) {
    OpenWindowHere(url, "", "30", "30", "755", "510", "No", "No", "No", "No", "No", "Yes", "No", "No");
}

//Open a new window @ 30,30 and size of 755,460 with nothing but a scrollbar and toolbar
function OpenWindowButtons(url) {
    OpenWindowHere(url, "", "30", "30", "755", "460", "No", "No", "No", "No", "No", "Yes", "No", "Yes");
}

//Open a new window @ 0,0 and size of 1024,734 with all bars
function OpenWindowFull(url) {
    OpenWindowHere(url, "", "0", "0", "1024", "734", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes");
}

//Open a new window with size of 1024x734 centered over the calling window
function OpenWindowFullCentered(strURL) {
    OpenWindowCentered(strURL, 1014, 648, "No", "No");
}

//Open a new window with size of 1024x734 centered over the calling window
function OpenWindowFullCenteredMenu(strURL) {
    OpenWindowCentered(strURL, 1014, 600, "No", "No", "Yes");
}

//Open a new window with size of 1024x734 centered over the calling window
function OpenWindowFullCenteredButtons(strURL, sMenu) {
    var iWidth = 1014;
    var iHeight = 570;
    var bResizable = false;
    var bScrollable = true;
    var vWinHeight;
    var vWinWidth;
    var vWinLeft;
    var vWinTop;

    if (browserInfo.ie) {
        vWinHeight = document.body.clientHeight;
        vWinWidth = document.body.clientWidth;
        vWinLeft = window.screenLeft;
        vWinTop = window.screenTop;

        if (browserInfo.ie7) vWinHeight -= 100;
        else vWinHeight -= 45;

        iWidth += 10;
        iHeight += 36;

        if (browserInfo.avant && (iHeight < 151)) iHeight = 151; //Avant Bug
    }
    else {
        vWinHeight = window.innerHeight - 45;
        vWinWidth = window.innerWidth;
        vWinLeft = window.screenX;
        vWinTop = window.screenY;

        iWidth += 6;
        iHeight += 54;
    }

    //Avant's offset is from inner left/top not screen left/top   
    var iX = ((vWinWidth / 2) + (browserInfo.avant ? 0 : vWinLeft) - (iWidth / 2));
    if (browserInfo.ie) iX += 4;

    if (iWidth > screen.width) {
        iWidth = screen.width - 12;
        iX = 0;
    }

    var iY = ((vWinHeight / 2) + (browserInfo.avant ? 0 : vWinTop) - (iHeight / 2));
    if (iY < 0) iY = 0;
    if (browserInfo.safari) iY += 86;
    else if (browserInfo.firefox) iY += 138;
    else if (browserInfo.ns) iY += 100;
    else if (browserInfo.op) iY += 53;

    if (iHeight > (browserInfo.win32 ? screen.Height - 75 : screen.Height)) {
        iHeight = screen.Height - 8;
        if (browserInfo.win32) iHeight -= 75;
        iY = 0;
    }

    var allowResize = ((bResizable == true) ||
							(bResizable == "true") || (bResizable == "True") ||
							(bResizable == "yes") || (bResizable == "Yes")) ? "Yes" : "No";

    var allowScroll = ((bScrollable == true) ||
							(bScrollable == "true") || (bScrollable == "True") ||
							(bScrollable == "yes") || (bScrollable == "Yes")) ? "Yes" : "No";

    var menu = "No";
    if (sMenu && sMenu != "") menu = sMenu;
    var win = OpenWindowHere(strURL, "", iX, iY, iWidth, iHeight, "No", "No", "No", menu, allowResize, allowScroll, "Yes", "Yes");
    if (win && browserInfo.op) win.moveTo(iX, iY);
}

//Open a new window with size of 1024x734 centered over the calling window with no scrolling
function OpenWindowTutorial(strURL) {
    OpenWindowFullCentered(strURL);
}

//Open a new window with size of w,h centered over the calling window with nothing but a scrollbar
function OpenWindowCentered(strURL, iWidth, iHeight, bResizable, bScrollable, sMenu) {
    var vWinHeight;
    var vWinWidth;
    var vWinLeft;
    var vWinTop;

    if (browserInfo.ie) {
        vWinHeight = document.body.clientHeight;
        vWinWidth = document.body.clientWidth;
        vWinLeft = window.screenLeft;
        vWinTop = window.screenTop;

        if (browserInfo.ie7) vWinHeight -= 100;
        else vWinHeight -= 45;

        iWidth += 10;
        iHeight += 36;

        if (browserInfo.avant && (iHeight < 151)) iHeight = 151; //Avant Bug
    }
    else {
        vWinHeight = window.innerHeight - 45;
        vWinWidth = window.innerWidth;
        vWinLeft = window.screenX;
        vWinTop = window.screenY;

        iWidth += 6;
        iHeight += 54;
    }

    //Avant's offset is from inner left/top not screen left/top   
    var iX = ((vWinWidth / 2) + (browserInfo.avant ? 0 : vWinLeft) - (iWidth / 2));
    if (browserInfo.ie) iX += 4;

    if (iWidth > screen.width) {
        iWidth = screen.width - 12;
        iX = 0;
    }

    var iY = ((vWinHeight / 2) + (browserInfo.avant ? 0 : vWinTop) - (iHeight / 2));
    if (iY < 0) iY = 0;
    if (browserInfo.safari) iY += 86;
    else if (browserInfo.firefox) iY += 138;
    else if (browserInfo.ns) iY += 100;
    else if (browserInfo.op) iY += 53;

    if (iHeight > (browserInfo.win32 ? screen.Height - 75 : screen.Height)) {
        iHeight = screen.Height - 8;
        if (browserInfo.win32) iHeight -= 75;
        iY = 0;
    }

    var allowResize = ((bResizable == true) ||
							(bResizable == "true") || (bResizable == "True") ||
							(bResizable == "yes") || (bResizable == "Yes")) ? "Yes" : "No";

    var allowScroll = ((bScrollable == true) ||
							(bScrollable == "true") || (bScrollable == "True") ||
							(bScrollable == "yes") || (bScrollable == "Yes")) ? "Yes" : "No";

    var menu = "No";
    if (sMenu && sMenu != "") menu = sMenu;
    var win = OpenWindowHere(strURL, "", iX, iY, iWidth, iHeight, "No", "No", "No", menu, allowResize, allowScroll, "No", "No");
    if (win && browserInfo.op) win.moveTo(iX, iY);
}

/**
* OpenWindow allows for opening another browser window,
* URL = url to open with
* title = name to show in the titlebar (can not have spaces)
* x,y,width,height = dimensions of the window
* each paramter after is a string "Yes" or "No" whether or not you want each option
*/
function OpenWindowHere(url, title, x, y, width, height, CopyHistory, Links, AddressBar, MenuBar, Resizable, Scrollbars, StatusBar, ToolBar) {
    var strSettings = "width=" + width + ",height=" + height +
						  ((browserInfo.ie) ? (",left=" + x) : (",screenX=" + x)) +
						  ((browserInfo.ie) ? (",top=" + y) : (",screenY=" + y)) +
						  ",copyhistory=" + (browserInfo.ie7 && CopyHistory == "Yes" ? "1" : CopyHistory) +
						  ",directories=" + (browserInfo.ie7 && Links == "Yes" ? "1" : Links) +
						  ",location=" + (browserInfo.ie7 && AddressBar == "Yes" ? "1" : AddressBar) +
						  ",menubar=" + (browserInfo.ie7 && MenuBar == "Yes" ? "1" : MenuBar) +
						  ",resizable=" + (browserInfo.ie7 && Resizable == "Yes" ? "1" : Resizable) +
						  ",scrollbars=" + (browserInfo.ie7 && Scrollbars == "Yes" ? "1" : Scrollbars) +
						  ",status=" + (browserInfo.ie7 && StatusBar == "Yes" ? "1" : StatusBar) +
						  ",toolbar=" + (browserInfo.ie7 && ToolBar == "Yes" ? "1" : ToolBar);
    return window.open(url, title, strSettings);
}

//Method retrieves the cookie value if there is one
//Please note this gets called on customer pages
//to prevent users from linking directly to .asp and .shtml.
function findCookie(name) {
    var dc = document.cookie;
    var cname = name + "=";
    var clen = dc.length;
    var cbegin = 0;

    while (cbegin < clen) {
        var vbegin = cbegin + cname.length;

        if (dc.substring(cbegin, vbegin) == cname) {
            var vend = dc.indexOf(";", vbegin);
            if (vend == -1)
                vend = clen;
            return unescape(dc.substring(vbegin, vend));
        }
        cbegin = dc.indexOf(" ", cbegin) + 1;

        if (cbegin == 0)
            break;
    }
    return null;
}

/**************************************************************************************/
// cString object
// Provides enhanced string functions: Left, Right, etc.
/**************************************************************************************/
function cString() {
    this.value = "";
    if ((arguments.length > 0) && (typeof(arguments[0]) == "string")) {
        this.value = arguments[0];
    }
}

cString.prototype.Length = function() {
    return this.value.length;
}
cString.prototype.Left = function(i) {
    if (this.value.length > (i - 2))
        return this.value.substring(0, i);
    else
        return this.value;
}
cString.prototype.Right = function(i) {
    var r = (this.value.length - i);
    if (r > 0)
        return this.value.substring(r);
    else
        return this.value;
}
