var containsError;
var formerrormsg="You have attempted to submit this form multiple times. Please wait while your request is processed."
var submitEnableTimeout = 4000;
submitFlag=false;
d=document;l=d.layers;op=navigator.userAgent.indexOf('Opera')!=-1;

function bookmark_it(argVal)
{
	var bookData = new Array();
	bookData = argVal.split("|");
if (document.all)
	window.external.AddFavorite(bookData[0], bookData[1]);
else
	alert("Netscape users must bookmark the pages manually by hitting <Ctrl-D>");
}

// GetElementbyID 
function gE(e,f)
{
if(d.all)return d.all[e];return d.getElementById(e);
}

// Show Layer
function sE(e){l?e.visibility='show':e.style.visibility='visible';}

// Hide Layer
function hE(e){l?e.visibility='hide':e.style.visibility='hidden';}

// set Z-Index of Layer
function sZ(e,z){l?e.zIndex=z:e.style.zIndex=z;}

// Moves layer along the X axis
function sX(e,x){l?e.left=x:op?e.style.pixelLeft=x:e.style.left=x;}

// Moves layer alon the Y axis
function sY(e,y){l?e.top=y:op?e.style.pixelTop=y:e.style.top=y;}

// sets the width of the layer
function sW(e,w){l?e.clip.width=w:op?e.style.pixelWidth=w:e.style.width=w;}

// sets the height of the layer
function sH(e,h){l?e.clip.height=h:op?e.style.pixelHeight=h:e.style.height=h;}

// sets the clipping properties of the layer
function sC(e,t,r,b,x){l?(X=e.clip,X.top=t,X.right=r,X.bottom=b,X.left=x):e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}

// writes content into the layer
function wH(e,h){if(l){sY=e.document;sY.open();sY.write(h);sY.close();}else if(e.innerHTML)e.innerHTML=h;}

//-=-=-=-=--=-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-=-
//Common JS function used to display ATI content...
//-=-=-=-=-=-=--==-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function PopUpATIWindow()
{
	//pass Content Id forward to Content Handler page...
	var contentId = 0;
	if ( arguments.length > 0 )
		contentId = arguments[0];
	
	window.open(UrlVirtualPrefix + '../ATIDisplay.aspx?atiID='+contentId,'Instructions','resizable=no, scrollbars=yes,toolbar=no,width=600, height=200,left=175, menubar=no');
}
//Allow only 30 characters...
function ValidateRejectReasonTxt()
{
	var thetxtreasObj = gE('txtReason');
	if (!thetxtreasObj) {return;}
	if (thetxtreasObj.value.length>300)
	{
		thetxtreasObj.value = thetxtreasObj.value.substr(0,300);
		thetxtreasObj.focus();
	}
}
// used by buttonController and buttonTemplate
function doSubmit()
{
	var	re = /[\/\\]/;
	with (document.forms[0])
	{
		switch (doSubmit.arguments.length)
		{
			case 0:
				action = window.location.href;
				break;
			case 1:
				action = doSubmit.arguments[0];
				break;
			case 2:
				action = doSubmit.arguments[0];
				if (doSubmit.arguments[1] != '') target = doSubmit.arguments[1];
				break;
			case 3:
				action = doSubmit.arguments[0];
				if (doSubmit.arguments[1] != '') target = doSubmit.arguments[1];
				if (doSubmit.arguments[2]) __VIEWSTATE.name = 'KillViewState';
				break;
			default:
				return;
		};

		// prevents multiple page submissions
		if (submitFlag == false) {
			submitFlag = true;
			submit();
		}
		else {
			displayError(formerrormsg);
		}
	}
}

// similar to doSubmit
function doPostBack( eventTarget, eventArgument ) 
{
		// prevents multiple page submissions
		if (submitFlag == false) {
			submitFlag = true;
			document.forms[0].action = window.location.href
			__doPostBack( eventTarget, eventArgument );  
		}
		else {
			displayError(formerrormsg);
		}
}

function setFocus(objControl)
{
	eval('document.forms[0].' + objControl + '.focus()');
}

function checkForm(functionName,validate,eventTarget)
{
	if (eventTarget == '')
	{
		alert('href needs an ID')
	}

	if (validate)
	{
		validateForm(document.forms[0])
		if (errorExists)
		{
			eval(functionName)
		}
	}
	else eval(functionName)
}


// remove this
function SubmitIt(actionstr)
{
	doSubmit(actionstr);
}

// glossary popup window
function openGlossary(objectname) 
{
	if (navigator.appName.indexOf("WebTV") != -1)
	{
		document.location.href="/TF/Online/Admin/Help/WebTv/GlossaryTerm?termname="+ objectname;
	}
	else
	{
		popUp("/TF/Online/Admin/Help/GlossaryTerms?termname="+ objectname,"glossary",565,150,"status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes")
	}

}

// change contents of a DIV
function changeText(id,text)
{
	buttonDiv = eval("gE('"+id+"')")
	wH(buttonDiv,text)
}

// simplified inline confirmation function
function displayConfirmation(str)
{
	if (navigator.appName.indexOf("WebTV") != -1) 
	{
		alert(str);
	}
	else
	{
		confirmationDiv = gE('singleConfirmation')
		wH(confirmationDiv,str);
		confirmationDiv.className="confirmationContainerShow";
		self.scrollTo(0,0);
	}
}

// hide inline confirmation function
function hideConfirmation(str)
{
	if (navigator.appName.indexOf("WebTV") != -1) 
	{
		return false;
	}
	else
	{
		confirmationDiv = gE('singleConfirmation');
		confirmationDiv.className="confirmationContainerHide";
	}
}

// REMOVE AFTER modifying Buttton Controller & customize pages like CustomizeActivity.xsl & CustomizeBalances.xsl
function canSubmit()
{
}

// sitewide popup function
function popUp(pageId,pageType,windowWidth,windowHeight,windowSpecs)
{
	if (windowSpecs)
	{
		windowSpecs = windowSpecs;
	}
	else
	{
		windowSpecs = "menubar=no,toolbar=no,location=no,resizable=no,status=no,scrollbars=no"
	};
	
	if (!windowWidth)
	{
		windowWidth = 300
	};
	if (!windowHeight)
	{
		windowHeight = 200
	};

	var screenHeight = screen.height;
	var topPosition = (screenHeight-windowHeight)/2;
	var screenWidth = screen.width;
	var leftPosition = (screenWidth-windowWidth)/2;
	
	var agt=navigator.appVersion.toLowerCase();
	if (agt.indexOf("aol") != -1)
	{
		topPosition = 0;
		leftPosition = 0;
	}
	windowSpecs += ",top="+topPosition+",left="+leftPosition+",width="+windowWidth+",height="+windowHeight+"";

	rExp = /'/g;
	pageId=pageId.replace(rExp,'\\\'');
	var strURL = pageId;
	var strWindowName = pageType;
	if (pageType == ""){strWindowName ="undefined"}
	var strCommand = "var "+strWindowName+" = window.open('"+pageId+"','"+strWindowName+"','"+windowSpecs+"');"
	eval(strCommand);
	eval(strWindowName+".focus();");
}

// disables button
function disableButton(id, buttonType, newURL)
{
	identity=document.getElementById(id);
	identity.className="buttonDisabled";
	eval("identity.onclick = function(){return false}"); 
	eval("identity.onfocus = function(){this.blur()}"); 
	if (document.images[id])
	{
		var imgName=(buttonType==null)?"":buttonType;
		imgName=(trimAll(imgName)=="")?"":("_"+imgName);
		document.images[id].src = '/TF.Online/images/0/shared/disabled_button'+imgName+'.gif';
	}
}

// enables button
function enableButton(id, buttonType, newURL)
{
	identity=document.getElementById(id);
	identity.className="button";
	eval("identity.onclick = function(){this.blur();"+newURL+";return false;}"); 
	eval("identity.onfocus = function(){}");
	if (document.images[id])
	{
		var imgName=(buttonType==null)?"":buttonType;
		imgName=(trimAll(imgName)=="")?"":("_"+imgName);
		document.images[id].src = '/TF.Online/images/0/shared/enabled_button'+imgName+'.gif';
	}
}

function confirmYesNo( question )
{
	var yes = confirm( question );
	if ( yes )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function setValueWithValidate( hiddenField, val )
{
	validateForm( document.forms[0] );
	if ( errorExists )
	{
		return setValue( hiddenField, val );
	}
	else
	{
		return false;
	}
}

function setValue( hiddenField, val )
{
	var fld = document.getElementById( hiddenField );
	if ( fld != null )
	{
		fld.value = val;
		return true;
	}
	else
	{
		return false;
	}
}

function isEnterKey( evt ) 
{
	if ( ! evt )
	{
		evt = window.event;
	}
    return ( evt.keyCode == 13 )
}

function onKeyPress( evt, key, arg, doValidation )
{
    if ( isEnterKey( evt ) )
    {
		var ctl = document.getElementById( key );
		if ( ctl )
			ctl.focus();
			
		if ( doValidation == '1' )
		{
			validateForm( document.forms[0] );
			if ( errorExists )
			{
				doPostBack( key, arg );
				return false;
			}
			else
			{
				evt.cancelBubble = true;
				evt.returnValue = false;
				return false;
			}
		}
		else
		{
			doPostBack( key, arg );
			return false;
        }
    }
    return true;
}

/* POP Functions */

// POP Login 1
function checkLogin(password, userid, imagebtn, evt, msg)
{
	if ( isEnterKey( evt ) )
	{
		clearError();
		if ( eval("document.forms[0]." + password + ".value") == "" || eval("document.forms[0]." + userid + ".value") == "")
		{
		displayError(msg);
		return false;
		}
		else
		{
		return(onKeyPress(evt,imagebtn,'','0'));
		}
	}
}

// POP Login 2
function checkClickLogin(var1,var2, msg)
{
   clearError();
   	if ( eval("document.forms[0]." + var1 + ".value") == "" || eval("document.forms[0]." + var2 + ".value") == "")
		{
		displayError(msg);
		return false;
		}
		else
		{
		return true;
		}
}

// POP Login 3
function CheckLogin(Acct,User, msgUser,msgAcct, radAcct,radUser,synUser,synAcct)
{
	if ( eval("document.forms[0]." + radAcct + ".checked") == true)
	{
		clearError();
		if ( eval("document.forms[0]." + Acct + ".value") == "" || eval("document.forms[0]." + Acct + ".value") == synAcct)
		{
			displayError(msgAcct);
			return false;
		}
		else
		{
			return true;
		}
	}
	else if( eval("document.forms[0]." + radUser + ".checked") == true)
	{
		clearError();
		if ( eval("document.forms[0]." + User + ".value") == "" || eval("document.forms[0]." + User + ".value") == synUser)
		{
			displayError(msgUser);
			return false;
		}
		else
		{
			return true;
		}
	}
	return true;
}

// related links under pop..should be removed from XSL to use popUp function directly instead
function popWin(winLoc,winHeight,winWidth,WinUrlBar,WinNavBar,WinScrBar,WinStatusBar,WinMenuBar,WinResize)
{
	newWin=window.open(winLoc,'RelatedLinkWin','height='+winHeight+',width='+winWidth+',location='+WinUrlBar+',toolbar='+WinNavBar+',scrollbars='+WinScrBar+',status='+WinStatusBar+',menubar='+WinMenuBar+',resizable='+WinResize);
}

// viewquicklinks.ascx
function CancelSubmit(listid)
{
	if(listid.selectedIndex == 0)
	{	
		return(false);
	}
	else
	{
		return(true);		
	}
	return(true);
}

// quicklinks from pop
function quickLinks()
{
	if (quickLinkObj.selectedIndex == 0 && quickLinkObj.length <= 1)
	{
		displayError(EX6);
	}
	else 
	{
		document.location.href="/TF/Online/Admin/EndUserCust/EditBookmarks";
	}
}
// search from pop
function gotoSearch() {
	searchDestination = "/TF/Online/Service/Help/Search?searchWords=";
	searchInput =  document.forms[0].popSearch.value;

	if (searchInput.length < 2 || searchInput == "Enter Keyword(s)"){
		displayError('To perform a search, please enter at least two characters.')
		document.forms[0].popSearch.focus();
	}
	else {
		top.document.location.href=  searchDestination + searchInput;
	}
}

// quick quote from pop
function testQ()
{
	if (popSymb != null || popSymb != "" || symb_in != "Enter Symbol" || symb_in != "Enter Symbol(s)") 
	{
		displayError(EX11);
		document.forms[0].Symbol1.focus();
		if (v==1) return false;
	}
}

// quick quote from pop
function PopGoToQuote(symb_in,v)
{
	var flag;
	var type;

	var popSymb;
	
	popSymb = customEscape(symb_in);

	if (document.forms[0].QuoteType) 
	{
		type = getRadioValue(document.forms[0].QuoteType);
	}
	else
	{
		type = "Basic";
	}

	if (popSymb == null || popSymb == "" || trimAll(symb_in) == "" || symb_in == "Enter Symbol" || symb_in == "Enter Symbol(s)") 
	{
		displayError(EX11);
		document.forms[0].Symbol1.focus();
		return false;
	}

	if (symb_in == "Enter Symbol" || symb_in == "Enter Symbol(s)") 
	{
		popSymb = "";
	}
	if (MQ == 1 && popSymb.indexOf("%2C") != -1) 
	{
		doSubmit('/TF/Online/Sitemap/Markets/Charts/Quotes/MultiQuote/MultiQuoteData?QuotePopEntry=true&QuoteTypePage=MultiQuotes&QuoteSymbol=' + popSymb,'','True');
	}
	else
	{
		if (FQ == 1 && type == "Extended")
		{
			doSubmit('/TF/Online/Sitemap/Markets/Charts/Quotes/ExtendedQuote/ExtendedQuoteResults?QuotePopEntry=true&QuoteTypePage=Extended&QuoteSymbol='+ popSymb,'','True');
		}
		else
		{
			if (symb_in != "Enter Symbol" && symb_in != "Enter Symbol(s)") document.forms[0].Symbol1.value = symb_in.toUpperCase();
			popUp('/TF/Online/Sitemap/Markets/Charts/BasicQuotesData?QuoteTypePage=Basic&QuoteSymbol=' + popSymb,'QuickQuote',215,650,'status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes');
		}
	}
	if (v==1) return false;
}

// quick quote from pop
function getRadioValue(radio) {
	for (index=0; index<radio.length; index++)
	{ 
		if (radio[index].checked) return radio[index].value; 
	}
	return null;
}

// quick quote from pop
function customEscape(entry) {
	var temp = "" + escape(entry); // temporary holder
	return temp.replace(/\//g,'%2F');
}



