function CheckLForm()
{
  f= document.login;
  re = /\W+/;
  if(f.username.value.length < 3 || f.username.value.length > 15 || re.test(f.username.value)){
      ferror(f.username,"the username is not valid");
	  return false;
  }
  if(f.passwd.value.length < 4 ||  f.passwd.value.length > 15 || re.test(f.passwd.value)){
      ferror(f.passwd,"the password is not valid");
	  return false;
  }
}
function CheckUForm()
{
  f = document.uname;
  re = /\W+/;
  upmsg="characters long\nand contain letters and digits only";
  if(f.username.value.length < 4 || f.username.value.length > 15 || re.test(f.username.value)){
      ferror(f.username,"the username must be between 4 and 15 " + upmsg);
	  return false;
  }
  if(f.passwd.value.length < 8 ||  f.passwd.value.length > 15 || re.test(f.passwd.value)){
      ferror(f.passwd,"the password must be between 8 and 15 " + upmsg);
	  return false;
  }
  return true;
}
////////////////////////////////////////////
function CheckSForm()
{
  f = document.sendpwd;
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(!re.test(f.email.value)){
    ferror(f.email,"Please enter a valid EMAIL address");
	return false;
  }
  return true;
}
/////////////////////////////////////////////
function CheckRForm()
{
  f = document.register;
  usa = f.strcountry.value == "US";
  if (ferror1(f.strname,"Please enter the NAME of your store", 3))
    return false;
  if (ferror1(f.straddr, "Please enter the ADDRESS of your store", 3))
    return false;
  if(ferror1(f.strcity,"Please enter the CITY for your store", 3))
    return false;
  re = /^[0-9]{5}$/; 
  if(usa && (f.strzip.value.length != 5 || !re.test(f.strzip.value))) {
    ferror(f.strzip, "Please enter a 5 digit ZIP code for your store");
	return false;
  }
  if(!usa && f.strprovince.value.length < 3) {
    ferror(f.strprovince,"Please enter a PROVINCE if your country is not the USA");
	return false;
  }
  if(usa && f.strstate.value=="XX"){
	  alert("Please enter a STATE in the USA");
      return false;
  }
  repho = /^\(?\d{3}\)?[-\s.]?\d{3}[-.]?\d{4}$/;
  phonemsg = "phone number with a 3 digit area code\nfollowed by a 3 digit prefix and 4 other digits";
  if(usa && !repho.test(f.strphone.value)) {
    ferror(f.strphone, "Please enter a store " + phonemsg);
	return false;
  }
  if(f.strfax.value.length > 0 && !repho.test(f.strfax.value)) {
    ferror(f.strfax,"FAX should be a " +phonemsg);
	return false;
  }
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(!re.test(f.email.value)){
    ferror(f.email,"Please enter a valid EMAIL address");
	return false;
  }
  // owner
  if (ferror1(f.license,"Please enter the Business License Number for the store", 4))
    return false;
  if (ferror1(f.ownfname,"Please enter the FIRST NAME of the OWNER of the store", 2))
    return false;
  if (ferror1(f.ownlname,"Please enter the LAST NAME of the OWNER of the store", 2))
    return false;
  if(usa && !repho.test(f.ownphone.value)) {
    ferror(f.ownphone, "Please enter a " + phonemsg + " for the OWNER of the store");
	return false;
  }
  if(f.owncell.value.length > 0 && !repho.test(f.owncell.value)) {
    ferror(f.owncell,"CELL should be a " +phonemsg);
	return false;
  }
  // buyer
  if (ferror1(f.buyfname,"Please enter the FIRST NAME of the BUYER for the store", 2))
    return false;
  if (ferror1(f.buylname,"Please enter the LAST NAME of the BUYER for the store", 2))
    return false;
  if(usa && !repho.test(f.buyphone.value)) {
    ferror(f.buyphone, "Please enter a " + phonemsg + " for the BUYER of the store");
	return false;
  }
  if(f.buycell.value.length > 0 && !repho.test(f.buycell.value)) {
    ferror(f.buycell,"CELL should be a " +phonemsg);
	return false;
  }
  // comments
  if (ferror1(f.merchandise,"Please enter a description of the merchandise in the store", 10))
    return false;
  if (ferror1(f.comments,"Please enter a description of what you are looking for the store", 10))
    return false;
  return true;
}
/////////////////////////////////////////////
function CheckShipping()
{
  f = document.orderform;
  usa = f.shipcountry.value == "US";
  if (ferror1(f.shipstore,"Please enter the NAME of your company", 3))
    return false;
  if (ferror1(f.shipfname,"Please enter the FIRST NAME of the recipient for your order", 2))
    return false;
  if (ferror1(f.shiplname,"Please enter the LAST NAME of the recipient for your order", 2))
    return false;
  if (ferror1(f.shipaddr, "Please enter a shipping ADDRESS for your order", 3))
    return false;
  if(ferror1(f.shipcity,"Please enter a CITY for your order", 3))
    return false;
  re = /^[0-9]{5}$/; 
  if(usa && (f.shipzip.value.length != 5 || !re.test(f.shipzip.value))) {
    ferror(f.shipzip, "Please enter a 5 digit ZIP code for your order");
	return false;
  }
  if(!usa && f.shipprovince.value.length < 3) {
    ferror(f.shipprovince,"Please enter a PROVINCE if your country is not the USA");
	return false;
  }
  if(usa && f.shipstate.value=="XX"){
	  alert("Please enter a STATE in the USA");
      return false;
  }
  repho = /^\(?\d{3}\)?[-\s.]?\d{3}[-.]?\d{4}$/;
  phonemsg = "phone number with a 3 digit area code\nfollowed by a 3 digit prefix and 4 other digits";
  if(usa && !repho.test(f.strphone.value)) {
    ferror(f.strphone, "Please enter a " + phonemsg);
	return false;
  }
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(!re.test(f.email.value)){
    ferror(f.email,"Please enter a valid EMAIL address");
	return false;
  }
  return true;
}
function CheckApplicant()
{
  f = document.register;
  if(f.confirm.value=="yes"){
   conf = confirm("Are you sure you want to delete this user?");
   if(conf)
	   return true;
   else
	   return false;
  }
  usa = f.strcountry.value == "US";
  if (ferror1(f.strname,"Please enter the NAME of your store", 3))
    return false;
  if (ferror1(f.straddr, "Please enter the ADDRESS of your store", 3))
    return false;
  if(ferror1(f.strcity,"Please enter the CITY for your store", 3))
    return false;
  re = /^[0-9]{5}$/; 
  if(usa && (f.strzip.value.length != 5 || !re.test(f.strzip.value))) {
    ferror(f.strzip, "Please enter a 5 digit ZIP code for your store");
	return false;
  }
  if(!usa && f.strprovince.value.length < 3) {
    ferror(f.strprovince,"Please enter a PROVINCE if your country is not the USA");
	return false;
  }
  if(usa && f.strstate.value=="XX"){
	  alert("Please enter a STATE in the USA");
      return false;
  }
  repho = /^\(?\d{3}\)?[-\s.]?\d{3}[-.]?\d{4}$/;
  phonemsg = "phone number with a 3 digit area code\nfollowed by a 3 digit prefix and 4 other digits";
  if(usa && !repho.test(f.strphone.value)) {
    ferror(f.strphone, "Please enter a store " + phonemsg);
	return false;
  }
  if(f.strfax.value.length > 0 && !repho.test(f.strfax.value)) {
    ferror(f.strfax,"FAX should be a " +phonemsg);
	return false;
  }
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(!re.test(f.email.value)){
    ferror(f.email,"Please enter a valid EMAIL address");
	return false;
  }
  // owner
  if (ferror1(f.license,"Please enter the Business License Number for the store", 4))
    return false;
  if (ferror1(f.ownfname,"Please enter the FIRST NAME of the OWNER of the store", 2))
    return false;
  if (ferror1(f.ownlname,"Please enter the LAST NAME of the OWNER of the store", 2))
    return false;
  if(usa && !repho.test(f.ownphone.value)) {
    ferror(f.ownphone, "Please enter a " + phonemsg + " for the OWNER of the store");
	return false;
  }
  if(f.owncell.value.length > 0 && !repho.test(f.owncell.value)) {
    ferror(f.owncell,"CELL should be a " +phonemsg);
	return false;
  }
  // buyer
  if (ferror1(f.buyfname,"Please enter the FIRST NAME of the BUYER for the store", 2))
    return false;
  if (ferror1(f.buylname,"Please enter the LAST NAME of the BUYER for the store", 2))
    return false;
  if(usa && !repho.test(f.buyphone.value)) {
    ferror(f.buyphone, "Please enter a " + phonemsg + " for the BUYER of the store");
	return false;
  }
  if(f.buycell.value.length > 0 && !repho.test(f.buycell.value)) {
    ferror(f.buycell,"CELL should be a " +phonemsg);
	return false;
  }
  return true;
}
///////////////////////////////
function ferror1(t, msg, len)
{
  if(t.value.length < len) {
   ferror(t,msg);
   return true;
  }
  return false;
}
///////////////////////////////
function ferror(t,msg)
{
  alert(msg)
  t.focus();
  t.select();
}
function CCSubmit()
{
	var f1, f2, f3, m;
	f1 = document.pay;
	m = f1.paymethod.value;
	f2 = document.secure;
	f3 = document.online;
	if(m=='cc1'){
	  f2.submit();
	  return;
	}
	if(m=='cc2')
		f3.paymethod.value ='cc2';
	else if(m=='chk')
		f3.paymethod.value='chk';
	f3.submit();
}