
function getHTTPObject() {
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    
}
  return xmlhttp;

  
}
var http = getHTTPObject(); // We create the HTTP Object

/*
	Funtion Name=requestInfo 
	Param = url >> Url to call : id = Passing div id for multiple use ~ as a seprator for eg. div1~div2 :
	redirectPage >> if you like to redirect to other page once the event success then 
	the response text = 1 and the redirectPage not left empty
*/

function requestInfo(url,id,redirectPage) {      
	var temp=new Array();
		http.open("GET", url, true);
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
			  if(http.status==200) {
				var results=http.responseText;
				if(redirectPage=="" || results!="1") {

					var temp=id.split("~"); // To display on multiple div 
					//alert(temp.length);
					var r=results.split("~"); // To display multiple data into the div 
					//alert(temp.length);
					if(temp.length>1) {
						for(i=0;i<temp.length;i++) {	
							//alert(temp[i]);
							document.getElementById(temp[i]).innerHTML=r[i];
						}
					} else {
						document.getElementById(id).innerHTML = results;
					}	
				} else {
					//alert(results);
					window.location.href=redirectPage;			
				}
			  } 
			}
		};
		http.send(null);
}

/*
	Function Name= emptyValidation
	Desc = This function is used to validation for the empty field 
	Param fieldList = This arguments set as a string varialble. you just need to supply the textbox name
	if the textbox is multiple then supply with ~ separator for eg. Login~password
*/
function emptyValidation(fieldList) {
		
		var field=new Array();
		field=fieldList.split("~");
		var counter=0;
		for(i=0;i<field.length;i++) {
			if(document.getElementById(field[i]).value=="") {
				document.getElementById(field[i]).style.backgroundColor="#FF0000";
				counter++;
			} else {
				document.getElementById(field[i]).style.backgroundColor="#FFFFFF";	
			}
		}
		if(counter>0) {
				alert("The Field mark as red could not left empty");
				return false;
				
		}  else {
			return true;
		}
		
}

function init_table() {
		requestInfo('showTable.php?mode=list','showTable','');
	}

function init_table2() {
		requestInfo('showTableFiles.php?mode=list','showTable2','');
	}
	
function save_data(so,sn) {
		var UserID=document.getElementById("UserID").value;
		var FirstName=document.getElementById("FirstName").value;
		var Login=document.getElementById("Login").value;
		var Password=document.getElementById("Password").value;
		var Class=document.getElementById("Class").value;
		var archived=document.getElementById("archived").value;
		var emailaddress=document.getElementById("emailaddress").value;
		var phonenumber=document.getElementById("phonenumber").value;
		var regstatus=document.getElementById("regstatus").value;
		var checkValidation=emptyValidation('FirstName~Login~Password~emailaddress');

	if(checkValidation==true) {
		requestInfo('showTable.php?mode=save_new&regstatus='+regstatus+'&phonenumber='+phonenumber+'&emailaddress='+emailaddress+'&Class='+Class+'&archived='+archived+'&FirstName='+FirstName+'&UserID='+UserID+'&Login='+Login+'&Password='+Password+'&searchoption='+so+'&searchname='+sn,'showTable','');
	} 
}

function update_data(so,sn) {
		var prev_UserID=document.getElementById("prev_UserID").value;
		var UserID=document.getElementById("UserID").value;
		var FirstName=document.getElementById("FirstName").value;
		var Login=document.getElementById("Login").value;
		var Password=document.getElementById("Password").value;
		var Class=document.getElementById("Class").value;		
		var archived=document.getElementById("archived").value;
		var emailaddress=document.getElementById("emailaddress").value;
		var phonenumber=document.getElementById("phonenumber").value;
		var regstatus=document.getElementById("regstatus").value;
		var memClass=document.getElementById("memClass").value;
		var RequestClass=document.getElementById("RequestClass").value;
		var preAssignedClass=document.getElementById("preAssignedClass").value;
	
		var LastName=document.getElementById("LastName").value;
		var gender=document.getElementById("gender").value;
		var curschool=document.getElementById("curschool").value;
		var yeargrad=document.getElementById("yeargrad").value;
		var address1=document.getElementById("address1").value;		
		var city=document.getElementById("city").value;
		var state=document.getElementById("state").value;
		var zip=document.getElementById("zip").value;
		var phonenumber2=document.getElementById("phonenumber2").value;
		var shirtsize=document.getElementById("shirtsize").value;
		var mothername=document.getElementById("mothername").value;
		var motherlast=document.getElementById("motherlast").value;
		var fathername=document.getElementById("fathername").value;
		var fatherlast=document.getElementById("fatherlast").value;		
		var motheremail=document.getElementById("motheremail").value;
		var fatheremail=document.getElementById("fatheremail").value;
		var motherphone=document.getElementById("motherphone").value;
		var fatherphone=document.getElementById("fatherphone").value;				
		var parentid=document.getElementById("parentid").value;		
		
		var checkValidation=emptyValidation('FirstName~Login~Password~emailaddress');
	
	if(checkValidation==true) {
		requestInfo('showTable.php?mode=update_data&preAssignedClass='+preAssignedClass+'&motherlast='+motherlast+'&&fatherlast='+fatherlast+'&RequestClass='+RequestClass+'&parentid='+parentid+'&yeargrad='+yeargrad+'&phonenumber2='+phonenumber2+'&shirtsize=' +shirtsize+'&memClass='+memClass+'&LastName='+LastName+'&gender='+gender+'&curschool='+curschool+'&address1='+address1+'&city='+city+'&state='+state+'&zip='+zip+'&mothername='+mothername+'&fathername='+fathername+'&motheremail='+motheremail+'&fatheremail='+fatheremail+'&motherphone='+motherphone+'&fatherphone='+fatherphone+'&regstatus='+regstatus+'&phonenumber='+phonenumber+'&emailaddress='+emailaddress+'&Class='+Class+'&archived='+archived+'&FirstName='+FirstName+'&UserID='+UserID+'&Login='+Login+'&Password='+Password+'&prev_UserID='+prev_UserID+'&searchoption='+so+'&searchname='+sn,'showTable','');
	} 
}

function save_dataCat(so,sn) {
		var CatID=document.getElementById("CatID").value;
		var catname=document.getElementById("catname").value;
		var disabled=document.getElementById("disabled").value;
		var checkValidation=emptyValidation('catname');

	if(checkValidation==true) {
		requestInfo('showCat.php?mode=save_new&disabled='+disabled+'&catname='+catname+'&CatID='+CatID,'showCat','');
	} 
}

function update_dataCat(so,sn) {
		var prev_CatID=document.getElementById("prev_CatID").value;
		var CatID=document.getElementById("CatID").value;
		var catname=document.getElementById("catname").value;
		var disabled=document.getElementById("disabled").value;
		var checkValidation=emptyValidation('catname');

	if(checkValidation==true) {
		requestInfo('showCat.php?mode=update_data&disabled='+disabled+'&catname='+catname+'&CatID='+CatID+'&prev_CatID='+prev_CatID,'showCat','');
	} 
}
	
function confirmLink(theLink)
{
   
    var is_confirmed = confirm('Are you sure to delete this record?\n\nThis will permanently delete the Record!');
    if (is_confirmed) {
        theLink.href += '';
    }

    return is_confirmed;
}
function data_MemberCurPage(setTo,searchoption) {	
	requestInfo('showMember.php?mode=list&searchoption='+searchoption+'&spPage='+setTo,'showMember','');
}
