﻿
var SpecialEmailAddress = "";

var crossWindowParam = "";

/* ************************************************** */
/*                   COMMON FUNCTIONS                 */
/* ************************************************** */

function getUrlVars(argURL)
{
    var vars = [], hash;

    var hashes = null;
    
    if (argURL == undefined) {
//        if (window.location.href.indexOf('#')>0) {
//            hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
//        }
//        else {
            hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
//        }
    }
    else {
//        if (argURL.indexOf('#')>0) {
//            hashes = argURL.slice(argURL.indexOf('#') + 1).split('&');
//        }
//        else {
            hashes = argURL.slice(argURL.indexOf('?') + 1).split('&');
//        }
    }
    
    for(var i = 0; i < hashes.length; i++)
    {
        if (hashes[i].indexOf('=')>0) {
            hash = hashes[i].split('=');
            
            if (hash[0].indexOf('?')>0) {
                vars.push("REDIRECT");
                vars["REDIRECT"] = hash[0].slice(0, hash[0].indexOf('?')).replace(/(%20)/g, " ");
                
                hash[0] = hash[0].slice(hash[0].indexOf('?') + 1);
            }
            vars.push(hash[0].toUpperCase());
            
            vars[hash[0].toUpperCase()] = hash[1].replace(/(%20)/g, " ");
        }
    }
//    alert(vars);
    return vars;
}

function Dictionary(){
    this.First;
    this.Last;
    this.Count = 0;

    // Add method
    this.Add = function(skey,scontent)
    {
        if(!this.Exists(skey))
        {
            var Cnode = new dicNode(skey,scontent);
            if (this.Count == 0)
            {
                this.First = this.Last = Cnode;
                this.First.next = this.Last;
            }
            else
            {
                Cnode.next = this.First;
                this.First = Cnode;
            }
            this.Count++;
        }
    };
    
    // Exists method
    this.Exists = function(skey)
    {
        var isex = false;
        var temp = this.First;
        
        for(var i=1;i <= this.Count;i++)
        {
            if(temp.key == skey)
            {
                isex = true;
                break;
            }
            else
            {
                temp = temp.next;
            }
        }
        return isex;
    };
    
    // return value by key
    this.Item = function(skey)
    {
        var scontent = '';
        var temp = this.First;
        
        if(String(skey).match(/^[0-9]\d*$/)==null)
        {
            for(var i=1;i <= this.Count;i++)
            {
                if(temp.key == skey)
                {
                    scontent = temp.content;
                    break;
                }
                else
                {
                    temp = temp.next;
                }
            }
        }
        else
        {
            var index = parseInt(skey);
            for(var i = (this.Count-1);i >= 0 ;i--)
            {
                if(i == index)
                {
                    scontent = temp.content;
                    break;
                }
                else
                {
                    temp = temp.next;
                }
            }
        }
        return scontent;
    };
    
    // Return key by index
    this.Key = function(index)
    {
        var skey = '';
        var temp = this.First;
        for(var i = (this.Count-1);i >= 0 ;i--)
        {
            if(i == index)
            {
                skey = temp.key;
                break;
            }
            else
            {
                temp = temp.next;
            }
        }
        return skey;
    };
    
    this.length = function() {
        return this.Count;
    }
    
    // Dictionary node class
    function dicNode(skey,scontent)
    {
        this.key = skey;
        this.content = scontent;
        this.next = null;
    } 
}
function getAppURL() {
    var strURL = window.location.href;
    
    strURL = strURL.replace(/[#].*$/g, "").replace(/[?].*$/g, "");
    strURL = strURL.left(strURL.lastIndexOf("/") + 1);
    //alert(strURL);
    return strURL;
}

function getPageURL(decode) {
    //alert("Malek: 'GetPageURL' function. ");
    var strURL = window.location.href.replace(/(:)/g, "%3a"); 
    //var strRedir = strURL.replace(/^.*[#]/g, "").replace(/[?].*$/g, "");
    
    //strURL = strURL.replace(/[#].*$/g, "").replace(/[?].*$/g, "");
    
//    var hashURLvars = getUrlVars();
//    
//    if (strURL.toLowerCase().indexOf("product.aspx") >= 0) {
//        if (hashURLvars["LEVEL"] != undefined) strURL += "?LEVEL=" + hashURLvars["LEVEL"];
//        if (hashURLvars["MENUNAME"] != undefined) strURL += "&MENUNAME=" + hashURLvars["MENUNAME"];
//        if (hashURLvars["CATEGORYID"] != undefined) strURL += "&CATEGORYID=" + hashURLvars["CATEGORYID"];
//        if (hashURLvars["PRODUCTID"] != undefined) strURL += "&PRODUCTID=" + hashURLvars["PRODUCTID"];
//        //if (strRedir != "") strURL += "&REDIRECT=" + strRedir;
//        if (hashURLvars["REDIRECT"] != undefined) {
//            if (hashURLvars["REDIRECT"].indexOf("http")<0) {
//                if (hashURLvars["REDIRECT"] != undefined) strURL += "&REDIRECT=" + hashURLvars["REDIRECT"];
//            }
//            else if (strRedir.indexOf("http")<0) {
//                if (strRedir != "") strURL += "&REDIRECT=" + strRedir;
//            }
//            else {
//                strURL += "&REDIRECT=Includes/ProductOverview.aspx";
//            }
//        }
//    }
//    else if (strURL.toLowerCase().indexOf("gsastatecontracts.aspx") >= 0) {
//        if (hashURLvars["REDIRECT"] != undefined) strURL += "?REDIRECT" + hashURLvars["REDIRECT"];
//        if (hashURLvars["STATE"] != undefined) strURL += "&STATE=" + hashURLvars["STATE"];
//    }
//    else {
//    }
        
    if (decode) {
        strURL = strURL.replace(/[\&]/g, "%26");
    }
       
    return strURL;
}

function DetectBrowserName()
{
	if(window.opera!=null) return "Opera";
	var info=window.navigator.userAgent;
	
	if(info.indexOf("Firefox")!=-1) return "Firefox";
	if(info.indexOf("MSIE")!=-1) return "MSIE";
	if(info.indexOf("Netscape")!=-1) return "Netscape";
	if(info.indexOf("Safari")!=-1) return "Safari";
	return "Other";
	
	// AJAX
	// Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7
}

String.prototype.trim = function() 
{ 
    if (this == null) {
        return null;
    }
    else {
        return this.replace(/(^\s*)|(\s*$)/g, ""); 
    }
}
String.prototype.left = function(argLength) {
	if (this == null) {
        return null;
    }
    else if (argLength <= 0) {
		return "";
    }
    else if (argLength >= this.length) {
		return this;
    }
    else {
        return this.substr(0, argLength);
    }
}
String.prototype.right = function(argLength) {
	if (this == null) {
        return null;
    }
    else if (argLength <= 0) {
		return "";
    }
    else if (argLength >= this.length) {
		return this;
    }
    else {
        //return this.substr(this.length - argLength, argLength);
        return this.substr(this.length - argLength);
    }
}

function GetEscapedCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            return GetCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) 
        {
            break;
        }
    }
    return null;
}

function GetCookie(name)
{
    var value = GetEscapedCookie(name);
    
    return value==null?null:unescape(value);
}

function GetUnescapedSubCookie(name, subname)
{
    var i = 0;    
    var vals = GetEscapedCookie(name).split("&");
    
    while (i < vals.length)
    {
        if (vals[i].indexOf(subname+"=") >= 0)
        {
            return vals[i].substring(vals[i].indexOf(subname+"=") + (subname+"=").length);
        }
        
        i++;
    }
    return null;
}

function GetSubCookie(name, subname)
{
    var value = GetUnescapedSubCookie(name, subname);
    
    return value==null?null:unescape(value);
}

function GetCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return document.cookie.substring(offset, endstr);
}

function SetCookie(name, value)
{
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : "/";
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null) 
    {
        expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    }
    //DelCookie(name);
    document.cookie = name + "=" + escape (value) 
        + ((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
        + ((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
        + ((secure == true) ? "; secure" : "");
}

function SetSubCookie(name, subname, value)
{
    var expdate = new Date();
    var argv = SetSubCookie.arguments;
    var argc = SetSubCookie.arguments.length;
//    var expires = (argc > 3) ? argv[3] : null;
//    var path = (argc > 4) ? argv[4] : null;
//    var domain = (argc > 5) ? argv[5] : null;
//    var secure = (argc > 6) ? argv[6] : false;
    var expires = null;
    var path =  "/";
    var domain = null;
    var secure = false;

    if(expires!=null) 
    {
        expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    }
    
    var cookievalue = GetEscapedCookie(name).replace("&"+subname+"="+(GetUnescapedSubCookie(name, subname)==null?"":GetUnescapedSubCookie(name, subname)), "");
    document.cookie = name + "=" + cookievalue + "&" + subname + "=" + escape(value) 
        + ((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
        + ((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
        + ((secure == true) ? "; secure" : "");
}
    
function DelCookie(name)
{
//    var exp = new Date();
//    exp.setTime (exp.getTime() - 1);
//    var cval = GetCookie (name);
//    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
    document.cookie = document.cookie.replace(GetCookie(name) + ";", "");
}

function loadFlash(flashvars, flashname, flashwidth, flashheight) {
    var strFlashObj = "";
    
    strFlashObj += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ flashwidth + '" height="' + flashheight + '" id="Upper_Menubar" align="middle">';
    strFlashObj += '<param name="allowScriptAccess" value="sameDomain" />';
    strFlashObj += '<param name="movie" value="' + flashname + '" />';
    strFlashObj += '<param name="quality" value="high" />';
    strFlashObj += '<param name="bgcolor" value="#ffffff" />';
    strFlashObj += '<param name="FlashVars" value="' + flashvars + '" />';
    strFlashObj += '<param name="wmode" value="transparent" />';
    strFlashObj += '<embed src="' + flashname + '" wmode="transparent" quality="high" bgcolor="#ffffff" width="' + flashwidth + '" height="' + flashheight + '" name="Upper Menubar" align="middle" flashvars="' + flashvars + '" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    strFlashObj += '</object>';
   
    document.write(strFlashObj);
}

function Cover(bottom, top, ignoreSize) {    
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';

    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

/*
 *	Main Function :		to append addition onclick event script to object
 *  Parameters    :		argObject<Object> : target object
 *  					argNewFunc<String>: string of a function to be appended
 *  Return Value  :		none
 */
function appendOnclickScript(argObject, argNewFunc) {	
	var sOldFunc = "";
	
	if (argObject == "undefined" || argNewFunc.trim() == "") {
	    return;
	}
	
	try {
		sOldFunc = argObject.getAttribute("onclick").toString();
	} 
	catch (e) {
	}
	
	switch (DetectBrowserName().toLowerCase()) {
		case "firefox":
		case "opera":
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onclick", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;
		case "msie": 
		    if (sOldFunc.trim() == "") {
		        argObject.onclick = new Function(argNewFunc);	
		    }
		    else {
		        if (sOldFunc.indexOf(argNewFunc) < 0) {
		            sOldFunc = sOldFunc.substring(22, sOldFunc.length -1).trim();
		            
			        argObject.onclick = new Function(sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			        
			        //argObject.onclick = new Function(sOldFunc.substring(22, sOldFunc.length -1) + argNewFunc);
			    }		
			}
			break;
		default:
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onclick", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;			
	}
}

/*
 *	Main Function :		to append addition onmouseup event script to object
 *  Parameters    :		argObject<Object> : target object
 *  					argNewFunc<String>: string of a function to be appended
 *  Return Value  :		none
 */
function appendOnmouseupScript(argObject, argNewFunc) {	
	var sOldFunc = "";
	
	if (argObject == "undefined" || argNewFunc.trim() == "") {
	    return;
	}
	
	try {
		sOldFunc = argObject.getAttribute("onmouseup").toString();
	} 
	catch (e) {
	}
	
	switch (DetectBrowserName().toLowerCase()) {
		case "firefox":
		case "opera":
//		    if (sOldFunc.indexOf(argNewFunc) < 0) {
//			    argObject.setAttribute("onmouseup", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
//			}
//			break;
		case "msie": 
		    if (sOldFunc.trim() == "") {
		        argObject.onmouseup = new Function(argNewFunc);	
		    }
		    else {
		        if (sOldFunc.indexOf(argNewFunc) < 0) {
		            sOldFunc = sOldFunc.substring(22, sOldFunc.length -1).trim();
		            
			        argObject.onmouseup = new Function(sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			        
			        //argObject.onmouseup = new Function(sOldFunc.substring(22, sOldFunc.length -1) + argNewFunc);
			    }		
			}
			break;
		default:
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onmouseup", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;			
	}
}

/*
 *	Main Function :		to append addition onchange event script to object
 *  Parameters    :		argObject<Object> : target object
 *  					argNewFunc<String>: string of a function to be appended
 *  Return Value  :		none
 */
function appendOnchangeScript(argObject, argNewFunc) {	
	var sOldFunc = "";
	
	if (argObject == "undefined" || argNewFunc.trim() == "") {
	    return;
	}
	
	try {
		sOldFunc = argObject.getAttribute("onchange").toString();
	} 
	catch (e) {
	}
	
	switch (DetectBrowserName().toLowerCase()) {
		case "firefox":
		case "opera":
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onchange", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;
		case "msie": 
		    if (sOldFunc.trim() == "") {
		        argObject.onchange = new Function(argNewFunc);	
		    }
		    else {
		        if (sOldFunc.indexOf(argNewFunc) < 0) {
		            sOldFunc = sOldFunc.substring(22, sOldFunc.length -1).trim();
		            
			        argObject.onchange = new Function(sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			    }		
			}
			break;
		default:		
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onchange", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;			
	}
}

/*
 *	Main Function :		to append addition onblur event script to object
 *  Parameters    :		argObject<Object> : target object
 *  					argNewFunc<String>: string of a function to be appended
 *  Return Value  :		none
 */
function appendOnblurScript(argObject, argNewFunc) {	
	var sOldFunc = "";
	
	if (argObject == "undefined" || argNewFunc.trim() == "") {
	    return;
	}
	
	try {
		sOldFunc = argObject.getAttribute("onblur").toString();
	} 
	catch (e) {
	}
	
	switch (DetectBrowserName().toLowerCase()) {
		case "firefox":
		case "opera":
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onblur", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;
		case "msie": 
		    if (sOldFunc.trim() == "") {
		        argObject.onblur = new Function(argNewFunc);	
		    }
		    else {
		        if (sOldFunc.indexOf(argNewFunc) < 0) {
		            sOldFunc = sOldFunc.substring(22, sOldFunc.length -1).trim();
		            
			        argObject.onblur = new Function(sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			        //argObject.onblur = new Function(sOldFunc.substring(22, sOldFunc.length -1) + argNewFunc);
			    }		
			}
			break;
		default:
			argObject.setAttribute("onblur", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			break;			
	}
}

/*
 *	Main Function :		to append addition onload event script to object
 *  Parameters    :		argObject<Object> : target object
 *  					argNewFunc<String>: string of a function to be appended
 *  Return Value  :		none
 */
function appendOnloadScript(argObject, argNewFunc) {	
	var sOldFunc = "";
	
	if (argObject == "undefined" || argNewFunc.trim() == "") {
	    return;
	}
	
	try {
		sOldFunc = argObject.getAttribute("onload").toString();
	} 
	catch (e) {
	}
	
	switch (DetectBrowserName().toLowerCase()) {
		case "firefox":
		case "opera":
		    if (sOldFunc.indexOf(argNewFunc) < 0) {
			    argObject.setAttribute("onload", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			}
			break;
		case "msie": 
		    if (sOldFunc.trim() == "") {
		        argObject.onload = new Function(argNewFunc);	
		    }
		    else {
		        if (sOldFunc.indexOf(argNewFunc) < 0) {
		            sOldFunc = sOldFunc.substring(22, sOldFunc.length -1).trim();
		            
			        argObject.onload = new Function(sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			        //argObject.onload = new Function(sOldFunc.substring(22, sOldFunc.length -1) + argNewFunc);
			    }		
			}
			break;
		default:
			argObject.setAttribute("onload", sOldFunc + (sOldFunc.right(1)==";"?"":";") + argNewFunc);
			break;			
	}
}

function doPostBack(objid) {
    var obj = window.top.$get(objid);

    if (obj == null || obj == "undefined") return;
    
    if (window.execScript && Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version >= 7) {
        window.top.execScript(obj.href);
    }
    else {
        var href = obj.href.replace(/%20/mg, " ").replace(/%22/mg, "'");
        var args;
        
        if (href.indexOf("'") > 0) {
            args = href.split("'");
        }
        else {
            args = href.split('"');
        }
        window.top.document.__doPostBack(args[1], args[3]);
        //setTimeout(href, 0);
    }
}

function ShowSignout(arg) {
    if (window.top.document.getElementById("uppermenu") == null || window.top.document.getElementById("uppermenu") == "undefined")
    {
        setTimeout("ShowSignout(" + arg + ");", 500);
        return;
    }
    else {
        var objLinks = window.top.document.getElementById("uppermenu").getElementsByTagName("A");
        if (arg == 1) {
            for (var iLoop=objLinks.length-1; iLoop>=0; iLoop--) {
                if (objLinks[iLoop].id.indexOf("lbnMenu7") > 0) {
                    objLinks[iLoop].style.display = "block";
                    break;
                }
            }
        }
        else {
            for (var iLoop=objLinks.length-1; iLoop>=0; iLoop--) {
                if (objLinks[iLoop].id.indexOf("lbnMenu7") > 0) {
                    objLinks[iLoop].style.display = "none";
                    break;
                }
            }
        }
    }
}


function forceHideUpdateprogress() {
    if (window.top.document.getElementById("ctl00_updateprogress") != undefined) {
        setTimeout('window.top.document.getElementById("ctl00_updateprogress").style.display = "none";', 1500);
    }
}