// JavaScript Document
//Comm AJEX Code//

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;
}
//clear All
function clearAll()
{
	document.getElementById('txtName').value = "";
	document.getElementById('txtEmail').value = "";
	document.getElementById('txtFeedback').value = "";
}
//end clear data//

//Valaditions//////////////////////
function checkMandatory()
{
 var name = document.getElementById('txtName').value;
 var email = document.getElementById('txtEmail').value;
 var feedback = document.getElementById('txtFeedback').value;
	
	if(name=='')
	{
	 alert("Please enter the Name");
	 document.getElementById('txtName').focus();
	 }
	 else if(email=='')
	 {
	 alert("Please enter the Email Address");
	 document.getElementById('txtEmail').focus();
	 }
	 else if(feedback=='')
	 {
	 alert("Please enter Your Feedback");
	 document.getElementById('txtFeedback').focus();
	 }
	 else
	 {
		ValidateForm();
	 }
}

//Email Validations//

function echeck(str) {

 var at="@"
 var dot="."
 var lat=str.indexOf(at)
 var lstr=str.length
 var ldot=str.indexOf(dot)
 if (str.indexOf(at)==-1){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(at,(lat+1))!=-1){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(dot,(lat+2))==-1){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(" ")!=-1){
 alert("Invalid E-mail ID")
 return false
 }
 }

function ValidateForm(){
	var emailID=document.frmFeedback.txtEmail

		if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
		}
		if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
		}

	saveFeedback();

 return true
 }
 ////////////////End of Validation//////////////////////

//Save Client Detials//
function saveFeedback()
{

 var cName = document.getElementById('txtName').value;
 var cEmail = document.getElementById('txtEmail').value;
 var cFeedback = document.getElementById('txtFeedback').value;
 

 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
 alert ("Your browser does not support AJAX!");
 return;
 }
 var url="feedback.php";
 url=url+"?&name="+cName+"&email="+cEmail+"&feedback="+cFeedback;
 xmlHttp.onreadystatechange=stateChangedclientDet;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function stateChangedclientDet()
{
 if (xmlHttp.readyState==2)
 {
 document.getElementById("lblStatusMsg").innerHTML="Processing.....";
 }
 else{}

 if (xmlHttp.readyState==4)
 {
	  document.getElementById("lblStatusMsg").innerHTML=xmlHttp.responseText;
	  
	  clearAll();
 }
 else{}
}
//End of Save Student Detials////

//operations/////
function dooperation(opr)
{
	if (opr == 'Submit')
	{
		checkMandatory();
	}
	else{}
}

//End Operations/////////



