
function sectionTitle(t) {
  document.write('<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td colspan="2" nowrap><span class="sectionTitle">\n');
  document.write(t + '</span></td><td valign="bottom" align="right" width="100%"><div style="height:8px;BORDER-TOP:#999999 1px solid;">\n');
  document.write('<img height="8" src="images/dt.gif" width="1"></div></td></tr></table>\n');
}

function clearHit(d){
 for (var x=0; x< hits.length; x++) {
    var object = eval("document.kregister._H_" + hits[x]);
               object.checked = false;
        if (d) object.disabled = true;
 }
}

function unclearHit(){
 for (var x=0; x< hits.length; x++) {
    var object = eval("document.kregister._H_" + hits[x]);
               object.disabled = false;
 }
}

function clearPit(d){
  for (var x=0; x< pits.length; x++) {
     var object = eval("document.kregister._P_" + pits[x]);
               object.checked = false;
        if (d) object.disabled = true;
 }
}

function unclearPit(){
  for (var x=0; x< pits.length; x++) {
     var object = eval("document.kregister._P_" + pits[x]);
               object.disabled = false;
 }
}

function clearCats() {
 clearHit(1);
 clearPit(1);
 document.kregister._PCAT[2].checked = true 
 document.kregister._HCAT[1].checked = true 
}

function st() {
 this.scrollBy(0,-30);
}

function validateForm(fd) {
if ( emptyField (fd.fname) || emptyField (fd.lname) ) { alert (" Your First and Last Name are Required"); fd.fname.focus();st();}
 else if ( emptyField (fd.street)) {alert (" Your Street Address is Required");fd.street.focus();st();}
 else if ( emptyField (fd.city)) {alert (" Your City is Required ");fd.city.focus();st();}
 else if ( fd.state.options[fd.state.selectedIndex].value == "0")  {alert (" Your State is Required");fd.state.focus();st();}
 else if ( emptyField (fd.zip)) {alert (" Your ZipCode is Required");fd.zip.focus();st();}
 else if ( emptyField (fd.email)) {alert (" An Email Address is Required");fd.email.focus();st();}
 else if ( !(EmailValid (fd.email.value)) ) {alert ("The Email Address Appears to be Invalid");fd.email.focus();st();}
 else if ( !(PhoneSupplied (fd))  ) ;
 else if ( mailQty(fd)   ) ;
 else if ( emptyField (fd.lgname)) {alert (" You Must Provide a Name for Your League");fd.lgname.focus();st();}
 else if ( fd._TCOUNT.options[0].selected) {alert (" You Did Not Specify the \nNumber of Teams in Your League");fd._TCOUNT.focus();st();}
 else if ( emptyRadio (fd.tday)) {alert (" You Did Not Specify the First Day of Your Week:\n  Sunday, Monday, Tuesday or Friday   "); fd.tday[0].focus();st();}
 else if ( emptyRadio (fd._ltype)) { alert (" You Did Not Specify the TYPE OF LEAGUE:\n          AL, NL, Mixed   ");  fd._ltype[0].focus();st();}
 else if ( fd._AHC.options[0].selected) { alert (" You Did Not Specify the size of your HITTING ACTIVE ROSTER");fd._AHC.focus();st();}
 else if ( fd._APC.options[0].selected) { alert (" You Did Not Specify the size of your PITCHING ACTIVE ROSTER");fd._APC.focus();st();}
 else {
   return validateForm2(fd);
  }
 return false;
}


function mailQty (fd) {

   return false;
  if (fd._mailqty.disabled==true) {
     return false;
   }  
  else if (fd._mailqty.selectedIndex == 0) {
      alert ('You opted to have Reports Mailed - But you\ndid not Specify the Number of Mailings');
      fd._mailqty.focus(); st();
      return true;
   }
return false;
}

function validateForm2(fd) {
  if ( checkHitters (fd) ) ;
   else if ( checkPitchers (fd) ) ;
 else {

   document.getElementById('sbut').style.visibility = 'hidden';
   document.getElementById('sbut0').style.visibility = 'visible';
   return true;
  }
 return false;
}



function checkHitters (fd) {
 hc = fd._AHC.selectedIndex + 4
 hof = fd.hp_of.selectedIndex
 h1b = fd.hp_1b.selectedIndex
 h2b = fd.hp_2b.selectedIndex
 h3b = fd.hp_3b.selectedIndex
 hss = fd.hp_ss.selectedIndex
 hct = fd.hp_c.selectedIndex
 hcm = fd.hp_cm.selectedIndex
 hmi = fd.hp_mi.selectedIndex
 hut = fd.hp_ut.selectedIndex
 hdh = fd.hp_dh.selectedIndex
 hsw = fd.hp_sw.selectedIndex
 hpcount = hof + h1b + h2b + h3b + hss + hcm + hct + hmi + hut + hdh + hsw
 if (! (hc == hpcount) ) {
   alert (" The Size of the ACTIVE HITTING ROSTER does not \n       Match the Size of the Position Distribution");
   fd._AHC.focus();
   st();
   fd.hp_of.focus();
   return true
  }
 return false
}


function checkPitchers (fd) {
 pc = fd._APC.selectedIndex + 4;
 pp =  fd.pp_p.selectedIndex;
 psp = fd.pp_sp.selectedIndex;
 prp = fd.pp_rp.selectedIndex;
 psw = fd.pp_sw.selectedIndex;
 ppcount = pp + psp + prp + psw;
 if (! (pc == ppcount) ) {
   alert (" The Size of the ACTIVE PITCHING ROSTER does not \n       Match the Size of the Position Distribution")
   fd._APC.focus();
   st();
   fd.pp_p.focus();
   return true
  }
 return false
}


function PhoneSupplied (d) {
  if (  emptyField (d.tda) ) {alert ("A Complete Phone Number with Area Code is Required");d.tda.focus();st();}
   else if (emptyField (d.tdp)) {alert ("A Complete Phone Number is Required");d.tdp.focus();st();}
   else if (emptyField (d.td4)) {alert ("A Complete Phone Number is Required");d.td4.focus();st();}
   else { return true; }
  return false;
}

function EmailValid (s) {
    if (s.length == 0) return true;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != " ")) { i++}
     if (i < sLength) return false;
    i = 1;
    while ((i < sLength) && (s.charAt(i) != "@")) { i++}
    if ((i >= sLength) || (s.charAt(i) != "@")) return false; else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")) { i++ }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false; else return true;
}


function emptyRadio (radioObj) {
 var value = null;
 for (var i=0; i<radioObj.length; i++) {
       if (radioObj[i].checked) {
          value = radioObj[i].value
       }
 }
if (value == null) return true
return false
}

function emptyField (textObj) {
if (textObj.length == 0 ) return true;
for (var i=0; i<textObj.value.length; ++i) {
       var ch = textObj.value.charAt(i);
       if (ch != ' ' && ch != '\t' && ch != '\n') return false;
     }
return true;
}


var hits = new Array ("AB","AV","SB","DT","RS","SW",
                      "HT","SL","NS","TB","JC","EO",
                      "RN","OB","BB","RP","RD","SO",
                      "HR","AS","B2","RH","RE",
                      "RB","OS","B3","RR","TX");
var hitl = new Array ("At Bats","Average","Steals","2B+3B","R+SB","BB minus K",
                      "Hits","Slug%","Net Steals","Total Bases","TB+BB+SB","Errors",
                      "Runs","OnBaseAvg","Walks","R+RBI-HR","R minus HR","Strikeouts",
                      "HR","Slg%+Avg","Doubles","Hits+Walks","RBI minus HR",
                      "RBI","Slg%+OBA","Triples","R+RBI","RB+BB");
var pits = new Array ("WN","SV","EA","HT","CG","GM",
                      "WL","NV","RT","RN","SH","IP",
                      "W2","HO","SO","ER","CH","NR",
                      "WP","HS","KB","BB","SF",
                      "WX","BS","KW","HR","KI");
var pitl = new Array ("Wins","Saves","ERA","Hits Allowed","Complete Gms","Appearances",
                      "Wins-Losses","Net Saves","WHIP","Runs Allowed","Shutouts","Total Innings",
                      "2 x Wins - Losses","Holds","Strikeouts","ER Allowed","CG + SHO","SV+HLD-BS",
                      "Win Percentage","Saves+Holds","SO - Walks","Walks","CG + Saves",
                      "Wins + Saves","Blown Saves","SO / Walks","HR Allowed","SO per Game");

function mcat(t,s,l) {
 var w = new Object();
 w.type = t;
 w.s = s;
 w.l = l;
 return w;
}

function acat (obj) {
 document.write('<td><input type="checkbox" name="_' + obj.type + '_' + obj.s + '" value="T" />');
 document.write (obj.l + '</td>');
}

function wrow(o,s,f) {
  document.write ('<tr class="selcatc">');
  for (var x=s;x<=f;x++) {
    acat(o[x]);
  }
  document.write ('</tr>');
}

function wrow2(o,s,f) {
  document.write ('<tr class="selcatc">');
  for (var x=s;x<=f;x++) {
    acat(o[x]);
  }
  document.write ('<td rowspan="2">&nbsp;</td></tr>');
}

var hd=[];
function writeHit() {
  for (var x=0;x<hits.length;x++) {
    hd.push(mcat("H",hits[x],hitl[x]));
  }
 wrow(hd,0,5);
 wrow(hd,6,11);
 wrow(hd,12,17);
 wrow2(hd,18,22);
 wrow(hd,23,27);
}

var pd=[];
function writePit() {
  for (var x=0;x<pits.length;x++) {
    pd.push(mcat("P",pits[x],pitl[x]));
  }
 wrow(pd,0,5);
 wrow(pd,6,11);
 wrow(pd,12,17);
 wrow2(pd,18,22);
 wrow(pd,23,27);
}

function checkMail() {
    var mq = document.getElementById("mqtyselect");

  if (document.getElementById("useMail").checked) {
     document.getElementById("mailqty").style.display = "inline";
     mq.disabled=false;
  } else {
    document.getElementById("mailqty").style.display = "none";
    mq.disabled=true;
  }
}


