// javascript library for CLGE/GE website

/** void submitForm(action)
 * sets form's action attribute to action
 * and submits form
 */
function submitForm(action, formID) {

	var form = false;
	if (formID) {
		form = document.getElementById(formID);
	}
	else {
		form = document.forms[0];
	}

	if (form) {
		form.action = action;
		if (typeof(myEditor) == 'object') {
			//alert(typeof(myEditor));
			myEditor.saveHTML();
		}
		form.submit();
	}
	else {
		alert('submit failed');
	}

}

/** void confirmSubmit()
 * asks for confirmation (with text).
 * If positive sets form's action attribute to action
 * and submits form
 * does nothing otherwise
 */
function confirmSubmit(action, text, formID) {

	if(window.confirm(text)) {

		var form = document.forms[0];
		form.action = action;
		form.submit();
	}

}

/** void uncheckAll()
 * unchecks all checkboxes
 */
function uncheckAll() {
	//window.alert('klik');
	chkboxes = document.getElementsByName('items[]');
	for (var i = 0; i < chkboxes.length; i++) {
		//window.alert(i)
		chkboxes[i].checked = false;
	};
}

/** void addFile()
 * adds a type file input element into parent element
 */
function addFile(id, e) {
	var source;
	if (e.srcElement) {
		source = e.srcElement;
	}
	else if (e.target) {
		source = e.target;
	}

	if (source.tagName == 'IMG') {
		source = source.parentNode;
	}

	source.innerHTML = "<input type=\"file\" name=\"" + id + "\" />";
	source.onclick = "";
}
