//creates a combo box like drop
function text_suggest(inputID, url, otherArgName, otherArgInputID, otherArg2Name, otherArg2InputID, otherArg3Name, otherArg3InputID) {
this._inputID;this._inputO;	this._inputID_O;this._otherInputID;this._otherInputO;this._input2O;this._otherInput2ID;this._otherInput2O;this._otherInput2Name;this._input3O;this._otherInput3ID;this._otherInput3O;this._otherInput3Name;this._divO=null;this._strURL;this._strSuggestions;this._backGroundColor;
this.get_suggestion = function(strSearchText) {
		if (text_sug._inputID_O) {
			text_sug._inputID_O.value = "";
		}
		if (strSearchText==null) {
	 		var str = escape(this._inputO.value);
	 	} else {
	 		var str = strSearchText;
	 	}
	 	if (str.trim() != "") {
		 	if (this._otherInputName != undefined) {
		 		var url  = this._strURL + str + '&' + this._otherInputName + '=' + escape(this._otherInputO.value);
		 		if (this._otherInput2Name != undefined) {
			 		url  = url + '&' + this._otherInput2Name + '=' + escape(this._otherInput2O.value);
		 		}
		 		if (this._otherInput3Name != undefined) {
			 		url  = url + '&' + this._otherInput3Name + '=' + escape(this._otherInput3O.value);
		 		}
	 		} else {
		 		var url  = this._strURL + str;
	 		}

			AjaxRequest.get(
				{
					'uservar':this,
					'url':url
					,'onSuccess':function(req){ req.uservar.get_suggestion_ajax_return(req.responseText);}
					,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				}
			);
		} else this.hide_div();
 	};
 	this.get_suggestion_ajax_return = function(strResponseText) {
		scripting=true;
		text_sug = this; //used to =functions can access this object;
			if (this._divO==null) {
				this._divO=document.createElement("DIV");
				elt=this._inputO;
				//find coords where the suggest div will appear
				pos2=findPos(elt); pos2.push(elt.offsetHeight); pos2.push(elt.offsetWidth);

				this._divO.style.top=(pos2[1]+pos2[2])+'px';
				this._divO.style.left=pos2[0]+'px';
				this._divO.style.width=pos2[3]+'px';
				this._divO.style.position="absolute";
				this._divO.style.visibility="visible"; // for Opera
				this._divO.style.backgroundColor=this._backGroundColor;
				document.body.appendChild(this._divO);
			}
			this._divO.innerHTML="";

			strResponseText = strResponseText.trim();
			strResponseText = strResponseText.split("\n");
			strResponseText_clean = new Array();
			var ct = 0;
			for (i=0;i<strResponseText.length;i++) {
				strResponseText[i] = strResponseText[i].trim();
				if (strResponseText[i] != "") {
					strResponseText_clean[ct] = strResponseText[i];
					ct++;
				}
			}
			if (strResponseText_clean.length>0) {
				var temp;
				for (i=0;i<strResponseText_clean.length;i++) {
					o=document.createElement("DIV");
					temp = strResponseText_clean[i].split("|");
					if (temp.length > 1) {
						o.innerHTML=temp[1];
						o.id=temp[0];
					} else {
						o.innerHTML=temp[0];
						o.id=temp[0];
					}
						o.style.paddingLeft='4px';
						o.style.backgroundColor=text_sug._backGroundColor;
						o.onmouseover=function(){
							this.style.backgroundColor="#3366CC";
							this.style.cursor="pointer";
							this.style.cursor="hand";
						}
						o.onmouseout=function(){
							this.style.backgroundColor=text_sug._backGroundColor;
						}
						o.onclick=function(){
							text_sug._inputO.value=this.innerHTML;
							if (text_sug._inputID_O) {
								text_sug._inputID_O.value = this.id;
							}
							text_sug._inputO.focus();
							text_sug.hide_div();
						}
						this._divO.appendChild(o)
				}
				this._inputO.focus();
				this.show_div();
			} else {
				this.hide_div();
			}

	 	};
		this.hide_div = function() {
			if (this._divO!=null) {
				this._divO.style.backgroundColor="";
				this._divO.style.border="";
				this._divO.innerHTML="";
			}
		};
		this.show_div = function() {
			if (this._divO!=null) {
				this._divO.style.backgroundColor="";
				this._divO.style.borderStyle="solid";
				this._divO.style.borderColor="#000000";
				this._divO.style.borderWidth="1px";
				this._divO.style.textAlign="left";
			}
		};
		this.show_all = function() {
			this.get_suggestion('\%');
		};
		this.add_drop_down_button = function() {
			this._inputO.style.paddingRight = "17px";
			this._inputO.style.backgroundImage = "url('images/form_tools_drop_down.png')";
			this._inputO.style.backgroundPosition = "center right";
			this._inputO.style.backgroundRepeat = "no-repeat";
			text_sug = this;
			this._inputO.onmousemove = function(e) {
				//Get Location of Mouse Click
				var IE = document.all?true:false;
  				if (IE) { // grab the x-y pos.s if browser is IE
					mouseX = event.clientX + document.body.scrollLeft
					mouseY = event.clientY + document.body.scrollTop
  				} else {  // grab the x-y pos.s if browser is NS
					mouseX = e.pageX
					mouseY = e.pageY
  				}
				//Get Location of Text Box
				elt=text_sug._inputO;
				pos2=findPos(elt); pos2.push(elt.offsetHeight); pos2.push(elt.offsetWidth);

				//Get location of Right Side of Text Box where the drop down img is displayed
				buttonX = pos2[0] + pos2[3] - 18;

				if ((mouseX > buttonX)) {
					text_sug._inputO.style.cursor="default";
				} else {
					text_sug._inputO.style.cursor="text";
				}
			}
			this._inputO.onclick = function(e) {

				//Get Location of Mouse Click
				var IE = document.all?true:false;
  				if (IE) { // grab the x-y pos.s if browser is IE
					mouseX = event.clientX + document.body.scrollLeft
					mouseY = event.clientY + document.body.scrollTop
  				} else {  // grab the x-y pos.s if browser is NS
					mouseX = e.pageX
					mouseY = e.pageY
  				}
				//Get Location of Text Box
				elt=text_sug._inputO;
				pos2=findPos(elt); pos2.push(elt.offsetHeight); pos2.push(elt.offsetWidth);
				//Get location of Right Side of Text Box where the drop down img is displayed
				buttonX = pos2[0] + pos2[3] - 18;

				if ((mouseX > buttonX)) {
					if ((text_sug._divO==null) || (text_sug._divO.innerHTML=="")) {
						text_sug.get_suggestion('\%');
					} else {
						text_sug.hide_div();
					}
				} else {
					text_sug.hide_div();
				}
			}
		}

		this.inputID = inputID;
		this._inputO = document.getElementById(this.inputID);
		this._inputID_O = document.getElementById(this.inputID+'_id');
		this._strURL = url;

		if (this._inputO != undefined) {
			this._backGroundColor = this._inputO.style.backgroundColor;
		}
		if (this._backGroundColor == "") { this._backGroundColor = "#FFFFFF"; }

		//Other Input ID incase there is another text inputs value to be included in the url
this._otherInputID = otherArgInputID;
this._otherInputO = document.getElementById(this._otherInputID);
this._otherInputName = otherArgName;
this._otherInput2ID = otherArg2InputID;
this._otherInput2O = document.getElementById(this._otherInput2ID);
this._otherInput2Name = otherArg2Name;

this._otherInput3ID = otherArg3InputID;
this._otherInput3O = document.getElementById(this._otherInput3ID);
this._otherInput3Name = otherArg3Name;

this._inputO.setAttribute("autocomplete","OFF");
//this._inputO.focus();
var text_sug = this;
this._inputO.onkeyup = function() {text_sug.get_suggestion()};
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}

function AjaxRequest() {var req = new Object();
req.uservar = null;
req.timeout = null;
req.generateUniqueUrl = true;
req.url = window.location.href;
req.method = "GET";
req.async = true;
req.username = null;
req.password = null;
req.parameters = new Object();
req.requestIndex = AjaxRequest.numAjaxRequests++;
req.responseReceived = false;
req.groupName = null;
req.queryString = "";
req.responseText = null;
req.responseXML = null;
req.status = null;
req.statusText = null;
req.aborted = false;
req.xmlHttpRequest = null;
req.onTimeout = null;
req.onLoading = null;
req.onLoaded = null;
req.onInteractive = null;
req.onComplete = null;
req.onSuccess = null;
req.onError = null;
req.onGroupBegin = null;
req.onGroupEnd = null;
req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();
	if (req.xmlHttpRequest==null) { return null; }
	req.xmlHttpRequest.onreadystatechange =
	function() {
		if (req==null || req.xmlHttpRequest==null) { return; }
		if (req.xmlHttpRequest.readyState==1) { req.onLoadingInternal(req); }
		if (req.xmlHttpRequest.readyState==2) { req.onLoadedInternal(req); }
		if (req.xmlHttpRequest.readyState==3) { req.onInteractiveInternal(req); }
		if (req.xmlHttpRequest.readyState==4) { req.onCompleteInternal(req); }
	};
	req.onLoadingInternalHandled = false;
	req.onLoadedInternalHandled = false;
	req.onInteractiveInternalHandled = false;
	req.onCompleteInternalHandled = false;
	req.onLoadingInternal =
		function() {
			if (req.onLoadingInternalHandled) { return; }
			AjaxRequest.numActiveAjaxRequests++;
			if (AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function") {
				AjaxRequestBegin();
			}
			if (req.groupName!=null) {
				if (typeof(AjaxRequest.numActiveAjaxGroupRequests[req.groupName])=="undefined") {
					AjaxRequest.numActiveAjaxGroupRequests[req.groupName] = 0;
				}
				AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
				if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function") {
					req.onGroupBegin(req.groupName);
				}
			}
			if (typeof(req.onLoading)=="function") {
				req.onLoading(req);
			}
			req.onLoadingInternalHandled = true;
		};
	req.onLoadedInternal =
		function() {
			if (req.onLoadedInternalHandled) { return; }
			if (typeof(req.onLoaded)=="function") {
				req.onLoaded(req);
			}
			req.onLoadedInternalHandled = true;
		};
	req.onInteractiveInternal =
		function() {
			if (req.onInteractiveInternalHandled) { return; }
			if (typeof(req.onInteractive)=="function") {
				req.onInteractive(req);
			}
			req.onInteractiveInternalHandled = true;
		};
	req.onCompleteInternal =
		function() {
			if (req.onCompleteInternalHandled || req.aborted) { return; }
			req.onCompleteInternalHandled = true;
			AjaxRequest.numActiveAjaxRequests--;
			if (AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function") {
				AjaxRequestEnd(req.groupName);
			}
			if (req.groupName!=null) {
				AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
				if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function") {
					req.onGroupEnd(req.groupName);
				}
			}
			req.responseReceived = true;
			req.status = req.xmlHttpRequest.status;
			req.statusText = req.xmlHttpRequest.statusText;
			req.responseText = req.xmlHttpRequest.responseText;
			req.responseXML = req.xmlHttpRequest.responseXML;
			if (typeof(req.onComplete)=="function") {
				req.onComplete(req);
			}
			if (req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function") {
				req.onSuccess(req);
			}
			else if (typeof(req.onError)=="function") {
				req.onError(req);
			}

			// Clean up so IE doesn't leak memory
			delete req.xmlHttpRequest['onreadystatechange'];
			req.xmlHttpRequest = null;
		};
	req.onTimeoutInternal =
		function() {
			if (req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled) {
				req.aborted = true;
				req.xmlHttpRequest.abort();
				AjaxRequest.numActiveAjaxRequests--;
				if (AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function") {
					AjaxRequestEnd(req.groupName);
				}
				if (req.groupName!=null) {
					AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
					if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function") {
						req.onGroupEnd(req.groupName);
					}
				}
				if (typeof(req.onTimeout)=="function") {
					req.onTimeout(req);
				}
			delete req.xmlHttpRequest['onreadystatechange'];
			req.xmlHttpRequest = null;
			}
		};
	req.process =
		function() {
			if (req.xmlHttpRequest!=null) {
				if (req.generateUniqueUrl && req.method=="GET") {
					req.parameters["AjaxRequestUniqueId"] = new Date().getTime() + "" + req.requestIndex;
				}
				var content = null; // For POST requests, to hold query string
				for (var i in req.parameters) {
					if (req.queryString.length>0) { req.queryString += "&"; }
					req.queryString += encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);
				}
				if (req.method=="GET") {
					if (req.queryString.length>0) {
						req.url += ((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;
					}
				}
				req.xmlHttpRequest.open(req.method,req.url,req.async,req.username,req.password);
				if (req.method=="POST") {
					if (typeof(req.xmlHttpRequest.setRequestHeader)!="undefined") {
						req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
					}
					content = req.queryString;
				}
				if (req.timeout>0) {
					setTimeout(req.onTimeoutInternal,req.timeout);
				}
				req.xmlHttpRequest.send(content);
			}
		};
req.handleArguments =
		function(args) {
			for (var i in args) {
				if (typeof(req[i])=="undefined") {
					req.parameters[i] = args[i];
				}
				else {
					req[i] = args[i];
				}
			}
		};
req.getAllResponseHeaders =
		function() {
			if (req.xmlHttpRequest!=null) {
				if (req.responseReceived) {
					return req.xmlHttpRequest.getAllResponseHeaders();
				}
				alert("Cannot getAllResponseHeaders because a response has not yet been received");
			}
		};
req.getResponseHeader =
		function(headerName) {
			if (req.xmlHttpRequest!=null) {
				if (req.responseReceived) {
					return req.xmlHttpRequest.getResponseHeader(headerName);
				}
				alert("Cannot getResponseHeader because a response has not yet been received");
			}
		};

	return req;
}
AjaxRequest.getXmlHttpRequest = function() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		// Based on http://jibbering.com/2002/4/httprequest.html
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				return null;
			}
		}
		@end @*/
	}
	else {
		return null;
	}
};
AjaxRequest.isActive = function() {return (AjaxRequest.numActiveAjaxRequests>0);};
AjaxRequest.get = function(args) {AjaxRequest.doRequest("GET",args);};
AjaxRequest.post = function(args) {AjaxRequest.doRequest("POST",args);};
AjaxRequest.doRequest = function(method,args) {if (typeof(args)!="undefined" && args!=null) {var myRequest = new AjaxRequest();myRequest.method = method;myRequest.handleArguments(args);myRequest.process();}};
AjaxRequest.submit = function(theform, args) {
	var myRequest = new AjaxRequest();
	if (myRequest==null) { return false; }
	var serializedForm = AjaxRequest.serializeForm(theform);
	myRequest.method = theform.method.toUpperCase();
	myRequest.url = theform.action;
	myRequest.handleArguments(args);
	myRequest.queryString = serializedForm;
	myRequest.process();
	return true;
};
AjaxRequest.serializeForm = function(theform) {
	var els = theform.elements;
	var len = els.length;
	var queryString = "";
	this.addField =
		function(name,value) {
			if (queryString.length>0) {
				queryString += "&";
			}
			queryString += encodeURIComponent(name) + "=" + encodeURIComponent(value);
		};
	for (var i=0; i<len; i++) {
		var el = els[i];
		if (!el.disabled) {
			switch(el.type) {
				case 'text': case 'password': case 'hidden': case 'textarea':
					this.addField(el.name,el.value);
					break;
				case 'select-one':
					if (el.selectedIndex>=0) {
						this.addField(el.name,el.options[el.selectedIndex].value);
					}
					break;
				case 'select-multiple':
					for (var j=0; j<el.options.length; j++) {
						if (el.options[j].selected) {
							this.addField(el.name,el.options[j].value);
						}
					}
					break;
				case 'checkbox': case 'radio':
					if (el.checked) {
						this.addField(el.name,el.value);
					}
					break;
			}
		}
	}
	return queryString;
};
AjaxRequest.numActiveAjaxRequests = 0;
AjaxRequest.numActiveAjaxGroupRequests = new Object();
AjaxRequest.numAjaxRequests = 0;