// domain.kg client-side script
// (c) http://www.e.com.kg

function ov(o,ot){if(document.all){o.style.background="#31659C"; ot.style.color="white";}}
function ou(o,ot){if(document.all){o.style.background="#E5E5E5"; ot.style.color="black";}}
function m_pid(){var o=document.forms[0].elements[0].checked, s=(o)?"pnh_n.html":"pnh_m.html"; document.location.replace(s);return(false);}
function m_dmn(){var o=document.forms[0].elements[0].checked, s=(o)?"dmn_n.html":"dmn_m.html"; document.location.replace(s);return(false);}

function ispswok(Str)
{ var rc=true, checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_#$@.-";
  for (i = 0;  i < Str.length;  i++)
    { ch = Str.charAt(i);
      for (j=0; j<checkOK.length; j++) if (ch == checkOK.charAt(j)) break;
      if (j==checkOK.length) {rc=false;}
    }
  return (rc);
}

function chk_pid(o,ii)
{ if(!ispswok(o.psw1.value)) { alert("Invalid password"); o.psw1.focus(); return(false);}
  if(o.psw1.value!=o.psw2.value) {{ alert("Passwords mismatch"); o.psw1.focus(); return(false);}}
  if (ii)
  { if( (o.psw1.value.length<6)&&(o.psw1.value.length>0) ) {alert("Password must be 6 chars or greater"); o.psw1.focus(); return(false);}
  }
  else
  { if (o.psw1.value.length<6) {alert("Password must be 6 chars or greater"); o.psw1.focus(); return(false);}
  }
  if((o.psw0.value.length<6)&&(ii)){alert("Password must be 6 chars or greater"); o.psw0.focus(); return(false);}
  if( (o.fio.value=="")||(o.eeml.value=="")||(o.addr.value=="")||(o.tel.value=="") )
  { alert("Please fill out ALL required fields"); o.fio.focus(); return(false);
  }
  return(true);
}

function chk_log(o)
{ if(!ispswok(o.psw.value)) { alert("Invalid passwrod"); o.psw.focus(); return(false);}
  if( (o.psw.value=="")||(o.pid.value=="") )
  { alert("Please specify all the necessary information"); o.pid.focus(); return(false);
  }
  o.pid.value=o.pid.value.toUpperCase();
  return(true);
}

function dm_log(o)
{ o.dmn.value=o.dmn.value.toUpperCase();
  var rc=true, Str=o.dmn.value, checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-";
  for (i = 0;  i < Str.length;  i++)
    { ch = Str.charAt(i);
      for (j=0; j<checkOK.length; j++) if (ch == checkOK.charAt(j)) break;
      if (j==checkOK.length) {rc=false;}
    }
  if (Str.length<1) {rc=false; o.dmn.focus();alert("Invalid domain name");}
  else if (!rc) {o.dmn.focus();alert("Invalid domain name");}
  return (rc);
}

function isIPvalid(mip)
{ var dots = new Array(15), nmbr = "0123456789", i = 0, j = 0;
  if (mip.length>15) return(false);
  for(i=0;i<mip.length;i++) if (mip.charAt(i)==".") { dots[j++]=i;} else if ( nmbr.indexOf(mip.charAt(i),0)==(-1) ) {j=66; break;}
  if (j!=3) return(false);
  if ((parseInt(mip.substring(0,dots[0]), 10)>254)||(parseInt(mip.substring(0,dots[0]), 10)<11)) return(false);
  if (parseInt(mip.substring(dots[0]+1,dots[1]),10)>255) return(false);
  if (parseInt(mip.substring(dots[1]+1,dots[2]),10)>255) return(false);
  if (parseInt(mip.substring(dots[2]+1,16),10)>255) return(false); 
  return(true);
}

function chk_dmn(o)
{ for (i=0;i<o.length-2;i++) if (i!=2) o.elements[i].value=o.elements[i].value.toUpperCase();
  if(!o.agree.checked){
    alert("Please read agreement"); return(false);
  }
  if((o.opid.value.length<1)||(o.psw.value.length<1)||(o.tpid.value.length<1)||(o.ns1.value.length<1)||(o.ns2.value.length<1))
  { alert("Please fill out ALL required fields"); return(false);
  }
  if(!ispswok(o.psw.value)) { alert("Invalid password"); o.psw.focus(); return(false);}
  if((o.ns1.value.indexOf(o.dmn.value,0)!=-1)&&(!isIPvalid(o.ns1ip.value)))
  {o.ns1ip.focus(); alert("NS1 overlaped, please specify IP"); return(false);
  }   
  if((o.ns2.value.indexOf(o.dmn.value,0)!=-1)&&(!isIPvalid(o.ns2ip.value)))
  {o.ns2ip.focus(); alert("NS2 overlaped, please specify IP"); return(false);
  }   
  if((o.ns3.value)&&(o.ns3.value.indexOf(o.dmn.value,0)!=-1)&&(!isIPvalid(o.ns3ip.value)))
  {o.ns3ip.focus(); alert("NS3 overlaped, please specify IP"); return(false);
  }   
  if((o.ns4.value)&&(o.ns4.value.indexOf(o.dmn.value,0)!=-1)&&(!isIPvalid(o.ns4ip.value)))
  {o.ns4ip.focus(); alert("NS4 overlaped, please specify IP"); return(false);
  }
  if((!o.ns3.value)&&(o.ns3ip.value))
  {o.ns3.focus(); alert("Please specify NS3 symbolic name"); return(false);
  }
  if((!o.ns4.value)&&(o.ns4ip.value))
  {o.ns4.focus(); alert("Please specify NS4 symbolic name"); return(false);
  }
  return(true);
}

function chk_dml(o)
{ o.dnam.value=o.dnam.value.toUpperCase();
  if(o.dnam.value.substring(0,4)=="WWW.") o.dnam.value=o.dnam.value.substring(4,250);
  if( (o.dnam.value.length<1)||(o.opsw.value.length<1) )
  { alert("Please specify all the necessary information"); o.dnam.focus(); return(false);
  }
  if(!ispswok(o.opsw.value)) { alert("Invalid password"); o.opsw.focus(); return(false);}
  return(true);
}

function chk_whs(o)
{ var s=o.whois.value.toUpperCase();
  if( (s.indexOf("-KG",0)!=-1)||((s.indexOf(".KG",0)!=-1)&&(s.indexOf("@",0)==-1)) ) o.whois.value=s;
  if( o.whois.value.length<1 )
  { alert("What do you want to search?"); o.whois.focus(); return(false);
  }
  return(true);
}

