// JavaScript Document
// work with css file dform_validate.css, which defines .drequired and .dhighlight
// for use of .dhint
onerror=handleErr;
var xFormValidate={
   req_class:"drequired",
   checked:"dchecked",
   hint:"dhint",
   highlight_class:"dhighlight",
   field:['input', 'textarea'],
   
   pass:true,
   
   validate: function(frm){
//alert(frm.action);
      this.form=frm;
      this.hint=document.getElementById(this.hint);
      this.pass=true;
      for (var i in this.field){
         this.pField( this.field[i] );
      }
      return this.pass;
   }, // validate
   
   checkPass: function (frm, newPass, retypePass){
      var nid=document.getElementById(newPass);
      var rid=document.getElementById(retypePass);
      if (nid.value == rid.value){
        return true;
      }else{
        alert('New password doesn\'t match with retype');
        return false;
      }
      alert(nid.value + '  =  ' + rid.value);
      return false;
   }, // checkPass
   
   pField: function(fld){
        var x=this.form.getElementsByTagName(fld);
        for (var i=0; i<x.length; i++) {
           if ( x[i].className.match(this.req_class)==this.req_class ) {         
               if ( x[i].value.trim().length>0?false:true ) {
                 x[i].className += " "+this.highlight_class;
                 if (this.hint!=null) this.hint.style.display="block";
                 this.pass=false;
               }
               else{
                 x[i].className.replace(this.highlight_class, "");
               }
           }
        }
     
   }, // pField
   
   pCheckBox: function (fld){
        var x=this.form.getElementsByTagName(fld);        
        for (var i=0; i<x.length; i++) {

           if ( x[i].className.match(this.checked)==this.checked ) {                
               if (x[i].checked){
                  this.pass= this.pass?true:false;
               }else{
                  this.pass=false;
               }
           }
        }

   }, // pCheckBox
   
   termsCheckBox: function (frm){
        this.validate(frm);
        this.pCheckBox("input");

      return this.pass;
   } // termsCheckBox
   
}  // xFormValidate

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}




/************/
function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n";
txt+="Error: " + msg + "\n";
txt+="URL: " + url + "\n";
txt+="Line: " + l + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return true;
}
/*************/
