// JavaScript Document
var xmlhttp

function buttonSubmit()
{
	if(document.all("status").value == "submit")
		{
		if(checkform())
		regCustomer();
		}
	else window.alert("Your application is submitted!")
}


function regCustomer()
{
var name = document.all("name").value;
var phone = document.all("phone").value;
var dobd = document.all("dobd").value;
var dobm = document.all("dobm").value;
var address = document.all("address").value;
var email = document.all("email").value;
var course = document.all("course").value;
var dob = dobd + "/" + dobm;

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="reg.php";
url=url+"?name="+name+"&phone="+phone;
url=url+"&dob="+dob+"&address="+address;
url=url+"&email="+email+"&course="+course;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("regform").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
} 

function checkform()
{
	if (document.all("name").value =="") {
		alert("Please enter your name.");
		document.all("name").style.background = 'Yellow';
		document.all("name").focus();
		return false;
	}
	else document.all("name").style.background = 'White';
	
	if (document.all("phone").value == "") {
		alert("Please enter your phone number.");
		document.all("phone").style.background = 'Yellow';
		document.all("phone").focus();
		return false;
	}
	else document.all("phone").style.background = 'White';

	if (document.all("email").value =="") {
		alert("Please enter your email address.");
		document.all("email").style.background = 'Yellow';
		document.all("email").focus();
		return false;
	}
	else document.all("email").style.background = 'White';

	if (document.all("course").value =="") {
		alert("Please enter the course you studied from Frederique Academy before.");
		document.all("course").style.background = 'Yellow';
		document.all("course").focus();
		return false;
	}
	else document.all("course").style.background = 'White';

	return true;
}


