String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function enterObj(thisplace,thistype,ajax,stg){
	//alert(ajax);
	//if thistype slse not a form
	try{
		var myscreenlocation =  pageYOffset;
	}catch(any){
		var myscreenlocation =	document.body.scrollTop;
	}
	//alert(myscreenlocation);
	
	var formdata = thistype.split("|");
		if (formdata[0] == "form"){
			//alert("You are now doing a form  "+formdata[1]);
			var urldata = formdata[1].split("?");
			if(urldata[0] == "url"){//then we are appending some url vars to the request
				xmlhttpPost("_AJAX/index.cfm?Ajax="+ajax+"&stage="+stg+"&"+urldata[1],"notform",thisplace,myscreenlocation)
			}else{
				xmlhttpPost("_AJAX/index.cfm?Ajax="+ajax+"&stage="+stg,formdata[1],thisplace,myscreenlocation)
			}
		} else {
			xmlhttpPost("_AJAX/index.cfm?Ajax="+ajax+"&stage="+stg,formdata[0],thisplace,myscreenlocation)
		}
}
//ajax code
function xmlhttpPost(strURL,inform,thisarea,thislocation) {
	//alert(strURL);
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari or IE
	self.xmlHttpReq = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

	if (inform){
		self.xmlHttpReq.open('GET', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	} else {
		self.xmlHttpReq.open('GET', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}
	self.xmlHttpReq.onreadystatechange = function() {
		window.scrollTo(0,thislocation);
		if (self.xmlHttpReq.readyState == 4) {
			if(thisarea){
				//alert(self.xmlHttpReq.responseText.trim());
				updatepage(self.xmlHttpReq.responseText,thisarea,thislocation);
			} else {
				updatepage(self.xmlHttpReq.responseText+self.xmlHttpReq.resposeXml);
			}
		}
	}
	//alert(inform);
	if (inform != "notform"){
			self.xmlHttpReq.send(form2queryString(document.forms[inform]));
		} else {
			self.xmlHttpReq.send(null);
			window.scrollTo(0,thislocation);
		}
		
	}
	function form2queryString(form){
	var obj = new Object();
	var ar = new Array();
	for(var i=0;i<form.elements.length;i++){
		try {
			elm = form.elements[i];
			nm = elm.name;
			if(nm != ''){
				switch(elm.type.split('-')[0]){
					case "select":
						for(var s=0;s<elm.options.length;s++){
							if(elm.options[s].selected){
								if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array();
								obj[nm][obj[nm].length] = escape(elm.options[s].value);
							}	
						}
						break;
					
					case "radio":
						if(elm.checked){
							if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array();
							obj[nm][obj[nm].length] = escape(elm.value);
						}	
						break;
					
					case "checkbox":
						if(elm.checked){
							if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array();
							obj[nm][obj[nm].length] = escape(elm.value);
						}	
						break;
					
					default:
						if(typeof(obj[nm]) == 'undefined') obj[nm] = new Array();
						obj[nm][obj[nm].length] = escape(elm.value);
						break;
				}
			}
		}catch(e){}
	}
	for(x in obj) ar[ar.length] = x+'='+obj[x].join(',');
return ar.join('&');
}

function getquerystring(incoming) {
//alert(incoming);
var form = document.forms[incoming];
var word = form.word.value;
qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
//alert(qstr);
return qstr;
}

function updatepage(str,pinpoint,mynewlocation){
	//alert(pinpoint + " " + str);
	var rejax = "";
	var ajaxReturnFn = str.substring(str.indexOf('~*^')+3,str.indexOf('^*~'));
	//alert(ajaxReturnFn);
	if(ajaxReturnFn.split('^')[0] == 'alert'){
		//alert(ajaxReturnFn.split('^')[1]);
		str = str.replace('~*^'+ajaxReturnFn+'^*~',"");
	}else if(ajaxReturnFn.split('^')[0] == 'script'){
		eval(ajaxReturnFn.split('^')[1]);
		str = str.replace('~*^'+ajaxReturnFn+'^*~',"");
	}else if(ajaxReturnFn.split('^')[0] == 'replay'){
		rejax = ajaxReturnFn.split('^')[1];
		str = str.replace('~*^'+ajaxReturnFn+'^*~',"");
		//alert(rejax);
	}
	
	if(pinpoint){
		document.getElementById(pinpoint).innerHTML=str;
	} else {
		//alert("here");
		//document.getElementById("main_body").innerHTML = str;
	}
	//remember to trim this later dude!!!!!!!!!!!!!!!!!!!!!!
	if(rejax != ""){
		//alert('test');
		eval(rejax);
		//eval("enterObj("+rejax+")");	
		rejax = "";
	}
	
}