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


/* 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 = "#DEDEDE";

	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;
			}

			// Password //
			if(ele.type == "password" && f.elements.repassword){
				if(ele.value!=f.elements.repassword.value){
					ele.style.background = hColor;
					f.elements.repassword.style.background = hColor;
					fAlert = true;
					msg = "Password boxes do not match. Please re-enter and try again.";
				}
			}

			// Radio buttons & Checkboxes //
			if(ele.type == "radio" || ele.type == "checkbox"){
				// Will most likely be an array but could be just one check box.
				aRad = f.elements[ele.name];
				fChecked = false;

				if(aRad.length){ // So check it's an array.
					for(n=0;rad=aRad[n];n++) if(rad.checked==true) fChecked = true;
				}else if(aRad.checked==true){ // Otherwise, just see if it's 'checked'.
					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;
	}

}



/* 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'; }
*/
