// Get browser information

var if_userAgent = navigator.userAgent.toLowerCase();
var opera = (if_userAgent.indexOf('opera') != -1); // is opera
var ns4 = (document.layers) ? true : false; // is netscape 4
var ie4 = (document.all && !document.getElementById) ? true : false; // is IE 4
var ie5 = (document.all && document.getElementById) ? true : false; // is IE 5+
var ns6 = (!document.all && document.getElementById) ? true : false; // is netscape 6


/* ----------------------------------------------------------- */
// Determine what object model we should use                   
/* ----------------------------------------------------------- */

function if_returnObjRef(objName) {

	var objReturn = '';
		if (ie5 || ns6)
		{
			objReturn = document.getElementById(objName);
			if (!objReturn) {
				objReturn = document.getElementById(if_findInASPNETControlTree(objName));
			}
		}
		else if (ie4 || opera)
		{
			objReturn = document.all[objName];
			if (!objReturn) {
				objReturn = document.all[if_findInASPNETControlTree(objName)];
			}
		}
		else if (ns4)
		{
			objReturn = document.layers[objName];
			if (!objReturn) {
				objReturn = document.layers[if_findInASPNETControlTree(objName)];
			}
		}

	return objReturn

}
/* ----------------------------------------------------------- */
// Toggle display of forum group					           
/* ----------------------------------------------------------- */

function if_toggleDisplay(objName, strStylePath, strCookie)
{

	//obj = if_returnObjRef("if_obj_Group_" + objName);
	obj = if_returnObjRef(objName);
	img = if_returnObjRef("Image" + objName);
	gft = if_returnObjRef("if_obj_Footer_" + objName);
	
	if (obj.style.display == "none" )//|| gft.style.display == "none"
	{
		obj.style.display = "";
		//gft.style.display = "";
		if(img)
		img.src = strStylePath + "Images/pil2.gif";
		if_update_cookie(objName, false,strCookie);

	}
	else
	{
		obj.style.display = "none";
		//gft.style.display = "none";
		if(img)img.src = strStylePath + "Images/pil1.gif";
		if_update_cookie(objName, true, strCookie);
	
	}
	return false;
}

/* ----------------------------------------------------------- */
// Save snapshot of forum groups into cookie		           
/* ----------------------------------------------------------- */

function if_update_cookie(objName, bolSave, strCookie)
{

	var ckName = strCookie //"TankbarExpandMenu";
	var ckColl = if_get_cookie(ckName);		
	var arrLocTemp = new Array();
	
	if (ckColl != null) // if cookie exists
	{
		arrColl = ckColl.split(","); // split cookie into array
		
		for (i in arrColl) // loop array
		{
			/* if item does not match objName or is blank */
			if (arrColl[i] != objName && arrColl[i] != "") 
			{
				arrLocTemp[arrLocTemp.length] = arrColl[i];
				
			}
		}
	}

	if (!bolSave) // if item is expanded save groupid to array
	{
		arrLocTemp[arrLocTemp.length] = objName;
		
	}
	if_set_cookie(ckName, arrLocTemp.join(",")); // save cookie
}

/* ----------------------------------------------------------- */
// Standard Cookie Functions                       	           
/* ----------------------------------------------------------- */

function if_set_cookie(name, value)
{

	expire = " expires=Wed, 1 Jan 2020 00:00:00 GMT;";
	document.cookie = name + "=" + value + "; path=/;" + expire;
}

/* ----------------------------------------------------------- */

function if_get_cookie(name)
{
	ckName = name + '=';
	ckPos  = document.cookie.indexOf(ckName);
	
	if ( ckPos != -1 )
	{
		ckStart = ckPos + ckName.length;
		ckEnd   = document.cookie.indexOf(";", ckStart);
		
		if (ckEnd == -1)
		{
			ckEnd = document.cookie.length;
		}
		
		return unescape( document.cookie.substring(ckStart, ckEnd) );
	}
	
	return null;
}

/* ----------------------------------------------------------- */
// If we cannot immediatly find a tbody object to hide a table this 
// will loop though all tbodies and find the object regardless of any
// asp.net control tree identifiers - things like _ctl1_objectID
/* ----------------------------------------------------------- */

function if_findInASPNETControlTree(strObjectName) {
	
	var strObjectOutput;
		tbodies = document.getElementsByTagName("tbody");
		for (var i = 0; i < tbodies.length; i++)
		{
			if (tbodies[i].id.indexOf(strObjectName) > 0) {
			strObjectOutput = tbodies[i].id;
			}
		}
		
	return strObjectOutput;
	
}

/* ----------------------------------------------------------- */
// Starting with the given node, find the nearest containing element
// with the specified tag name.
/* ----------------------------------------------------------- */

function if_getContainer(node, tagName) {

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName)
      return node; node = node.parentNode;
  }

  return node;
}
