function echeck(str) {
	//alert('sdfg');

		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
			
			 
		 }
		 validate();
		
		 return true				
	}

function ValidateForm(nme,eml,phn){
	
	 
	 
	// var dValidate=document.frm.numberValidate.value;
	 
	
	 
	
//	alert(document.getElementById(nme).value);
	var emailID=document.getElementById(eml).value;
	
	var name=document.getElementById(nme).value;
	
	// var phnVali=document.getElementById(phn).value;
	
	
	
//	alert(name.value);
	
//	alert('asdf');

	if ((name==null)||(name=='Name...')||(name=="")){
		alert("Please Enter your Name")
		document.getElementById(nme).value="";
		document.getElementById(nme).focus()
		return false
	}
	
	
	if ((emailID==null)||(emailID=='Email...')||(emailID=="")){
		alert("Please Enter your Email ID");
		document.getElementById(eml).value="";
		document.getElementById(eml).focus();
		return false
	}
	
	
	if (echeck(emailID)==false){
		document.getElementById(eml).value="";
		document.getElementById(eml).focus();
		return false
		
	}
	
	
	return false
	
 }
 
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sendemail() {
	var comments = document.contactform.comments.value;
	var name = document.contactform.name.value;
	var email = document.contactform.email.value;
	var phone = document.contactform.phone.value;
	document.contactform.send.disabled=true; 
	document.contactform.send.value='Sending....';

    http.open('get', 'contact.php?comments='+comments+'&name='+name+'&phone='+phone+'&email='+email+'&action=send');
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
         
        }
    }
}


function validate()
{
  var dValidate=document.contactform.phone.value;
 // if(dValidate=="")
  if ((dValidate==null)||(dValidate=='Phone...')||(dValidate==""))
  {
    alert("Number Field is empty")
		document.contactform.phone.value="";
		document.contactform.phone.focus();
    return false;
  }
  else if(isDigits(dValidate)==false)
  {
   alert("Field is numeric")
   		document.contactform.phone.value="";
		document.contactform.phone.focus();
   return false;
 
  }
     sendemail();
}

function isDigits(argvalue) {
    argvalue = argvalue.toString();
    var validChars = "00123456789()+-_/. ";
    var startFrom = 0;
	/*
    if (argvalue.substring(0, 2) == "0x") {
       validChars = "00123456789abcdefABCDEF()+-_/";
       startFrom = 2;
    } else if (argvalue.charAt(0) == "00") {
       validChars = "001234567";
       startFrom = 1;
    }
	*/
    for (var n = 0; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
  return true;
  
}
//function changeText2(){
//var name = document.getElementById('name').value;
//var email=document.getElementById('email').value;
//
////alert(document.getElementById('hidden_name').value);
//document.getElementById('hidden_name').value=name;
//document.getElementById('hidden_email').value=email;
//document.getElementById('boldStuff2').innerHTML ='Thankyou '+name+ ', your Email address have been saved.<br>Now you can download your Coupon by clicking this following link or Preview your Coupon here.<br /><br /><input type="submit" name="button" id="button" value="Get Your Coupon" style="font-family: Arial; font-size: 12px; border: 1px solid #000000; background-color: #ffffff"; />';
//}
//
//function Hide(){
//document.getElementById( "myId" ).style.display = "none"; 


//}
