// JavaScript Documentvar xmlHttp = false;
var xmlBusy = false;
var loadCount = 0;
try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
        xmlHttp = false;
    }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

function GetListGrantsSorted(field) {
    try{
	var tStateID = document.getElementById("tStateID").value;
	var sort_field = field;
	var sort_order = document.getElementById("sort_order").value;
	
        xmlHttp.open("POST", "getListGrantsSorted.php", true);
        
        var stuff = "tStateID="+tStateID+"&sort_field="+sort_field+"&sort_order="+sort_order;
	
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length",stuff.length);
	if(stuff != ""){
		
		xmlHttp.send(stuff);
		if (sort_order == "ASC"){
		    document.getElementById("sort_order").value = "DESC";
		}
		else{
		    document.getElementById("sort_order").value = "ASC";	
		}
	}
	else{
		alert('No Grants Available');
		document.getElementById('divContainer').innerHTML = " ";
	}

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		    if(xmlHttp.responseText != "") {
			document.getElementById('divContainer').innerHTML = xmlHttp.responseText;
		    } else {
			//window.location = "grants_picker.php";					
		    }
		}
	     };
    }catch(e){

    }
}


function GetListGrants() {
    try{
	var tStateID = document.getElementById("tStateID").value;
    xmlHttp.open("POST", "getListGrants.php", true);
    var stuff = "tStateID="+tStateID;
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length",stuff.length);
	if((tStateID != "")){
		
		xmlHttp.send(stuff);
	}
	else{
		alert('No Grants Available');
		document.getElementById('divContainer').innerHTML = " ";
	}

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		    if(xmlHttp.responseText != "") {
			document.getElementById('divContainer').innerHTML = xmlHttp.responseText;
		    } else {
			//window.location = "grants_picker.php";					
		    }
		}
	     };
    }catch(e){

    }
}

function updateListStdPhysicalActivityGrades(tStandardsPhysicalActivityTitle, tStandardsPhysicalActivityGrades, tStandardsPhysicalActivityID, tStandardsDescriptionID, action)
{
        if (action != "edit"){
  	    document.getElementById("tStandardsPhysicalActivityID").value = tStandardsPhysicalActivityID;
	}

	if (xmlHttp==null)
  	{
  		alert ("Browser does not support HTTP Request");
  		return;
  	}
  	
	var url="updateListStdPhysicalActivityGrades.php";
	url=url+"?tStandardsPhysicalActivityTitle="+tStandardsPhysicalActivityTitle; 
	url=url+"&tStandardsPhysicalActivityGrades="+tStandardsPhysicalActivityGrades;
	url=url+"&tStandardsPhysicalActivityID="+tStandardsPhysicalActivityID;
	url=url+"&tStandardsDescriptionID="+tStandardsDescriptionID;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



function removeAlpha( strValue ) {
/************************************************
DESCRIPTION: Removes other characters other than numbers
   from source string.

PARAMETERS: 
  strValue - Source string from which characters 
  other than numbers will be removed;

RETURNS: Source string with characters other 
  than numbers removed.
*************************************************/
 var objRegExp = /[A-z]/g; //search for alphabet globally

  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}
