// JavaScript Document
// *check the email address is valid
function IsValidEmail(Email){
  ValidFlag = false
  BadFlag = false
  if (Email.value != "" && Email.indexOf("@") > 0 && Email.indexOf(".") > 0){
    atCount = 0 
    SpecialFlag = false 
    for (atLoop=0; atLoop < Email.length; atLoop++){
      if (Email.charAt(atLoop) == "@"){ atCount = atCount + 1 }
      if (Email.charCodeAt(atLoop) >= 32 && Email.charCodeAt(atLoop) <= 44){ SpecialFlag = true }
      if (Email.charCodeAt(atLoop) == 47 || Email.charCodeAt(atLoop) == 96 || Email.charCodeAt(atLoop) >= 123){ SpecialFlag = true }
      if (Email.charCodeAt(atLoop) >= 58 && Email.charCodeAt(atLoop) <= 63){ SpecialFlag = true }
      if (Email.charCodeAt(atLoop) >= 91 && Email.charCodeAt(atLoop) <= 94){ SpecialFlag = true }
    }
    if (atCount == 1 && SpecialFlag == false){ 
      tAry1 = Email.split("@") 
      UserName = tAry1[0] 
      DomainName = tAry1[1] 
      if (UserName == "" || DomainName == ""){ BadFlag = true }
      if (DomainName.charAt(0) == "." ){ BadFlag = true }
      if (DomainName.charAt(DomainName.length-1) == "."){ BadFlag = true }
      ValidFlag = true 
    }
  } 
  if (BadFlag == true){ ValidFlag = false }
  return ValidFlag
}

function IsValidPass(code){
  ErrFlag = false
  for (atLoop=0; atLoop < code.length; atLoop++){
    if (code.charCodeAt(atLoop) >= 32 && code.charCodeAt(atLoop) <= 47){ ErrFlag = true; }
    if (code.charCodeAt(atLoop) >= 58 && code.charCodeAt(atLoop) <= 64){ ErrFlag = true; }
    if (code.charCodeAt(atLoop) >= 91 && code.charCodeAt(atLoop) <= 96){ ErrFlag = true; }
    if (code.charCodeAt(atLoop) > 122){ ErrFlag = true; }
  }
  return ErrFlag 
}

function IsValidContact(contact){
  ErrFlag = false;
  if (contact.length < 8){ ErrFlag = true }
  for (atLoop=0; atLoop<contact.length; atLoop++){
	if ((contact.charCodeAt(atLoop) < 48 || contact.charCodeAt(atLoop) > 57) && contact.charCodeAt(atLoop) != 45 && contact.charCodeAt(atLoop) != 46 && contact.charCodeAt(atLoop) != 43 && contact.charCodeAt(atLoop) != 32){ ErrFlag = true }
  }
  return ErrFlag;
}

function IsValidSite(site){
  return site.match(/^[A-Za-z0-9-_.]+\.+[A-Za-z0-9-_%&\?\/=.]+[A-Za-z]{2,3}$/g);
}

function isValidName(name){
	return name.match(/^([A-Za-z.-]+\'*\s*\-*){1,20}$/g);
}
function isValidAddress(address){
	return address.match(/^[A-Za-z0-9]+[\/\w\s,.'-]{9,39}[A-Za-z0-9.]+$/g);
}
function isValidCompanyName(companyname){
	return companyname.match(/^[A-Za-z0-9]+[\/\w\s,.'&+-]{9,39}[A-Za-z0-9.]+$/g);
}
function isValidCity(city){
	return city.match(/^[\/\w\s,.'-]{5,39}$/g);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}