//--- set to true to skip client side validations for testing server side validation
lDebugServerSide = false;

//--- validation regexes
rxUserName = /^[-a-zA-Z0-9._]{1,30}$/;
rxPassword = /^[-a-zA-Z0-9._]{5,30}$/;
rxEmail    = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;

/*
-- Signup2 validation
*/
function ValidateSignup2() {

  if ( lDebugServerSide ) { return true; }

  lRet   = true;
  oMsg   = false;
  cName  = document.getElementById("txtUserName").value;
  cPw1   = document.getElementById("txtPassword1").value;
  cPw2   = document.getElementById("txtPassword2").value;
  cEmail = document.getElementById("txtEmail").value;
  
  //----- validations
  if ( !rxUserName.test(cName) ) {
  
    oMsg = BuildVMsg(" -- Invalid user name.", oMsg);
  }
  if ( !rxPassword.test(cPw1) ) {
  
    oMsg = BuildVMsg(" -- Invalid password.", oMsg);
    
  } else if (cPw1 != cPw2) {
  
    oMsg = BuildVMsg(" -- Passwords don't match.", oMsg);    
  }
  if ( !rxEmail.test(cEmail) ) {

    oMsg = BuildVMsg(" -- Invalid email.", oMsg);
  }

  //---- remove any old validations messages
  oDiv = document.getElementById("Signup2ValidationMsg");
 
  while ( oDiv.hasChildNodes() ) { 
  
    oDiv.removeChild(oDiv.lastChild); 
  }
  
  if (oMsg) {
  
    lRet = false;
  
    oDiv.appendChild(oMsg);  
  }
  return lRet;
} 

function BuildVMsg(cMsg, oP) {

  if ( !oP ) {
  
    oP = document.createElement("p");

    oP.className = "VError";
  }

  if ( oP.hasChildNodes() ) {
  
    oP.appendChild( document.createElement("br") );
    
  }
  
  oTxt = document.createTextNode(cMsg);
  
  oP.appendChild(oTxt);
  
  return oP;
}
function ReplaceContent(oParent, oNewContent)
{
    if ( typeof oParent == "string" )
    {
        oParent = document.getElementById(oParent);
    }
    while ( oParent.hasChildNodes() ) 
    { 
        oParent.removeChild(oParent.lastChild); 
    }
    oParent.appendChild(oNewContent);
}

function rOver(oImg) {
  var cSrc = oImg.src;
  var rRO  = /_ro\./;
  if (!rRO.test(cSrc)) {oImg.src = cSrc.replace(/.jpg/,"_ro.jpg");}
}
function rOut(oImg) {
  var cSrc = oImg.src;
  var rRO  = /_ro\./;
  if (rRO.test(cSrc)) {oImg.src = cSrc.replace(/_ro.jpg/,".jpg");}
}


