var isIE = false;

if(navigator.appName.toUpperCase() == "MICROSOFT INTERNET EXPLORER")
{
	var MSIEPos = navigator.appVersion.toUpperCase().indexOf('MSIE');
	var MSIEVersion = parseFloat(navigator.appVersion.substring(MSIEPos + 5, navigator.appVersion.indexOf(';', MSIEPos)));
	
	if (MSIEVersion >= 5)
	{
		isIE = true;
	}
}

//detect and redirect old browsers
if (!document.getElementById)
{
    //window.location.href = "http://www.webstandards.org/upgrade/";
}


function EditHTMLField(FieldRef)
{
	if (isIE)
	{
		status = 'Loading content editor.....';
		//alert("IE version " + MSIEVersion + " detected!");

		var tmpObj = new Object();
		tmpObj.code = FieldRef.value;
		
		var returnVal = window.showModalDialog("HTMLEditor/HTMLEditor.htm",tmpObj,"dialogWidth:700px; dialogHeight:500px;help:no;")
		
		if (returnVal!=null)
		{
			FieldRef.value = returnVal;
			status = 'Content saved to form.';
			//DataChanged();
			
			var Butt = document.getElementById("_action_Save");
			Butt.click();
		}
		else
		{
			status = 'Content left unchanged.';
		}
	}
	else
	{
		alert("Support for < IE5 not added yet");
	}
}

	
function ColourPicker(curValue)
{
	if (isIE)
	{
		var FieldObj = new Object();
		FieldObj.value = curValue;
		
		status = 'Loading colour picker.....';
		var returnVal = showModalDialog("HTMLEditor/selcolor.htm", FieldObj, "dialogWidth:400px; dialogHeight:500px;help:yes;");
		
		if((returnVal != '') && (returnVal != null))
		{
			returnVal = returnVal.toUpperCase();
			status = 'Field updated with chosen colour.';
			return returnVal;
			//FieldObj.style.backgroundColor = returnVal;
			//FieldObj.style.layer-background-color = returnVal;
			
			//DataChanged();
			
			//var Butt = document.getElementById("ButtonSave");
			//Butt.click();
		}
		else
		{
			return curValue;
			status = 'Field left unchanged.';
		}
	}
	else
	{
		alert("Support for < IE5 not added yet");
	}
}

function DataChanged()
{
	var Butt;
	
	Butt = document.all("ButtonSave");
	if (Butt != null)
	{
		Butt.disabled = false;
	}
	
	Butt = document.all("ButtonReload");
	if (Butt != null)
	{
		Butt.disabled = false;
	}
	
	status = "Data has changed. Remember to save your changes!";
}