/* --------------------------------------------------------------------------
 * class FormValidator, specialization of FormValidator for Field value testing  
 * -------------------------------------------------------------------------- */
function FormValidator() {
  this.bEmail = true; 
  this.bPwd = true;
  this.bPwd2 = true;
  this.bEmail2 = true; 
  this.bEmpty = true; 
  this.bRadio = true;
  this.bZip = true;
  this.bUrl = true;
  this.bChecked = true;
  this.bMeaningful = true;
}

/* --------------------------------------------------------------------------
 * private members 
 * -------------------------------------------------------------------------- */
FormValidator.prototype.showErr = function(input_id,err_id) {
  var i=document.getElementById(input_id);
  var e=document.getElementById(err_id);
  i.style.border='1px solid #F00';
  i.style.backgroundColor='#FEE';
  e.style.visibility='visible';
}
FormValidator.prototype.hideErr = function(input_id,err_id) {
  var i=document.getElementById(input_id);
  var e=document.getElementById(err_id);
  i.style.border='1px solid #F2BD2F';
  i.style.backgroundColor='#FFF4C6';
  e.style.visibility='hidden';
}

/* --------------------------------------------------------------------------
 * public members 
 * -------------------------------------------------------------------------- */
FormValidator.prototype.ret = function() {
  var bRet = this.bEmail && this.bPwd && this.bPwd2 && this.bEmail2 && this.bEmpty && this.bRadio && this.bZip && this.bUrl && this.bChecked && this.bMeaningful; 
  return bRet; 
}
FormValidator.prototype.set_bEmail = function( value ) {
  this.bEmail = value; 
}
FormValidator.prototype.email = function( value, input_id, err_id ) {
  var regexEmail = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/
  if( value.search(regexEmail) == -1 ) {
    this.showErr( input_id, err_id );
    this.bEmail = false;
    return false;
  } else {
    this.hideErr( input_id, err_id );
    this.bEmail = true;
    return true;
  }
}
FormValidator.prototype.email2 = function( value, value2, input_id, err_id ) {
  if( value == undefined || value2 == undefined ) return;
  if( value != value2 ) {
    this.showErr( input_id, err_id );
    this.bEmail2 = false;
  } else {
    this.hideErr( input_id, err_id );
    this.bEmail2 = true;
  }
}
FormValidator.prototype.pwd = function( value, input_id, err_id ) {
  if( value.length < 6 ) {
    this.showErr( input_id, err_id );
    this.bPwd = false;
  } else {
    this.hideErr( input_id, err_id );
    this.bPwd = true;
  }
}
FormValidator.prototype.pwd2 = function( value, value2, input_id, err_id ) {
  if( value != value2 ) {
    this.showErr( input_id, err_id );
    this.bPwd2 = false;
  } else {
    this.hideErr( input_id, err_id );
    this.bPwd2 = true;
  }
}
FormValidator.prototype.isMeaningful = function( value, input_id, err_id ) {
  if( value.length < 25 ) {
    this.showErr( input_id, err_id );
    this.bMeaningful = false;
  } else {
    this.hideErr( input_id, err_id );
    this.bMeaningful = true;
  }
}
FormValidator.prototype.empty = function( value, input_id, err_id ) {
  if( value == "" ) {
    this.showErr( input_id, err_id );
    this.bEmpty = false;
  }
  else {
    this.hideErr( input_id, err_id );
    this.bEmpty = true;
  }
}
FormValidator.prototype.radio = function( oGender, frame_id, err_id ) {
  var f=document.getElementById(frame_id);
  var e=document.getElementById(err_id);
  if( oGender[0].checked || oGender[1].checked ) {
    f.style.border='1px solid #FFF';
    e.style.visibility='hidden';
    this.bRadio = true;        
  } else {  
    f.style.border='1px solid #F11';
    e.style.visibility='visible';    
    this.bRadio = false;
  }
}
FormValidator.prototype.isZip = function( value, input_id, err_id ) {
  if( isNaN( value ) || value.length != 5 ) {
    this.showErr( input_id, err_id );
    this.bZip = false;
  } else {
    this.hideErr( input_id, err_id );
    this.bZip = true;
  }    
}
FormValidator.prototype.isUrl = function( value, input_id, err_id ) {
  var regexUrl = /^(http:\/\/)?[A-Z0-9-_.]+\.[A-Z]{2,4}(\/[A-Z0-9-\/]*)?\b/i  
  if( value.search(regexUrl) > -1 || value == '' ) {
    this.hideErr( input_id, err_id );
    this.bUrl = true;
    return true;
  } else {
    this.showErr( input_id, err_id );
    this.bUrl = false;
    return false;
  }
}
FormValidator.prototype.isChecked = function( checkbox, input_id, err_id ) {
  if( checkbox.checked == false ) {
    this.showErr( input_id, err_id );
    this.bChecked = false;
  }  
  else {
    this.hideErr( input_id,err_id );
    this.bChecked = true;    
  }
}
