var popupCounter = 0;
function popup(url){
	if(opener == null){//in the main window
		Window = window.open(url, "littleWindow", "location=no,width=800,height=680");
		popupCounter = 0;
	}else{//in the popup window
		if(popupCounter == null) popupCounter = 0;
		popupCounter++;
		window_offset = 40*popupCounter;
		window_preference = "status=yes,menubar=yes,scrollbars=yes,location=yes,toolbar=yes,width=800,height=680,resizable=yes,top=" + window_offset + ",left=" + window_offset;
		window.open(url, "", window_preference);
}
	}

function lookupSymbol(event, myform) {  
	 var code = 0;
	 
	 if (window.event) {
		 code = window.event.keyCode;
	 } else {
		 code = event.which;
	 }

	 if (code == 13){
		  event = null;
		  popup('viewSymbolSummary?symbol=' + myform.symbol.value);
		  return false;
	 }
} 

function focusLoginUserName() {
	var userNameText = document.getElementById("loginUserName");
	if (userNameText) {
		userNameText.focus();
	}
}

function showTerms(url) {
	var win = window.open(url, "terms", "height=400, width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");
	win.focus();	
	return false;
}


function agreeUserTerms() {
	window.close();
	window.opener.document.registerForm.submit();	
}
function agreeCompetitionTerms() {
	window.close();
	window.opener.document.competitionRegistrationForm.submit();	
}

function declineTerms() {	
	window.close();
}

function setCompetitionLink() {
	var compId = window.opener.document.competitionRegistrationForm.id.value;
	var link = document.getElementById("compLink");
	link.href = "http://www.equitrader.com/trader/xco/compDetails?id=" + compId;
	link.innerHTML = "http://www.equitrader.com/trader/xco/compDetails?id=" + compId;
}

function checkTradeFormSelection(object) {
	if (object == null) return;
	value = object.value;
	if (value == "-1") {
		object.style.background = "#ff0";
	}
	else {
		object.style.background = "";
	}
}

function AnotherPage(herf) {
  document.location.href = herf;
  return false;
}

function globalOnLoad() {
	if (document.getElementById('tradeFormCompetition') != null) {
		checkTradeFormSelection(document.getElementById('tradeFormCompetition'));
	}
	
	if (window.minmax_stop) {
		minmax_stop();
	}
	
	if (document.loginForm) {
		document.loginForm.userName.focus();
	}
	
	if (document.loadCurrentCompForm) {
		document.loadCurrentCompForm.redirect.click();
	}
}

window.onload = globalOnLoad;
