/**
 * @author Administrator
 */

var xmlHttp
var Effect;

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 submitEmail()
{
			
		email = document.getElementById("submit_email").value;
		name = document.getElementById("submit_name").value;
		phone = document.getElementById("submit_phone").value;				
		
		
		if(!isEmailValid(email) || email=="" || name =="" || phone=="")
		{
			alert('The details entered are not valid. Please try again.');
		}
		else
		{
			document.getElementById("switch_step1").innerHTML = '<img src="/images/loading.gif" alt="Loading..." />';		
			
			xmlHttp = GetXmlHttpObject()
			
			if (xmlHttp == null) {
				alert("Your browser does not support AJAX!");
				return;
			}
			
			var url = "ajax_submitemail.php?email=" + email;
			url = url + "&name=" + name;
			url = url + "&phone=" + phone;
			url = url + "&sid=" + Math.random();
			xmlHttp.onreadystatechange = emailSubmitted;
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);			
		}
				

		
} 



function emailSubmitted() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("switch_step1").innerHTML=xmlHttp.responseText;
		document.getElementById("switch_step1").style.border = "0px";		
		document.getElementById("switch_step1").style.padding = "12px 0px 0px 48px";				

		document.getElementById("switch_step2").style.border = "5px solid #CDCDCD";				
		document.getElementById("switch_step2").style.padding = "12px 16px 16px 40px";					
		
		document.getElementById("buy_button").style.display = "block";
	}
}


function isEmailValid(email)
{
	
	valid = true;
	
	apos = email.indexOf("@");
	dotpos = email.lastIndexOf(".");
	
	if (apos<1||dotpos-apos<2) 
	{
	    valid = false;		
	}		
	
	return valid;

}



function checkClaimCode()
{
	
		email = document.getElementById("check_email").value;
		claim_code = document.getElementById("check_claim_code").value;		
				
		if( !isEmailValid(email) || (claim_code.length<9) )
		{
			alert('The details entered are not valid.');
		}
		else
		{
			
			document.getElementById("switch_step1").innerHTML = '<img src="/images/loading.gif" alt="Loading..." />';
					
			xmlHttp = GetXmlHttpObject()
			
			if (xmlHttp == null) {
				alert("Your browser does not support AJAX!");
				return;
			}
			
			var url = "ajax_checkclaimcode.php?email=" + email;
			url = url + "&claim_code=" + claim_code;
			url = url + "&sid=" + Math.random();
			xmlHttp.onreadystatechange = claimCodeChecked;
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);			
		}
				

		
} 



function claimCodeChecked() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("check_results").innerHTML=xmlHttp.responseText;
		
		document.getElementById("switch_step1").style.display = "none";
	}
}

  