

/*
	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("/");
	// Just incase the url has a querystring
	var urlSplit2 = urlSplit[(urlSplit.length - 1)].split("?");
	var urlFinal = urlSplit2[0];
	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;
}

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;	
}

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+"'");
}

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();
}

function windowOpenerRedirect(myURL) {
	window.opener.location = myURL;	
}

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   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

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++) {
			document.getElementById(arrayGroup[i]).style.visibility = "hidden";
			document.getElementById(arrayGroup[i]).style.display = "block";
			document.getElementById(arrayGroup[i]).style.display = "none";
			document.getElementById(arrayGroup[i]).style.visibility = "visible";
		}
	}
	// Stop the init toggle readyness
	toggleDivGroupCount ++;
	
	for (var j=0; j <arrayGroup.length; j++) {
		if	(document.getElementById(arrayGroup[j]).id == target) {
				document.getElementById(arrayGroup[j]).style.display = "block";
		} else {
			document.getElementById(arrayGroup[j]).style.display = "none";
		}
	}
	// Reset the toggleCount
	toggleDivGroupCount = 0;
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 4: TOGGLE GROUP DISPLAY   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 5: CHANGE IMG & CHANGE BACKGROUND IMG & POS  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function changeImg() {
	document.getElementById(objId).style.backgroundImage = "url(" + imgDir + newImg + ")";
	document.getElementById(objId).blur();
}

function changeBGImg(objId, newImg) {
	document.getElementById(objId).style.backgroundImage = "url(" + imgDir + newImg + ")";
	document.getElementById(objId).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 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]);
			}
		}
	}
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 5: CHANGE IMG & CHANGE BACKGROUND IMG & POS  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 6: CHANGE CLASS PROPERTIES  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

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  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
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, "");
}
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ||  START 7: CUSTOM STRING METHODS  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/