// Copyright © 2005-2006 Water Street Web Solutions, LLC.  All rights reserved. --
// ----------------------------------------------------------------------------------
// Water Street Web Solutions (WSWS) software and code [both binary and source 
// (if released)] (Software) is intellectual property owned by WSWS and is copyright 
// of WSWS in all countries in the world, and ownership remains with WSWS.
//
// You (Licensee) may use the WSWS Software and install it only in accordance with 
// use and licensing agreements you have signed with WSWS.  Licenses are distributed 
// only by WSWS. Please send an email to info@waterstreetusa.com for more information.
//
// If you do not have a valid signed license agreement, you may not use, copy or
// distribute the Software for any purpose.
//
// This copyright notice may not be removed or altered or it will constitute a
// violation of any license agreements.
// ----------------------------------------------------------------------------------

function GetRequestObject()
{
	xmlhttp = false;
	// code for Mozilla, IE7, etc.
	if (window.XMLHttpRequest)
	{
		try
		{
			//alert('AJAX using XMLHttpRequest');
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;		
		}
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		try
		{
			//alert('AJAX using window.ActiveXObject Msxml2.XMLHTTP');
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				//alert('AJAX using window.ActiveXObject Microsoft.XMLHTTP');
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				xmlhttp = false;
			}
		}
	}
	if (!xmlhttp) alert('Failed to get XML HTTP Request object. Your browser does not support the features needed for this operation.');
	return xmlhttp;
}
function ReleaseRequestObject(xmlhttp)
{
	// this method may not really be necessary, but provides a useful hook
	if (xmlhttp)
	{
		//DisplayXmlHttpInfo(xmlhttp); // debug:: display some info
		xmlhttp.abort(); // ensure the action is complete
	}	
	xmlhttp = null; // ensure it's vanquished
	
}
function ExecuteHttpPost(xmlhttp, url, args)
{
	xmlhttp.open("POST", url, false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send(args);
}
function DisplayXmlHttpInfo(xmlhttp)
{
	alert("The oject:  " + xmlhttp);
	if (xmlhttp)
	{
		if (xmlhttp.readyState != null)
			alert("readyState: " + xmlhttp.readyState);
		else
			alert("readyState is null");

		if (xmlhttp.readyState != 0)
		{
			if (xmlhttp.status != null)
				alert("status: " + xmlhttp.status);
			else
				alert("status is null");

			if (xmlhttp.statusText != null)
				alert("statusText: " + xmlhttp.statusText);
			else
				alert("statusText is null");

			if (xmlhttp.responseText != null)
				alert("responseText: " + xmlhttp.responseText);
			else
				alert("responseText is null");

			if (xmlhttp.responseXML != null)
				alert("responseXML: " + xmlhttp.responseXML);
			else
				alert("responseXML is null");
		}
		else
		{
			alert("XMLHTTP is not yet initialized.");
		}
	}
	else
	{
		alert("XmlHTTP object is not valid.");
	}
}


function RegExEscape(text)
{
	if (!arguments.callee.sRE)
	{
		var specials = [
			'/', '.', '*', '+', '?', '|',
			'(', ')', '[', ']', '{', '}', '\\'
			];
		arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
	}
	return text.replace(arguments.callee.sRE, '\\$1');
}

function UpdateEncodedUrl(oldUrl, oldText, newText)
{
	alert(oldUrl);
}
function ReplaceString(input, oldText, newText)
{
//	alert("input=" + input);
//	alert("old=" + oldText);
//	alert("new=" + newText);
//	alert("escaped=" + RegExEscape(oldText));
	var re = new RegExp(RegExEscape(oldText), "gi");
	newstr = input.replace(re, newText);
//	alert("result=" + newstr);
	return newstr;
}
function SetClipboardText(clipboardtext)
{
	if (window.clipboardData) //For IE so muc easier than mozilla
	{
		window.clipboardData.setData("Text", clipboardtext);
	}
	else if (window.netscape) 
	{ 
		alert("not ie");
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		alert("1");

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		alert("1");

		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=clipboardtext;

		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		
		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("The URL: '" + clipboardtext + "' was copied to the clipboard");
}
function UrlEncode(input)
{
		if (window.encodeURIComponent) 
				return encodeURIComponent(input); 
		else if (window.escape) 
				return escape(input);
	
		return input;
}
function UrlDecode(input)
{
		if (window.decodeURIComponent) 
				return decodeURIComponent(input); 
		else if (window.unescape) 
				return unescape(input);
	
		return input;
}