//function to create an xmlhttp object for all browser type
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // use this for Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // and this for Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}


//function to check the state of an xmlhttp object.

function checkState(obj){	//function to check the state of the xmlHTTP object
if(obj.readyState==4){		//and respond accordingly
   if(obj.status==200){
	return true;
	}
   else{
        alert("There was an error processing your request");
	return false;
	}
   }
}

//function to validate form input
function checkName(frm){
var name=frm.usrName.value
if (name==""){
	return false;
	}
	return true;
}

function checkMail(frm){
var txtmail=frm.mail.value;
//build a regular expression to check valid email entry
var p=/^([a-z0-9_]+\.)?[a-z0-9_]+@[a-z0-9-]+(\.[a-z]{2,3})+$/
if (!p.test(txtmail)){
	return false;
	}
	return true;
}

function checkMessage(frm){
var msg=frm.txtMsg.value
if (msg==""){
	return false;
	}
	return true;
}

function validateInput(frm){	//combine all the function to check value
if (!checkName(frm)){
	alert("Please enter your name");
	frm.usrName.focus();
	frm.usrName.select();
	return false;
	}
	if (!checkMail(frm)){
		alert("Invalid email address, please try again");
		frm.mail.focus();
		frm.mail.select();
		return false;
		}
		if (!checkMessage(frm)){
			alert("Please type in a message");
			frm.txtMsg.focus();
			frm.txtMsg.select();
			return false;
			}
			return true;
	}


function writeToNewPage(content){
var newPage;
newPage=window.open('','Successful','width=120,height=80,left=320,top=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
newPage.document.write(content);
newPage.document.write('<div align="center">');
newPage.document.write('<form><input type="button" value="Close" onclick="window.close()"></form>');
newPage.document.write('</div>')
newPage.document.close();
}

