
document.write('<script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/yahoo/yahoo-min.js"></script>');  
document.write('<script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/event/event-min.js"></script>');  
document.write('<script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/connection/connection-min.js"></script>');

var IFrameObj;  

function detectNeedForAjaxAlternate()
{
	needAlternate = 0;
	if (!window.XMLHttpRequest)
	{
		needAlternate=1;
		if(window.ActiveXObject)
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (!xmlhttp)
					xmlhttp = new ActiveXObject("Mscml2.XMLHTTP");

				if (xmlhttp)
					needAlternate=0;
			}
			catch(e)
			{
			}
		}
	}
	return needAlternate;
}

function ajaxCavez(strPHP, callback, aNames, aData) 
{
	var method = "GET";
	if (arguments.length == 5)
		method = arguments[4];
		
	// Get size of arrays
	var szArray = aNames.length;
	if (szArray != aData.length)
	{
		alert ("Names and Data arrays passed to ajaxCavez() are of different sizes!  Ajax call ignored.");
		return;
	}

	// Figure out which mode
	mode = 1 - detectNeedForAjaxAlternate();

	s = new String( callback );
	// Extract function name and argument list
	var r = /\s*function\s*(\w+)([^\{\}]*\))/;
	var retval = r.exec( s );
	var strCallback = new String( RegExp.$1 );
	//MCP: Below - Bug fix - Javascript RegExp object is global, so strCallback can have spurious results if the exec() fails to match
	if (retval === null)
		strCallback = "";

	var URL = strPHP + "?";
	
	if (method == "POST")
		URL += "ajaxCavezMethod=POST&";
	
	if (mode == 0)
		URL += "callback=" + strCallback;
	else
		URL += "mode=1";
	for (i=0; i<szArray; i++)
		URL += "&" + escape(aNames[i]) + "=" + escape(aData[i]);
	URL += "&rnd=" + (new Date()).getTime();

	if (mode == 0)
		iFrameCall(URL);
	else
		jsCall(URL, callback, method);
}

// Function below is similar to ajaxCavez, but forces it to 
//  use the old-style IFrame method, since the XMLHttpRequest method
//  screws up file uploads
function ajaxCavezIFrame(strPHP, callback, aNames, aData) 
{
	// Get size of arrays
	var szArray = aNames.length;
	if (szArray != aData.length)
	{
		alert ("Names and Data arrays passed to ajaxCavez() are of different sizes!  Ajax call ignored.");
		return;
	}

	s = new String( callback );
	// Extract function name and argument list
	var r = /\s*function\s*(\w+)([^\{\}]*\))/;
	var retval = r.exec( s );
	var strCallback = new String( RegExp.$1 );
	//MCP: Below - Bug fix - Javascript RegExp object is global, so strCallback can have spurious results if the exec() fails to match
	if (retval === null)
		strCallback = "";

	var URL = strPHP + "?";
	URL += "callback=" + strCallback;
	for (i=0; i<szArray; i++)
		URL += "&" + escape(aNames[i]) + "=" + escape(aData[i]);
	URL += "&rnd=" + (new Date()).getTime();

	iFrameCall(URL);
}


function jsCall(strURL, callbackFunc, method)
{
	var callback = { };
	if (callbackFunc != 0)
		callback = 
			{
			  success:callbackFunc
			};

	if (method == "GET") {
		var request = YAHOO.util.Connect.asyncRequest('GET', strURL, callback);
	}
	else {
		var request = YAHOO.util.Connect.asyncRequest('POST', strURL.substring(0, strURL.indexOf('?')), callback, strURL.substring(strURL.indexOf('?')+1));
	}
}

function iFrameCall(URL)
{
	if (!document.createElement) {return true};

	var IFrameDoc;

	if (!IFrameObj && document.createElement) {
		// create the IFrame and assign a reference to the
		// object to our global variable IFrameObj.
		// this will only happen the first time 
		// iFrameCall() is called
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				// this is for IE5 Mac, because it will only
				// allow access to the document object
				// of the IFrame if we access it through
				// the document.frames array
				IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			// This is for IE5 PC, which does not allow dynamic creation
			// and manipulation of an iframe object. Instead, we'll fake
			// it up by creating our own objects.
			iframeHTML='<iframe id="RSIFrame" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout('iFrameCall(URL)',10);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	
	IFrameDoc.location.replace(URL);
	return false;
}

function getXML(str, name)
{
	iStart = str.indexOf('<' + name + '>');
	iStop = str.indexOf('</' + name + '>');
	if (iStart < 0  ||  iStop < 0  ||  iStart+1 == iStop)
		return '';
	return unescape(str.substring(iStart+1+name.length+1, iStop));
}


