function checkEmail(email) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return true;		
	else
		return false;
}


function isNumber(num)
{
	if (/(^-*\d+$)|(^-*\d+\.\d+$)/.test(num))
		return true;
	else
		return false;
}


function IsZip(num)
{
	ValidChars = "0123456789";
	zipF="";

	for (i=0; i<num.length; i++)
	{
		Char = num.charAt(i);
		if (ValidChars.indexOf(Char) != -1) 
			zipF+=Char;
	}
	
	
	if (zipF.length!=5)
		return false;
		
	return zipF;
}



function abd()
    {
       // document.getElementById('txtEmail').value="";
        document.getElementById('search').value="";
        }
    function abc(id)
    {

      document.getElementById(id).value="";
        
          document.getElementById(id).focus();

    }
    function validString(thefield,therlength,themessage,id)
{
	var theinput=thefield.value;

   String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");}
     var t=theinput.toString();
        var a=t.trim();
        var thelength=a.length;
	//var thelength=theinput.length;
	var goodzip=true;
      /*  if(thelength==0)
            {
                alert()
            }*/
//    String.prototype.trim = function() {
//	return this.replace(theinput,"");
//         }

	if(thelength<therlength)
	{
		goodzip=false;
	}
	if(thelength>=therlength)
	{
		for(var i=0;i<thelength;i++)
		{
			var thechar=theinput.substring(i,i+1);
		if(!(thechar>="a" && thechar<="z" || thechar>="A" && thechar<="Z" || thechar==" "))
			{
				goodzip=false;
			}
		}
	}
	if(goodzip==false)
	{
        //if(thelength==0){empty(theinput);}
		alert(themessage);
                return  abc(id);
                  //thefield.length.focus();
	}
	return goodzip;
}
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
		 }

 		 return true
	}

function ValidateEmail(){
	var emailID=document.thisform.email

	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
	}
	return true
 }
 function checkEmpty(thefield,themessage,length)
{
    var theinput=thefield.value;
   String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");}
var t=theinput.toString();
var a=t.trim();
var thelength=a.length;
  var goodzip=true;

if((thelength<=0))
	{
		goodzip=false;
	}
        if(!(thelength<=length)){
            goodzip=false;
        }

	if(goodzip==false)
	{
           alert(themessage);
           thefield.focus();
	}
	return goodzip;
}


    function validation(){
     if(!validString(document.thisform.fname,2,"Please enter valid first name ",'fname'))
        return false;
    if(!validString(document.thisform.lname,2,"Please enter valid last name ",'lname'))
        return false;

    if(!ValidateEmail())
        return false;
    if(!checkEmpty(document.thisform.address,"Address is empty",50))
        return false;
    if(!validString(document.thisform.city,2,"Please enter valid city name",'city'))
        return false;
    if(!validString(document.thisform.state,2,"Please enter valid state name",'state'))
        return false;
    if(!checkEmpty(document.thisform.zip,"please enter zip code up to the 6 character ",6))
        return false;
    }
