//Replaces text in a field that .Net treats as invalid for submission on page.
function SubstituteTextFieldText(txtField) {
    if (txtField && txtField.value) {
        txtField.value = txtField.value.replace(/</g, "< ").replace(/<\s+/g, "< "); //< invalid when followed by a letter, !, #, / or ?
        txtField.value = txtField.value.replace(/&#/g, "& #"); //&# invalid always
    }
}

//This method correctly resets the border for a control in most browsers.
function resetBorder(element) {
    if (element && element.style) {
        element.style.borderStyle = "";
        element.style.borderColor = "";
        element.style.borderWidth = "";
    }
}

function show(objControl) {
    if (objControl) {
        if (typeof (objControl) == "string") objControl = getElementFromID(objControl);
        var c = $(objControl);
        c.css("visibility", "visible");
        c.show();
    }
}

function hide(objControl) {
    if (objControl) {
        if (typeof (objControl) == "string") objControl = getElementFromID(objControl);
        var c = $(objControl);
        c.css("visibility", "hidden");
        c.hide();
    }
}

function Tip(desc, width, alignment) {
    ddrivetip(desc, width, '', alignment);
}

function TipIsStillActive() {
    return enabletip; //From Tooltip dynamicdrive include
}

function UnTip() {
    hideddrivetip();
}

function highlightRow() {
    var objA;
    var objColorTo;
    var objColorToRGB;
    var objColorBkGnd = "#FFFFFF";
    var objColorAlternatingBkGnd = "#FFFFFF";

    switch (arguments.length) {
        case 0:
            return null;
        case 1:
            objA = arguments[0];
            objColor = "#DCDCB6";
            objColorRGB = "RGB(" +
				parseInt("0xDC") + ", " +
				parseInt("0xDC") + ", " +
				parseInt("0xB6") + ")";
            break;
        case 2:
            objA = arguments[0];
            objColor = arguments[1];
            if (objColor.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }
            objColorRGB = "RGB(" +
				parseInt(objColor.substr(1, 2), 16) + ", " +
				parseInt(objColor.substr(3, 2), 16) + ", " +
				parseInt(objColor.substr(5, 2), 16) + ")";
            break;
        case 3:
            objA = arguments[0];
            objColor = arguments[1];
            if (objColor.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }

            objColorRGB = "RGB(" +
				parseInt(objColor.substr(1, 2), 16) + ", " +
				parseInt(objColor.substr(3, 2), 16) + ", " +
				parseInt(objColor.substr(5, 2), 16) + ")";

            objColorBkGnd = arguments[2];
            if (objColorBkGnd.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }

            objColorAlternatingBkGnd = objColorBkGnd;
            break;
        case 4:
            objA = arguments[0];
            objColor = arguments[1];
            if (objColor.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }

            objColorRGB = "RGB(" +
				parseInt(objColor.substr(1, 2), 16) + ", " +
				parseInt(objColor.substr(3, 2), 16) + ", " +
				parseInt(objColor.substr(5, 2), 16) + ")";

            objColorBkGnd = arguments[2];
            if (objColorBkGnd.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }

            objColorAlternatingBkGnd = arguments[3];
            if (objColorAlternatingBkGnd.length != 7) {
                alert("Error, highlightRow(): Color must be in the format of \"#RRGGBB\".");
                return;
            }

            break;
    }

    var objTR = objA;
    if (objTR) {
        while (objTR && objTR.nodeName != "TR") {
            objTR = getParentElement(objTR);
        }

        if (objTR) {
            var objTable = getParentElement(objTR);
            var objTRs = getChildElements(objTable);
            if (objTRs != null) {
                var end = objTRs.length;
                for (var i = 0; i < end; i++) {
                    if (objTRs[i] && objTRs[i].style &&
					 ((objTRs[i].style.backgroundColor.toUpperCase() == objColor) ||
					  (objTRs[i].style.backgroundColor.toUpperCase() == objColorRGB))) {
                        if (i % 2 == 0)
                            objTRs[i].style.backgroundColor = objColorAlternatingBkGnd;
                        else
                            objTRs[i].style.backgroundColor = objColorBkGnd;
                    }
                }
            }

            objTR.style.backgroundColor = objColor;
        }
    }
}

function hasAttributeValue(obj, attname)
{
    return (getAttributeValue(obj, attname) != null);
}

function getAttributeValue(obj, attname)
{
    if ((obj != null) && (attname != null)) { if (attname != "") {
        if (browserInfo.ie) { if (attname.toUpperCase() == "CLASS") attname = "className"; else if (attname.toUpperCase() == "FOR") attname = "htmlFor"; }
        if (obj.getAttribute) { if (obj.getAttribute(attname) != null) { return obj.getAttribute(attname); } }
    } }
    return "";
}

function setAttributeValue(obj, attname, newvalue)
{
    if ((obj != null) && (attname != null)) { if (attname != "") {
        if (browserInfo.ie) { if (attname.toUpperCase() == "CLASS") attname = "className"; else if (attname.toUpperCase() == "FOR") attname = "htmlFor"; }
        if (newvalue == null) newvalue = "";
        if (obj.setAttribute) { obj.setAttribute(attname, newvalue); }
    } }
}

/**************************************************************************************/
// Generic methods to find parent and child elements
/**************************************************************************************/
function getParentElement(obj) {
    if (obj.parentElement) return obj.parentElement;
    else if (obj.parentNode) return obj.parentNode;
    else if (obj.parent) return obj.parent;
    else return null;
}

function getParentTable(obj) {
    while (obj && obj.nodeName && (obj.nodeName != "TABLE")) {
        obj = getParentElement(obj);
    }
    return obj;
}

function getParentTableRow(obj) {
    while (obj && obj.nodeName && (obj.nodeName != "TR")) {
        obj = getParentElement(obj);
    }
    return obj;
}

function getChildElements(obj) {
    if (obj.children) return obj.children;
    else if (obj.childNodes) return obj.childNodes;
    else return null;
}

/// Gets a child TABLE element
/// <param index=0>Parent web control</param>
/// <param index=1>N: Specifies to return the Nth TABLE element</param>
/// <returns>The Nth (or last) child TABLE element belonging to a parent control.</returns>
function getChildTable() {
    var objParent = null;
    var targetNodeCount = 1;
    var returnValue = null;
    
    switch (arguments.length)  {
        case 0:
            return null;
        case 1:
            objParent = arguments[0];
            break;
        case 2:
            objParent = arguments[0];
            targetNodeCount = arguments[1];
            break;
    }
    
    if (objParent && (objParent != null))
    {
        var objChildren = getChildElements(objParent);
        if (objChildren != null) {
            var end = objChildren.length;
            var nodeCount = 1;
            for (var i=0; i<end; i++) {
                if (objChildren[i].nodeName == "TABLE")
                {
                    if (nodeCount == targetNodeCount)
                    {
                        return objChildren[i];
                    }
                    else
                    {
                        nodeCount++;
                        returnValue = objChildren[i];
                    }
                }
            }
        }
    }
    
    return returnValue;
}

/**************************************************************************************/
// Browse Methods
/**************************************************************************************/

/// Highlights a row in a browse
/// <param index=0>New row to highlight</param>
/// <param index=1>Previous row to remove highlighting from</param>
/// <param index=2>Class to use for the highlight.</param>
function highlightBrowseRow() {
    var objTR;
    var objPreviousTR;
    var objClassName;
    
    if (arguments.length < 3) return null;

    objTR = arguments[0];
    objPreviousTR = arguments[1];
    objClassName = arguments[2];

    if (objTR != null) {
        if (objPreviousTR != null) setAttributeValue(objPreviousTR, "class", getAttributeValue(objPreviousTR, "previousClass"));
        setAttributeValue(objTR, "previousClass", getAttributeValue(objTR, "class"));
        setAttributeValue(objTR, "class", objClassName);
    }
}

/// Scroll the column headers and fixed columns with the rest of the browse
/// <param index=0>Scroll event object</param>
function onBrowseScroll(e) {
	var EE = eventElement(e);
	if (isDefined(EE))
	{
		var BROWSE_BODY = EE;
		if (isDefined(BROWSE_BODY))
		{
			var BROWSE_ID = BROWSE_BODY.id.substring(0, BROWSE_BODY.id.lastIndexOf("_"));
			var BROWSE = getElementFromID(BROWSE_ID);
		    var BROWSE_HEADER = getElementFromID(BROWSE_ID + "_Header");
    		BROWSE_BODY = getElementFromID(BROWSE_ID + "_Body");
    		
    		if (isDefined(BROWSE_HEADER) && (BROWSE_HEADER.scrollLeft != BROWSE_BODY.scrollLeft))
    			BROWSE_HEADER.scrollLeft = BROWSE_BODY.scrollLeft;
    
    		if (getAttributeValue(BROWSE, "hasfixedcolumns").toUpperCase() == "TRUE")
    		{
    			var BROWSE_FIXEDBODY = getElementFromID(BROWSE_ID + "_FixedBody");
    			if(isDefined(BROWSE_FIXEDBODY) && (BROWSE_FIXEDBODY.scrollTop != BROWSE_BODY.scrollTop))
    				BROWSE_FIXEDBODY.scrollTop = BROWSE_BODY.scrollTop;
    		}
        }
    }
}

/// Scroll the columns in the main browse as the fixed columns scroll
/// <param index=0>Scroll event object</param>
function onBrowseFixedBodyScroll(e) {
	var EE = eventElement(e);
	if (isDefined(EE))
	{
		var BROWSE_BODY = getParentTable(EE).parentNode;
		if (isDefined(BROWSE_BODY))
		{
			var BROWSE_ID = BROWSE_BODY.id.replace("Fixed","");
			var BROWSE = getElementFromID(BROWSE_ID);

			if (isDefined(BROWSE))
			{
				BROWSE.scrollTop -= eventMouseScrollDelta(e)*50;
			}
		}
	}
}

/// Highlight/dehighlight row when clicking on a row
/// <param index=0>Click event object</param>
function onBrowseBodyClick(e) {
	var ROW = getParentTableRow(eventElement(e));
	if (isDefined(ROW))
	{
		var ALTERNATEROW = null;
		var BROWSE_BODY = getParentTable(ROW).parentNode;
		if (isDefined(BROWSE_BODY))
		{
			var BROWSE_ID = BROWSE_BODY.id.substring(0, BROWSE_BODY.id.lastIndexOf("_"));
			var BROWSE = getElementFromID(BROWSE_ID);
			if (isDefined(BROWSE))
			{
				if (getAttributeValue(BROWSE, "hasfixedcolumns").toUpperCase() == "TRUE")
				{
					var BROWSE_ALTERNATEBODY = getElementFromID(BROWSE_ID + "_FixedBody");
					if (BROWSE_BODY.id.indexOf("Fixed")>-1)
						BROWSE_ALTERNATEBODY = getElementFromID(BROWSE_ID + "_Body");
					
					var BROWSE_ALTERNATEBODY_T = getChildTable(BROWSE_ALTERNATEBODY);
					if (isDefined(BROWSE_ALTERNATEBODY_T))
						ALTERNATEROW = BROWSE_ALTERNATEBODY_T.rows[ROW.rowIndex];
				}
				
				eval("var PreviousIndex = " + BROWSE_ID + "_PreviousIndex");
				if (PreviousIndex >= 0)
				{
				    highlightBrowseRow(ROW, getParentElement(ROW).rows[PreviousIndex], "bDataRowSelected");
					if (isDefined(ALTERNATEROW))
					{
						var ALTERNATEROW_PARENT = getParentElement(ALTERNATEROW);
						if (isDefined(ALTERNATEROW_PARENT))
							highlightBrowseRow(ALTERNATEROW, ALTERNATEROW_PARENT.rows[PreviousIndex], "bDataRowSelected");
					}
				}
				else
				{
				    highlightBrowseRow(ROW, null, "bDataRowSelected");
					if (isDefined(ALTERNATEROW))
					    highlightBrowseRow(ALTERNATEROW, null, "bDataRowSelected");
				}
				
				eval(BROWSE_ID + "_PreviousIndex = ROW.rowIndex;");

				//The scrolling event must always fire on the main body, not the fixed body so it syncs correctly
				if ((parseDecimal(ROW.offsetTop) < parseDecimal(BROWSE_BODY.scrollTop)) && ROW.scrollIntoView) {
					if (BROWSE_BODY.id.indexOf("Fixed")>-1)
						ALTERNATEROW.scrollIntoView(true);
					else
						ROW.scrollIntoView(true);
				}
				if ((parseDecimal(ROW.offsetTop) + parseDecimal(ROW.offsetHeight)) > 
					 (parseDecimal(BROWSE_BODY.scrollTop) + parseDecimal(BROWSE_BODY.clientHeight)) && ROW.scrollIntoView) {
					if (BROWSE_BODY.id.indexOf("Fixed")>-1)
						ALTERNATEROW.scrollIntoView(false);
					else
						ROW.scrollIntoView(false);
				}
			}
		}
	}
}

/**************************************************************************************/
// cRECT object
// Rectangle providing left, top, width, height properties and methods to get
// various web-page related Rectangles
/**************************************************************************************/
function cRECT() {
    this.left = 0;
    this.top = 0;
    this.width = 0;
    this.height = 0;
}

cRECT.prototype.getLeft = function() { return (this.left ? this.left : 0) + "px"; }
cRECT.prototype.getTop = function() { return (this.top ? this.top : 0) + "px"; }
cRECT.prototype.getWidth = function() { return (this.width ? this.width : 0) + "px"; }
cRECT.prototype.getHeight = function() { return (this.height ? this.height : 0) + "px"; }
cRECT.prototype.toString = function() {
    return "[Position: " +
      (this.left ? this.left : 0) + " , " +
      (this.top ? this.top : 0) +
      " | Size: " +
      (this.width ? this.width : 0) + " x " +
      (this.height ? this.height : 0) + "]";
}

function getDocumentRect() {
    var returnValue = new cRECT();

    returnValue.left = 0;
    returnValue.top = 0;

    if (self.innerHeight) // all except Explorer
    {
        returnValue.width = self.innerWidth;
        returnValue.height = self.innerHeight;

        var pr = getPageRect();
        if (pr.width < returnValue.width) returnValue.width = pr.width;
    }
    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    {
        returnValue.width = document.documentElement.clientWidth;
        returnValue.height = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        returnValue.width = document.body.clientWidth;
        returnValue.height = document.body.clientHeight;
    }

    return returnValue;
}

function getPageRect() {
    var returnValue = new cRECT();

    returnValue.left = 0;
    returnValue.top = 0;

    var sW = document.body.scrollWidth;
    var sH = document.body.scrollHeight;
    var oW = document.body.offsetWidth;
    var oH = document.body.offsetHeight;

    returnValue.width = (sW > oW) ? sW : oW;
    returnValue.height = (sH > oH) ? sH : oH;

    return returnValue;
}

function getViewportRect(objControl) {
    var returnValue = getDocumentRect();

    if (objControl) {
        if (objControl.pageYOffset) // all except Explorer
        {
            returnValue.left = objControl.pageXOffset;
            returnValue.top = objControl.pageYOffset;
        }
        else if (objControl.scrollTop) // Explorer
        {
            returnValue.left = objControl.scrollLeft;
            returnValue.top = objControl.scrollTop;
        }
    }
    else {
        if (self.pageYOffset) // all except Explorer
        {
            returnValue.left = self.pageXOffset;
            returnValue.top = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
        {
            returnValue.left = document.documentElement.scrollLeft;
            returnValue.top = document.documentElement.scrollTop;
        }
        else if (document.body) // all other Explorers
        {
            returnValue.left = document.body.scrollLeft;
            returnValue.top = document.body.scrollTop;
        }
    }

    return returnValue;
}

function getScreenRect() {
    var returnValue = new cRECT();

    returnValue.left = 0;
    returnValue.top = 0;
    returnValue.width = parseInt(screen.availWidth, 10);
    returnValue.height = parseInt(screen.availHeight, 10);

    return returnValue;
}

function getWindowRect() {
    var returnValue = new cRECT();

    var win = window;
    if (arguments.length > 0) win = arguments[0];

    returnValue.left = win.screenLeft ? parseInt(win.screenLeft, 10) : (win.screenX ? parseInt(win.screenX, 10) : 0);
    returnValue.top = win.screenTop ? parseInt(win.screenTop, 10) : (win.screenY ? parseInt(win.screenY, 10) : 0);

    if (win.self.outerWidth) {
        returnValue.width = parseInt(win.self.outerWidth, 10);
        returnValue.height = parseInt(win.self.outerHeight, 10);
    }
    else if (win.document.body.offsetWidth) {
        //IE has no properties; must do some comparisons to compute it.
        //If using DOCTYPE, documentElement has the properties, not body
        var cWidth = parseInt(win.document.documentElement.offsetWidth ? win.document.documentElement.offsetWidth : win.document.body.offsetWidth, 10);
        var cHeight = parseInt(win.document.documentElement.offsetHeight ? win.document.documentElement.offsetHeight : win.document.body.offsetHeight, 10);
        win.resizeTo(cWidth, cHeight);
        var rWidth = parseInt(win.document.documentElement.offsetWidth ? win.document.documentElement.offsetWidth : win.document.body.offsetWidth, 10);
        var rHeight = parseInt(win.document.documentElement.offsetHeight ? win.document.documentElement.offsetHeight : win.document.body.offsetHeight, 10);
        returnValue.width = 2*cWidth - rWidth;
        returnValue.height = 2*cHeight - rHeight;
        win.resizeTo(returnValue.width, returnValue.height);
        //IE's browser top/left is not available, rather the body's top/left is returned; must resize to compute it.
        //offset the moveto by 8,100 (toolbars/border) to reduce window jitter
        var cLeft = returnValue.left;
        var cTop = returnValue.top;
        win.moveTo(cLeft-8, cTop-100);
        var mLeft = parseInt(win.screenLeft, 10);
        var mTop = parseInt(win.screenTop, 10);
        returnValue.left = 2*cLeft - mLeft - 8;
        returnValue.top = 2*cTop - mTop - 100;
        win.moveTo(returnValue.left, returnValue.top);
    }

    return returnValue;
}

function getControlRect(objControl) {
    var returnValue = new cRECT();
    if (objControl) {
        if (typeof (objControl) == "string")
            objControl = getElementFromID(objControl);

        returnValue.left = parseInt(objControl.offsetLeft, 10);
        if (returnValue.left == 0 && objControl.style.left) returnValue.left = parseInt(objControl.style.left, 10);
        returnValue.top = parseInt(objControl.offsetTop, 10);
        if (returnValue.top == 0 && objControl.style.top) returnValue.top = parseInt(objControl.style.top, 10);
        returnValue.width = parseInt(objControl.offsetWidth, 10);
        if (returnValue.width == 0 && objControl.style.width) returnValue.width = parseInt(objControl.style.width, 10);
        returnValue.height = parseInt(objControl.offsetHeight, 10);
        if (returnValue.height == 0 && objControl.style.height) returnValue.height = parseInt(objControl.style.height, 10);

        var objControlParent = objControl.offsetParent;
        var tLeft, tTop;
        while (objControlParent) {
            if (objControlParent.offsetLeft) {
                tLeft = parseInt(objControlParent.offsetLeft, 10);
                if (tLeft == 0) returnValue.left += parseInt(objControlParent.style.left, 10);
                else returnValue.left += parseInt(tLeft, 10);
            }
            else if (objControlParent.style.left) {
                returnValue.left += parseInt(objControlParent.style.left, 10);
            }
            if (objControlParent.offsetTop) {
                tTop = parseInt(objControlParent.offsetTop, 10);
                if (tTop == 0) returnValue.top += parseInt(objControlParent.style.top, 10);
                else returnValue.top += parseInt(tTop, 10);
            }
            else if (objControlParent.style.top) {
                returnValue.top += parseInt(objControlParent.style.top, 10);
            }
            objControlParent = objControlParent.offsetParent;
        }
    }
    return returnValue;
}

/**************************************************************************************/
// cColor object
// Color providing R, G, B properties and methods to generate RGB or HEX output
/**************************************************************************************/
function cColor() {
    this.color_defs =
      [
         {
             regexpression: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
             example: ["rgb(123, 234, 45)", "rgb(255,234,245)"],
             process: function(bits) {
                 return
                 [
                    parseInt(bits[1]),
                    parseInt(bits[2]),
                    parseInt(bits[3])
                ];
             }
         },
         {
             regexpression: /^(\w{2})(\w{2})(\w{2})$/,
             example: ["#00ff00", "336699"],
             process: function(bits) {
                 return
                 [
                    parseInt(bits[1], 16),
                    parseInt(bits[2], 16),
                    parseInt(bits[3], 16)
                ];
             }
         },
         {
             regexpression: /^(\w{1})(\w{1})(\w{1})$/,
             example: ["#fb0", "f0f"],
             process: function(bits) {
                 return
                 [
                    parseInt(bits[1] + bits[1], 16),
                    parseInt(bits[2] + bits[2], 16),
                    parseInt(bits[3] + bits[3], 16)
                ];
             }
         }
      ];

    this.r = 0;
    this.g = 0;
    this.b = 0;

    if (arguments.length == 1) {
        parse(arguments[0]);
    }
}

cColor.prototype.parse = function(sColor) {
    var regexpression, processor, bits, channels;

    for (var i = 0; i < this.color_defs.length; i++) {
        regexpression = this.color_defs[i].regexpression;
        processor = this.color_defs[i].process;
        bits = regexpression.exec(sColor);
        if (bits) {
            channels = processor(bits);
            this.r = channels[0];
            this.g = channels[1];
            this.b = channels[2];
        }
    }

    this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
    this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
    this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);
}

cColor.prototype.toRGB = function() {
    return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")";
}

cColor.prototype.toHex = function() {
    var r = this.r.toString(16);
    var g = this.g.toString(16);
    var b = this.b.toString(16);
    if (this.r < 17) r = "0" + r;
    if (this.g < 17) g = "0" + g;
    if (this.b < 17) b = "0" + b;
    return '#' + r + g + b;
}

/**************************************************************************************/
// Redirection Method & Enums
/**************************************************************************************/

var WinTargets = {
    Self: "_self",
    Parent: "_parent",
    Top: "_top",
    Blank: "_blank",
    New: "_blank",
    Domain: "_",
    Window: ""
}

var WinAligns = {
    TopLeft: "top-left",
    BottomLeft: "bottom-left",
    TopRight: "top-right",
    BottomRight: "bottom-right",
    Center: "center",
    CenterParent: "center-parent"
}

var WinDimensions = {
    MaxWidth: 1024,
    MaxHeight: 734
}

function redirectTo() {
    var url, target, replace, width, height, alignment, resizable, scrollable, menubar, statusbar, toolbar;
    if (arguments.length > 10) toolbar = arguments[10]; else toolbar = false;
    if (arguments.length > 9) statusbar = arguments[9]; else statusbar = false;
    if (arguments.length > 8) menubar = arguments[8]; else menubar = false;
    if (arguments.length > 7) scrollable = arguments[7]; else scrollable = true;
    if (arguments.length > 6) resizable = arguments[6]; else resizable = false;
    if (arguments.length > 5) alignment = arguments[5]; else alignment = WinAligns.CenterParent;
    if (arguments.length > 4) height = arguments[4]; else height = WinDimensions.MaxHeight;
    if (arguments.length > 3) width = arguments[3]; else width = WinDimensions.MaxWidth;
    if (arguments.length > 2) replace = arguments[2]; else replace = false;
    if (arguments.length > 1) target = arguments[1]; else target = WinTargets.Self;
    if (arguments.length > 0) url = arguments[0]; else return null;

    if (target == WinTargets.Domain)
        target = new $location(url).isCurrentWebsite() ? WinTargets.Self : WinTargets.Blank;

    if (replace) {
        if (target == WinTargets.Self) window.location.replace(url);
        else if (target == WinTargets.Parent) window.parent.location.replace(url);
        else if (target == WinTargets.Top) window.top.location.replace(url);
        else if (target != WinTargets.Blank) eval(target + ".location.replace(url);");
    }
    else {
        if (target == WinTargets.Self) window.location = url;
        else if (target == WinTargets.Parent) window.parent.location = url;
        else if (target == WinTargets.Top) window.top.location = url;
        else if (target == WinTargets.Blank) window.open(url);
        else if (target != WinTargets.Window) eval(target + ".location = url;");
        else {
            var x, y;
            var sr = getScreenRect();
            var wr = getWindowRect(window.top); //Use top in case I'm framed
            
            switch (alignment) {
                case WinAligns.TopLeft: x = 0; y = 0; break;
                case WinAligns.BottomLeft: x = 0; y = sr.height - height; break;
                case WinAligns.TopRight: x = sr.width - width; y = 0; break;
                case WinAligns.BottomRight: x = sr.width - width; y = sr.height - height; break;
                case WinAligns.Center: x = sr.width/2 - width/2; y = sr.height/2 - height/2; break;
                default: x = (wr.left+wr.width/2) - width/2; y = (wr.top+wr.height/2) - height/2; break;
            }
                        
            if (browserInfo.ie) {
                resizable = resizable ? "1" : "0";
                scrollable = scrollable ? "1" : "0";
                menubar = menubar ? "1" : "0";
                statusbar = statusbar ? "1" : "0";
                toolbar = toolbar ? "1" : "0";
            } else {
                resizable = resizable ? "yes" : "no";
                scrollable = scrollable ? "yes" : "no";
                menubar = menubar ? "yes" : "no";
                statusbar = statusbar ? "yes" : "no";
                toolbar = toolbar ? "yes" : "no";
            }

            //Browser-adjusted width/height correction
            if (browserInfo.firefox) 
            {
                width -= 12; 
                height -= 71; 
            }
            else if (browserInfo.ie) 
            { 
                width -= 15
                height -= 70; 
            }
            else
            {
                width -= 14;
                height -= 63;
            }
            
            
            var strSettings = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y +
                ",copyhistory=0,directories=0,location=0" + ",menubar=" + menubar + ",resizable=" + resizable + 
                ",scrollbars=" + scrollable + ",status=" + statusbar + ",toolbar=" + toolbar;

            window.open(url, "", strSettings);
        }
    }
}

function SelectjQueryTab(tabObj, tab, url) {
    $(tabObj).tabs("select", tab);
    return ((new $location(location.href)).pathname.toLowerCase() != (new $location(url)).pathname.toLowerCase());
}

function SelectjQueryTabR(tabObj, tab, url)
{
    if ((new $location(location.href)).pathname.toLowerCase() != (new $location(url)).pathname.toLowerCase())
    {
        redirectTo(url);
    }
    else
    {
        $(tabObj).tabs("select", tab);
    }
}

$(function() {
    if (window.location.hash)
    {
        //Prevents scrolling when navigating to a jquery tab.
        setTimeout("$('html, body').scrollTop(0);", 325);
    }
});

