// JavaScript Document
function toggle_display(id) {
	var disp = document.getElementById(id).style.display;
	if (disp == 'none') {
		disp = 'block';	
	} else {
		disp = 'none';
	}
}
function validate_required(field)
{
	with (field)
	{
		if (value==null||value=="")
		{
			return false;
		} else {
			field.focus();
			return true;
		}
	}
}
function validate_expression(field, expr)
{
	var ex = '';
	switch (expr) {
		case 'alpha':
			ex = /^[a-zA-Z ]+$/;
			break;
		case 'number':
			ex  = /^[0-9]+$/;
			break;
		case 'alphanum':		
			ex = /^[0-9a-zA-Z ]+$/;
			break;
		case 'email':
			ex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;	
			break;
		default: // alpha
			ex = /^[a-zA-Z ]+$/;
			break;
	}

	var val = field.value.replace(/ /,'');
	if (val.match(ex)) {
		return true;	
	} else {
		field.focus();
		return false;
	}
}

function compare_values(field_a, field_b) {
	if (field_a.value == field_b.value) {
		return true;
	} else {
		field_a.focus();
		return false;
	}
}

function confirm_delete(obj_name, id, page) {
	if (confirm("Are you sure you want to delete " + obj_name + "?")) {
		window.location.href = page + "?id=" + id + "&action=remove";
	}
}

/* BEGIN DROP-DOWN MENU */
function loadNav(list) {
	var ids = new Array(list);
	for(var i = 0; i < ids.length; i++)
	{
		var sfEls = document.getElementById(ids[i]).getElementsByTagName("LI");
		for (var i = 0; i < sfEls.length; i++) {
			sfEls[i].onmouseover = function() {
				if(!this.oldClassName)
					this.oldClassName = this.className.replace(new RegExp("\\bsfhover\\b"), "");
				this.className += " sfhover";
			}
			sfEls[i].onmouseout = function() {
				this.className = this.oldClassName;
			}

			var sfEls2 = sfEls[i].getElementsByTagName("A");
			for (var j = 0; j < sfEls2.length; j++)
			{
				sfEls2[j].onclick = function() {
					if(this.href.substr(this.href.length-1) == "#")
						return false;
					else
						this.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.oldClassName;
					if(this.className == "subnewwindow")
					{
						window.open(this.href);
						return false;
					}
				}
			}
		}
	}
}
/* END DROP-DOWN MENU */

window.onload = function () {
	loadNav('nav');
}