var objWin;
var objWinBar;

function launchApp(sURL) {
	var intHeight = screen.availHeight - 60;
	var intWidth = screen.availWidth;
	var strAttString = "height=" + intHeight + ",width=" + intWidth + ",status=yes,toolbar=no,menubar=no,location=no,top=0,left=0,resizable=yes,scrollbars=yes";
	if (document.frmOverride) {
		objWin = window.open("override.asp", "MyWin", strAttString);
		} else {
		objWin = window.open(sURL, "MyWin", strAttString);
	}
}
function singleLaunch(sURL) {
	if (document.frmOverride) {
		document.frmOverride.frmURL.value=sURL;
	}
	if (objWin && objWin.open && !objWin.closed){
		alert("You already have an instance of this application open in your current session.");
	} else {
		launchApp(sURL);
	}
}
	
function launchAppBar(sURL) {
	var intHeight = screen.availHeight - 60;
	var intWidth = screen.availWidth;
	var strAttString = "height=" + intHeight + ",width=" + intWidth + ",status=yes,toolbar=yes,menubar=yes,location=no,top=0,left=0,resizable=yes";
	if (document.frmOverride) {
		objWinBar = window.open("override.asp", "BarWin", strAttString);
	} else {
		objWinBar = window.open(sURL, "BarWin", strAttString);
	}
}

function singleLaunchBar(sURL) {
	if (document.frmOverride) {
		document.frmOverride.frmURL.value=sURL;
	}
	if (objWinBar && objWinBar.open && !objWinBar.closed){
		alert("You already have an instance of this application open in your current session.");
	} else {
		launchAppBar(sURL);
	}
}

function showProcess(url) 
{
	if (document.all('process')) 
		document.all('process').style.display="block"; 
	window.location.replace(url);
}

function trackLink(iNewWindow, linkId, lobKey, titleKey, url)
{
	var destUrl = new String(url);
	destUrl = destUrl.replace(/\?/g, "|QM|");
	destUrl = destUrl.replace(/=/g, "|EQ|");
	destUrl = destUrl.replace(/&/g, "|AM|");
	destUrl = destUrl.replace(/;/g, "|SC|");
	
	var trackUrl = "AgentHQWebMetrics.aspx?id=" + linkId + "&lob=" + lobKey + "&title=" + titleKey
	trackUrl = trackUrl + "&du=" + destUrl;

	switch (iNewWindow)
	{
		case 1: window.open(trackUrl); break;
		case 2:	singleLaunchBar(trackUrl); break;
		case 3: showProcess(trackUrl); break;
		case 4: singleLaunch(trackUrl); break;
		case 0: location.href = trackUrl;	break;
	}
}

function processForm(formType)
{
	if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
	var isValid = true;
	try { isValid = Page_IsValid } 
	catch (ex) { isValid = true;}
	if (isValid)
	{
		document.Form1.formType.value = "" + formType; 
		document.Form1.submit();
	}
}

function removeHTMLTags(strInputCode)
{
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		return strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
}
function fixTitle()
{
	document.title = removeHTMLTags(document.title);
}
function postForm(destUrl, targetName)
{
	document.Form1.action = destUrl;
	if ((null != targetName) && ("" != targetName))
	{
		document.Form1.target = targetName;
	}
	document.Form1.submit();
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}