var result = "";

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){
     result = "You provided an invalid E-mail address";
     return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     result = "You provided an invalid E-mail address";
     return false
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      result = "You provided an invalid E-mail address";
      return false
  }

   if (str.indexOf(at,(lat+1))!=-1){
      result = "You provided an invalid E-mail address";
      return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      result = "You provided an invalid E-mail address";
      return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
      result = "You provided an invalid E-mail address";
      return false
   }
  
   if (str.indexOf(" ")!=-1){
      result = "You provided an invalid E-mail address";
      return false
   }

    return true     
 }

function ValidateForm(field, type)
{
	if (type == 'email')
	{
		 //var emailID=document.getElementById(fieldId);
		 //var field
		 
		 if ((field.value==null)||(field.value=="")){
		  result = "E-mail is required";
		  //emailID.focus()
		  return result;
		 }
		 if (echeck(field.value)==false){
		  field.value="";
		  //emailID.focus()
		  return result;
		 }
		 return true
	} else if (type == 'text')
	{
		//var field = document.getElementById(fieldId);
		var check_text = /^[\s]+[^A-Za-z0-9]+$|^[\s]+$/;
		if (((field.value) && (field.value.length == 0)) || (check_text.test(field.value) == true))
		{
			result = "required";
			return result;
		} else {
			return true;
		}
	} 
}
