
function validate_form()
{	
	// empty name
	if (document.promo_form.name.value == "" || found_script(document.promo_form.name) == true)
	{
		alert("Please write down your name");
		document.promo_form.name.focus();
		return false;
	}
	// validate email
	else if (!validate_email(document.promo_form.email) || found_script(document.promo_form.email) == true)
	{
		alert("The E-mail you have entered is not legal.");
		document.promo_form.email.focus();
		return false;
	}
	// validate url
//	else if (document.promo_form.url.value == "" || found_script(document.promo_form.url) == true)
//	{
//		
//		alert("Missing or ilegal url.");
//		document.promo_form.url.focus();
//		return false;
//	}
	// validate captcha
	else if (document.promo_form.captcha.value.length != 5)
	{
		alert("The Image contains 5 letters. please make sure you have entered 5 characters.");
		document.promo_form.captcha.focus();
		return false;
	}
	else if (document.promo_form.i_agree.checked == "true")
	{	
		alert("Please check 'I agree to the terms and conditions' box.");
		document.promo_form.i_agree.focus();
		return false;
	}
	else // i can submit
	{
		document.getElementById("progress_bar").style.visibility = "visible";
		ajaxFunction();
		//document.promo_form.email.value = "";
		//document.promo_form.name.value = "";
		//document.promo_form.url.value = "";
		return false;
	}
}

function validate_email(field)
{
	with (field)
	{
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) 
  		{
  			return false
  		}
		else 
		{
			return true
		}
	}
}

function found_script(field)
{
	with (field)
	{
		s=value.match("<script")
		
		if (s == null) 
  		{
  			return false;
  		}
		else 
		{
			return true;
		}
	}
}

function ajaxFunction()
{
  		var xmlHttp;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		    catch (e)
		    {
		    	try
		        {
		        	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		        }
		    	catch (e)
		        {
		        	alert("Your browser does not support AJAX!");

		        }
		    }
		}
		xmlHttp.onreadystatechange=function()
      	{
      		if(xmlHttp.readyState==4)
        	{
        		//document.getElementById("dynamic_content").innerHTML=xmlHttp.responseText;
        		if (xmlHttp.responseText == 1)
        		{
        			alert("Thank you for participating in 888.com's special Shane Warne promotion");
        			document.promo_form.email.value = "";
					document.promo_form.name.value = "";
					document.promo_form.url.value = "";
					document.promo_form.i_agree.checked = "false";
					document.promo_form.captcha.value = "";
        		}
        		else
        		{
  					alert(xmlHttp.responseText);
        		}
  				document.getElementById("progress_bar").style.visibility = "hidden";
        	}
      	}
      			
     	xmlHttp.open("GET","save.php?name=" + document.getElementById("name").value + "&email=" + document.getElementById("email").value + "&url=" + document.getElementById("url").value +  "&i_agree=" + document.getElementById("i_agree").checked + "&captcha=" + document.getElementById("captcha").value,true);
    	xmlHttp.send(null);
}

