// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{  
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)


    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function sel_category()
{
  //alert("in");
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var icount;
	var totlength = document.getElementById('category').length;
	//alert(totlength);
	var cat = "";
	for(icount=1; icount<totlength; icount++)
	{
		if(document.getElementById('category')[icount].selected == true)
		{
			cat =cat +document.getElementById('category')[icount].value +",";
		}
	}
   // execute the quickstart.php page from the server
     xmlHttp.open("GET", "findsub.php?cat="+ cat, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = Loadmsg;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('sel_category()', 1000);
}
function admin_sel_category()
{
  //alert("in");
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var icount;
	var totlength = document.getElementById('category').length;
	//alert(totlength);
	var cat = "";
	for(icount=1; icount<totlength; icount++)
	{
		if(document.getElementById('category')[icount].selected == true)
		{
			cat =cat +document.getElementById('category')[icount].value +",";
		}
	}
   // execute the quickstart.php page from the server
     xmlHttp.open("GET", "../findsub.php?cat="+ cat, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = Loadmsg;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('sel_category()', 1000);
}
// executed automatically when a message is received from the server
function Loadmsg()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("subcategory").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function loadsignajax()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var signindex = document.getElementById('img_index').value;
	// execute the quickstart.php page from the server
     xmlHttp.open("GET", "sign.php?id="+ signindex, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = Loadsign;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('loadsignajax()', 1000);
}
// executed automatically when a message is received from the server
function Loadsign()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("img_sign").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function load_title_graphics_ajax()
{
  
  // proceed only if the xmlHttp object isn't busy
  //alert(id);
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var signindex = document.getElementById('img_index').value;
	// execute the quickstart.php page from the server
	//alert(signindex );
     xmlHttp.open("GET", "graphics_load.php?id="+ signindex, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = loadgraphics;
    // make the server request
    xmlHttp.send(null);
  }
  
}
function loadgraphics()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("img_sign").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function sel_category_search()
{
	//document.getElementById("div_subcategory").innerHTML = "<img src='images/loading.gif' border='0' alt='loading'>";;
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var cat;
	cat = document.getElementById('category').value;
   // execute the quickstart.php page from the server
   if(cat!='0')
   {
     xmlHttp.open("GET", "subcatlist.php?cat="+ cat, true);
	 xmlHttp.onreadystatechange = LoadSubCategories;
    // make the server request
    xmlHttp.send(null);
   }
    // define the method to handle server responses
    
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('sel_category_search()', 1000);
}

function LoadSubCategories()
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("div_subcategory").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function fetch_grad_subject()
{
  //alert("in");
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var icount;
	var totlength = document.getElementById('graduation').length;
	//alert(totlength);
	var cat = "";
	for(icount=1; icount<totlength; icount++)
	{
		if(document.getElementById('graduation')[icount].selected == true)
		{
			cat =cat +document.getElementById('graduation')[icount].value +",";
		}
	}
   // execute the quickstart.php page from the server
     xmlHttp.open("GET", "findgrad.php?id="+ cat, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = Loadgrad;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('fetch_grad_subject()', 1000);
}
function Loadgrad()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("td_grad_sub").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function sel_pg()
{
  //alert("in");
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	// retrieve the name typed by the user on the form
    //u_name = encodeURIComponent(document.getElementById("name").value);
	var icount;
	var totlength = document.getElementById('pg').length;
	//alert(totlength);
	var cat = "";
	for(icount=1; icount<totlength; icount++)
	{
		if(document.getElementById('pg')[icount].selected == true)
		{
			cat =cat +document.getElementById('pg')[icount].value +",";
		}
	}
   // execute the quickstart.php page from the server
     xmlHttp.open("GET", "find_pg.php?id="+ cat, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = Loadpgrad;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('sel_pg()', 1000);
}
function Loadpgrad()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // update the client display using the data received from the server
	  document.getElementById("div_pg_spec").innerHTML = xmlHttp.responseText ;
      // restart sequence
     // setTimeout('process()', 1000);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      //alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
