

/*
	0: DATE & TIME
	1: URL PARSING
	2: EVENT LISTENERS
	3: BROWSER PROPERTIES/DETECTION (Cookies)
	4: TOGGLE GROUP DISPLAY 
	5: CHANGE IMG & CHANGE BACKGROUND IMG & POS
	6: CHANGE CLASS PROPERTIES
	7: CUSTOM STRING METHODS
*/

// Init Asset Info:
var imgDir = "lib/images/";

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 0: DATE & TIME  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function getTheYear() {
	var year = new Date();
	return year.getFullYear();
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 0: DATE & TIME  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 1: URL PARSING  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function getFullURL() {
	var locURL = window.location.href;
	return locURL;	
}

function getURLParts() {
	var urlParts = getFullURL();
	var urlSplit = urlParts.split("//");
	var urlFinal = urlSplit[1];
	return urlFinal;
}

function getURLDirectory() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 2)];
	return urlFinal;
}

function getURLPage() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 1)];
	return urlFinal;
}

function getURLQuryString() {
	var fullURL = getFullURL();
	var qString = fullURL.split("?");
	return qString;
}

function getPageURL(url) {
	var fn = url.match(/\/([a-z0-9_-]+\.\w+)/i);
    return (fn == null) ? "" : fn[1];
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 1: URL PARSING  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 2: EVENT LISTENERS  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function addEvent(evnt, elem, func) {
	if (elem.addEventListener)  { // W3C DOM
		elem.addEventListener(evnt,func, false);
	} else if (elem.attachEvent) { // IE DOM
		var r = elem.attachEvent("on"+evnt, func);
		return r;
	}
}
// How To call the eventListener
// --> addEvent('load', window, function() { //Do something });

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 2: EVENT LISTENERS  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 3: BROWSER PROPERTIES/DETECTION  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

var mouseX;
var mousey;
var mousePos;

/*

function getMousePos(evt) {
	/// Needed for IE Only
	if (!evt) {
		evt = window.event;
	}
	// Record the mouse Coords
	mouseX = evt.clientX;
	mouseY = evt.clientY;
	mousePos = new Array (mouseX, mouseY);
	// Loop this process
	document.onmousemove = getMousePos; 
}

// returns [windowWidth, windowHeight]
function getScreenDimensions() {
	var screenDim = new Array(screen.availWidth, screen.availHeight);
	return screenDim;
}

// returns the browsers dimensions
function getBrowserDimensions() {
	var browserWidth;
	var browserHeight;

	if (window.innerWidth) {
		browserWidth = window.innerWidth;
	} else {
		browserWidth = document.body.clientWidth;	
	}
	
	if (window.innerHeight) {
		browserHeight = window.innerHeight;
	} else {
		browserHeight = document.body.clientHeight;	
	}
	
	var browserDim = new Array(browserWidth, browserHeight);
	return browserDim;	
}
*/
// opens a new window
function openNewWindow(page, title, toolbar, menubar, url, status, scroll, resize, width, height) {
	var winPage = page;
	var winTitle = title;
	var winToolbar = toolbar;
	var winMenubar = menubar;
	var winURL = url;
	var winStatus = status;
	var winScroll = scroll;
	var winResize = resize;
	var winWidth = width;
	var winHeight = height;
	return window.open(winPage, winTitle, "'toolbar="+winToolbar+",  resizeable="+winResize+", menubar="+winMenubar+", url="+winURL+", status="+winStatus+", scrollbars="+winScroll+", width="+winWidth+", height="+winHeight+"'");
}

// resizes the window to fit the inline image
function resizeWindowToImage() {
	var browserDim = getBrowserDimensions();
	var app = navigator.appName;
	var winWidth;
		winWidth = document.images["largeImg"].width - browserDim[0];
	var winHeight;
	if (window.innerHeight) {
		winHeight = document.images["largeImg"].height - browserDim[1];
	} else {
		var height = (browserDim[1]/2) + 5;
		winHeight = document.images["largeImg"].height - height;
		
	}
	window.resizeBy(winWidth, winHeight); 
    self.focus();
}

// redirect the parent window
function windowOpenerRedirect(myURL) {
	window.opener.location = myURL;	
}

// move the new window on the end users screen
function windowMoveTo(xx, yy) {
	window.moveTo(xx, yy);
}

// Set A Cookie
function setCookie(c_name,value,expiredays) {
	var exdate= new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());	
}

// Return A Cookie
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end == -1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 3: BROWSER PROPERTIES/DETECTION  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 4: TOGGLE GROUP DISPLAY   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function hideDivDisplay(target) {
	document.getElementById(target).style.display = "none";
	document.getElementById(target).style.visibility = "hidden";
}
	
function showDivDisplay(target) {
	document.getElementById(target).style.display = "block";
	document.getElementById(target).style.visibility = "visible";
}
	
	
var toggleDivGroupCount = 0;

function toggleDivGroupDisplay(arrayGroup, target) {
	
	// Make invisible and show, then hide to activate toggle.....Needed for IE
	if (toggleDivGroupCount < 1) {
		for (var i = 0; i < arrayGroup.length; i++) {
			var element = document.getElementById(arrayGroup[i]);
			if(element){
				element.style.visibility = "hidden";
				element.style.display = "block";
				element.style.display = "none";
				element.style.visibility = "visible";
			}
		}
	}
	// Stop the init toggle readyness
	toggleDivGroupCount ++;
	
	for (var j = 0; j < arrayGroup.length; j++) {
		var element = document.getElementById(arrayGroup[j]);
		if(element){
			if(element.id == target) {
				element.style.display = "block";
				element.style.visibility = "visible";
			} else {
				element.style.display = "none";
				element.style.visibility = "hidden";
			}
		}
	}
	// Reset the toggleCount
	toggleDivGroupCount = 0;
}


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 4: TOGGLE GROUP DISPLAY   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 5: CHANGE IMG & CHANGE BACKGROUND IMG & POS  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

// Change the background color
function changeBGColor(objId, newColor) {
	var element = document.getElementById(objId)
	if(element){
		element.style.backgroundColor = newColor;
		element.blur();
	}
}

// Change the background image
function changeBGImg(objId, newImg) {
	document.getElementById(objId).style.backgroundImage = "url(" + imgDir + newImg + ")";
	document.getElementById(objId).blur();
}

function changeBGImgY(objId, newY) {
	document.getElementById(objId).style.backgroundPosition = "0 " + newY + "px";
	document.getElementById(objId).blur();
}

function changeBGImgX(objId, newX) {
	document.getElementById(objId).style.backgroundPosition = newX + "px " + "0";
	document.getElementById(objId).blur();
}

function changeBGImgXY(objId, newX, newY) {
	//alert(objId + " : " + newX + " : " + newY);
	var element = document.getElementById(objId)
	if(element){
		element.style.backgroundPosition = newX + "px " + newY + "px";
		element.blur();
	}
}

// The first item in the array mut be the name & loc of the  default image...then list the id's of the elements to target
function changeAllBGPos(arrayGroup, target) {
	for (var i=0; i <arrayGroup.length; i++) {
		if(i!=0) {
			var element = document.getElementById(arrayGroup[i][0]);
			if(element){
				if	(element.id == target) {
					changeBGImgXY(arrayGroup[i][0], arrayGroup[i][1], arrayGroup[i][2]);
				} else {
					changeBGImgXY(arrayGroup[i][0], arrayGroup[0][1], arrayGroup[0][2]);
				}
			}
		}
	}
}

// The first item in the array mut be the name & loc of the  default image...then list the id's of the elements to target
function changeAllBGImg(arrayGroup, target, newImg) {
	for (var i=0; i <arrayGroup.length; i++) {
		if(i!=0) {
			if	(document.getElementById(arrayGroup[i]).id == target) {
					changeBGImg(target, newImg);
			} else {
				changeBGImg(arrayGroup[i], arrayGroup[0]);
			}
		}
	}
}

// The first item in the array mut be the name & loc of the  default image...then list the id's of the elements to target
function changeAllBGColor(arrayGroup, target, newColor, defaultColor) {
	for (var i=0; i <arrayGroup.length; i++) {
		if(arrayGroup[i][0] != "DEFAULTS") {
			if	(document.getElementById(arrayGroup[i]).id == target) {
					changeBGColor(target, newColor);
			} else {
				changeBGColor(arrayGroup[i], defaultColor);
			}
		}
	}
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 5: CHANGE IMG & CHANGE BACKGROUND IMG & POS  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 6: CHANGE CLASS PROPERTIES  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

// Change the items class
function changeClass(objId, newClass) {
	document.getElementById(objId).className = newClass;
	document.getElementById(objId).blur();
}

// The first item in the array must be the default color...then list the id's of the elements to target
function changeAllClass(arrayGroup, target, newClass) {
	for (var i=0; i <arrayGroup.length; i++) {
		if(i!=0) {
			if	(document.getElementById(arrayGroup[i]).id == target) {
					changeClass(target, newClass);
			} else {
				changeClass(arrayGroup[i], arrayGroup[0]);
			}
		}
	}
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 6: CHANGE CLASS PROPERTIES  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ||  START 7: CUSTOM STRING METHODS  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

// trim blank space on all ends
String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
  
// trim blank space at the beginning
String.prototype.LTrim = function() {
	return this.replace(/(^\s*)/g, "");
}
  
// trim blank space at the end
String.prototype.RTrim = function() {
	return this.replace(/(\s*$)/g, "");
}

String.prototype.StripTabs = function() {
	// Define a new string
	var newStr;
	
	// Strip any type of tab
	// this.charAt(i) !== "\u000D" == carriage return
	for (var i = 0; i < this.length; i++) {
		if (this.charAt(i) !== "\u0009" || 
			this.charAt(i) !== "\u000B" || 
			this.charAt(i) !== "\u000C" || 
			this.charAt(i) !== "\u000A"
		) {
			newStr += this.charAt(i);
		}
	}
	// Strip undefined text if found
	if (newStr.indexOf("undefined") > -1) {
		newStr = newStr.substring(9, newStr.length);
	}
	
	// Strip & trim leading dead space
	for (var i=0; i < newStr.length; i++) {
		var regEx = /(^\s*)$/;
		if (!regEx.test(this.charAt(i))) {
			newStr = newStr.substring(i, newStr.length);
			return newStr;
		}
	}
	
}
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ||  START 7: CUSTOM STRING METHODS  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ||  START 7: CSS MENUS  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function cssMenuHover() {
	var sfEls = document.getElementById("leftColumn").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		//alert(sfEls[i]);
		sfEls[i].onmouseover=function() {
			this.className ="hoverOut";
		}
		sfEls[i].onmouseout=function() {
			this.className="";
		}
	}
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ||  START 7: CSS MENUS  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

/*
==================================================================================
	Author: Joe Mallory
	Date Addad: 10-02-2007
	Purpose: Global Variables/Functions
==================================================================================
*/

// Listener for trackin pouse pos
function mouseListener(evt) {
		// Init mouse tracking vars
		mouseX = 0 + "px";
		mouseY = 0 + "px";

		var evt = (evt) ? evt :(window.event) ? event : null;
		mouseX = evt.clientX;
		mouseY = evt.clientY;
		
		checkMenu();
		document.onmousemove = mouseListener;

}

function getId(evt) {
	var elemId = (evt.target) ? evt.target.id : ((evt.srcElement) ? evt.srcElement.id : null); 
	return elemId;
}

// Check the browsers current width and return it
function getBrowserWidth() {
	var browserWidth;
	// FireFox 1.0+, Safari 1.0+, NN 6.0+
	if (document.documentElement.offsetWidth) {
		browserWidth = document.documentElement.offsetWidth;
	}
	// IE 5.0+ & Opera 6.0+
	if (document.body.clientWidth) {
		browserWidth = document.body.clientWidth;
	}
	return browserWidth;
}

function getBrowserScroll() {
	var browserScroll;
	// IE 6.0+, Opera 8.0+ --> (I think with Opera)
	if (document.documentElement.scrollTop) { 
		browserScroll = document.documentElement.scrollTop
	} else {
		if (document.body.scrollTop) { // Safari, IE 5.0 and prior
			browserScroll = document.body.scrollTop;
		} else if (window.pageYOffset) { // Don't even need this really: Firefox, Netscape
			browserScroll = window.pageYOffset;
		}
	}
	
	// Bug - Some browsers return 'undefined' if no scroll instead of 0 (zero);
	if (browserScroll == undefined) {
		return 0;	
	} else {
		return browserScroll;
	}
}

// Check the Expandable Banner boundaries when active to close when done.
function checkMenu() {
	if(document.getElementById("flyOutMenu")) {
		var getBounds = findPos(document.getElementById("flyOutMenu"));
		
		var leftBounds      = getBounds[0];
		var rightBounds     = getBounds[0] + document.getElementById("flyOutMenu").offsetWidth;
		var topBounds       = getBounds[1] - getBrowserScroll();
		var bottomBounds    = (getBounds[1] + document.getElementById("flyOutMenu").offsetHeight) - getBrowserScroll();
		
		/*
		document.getElementById("rightSidebar").innerHTML = "Top Bounds: " + topBounds + " || " + mouseY;
		document.getElementById("rightSidebar").innerHTML += "<br />Bottom Bounds: " + bottomBounds + " || " + mouseY;
		document.getElementById("rightSidebar").innerHTML += "<br />Left Bounds: " + leftBounds + " || " + mouseX;
		document.getElementById("rightSidebar").innerHTML += "<br />Right Bounds: " + rightBounds + " || " + mouseX;
		*/
		
		if (document.getElementById("flyOutMenu").style.display == "block") {
			if ((mouseX < (leftBounds - 220)) && (mouseY > (topBounds+25))) {
				alert("Button XY Passed");	
			}
			if ((mouseX < (leftBounds - 220)) || (mouseY > (topBounds+25)) && (mouseX < leftBounds) || (mouseX > rightBounds) || (mouseY < topBounds) || (mouseY > bottomBounds)) {
				document.getElementById("flyOutMenu").style.display = "none";
			}
		}
	}
	
}

// Find the top & left position of the current element within the site and return it
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

