/* javascript file */
function getXMLHttpRequestObject()
  { var ajax= false;
    if (window.XMLHttpRequest)
      {ajax = new XMLHttpRequest();}
        else if (window.ActiveXObject)
          {
            try {ajax = new ActiveXObject("Msxml2.XMLHTTP");}
            catch(e){
                    try {ajax = new ActiveXObject("Microsoft.XMLHTTP");}
                    catch(e){}
                    }
          } 
      return ajax;
  }

function getInfo()
{
    var ajax = getXMLHttpRequestObject();
    var myId = document.forms.studentPick.studId.value;
    var spoolUrl =  "http://" + location.host + "/ccagAttend/editStudent.php?mode=getStudent&studId=" + myId;
    spoolUrl = encodeURI(spoolUrl);
    ajax.open('get',spoolUrl);
    ajax.onreadystatechange = function() {
    getStudJson(ajax);}
    ajax.send(null);
}
function sendAtt(myForm)
{
    var myDateP = /^\d{4}-\d{2}-\d{2}/;
    if (myForm.attDate.value.search(myDateP)==-1)
    {
        alert("Please enter the date in the following format - 2009-08-30");
        return false;
    }
   /* var myDate = new Date(myForm.attDate.value);
    if(myDate.getDay() != 0)
    {
        alert(myForm.attDate.value + " is not a Sunday");
        return false;
    }*/
    var ajax = getXMLHttpRequestObject();
    var spoolUrl =  "http://" + location.host + "/ccagAttend/sendMsg.php?attDate=" + myForm.attDate.value;
    spoolUrl = encodeURI(spoolUrl);
    ajax.open('get',spoolUrl);
    ajax.onreadystatechange = function() {
    subStud(ajax);}
    ajax.send(null);
}

function getStudJson(ajax)
{
    if (ajax.readyState == 4) 
    {
        if ((ajax.status == 200) || (ajax.status == 304)) 
        {
            var myStudent = eval('(' + ajax.responseText + ')');
            document.forms.studentEdit.first.value = myStudent.allInfo['first'];
            document.forms.studentEdit.last.value = myStudent.allInfo['last'];
            document.forms.studentEdit.classId.value = myStudent.allInfo['classId'];
            document.forms.studentEdit.studId.value = myStudent.studId;
            (myStudent.allInfo['isInstr'] == 1)?document.forms.studentEdit.instr.checked = true:document.forms.studentEdit.instr.checked = false;
            (myStudent.allInfo['active'] == 1)?document.forms.studentEdit.active.checked = true:document.forms.studentEdit.active.checked = false;
            document.forms.studentEdit.updateStud.disabled = false;
			document.forms.studentEdit.removeStud.disabled = false;
            document.forms.studentEdit.addStud.disabled = true;
        }
    }
}

function submitInfo(modeStr)
{
    /*var ajax = getXMLHttpRequestObject();
    var myId = document.forms.studentEdit.studId.value;
    var firstName = document.forms.studentEdit.first.value;
    var lastName = document.forms.studentEdit.last.value;
    var classId = document.forms.studentEdit.classId.value;
    var instr = document.forms.studentEdit.instr.value;
    document.forms.studentEdit.active.checked?active=1:active=0;
	document.forms.studentEdit.instr.checked?instr=1:instr=0;
    var spoolUrl =  "http://" + location.host + "/ccagAttend/students2.php?mode=" + modeStr + "&first=" + firstName + "&last=" + lastName +"&studId=" + myId + "&classId=" + classId + "&active=" + active+ "&instr=" + instr;
    ajax.open('get',spoolUrl);
    ajax.onreadystatechange = function() {
    subStud(ajax);}
    ajax.send(null);*/
	document.forms.studentEdit.action.value= modeStr
	document.forms.studentEdit.submit();
}
function submitClass(modeStr,thisForm)
{
    /*var ajax = getXMLHttpRequestObject();
    var myclsId = thisForm.clsId.value;
    var clsDesc = thisForm.clsDesc.value;
    var instrId = thisForm.instrId.value;
    (typeof(instrId == "undefined"))?instrId="":instrId = instrId;
    var spoolUrl =  "http://" + location.host + "/ccagAttend/editStudent.php?mode=" + modeStr + "&classId=" + myclsId + "&clsDesc=" + clsDesc +"&instrId=" + instrId;
    spoolUrl = encodeURI(spoolUrl);
    ajax.open('get',spoolUrl);
    ajax.onreadystatechange = function() {
    subStud(ajax);}
    ajax.send(null);*/
	thisForm.submit();
}
function subStud(ajax)
{
    if (ajax.readyState == 4) 
    {
        if ((ajax.status == 200) || (ajax.status == 304)) 
        {
            document.getElementById("content").innerHTML = ajax.responseText;
            setTimeout("clearMsg()",7000)
        }
    }
}

function submitAttend(myForm)
{
    var myDateP = /^\d{4}-\d{2}-\d{2}/;
    if (myForm.attDate.value.search(myDateP)==-1)
    {
        alert("Please enter the date in the following format - 2009-08-30");
        return false;
    }
    /*var myDate = new Date(myForm.attDate.value);
    if(myDate.getDay() != 0)
    {
        alert(myForm.attDate.value + " is not a Sunday");
        return false;
    }*/
    myForm.submit();
}

function clearMsg ()
{
    document.getElementById("msg").innerHTML = "";
}
