/**
 *	Standard form validation functions
 *
 */
 
var reqargs = {};
 
function showGoodField(obj) {
	obj.style.borderColor = "#ccc";
}
function showBadField(obj, msg) {
	if (msg) {
		var m = new balloon();
		m.print(msg);
		window.status = msg;
	}
	obj.style.borderColor = "#c63";
}

function validate(showMsg) {

	var err = 0, str = "";
	for(i in reqargs) {
		if (reqargs[i] == 0) {
			showBadField(document.getElementById(i));
			var fieldName = document.getElementById(i).parentNode.parentNode.childNodes[1].innerHTML;
			if (typeof fieldName == "undefined")
				var fieldName = document.getElementById(i).parentNode.parentNode.childNodes[0].innerHTML;
			
			if (fieldName.indexOf("<label") == 0) {
				// Strip out the label tag and get just its contents
				var idx1 = fieldName.indexOf(">");
				var idx2 = fieldName.indexOf("<", idx1);
				fieldName = fieldName.substr(idx1+1, idx2-idx1-1);
			}
			
			err = true;
			str += fieldName + "\n";
		} else {
			showGoodField(document.getElementById(i));
		}			
	}
	if (err && showMsg) {
		alert("Some form fields were not completed.\n\n" + str);
		return false;
	}	
	return true;
}

function balloon() {

	this.print = function(str) {
return;
		document.getElementById("balloonHelp").innerHTML = str;
		this.show();
	}
	this.hide = function() {
		document.getElementById("balloonHelp").display = "none";
	}
	this.show = function() {
		document.getElementById("balloonHelp").display = "block";
		reveal();
	}
	
	var m = 0;
}

function reveal() 
{
	var obj = document.getElementById("balloonHelp");
	obj.style.display = "block";
	var opa = parseFloat(obj.style.opacity);
	
	if (typeof opa == "undefined" || !opa) {
		obj.style.opacity = "0.0";
		opa = 0;
	}
		
//window.status = "Opacity: " + opa;
		
	if (parseInt(opa) < 1) {
		opa += 0.05;
		obj.style.opacity = opa;
		window.setTimeout(reveal, 100);
	}
	else {
		window.setTimeout(disappear, 3500);
	}
}

function disappear()
{
	
	var obj = document.getElementById("balloonHelp");
	var opa = parseFloat(obj.style.opacity);
	
	if (typeof opa == "undefined" || !opa) {
		obj.style.display = "hidden";
		return;
	}
		
	if (opa > 0) {
		opa -= 0.1;
		obj.style.opacity = opa;
		window.setTimeout(disappear, 100);
	}
	else {
		obj.style.display = "hidden";
		
	}
}

