var ErrorMsg=new Array(
 'is empty',
 'is not a possitive number',
 'is not a valid date (dd.mm.yyyy)',
 'is not a valid IP address\n\nExample: 192.168.0.1',
 'is not a valid email address\n\nExample: you@yourserver.com',
 'is less then 0'
);
var Condition=new Array(
 'a!=""',
 'a>0',
 'a.length>7&&!(a.split(".")[0]*1>31)&&!(a.split(".")[1]*1>12)&&!(a.split(".")[2]*1<1900)', //date
 'a.length>6&&!(a.split(".")[0]*1>255)&&!(a.split(".")[0]*1<1)&&!(a.split(".")[1]*1>255)&&!(a.split(".")[2]*1>255)&&(a.split(".")[3])&&!(a.split(".")[3]*1>255)', //ip
 'a!=""&&a.length>5&&a.indexOf("@")!=-1&&a.indexOf(".")!=-1', //email
 'a>=0'
);

function docheck(RuleN,FormName,CtrlName,Name){
   eval("a=document." + FormName + "." + CtrlName + ".value");
   if(! eval(Condition[RuleN])) {
      err = "Error: \n'" + Name + "' " + ErrorMsg[RuleN];
      alert(err);
      eval("document." + FormName + "." + CtrlName + ".focus()");
      return false;
   }
   return true;
}

function chk_model(){
   var ret = true;
   ret &= docheck(1,'modelfrm','power','Power');
   ret &= docheck(1,'modelfrm','load','Load');
   ret &= docheck(1,'modelfrm','htime','Hold Time');
   ret &= docheck(1,'modelfrm','rtime','Recharge Time');
   ret &= docheck(2,'modelfrm','bid','Battery Installation Date');
   return ret?true:false;
}

function chk_net(){
   var ret = true;
   ret &= docheck(3,'netfrm','ip','Local Address');
   ret &= docheck(3,'netfrm','dgw','Default Gateway');
   ret &= docheck(3,'netfrm','subnet','Subnet Mask');
   if(document.netfrm.pwd1.value != document.netfrm.pwd2.value) {
      alert("administrator passwords different");
      document.netfrm.pwd2.focus();
      return false;
   }
   if(document.netfrm.mpwd1.value != document.netfrm.mpwd2.value) {
      alert("upsmon passwords different");
      document.netfrm.mpwd2.focus();
      return false;
   }
   return ret?true:false;
}

function chk_snmp(){
   var ret = true;
   return ret?true:false;
}

function chk_mail(){
   var ret = true;
   //ret &= docheck(3,'mailfrm','server','Mail Server Address');

   ret &= docheck(4,'mailfrm','account','Account Name');
   if(document.mailfrm.eventmail.checked) {
      ret &= docheck(4,'mailfrm','admaccount','Administrator Account');
   }

   if(document.mailfrm.pwd1.value != document.mailfrm.pwd2.value) {
      alert("passwords different");
      document.mailfrm.pwd2.focus();
      return false;
   }
   return ret?true:false;
}

function chk_mail2(){
   var ret = true;
   //ret &= docheck(4,'mailfrm2','receiver','Receiver Address');
   ret &= docheck(0,'mailfrm2','mail','EMail Body');
   return ret?true:false;
}

function chk_mail3(){
   return true;
}

function chk_time(){
   var ret = true;
   //ret &= docheck(3,'timefrm','timea','Time Server Address');
   return ret?true:false;
}

function chk_com2(){
   var ret = true;
   return ret?true:false;
}

function chk_tempman(){
   var ret = true;
   return ret?true:false;
}

function chk_job(){
   return true;
}

function set_model(x) {
 if(document.modelfrm.power)  document.modelfrm.power.value = model[x].split("|")[0];
 if(document.modelfrm.load)   document.modelfrm.load.value = model[x].split("|")[1];
 if(document.modelfrm.htime)  document.modelfrm.htime.value = model[x].split("|")[2];
 if(document.modelfrm.rtime)  document.modelfrm.rtime.value = model[x].split("|")[3];
 if(document.modelfrm.baud)   document.modelfrm.baud.value = model[x].split("|")[4];
 if(document.modelfrm.parity) document.modelfrm.parity.value = model[x].split("|")[5];
 if(document.modelfrm.dbits)  document.modelfrm.dbits.value = model[x].split("|")[6];
 if(document.modelfrm.sbits)  document.modelfrm.sbits.value = model[x].split("|")[7];
 if(document.modelfrm.cable)  document.modelfrm.cable.value = model[x].split("|")[8];
 var prot = model[x].split("|")[9];
 if((prot==32887/*AETSET*/) || (prot==32860/*FUJI__G*/)) {
  document.getElementById("vout_a").style.display = "inline";
  document.getElementById("vout_b").style.display = "inline";
 }
 else {
  document.getElementById("vout_a").style.display = "none";
  document.getElementById("vout_b").style.display = "none";
 }
}

// tooltip functions

document.onmousemove = TTupdate;
var tt_cs121 = null;

function TTupdate(e) {
 x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
 y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
 if(tt_cs121) {
  tt_cs121.style.left = (x - (x/8)) + "px";
  tt_cs121.style.top  = (y + 16) + "px";
 }
}

function TTshow(id) {
 if(tt_cs121 = document.getElementById(id)) {
  if(document.all) {
   tt_cs121.style.left= (window.event.x+document.body.scrollLeft+8)+ "px";
   tt_cs121.style.top = (window.event.y+document.body.scrollTop+8) + "px";
  }
  tt_cs121.style.display = "block";
 }
}

function TTtext(id, txt) {
 if(tt_cs121 = document.getElementById(id)) {
  tt_cs121.innerHTML = txt;
  TTshow(id);
 }
}

function TThide() {
 if(tt_cs121) {
  tt_cs121.style.display = "none";
 }
}
