// JavaScript Document
var iskeyup = true;

function getXMLHttp(){
		var xmlHttp

 		try
  		{
    		//Firefox, Opera 8.0+, Safari
    		xmlHttp = new XMLHttpRequest();
  		}
  		catch(e)
  		{
    		//Internet Explorer
    		try
    		{
      			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    		}
    		catch(e)
    		{
      			try
      			{
        			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      			}
      			catch(e)
      			{
        			alert("Your browser does not support AJAX!")
        			return false;
      			}
    		}
  		}
  		return xmlHttp;
}

function SearchInventoryResponse(response)
{
  document.getElementById('searchresults').innerHTML = response;
}

function SearchInventoryRequest(whichroom2)
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      SearchInventoryResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "search_inventory.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("searchinv=" + document.getElementById('searchme').value +
			   "&roomname=" + whichroom2);
}

function SearchGo(whichroom1)
{
	if ( iskeyup == true )
		document.cookie = "inventorycookie" + "=" + document.getElementById('searchme').value + "; path=/ ;";
		
		SearchInventoryRequest(whichroom1);
}

function SearchKeyUp(whichroom0)
{
	iskeyup = true;
	if (whichroom0 == "jennings")
		setTimeout("SearchGo('jennings')", 1000);
	else if (whichroom0 == "m006")
		setTimeout("SearchGo('m006')", 1000);
	else
		setTimeout("SearchGo('all')", 1000);
}

function SearchKeyDown()
{
	iskeyup = false;
}


function OrderInventoryResponse(response)
{
  document.getElementById('currentqty').innerHTML = response;
  document.getElementById('orderqty').value = "";
}

function OrderInventoryItem()
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      OrderInventoryResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "inventory_orderitem.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("idnum=" + document.getElementById('orderitemid').value + 
			   "&quantity=" + document.getElementById('orderqty').value + 
			   "&username=" + document.getElementById('username').value);
}

function DeleteInventoryResponse(response)
{
  document.getElementById('viewordersdiv').innerHTML = response;
}

function DeleteInventoryItem(itemdelete)
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      DeleteInventoryResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "inventory_deleteitem.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("idnum=" + itemdelete);
}


function AddWorkorderReplyResponse(response)
{
  document.getElementById('tasknotes').innerHTML = response;
}

function AddWorkorderReply()
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      AddWorkorderReplyResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "work_addreply.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("reply=" + document.getElementById('replynotesid').value + 
			   "&taskid=" + document.getElementById('taskidnum').value +
			   "&currentuser=" + document.getElementById('username').value);
}

function SortWorkordersResponse(response)
{
  document.getElementById('workordertable').innerHTML = response;
}

function SortWorkorders(sortbywhat)
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      SortWorkordersResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "work_sort.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("sortbyfield=" + sortbywhat + 
			   "&whichquery=workorders");
}


function MySortWorkordersResponse(response)
{
  document.getElementById('myworkordertable').innerHTML = response;
}

function MySortWorkorders(sortbywhat, assignerid, username)
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      MySortWorkordersResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "work_sort.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("sortbyfield=" + sortbywhat + 
			   "&whichquery=myworkorders" +
			   "&assigneridnum=" + assignerid +
			   "&sessionuser=" + username);
}


function MySortWorkordersResponse2(response)
{
  document.getElementById('myworkordertable2').innerHTML = response;
}

function MySortWorkorders2(sortbywhat, assignerid, username, isstudent)
{
  var xmlHttp = getXMLHttp();
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      MySortWorkordersResponse2(xmlHttp.responseText);
    }
  }

  xmlHttp.open("POST", "work_sort.php", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send("sortbyfield=" + sortbywhat + 
			   "&whichquery=myworkorders2" +
			   "&assigneridnum=" + assignerid +
			   "&sessionuser=" + username +
			   "&isstudent=" + isstudent);
}



