﻿var inputIdPwd = "txtPwd";
var inputIdConfirmPwd = "txtConfirmPwd";
var inputIdEmail = "txtEmail";
var inputIdConfirmEmail = "txtConfirmEmail";
var inputUserName = "txtUserName";
var inputIdFirstName = "txtFirstName";
var inputIdLastName = "txtLastName";
var inputIdMailingAddress = "txtAddress1";
var inputIdMailingAddress2 = "txtAddress2";
var inputIdCity = "txtCity";
var inputIdPhoneNumber = "txtPhoneNumber";
var inputIdCheckStrongPwd = "txtPwdStrongCheck";
var inputZipCode = "txtPostalCode";
var inputReferrer = "txtReferrer";

//---------------------------------------
var cmbCountryId = "cmbCountry";
var cmbState = "cmbState";


//---------------------------------------
var pUser = "pUserName";
var pIdConfirmPwdInfo = "pConfirmPwd";
var pIdPwdInfo = "pPwd";
var pEmail = "pEmail";
var pConfirmEmail = "pConfirmEmail";
var pFirstName = "pFirstName";
var pLastName = "pLastName";
var pMailAddress = "pMailingAddress";
var pMailAddress2 = "pMailingAddress2";
var pCity = "pCity";
var pCountry = "pCountry";
var pState = "pState";
var pPhoneNumber = "pPhoneNumber";
var pZipCode = "pZipCode";
var pReferrer = "pReferrer";

//--------------------------------------
var trUserName = "trInfoUserName";
var trIDPasswordInfo = "trInfoPwd";
var trIDPasswordInfo2 = "trInfoPwd2";
var trIDPasswordInfo3 = "trInfoPwd3";
var trIDConfirmPasswordInfo = "trInfoConfirmPwd";
var trIDInfoEmail = "trInfoEmail";
var trIDInfoConfirmEmail = "trInfoConfirmEmail";
var trIDFirstName = "trInfoFirstName";
var trIDLastName = "trInfoLastName";
var trIDMailingAddress = "trInfoAddress1";
var trIDMailingAddress2 = "trInfoAddress2";
var trIDCity = "trInfoCity";
var trIDCountry = "trInfoCountry";
var trIDState = "trInfoState";
var trZipCode = "trZipCode";
var trPhoneNumber = "trInfoPhoneNumber";
var trReferrer = "trInfoReferrer";
//----------------------------

var tdIDPwdMeter = "tdPwdMeter";

//-----------------------------

var divIdPwdStrongCheck = "divPwdStrongCheck";


//----------------------------
var errorPwdNotMatched = "This password doesn't match the confirmation password.";
var errorPwdLengthNotEnough = "Your password must be longer than 7 characters.";
var errorEmailFormat = "Please enter your e-mail address in the format someone@example.com."
var errorEmailNotMatched = "This email doesn't match the confirmation email.";
var errorEmpty = "Required information is missing.";
var errorSpecailCharacterFound = "The input shouldn't contain special characters, such as \\,<,>,&,' ";
var errorSbcCharacterFound = "The input should only contain ASCII characters now. Any other language characters such as Chinese, Japanese are not supported.";

//------------------------------
var regSbc = new RegExp('[^\x01-\xff]');
var regEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//------------------------------
function changeRowVisibleState(isVisible, rowId)
{
   if(isVisible!='true'&&isVisible!='false')
   {
      return;
   }
   var oRow = document.getElementById(rowId);
   if(oRow.style.display=='none'&&isVisible=='true')
   {
      oRow.style.display='';
      return;
   }
   
   if(oRow.style.display!='none'&&isVisible=='false')
   {   
      oRow.style.display="None";
      return;
   }
}

//type info: info, warning, error
function makeInfoText(txt, infoType, pId)
{
   
   var oP = document.getElementById(pId);
   if(infoType=="error")
   {
      oP.className="errMsg";
   }
   if(oP.hasChildNodes())
      oP.removeChild(oP.childNodes[0]);
   oP.appendChild(document.createTextNode(txt));
}

// Check whether pwd matched
function checkPwdMatch()
{
   var pwd = document.getElementById(inputIdPwd);
   var pwdConfirmed = document.getElementById(inputIdConfirmPwd);
   if(pwdConfirmed.value.length==0||pwd.value.length==0)
   {
      changeRowVisibleState("false",trIDConfirmPasswordInfo);
      return true;
   }
   if(pwd.value!=pwdConfirmed.value)
   {   
      makeInfoText(errorPwdNotMatched,"error",pIdConfirmPwdInfo);
      changeRowVisibleState("true",trIDConfirmPasswordInfo);
      return false;
   }
   else
   {
      changeRowVisibleState("false",trIDConfirmPasswordInfo);
      return true;
   }
}


function pwdLongEnough(minLength)
{
   var pwd = document.getElementById(inputIdPwd);
   if(pwd.value.length<minLength&&pwd.value.length>0)
   {
      makeInfoText(errorPwdLengthNotEnough,"error",pIdPwdInfo);
      changeRowVisibleState("true",trIDPasswordInfo);
      return false;
   }
   else
   {
      changeRowVisibleState("false",trIDPasswordInfo);
      return true;
   }
}

function validateEmail()
{
   var address  = document.getElementById(inputIdEmail).value;
   if(regEmail.test(address) == false) 
   {
      if(address=="")
      {
         changeRowVisibleState("false",trIDInfoEmail);
         return false;
      }
      makeInfoText(errorEmailFormat,"error",pEmail);
      changeRowVisibleState("true",trIDInfoEmail);
      return false;
   }
   else
   {
      changeRowVisibleState("false",trIDInfoEmail);
      return true;
   }
}

function validateConfirmEmail()
{
   var address  = document.getElementById(inputIdConfirmEmail).value;
   if(regEmail.test(address) == false) 
   {
      if(address=="")
      {
         changeRowVisibleState("false",trIDInfoConfirmEmail);
         return false;
      }
      makeInfoText(errorEmailFormat,"error",pConfirmEmail);
      changeRowVisibleState("true",trIDInfoConfirmEmail);
      return false;
   }
   else
   {
      changeRowVisibleState("false",trIDInfoConfirmEmail);
      return true;
   }
}

// Check whether Email matched
function checkEmailMatch()
{
   var email = document.getElementById(inputIdEmail);
   var emailConfirmed = document.getElementById(inputIdConfirmEmail);
   if(email.value.length==0||emailConfirmed.value.length==0)
   {
      changeRowVisibleState("false",trIDInfoConfirmEmail);
      return true;
   }
   if(email.value!=emailConfirmed.value)
   {   
      makeInfoText(errorEmailNotMatched,"error",pConfirmEmail);
      changeRowVisibleState("true",trIDInfoConfirmEmail);
      return false;
   }
   else
   {
      changeRowVisibleState("false",trIDInfoConfirmEmail);
      return true;
   }
}

function submitEmptyCheck()
{
   var tagResult = true;
   //check user name
   tagResult = (EmptyUserNameCheck(2) && tagResult)?true:false;
  
   //check password
   tagResult = (EmptyPasswordCheck(2) && tagResult)?true:false;
   
   //check confirm password
   tagResult = (EmptyPasswordConfirmCheck(2) && tagResult)?true:false;

   
   //check email
   tagResult = (EmptyEmailCheck(2) && tagResult)?true:false;
   
   //check confirm email
   tagResult = (EmptyConfirmEmailCheck(2) && tagResult)?true:false;
   
   //check first name
   tagResult = (EmptyFirstNameCheck(2) && tagResult)?true:false;
   
   //check last name
   tagResult = (EmptyLastNameCheck(2) && tagResult)?true:false;
   
   //check address
   tagResult = (EmptyAddressCheck(2) && tagResult)?true:false;
   
   //check city
   tagResult = (EmptyCityCheck(2) && tagResult)?true:false;
   
   //check country
   tagResult = (EmptyCountryCheck(2) && tagResult)?true:false;
   
   //check state
   tagResult = (EmptyStateCheck(2) && tagResult)?true:false;
   
   //check zipCode
   tagResult = (EmptyZipCodeCheck(2) && tagResult)?true:false;
   return tagResult;}

//-------------region empty check methods group----------
//---- check type: 0= if empty, 1= if not empty, 2= both  
function EmptyUserNameCheck(checkType) 
{
   var tagResult = true;
   var userName = RTrim(document.getElementById(inputUserName).value);
   if(userName == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pUser);
      changeRowVisibleState("true",trUserName);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trUserName);
   }
   return tagResult;
}
function EmptyPasswordCheck(checkType) 
{
   var tagResult = true;
   var pwd = document.getElementById(inputIdPwd).value;
   if(pwd == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pIdPwdInfo);
      changeRowVisibleState("true",trIDPasswordInfo);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDPasswordInfo);
   }
   return tagResult;
}
function EmptyPasswordConfirmCheck(checkType) 
{
   var tagResult = true;
   var pwdConfirm = document.getElementById(inputIdConfirmPwd).value;
   if(pwdConfirm == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pIdConfirmPwdInfo);
      changeRowVisibleState("true",trIDConfirmPasswordInfo);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDConfirmPasswordInfo);
   }
   return tagResult;
}
function EmptyEmailCheck(checkType) 
{
   var tagResult = true;
   var email = RTrim(document.getElementById(inputIdEmail).value);
   if(email == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pEmail);
      changeRowVisibleState("true",trIDInfoEmail);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDInfoEmail);
   } 
   return tagResult;
}
function EmptyConfirmEmailCheck(checkType) 
{
   var tagResult = true;
   var confirmEmail = RTrim(document.getElementById(inputIdConfirmEmail).value);
   if(confirmEmail == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pConfirmEmail);
      changeRowVisibleState("true",trIDInfoConfirmEmail);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDInfoConfirmEmail);
   }
   return tagResult;
}
function EmptyFirstNameCheck(checkType) 
{
   var tagResult = true;
   var firstName = RTrim(document.getElementById(inputIdFirstName).value);
   if(firstName == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pFirstName);
      changeRowVisibleState("true",trIDFirstName);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDFirstName);
   } 
   return tagResult;
}
function EmptyLastNameCheck(checkType) 
{
   var tagResult = true;
   var lastName = RTrim(document.getElementById(inputIdLastName).value);
   if(lastName == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pLastName);
      changeRowVisibleState("true",trIDLastName);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDLastName);
   }
   return tagResult;
}
function EmptyAddressCheck(checkType) 
{
   var tagResult = true;
   var address = RTrim(document.getElementById(inputIdMailingAddress).value);
   if(address == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pMailAddress);
      changeRowVisibleState("true",trIDMailingAddress);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDMailingAddress);
   } 
   return tagResult;
}
function EmptyCityCheck(checkType) 
{
   var tagResult = true;
   var city = RTrim(document.getElementById(inputIdCity).value);
   if(city == "")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pCity);
      changeRowVisibleState("true",trIDCity);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDCity);
   }
   return tagResult;
}
function EmptyCountryCheck(checkType) 
{
   var tagResult = true;
   var countryIndex = document.getElementById(cmbCountryId).selectedIndex;
   if(countryIndex == "0")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pCountry);
      changeRowVisibleState("true",trIDCountry);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDCountry);
   }
   return tagResult;
}
function EmptyStateCheck(checkType) 
{
   var tagResult = true;
   var stateIndex = document.getElementById(cmbState).selectedIndex;
   var countryIndex = document.getElementById(cmbCountryId).selectedIndex;
   if(stateIndex == "0"&&document.getElementById(cmbCountryId).options[countryIndex].value=="US")
   {
      if(checkType==0||checkType==2)
      {
      makeInfoText(errorEmpty,"error",pState);
      changeRowVisibleState("true",trIDState);
      tagResult = false;
      }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trIDState);
   }
   return tagResult;
}
function EmptyZipCodeCheck(checkType) 
{
   var tagResult = true;
   var zipCode = RTrim(document.getElementById(inputZipCode).value);
   if(zipCode == "")
   {
       if (checkType == 0 || checkType == 2) {
           makeInfoText(errorEmpty, "error", pZipCode);
           changeRowVisibleState("true", trZipCode);
           tagResult = false;
       }
   }
   else
   {
      if (checkType == 1 || checkType == 2)
      changeRowVisibleState("false",trZipCode);
   }
   return tagResult;
} 
 
//-------------end region-----------------------


//-------------region sbc check method----------
function SbcUserNameCheck() 
{
    var tagResult = true;
    var userName = document.getElementById(inputUserName).value;
    if (regSbc.exec(userName)) {
        makeInfoText(errorSbcCharacterFound, "error", pUser);
        changeRowVisibleState("true", trUserName);
        tagResult = false;
    }
    else 
    {
        changeRowVisibleState("false", trUserName);
    }
    return tagResult;
}

function SbcPasswordCheck() 
{
    var tagResult = true;
    var pwd = document.getElementById(inputIdPwd).value;
    if (regSbc.exec(pwd)) {
        makeInfoText(errorSbcCharacterFound, "error", pIdPwdInfo);
        changeRowVisibleState("true", trIDPasswordInfo);
        tagResult = false;
    }
    else 
    {
        changeRowVisibleState("false", trIDPasswordInfo);
    }
    return tagResult;
}

function SbcEmailCheck() 
{
    var tagResult = true;
    var email = document.getElementById(inputIdEmail).value;
    if (regSbc.exec(email)) {
        makeInfoText(errorSbcCharacterFound, "error", pEmail);
        changeRowVisibleState("true", trIDInfoEmail);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDInfoEmail);
    }
    return tagResult;
}

function SbcFirstNameCheck() 
{
    var tagResult = true;
    var firstName = document.getElementById(inputIdFirstName).value;
    if (regSbc.exec(firstName)) {
        makeInfoText(errorSbcCharacterFound, "error", pFirstName);
        changeRowVisibleState("true", trIDFirstName);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDFirstName);
    }
    return tagResult;
}
function SbcLastNameCheck() 
{
    var tagResult = true;
    var lastName = document.getElementById(inputIdLastName).value;
    if (regSbc.exec(lastName)) {
        makeInfoText(errorSbcCharacterFound, "error", pLastName);
        changeRowVisibleState("true", trIDLastName);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDLastName);
    }
    return tagResult;
}
function SbcAddressCheck() 
{
    var tagResult = true;
    var address = document.getElementById(inputIdMailingAddress).value;
    if (regSbc.exec(address)) {
        makeInfoText(errorSbcCharacterFound, "error", pMailAddress);
        changeRowVisibleState("true", trIDMailingAddress);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDMailingAddress);
    }
    return tagResult;
}
function SbcAddress2Check() 
{
    var tagResult = true;
    var address2 = document.getElementById(inputIdMailingAddress2).value;
    if (regSbc.exec(address2)) {
        makeInfoText(errorSbcCharacterFound, "error", pMailAddress2);
        changeRowVisibleState("true", trIDMailingAddress2);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDMailingAddress2);
    }
    return tagResult;
}
function SbcCityCheck() 
{
    var tagResult = true;
    var city = document.getElementById(inputIdCity).value;
    if (regSbc.exec(city)) {
        makeInfoText(errorSbcCharacterFound, "error", pCity);
        changeRowVisibleState("true", trIDCity);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDCity);
    }
    return tagResult;
}
function SbcPhoneNumberCheck() 
{
    var tagResult = true;
    var phoneNumber = document.getElementById(inputIdPhoneNumber).value;
    if (regSbc.exec(phoneNumber)) {
        makeInfoText(errorSbcCharacterFound, "error", pPhoneNumber);
        changeRowVisibleState("true", trPhoneNumber);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trPhoneNumber);
    }
    return tagResult;
}
function SbcZipCodeCheck() 
{
    var tagResult = true;
    var zipCode = document.getElementById(inputZipCode).value;
    if (regSbc.exec(zipCode)) {
        makeInfoText(errorSbcCharacterFound, "error", pZipCode);
        changeRowVisibleState("true", trZipCode);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trZipCode);
    }
    return tagResult;
}
function SbcReferrerCheck() 
{
    var tagResult = true;
    var referrer = document.getElementById(inputReferrer).value;
    if (regSbc.exec(referrer)) {
        makeInfoText(errorSbcCharacterFound, "error", pReferrer);
        changeRowVisibleState("true", trReferrer);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trReferrer);
    }
    return tagResult;
}

//-------------end region-----------------------

function submitSbcCheck() {
    var tagResult = true;
    //check user name
    tagResult = (SbcUserNameCheck() && tagResult)?true:false;

    //check password
    tagResult = (SbcPasswordCheck() && tagResult)?true:false;

    //check email
    tagResult = (SbcEmailCheck() && tagResult)?true:false;

    //check first name
    tagResult = (SbcFirstNameCheck() && tagResult)?true:false;

    //check last name
    tagResult = (SbcLastNameCheck() && tagResult)?true:false;

    //check address
    tagResult = (SbcAddressCheck() && tagResult)?true:false;

    //check address2
    tagResult = (SbcAddress2Check() && tagResult)?true:false;

    //check city
    tagResult = (SbcCityCheck() && tagResult)?true:false;

    //check phoneNumber
    tagResult = (SbcPhoneNumberCheck() && tagResult)?true:false;

    //check zipCode
    tagResult = (SbcZipCodeCheck() && tagResult)?true:false;

    //check referrer
    tagResult = (SbcReferrerCheck() && tagResult)?true:false;
    
    return tagResult;
}

function submitCheck()
{
   if (!submitSbcCheck()) 
   {
        return false;
   }
   if (!submitSpecialCharacterCheck()) {
        return false;
   }
   if(!submitEmptyCheck())
   {
      return false;
   }
   if(!pwdLongEnough(7))
   {
      return false;
   }
   if(!checkPwdMatch())
   {
      return false;
   } 
   if(!validateEmail())
   {
      return false;
   }
   if(!validateConfirmEmail())
   {
      return false;
   }
   if(!checkEmailMatch())
   {
      return false;
   }
   return true;
}

function checkStrongPassword()
{
   var oInputPwd = document.getElementById(inputIdPwd);
   var oTdCheckStrongPwd = document.getElementById(tdIDPwdMeter);
   var divCheckPwd = document.getElementById(divIdPwdStrongCheck);
   if(oTdCheckStrongPwd.hasChildNodes())
      oTdCheckStrongPwd.removeChild(oTdCheckStrongPwd.childNodes[0]);
   if(oInputPwd.value.length>=7)
   {
      var patrn1=/[0-9]/;
      var numberExist = patrn1.exec(oInputPwd.value);
      var patrn2=/[a-zA-Z]/;
      var characterExist = patrn2.exec(oInputPwd.value);
      var patrn3=/[^a-zA-Z0-9]/;
      var specialCharacterExist = patrn3.exec(oInputPwd.value);
      if(numberExist&&characterExist&&specialCharacterExist)
      {  
         divCheckPwd.style.width="170px"
         oTdCheckStrongPwd.appendChild(document.createTextNode("Strong"));
         
      }
      else if((!numberExist)&&characterExist&&specialCharacterExist)
      {  
         divCheckPwd.style.width="114px"
         oTdCheckStrongPwd.appendChild(document.createTextNode("Medium"));
      }
      else if(numberExist&&(!characterExist)&&specialCharacterExist)
      {  
         divCheckPwd.style.width="114px"
         oTdCheckStrongPwd.appendChild(document.createTextNode("Medium"));
      }
      else if(numberExist&&characterExist&&(!specialCharacterExist))
      {  
         divCheckPwd.style.width="114px"
         oTdCheckStrongPwd.appendChild(document.createTextNode("Medium"));
      }
      else
      {
        divCheckPwd.style.width="57px"
        oTdCheckStrongPwd.appendChild(document.createTextNode("Weak"));
      }
  }
  else
  {
        divCheckPwd.style.width="0px"  
  }
}


function checkCountryChange()
{
   var objCountry = document.getElementById(cmbCountryId);
   var countryIndex = objCountry.selectedIndex;
   var objState = document.getElementById(cmbState);
   if(objCountry.options[countryIndex].value=="US")
   {
      objState.disabled = false;
   }
   else
   {
      objState.selectedIndex=0;
      objState.disabled = true;
      changeRowVisibleState("false",trIDCountry);
   }
}

function onblurUerNameCheck()
{
    if(!EmptyUserNameCheck(1))
        return;
    if (!SCUserNameCheck())
        return;
    SbcUserNameCheck();
}

function onblurFirstNameCheck() {
    if (!EmptyFirstNameCheck(1))
        return;
    if (!SCFirstNameCheck())
        return;
    SbcFirstNameCheck();

}

function onblurLastNameCheck() {
    if (!EmptyLastNameCheck(1))
        return;
    if (!SCLastNameCheck())
        return;
    SbcLastNameCheck();
}

function onblurMailingAddressCheck()
{
    if (!EmptyAddressCheck(1))
        return;
    if (!SCAddressCheck())
        return;
    SbcAddressCheck();
}

function onblurMailingAddress2Check() {
    if (!SCAddress2Check())
        return;
    SbcAddress2Check();
}

function onblurCityCheck()
{
    if (!EmptyCityCheck(1))
        return;
    if (!SCCityCheck())
        return;
    SbcCityCheck();}

function onblurZipcodeCheck() {
    if (!EmptyZipCodeCheck(1))
        return;
    if (!SCZipCodeCheck())
        return;
    SbcZipCodeCheck();
}

function onblurPhoneNumberCheck() {
    if (!SCPhoneNumberCheck())
        return;
    SbcPhoneNumberCheck();
}

function onblurReferrerCheck() {
    if (!SCReferrerCheck())
        return;
    SbcReferrerCheck();
}

function displayStrongpasswordBar(displayed)
{
   if(displayed=="true")
       changeRowVisibleState("true",trIDPasswordInfo3);
    else  
       changeRowVisibleState("false",trIDPasswordInfo3);
}

function txtPhoneNumber_onclick()
{
   //Todo: Need to know the policy to check phone number.
   return true;
}

function findSpecailCharacters(str)
{
   if(str.indexOf("\\")>-1)
   {
      return false;
   }
   if(str.indexOf("<")>-1)
   {
      return false;
   }
   if(str.indexOf(">")>-1)
   {
      return false;
   }
   if(str.indexOf("&")>-1)
   {
      return false;
   }
   if (str.indexOf("'") > -1) {
       return false;
   }
   return true;
}

//--------------region special character check------------

function SCUserNameCheck() {
   var tagResult = true;
   var userName = document.getElementById(inputUserName).value;
   if(!findSpecailCharacters(userName))
   {
      makeInfoText(errorSpecailCharacterFound,"error",pUser);
      changeRowVisibleState("true",trUserName);
      tagResult = false;
   }
   else
   {
      changeRowVisibleState("false",trUserName);
   }
   return tagResult;
}

function SCPasswordCheck() {
   var tagResult = true;
   var pwd = document.getElementById(inputIdPwd).value;
   if(!findSpecailCharacters(pwd))
   {
      makeInfoText(errorSpecailCharacterFound,"error",pIdPwdInfo);
      changeRowVisibleState("true",trIDPasswordInfo);
      tagResult = false;
   }
   else
   {
      changeRowVisibleState("false",trIDPasswordInfo);
   }
   return tagResult;
}

function SCEmailCheck() {
    var tagResult = true;
    var email = document.getElementById(inputIdEmail).value;
    if(!findSpecailCharacters(email))
    {
      makeInfoText(errorSpecailCharacterFound,"error",pEmail);
      changeRowVisibleState("true",trIDInfoEmail);
      tagResult = false;
    }
    else
    {
      changeRowVisibleState("false",trIDInfoEmail);
    }
    return tagResult;
}

function SCFirstNameCheck() {
   var tagResult = true;
   var firstName = document.getElementById(inputIdFirstName).value;
   if(!findSpecailCharacters(firstName))
   {
      makeInfoText(errorSpecailCharacterFound,"error",pFirstName);
      changeRowVisibleState("true",trIDFirstName);
      tagResult = false;
   }
   else
   {
      changeRowVisibleState("false",trIDFirstName);
   }
    return tagResult;
}

function SCLastNameCheck() {
   var tagResult = true;
   var lastName = document.getElementById(inputIdLastName).value;
   if(!findSpecailCharacters(lastName))
   {
      makeInfoText(errorSpecailCharacterFound,"error",pLastName);
      changeRowVisibleState("true",trIDLastName);
      tagResult = false;
   }
   else
   {
      changeRowVisibleState("false",trIDLastName);
   }
   return tagResult;
}

function SCAddressCheck() {
    var tagResult = true;
    var address = document.getElementById(inputIdMailingAddress).value;
    if(!findSpecailCharacters(address))
    {
      makeInfoText(errorSpecailCharacterFound,"error",pMailAddress);
      changeRowVisibleState("true",trIDMailingAddress);
      tagResult = false;
    }
    else
    {
      changeRowVisibleState("false",trIDMailingAddress);
    }
    return tagResult;
}

function SCAddress2Check() {
    var tagResult = true;
    var address2 = document.getElementById(inputIdMailingAddress2).value;
    if (!findSpecailCharacters(address2)) {
        makeInfoText(errorSpecailCharacterFound, "error", pMailAddress2);
        changeRowVisibleState("true", trIDMailingAddress2);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trIDMailingAddress2);
    }
    return tagResult;
}

function SCCityCheck() {
   var tagResult = true;
   var city = document.getElementById(inputIdCity).value;
   if(!findSpecailCharacters(city))
   {
      makeInfoText(errorSpecailCharacterFound,"error",pCity);
      changeRowVisibleState("true",trIDCity);
      tagResult = false;
   }
   else
   {
      changeRowVisibleState("false",trIDCity);
   }
   return tagResult;
}


function SCZipCodeCheck() {
    var tagResult = true;
    var zipCode = document.getElementById(inputZipCode).value;
    if (!findSpecailCharacters(zipCode)) {
        makeInfoText(errorSpecailCharacterFound, "error", pZipCode);
        changeRowVisibleState("true", trZipCode);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trZipCode);
    }
    return tagResult;
}

function SCPhoneNumberCheck() {
    var tagResult = true;
    var phoneNumber = document.getElementById(inputIdPhoneNumber).value;
    if (!findSpecailCharacters(phoneNumber)) {
        makeInfoText(errorSpecailCharacterFound, "error", pPhoneNumber);
        changeRowVisibleState("true", trPhoneNumber);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trPhoneNumber);
    }
    return tagResult;
}

function SCReferrerCheck() {
    var tagResult = true;
    var referrer = document.getElementById(inputReferrer).value;
    if (!findSpecailCharacters(referrer)) {
        makeInfoText(errorSpecailCharacterFound, "error", pReferrer);
        changeRowVisibleState("true", trReferrer);
        tagResult = false;
    }
    else {
        changeRowVisibleState("false", trReferrer);
    }
    return tagResult;
}



//--------------end region ------------
function submitSpecialCharacterCheck()
{
    var tagResult = true;
   //check user name
   tagResult = (SCUserNameCheck() && tagResult)?true:false;

   //check email
   tagResult = (SCEmailCheck() && tagResult) ? true : false;

   //check password
   tagResult = (SCPasswordCheck() && tagResult) ? true : false;
   
   //check first name
   tagResult = (SCFirstNameCheck() && tagResult)?true:false;
   
   //check last name
   tagResult = (SCLastNameCheck() && tagResult)?true:false;
   
   //check address
   tagResult = (SCAddressCheck() && tagResult)?true:false;

   //check address2
   tagResult = (SCAddress2Check() && tagResult)?true:false;
   
   //check city
   tagResult = (SCCityCheck() && tagResult)?true:false;

   //zipcode check
   tagResult = (SCZipCodeCheck() && tagResult)?true:false;
   
   //phone number
   tagResult = (SCPhoneNumberCheck() && tagResult)?true:false;

   //referrer
   tagResult = (SCReferrerCheck() && tagResult)?true:false;
   
   return tagResult;
}


window.onload = function()
{
   checkCountryChange();
}

// ==========================================================================
// Fuctions to mimic LTrim, RTrim, and Trim...

// ==========================================================================

// --------------------------------------------------------------------------
// Remove leading blanks from our string.

// I               str - the string we want to LTrim
// Return          the input string without any leading whitespace

// --------------------------------------------------------------------------
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}

// --------------------------------------------------------------------------
// Remove trailing blanks from our string.

// I               str - the string we want to RTrim
// Return          the input string without any trailing whitespace

// --------------------------------------------------------------------------
function RTrim(str)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...

    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;


    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}


// --------------------------------------------------------------------------
// Remove railing and leading blanks from our string.

// I               str - the string we want to Trim
// Return          the trimmed input string

// --------------------------------------------------------------------------
function Trim(str)
{
  return RTrim(LTrim(str));
}

// EOF