/* Sets the focus to the first visible field in a form */
function setFocus() {
	if (document.forms[0] == null)
		return;
	for (i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type != "hidden") {
			document.forms[0].elements[i].focus();
			return;
		}
	}
}

/* Verifies that all visible fields in a form contain text */
function validateForm(form) {
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type != "hidden") {
			if (form.elements[i].value == '') {
				alert("Please enter all the required information");
				form.elements[i].focus();
				return false;
			}
		}
	}
	return true;
}

/* Verifies that all fields in the subscription form are filled out */
function validateSubscribeForm(form) {
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type != "hidden") {
			var fld = form.elements[i].name;
			if (fld != "address2" && fld != "zip" && fld != "country") {
				if (form.elements[i].value == '') {
					alert("Please enter all the required information");
					form.elements[i].focus();
					return false;
				}
			}
		}
	}
	return true;
}

/* Verifies that at least one message selection has been made */
function isMessageSelected(form) {
	return true;
//	for (i = 0; i < form.elements.length; i++) {
//		if (form.elements[i].type == 'checkbox') {
//			if (form.elements[i].checked) {
//				return true;
//			}
//		}
//	}
//	alert("Please select a message by clicking on its checkbox.");
//	return false;
}

/* Checks or unchecks all messages in the list */
function selectAll(form) {
	var check = true;
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == 'checkbox') {
			if (form.elements[i].checked)
				check = false;
			break;
		}
	}
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == 'checkbox') {
			form.elements[i].checked = check;
			highlight(form.elements[i]);
		}
	}
}

/* highlights/un-highlights the row containing a checkbox */
function highlight(checkbox) {
	if (checkbox.checked)
		select(checkbox);
	else
		unselect(checkbox);
}

/* highlights a selected row in a table */
function select(element) {
	var ie = document.all ? true : false;
	if (ie) {
		while (element.tagName != "TR")
			element = element.parentElement;
	}
	else {
		while (element.tagName != "TR")
			element = element.parentNode;
	}
	element.className = "selected";
}

/* normalizes an un-selected row in a table */
function unselect(element) {
	var t = null;
	var ie = document.all ? true : false;
	if (ie) {
		while (element.tagName != "TR")
			element = element.parentElement;
		t = element.parentElement;
	}
	else {
		while (element.tagName != "TR")
			element = element.parentNode;
		t = element.parentNode;
	}
	element.className = (element.id % 2 == 0) ? "evenrow" : "oddrow";
}


/* the chat applet popup window */
var w = null;

/* opens the Chat applet screen as a popup window */
function openChat() {
	var url = "http://death2spam.net:2000/";
	var title = "Death2Spam Technical Support";
	var width = 625;
	var height = 485;
	config = "height=" + height + ",innerHeight=" + height;
	config += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		config += ",left=" + xc + ",screenX=" + xc;
		config += ",top=" + yc + ",screenY=" + yc;
	}
	config += ",scrollbars=no,resizable=no,toolbar=no";
	config += ",menubar=no,status=yes,location=no,directories=no";
	w = window.open(url, '', config);
}

/* closes the chat applet popup */
function closeChat() {
	if (w != null && w.open && !w.closed)
		w.close();
}

