// Insert any javascript here
function emptyField(id, value) {
	
	// Empty the fields
	var currentValue = document.getElementById(id).value;
	if (!currentValue) {
		document.getElementById(id).value = value;
	} else if (currentValue == value) {
		document.getElementById(id).value = "";
	}
	
}

function confirmDelete(message, location) {

	var check;
	check = confirm(message);
	if (check) {
		window.location=location;	
	}

}

// Do they really want to submit the form?
function confirmSubmit(message, formID) {
	
	var check;
	check = confirm(message);
	if (check) {
		return true;
		//document.getElementById(formID).submit();
	} else {
		return false;
	}
	
	return false;
	
}

// Taken from http://www.dustindiaz.com/getelementsbyclass
function getElementsByClass(searchClass, node, tag) {
	
	var classElements = new Array();
	if (node == null) {
		node = document;
	}
	if (tag == null) {
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
	
}

function toggleSection(id, amount) {
	
	for (var count=0; count<amount; count++) {
		
		if (count == id) {
			var currentDisplay = document.getElementById("section-" + id + "-operations").style.display;
			if (currentDisplay != "block") {
				document.getElementById("section-" + id + "-operations").style.display = "none";
				document.getElementById("section-" + id + "-operations").style.display = "block";
			} else {
				document.getElementById("section-" + id + "-operations").style.display = "none";
			}
		} else {
			if (document.getElementById("section-" + count + "-operations")) {
				document.getElementById("section-" + count + "-operations").style.display = "none";
			}
		}
	
	}
	
}

function help(id) {
	
	var help_message = document.getElementById('cms-help-' + id).style.display;
	if (help_message != "block") {
		document.getElementById('cms-help-' + id).style.display = "block";
		document.getElementById('cms-help-icon-' + id).className = "cms-help-icon-selected";
	} else {
		document.getElementById('cms-help-' + id).style.display = "none";
		document.getElementById('cms-help-icon-' + id).className = "cms-help-icon";
	}
	
}

