// JavaScript Document

function validate_advert_signup()
{
	var f = document.forms[0];
	
	if(f.business_name.value == "")
	{
		f.business_name.focus();
		alert("Please enter Business Name");
		return false;
	}
    
    if(f.business_address.value == "")
	{
		f.business_address.focus();
		alert("Please enter Business Address");
		return false;
	}
    
    if(f.business_suburb.value == "")
	{
		f.business_suburb.focus();
		alert("Please enter Suburb");
		return false;
	}
    if(f.business_state.value == "")
	{
		f.business_state.focus();
		alert("Please enter State");
		return false;
	}
    
    if(f.business_postcode.value == "")
	{
		f.business_postcode.focus();
		alert("Please enter Postcode");
		return false;
	}
	
	if(f.contact_name.value == "")
	{
		f.contact_name.focus();
		alert("Please enter Contact Name");
		return false;
	}

	if(f.contact_phone.value == "")
	{
		f.contact_phone.focus();
		alert("Please enter Contact Phone");
		return false;
	}

	if(!validate_phone(f.contact_phone.value))
	{
		f.contact_phone.focus();
		alert("Contact Phone has least 8-15 numbers");
		return false;
	}

	if(f.contact_email.value == "")
	{
		f.contact_email.focus();
		alert("Please enter your email");
		return false;
	}

	if(!validate_email(f.contact_email.value))
	{
		f.contact_email.focus();
		alert("Please enter your email in format");
		return false;
	}

	if(f.test_code.value == "")
	{
		f.test_code.focus();
		alert("Please enter security code");
		return false;
	}
	/*
	 *	Yuranga - Quoc Che modified
	 *	Mantis Isuue ID : 789
	 *  Project : eSchools Marketing 
	 *	Date : 2009-04-23 12:25 EST
	 */
	if(f.contact_passwd.value == "")
	{
		f.contact_passwd.focus();
		alert("Please enter password.");
		return false;
	}
	if(f.contact_passwd_confirm.value == "")
	{
		f.contact_passwd_confirm.focus();
		alert("Please enter confirm password.");
		return false;
	}
	if(f.contact_passwd_confirm.value != "" && f.contact_passwd.value != "" )
	{
		
		if (f.contact_passwd_confirm.value != f.contact_passwd.value  )
		{
			f.contact_passwd_confirm.value = "";
			f.contact_passwd.value = "";
			f.contact_passwd.focus();
			alert("Password and Confirm password must be the same.");	
			return false;
		}
		return true;
		
	}
	if(f.flagDupEmail.value == "1")
	{
		f.contact_email.value = "";
		f.contact_email.focus();
		alert("Please enter other email.");
		return false;
	}
	return true;
}
function AjaxCRequest(url, params, target, form) {
	// check browser support
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// send data
	xmlHttp.onreadystatechange = function() {cRequestHandler(url, target, form);};
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}

function cRequestHandler(url, target, form) {
	
	
	document.getElementById('errDuplicateEmail').innerHTML = '<img src="admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
	
  if (xmlHttp.readyState == 4) { // only if req is "loaded"
    if (xmlHttp.status == 200) { // only if "OK"
		if (form == 1) {
						
			if (xmlHttp.responseText == "1")
			{
				document.getElementById('flagDupEmail').value = '1';
				document.getElementById(target).style.color = "red";
				document.getElementById(target).style.fontSize = "11px";
				document.getElementById(target).style.fontFamily =" tahoma, verdana, arial, helvetica, sans-serif";
				document.getElementById(target).innerHTML = "Existed.";
			}
			else
			{
				document.getElementById('flagDupEmail').value = '0';
				document.getElementById(target).style.color = "green";
				document.getElementById(target).style.fontSize = "11px";
				document.getElementById(target).style.fontFamily =" tahoma, verdana, arial, helvetica, sans-serif";
				document.getElementById(target).innerHTML = "Available.";
			}
		} else {
      		//document.getElementById('flagDupEmail').value = '1';
			//document.getElementById(target).innerHTML = "Existed.";
		}
    } else {
      document.getElementById(target).innerHTML=" cRequest Error:\n"+ xmlHttp.status + "\n" + xmlHttp.statusText;
    }
  }
}
/*
 *	End Yuranga - Quoc Che
 */
