var popups = new Array();
var popupsCount = 0;

function openWin(url,name,arguments)
{
	popups[popupsCount] = window.open(url,name,arguments);
	if(popups[popupsCount] != null) popups[popupsCount].focus();
	popupsCount++;
}
		
function closeWin()
{
    for(var openPops = 0; openPops < popupsCount; openPops++)
    {
        if(popups[openPops] != null)
        {
            if(typeof(popups[openPops]) == "object") popups[openPops].close();
        }
    }
}

function getCookieValue(cKey)
{
	cookieString = String(document.cookie);
	cookieVals = cookieString.split(";");
	for(i = 0; i < cookieVals.length; i++)
	{
		cookieVals[i] = cookieVals[i].replace(" ","");
		if(cookieVals[i].substring(0,cKey.length) == cKey) 
        {
            return(cookieVals[i].substring(cKey.length+1,cookieVals[i].length));
        }
	}
}

//get the cursor position
function getPosition(e)
{
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY)
    {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else
    {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

//JS error handling START
window.onerror = myOnError;

function myOnError(msg,url,lno)
{
    //replace chars
    while(msg.indexOf("'") > -1) msg = msg.replace("'","");
    while(msg.indexOf("\"") > -1) msg = msg.replace("\"","");
    while(msg.indexOf(";") > -1) msg = msg.replace(";","");
    while(msg.indexOf("|") > -1) msg = msg.replace("|","");
    while(msg.indexOf(">") > -1) msg = msg.replace(">","");
    while(msg.indexOf("<") > -1) msg = msg.replace("<","");
    while(msg.toLowerCase().indexOf("exec") > -1) msg = msg.replace(/exec/i,"ex_ec");
    while(msg.toLowerCase().indexOf("declare") > -1) msg = msg.replace(/declare/i,"de_clare");
    
    //skip msgs from defect header/footer pages
    if(msg.indexOf("self.name") == 0) return true;
    if(msg.indexOf("ctrl") == 0) return true;
    if(msg.indexOf("urchinTracker") == 0) return true;
    if(msg.indexOf("s is") == 0) return true;

	if(document == null) return true;
	if(document.images == null) return true;
	if(document.images["jsErrorPixel"] == null) return true;
    document.images["jsErrorPixel"].src = "jserrorpixel.aspx?url=" + escape(url) + "&msg=" + escape(msg) + "&lno=" + escape(lno);
	return true;
}
//JS error handling END