// JavaScript Document



function echeckName(strEmail) {

        var at="@"

        var dot="."

        str=strEmail;

        if(str!="")

       {

        var lat=str.indexOf(at)

        var lstr=str.length

        var ldot=str.indexOf(dot)

        if (str.indexOf(at)==-1){

           return false

        }



        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || (str.indexOf(at)+1)==lstr){

           return false

        }



        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || (str.indexOf(dot)+1)==lstr){

            return false

        }



         if (str.indexOf(at,(lat+1))!=-1){

            return false

         }



         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

            return false

         }



         if (str.indexOf(dot,(lat+2))==-1){

            return false

         }



         if (str.indexOf(" ")!=-1){

            return false

         }



         if (str.substring(str.lastIndexOf(dot)+1)==""){

            return false

         }



         return true

    }

}



function clear()

{

	document.getElementById('uname').value="";	

	document.getElementById('email').value="";

	document.getElementById('pho').value="";

	document.getElementById('comm').value="";

}



var xmlHttp // xmlHttp variable



function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.



var objXMLHttp=null // Sets objXMLHttp to null as default.

if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.

objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.

}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.

objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.

} // End ElseIf.

return objXMLHttp// Returns the xhttp object.

} // Close Function



function insert_data(){ // This function we will use to check to see if a username is taken or not.

var name=document.getElementById('uname').value;

var email=document.getElementById('email').value;

var pho=document.getElementById('pho').value;

var comm=document.getElementById('comm').value;

if(name == '')

{

	alert('Please Enter Name');

	document.getElementById('uname').focus();

	return false;

}

if(email == '')

{

	alert('Please Enter Email');

	document.getElementById('email').focus();

	return false;

}

if(!echeckName(email)) {

		alert('Email Address is Invalid');

        return false;

     }

if(pho == '')

{

	alert('Please Enter Phone Number');

	document.getElementById('pho').focus();

	return false;

}

if(isNaN(pho))

{

	alert('Phone Number Must Be Digit');

	document.getElementById('pho').focus();

	return false;

}

if(comm == '')

{

	alert('Please Enter Some Message');

	document.getElementById('comm').focus();

	return false;

}

xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.

if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.

alert ("Browser does not support HTTP Request") // Alert Them!

return // Returns.

} // End If.



var url="insert.php?name="+name+"&email="+email+"&pho="+pho+"&comm="+comm;// Url that we will use to check the username.

xmlHttp.open("GET",url,true) // Opens the URL using GET

xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.

if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.



alert(xmlHttp.responseText);

clear();

//document.getElementById("record1").innerHTML = xmlHttp3.responseText; // Updates the div with the response text from check.php

} // End If.

}; // Close Function

xmlHttp.send(null); // Sends NULL instead of sending data.

} // Close Funct







