function getKeyCode(event) {
	return event.keyCode?event.keyCode:event.which?event.which:event.charCode;
}
function isEnter(event) {
	return (getKeyCode(event) == 13);
}
function get_object(o) {
	if (document.getElementById && document.getElementById(o) != null)
		return document.getElementById(o);
	else if (document.layers && document.layers[object] != null)
		return document.layers[o];
	else if (document.all)
		return document.all[o];
}
function isJpg(value) {
	var valueLCase=value.toLowerCase();
	return value.match('.jpg$');
}
function doOnload() {
	if (window.doOnload_extended)
		doOnload_extended();
	if (window.menuOnLoad)
		menuOnLoad();
}
function getCheckedRadioValue(theRadio) {
	var considerDisabled=(getCheckedRadioValue.arguments[1]);
	if (theRadio[1]) {
		for (i=0;i<theRadio.length;i++) {
			if (theRadio[i].checked && (!considerDisabled || (considerDisabled && !theRadio[i].disabled)))
				return theRadio[i].value;
		}
	} else {//single element (possible hidden)
		return theRadio.value;
	}
	return '';
}
function getCheckedValues(theCheckbox) {
	if (getCheckedValues.arguments[1])
		theReturnType=getCheckedValues.arguments[1];
	else
		theReturnType='list';
	switch (theReturnType) {
		case 'list'://returns a list with the checked values
			var theList='';
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked) {
						if (theList.length > 0)
							theList=theList+',';
						theList=theList+theCheckbox[i].value;
					}
				}
			else if (theCheckbox.checked)
				theList=theCheckbox.value;
			return theList;
		break;
		case 'array'://returns an array with the checked values
			var theArray=new Array();
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked)
						theArray.push(theCheckbox[i].value);
				}
			else if (theCheckbox.checked)
				theArray.push(theCheckbox.value);
			return theArray;
		break;
		case 'count'://returns number of checked items
			var checkedCount=0;
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked)
						checkedCount++;
				}
			else if (theCheckbox.checked)
				checkedCount++;
			return checkedCount;
		break;
		case 'boolean'://returns if any is checked
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked) {
						return true;
						break;
					}
				}
			else if (theCheckbox.checked)
				return true;
		break;
		case 'indexList'://returns list with the checked indexes
			var theList='';
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked) {
						if (theList.length > 0)
							theList=theList+',';
						theList=theList+''+i;
					}
				}
			else if (theCheckbox.checked)
				theList=-1;
			return theList;
		break;
	}
	return false;
}
function LTrim(value) {
	var re=/\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
function RTrim(value) {
	var re=/((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
function trim(value) {
	return LTrim(RTrim(value));
}
function isValid(type,value) {
	switch (type) {
		case 'email':
			var lCaseValue=value.toLowerCase();
			return lCaseValue.match(/^[\_]*([a-z0-9]+(\.|\_*|\-*)?)+@([a-z][a-z0-9\-\.]+(\.|\-*\.))+[a-z]{2,6}$/);
		break;
		case 'webImage':
			var re=/.jpg$/i;
			if (re.test(value))
				return true;
			var re=/.jpeg$/i;
			if (re.test(value))
				return true;
			var re=/.gif$/i;
			if (re.test(value))
				return true;
			var re=/.png$/i;
			if (re.test(value))
				return true;
			return false;
		break;
		case 'swf':
			var re=/.swf$/i;
			if (re.test(value))
				return true;
			return false;
		break;
	}
	return false;
}
function loadXML(label,url) {
	XMLRequestTypeInProcess=(loadXML.arguments[2])?loadXML.arguments[2]:'xml';//probably 'text' if not 'xml';
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		eval('XMLRequest_'+label+'=new XMLHttpRequest();');
		var XMLRequest=eval('XMLRequest_'+label);
		XMLRequest.open("GET",url,true);
		XMLRequestLabelInProcess=label;
		XMLRequest.onreadystatechange=processXML;
		XMLRequest.send(null);
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		eval('XMLRequest_'+label+'=new ActiveXObject("Microsoft.XMLHTTP");');
		var XMLRequest=eval('XMLRequest_'+label);
		if (XMLRequest) {
			XMLRequest.open("GET",url,true);
			XMLRequestLabelInProcess=label;
			XMLRequest.onreadystatechange=processXML;
			XMLRequest.send();
		}
	}
}
function processXML() {
	var theRequest=eval('XMLRequest_'+XMLRequestLabelInProcess);
	// only if req shows "complete"
	if (theRequest.readyState == 4) {
		// only if "OK"
		if (theRequest.status == 200) {
			response=(XMLRequestTypeInProcess == 'xml')?theRequest.responseXML.documentElement:theRequest.responseText;
			eval('popXML_'+XMLRequestLabelInProcess+'(response);');
		}
	}
}
function setTinymceEditor(editorCount,action) {
	var debug=false;
	if (setTinymceEditor.arguments[2])
		var value=setTinymceEditor.arguments[2];
	if (debug) { get_object('debug').innerHTML+='<br>setTinymceEditor('+editorCount+','+action+','+value+')'; }
	for (var i=0;i<editorCount;i++) {
		try {
			switch (action) {
				case 'width':
					get_object('mce_editor_'+i).style.width=value+'px';
				break;
				case 'bgColor':
					tinyMCE.getInstanceById('mce_editor_'+i).contentDocument.body.style.backgroundColor=value;
//					tinyMCE.getInstanceById('mce_editor_'+i).getWin().document.body.style.backgroundColor=value;
				break;
				case 'css':
					setTimeout("tinyMCE.execCommand('mceRemoveControl',false,'editorId')",i);
					initializeTinyMCE(value);
					setTimeout("tinyMCE.execCommand('mceAddControl',false,'editorId')",i);
				break;
				case 'blur':
					value.focus();
					value.blur();
				break;
			}
		}
		catch (err) {
			if (debug) { alert(err); }
		}
	}
}

