/* South County Football League Copyright 2009, 2010, 2011
   Original content authored/modified by Mitch Provost -->*/
var xmlhttp
function bodyclk () {
    document.body.onclick = chkbx;
}
function showChild(arrow, child_id, edit, sd)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("We're sorry but your browser does not support AJAX!");
  return;
  }
var cid = document.getElementById('cid');
var url="admin/getchild.php";
if (edit == 'edit') {url = "admin/getchildinput.php";}
if (child_id == null) {
    if (cid == null) {url=url+"?dir="+arrow+"&cid="+1;}
    else {url=url+"?dir="+arrow+"&cid="+cid.value;}
}
else {url=url+"?dir="+arrow+"&cid="+child_id;}
if (edit == 'delete') {url=url+"&edit="+edit;}
if (sd == '1') {url=url+"&sd=1";}
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
document.body.onclick = chkbx;
}
function chfind ( lname, sd ) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("We're sorry but your browser does not support AJAX!");
  return;
  }
var url = "admin/chfind.php?lname="+lname;
if (sd != null) url = url+"&sd="+sd;
xmlhttp.onreadystatechange=searchbx;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
bxfocus("searchbx");
}
function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("inside").innerHTML=xmlhttp.responseText;
  }
}
function searchbx () {
if (xmlhttp.readyState==4)
  {
  var e = document.getElementById("searchbx");
  e.style.visibility = 'visible';
  e.innerHTML=xmlhttp.responseText;
//  e.style.zIndex = 1;
  }
}
function hidesearch(a) {
  var e = document.getElementById(a);
  e.style.visibility = 'hidden';
}
function chkbx(){
  var el = document.getElementById("searchbx");
  if (el && el.style.visibility == 'visible') {
      el.style.visibility = 'hidden';
      document.getElementById("lastName").value = document.getElementById("lastName").name;
      hidesearch("searchbx");
  }
  var el2 = document.getElementById("menubx");
  if (el2 && el2.style.visibility == 'visible') {
      el2.style.visibility = 'hidden';
      el2.style.zIndex = 98;
      hidesearch("menubx");
  }
  else {
      el2.style.zIndex = 99;
  }

}
function bxfocus (a) {
    document.getElementById(a).style.visibility = 'visible';
}
function showadmin()
{
    var el2 = document.getElementById("menubx");
    if (el2 && (el2.style.visibility == 'visible' || el2.style.zIndex == 98)) {
      chkbx();
      el2.style.zIndex = 99;
    }
    else {
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
          {
          alert ("We're sorry but your browser does not support AJAX!");
          return;
          }

        var url = "admin/adminmenu.php?sid="+Math.random();
        xmlhttp.onreadystatechange=menubx;
        xmlhttp.open("POST",url,true);
        xmlhttp.send(null);
        bxfocus("menubx");
    }
}
function menubx () {
if (xmlhttp.readyState==4)
  {
  var e = document.getElementById("menubx");
  x = xmlhttp.responseText.split(":");
  e.style.height = x[0] + "px";
//  e.style.height = 200 + "px";
  e.style.visibility = 'visible';
  e.innerHTML=x[1];
//  e.style.zIndex = 1;
  }
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
function arrw(nme, fn){
    document.images[nme].src = 'widgets/'+fn;
}
function delch(cid){
    ans = confirm('Are you sure you want to delete this record?\n\
(Deleted records are recoverable.)');
    if (ans == true) {
        showChild('none',cid,'delete');
        return true;
    }
    return false;
}
function excel() {
    window.open("https://www.scfootball.org/includes/export_excel.inc.php");
}
function reg_excel(host, pcode) {
    window.open(host+"includes/export_excel_reg.inc.php?pcode="+pcode);
}
function capp_excel(host, div) {
    window.open(host+"includes/export_excel_capp.inc.php?div="+div);
}
function export_excel(host, key, yr) {
    y = '';
    if (yr !== '') y = '&y='+yr;
    newtab = window.open(host+"includes/PHPExcel/scfl-excel.php?"+key+y);
}
function export_report(host, r) {
    s = (r.substr(0,1) == 'r' ? r: 'dte='+r);
    newtab = window.open(host+"includes/reports.inc.php?"+s);
}
function import_excel(host, key, yr) {
    y = (yr !== '' ? '&y='+yr : '');
    newtab = window.open(host+"includes/PHPExcel/import-excel.php?"+key+y);
}
function vfind ( vid, strt ) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("We're sorry but your browser does not support AJAX!");
  return;
  }
var st = (strt != null ? '&strt='+strt : '');
var url = "videodata.php?vid="+vid+st;
xmlhttp.onreadystatechange=getvideo;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
function getvideo()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("player").innerHTML=xmlhttp.responseText;
  }
}
function tscontent ( menuitem, tm ) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("We're sorry but your browser does not support AJAX!");
  return;
  }
var url = menuitem+".php?tm="+tm;
xmlhttp.onreadystatechange=gettscontent;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
function gettscontent()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("tscenter").innerHTML=xmlhttp.responseText;
  }
}
function capp(yr) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("We're sorry but your browser does not support AJAX!");
  return;
  }
var url = "admin/capp.php";
if (yr != null) url = url + '?y='+yr;
xmlhttp.onreadystatechange=displayform;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
function displayform()
{
  if (xmlhttp.readyState==4)
    if (xmlhttp.responseText == "") {
        alert('You must login to submit a coach application.');
    }
    else {
        if (xmlhttp.responseText.search('s=1') && xmlhttp.responseText.search('c=1') !== -1) {
            ans = confirm('You have already submitted a coach application.  Do you want to revise it?');
            if (!ans) {
                return;
            }
        }
        var url = 'admin/cappform.php'+xmlhttp.responseText;
//        if (xmlhttp.responseText.search('c=1') == -1) {
//            url = 'admin/conform.php'+xmlhttp.responseText;
//        }
        window.open(url, '',
            'width=900, height=600, top=100, left=100');
    }
}
function opendocf(file)
{
    window.open(file, '',
        'width=900, height=615, top=80, left=120, resizable=yes, scrollbars=no');
}
function opendoc(file)
{
    window.open(file, '',
        'width=900, height=600, top=120, left=120, resizable=yes, scrollbars=yes');
}
function opendocv(file)
{
    newsite = window.open(file, "",
        "width=900, height=600, top=120, left=120, menubar=yes, resizable=yes, scrollbars=yes");
}
function chkcappform ()
{
    var scfl_rules = document.getElementById('scfl_rules');
    var consentbox = document.getElementById('consentbox');
    var felony = document.getElementById('q15');
    var el = document.forms[0].elements;
    var submitted = document.getElementById('submitted');
    for (i=0; i< el.length; i++) {
        if (el[i].type == 'radio') {
            radiogroup = el[el[i].name];
            itemchecked = false;
            for (j=0; j < radiogroup.length; j++) {
                if (radiogroup[j].checked) {
                    itemchecked = true;
                    break;
                }
            }
            if (!itemchecked) {
                if (el[i].focus) el[i].focus();
                ans = confirm('Form is not complete.\nDo you want to save it and complete your application later?');
                if (ans) {
                    submitted.value = 0;
                    return true;
                }
                else return false;
            }
        }
    }
    
    for (i=0; i< el.length; i++) {
        if (el[i].type == 'text') {
            if (el[i].value == '') {
                if (el[i].name != 'q16a' && el[i].name != 'q16b' && el[i].name != 'q16c' && el[i].className != 'ng_cal_input_field') {
                    if (el[i].focus) el[i].focus();
                    ans = confirm('Form is not complete.\nDo you want to save it and complete your application later?');
                    if (ans) {
                        submitted.value = 0;
                        return true;
                    }
                    else return false;
                }
                else if (el['q15'][0].checked) {
                    if (el[i].focus) el[i].focus();
                    ans = confirm('Form is not complete.\nDo you want to save it and complete your application later?');
                    if (ans) {
                        submitted.value = 0;
                        return true;
                    }
                    else return false;
                }
            }
        }
    }
    if (!scfl_rules.checked) {
        alert('You must check the SCFL Rules check box to submit your application.');
        scfl_rules.focus();
        return false;
    }
    if (!consentbox.checked) {
        alert('You must check the background consent check box to submit your application.');
        scfl_rules.focus();
        return false;
    }
    return true;
}
function itemdel(pg, id, sn, ttl)
{
    var s = '';
    if (pg == 'cal') pageno = 48;
    if (pg == 'faq') pageno = 32;
    if (pg == 'news') {
        pageno = 28;
        s = '&sn='+sn;
    }
    if (pg == 'con') pageno = 37;
    if (pg == 'tryout') pageno = 52;
    ans = confirm('Do you really want to delete "'+ttl+'"?');
    if (ans) {
        window.location.href = ''+pageno+'&item='+id+s+'&act=del';
    }
}
function itemedit(pg, id, sn)
{
    var s = '';
    if (pg == 'cal') pageno = 48;
    if (pg == 'faq') pageno = 32;
    if (pg == 'news') {
        pageno = 28;
        s = '&sn='+sn;
    }
    if (pg == 'con') pageno = 37;
    if (pg == 'store') pageno = 50;
    window.location.href = ''+pageno+'&item='+id+s+'&act=edit';
}
function editcal(item)
{
    window.location.href = '48&item='+item+'&act=edit';
}
function delcal(item, ttl)
{
    ans = confirm('Do you really want to delete "'+ttl+'"?');
    if (ans) {
        window.location.href = '48&item='+item+'&act=del';
    }
}
function editsch(item)
{
    window.location.href = '51&item='+item+'&act=edit';
}
function delsch(item, ttl)
{
    ans = confirm('Do you really want to delete "'+ttl+'"?');
    if (ans) {
        window.location.href = '51&item='+item+'&act=del';
    }
}
function sponsform()
{
    var hst = '';
    if (document.domain != 'localhost') hst = 'http://www.scfootball.org/';
    opendocf(hst+'admin/sponsform.php');
}
function confirmadd()
{
    var pcode = document.getElementById('productCode');
    var mx = document.getElementById('max-'+pcode.value);
    if (mx.value == "1") {
        ans = confirm('Registration for this division has reached maximum capacity.  Do you want to override?');
        if (ans) {
            return true;
        }
        else return false;
    }
    return true;
}
function disableform()
{
    var d = document.getElementsByName('cancel');
    var el = document.forms[1].elements;
    for (i=0; i< el.length; i++) {
        if (el[i].name != 'cancel' && el[i].name != 'submitedit' && el[i].name != 'submitadd' && el[i].name != 'ID') {
            if (d[0].checked == true) el[i].disabled=true;
            else el[i].disabled=false;
        }
    }
    return true;
}
