

/*
	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 getURLQueryString() {
	var fullURL = getFullURL();
	var qString = fullURL.split("?");
	return qString[1];
}

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   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

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 4B: TOGGLE SINGLE DISPLAY   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function toggleDivSingleDisplay(target, style) {
	document.getElementById(target).style.display = style;
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 4: TOGGLE SINGLE DISPLAY   || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/


/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 5: CHANGE IMG & CHANGE BACKGROUND IMG & POS  || :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

// 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) {
	document.getElementById(objId).style.backgroundPosition = newX + "px " + newY + "px";
	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 changeAllBGPos(arrayGroup, target) {
	for (var i=0; i <arrayGroup.length; i++) {
		if(i!=0) {
			if	(document.getElementById(arrayGroup[i][0]).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]);
			}
		}
	}
}

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || 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();
}

// 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  || ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
