



function Form1_Validator(theForm)
{
if (theForm.flag.value=='flag')
{

  if (theForm.Login.value == "")
  {
    alert("Please enter a value for the \'Login\' field");
    theForm.Login.focus();
    return (false);
  }

 if (hasQuots(theForm.Login.value) == true )
  {
    alert("Please enter a value for the \'Login\' field without \" and \' symbols.");
    theForm.Login.focus();
    return (false);
  }
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \'Password\' field.");
    theForm.Password.focus();
    return (false);
  }
   if (hasQuots(theForm.Password.value) == true )
  {
    alert("Please enter a value for the \'Password\' field without \" and \' symbols.");
    theForm.Password.focus();
    return (false);
  }




  if (theForm.Password.value != theForm.CPassword.value )
  {
    alert("Passwords do not match.");
    theForm.Password.focus();
    return (false);
  }

  if (theForm.Name && theForm.Name.value == "")
  {
    alert("Please enter a value for the \'Name\' field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Name && theForm.Name.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'Name\' field.");
    theForm.Name.focus();
    return (false);
  }
  
  if (theForm.firstName && theForm.firstName.value == "")
  {
    alert("Please enter first name");
    theForm.firstName.focus();
    return (false);
  }

  if (theForm.lastName && theForm.lastName.value == "")
  {
    alert("Please enter last name");
    theForm.lastName.focus();
    return (false);
  }


  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \'Email\' field.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'Email\' field.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Address.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'Address\' field.");
    theForm.Address.focus();
    return (false);
  }

  if (theForm.ZIP.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'ZIP\' field.");
    theForm.ZIP.focus();
    return (false);
  }

  if (theForm.City.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'City\' field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.Phone.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \'Phone\' field.");
    theForm.Phone.focus();
    return (false);
  }
  if (!isNumber(theForm.Phone)) return false;
  if (!validateEmail(theForm.Email.value)) 
  {
    alert("Enter correct E-mail address");
    theForm.Email.focus();
    return false;
  }
  return (true);
 }
else return true; 
}

function isNumber(f)
{
var data=f.value;
var numStr="0123456789 -()+"; var th;  var counter=0;  var ret=false;
 for(var i=0; i < data.length; i++)
 {th = data.substring(i, i+1); if(numStr.indexOf(th) != -1) counter++;}
 if(counter == data.length) return true; 
 alert("Enter correct phone number");
 f.select(); f.focus(); 
 return(ret);
}

function hasQuots(logpas)
{ var mystr=new String(logpas);
  if((mystr.indexOf('\'')!=-1)||(mystr.indexOf('\"')!=-1))
    return (true);
  return(false); 
}



function validateEmail(em) {
  var str = new String(em);
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)) {
      return true;
    }
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    return false;
  }
}

