////////////////////////////////////////////////////////
//    Javascript for J-Club-F.asp and J-Club-U2.asp   //
//    Also used in A-Club-F.asp and A-Club-U2.asp     //
////////////////////////////////////////////////////////

var xmlHttp;
var form = document.frmNewClub;
var fldClubName, fldContactLName, fldContactFName, fldContactPhone, fldContactEmail, fldGender;
var fldAge12, fldAge13, fldAge14, fldAge15, fldAge16, fldAge17, fldAge18;
var fldLvlAA, fldLvlA, fldLvlBB, fldLvlB, fldLvlOpen, fldLvlAAA, fldLvlBBB, fldLvlBBA, fldNumTeams;
var fldFacilityName, fldFacilityAddress, fldFacilityCity, fldFacilityState, fldFacilityZip, fldWebLink, level;
var fldMission, fldMtgDate, fldMtgTime, fldMtgLocation, fldTryoutInfo, fldPracticeInfo, fldOtherInfo;
var UclubName, UcontactLName, UcontactFName, UcontactPhone, UcontactEmail, Ugender;
var Uage12, Uage13, Uage14, Uage15, Uage16, Uage17, Uage18;
var UlvlAA, UlvlA, UlvlBB, UlvlB, UlvlOpen, UlvlAAA, UlvlBBB, UlvlBBA;
var UnumTeams, UfacilityName, UfacilityAddress, UfacilityCity, UfacilityState, UfacilityZip, UwebLink;
var Umission, UmtgDate, UmtgTime, UmtgLocation, UtryoutInfo, UpracticeInfo, UotherInfo;

// -------------------------------------------------------------------------------
function onclickSubmit_NewClub(frmName)
{
//    alert("This form name is: " + String(frmName));
    
    var submittingForm = String(frmName);
    
    fldClubName = document.getElementById("txtClubName");
    fldContactLName = document.getElementById("txtContactLName");
    fldContactFName = document.getElementById("txtContactFName");
    fldContactPhone = document.getElementById("txtContactPhone");
    fldContactEmail = document.getElementById("txtContactEmail");
    fldGender = document.getElementById("selGender");
    if (submittingForm == 'junior')
    {
        level = 'j';
        fldAge12 = document.getElementById("ckb12");
        fldAge13 = document.getElementById("ckb13");
        fldAge14 = document.getElementById("ckb14");
        fldAge15 = document.getElementById("ckb15");
        fldAge16 = document.getElementById("ckb16");
        fldAge17 = document.getElementById("ckb17");
        fldAge18 = document.getElementById("ckb18");
        Uage12 = fldAge12.checked;
        Uage13 = fldAge13.checked;
        Uage14 = fldAge14.checked;
        Uage15 = fldAge15.checked;
        Uage16 = fldAge16.checked;
        Uage17 = fldAge17.checked;
        Uage18 = fldAge18.checked;
        if (Uage12) { Uage12 = 1; } else { Uage12 = 0; }
        if (Uage13) { Uage13 = 1; } else { Uage13 = 0; }
        if (Uage14) { Uage14 = 1; } else { Uage14 = 0; }
        if (Uage15) { Uage15 = 1; } else { Uage15 = 0; }
        if (Uage16) { Uage16 = 1; } else { Uage16 = 0; }
        if (Uage17) { Uage17 = 1; } else { Uage17 = 0; }
        if (Uage18) { Uage18 = 1; } else { Uage18 = 0; }
        UlvlAAA = 0;
        UlvlAA = 0;
        UlvlA = 0;
        UlvlBBA = 0;
        UlvlBBB = 0;
        UlvlBB = 0;
        UlvlB = 0;
        UlvlOpen = 0;
    }
    if (submittingForm == 'adult')
    {
        level = 'a';
        fldLvlAAA = document.getElementById("ckbAAA");
        fldLvlAA = document.getElementById("ckbAA");
        fldLvlA = document.getElementById("ckbA");
        fldLvlBBA = document.getElementById("ckbBBA");
        fldLvlBBB = document.getElementById("ckbBBB");
        fldLvlBB = document.getElementById("ckbBB");
        fldLvlB = document.getElementById("ckbB");
        fldLvlOpen = document.getElementById("ckbOpen");
        UlvlAAA = fldLvlAAA.checked;
        UlvlAA = fldLvlAA.checked;
        UlvlA = fldLvlA.checked;
        UlvlBBA = fldLvlBBA.checked;
        UlvlBBB = fldLvlBBB.checked;
        UlvlBB = fldLvlBB.checked;
        UlvlB = fldLvlB.checked;
        UlvlOpen = fldLvlOpen.checked;
        if (UlvlAAA) { UlvlAAA = 1; } else { UlvlAAA = 0; }
        if (UlvlAA) { UlvlAA = 1; } else { UlvlAA = 0; }
        if (UlvlA) { UlvlA = 1; } else { UlvlA = 0; }
        if (UlvlBBA) { UlvlBBA = 1; } else { UlvlBBA = 0; }
        if (UlvlBBB) { UlvlBBB = 1; } else { UlvlBBB = 0; }
        if (UlvlBB) { UlvlBB = 1; } else { UlvlBB = 0; }
        if (UlvlB) { UlvlB = 1; } else { UlvlB = 0; }
        if (UlvlOpen) { UlvlOpen = 1; } else { UlvlOpen = 0; }
        Uage12 = 0; 
        Uage13 = 0; 
        Uage14 = 0; 
        Uage15 = 0; 
        Uage16 = 0; 
        Uage17 = 0; 
        Uage18 = 0; 
    }
    fldNumTeams = document.getElementById("txtNmbTeams");
    fldFacilityName = document.getElementById("txtFacilityName");
    fldFacilityAddress = document.getElementById("txtFacilityAddress");
    fldFacilityCity = document.getElementById("txtFacilityCity");
    fldFacilityState = document.getElementById("selState");
    fldWebLink = document.getElementById("txtWebsite");
    UclubName = fldClubName.value;
    UcontactLName = fldContactLName.value;
    UcontactFName = fldContactFName.value;
    UcontactPhone = fldContactPhone.value;
    UcontactEmail = fldContactEmail.value;
    UnumTeams = fldNumTeams.value;
    Ugender = fldGender[fldGender.selectedIndex].value;
    UfacilityName = fldFacilityName.value;
    UfacilityAddress = fldFacilityAddress.value;
    UfacilityCity = fldFacilityCity.value;
    UfacilityState = fldFacilityState[fldFacilityState.selectedIndex].value;
    UwebLink = fldWebLink.value;
        
  //-----------------------------------------------------------
  //----------         field validation          --------------
  //-----------------------------------------------------------

  if (UclubName.length == 0)
  {
  	 alert("You must provide your club's name.");
  	 document.frmNewClub.txtClubName.focus();
  	 return false;
  }
  if (UcontactLName.length == 0)
  {
  	 alert("You must provide your club's contact/director last name.");
  	 document.frmNewClub.txtContactLName.focus();
  	 return false;
  }
    if (UcontactFName.length == 0)
  {
  	 alert("You must provide your club's contact/director first name.");
  	 document.frmNewClub.txtContactFName.focus();
  	 return false;
  }
  if (UcontactPhone.length == 0)
  {
  	 alert("You must provide a phone number for your club's contact/director.");
  	 document.frmNewClub.txtContactPhone.focus();
  	 return false;
  }
  if (UcontactEmail.length == 0)
  {
  	 alert("You must provide an email address for your club's contact/director");
  	 document.frmNewClub.txtContactEmail.focus();
  	 return false;
  }
  if (UnumTeams.length == 0)
  {
  	 alert("Please provide the number of teams fielded by your club.");
  	 document.frmNewClub.txtNmbTeams.focus();
  	 return false;
  }
  if (fldGender.selectedIndex == 0)
  {
  	 alert("You must select the gender of your club.");
  	 document.frmNewClub.selGender.focus();
	 return false;      
  }

  //-----------------------------------------------------------
  //----------       end field validation         -------------
  //-----------------------------------------------------------
  
  if (jcap())
  {
      var url="Club-F-Submit.asp?n=" + UclubName + "&l=" + level;
      url = url + "&cln=" + UcontactLName + "&cfn=" + UcontactFName + "&cp=" + UcontactPhone + "&ce=" + UcontactEmail + "&g=" + Ugender;
      url = url + "&a2=" + Uage12 + "&a3=" + Uage13 + "&a4=" + Uage14 + "&a5=" + Uage15 + "&a6=" + Uage16 + "&a7=" + Uage17 + "&a8=" + Uage18;
      url = url + "&laaa=" + UlvlAAA + "&laa=" + UlvlAA + "&la=" + UlvlA + "&lbba=" + UlvlBBA + "&lbbb=" + UlvlBBB + "&lbb=" + UlvlBB + "&lb=" + UlvlB + "&lo=" + UlvlOpen;
      url = url + "&nt=" + UnumTeams + "&fn=" + UfacilityName + "&fa=" + UfacilityAddress + "&fc=" + UfacilityCity + "&fs=" + UfacilityState;
      url = url + "&w=" + UwebLink;

      //alert(url);  
      //ajaxFunction(url);  
      
      document.frmNewClub.action = String(url);
      document.frmNewClub.submit();
  }
  else
  {
    return false;
  }  
}


// -------------------------------------------------------------------------------
function onclickSubmit_UpdateClub(frmName,id)
{   
    var submittingForm = String(frmName);
    
    fldContactLName = document.getElementById("txtContactLName");
    fldContactFName = document.getElementById("txtContactFName");
    fldContactPhone = document.getElementById("txtContactPhone");
    fldContactEmail = document.getElementById("txtContactEmail");
    fldGender = document.getElementById("selGender");
    if (submittingForm == 'junior')
    {
        level = 'j';
        fldAge12 = document.getElementById("ckb12");
        fldAge13 = document.getElementById("ckb13");
        fldAge14 = document.getElementById("ckb14");
        fldAge15 = document.getElementById("ckb15");
        fldAge16 = document.getElementById("ckb16");
        fldAge17 = document.getElementById("ckb17");
        fldAge18 = document.getElementById("ckb18");
        Uage12 = fldAge12.checked;
        Uage13 = fldAge13.checked;
        Uage14 = fldAge14.checked;
        Uage15 = fldAge15.checked;
        Uage16 = fldAge16.checked;
        Uage17 = fldAge17.checked;
        Uage18 = fldAge18.checked;
        if (Uage12) { Uage12 = 1; } else { Uage12 = 0; }
        if (Uage13) { Uage13 = 1; } else { Uage13 = 0; }
        if (Uage14) { Uage14 = 1; } else { Uage14 = 0; }
        if (Uage15) { Uage15 = 1; } else { Uage15 = 0; }
        if (Uage16) { Uage16 = 1; } else { Uage16 = 0; }
        if (Uage17) { Uage17 = 1; } else { Uage17 = 0; }
        if (Uage18) { Uage18 = 1; } else { Uage18 = 0; }
        UlvlAAA = 0;
        UlvlAA = 0;
        UlvlA = 0;
        UlvlBBA = 0;
        UlvlBBB = 0;
        UlvlBB = 0;
        UlvlB = 0;
        UlvlOpen = 0;

    }
    if (submittingForm == 'adult')
    {
        level = 'a';
        fldLvlAAA = document.getElementById("ckbAAA");
        fldLvlAA = document.getElementById("ckbAA");
        fldLvlA = document.getElementById("ckbA");
        fldLvlBBA = document.getElementById("ckbBBA");
        fldLvlBBB = document.getElementById("ckbBBB");
        fldLvlBB = document.getElementById("ckbBB");
        fldLvlB = document.getElementById("ckbB");
        fldLvlOpen = document.getElementById("ckbOpen");
        UlvlAAA = fldLvlAAA.checked;
        UlvlAA = fldLvlAA.checked;
        UlvlA = fldLvlA.checked;
        UlvlBBA = fldLvlBBA.checked;
        UlvlBBB = fldLvlBBB.checked;
        UlvlBB = fldLvlBB.checked;
        UlvlB = fldLvlB.checked;
        UlvlOpen = fldLvlOpen.checked;
        if (UlvlAAA) { UlvlAAA = 1; } else { UlvlAAA = 0; }
        if (UlvlAA) { UlvlAA = 1; } else { UlvlAA = 0; }
        if (UlvlA) { UlvlA = 1; } else { UlvlA = 0; }
        if (UlvlBBA) { UlvlBBA = 1; } else { UlvlBBA = 0; }
        if (UlvlBBB) { UlvlBBB = 1; } else { UlvlBBB = 0; }
        if (UlvlBB) { UlvlBB = 1; } else { UlvlBB = 0; }
        if (UlvlB) { UlvlB = 1; } else { UlvlB = 0; }
        if (UlvlOpen) { UlvlOpen = 1; } else { UlvlOpen = 0; }
        Uage12 = 0; 
        Uage13 = 0; 
        Uage14 = 0; 
        Uage15 = 0; 
        Uage16 = 0; 
        Uage17 = 0; 
        Uage18 = 0; 

    }
    fldNumTeams = document.getElementById("txtNmbTeams");
    fldFacilityName = document.getElementById("txtFacilityName");
    fldFacilityAddress = document.getElementById("txtFacilityAddress");
    fldFacilityCity = document.getElementById("txtFacilityCity");
    fldFacilityState = document.getElementById("selState");
    fldFacilityZip = document.getElementById("txtZipcode");
    fldWebLink = document.getElementById("txtWebsite");
    fldMission = document.getElementById("txtClubMission");
    fldMtgDate = document.getElementById("txtInfoMtgDate");
    fldMtgTime = document.getElementById("txtInfoMtgTime");
    fldMtgLocation = document.getElementById("txtInfoMtgLocation");
    fldTryoutInfo = document.getElementById("txtTryoutInfo");
    fldPracticeInfo = document.getElementById("txtPracticeInfo");
    fldOtherInfo = document.getElementById("txtOtherInfo");
    UcontactLName = fldContactLName.value;
    UcontactFName = fldContactFName.value;
    UcontactPhone = fldContactPhone.value;
    UcontactEmail = fldContactEmail.value;
    UnumTeams = fldNumTeams.value;
    Ugender = fldGender[fldGender.selectedIndex].value;
    UfacilityName = fldFacilityName.value;
    UfacilityAddress = fldFacilityAddress.value;
    UfacilityCity = fldFacilityCity.value;
    UfacilityState = fldFacilityState[fldFacilityState.selectedIndex].value;
    UfacilityZip = fldFacilityZip.value;
    UwebLink = fldWebLink.value;
    Umission = fldMission.value;
    UmtgDate = fldMtgDate.value;
    UmtgTime = fldMtgTime.value;
    UmtgLocation = fldMtgLocation.value;
    UtryoutInfo = fldTryoutInfo.value;
    UpracticeInfo = fldPracticeInfo.value;
    UotherInfo = fldOtherInfo.value;
    
  //-----------------------------------------------------------
  //----------         field validation          --------------
  //-----------------------------------------------------------

  if (UcontactLName.length == 0)
  {
  	 alert("You must provide your club's contact/director last name.");
  	 document.frmNewClub.txtContactLName.focus();
  	 return false;
  }
    if (UcontactFName.length == 0)
  {
  	 alert("You must provide your club's contact/director first name.");
  	 document.frmNewClub.txtContactFName.focus();
  	 return false;
  }
  if (UcontactPhone.length == 0)
  {
  	 alert("You must provide a phone number for your club's contact/director.");
  	 document.frmNewClub.txtContactPhone.focus();
  	 return false;
  }
  if (UcontactEmail.length == 0)
  {
  	 alert("You must provide an email address for your club's contact/director");
  	 document.frmNewClub.txtContactEmail.focus();
  	 return false;
  }
  if (UnumTeams.length == 0)
  {
  	 alert("Please provide the number of teams fielded by your club.");
  	 document.frmNewClub.txtNmbTeams.focus();
  	 return false;
  }

  //-----------------------------------------------------------
  //----------       end field validation         -------------
  //-----------------------------------------------------------

  var url="Club-F-Update.asp?id=" + id + "&l=" + level;
  url = url + "&cln=" + UcontactLName + "&cfn=" + UcontactFName + "&cp=" + UcontactPhone + "&ce=" + UcontactEmail + "&g=" + Ugender;
  url = url + "&a2=" + Uage12 + "&a3=" + Uage13 + "&a4=" + Uage14 + "&a5=" + Uage15 + "&a6=" + Uage16 + "&a7=" + Uage17 + "&a8=" + Uage18;
  url = url + "&laaa=" + UlvlAAA + "&laa=" + UlvlAA + "&la=" + UlvlA + "&lbba=" + UlvlBBA + "&lbbb=" + UlvlBBB + "&lbb=" + UlvlBB + "&lb=" + UlvlB + "&lo=" + UlvlOpen;
  url = url + "&nt=" + UnumTeams + "&fn=" + UfacilityName + "&fa=" + UfacilityAddress + "&fc=" + UfacilityCity + "&fs=" + UfacilityState;
  url = url + "&w=" + UwebLink + "&fz=" + UfacilityZip + "&m=" + Umission + "&md=" + UmtgDate + "&mt=" + UmtgTime + "&ml=" + UmtgLocation;
  url = url + "&ti=" + UtryoutInfo + "&pi=" + UpracticeInfo + "&oi=" + UotherInfo;

  //alert(url);  
  //ajaxFunction(url);  
  
  document.frmNewClub.action = String(url);
  document.frmNewClub.submit();
}
  
  
// -------------------------------------------------------------------------------
function onclickSubmit_ChangePassword(id,pw0,pw,frm)
{
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
   {
      alert("Your browser does not support AJAX!");
   }
   var url = "Club-Password-Change.asp?cid=" + String(id) + "&pw0=" + String(pw0) + "&pw=" + String(pw);

  // alert(url);
  
   if (frm == "j-club-u2") 
   {
      xmlHttp.elemId = 90; 
   }
   if (frm == "a-club-u2") 
   {
      xmlHttp.elemId = 91; 
   }
   xmlHttp.onreadystatechange = stateChanged;
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
}
  
  
// -------------------------------------------------------------------------------
function ajaxFunction(url)
{ 

    var myUrl = String(url);
    
    //alert(myUrl);
    
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
       alert("Your browser does not support AJAX!");
       return;
    } 
    
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET",myUrl,true);
    xmlHttp.send(null);
}

// -------------------------------------------------------------------------------
function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        var returnMsg = xmlHttp.responseText;
         
         if (xmlHttp.elemId == 90)
         {
             if (returnMsg == "pwChanged")
             {
                 location.href = "J-Club-U.asp";
                 alert("The password was changed successfully.");
             }
             else if (returnMsg == "pwFailed")
             {
                 alert("The password provided is not correct.");
             }
         }
         else if (xmlHttp.elemId == 91)
         {
             if (returnMsg == "pwChanged")
             {
                 location.href = "A-Club-U.asp";
                 alert("The password was changed successfully.");
             }
             else if (returnMsg == "pwFailed")
             {
                 alert("The password provided is not correct.");
             }
         }
         else
         {
           //alert(returnMsg);
           alert("An error has occurred while attempting to submit your new club request.");
         }
    }
}

// -------------------------------------------------------------------------------
function GetXmlHttpObject()
{
    var xmlHttp = null;
    try
    {    
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest(); 
        if (xmlHttp.overrideMimeType) 
        { 
            // set type accordingly to anticipated content type 
            //http_request.overrideMimeType('text/xml'); 
            xmlHttp.overrideMimeType('text/html'); 
        }
    }
    catch (e)
    {    
        // Internet Explorer 
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        }
    }
    return xmlHttp;    
}
