//--------------varibles for AJAX-----------------------
var serverResponse='';
var receiveReq = getXmlHttpRequestObject();
//------------------------------------------------------


function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert('Status: Could not create XmlHttpRequest Object.' +'Consider upgrading your browser.');
	}
}

function getServerResponse() {
	
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		receiveReq.open("GET", "/intervest/affiliatequery"+ "?t=" + new Date().getTime(), true);
		receiveReq.onreadystatechange = callBack;
		receiveReq.send(null);


	}			
} 

function callBack(){

	if (receiveReq.readyState == 4){
		var response = eval("(" +receiveReq.responseText  + ")");
		affiliateId = response.affiliateId;

		if (affiliateId == "1"){
			//urlPrefix = location.protocol+"//"+location.host	
			document.title = "Low Cost Insurance from Insureme4";
        	try{
    			html = 	"<ul class=\"MainNav ui-sortable\">	<li class=\"current sortable-item\"><a href=\"/home\">Home Page</a></li><li class=\" sortable-item\"><a href=\"/travel-insurance\">Travel</a></li><li class=\" sortable-item\"><a href=\"/holiday-home-insurance\">Holiday Home</a></li></ul>";
    			menu = document.getElementById("navigation");
    			menu.innerHTML = html;
        	}
        	catch(e){

			}
        	try{
        		path = location.pathname;
        		if (path == "/home"){
            		html = "<ul class=\"HomePage\"><li class=\"travelins current\"><a href=\"/travel-insurance\">Travel Insurance</a></li><li class=\"holidayhomeins\"><a href=\"/holiday-home-insurance\">Holiday Home Insurance</a></li></ul>";
            		navi = document.getElementById("LeftNavigation_U");
            		navi.innerHTML = html;
        		}
        		
        	}
        	catch(e){

			}
			
		}
		else if (affiliateId == "2"){
			//urlPrefix = location.protocol+"//"+location.host	
			document.title = "Over 50 insurance";
	    	try{
				html = 	"	<ul class=\"MainNav ui-sortable\">	<li class=\"current sortable-item\"><a href=\"http://www.staysure.co.uk/insurance\">Insurance</a></li></ul>";
				menu = document.getElementById("navigation");
				menu.innerHTML = html;
				
				html = 	"	<ul class=\"SubNav\"><li><a href=\"/travel-insurance\">Travel Insurance</a></li><li><a href=\"/holiday-home-insurance\">Holiday Home Insurance</a></li></ul><div class=\"clear\">&nbsp;</div>"
				submenu = document.getElementById("sub_navigation_menu");
				submenu.innerHTML = html;
				
				html = "<ul><li><label><input checked=\"checked\" name=\"radiobutton\" value=\"/sapi-travelinsurance/index\" type=\"radio\">&nbsp; Travel Insurance</label></li><li><label><input name=\"radiobutton\" value=\"holiday-home-insurance/search\" type=\"radio\">&nbsp; Holiday Home Insurance</label></li></ul>"
				radioButtons = document.getElementById("ins_needIns_U");
				radioButtons.innerHTML = html;
	    	}
	    	catch(e){

			}
	    	try{
		
				html = "<ul><li><label><input checked=\"checked\" name=\"radiobutton\" value=\"/sapi-travelinsurance/index\" type=\"radio\">&nbsp; Travel Insurance</label></li><li><label><input name=\"radiobutton\" value=\"holiday-home-insurance/search\" type=\"radio\">&nbsp; Holiday Home Insurance</label></li></ul>"
				radioButtons = document.getElementById("ins_needIns_U");
				radioButtons.innerHTML = html;
	    	}
	    	catch(e){

			}	    	
	    	try{
	    		path = location.pathname;
	    		if (path == "/insurance"){
	        		document.getElementById("ins_homepg_insuranceNeeds_U").style.display='none';
	        		document.getElementById("ins_holidayMoney-Wide_U").style.display='none';
	        		document.getElementById("ins_homepg_overseasExpat_U").style.display='none';
	        		
	    		}
	    		
	    	}
	    	catch(e){

			}
			
		}
	}
	
}

function doAffiliatePageChanges(){
	getServerResponse();
	


}
