function CreateXMLHttp()
{
	xmlhttp = false;

	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest)
	{
		try
		{
			xmlhttp = window.createRequest();
		}
		catch (e)
		{
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function EraseOptions(sFormField)
{
	if (sFormField.options)
	{
		for(i = sFormField.options.length-1; i >= 0; --i)
		{
			sFormField.options[i]=null;
		}
	}
}

function Show(sRow)
{
	var oRow = document.getElementById(sRow);

	try
	{
	  oRow.style.display="table";
	}
	catch(e)
	{
	  oRow.style.display = "block";
	}
}

function ShowBlock(sID)
{
	var oRow = document.getElementById(sID);
	oRow.style.display = "block";
}

function Hide(sRow)
{
	var oRow = document.getElementById(sRow);
	oRow.style.display="none";
}

Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
	var i;
	for (i=0; i < this.length; ++i) 
	{
		if (this[i] == value)
		{
			return true;
		}
	}
	return false;
};

function UpdateContent(sContent, sTargetDiv)
{
	var oDiv = document.getElementById(sTargetDiv);
	oDiv.innerHTML = sContent;
	
	SetTextareas();
}

function ClearMessageDiv()
{
	oMessage = document.getElementById('message_div');
	if (oMessage)
	{
		oMessage.className = "";
		oMessage.innerHTML = '<br style="clear: both; line-height: 3.6em;" />';
	}
}

function SetTextareas()
{
	document.getElementsByClassName( 'replace-with-zeditor', 'TEXTAREA' ).each
	( 
		function( oValue, iIdx ) 
		{
			aEditors.push
			( 
				new ZEditor
				(
					oValue,
					{
						iWidth: oValue.offsetWidth + 'px',
						iHeight: oValue.offsetHeight + 'px',
						sFileBrowserUrl: ( window.location.toString().match( /zincastle/i ) || window.location.toString().match( /zssweb/i ) ? ZEditorParams.Development.sFileBrowserUrl : ZEditorParams.Live.sFileBrowserUrl ),
						sFileDir: ( window.location.toString().match( /zincastle/i ) || window.location.toString().match( /zssweb/i ) ? ZEditorParams.Development.sFileDir : ZEditorParams.Live.sFileDir ),
						sImageBrowserUrl: ( window.location.toString().match( /zincastle/i ) || window.location.toString().match( /zssweb/i ) ? ZEditorParams.Development.sImageBrowserUrl : ZEditorParams.Live.sImageBrowserUrl ),
						sImageDir: ( window.location.toString().match( /zincastle/i ) || window.location.toString().match( /zssweb/i ) ? ZEditorParams.Development.sImageDir : ZEditorParams.Live.sImageDir ),
						sUploadUrl: ( window.location.toString().match( /zincastle/i ) || window.location.toString().match( /zssweb/i ) ? ZEditorParams.Development.sUploadUrl : ZEditorParams.Live.sUploadUrl )
					}
				)
			);
			Event.observe(
				oValue,
				'keydown',
				function( oEvent )
				{
					if( oEvent.keyCode == Event.KEY_TAB )
					{
						Event.stop( oEvent );
						var oTextArea = this;
						Try.these(
							function()
							{
								document.selection.createRange().text = '\t';
							},
							function()
							{
								new ZSelection( oTextArea ).replaceSelectedText( '\t' );
								oTextArea.selectionStart = oTextArea.selectionEnd;
							},
							function()
							{
								alert( 'Unsupported browser!' );
							}
						);
					}
				}.bindAsEventListener( oValue ),
				false
			);
		} 
	);
}