var xmlHttp;

//---------------------------------------
function processform() {
  	  
	var isSRS = document.getElementById('SRS');													 
	if (document.getElementById("unam2").value == "" && document.getElementById("pwrd2").value == "") {
		return false;
	}
	if (isSRS)
	{
		//do nothing
	} else {
		if (document.getElementById("agree").checked == false)
		{
			alert("You must check that you have read the disclaimer to login.");
			return false;
		}
	}

	theDate = new Date();
	expDate = new Date(theDate.getFullYear()+1, theDate.getMonth(), theDate.getDate());
	setCookieOpt( "platdisclaimer", "1", expDate, "/", document.domain );                                                                      								
	
  savePW();
     
  validatePlatUsername(document.getElementById("unam2").value);

}
    
//---------------------------------------
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
	}
	return xmlHttp;
}
		

//---------------------------------------
function validatePlatUsername(strUsername) {						    
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url = "/lib/PlatinumCreation/validateProUsername.asp";			    
	var param = "username="+strUsername;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
	xmlHttp.send(param);
	xmlHttp.onreadystatechange = handleHttpResponse_ValidatePlat;
}	
		

//---------------------------------------
function redirectToRenewal(strUsername) {								    
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url = "/lib/PlatinumCreation/redirectPlatRenewal.asp";			    
	var param = "username="+strUsername;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
	xmlHttp.send(param);
	xmlHttp.onreadystatechange = handleHttpResponse_Renewal;
}			
		

//---------------------------------------
function handleHttpResponse_ValidatePlat() {

	if (xmlHttp.readyState == 4) {
	  
	  // True will be returned if username is a valid, active Platinum Pro subscriber, otherwise "False"
		if (xmlHttp.responseText == "True") {  	
//  		strAction = "http://platinum.optionetics.com/cgi-bin/platinumv42/op4main.php";	
//  		strAction = "http://platinumapp9.optionetics.com/cgi-bin/platinumv42/op4main.php";	
  		strAction = "http://platinum.optionetics.com/cgi-bin/platinumv44/op4main.php";	
  		includer = 6;		
  	} else {
  	  
  	  
//  		strAction = "http://platinum.optionetics.com/cgi-bin/platinumv40/op4main.php";
  		strAction = "http://platinum.optionetics.com/cgi-bin/platinumv44/op4main.php";
  		includer = 8;
  	}
  	
  	var randomnumber = Math.floor(Math.random()*1000000);

  	document.getElementById("includer").value = includer;
  	document.getElementById("platform").action = strAction;
  	document.getElementById("platform").target = "plat" + randomnumber;
  


    redirectToRenewal(document.getElementById('unam2').value);

  }   	    				
}


//---------------------------------------
function handleHttpResponse_Renewal() {

	if (xmlHttp.readyState == 4) {		   	    				
            if (xmlHttp.responseText == "Renew") {
            
                var redirectURL = "/platinum/renew/default.asp?PlatinumUsername="+document.getElementById('unam2').value+"&PlatinumPassword="+document.getElementById('pwrd2').value;                  	
                window.location = redirectURL;
	    }
	    else
	        document.getElementById("platform").submit();
    }
}
		

//---------------------------------------
function savePW(){
  
  if (document.getElementById("saveme") != null)	{
		if (document.getElementById("saveme").checked || document.getElementById("saveme").value == "true") {
    	theDate = new Date();
    	expDate = new Date(theDate.getFullYear()+1, theDate.getMonth(), theDate.getDate());
		  setCookieOpt( "clearCookie","false", expDate, "/", document.domain );
			setCookieOpt( "platusername",document.getElementById('unam2').value, expDate, "/", document.domain );
			setCookieOpt( "platpassword", document.getElementById('pwrd2').value, expDate, "/", document.domain );
		} else {
			expDate = null;
		  setCookieOpt( "clearCookie","true", new Date(), "/", document.domain );
			setCookieOpt( "platusername", "", expDate, "/", document.domain );
			setCookieOpt( "platpassword", "", expDate, "/", document.domain );
		}
	}			
}


//---------------------------------------
function setCookieOpt(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "");
	document.cookie = curCookie;
}

