var AjaxSection = "InnerBody";
var AjaxMessageSection = "LoadingMessage";

function onAjaxClickEvent(Obj){
	d=document;
	if(d.getElementById(onAjaxClickEvent.arguments[1]) != null)
		AjaxSection = onAjaxClickEvent.arguments[1];
	if(d.getElementById(onAjaxClickEvent.arguments[2]) != null)
		AjaxMessageSection = onAjaxClickEvent.arguments[2];
	ExecuteAjax = new AjaxEvent(AjaxMessageSection, AjaxSection, Obj);
	return true;
}
/* 
	Begin Ajax Class
    SectionMessage : the please wait message id 
    SectionLoad : the content holder id  
*/
function AjaxEvent(SectionMessage,SectionLoad,Url){
	var AjaxAlerts = {
		SERVERSTATUS:"There seems to be a problem with the server. Please\n try again."+ 
					"If this problem persists, refresh the page\nand contact the Webmaster with the below information:"+
					"\n\nThere was an Internal Error. Status:"
	}
	var URL= Url+((Url.indexOf("?") != -1) ? "&t=" : "?t=")+ Math.random();
	var SECTION_MESSAGE=SectionMessage;
	var SECTION_LOAD=SectionLoad;
	var PARAM = SetParam();
	var METHOD = SetMethod();
	var HASMESSAGE = (AjaxEvent.arguments.length >= 4) ? AjaxEvent.arguments[3] : true; // show message after completion
	var TYPEOFREQUEST = SetRequest();
	var d=document;
	var ShowHideSetting = (AjaxEvent.arguments.length >= 5) ? AjaxEvent.arguments[4] : true; // hide ajax section while loading;
	
	function SetParam(){ return (UrlParameters) ? UrlParameters : null; }
	function SetMethod(){ return (UrlParameters) ? "POST" : "GET"; }
	function SetRequest(){ return (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); }

	function IsElement(ID){ return (document.getElementById(ID)) ? true : false; }
	function WriteContent(ID,Content){ document.getElementById(ID).innerHTML=Content; if(HASMESSAGE) ajaxShowMessage(); }
	
	function Hide(){
		for(i = 0; i < Hide.arguments.length; i++){
			if(IsElement(Hide.arguments[i])){
				d.getElementById(Hide.arguments[i]).style.display="none";
			}
		}
	}	
	function Display(){
		for(i=0; i < Display.arguments.length; i++){
			if(IsElement(Display.arguments[i]))
				d.getElementById(Display.arguments[i]).style.display="";
		}
	}
	function Interactive(){}
	function Success(){ 
		if(ShowHideSetting){
			Hide(SECTION_MESSAGE);
			Display(SECTION_LOAD);
		}
		if(IsElement(SECTION_LOAD)){ WriteContent(SECTION_LOAD,TYPEOFREQUEST.responseText)}else if(TYPEOFREQUEST.responseText!="" && TYPEOFREQUEST.responseText!="NULL"){ alert(TYPEOFREQUEST.responseText)} 
		if(typeof DoMore == 'function'){ DoMore(); }
	}
	function Failure(){ 
		if(ShowHideSetting){
			Hide(SECTION_MESSAGE);
			Display(SECTION_LOAD);
		}
		if(IsElement(SECTION_LOAD) && TYPEOFREQUEST.status!=0){ WriteContent(SECTION_LOAD,AjaxAlerts.SERVERSTATUS + TYPEOFREQUEST.status)}else if(TYPEOFREQUEST.status!=0){ alert(AjaxAlerts.SERVERSTATUS + TYPEOFREQUEST.status)} 
	}
	function LoadPage(){
		TYPEOFREQUEST.onreadystatechange=HttpHandler;
		TYPEOFREQUEST.open(METHOD,URL,true);
		// set header if POST call
		if(PARAM != null){ TYPEOFREQUEST.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); }
		TYPEOFREQUEST.send( PARAM );
	}
	function HttpHandler(){
		switch(TYPEOFREQUEST.readyState){
			case 4:
				if (TYPEOFREQUEST.status==200){
					Success();
				}else{
					Failure();                     
				}
				return;
		 }
	}
	function Initialize(){
		if(ShowHideSetting){ 
			Display(SECTION_MESSAGE);
			Hide(SECTION_LOAD);
		}
		LoadPage();	
	}
	Initialize();
}
// End Ajax Class
function ajaxShowMessage(){
	if(document.getElementById("message_confirmation")){
		if(!ajaxShowMessage.arguments[0]) MessageId = window.setTimeout("ajaxHideMessage()", "3000");
	}
}
function ajaxHideMessage(){
	if(document.getElementById("message_confirmation")){
		//document.getElementById("message_confirmation").parentNode.innerHTML = "";
		ajaxnodisplay("message_confirmation");
		window.clearTimeout(MessageId);
	}
}
function ajaxnodisplay(){
	var d=document;
	
	for(i = 0; i < ajaxnodisplay.arguments.length; i++){
			if(d.getElementById(ajaxnodisplay.arguments[i])){	
				d.getElementById(ajaxnodisplay.arguments[i]).style.display="none";
			}
	}
}
function ajaxdisplay(){
	var d=document;
	for(i=0; i < ajaxdisplay.arguments.length; i++){
			if(d.getElementById(ajaxdisplay.arguments[i])){
				d.getElementById(ajaxdisplay.arguments[i]).style.ajaxdisplay="";
			}
	}
}