function drawEditor(sEditName,sHiddenName,sBase) {
	var oTextSrc=getElement(sHiddenName);
	var oEditor=getEditor(sEditName);
	if (oEditor) {
		oEditor.document.designMode="on";
		oEditor.document.open();
		oEditor.document.write('<html>\n<head>\n');
		oEditor.document.write('<base href="'+sBase+'">\n');
		oEditor.document.write('<link rel="stylesheet" type="text/css" href="admin/rted.css">\n');
		oEditor.document.write('</head>\n');
		oEditor.document.write('<body>\n');
		oEditor.document.write(oTextSrc.value);
		oEditor.document.write('\n</body>\n</html>');
		oEditor.document.close();
		oEditor.focus();
	}
}
function ex(sEditName,cmd,val) {

	var oEditor=getEditor(sEditName);
	if (oEditor!=null) {
		if (document.selection){
			if (oEditor.document.selection.type=="Control") {		
				crange=oEditor.document.selection.createRange();
				obj=crange.item(0);
				if (obj.tagName=="IMG" || obj.tagName=="TABLE") {
					if (cmd=="justifyleft")   obj.align="left";
					if (cmd=="justifyright")  obj.align="right";
					if (cmd=="justifycenter") obj.align="center";
				}
			}
			else {
				if (val==null)
					oEditor.document.execCommand(cmd);
				else				
					oEditor.document.execCommand(cmd,"",val);
						
				oEditor.focus();
			}
		} else {
			oEditor.document.execCommand(cmd, false, null); 
		}
	}
}
function createLink(sEditName) {
	var oEditor=getEditor(sEditName);
	if (oEditor!=null){
		if ( document.selection)
			oEditor.document.execCommand("createLink",true,null);
		else
			alert("This option is only available in Internet Explorer");
	}
}
function applyParaStyle(sEditName, style) {	
	var oEditor=getEditor(sEditName);
	
	if (oEditor!=null) {
		if (document.selection && document.selection.createRange) {					
			
			range=oEditor.document.selection.createRange();
			seltext=range.text;			
			ele=range.parentElement();
			
		// FIND CONTAINING PARAGRAPH (HOPEFULLY)
			while (ele.tagName!="P" && ele.tagName!="BODY") {												
					ele=ele.parentElement;
			}	
			
			if ( ele ){
				if ( ele.tagName=="P" ) 
					ele.className=style;
				else 				
					range.pasteHTML("<p class=\"" +style + "\">" + seltext + "</p>");					
			} else {
				alert("This style can only be applied to a paragraph or single text line");
			} 
		} else 	{
			if (oEditor.document.getSelection()) {			
				alert("This option is only available in Internet Explorer");
			}			
		}	
	}
}
function saveRTF(sEditName,sHiddenName) {
	var oTextSrc=getElement(sHiddenName);
	var oEditor=getEditor(sEditName);
	if (oTextSrc!=null && oEditor!=null)
		oTextSrc.value=oEditor.document.body.innerHTML;
}
function getTextRTF(sEditName) {
	var sText="";
	var oEditor=getEditor(sEditName);
	if (oEditor!=null) {
		var sText=oEditor.document.body.innerHTML;
		if (sText=="<P>&nbsp;</P>" || sText=="<P class=subtitle>&nbsp;</P>") sText="";
		else if (sText.replace(/\r\n/g,"")=="<br>") sText="";
	}
	return sText;
}
function getEditor(sEditName) {
	return window.frames[sEditName];
}
// FORM VALIDATION STUFF
var bFormValid=true;
function resetValidate() {
	bFormValid=true;
}
function showErrorMessage(sMsg) {
	if (bFormValid) {
		bFormValid=false;
		alert(sMsg);
	}
}
function isNumeric(sName) {
	var sVal=getElement(sName).value;
	var re=/(^\d+$)|(^\d+\.\d+$)/;
	return (re.test(sVal));
}
function isInteger(sName) {
	var sVal=getElement(sName).value;
	var re=/(^\d+$)/;
	return (re.test(sVal));
}
function isPrice(sName) {
	var sVal=getElement(sName).value;
	var re=/(^\d+$)|(^\d+\.\d\d$)/;
	return (re.test(sVal));
}
function isDate(sNameDD,sNameMM,sNameYYYY,bRequired) {
	var bValid=false;
	var DD=getElement(sNameDD).value;
	var MM=getElement(sNameMM).value;
	var YYYY=getElement(sNameYYYY).value;
	
	if (!bRequired && DD.length==0 && MM.length==0 && YYYY.length==0)
		bValid=true;
	else {
		if (DD.length==2 && MM.length==2 && YYYY.length==4) {
			MM=(1*MM)-1;
			var dateTest=new Date(YYYY,MM,DD);
			if (dateTest.getDate()==DD && dateTest.getMonth()==MM && dateTest.getFullYear()==YYYY)
				bValid=true;
		}
	}
	return bValid;
}
String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");
String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
