// JavaScript Document
 
function showElement(invis,classN)
{	
 
var shw = document.getElementById(invis);
// shw.className ="visible";
		if(classN == '')
			shw.className ="visible";
		else
			shw.className = classN+"_visible";
			 
		 
	return false;
}
function hideElement(invis,classN)
{	var shw = document.getElementById(invis);
		 
		if(classN == '')
			shw.className ="invisible";
		else
			shw.className = classN+"_invisible";
			
			 
		return false;
}


//switches class names from visible to invisible
// ele - element ID name to switch
// bkg - optional background element to switch
function switchVisibility(ele,bkg, bkgImg)
{	
	var shw = document.getElementById(ele);
	 
	if(shw.className == 'visible')
	{
			shw.className = 'hidden';
			if( document.getElementById( bkg) )
			{ 
				document.getElementById( bkg).style.background  = "url('/assets/images/icons/down.gif')   no-repeat";
				 
			}
	}
	else
	{
		shw.className = 'visible';
			if( document.getElementById( bkg) )
			{ 
				document.getElementById( bkg).style.background  = "url('/assets/images/icons/up.gif')   no-repeat";
			}
	}
	
}


// hide - 'name' of document ID element 
// show - 'name' of document ID element 
// show =true - make hide invisible and show visible
//show = false -make hide  visible and show invisible
function showHideMsg(hide, show, show)
{	var shw = document.getElementById(hide);
	var nxt = document.getElementById(show);
	
	if( show == "yes" || show == true)
	{
		nxt.style.visibility ="hidden";
		nxt.style.display ="none";
		
		shw.style.visibility ="visible";
		shw.style.display ="block";
	}
	else
	{
		nxt.style.visibility ="visible";
		nxt.style.display ="block";
	
		shw.style.visibility ="hidden";
		shw.style.display ="none";
		
	}
}

//Hides all of the childeren elements of IDName excluding the id of except
function clearAll(idName, except)
{
		var oDiv = document.getElementById(idName);

		if(oDiv.firstChild) { // check for children
		   var oChild = oDiv.firstChild;
		   while(oChild) { // run over them
			 if(oChild.nodeType==1) { // element
			   // oChild is a first level child of oDiv
			   // Do what you want with it here
			   if(oChild.id != except)
			   {
			   	   oChild.className="hidden";
			   }
			 }
			 oChild = oChild.nextSibling;
		   }
		}

}

function enable(eleName)
{
var eleObj = document.getElementById(eleName);
eleObj.disabled =false;

}

function disable(eleName)
{
var eleObj = document.getElementById(eleName);
eleObj.disabled =true;

}

function makeRequired(name)
{
	var ele = document.getElementById(name);
	
	if(ele.validate == "false")
	{
		ele.validate= "true";
	}
 
}

function clearRequired(name)
{
	var ele = document.getElementById(name);
	
	if(ele.validate == "true")
	{
		ele.validate= "false";
	}
 
}



/* AJAX function to keep a users session alive
  pass in coldfusion session variables 
  cfid and cftoken in string url format
  &cfid=######&cftoken=######
  
*/

function sessionTimeout(sessionVars)
{   
	var xmlhttp ="";
	//non IE browsers
	if(window.XMLHttpRequest)
	   xmlhttp = new XMLHttpRequest();  
    //IE
	else if( window.ActiveXObject)
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	 
	//call a simple coldfuison page that will keep a users sesison alive
    xmlhttp.open('GET','keep_alive.cfm', true);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  /*response function*/
  xmlhttp.onreadystatechange = function()
  {
	if(xmlhttp.readyState == 4)// complete
	{
		if(xmlhttp.status == 200) //ok status
		{ //alert(xmlhttp.responseText);
			 alert("your session was about to expire");
		}
	}
  }
  //cfid and cftoken in string url format
  //&cfid=######&cftoken=######
  //submit the request 
  xmlhttp.send(sessionVars);
  
  setTimeout("sessionTimeout('"+sessionVars+"' )",300000); //every 5 minutes 300000
}
