// JavaScript Document

var xmlHttp;

function hidediv() {
	if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById('hideshow').style.visibility = 'hidden';
	}else {			
		if(document.layers){ // Netscape 4
			document.hideshow.visibility = 'hidden';
		}else { // IE 4
			document.all.hideshow.style.visibility = 'hidden';
		}
	}
}

function showdiv(){
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('hideshow').style.visibility = 'visible';
	}else{
		if(document.layers) { // Netscape 4
			document.hideshow.visibility = 'visible';
		}else { // IE 4
			document.all.hideshow.style.visibility = 'visible';
		}
	}
}

function getkey(e){
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function goodchars(e, goods){
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;	
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();	
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;	
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;	
	// else return false
	return false;
}

function validation(){
	xmlHttp=GetXmlHttpObject();	
	fname = document.email_form.fname.value;
	lname = document.email_form.lname.value;
	email = document.email_form.email.value;
	phone = document.email_form.phone.value;
	comments = document.email_form.comments.value;
	
	if(fname == ""){
		alert("Please enter your Full Name");
		document.email_form.fname.focus();
	}else if(lname == ""){
		alert("Please enter your Last Name");
		document.email_form.lname.focus();
	}else if(email == ""){
		alert("Please enter your Email ID");
		document.email_form.email.focus();
	}else if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		alert("Please enter your Valid Email ID");
		document.email_form.email.focus();
	}else if(phone == ""){
		alert("Please enter your Phone Number");
		document.email_form.phone.focus();
	}else if(comments == ""){
		alert("Please enter your Comments");
		document.email_form.comments.focus();
	}else{
		str = "fname="+fname+"&lname="+lname+"&email="+email+"&phone="+phone+"&comments="+comments;
		url="mail.php?"+str;
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState==0 || xmlHttp.readyState==3 || xmlHttp.readyState==1 || xmlHttp.readyState==2){ 
				document.getElementById("mesg").innerHTML="<table width='80%' align='center' cellpadding='0' cellspacing='0' class='formtableborder'><tr><td align='center'><strong class='headings'>Loading</strong></td></tr><tr><td height='150' align='center' valign='top'><img src='images/loading.gif'></td></tr></table>";
			}
			if(xmlHttp.readyState==4){
				document.getElementById("mesg").innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

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;
}
