

// written by Perry
// ajaxFunction Version 3   01/30/2007
// Version 3 
// Finally, I made this an object.
// loadingImageOn is added.

// Version 4 09/18/2007
// RunThisAfterSyn is added to support any functions after the sync is done

// Version 2 of ajaxFunction can take more than 1 argument as queryString with separater "&".
// str is the value passed to the destination page as a querystring variable
// dest is the page which takes str as an argument or querystring
// queryString is the name of the queryString will be used in the dest page
// objName is the div object located in the caller

//var ajaxPageFolder = "/ajaxPage/"

	function ajaxObj(){
		
		var xmlHttp
		var obj
		var that = this
		
		this.focusOn = ''
		
		this.ajaxPageFolder = "/ajaxPage/"
		this.loadingContentOn = true
		this.loadingContent = '<img src=\"/images/symbols/ajax-loader_blue.gif\" />'
		this.fixedheight = ''


		this.setLoadingContent = function(LoadingContent){
			this.loadingContent = LoadingContent
		}
		
		this.setLoadingContentOn = function(LoadingContentOn){
			this.loadingContentOn = LoadingContentOn
		}		
	
		this.ajaxFunction = function(queryStringKey, queryStringValue,dest,objName){ 
			
			if(objName){
				obj = objName 
			
				if (this.fixedheight != ''){
					document.getElementById(obj).style.height = this.fixedheight
				}
				
				if (this.loadingContentOn){
					document.getElementById(obj).innerHTML = this.loadingContent
				}
			}
			
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null){
				alert ("Browser does not support HTTP Request")
				return
			} 
			
			var KeyArray = queryStringKey.split("&");
			var ValueArray = queryStringValue.split("&");
		
			var queryString = ""
			
			var value = ""
			for (var i=0; i < KeyArray.length ; i++){				
				value = ValueArray[i]
				value = value.replace(/\+/g,'%2B')
				queryString = queryString + KeyArray[i] + "=" + value + "&"
			}
			
			dest = this.ajaxPageFolder+dest+"?"+queryString			
			
			xmlHttp.onreadystatechange = stateChanged
			xmlHttp.open("GET",dest,true)
			xmlHttp.send(null)
			
			if (this.focusOn != '')
				location.href = '#' + this.focusOn
			
		}
		
		this.RunAfterSync = function(){

		}

		function stateChanged() { 
			if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete") && (obj)){ 
				if(xmlHttp.status  == 200){
					document.getElementById(obj).innerHTML=xmlHttp.responseText 	
					that.RunAfterSync();
				}else{
					
				}
				if (this.fixedheight != ''){
					document.getElementById(obj).style.height = ''
				}			
				
			} 
		} 
		
		function GetXmlHttpObject() { 
			var objXMLHttp=null
			if (window.XMLHttpRequest){
				objXMLHttp=new XMLHttpRequest()
			}else if (window.ActiveXObject){
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			return objXMLHttp
		}
		

	}