var ver=navigator.appVersion;
var dom=document.getElementById?1:0;
var iedom=(ver.indexOf("MSIE")>-1 && dom)?1:0;

function checkEntryButton(e) {
  // Submit the login form when Entry button is pressed
  var code = 0;
  if (document.LOGINBOX) {
     if (iedom)
        code = window.event.keyCode;
     else if (dom)
        code = e.keyCode;
     if (code == 13) {
			 checkLoginInfo();
	 }
  }
}

function checkLoginInfo()
{
	var eMailElement = document.getElementById('loginUserId');
	var passwordElement = document.getElementById('loginPassword');

	//var eMailElement = document.loginUserId;
 	eMailElement.value = trim(eMailElement.value);
	if (eMailElement.value.length == 0)
	{
		alert('Please enter a valid user id.');
		eMailElement.focus();
		return;
	}
	var eMailValid = checkEmail(eMailElement.value);
	if (eMailValid == 2)  // bad email
	{
		alert ('The user id ' + eMailElement.value + ' is not valid.  Please re-enter a valid email address and try again.');
		eMailElement.focus();
		return;
	}

	if (trim(passwordElement.value).length == 0)
	{
      alert ("You must enter a password.  Please try again.");
	   passwordElement.focus();
  	   return;
	}

    document.LOGINBOX.submit();
}

function retrievePassword()
{
	var eMailElement = document.getElementById('loginUserId')

	if (eMailElement.value.length < 1)
	{
		alert("Please enter a valid user id.\nTry your email address.");
		eMailElement.focus();
		return;
	}
	var eMailValid = checkEmail(eMailElement.value);
	if (eMailValid == 2)  // bad email
	{
		alert ('The user id ' + eMailElement.value + ' is not valid.  Please re-enter a valid email address and try again.');
		eMailElement.focus();
		return;
	}

	window.location.href = "http://fantasy.atpworldtour.com/fantasy/PostHandler.aspx?process=password&email=" + eMailElement.value;

// document.GETPASSWORD.submit();

}

function LogOut()
{

    var domain = "";
    var url = location.href;
	url = url.toLowerCase();
	if (url.indexOf("rtsports.com") != -1) {
		domain = ".rtsports.com";
		url = "http://ballboy.rtsports.com";
	}else{
		domain = ".atpworldtour.com";
		url = "http://challenge.atpworldtour.com";
    }

	var date = new Date();
	date.setTime(date.getTime()-(86400*1000)); // yesterday

	var cookie_name = "ATPBRACKET";
	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); // trim the front of the string
		if (c.indexOf(cookie_name) == 0 ) { // account cookie
          var name = c.split('=');
      	  document.cookie = name[0] + "=LoggedOut; path=/; domain=" + domain + "; expires=" + date.toGMTString() + ";"
      }
	}

	//forums cookie
	var cookie_name = "atpforums_sid";
	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); // trim the front of the string
		if (c.indexOf(cookie_name) == 0 ) { // account cookie
          var name = c.split('=');
      	  document.cookie = name[0] + "=LoggedOut; path=/; domain=" + domain + "; expires=" + date.toGMTString() + ";"
      }
	}

	location.href = url;
}

function ClearBkgd(id, theForm)
{
	if (theForm) {
		if (theForm.elements) {
			if (theForm.elements[id]) {
				theForm.elements[id].style.background = "#FFFFFF";
			}
		}
	}
}

function CheckLoginBkgds()
{
	if (document.getElementById('loginUserId')) {
		if (document.getElementById('loginUserId').value.length > 0) {
			ClearBkgd('loginUserId');
		}
	}

	if (document.getElementById('loginPassword')) {
		if (document.getElementById('loginPassword').value.length > 0) {
			ClearBkgd('loginPassword');
		}
	}
}
