/* -------------------------------------------------------------
	Z Integration
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Description:	Primary ECMA Script File
	Filename:		script.js
	Version:		1.2
	Date:			11 January 2006
------------------------------------------------------------- 

Table of Contents (subject to change):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	+ Custom Functions
	+ Document Initiation
	+ Event Listeners

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
*/




/* -------------------------------------------------------------
	Custom Functions
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
var set = {
	external : function(){
		if (!document.getElementsByTagName) return;
		var links = document.getElementsByTagName("a");
		if (!links) return;
		for (var i=0; i<links.length; i++) {
			var link = links[i];
			if (link.getAttribute("href") && link.getAttribute("rel") == "external") {
				link.target = "_blank";
			}
		}		
	}
};


/*	Form Validation Object
	-------------------------------------
	Author: Ronald Timoshenko (Triad)
	Version: 0.5 (Updated 25 July 2006)
*/

var form = {
	requireClass : "require", // apply this class to inputs for validation
	invalidFields : null,
	init : function(){
		if (!document.getElementsByTagName) return;
		var forms = document.getElementsByTagName("form");
		for (var i=0; i<forms.length; i++){
			forms[i].onsubmit = function(){
				return form.validate(this);
			}
		}
	},
	validate : function(formObj){
		form.invalidFields = 0;
		for (var i=0; i<formObj.length; i++){
			var field = formObj[i];
			var fieldClass = String(field.className);
			if (fieldClass.indexOf(form.requireClass) != -1){
				if (field.value == 0 || field.value == ""){
					form.invalidFields++;
				}
			}
		}
		if(form.invalidFields != 0){
			alert("There are still " + form.invalidFields + " empty fields.");
			return false;
		} else {
			return true;
		}
	}	
};







/* -------------------------------------------------------------
	Document Initiation
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

/*  Document Initiation Function
	Used to replace multiple function calls appended to listeners, etc.
	Add as many functions as you want.
*/

var doc = {
	loaded : function(){
		set.external();
		form.init();
	}
};


/* -------------------------------------------------------------
	Event Listeners
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
if (window.addEventListener) {
	window.addEventListener("load", doc.loaded, false);
} else if (document.addEventListener) {
	document.addEventListener("load", doc.loaded, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", doc.loaded);
} else if (typeof window.onload == "function") {
	window.onload = function(){
		doc.loaded();
	};
} else {
	window.onload = doc.loaded;
}