/*Usage
 * var request = getHTTPObject();
 * if(request){
 * AJAX CODE HERE
 * }
 * 
 * If getHTTPObject returns false, the browser isn't Ajax compatible. The if 
 * statement checks to see if it exists, then runs the code.
 */
function getHTTPObject() {
	var xhr = false;//set to false, so if it fails, do nothing
	if(window.XMLHttpRequest) {//detect to see if browser allows this method
		var xhr = new XMLHttpRequest();//set var the new request
	} else if(window.ActiveXObject) {//detect to see if browser allows this method
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
		} catch(e) {//if it fails move onto the next
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
			} catch(e) {//if that also fails return false.
				xhr = false;
			}
		}
	}
	return xhr;//return the value of xhr
}

function getCss()
{
	
	httpObject = getHTTPObject();
	if (httpObject != null)
	{
		httpObject.open("GET", "/includes/fob_footer_css.php");
		httpObject.onreadystatechange = setCss;
		httpObject.send(null);
		
	}
}

function getHtml()
{
	httpObject2 = getHTTPObject();
	if (httpObject2 != null)
	{
		httpObject2.open("GET", "/includes/hh_brand_bar.php");
		httpObject2.onreadystatechange = setHtml;
		httpObject2.send(null);
	}
}

function setCss(){
	if(httpObject.readyState == 4){
		var code = httpObject.responseText;
		var css = document.createElement('STYLE');
		css.type = "text/css";
		
		if(css.styleSheet)
		{
			//ie
			css.styleSheet.cssText = code;
			document.body.appendChild(css);
		
		}
		else{
			//safari, firefox
			var head=document.getElementsByTagName("head")[0];
			var styleNode = document.createElement("style");
			styleNode.appendChild(document.createTextNode(code));
			head.appendChild(styleNode);
		}
		
		//get html for family of brands footer
		getHtml();
	}
}

function setHtml(){
	if(httpObject2.readyState == 4){
		var code2 = httpObject2.responseText;
		var container2 = document.createElement('div');
		container2.setAttribute('id','hf_brands_footer')
		container2.innerHTML = code2;
   		document.body.appendChild(container2);
	}
	
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(getHtml);
