/*
    In order for the javasciprt whitespace module to remove comments properly, use the block comments
    and not the line comments "//"
*/  

function displayMsg(m)
{
    return confirm(m);
}


/* popup syntax: 
   <a href="link.exe" onclick="return popup('popup_page.aspx', [name], [width], [height])>Open Popup!</a> */

function poll_popup(link, n, w, h)
{
    var p = window.open(link, n, "width="+w+",height="+h+",location=0,menubar=0,toolbar=0,scrollbars=1,status=0,resizable=1");
    p.focus();
    
    return true;
}

/* popup syntax: 
   <a href="popup_link.html" onclick="return popup(this, [name], [width], [height])>Open Popup!</a> */

function popup(link, n, w, h)
{
	var p = window.open(link.getAttribute('href'), n, "width="+w+",height="+h+",location=0,menubar=0,toolbar=0,scrollbars=0,status=0");
	p.focus();
	
	return false;
}

function appendParent(parent, child)
{
	newParent = parent.cloneNode(false);
	newParent.appendChild(child.cloneNode(true));
	child.parentNode.replaceChild(newParent, child);
}

function initListRowBehavior()
{
	var divs = document.getElementsByTagName('div');
	for (var d=0; d<divs.length; d++)
	{
		var div = divs[d];
		if (div.className == "list")
		{
			var rows = div.getElementsByTagName('tr');
			for (var r=0; r<rows.length; r++)
			{
				var row = rows[r];
				var links = row.getElementsByTagName('a');
				if(links.length == 1)
				{
				    // This part avoids double popups
				    var currentLink = links[0];
				    if (currentLink.className == "singlePopupRedLink") {
				        currentLink.style.display = "none";
				        currentLink.parentNode.innerHTML += "<span class=\"singlePopupRedLink\" style=\"color: Red; text-decoration: underline \">" + currentLink.innerHTML + "</span>";
				    } else if (currentLink.className == "singlePopupWhiteLink") {
				        currentLink.style.display = "none";
				        currentLink.parentNode.innerHTML += "<span class=\"singlePopupWhiteLink\" style=\"color: White; text-decoration: none \">" + currentLink.innerHTML + "</span>";
				    }
				    
				    row.onmouseover = function()
					{
						this.className = 'hover';
					}
					row.onmouseout = function()
					{
						this.className = '';
					}
					row.onclick = function()
					{
						var link = this.getElementsByTagName('a')[0];
						var url = link.getAttribute('href');
						if(link.getAttribute('target') == '_blank')
						{
						    window.open(url);
						}
						else
						{
						    window.open(url, '_self');
						}
					}
				}
				else
				{
					var link;
					for (var l=0; l<links.length; l++)
					{
					    link = links[l];
						if (link.parentNode.nodeName == 'H4') break;
					}
					var img = row.getElementsByTagName('img')[0];
					if (link && img)
					{
						appendParent(link, img);
					}
				}
			}
		}
	}
}

function popWindow(url, params)
{
    newWindow=window.open(url,'popWin', params);
    if (newWindow.opener == null) newWindow.opener = self;
        newWindow.focus();
}


function warnuser()
{
    if (confirm("There has been no activity for some time.\n\nClick 'OK' if you wish to continue your session,\nor click 'Cancel' to log out.\n\nFor your security if you are unable to respond to this message within 2 minutes you will be logged out automatically."))
    {
        //post the page to itself
        window.location.reload();
    }
    else
    {
        document.location.href = "logout.aspx";
    }
}



var windowLoadFunctions = [initListRowBehavior];


window.onload = function()
{
	for( var i = 0; i < windowLoadFunctions.length; i ++ )
	{
	    windowLoadFunctions[ i ]();
	}
	
	// This pops up the amd survey 2% of the time when the user visits any page on the site
    /*if (Math.random() < 0.02 && document.cookie.indexOf("viewedSurvey=true") < 0)
    {
        var yearFromNow = new Date();
        yearFromNow.setFullYear(yearFromNow.getFullYear() + 1);
        document.cookie = "viewedSurvey=true;path=/;expires=" + yearFromNow.toGMTString();
        window.open("http://www.amdsurveys.com/se.ashx?s=5A1E27D25F6D3308&refurl=" + location.href);
    }*/
}