/*
  Functions to control ajax changing page 
  content in navigation


*/

// ajax function always throws an error

window.onerror=doNothing;

function doNothing(){
	return true;
}

	var http = createRequestObject();
	
	var postArrayKeys	=	new Array();
	var postArrayValues	=	new Array();	
	var httpPostSendString="";
	var previousComponentURL="";
	
	function createRequestObject() {
	    var ro;
	    var browser = navigator.appName;
	    if(browser == "Microsoft Internet Explorer"){
	        ro = new ActiveXObject("Microsoft.XMLHTTP");
	    }else{
	        ro = new XMLHttpRequest();
	    }
	    return ro;
	}


var globalComponent='';
	
//alert('ajax lib loaded');
	function sndReqFullURL(loc) {
		//first step change the innerHTML of the 
		// current maincontent layer to the waiting gif
		//alert(loc);
		
		var obj=document.getElementById('theMainContent');
		obj.innerHTML="<div class='ajaxPleaseWait' ><img src='images/icons/indicator.black.gif'> Please wait ...</div>";	
		
		if(arguments.length ==0){
	    	
		} else {
			http.open('get', loc);
			//previousComponentURL=loc;
		}

		globalComponent=loc;
      // alert(globalComponent);
	    http.onreadystatechange = handleResponse;
	    setTimeout('http.send(null);',200);
	    //http.send(null);
	   
	}

	function change(){
		alert('');
			var obj=document.getElementById('theMainContent');
		obj.innerHTML="<p>The inner html changed</p>";	
	}

	
	function handleResponse() {
		//alert(http.readyState+ " "+http.status);
	    
	    if(http.readyState == 4 && http.status == 200){
	        var response = http.responseText;
	    //    var update = new Array();
	    //    update = response;
	    
	    		//setTimeout("Effect.Fade('theMainContent");", 10);
	    		//document.getElementById("theMainContent").style.visibility='hidden';
	    		//document.getElementById("theMainContent").style.display='none';
	            document.getElementById("theMainContent").innerHTML = response;
	            //document.getElementById("theMainContent").style.visibility='visible';
	    		httpPostSendString="";
   				//setTimeout("Effect.Appear('theMainContent');", 150);
   				setTimeout("Effect.Slide('theMainContent');", 150);   				
	    		var obj=document.getElementById("theMainContent");
	    		//obj.style.top= parseInt(obj.style.top)+100;
	    		//parseInt(xy[1])
	    } else if(http.status == 404){
	            var tmp = "<p class='warning'";
	            tmp += "style='background:white;border:2px solid red;padding:5px;'>";
		        tmp += "<img src='images/icons/warning.png'> 404 - AJAX Component not found</p>";
	   
	   			document.getElementById("theMainContent").innerHTML=tmp;
	    }
	}
	
	function refreshComponent(){
		alert('test');
		/*if(globalComponent != ''){
			sndReqFullURL(globalComponent);
		} else {
			// just refresh this location
			//location.replace(window.location);
			location.reload(true);
		}*/
	}	
	
	function refreshCurrentComponent(){
		//alert('test');
		if(globalComponent != ''){
			sndReqFullURL(globalComponent);
		} else {
			// just refresh this location
			//location.replace(window.location);
			location.reload(true);
		}
	}		
	