
/****************************************
	Sends a server request to the ajax 
*****************************************/
function requestServer(url, locale) {
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null)
		return;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-Language", locale);
	xmlHttp.setRequestHeader("Accept-Language", locale);
	
	xmlHttp.send(null);
}

/**********************************************
	Replaces the div contents with the response
**********************************************/
function loadOnDemand(src) {
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = src;
   head.appendChild(script);
 }
function stateChanged() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var x = xmlHttp.responseText;
		//x = eval("("+x+")");
		document.getElementById(div).innerHTML=x;
		var x = document.getElementById(div).getElementsByTagName("script");
		for(var i=0;i<x.length;i++)
		{
			eval(x[i].text);
		}
		
		//eval(document.getElementById(div).innerHTML);
		reroutelinks();
		showImage(activetab, false);
	}
}


/**********************************************
	Creates AJAX request object
**********************************************/

function GetXmlHttpObject() {
	var xmlHttp=null;
	 if (window.ActiveXObject) {
		// Internet Explorer
		try {
	        xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				xmlHttp = false;
			}
		}
	}else if (window.XMLHttpRequest) {
		// Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
		
	// Check if browser supports Ajax or not
	if(xmlHttp==null) {
		alert("Your browser does not support AJAX!");
		return;
	}
	
	return xmlHttp;
}

/**********************************************
	Sends a WCM menu request
**********************************************/
function servicecatPagingGoto(url) {
	showImage(activetab, true);
	requestServer(url, locale);
}

/**********************************************
	Sends a different tab request
**********************************************/
function requestTab(url, tab, locale) {
	setActiveTab(tab);
	showImage(activetab, true);
	requestServer(url, locale);
}

/**********************************************
	Switches tab style to active
**********************************************/
function setActiveTab(tab) {
	if(tab != '') {
		inactive = "inactiveTabStyle";
		active = "activeTabStyle";
		
		// save active tab
		activetab = tab;
		// set three tabs to inactive
		for( i = 1; i <= 3; i++) {
			document.getElementById("tab" + i).className = inactive;
		}
			
		// set the selected to active
		document.getElementById(tab).className = active;
	}
}


/**********************************************
	Re-formats the paging links to AJAX, and
	Removes IE link additions
**********************************************/
function reroutelinks() {
	// Replace the menu response links
	if(document.getElementById("servicecatPaging")) {
		for (t=0; t < document.getElementById("servicecatPaging").childNodes.length; t++){
	   		obj = document.getElementById("servicecatPaging").childNodes[t];
	   		
	   		// clear the #
			if (obj.tagName == "A") {
		   		var link = obj.getAttribute('href');
				
		   		if(link.indexOf("#") > -1) {
			   			link = link.substring(0, link.indexOf("#"));
			   			obj.setAttribute('href', link);
				}
				obj.setAttribute("href", "javascript:servicecatPagingGoto('"+obj+"')");
	   		}
	   		
	   	}
	}
}

/**********************************************
	Redirects to the WCM services page
**********************************************/
function getservice(servPath) {

	off1=servPath.indexOf("/organizations/")+15;
	off2=servPath.indexOf("/services/")+10;
	off3=servPath.indexOf("/",off2);
	
	orgid=servPath.substring(off1,off2-10);
	srvid=servPath.substring(off2,off3);

	var destination = srvURL + "orgid="+orgid+"&srvid="+srvid+"&catid=";
	window.location = destination;
}

/**********************************************
	Redirects to the WCM services page
**********************************************/
function getServiceByServiceType(servicecat) {

	var destination = srvTypeURL + "taxonomy="+taxonomy+"&catid="+catID+"&srvtypetx="+serviceTypeTx+"&srvtypecatid="+servicecat;
	window.location = destination;
}

function setServiceTypeTaxonomies(_taxonomy,_catID,_serviceTypeTx){
	taxonomy = _taxonomy;
	catID = _catID;
	serviceTypeTx = _serviceTypeTx;
}

/**********************************************
	Show or Hide the loading image in tab 
	during AJAX loading
**********************************************/
function showImage(tab, showcmd) {
	num = tab.substring(3);
	var imgId = "img" + num;
	
	var obj = document.getElementById(imgId).style;
	if(showcmd)
		obj.display="block";
	else
		obj.display="none";
}

