function makeRequest(url, elementId, callback) {
	var http_request = initXmlHttpObj();

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function() { displayResponse(http_request, elementId, callback); };	
	http_request.open('GET', url, true);
	http_request.send(null);

}

function displayResponse(http_request, elementId, callback) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
			var root_node = xmldoc.getElementsByTagName("string").item(0);
			
			//Checking for null value first before setting the display element
			if(elementId && root_node.firstChild) {
				if(root_node.firstChild.data != null) 
				{
					var displayElement = document.getElementById(elementId);
					displayElement.innerHTML = root_node.firstChild.data;
				}	
			}
			
			if(callback && typeof(callback) == 'function') {
				if(root_node.firstChild)
					callback(true, xmldoc);
				else
					callback(false, null);
			}
		} else {
			//alert('There was a problem with the request.');
			if(callback && typeof(callback) == 'function') {
				callback(false, null);
			}
		}
	}

}

// JSON Style
function makeRequestJson(url, callback) {
	var http_request = initXmlHttpObj();
	
	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function() { displayResponseJson(http_request, callback); };	
	http_request.open('GET', url, true);
	http_request.send(null);

}

function initXmlHttpObj()
{
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return http_request;
}

function displayResponseJson(http_request, callback) {

	if (http_request.readyState == 4) {
		try
		{
			if (http_request.status && http_request.status == 200) {
				var responseText = http_request.responseText;
				var resultObj = null;
				try
				{
					resultObj = eval('(' + responseText + ')');
				}
				catch(e)
				{
					// eat exception
				}
				if(callback && typeof(callback) == 'function') {
					callback(true, resultObj);
					
				}
			} else {
				//alert('There was a problem with the request.');
				if(callback && typeof(callback) == 'function') {
					callback(false, null);
				}
			}
		}
		catch(e)
		{
			if(callback && typeof(callback) == 'function') {
					callback(false, null);
				}
		}
	}

}

function populateCLUFeatureColumn()
{
	var corpID = GetCookie("Serviceability","CorpID");
	var levelNumber = 1;
	if(corpID)
	{
		levelNumber = 4;
	}
	else
	{
		corpID = 1;
	}
	makeRequest('/userservices/localcontent.asmx/GetCLUPageContent?LevelNumber=' + levelNumber + '&LevelID=' + corpID,'feature')
}

function populateHomeQuickLinks()
{
	var corpID = GetCookie("Serviceability","CorpID");
	var levelNumber = 1;
	if(corpID)
	{
		levelNumber = 4;
	}
	else
	{
		corpID = 1;
	}
	var linksDiv = document.getElementById("dynamicLinks");
	linksDiv.style.display = "inline";
	makeRequest('/userservices/localcontent.asmx/GetLinksHome?LevelNumber=' + levelNumber + '&LevelID=' + corpID,'dynamicLinks')
	
}

function populateCustCentralQuickLinks()
{
	var corpID = GetCookie("Serviceability","CorpID");
	var levelNumber = 1;
	if(corpID)
	{
		levelNumber = 4;
	}
	else
	{
		corpID = 1;
	}
	var linksDiv = document.getElementById("dynamicLinks");
	if(linksDiv != null)
	{
    	linksDiv.style.display = "inline";
	    makeRequest('/userservices/localcontent.asmx/GetLinksCustCentral?LevelNumber=' + levelNumber + '&LevelID=' + corpID,'dynamicLinks')
	}
}

function populateMyAccountCorporateShopContent()
{
    makeRequest('/userservices/localcontent.asmx/GetShopContentMyAccount?CorpId=1','corporateShopContent')
}

function populateMyAccountShopContent()
{
    var corpID = GetCookie("Serviceability","CorpID");
    makeRequest('/userservices/localcontent.asmx/GetShopContentMyAccount?CorpId='+ corpID,'shopContent')
}

function populateHomePromo()
{
	var corpID = GetCookie("Serviceability", "CorpID");
	var levelNumber = 1;
	if(corpID)
	{
		levelNumber = 4;
	}
	else
	{
		corpID = 1;
	}
	var linksDiv = document.getElementById("PromoSection");
	linksDiv.style.display = "inline";
	makeRequest('/userservices/localcontent.asmx/GetHomePageContent?LevelNumber=' + levelNumber + '&LevelID=' + corpID,'PromoSection')
	
}

