if(!ajaxURL) var ajaxURL = 'TabRequest.php';
if(!loadTab) var loadTab = 'tab-info';

function openTab(tabName) {
	resetTabs();
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")) {
			if(anchor.getAttribute("rel")) {
				var strRel = anchor.getAttribute("rel");
				if(strRel.substr(0, 3) == "tab") {
					if(strRel == tabName) {
						anchor.className = strRel + "-selected";
						getTabContents(tabName);
					} //end if
				} //end if
			} //end if
		} //end if
	} //end for
	
} //end function

function loadTabs(tabSelected) {
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")) {
			if(anchor.getAttribute("rel")) {
				var strRel = anchor.getAttribute("rel");
				if(strRel.substr(0, 3) == "tab") {
					if(strRel == tabSelected) {
						anchor.className = strRel + "-selected";
						getTabContents(strRel);
					} else {
						anchor.className = strRel.replace("-selected", "");	
					} //end if
				} //end if
			} //end if
		} //end if
	} //end for
} //end function

function resetTabs() {
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")) {
			if(anchor.getAttribute("rel")) {
				var strRel = anchor.className;
				if(strRel.substr(0, 3) == "tab") {
					if(strRel.indexOf("-selected")) {
						anchor.className = strRel.replace("-selected", "");
					} //end if
				} //end if
			} //end if
		} //end if
	} //end for
} //end function

function getTabContents(tabName) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    } //end if
    if(window.location.search.substring(1)) {
    	var urlBuild = ajaxURL + "?tab=" + tabName + "&" + window.location.search.substring(1);
    } else {
    	var urlBuild = ajaxURL + "?tab=" + tabName;
    }
    
    var curDate = new Date();
    
    var urlBuild = urlBuild + "&td=" + curDate.getTime();
    
    self.xmlHttpReq.open("GET", urlBuild, true);
    self.xmlHttpReq.onreadystatechange = function() {
	    if (self.xmlHttpReq.readyState == 4) {
	        updateTab(self.xmlHttpReq.responseText);
	    } //end if
    } //end function
    document.getElementById(loadTab).innerHTML = "<div class='tab-info-margin'><img src='/images/spacer.gif' style='float:left;' width='1' height='270'>Please wait while we process your request...<div class='clear'></div></div>";
    self.xmlHttpReq.send(null);
} //end function

function updateTab(strData){
    document.getElementById(loadTab).innerHTML = strData;
} //end function
