/* -------------------------------------------------------------
	John Christner Trucking
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Description:	Primary ECMA Script File
	Filename:		script.js
	Version:		1.0
	Date:			18 July 2006
------------------------------------------------------------- 

Table of Contents (subject to change):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	+ Custom Functions
	+ Unobtrusive Flash Object Definition
	+ 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";
			}
		}		
	}
}

var q = {
	element : null,
	init : function(){
	    var a = "";
		if (!document.getElementById) return;
		if (a != "1") return;
		q.element = document.getElementById("messaging");
		var imgArray = ["header_02.jpg","header_03.jpg","header_04.jpg","header_05.jpg","header_06.jpg","header_07.jpg","header_08.jpg","header_09.jpg","header_10.jpg","header_11.jpg","header_12.jpg","header_13.jpg"];
		q.run(imgArray);
	},
	run : function(theArray){
		var newNumber = Math.floor(Math.random()*theArray.length);
		var imgSrc = "/images/";
		var newBG = "url(" + imgSrc + theArray[newNumber] + ")";
		q.element.style.backgroundImage = newBG;
		q.element.style.visibility = "visible";
	}
};


/*	Form Validation Object
	-------------------------------------
	Author: Ronald Timoshenko
	Version: 0.5 (Updated 21 July 2006)
*/

var form = {
	requireClass : "field_required",
	invalidFields : null,
	init : function(){
		if (!document.getElementsByTagName) return;
		var forms = document.getElementsByTagName("form");
		if (!forms) return;
		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];
			if (field.className == form.requireClass){
				if (field.value == 0 || field.value == ""){
					form.invalidFields++;
				}
			}
		}
		if(form.invalidFields != 0){
			alert("There are still " + form.invalidFields + " required fields that you must fill out.");
			return false;
		} else {
			return true;
		}
	}	
}

/* -------------------------------------------------------------
	qTip - CSS Tool Tips
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//
// Modified by Ronald Timoshenko (06 June 2006)
//////////////////////////////////////////////////////////////////





var tooltip = {
	
	/* Variables
	------------------------------------------------ */
	
	name : "qTip",
	offsetX : -30, //This is qTip's X offset//
	offsetY : 25, //This is qTip's Y offset//
	tip : null,
	
	/* Functions
	------------------------------------------------ */
	
	init : function () {
		var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
		if(!tipContainerID){ var tipContainerID = "qTip";}
	
		if(!tipContainer) {
		  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
			tipContainer.setAttribute("id", tipContainerID);
		  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
		}
	
		if (!document.getElementById) return;
		tooltip.tip = document.getElementById (tooltip.name);
		if (tooltip.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
	
		var tipContainer = document.getElementById(tipContainerID);
	
		var a, sTitle;
		var anchors = document.getElementsByTagName ("img"); //Which tag do you want to qTip-ize? Keep it lowercase!//
	
		for (var i = 0; i < anchors.length; i ++) {
			a = anchors[i];
			sTitle = a.getAttribute("longdesc");
			if(sTitle) {
				a.setAttribute("tiptitle", sTitle);
				a.removeAttribute("longdesc");
				a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
				a.onmouseout = function() {tooltip.hide()};
			}
		}
	},
	move : function (evt) {
		var x=0, y=0;
		if (document.all) {//IE
			x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			x += window.event.clientX;
			y += window.event.clientY;
			
		} else {//Good Browsers
			x = evt.pageX;
			y = evt.pageY;
		}
		tooltip.tip.style.left = (x + tooltip.offsetX) + "px";
		tooltip.tip.style.top = (y + tooltip.offsetY) + "px";
	},
	show : function (text) {
		if (!tooltip.tip) return;
		tooltip.tip.innerHTML = text;
		tooltip.tip.style.display = "block";
	},
	hide : function () {
		if (!tooltip.tip) return;
		tooltip.tip.innerHTML = "";
		tooltip.tip.style.display = "none";
	}
}




/* -------------------------------------------------------------
	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();
		tooltip.init();
		form.init();
		q.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;
}

