// modified by metromolians
//Change Log:
//* Updated: July 11th, 07: Fixed bug with persistence not working. Doh.
//* Updated: July 9th, 07: Added session only persistence to tabs (set "enabletabpersistence" var below). Only .js file changed.
//* Updated Nov 8th, 06. Ability to select a tab dynamically, by calling a method (ie: via a link). Only .js file changed.

/* var bustcachevar=0 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered (1=yes, 0=no)? */
var loadstatustext="<div align='center' style='padding:5px;'>Requesting content...</div>"

////NO NEED TO EDIT BELOW////////////////////////

function ajaxPage(id, pageName)
{
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
		catch (e){}
		}
	}
	else
		return false

  containerid = 'content'+id;
	document.getElementById(containerid).innerHTML=loadstatustext;

  url = '?Ajax=ShowTab&WebSiteID='+id+'&TabContent='+pageName;
	
  	page_request.onreadystatechange = function(){ loadPage(page_request, containerid) };
	page_request.open('GET', url, true);
	page_request.send(null);
}

function loadPage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	  document.getElementById(containerid).innerHTML=page_request.responseText;
}

function deselectAllTabs(ulObj)
{
  var ullist=ulObj.getElementsByTagName("li"); //array containing the LI elements within our UL
	for (i in ullist)
		ullist[i].className="";  //deselect all tabs
}

function closeTabs(adId)
{
   hideDiv('content'+adId);
   deselectAllTabs(document.getElementById('maintab'+adId));
   return false;
}

function tabClick(targetObj, id, pageName)
{
  if (targetObj.parentNode.className == "selected")              //if the tab clicked on is already selected, close it.
    closeTabs(id);
  else {
    deselectAllTabs(targetObj.parentNode.parentNode);            //up the tree to the UL
    targetObj.parentNode.className="selected";                   //highlight currently clicked-on tab
    ajaxPage(id, pageName);
    showDiv('content'+id);
  }
}