function LTrim( value ) {
 	var re = /\s*((\S+\s*)*)/;
   	return value.replace(re, "$1");
     	
     }
     
    // Removes ending whitespaces
  function RTrim( value ) {
    	
  	var re = /((\s*\S+)*)\s*/;
   	return value.replace(re, "$1");
   	
   }
    
 // Removes leading and ending whitespaces
   function trim( value ) {
  	
    	return LTrim(RTrim(value));
   }

function check(email)
{

var email=(document.testing.email.value);


 //**************************email*********************
	 
	  //email validation
	  
	  if(email=="")
		{
				alert("Enter Email_Id.");
				document.getElementById('email').focus()
				return false;
		}
		if(trim(email)=="")
		{
				alert("Please enter Email_Id.");
				document.getElementById('email').focus()
				return false;
		}

		var str=email;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.indexOf(at,(lat+1))!=-1)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.indexOf(dot,(lat+2))==-1)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}

		else if (str.indexOf(" ")!=-1)
		{
			alert("Enter valid email id.");
			document.getElementById('email').focus()
				return false;
		}
		
		else{
		
		  return true;
		}
		//document.testing.action="email_testing1.php?page="+email;
		//document.testing.submit();
}
