
//validates that we have a selected a gender + looking for
function ValidateGender(){
    var res = true;
    if(getDropListSelectedValue('cbGender')==0) res=false;
    setValidIcon('valid_icon_g',res);
    return res;
}

function ValidateScreenName()
{
    var res = true;
    if (document.getElementById('txtRegUserName').value.length < 4)res=false;
    
    showItemError('valid_icon_n','name_error_txt',res,'Screen name invalid');
    return res;
}

function ValidatePassword()
{
  var res = true;
  if (document.getElementById('txtRegPassword').value.length < 6)res=false;
  
  showItemError('valid_icon_p','pass_error_txt',res,'6 or more characters');
  return res;

}

function ValidateEmail()
{
    var res = true;
    var eml=  document.getElementById('txtEmail').value;

    if (!IsEmailValid(eml)) res = false;
    
    showItemError('valid_icon_e','email_error_txt',res,'Email Address not valid');

    return res;
}

function ValidateLocation()
{
    var res = true;
    if (document.getElementById('txtLocation').value.length < 3) res=false;
    
    showItemError('valid_icon_l','loc_error_txt',res,'location area required');
   
    
   return res;

}



function ValidateDate()
{
   var res = true;
 
   if(getDropListSelectedValue('cbDay')==0 || 
      getDropListSelectedValue('cbMonth')==0 || 
      getDropListSelectedValue('cbYear')==0){
                   res = false;}
                   
   setValidIcon('valid_icon_d',res);
   
   
   return res;
}




function ValidateFrom()
{
 var res = true;
    
    if( !ValidateGender() | !ValidateDate() | !ValidateLocation() )
            res = false;

    if(!ValidateScreenName()| !ValidatePassword() | !ValidateEmail())
            res=false;

//now postback
if(res) {
__doPostBack('__Page', 'MyCustomArgument');

}

}

//++++++++++++++++++Helper Functions++++++++++++++++++++++++++++++++++++


function showItemError(icId,erId,res,text){
    if(res){
    document.getElementById(icId).className  = 'valid';
    clearErrorText(erId);
    }else{
    document.getElementById(icId).className  = 'invalid';
    showErrorText(erId,text);
    }
}


function showErrorText(id,text){
   document.getElementById(id).className  += ' error_txt';
   document.getElementById(id).innerHTML = text;
}

function clearErrorText(id){
   document.getElementById(id).className  = 'error_txt_box';
   document.getElementById(id).innerHTML = '';
}


function getDropListSelectedValue(id){
   return document.getElementById(id)[document.getElementById(id).selectedIndex].value;
}

//Sets valid/invalid icon
function setValidIcon(id,res){
   if(res)
     document.getElementById(id).className  = 'valid';
   else
     document.getElementById(id).className  = 'invalid';
}

function IsEmailValid(email){
var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
return filter.test(email)
}

function getKey(e){   
if (window.event)   
   return window.event.keyCode;   
else if (e)   
   return e.which;   
else   
   return null;   
} 

function restrictChars(e, validList)   
{   
var key, keyChar;   
key = getKey(e);   
if (key == null) return true;   
// get character - remove toLowerCase for case sensitive checking   
keyChar = String.fromCharCode(key).toLowerCase();   
// check valid characters - remove toLowerCase for case sensitive checking   
if (validList.toLowerCase().indexOf(keyChar) != -1)   
return true;   
// control keys   
// null, backspace, tab, carriage return, escape   
if ( key==0 || key==8 || key==9 || key==13 || key==27 )   
   return true;   
// else return false   
return false;   
}  

function numericOnly( e){    
  return restrictChars( e, "0123456789");   
}   
  
function alphanumericOnly(e){     
  return restrictChars( e, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");   
}  

function handleRestrict(e){
    return restrictChars(e, "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");   
}  