var xmlHttp

function show_contact(def)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="../steamsun_lib/contact_form_lib.php";
	url=url+"?do="+def;
// 	url=url+"&l="+limit;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("contact").innerHTML=xmlHttp.responseText;
	}
	else
	{ 
		document.getElementById("contact").innerHTML='<hr /><h3>Loading please wait...</h3><img src="steamsun_images/lightbox/ajax-loader.gif" width="220" height="10">' ;
	}
}

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 leave () {
	var chk = document.regform.under.value;
	if ( chk == 'y' );
	{
		window.location = "http://localhost/dev/index.php";
	}
}
function checkemail () {
	
	var email = document.regform.email.value;
	var last  = email.length - 1;
	
	if ( last == -1 ) { alert('Please enter your email address.'); return false; }
	
	if ( email.charAt(0) == '@' ) { alert('Your Email address is missing the first part.\ne.g. yourname@'); return false; }
	if ( email.charAt(last) == '@' ) { alert('Your Email address is missing the last part.\ne.g. @yourserviceprovider.co.uk'); return false; }
	
	var atcount = 0;
	var dotcount = 0;
	
	for ( var x=0; x <= last; x++ ) {
		
		if ( email.charAt(x) == '@' ) { atcount++; }
		else if ( email.charAt(x) == '.' ) { if ( atcount > 0 ) { dotcount++; } }
	}
	
	if ( atcount == 0 || atcount > 1 ) { alert('Your Email address must contain one @ character.\ne.g. yourname@yourserviceprovider.co.uk'); return false; }
	if ( dotcount == 0 ) { alert('Your Email address must contain at least one dot after the @ sign\ne.g. yourserviceprovider.co.uk'); return false; }
	if ( last < 8 ) { alert('Your email appears to be too short to be valid - please check'); return false; }
	
	return true;
	
} 

function checkform() {
	
	if ( document.regform.u_name.value == '' )
	{
		alert('Please enter your user name');
		document.regform.u_name.focus();
		return false;
	}
	else if ( document.regform.password.value == '' )
	{
		alert('Please choose a password');
		document.regform.password.focus();
		return false;
	}
	else if ( document.regform.password_again.value == '' )
	{
		alert('Please enter your password again to confirm');
		document.regform.password_again.focus();
		return false;
	}
	else if ( document.regform.password.value != document.regform.password_again.value)
	{
		alert('The 2 passwords you entered are different');
		document.regform.password.focus();
		return false;
	}
	else if (document.regform.email.value == '' )
	{
		alert('Please enter your email address');
		document.regform.email.focus();
		return false;
	}
	else if ( document.regform.email.value != document.regform.email_again.value)
	{
		alert('The 2 emails you entered are different');
		document.regform.email.focus();
		return false;
	}
	else if (!document.regform.inagreement.checked )
	{
		alert("You must agree to our terms and privacy policy before proceeding - please tick the box under 'Your agreement with us'");
		
		return false;
	}
//else if ( !checkemail())
//	{
//	document.regform.email.focus();
//	return false;
//	}
	else 
	{
		return confirm('You have entered your email as\n'+document.regform.email.value+'\nPlease double check this is correct as your access details will be emailed to this address\nIf you wish to change it, please press cancel');
	} 
	
}