//#########################################################################################
//# Copyright (C) 2006 StopDog, Inc. All Rights Reserved.
//# Author        : Scott Wilfong (swilfong@exodusweb.com)
//# Inception     : January 14, 2008
//# Contributers  : ???
//#////////////////////////////////////////////////////////////////////////////////////////
//# Change Log
//#    2006-10-02 > by Scott Wilfong
//#               >  
//#########################################################################################
	//******************************************************************************//
	//* Usage       : AjaxURL();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : URLs outside of this site
	//******************************************************************************//
	function AjaxURL(url){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
//		MyAjaxEngine._is_async = false;
		
		//to store the return value from the ajax call
		var successfulCall = true;
		
		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.abort();
				}
			};
		//end handling interactive

		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
/*					var searching = document.$('scanning');
					var warning = document.$('warning');
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						searching.style.display = "none";
						document.$('warning_link').href = "http://" + url;
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
						grayOut(false,'');
*/
						window.open("http://" + response.text,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
//					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			//gray out the screen
//			grayOut(true,{'opacity':'20'});

			//call the aspx page with the parameters
			url = url.toString().replace("http://","");
			MyAjaxEngine.post("/url.aspx?r=ajax_article", "u="+URLEncode(url));

//			//if we had success let's turn off the gray screen
//			if(successfulCall) grayOut(false);

			return false;
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : DMOZAjaxArticle();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : DMOZ articles
	//******************************************************************************//
	function DMOZAjaxArticle(url){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		MyAjaxEngine._is_async = false;
		
		//to store the return value from the ajax call
		var successfulCall = true;
		var startTime = (new Date()).getTime();
		
		//short cuts for the dialogs
		var searching = document.$('scanning');
		var warning = document.$('warning');

		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
				var currentTime = (new Date()).getTime();
/*				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.abort();
					window.open("http://" + url,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
				}
*/
			};
		//end handling interactive
		
		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
/*					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
						var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;

						searching.style.display = "none";
						document.$('warning_link').href = "http://" + url;
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
						successfulCall = false;
						//grayOut(false);
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
						//grayOut(false);
*/
//						window.open("http://" + response.text,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
//					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			//gray out the screen
//			grayOut(true,{'opacity':'20'});

			//call the aspx page with the parameters
			url = url.toString().replace("http://","");

			//execute the request
			MyAjaxEngine.post("/dmoz.aspx?r=ajax_article", "u="+URLEncode(url));

			//if we had success let's turn off the gray screen
//			if(successfulCall) grayOut(false);

			//return true/false based on the success returned from the request
			return true;//successfulCall;
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : ThesaurusAjaxArticle();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : thesaurus articles
	//******************************************************************************//
	function ThesaurusAjaxArticle(word, query){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		
		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	
		
		//begin handling interactive
			MyAjaxEngine.interactive = function() {
/*				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.abort();
				}
*/
			};
		//end handling interactive

		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
/*					var searching = document.$('scanning');
					var warning = document.$('warning');
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						searching.style.display = "none";
						document.$('warning_link').href = "/thesaurus/" + word;
						document.$('warning_link').target = "";
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
*/
						window.location.href = response.text;
//					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			
			//call the aspx page with the parameters
			MyAjaxEngine.post("/thesaurus.aspx?r=ajax_article", "w="+word);
			return false;
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : WikipediaAjaxArticle();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : wikipedia articles
	//******************************************************************************//

	function WikipediaAjaxArticle(articleName, query){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		
		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
/*				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.complete = function(){};
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					document.$('timeout').style.top = top + "px";
					document.$('timeout').style.left = left + "px";
					document.$('scanning').style.display = "none";
					document.$('timeout').style.display = "block";
					MyAjaxEngine.abort();
				}
*/
			};
		//end handling interactive
		
		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()){
/*					var searching = document.$('scanning');
					var warning = document.$('warning');
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						searching.style.display = "none";
						document.$('warning_link').href = response.text;
						document.$('warning_link').target = "";
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
*/
						window.location.href = response.text;
//					}
//					clearTimeout(sto);
				}
				else {
					var ErrorWindow = window.open('','Error','location=yes,status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request

		//call the aspx page with the parameters
			MyAjaxEngine.post("/wikipedia.aspx?r=ajax_article", "a="+articleName);
			return false;	
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : WiktionaryAjaxArticle();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : wiktionary articles
	//******************************************************************************//
	function WiktionaryAjaxArticle(articleName, query){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		
		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
/*				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.complete = function(){};
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					document.$('timeout').style.top = top + "px";
					document.$('timeout').style.left = left + "px";
					document.$('scanning').style.display = "none";
					document.$('timeout').style.display = "block";
					MyAjaxEngine.abort();
				}
*/
			};
		//end handling interactive
		
		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
/*					var searching = document.$('scanning');
					var warning = document.$('warning');
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						searching.style.display = "none";
						document.$('warning_link').href = response.text;
						document.$('warning_link').target = "";
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
*/
						window.location.href = response.text;
//					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			
			//call the aspx page with the parameters
			MyAjaxEngine.post("/wiktionary.aspx?r=ajax_article", "a="+articleName);
			return false;
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : StopDogAjaxArticle();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : StopDog articles
	//******************************************************************************//
	function StopDogAjaxArticle(url){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		MyAjaxEngine._is_async = false;
		
		//to store the return value from the ajax call
		var successfulCall = true;
		
		//shortcut variables for dialogs
		var searching = document.$('scanning');
		var warning = document.$('warning');

		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
/*				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.complete = function(){};
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					document.$('timeout').style.top = top + "px";
					document.$('timeout').style.left = left + "px";
					document.$('scanning').style.display = "none";
					document.$('timeout').style.display = "block";
					MyAjaxEngine.abort();
				}
*/
			};
		//end handling interactive
		
		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
/*					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						searching.style.display = "none";
						document.$('warning_link').href = "http://" + url;
						warning.style.display = "block";
						warning.style.top = top + "px";
						warning.style.left = left + "px";
						successfulCall = false;
					}
					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						warning.style.display = "none";
						searching.style.display = "block";
						grayOut(false,{'opacity':'20'});
*/
//						window.open(response.text,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
//					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			//gray out the screen
//			grayOut(true,{'opacity':'20'});

			//call the aspx page with the parameters
			url = url.toString().replace("http://","");

			//execute the request
			MyAjaxEngine.post("/stopdog.aspx?r=ajax_article", "u="+URLEncode(url));

			//if we had success let's turn off the gray screen
//			if(successfulCall) grayOut(false);

			//return true/false based on the success returned from the request
			return successfulCall;
		//end execute request	
	}

	//******************************************************************************//
	//* Usage       : AjaxSearch();
	//* Purpose     : This script handles the ajax request for retreiving/filtering
	//*             : search results
	//******************************************************************************//
	function AjaxSearch(url, type){
		//create ajax object
		var MyAjaxEngine = new powerHTTP();
		
		var startTime = (new Date()).getTime();
		
		//begin handling loading
			MyAjaxEngine.loading = function() {
			};
		//end handling loading	

		//begin handling interactive
			MyAjaxEngine.interactive = function() {
/*				var currentTime = (new Date()).getTime();
				if(currentTime - startTime > 10000){
					MyAjaxEngine.onreadystatechange = function(){};
					MyAjaxEngine.complete = function(){};
					var top = Math.round(document.getWindowHeight() / 2) + document.getScrolledY() - 175;
					var left = Math.round(document.getWindowWidth() / 2) + document.getScrolledX() - 225;
					document.$('timeout').style.top = top + "px";
					document.$('timeout').style.left = left + "px";
					document.$('scanning').style.display = "none";
					document.$('timeout').style.display = "block";
					MyAjaxEngine.abort();
				}
*/
			};
		//end handling interactive
		
		//begin handling response
			MyAjaxEngine.complete = function(response) {
				if(MyAjaxEngine.was_successful()) {
					var searching = document.$('scanning');
					var warning = document.$('warning');

					if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'failure'){
						window.location.href = "/search_denied?s=" + type + "&q=" + response.text;
					}
					else if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'redirect'){
						var RedirectUrl = MyAjaxEngine.get_response_header("X-WebLegs-Data")
						window.location.href = RedirectUrl;
					}
					else if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'keyword_mod'){
						var NewKeyword = MyAjaxEngine.get_response_header("X-WebLegs-Data")
						window.location.href = "/search?s=" + type + "&q=" + NewKeyword;
					}
					else if(MyAjaxEngine.get_response_header("X-WebLegs-Action") == 'success'){
						window.location.href = "/search?s=" + type + "&q=" + response.text;
					}
				}
				else {
					var ErrorWindow = window.open('','Error','status=no,scrollbars=yes,resizable=yes,width=640,height=480');
					ErrorWindow.document.write(response.text);
				}
			};
		//end handling response		
		
		//begin execute request
			//call the aspx page with the parameters
			MyAjaxEngine.post("/search?r=ajax_search&q="+URLEncode(url), "");
			return false;
		//end execute request	
	}

	//******************************************************************************//
	
	function URLEncode(clearString) {
		var output = '';
		var x = 0;
		clearString = clearString.toString();
		var regex = /(^[a-zA-Z0-9_.]*)/;
		while (x < clearString.length) {
			var match = regex.exec(clearString.substr(x));
			if (match != null && match.length > 1 && match[1] != '') {
				output += match[1];
				x += match[1].length;
			} else {
				if (clearString[x] == ' ')
					output += '+';
				else {
					var charCode = clearString.charCodeAt(x);
					var hexVal = charCode.toString(16);
					output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
				}
				x++;
			}
		}
		return output;
	}
	

//#########################################################################################
//# Copyright (C) 2006 StopDog, Inc. All Rights Reserved.
//#########################################################################################