// This file is part of Tasks
// Copyright (c) 2002-2007 Alex King, Crowd Favorite, Ltd.
// see LICENSE.txt for more information

// General Functions

function toggleDiv(divName) {
	thisDiv = document.getElementById(divName);
	if (thisDiv) {
		if (thisDiv.offsetHeight > 0 || thisDiv.style.display == "block") {
			thisDiv.style.display = "none";
		}
		else {
			thisDiv.style.display = "block";
		}
	}
}

function toggleCheckbox(thisCheckbox) {
	thisCheckbox.checked = !(thisCheckbox.checked);
}

function toggleCheckboxById(thisCheckbox) {
	document.getElementById(thisCheckbox).checked = !(document.getElementById(thisCheckbox).checked);
}

function toggleCheckboxValue(thisCheckbox, thisValue) {
	for (i = 0; i < thisCheckbox.length; $i++) {
		if (thisCheckbox[i].value == thisValue) {
			thisCheckbox.checked = !(thisCheckbox.checked);
		}
	}
}

function setSelectedRadioButton(radioArray, radioValue) {
	for (i = 0; radioArray[i]; i++) {
		if (radioArray[i].value == radioValue) {
			radioArray[i].checked = true;
		}
	}
}

function getSelectedRadioButton(radioArray) {
	for (i = 0; radioArray[i]; i++) {
		if (radioArray[i].checked == true) {
			return radioArray[i].value;
		}
	}
	return false;
}

function setSelectToValue(thisSelect, thisValue) {
	for (i = 0; thisSelect[i]; i++) {
		if (thisSelect[i].value == thisValue) {
			thisSelect[i].selected = true;
		}
	}
}

function getSelectOptionOfThisValue(thisSelect, thisValue) { // select the specified option
	success = 0;
	for (i = 0; thisSelect[i]; i++) {
		if (thisSelect[i].value == thisValue) {
			success = 1;
			return i;
		}
	}
	if (success == 0) {
		return false;
	}
}

function zero(thisString, thisLength) {
	thisString = thisString.toString();
	if (thisString.length < thisLength) {
		var padding = "";
		for (i = 0; i < (thisLength - thisString.length); i++) {
			padding += "0";
		}
		thisString = padding + thisString;
	}
	return thisString;
}

function email(a, b, c, d, show) { // try to avoid spam trollers, intentionally complex
	if (!show) {
		show = a + b + c + d;
	}
	e_string = "<a href=\"ma" + "ilto:" + a + b + c + d + "\">" + show + "</a>";
	document.write(e_string);
}
