/* Global functions/objects ................................................................................................ */

/* Element shortcuts */
function $(id){ return document.getElementById(id) }
function $show(id){ $(id).style.display = ''; }
function $hide(id){ $(id).style.display = 'none'; }
function $showhide(id){ $(id).style.display = ($(id).style.display == 'none') ? '' : 'none'; }


/* Onload object */
function objOnload()
{
	this.aFunc = [];
	this._run = function(){
		for(i=0;i<this.aFunc.length;i++){
			this.aFunc[i]._init();
		}
	}
}
oLoad = new objOnload();


/* Form Validation ................................................................................................ */
function formValidation(f){
	aEle = f.elements;
	fAlert = false;
	msg = "Sorry, it looks like you've left some required fields blank or entered an invalid email address.";
	msg += "\n\nPlease check the highlighted fields and try again.";
	hColor = "#333";

	for(i=0;i<aEle.length;i++){
		ele = aEle[i];
		ele.style.background = "";

		if(ele.className.indexOf("js_req") > -1){

			// Text boxes //
			if((ele.type == "text" || ele.type == "textarea" || ele.type == "password") && ele.value.length == 0){
				ele.style.background = hColor; fAlert = true;
			}

			// Radio buttons //
			if(ele.type == "radio" || ele.type == "checkbox"){
				aRad = f.elements[ele.name];
				fChecked = false;
				
				for(n=0;n<aRad.length;n++) if(aRad[n].checked == true) fChecked = true;
	
				if(fChecked == false){ ele.parentNode.parentNode.style.background = hColor; fAlert = true; }
				else ele.parentNode.parentNode.style.background = "";
				
				i += aRad.length-1;
			}

		}

		// Email Check //
		if(ele.className.indexOf("js_eReq") > -1 && (ele.value.length < 8 || ele.value.indexOf("@") < 2 || ele.value.lastIndexOf(".") > (ele.value.length-1))){
			ele.style.background = hColor; fAlert = true;
		}
			
	}

	if(fAlert == true){ alert(msg); return false; }

}