// JavaScript Document
// always have var
var xmlHttp;
// this function creates XmlHttpObject
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;
}
// this function gets staff data
function showstaff(str)
	{
	if(str != 'X')
		{		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="staffdata.cfm";
		url=url+"?staff_id="+str;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		}
		// this function gets state of readystate
		
}
// this function will write response text to innerHTML
function stateChanged() 
		{ 
			if (xmlHttp.readyState==4)
			{ 
			document.getElementById("ajax1").innerHTML=xmlHttp.responseText;
			}
	}
// this function gets hints for staff names
function attrhint(str,thepage,thevar,thecfc,thecity,thestate,thedb)
	{xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="../ajax/items.cfm";
	url=url+"?name="+str;
	url=url+"&sid="+Math.random();
	url=url+"&cfc="+thecfc+"&thedb="+thedb+"&city="+thecity+"&state="+thestate;
	url=url+"&item=namehint&nologo=yes&page="+thepage+"&thevar="+thevar;
	//alert("url="+url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
// this function gets another page as specified and returns it
function pullpage(thepage){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url=thepage;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
// this function outputs system time to inner HTML
function input_time()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	 var url="ajaxitems.cfm?function=input_time";
	 url=url+"&sid="+Math.random();
	 xmlHttp.onreadystatechange=stateChangedInput;
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);
}
// this function will write response text to input value
function stateChangedInput() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("ajax1").value=xmlHttp.responseText;
	}
}
// this is stuff for new homepage or wherever it can be used
var myelement;
var myserver='dfdweb'
function swapbuttons(theid,in_out){
	myelement=document.getElementById(theid);
	if(in_out==1)
		{myelement.style.color='#CCCCCC';
		}
	else
		{myelement.style.color='#0000FF';
		}
	}
function linker(page){
	window.location='http://'+myserver+'/'+page+'?serveraddress='+myserver;
	}
function doserver(stat){
	if(stat==1)
		{myserver='dfdweb';
		}
	else
		{myserver='10.137.130.5';
		}
	}
function openwin(page){
	window.open(page);
	}
// this function gets hints for staff names
function singlepix(thevar,thecfc,thedb)
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="../ajax/items.cfm";
	url=url+"?sid="+Math.random();
	url=url+"&cfc="+thecfc+"&thedb="+thedb;
	url=url+"&item=singlepix&nologo=yes&pix_id="+thevar;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
function singlepod(thevar,thecfc,thedb)
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax/items.cfm";
	url=url+"?sid="+Math.random();
	url=url+"&cfc="+thecfc+"&thedb="+thedb;
	url=url+"&item=singlepod&nologo=yes&hist_id="+thevar;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function setselect(selectID,theval){
	var mysel=document.getElementById(selectID);
	for (var i=0;i<mysel.options.length;i++)
		{//alert("theval is "+mysel.options[i].value);
		if(mysel.options[i].value==theval)
			{//alert("I am selecting"+mysel.options[i].value);
			mysel.selectedIndex=i;
			}
		}
}
function movediv(thediv,thex,they){
	var myelement=document.getElementById(thediv);
	//document.myform.yval.value=ypos;
	//document.myform.xval.value=xpos;
	myelement.style.zIndex=3;
	myelement.style.left=thex+'px';
	myelement.style.top=they+'px';
	}
function centerdiv(thediv){
	var myel=document.getElementById(thediv);
	var divHeight=myel.clientHeight;
	var divWidth=myel.clientWidth;
	//alert(divHeight+" "+divWidth);
	// set vars and determine if IE or not
	var scrollY;
	var scrollX;
	var centerHeight;
	var centerWidth;
	var IE = document.all?true:false;
	if (IE)
		{// see if we are in strict xhtml mode for IE
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
		scrollY=iebody.scrollTop;
		scrollX=iebody.scrollLeft
		centerHeight=document.body.clientHeight;
		centerWidth=document.body.clientWidth;
		}
	else
		{scrollY=window.pageYOffset;
		scrollX=window.pageXOffset;
		centerHeight=window.innerHeight;
		centerWidth=window.innerWidth;
		}
	//calc center of screet
	centerHeight=Math.round(centerHeight/2);
	centerWidth=Math.round(centerWidth/2);
	var docTop=Math.round(centerHeight-(divHeight/2))+scrollY;
	var docLeft=Math.round(centerWidth-(divWidth/2))+scrollX;
	//alert("IE="+IE+" and x,y="+scrollX+", "+scrollY+" docLeft="+docLeft+" and docTop="+docTop+" centerwidth="+centerWidth+" and centerheight="+centerHeight+" divHeight="+divHeight+" and divwidth="+divWidth);
	movediv(thediv,docLeft,docTop);
}
function setinnerHTML(theid,theval){
	document.getElementById(theid).innerHTML=theval;
}
function movedivtomouse(theevent,thediv){
	var IE = document.all?true:false;
	if (IE) { // grab the x-y pos.s if browser is IE
	tempX = theevent.clientX + document.body.scrollLeft;
	tempY = theevent.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
	tempX = theevent.pageX;
	tempY = theevent.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	tempX=tempX+10;
	tempY=tempY+10;
	movediv(thediv,tempX,tempY);
	}
