   var http_request = false;
   var displayNav = "block";
   var xmlHttp
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   
   	function writeout(auth)
	{

		if (auth == 1)
			{
				out = "Logged in:"
			}
		else
			{
				out = '<div id = "redText"><p>The login and password combination provided is not valid.</p></div>'  +
						'<p>' +
						  '<form name="loginForm" id="loginForm" action="javascript:get(document.getElementById(\'loginForm\'));"> ' +
						  '<p>A Login and Password is required to log into this area.</p>' +
						  '<p>Username: <input name="user" id="user" type="text" maxlength="100" size="15" /></p>' +
						  '<p>Password: <input name="pass" id="pass" type="password" maxlength="100" size="15" /></p>' +
						  '<p><input name="login" type="submit" maxlength="100" size="20" value="Login"/></p>' +
						  '</form>' +
					  '</p>';
			}
	}
	
   
   function adminNav(show,auth) 
   	{
		document.getElementById('AdminNav').style.display = show;
		writeout(auth)
	}

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			
            result = http_request.responseText;
			
				if (result == 1)
					{
					adminNav("block",result)
					//form_select_options();
					
					}
				else if (result == 0)
					{
					adminNav("none",result)
					}
				else
					{
					out = result;
					document.getElementById('AdminNav').style.display = "none";
					}
			
            document.getElementById('output').innerHTML = out;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
		var poststr = "user=" + escape(encodeURI(
		document.getElementById("user").value )) +"&pass=" +
		escape(encodeURI( document.getElementById("pass").value ));
		
		
      makePOSTRequest('application.php', poststr);
   }
   

   function logout() {
		var poststr = "logout=1";
		displayNav = "none"
      makePOSTRequest('application.php', poststr);
	  document.getElementById('forms').style.display = "none";
	  document.getElementById('divSelOptions').style.display = "none";
	  document.getElementById('lists').style.display = "none";
	  document.getElementById('AdminNav').style.display = "none";
	  

   }
   
   function sortByOption(id)
   {
   
	
  	   	 xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  	} 	
	
		
			var url="application.php";
			url=url+"?sid="+Math.random();
			url=url+"&uvar=sortCat";
			url=url+"&cat_id="+id;
	
			xmlHttp.onreadystatechange=stateChangedSortCat;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		
		
		
   	}
		
	function stateChangedSortCat() 
	{ 

			if (xmlHttp.readyState==4)
			{ 
			
			document.getElementById("lists").innerHTML=xmlHttp.responseText;
		
			}
		}
		
   
   function form_select_options()
   {
	  xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  	} 			
		
			var url="application.php";
			url=url+"?sid="+Math.random();
			url=url+"&uvar=selectCat";
			xmlHttp.onreadystatechange=stateChangedSel;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		   
   		}
	
	function stateChangedSel() 
	{ 

			if (xmlHttp.readyState==4)
			{ 
			document.getElementById("divSelOptions").innerHTML=xmlHttp.responseText;
		
			}
		}
	
  function listCat()
  {
    xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 			

	var url="application.php";
	url=url+"?sid="+Math.random();
	url=url+"&uvar=catOpts";
	xmlHttp.onreadystatechange=stateChangeLC;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
  }
  
  function stateChangeLC() 
	{ 

	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("catOpts").style.display="block";
	document.getElementById("catOpts").innerHTML=xmlHttp.responseText;

	}
	}
	
  function pVal(id) 
  {
    document.getElementById("parent").value=id;
    document.getElementById("catOpts").innerHTML="";
    document.getElementById("catOpts").style.display="none";
  }

  function showAddForm(id)
  {
  	if (!document.getElementById("desc"))
  	{
  	 //form object desc does not exist
  	 
  	}
  	else
  	{
  		removeControls("desc")
  	}
	x = document.getElementById("select_cat").value

	
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 			

	var url="application.php";
	url=url+"?sid="+Math.random();
	url=url+"&uvar=catId2type";
	url=url+"&catId="+id;
	xmlHttp.onreadystatechange=stateShowAddForm;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
  }

   function stateShowAddForm() 
	{ 
	  if (xmlHttp.readyState==4)
			{ 
					//write the correct form
				
				document.getElementById("form").innerHTML=xmlHttp.responseText;
				tinyMCE.execCommand('mceAddControl', false, 'desc');
				document.getElementById("categoryId").value = x
	

	
			}
	}
	
function insertImage()
{
  var selectedArray = new Array();
  var selObj = document.getElementById('imgOpts');
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      //selectedArray[count] = selObj.options[i].value;
      alt = selObj.options[i].text
      img = selObj.options[i].value
      html = '<img src="images/upload/'+img+'" alt="'+alt+'" /> '
      HtmlInserter('desc',html)
      count++;
    }
  }
  
}

	

function HtmlInserter(textAreaId, insertHtml)
{
 	tinyMCE.execInstanceCommand(tinyMCE.getEditorId(textAreaId), 'mceInsertContent', false, insertHtml, true);
 		
}

function SetHtml(textAreaId, insertHtml)
{
 	tinyMCE.execInstanceCommand(tinyMCE.getEditorId(textAreaId), 'mceSetContent', false, insertHtml, true);
 	//SetHtml('desc', xmlHttp.responseText);  (example usage)
}

function removeControls(textid)
{
//id = tinyMCE.getEditorId(textid)
 tinyMCE.execCommand('mceFocus', false, textid);   
 tinyMCE.execCommand('mceRemoveControl', false, textid);
}
formdivId = ""
function editQuip(eqId,divId,description,formdiv,cid)
	{
	formdivId = formdiv
	descform = description
	vis = document.getElementById(divId).style.display
		if ( vis == "" || vis == "none")
			{
			
			document.getElementById(divId).style.display = "block";
			equipmentUpdate(cid,eqId)
			
				}
		else 
			{
			removeControls(description)
			document.getElementById(divId).style.display = "none";
			
				}
	}
  
  function equipmentUpdate(cid,eid)
	{ 

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 			

	var url="application.php";
	url=url+"?sid="+Math.random();
	url=url+"&uvar=equipmentUpdate";
	url=url+"&categoryId="+cid
	url=url+"&equipmentId="+eid
	xmlHttp.onreadystatechange=equipUpdateState;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

   function equipUpdateState() 
	{ 

	if (xmlHttp.readyState==4)
	{ 
	
	document.getElementById(formdivId).innerHTML=xmlHttp.responseText;
	tinyMCE.execCommand('mceAddControl', false, descform);

	}
	}
	
	
    
  
	function getequipnav()
	{ 

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 			

	var url="application.php";
	url=url+"?sid="+Math.random();
	url=url+"&uvar=equipNav";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

   function stateChanged() 
	{ 

	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("equipNav").innerHTML=xmlHttp.responseText;

	}
	}
   
   function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
	}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function eraseCookie(c_name) {
	setCookie(c_name,"",-1);
}

//show and hide menu items
function showHide(subID)
	{
		
	
		displayul = document.getElementById(subID).style.display
		if (displayul == null || displayul == "none" || displayul == "")
			{
				setCookie(subID,"block",5);
			}
		else 
			{
				setCookie(subID,"off",5);
			}
	}
	


function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function getAllCookies() 
	{
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			var ba = c.split("=");
			
			for(var l=0; l < ba.length; l++) {
				var m = ba[l];
				var ism = getCookie(m)
				if (ism != "")
					{
						if(ism == "off")
							{
								var ulID = m;
								
								document.getElementById(  ulID  ).style.display = "none"
							}
						else if(ism == "block")
							{
								var ulID = m;
								
								document.getElementById(  ulID  ).style.display = ism
							}
						
					}
									
			}
			
					
		}
			
	}



function checking(c_name)
	{
	
		x = getCookie(c_name)
		if (x != null) {
				 if (x == "off") 
				 	{
						x = "none"
					}
			
			document.getElementById(c_name).style.display = x
			
		}
		
		//getAllCookies()
		
	}