﻿/* Extracted from Prototype JS Library, http://prototype.conio.net/
 Written by Sam Stephenson, http://conio.net/ */
function _gel() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = (document.getElementById) ? document.getElementById(element) : eval("document.all."+element) ;
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}
/* Function to remove all child nodes of an element. */
function clean(elm) {
	while(_gel(elm).hasChildNodes()) {
		_gel(elm).removeChild(_gel(elm).childNodes[0]);
	}
	return true;
}
/* Functions to handle cross-browser events.
 Written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com. */
/* get the target of an event object */
function getTarget(e) {
	return (e.target) ? e.target : e.srcElement;
}

/* Function to grab all elements with a specific class name.
 Original written by Jonathan Snook, http://www.snook.ca/jonathan
 Add-ons by Robert Nyman, http://www.robertnyman.com 	
 Re-written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com */
function getElementsByClass(className, elm, tag){
	if(elm == null) elm = document;
	if(tag == null) tag = '*';
	var elems = elm.getElementsByTagName(tag);
	var returnElems = new Array();
	className = className.replace(/\-/g, "\\-");
	var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
	for(var i=0; i<elems.length; i++){
		if(pattern.test(elems[i].className)) returnElems.push(elems[i]);
	}
	return returnElems
}

/* Function to return the class attribute. IE and all other standards compliant browsers have different names for the class attribute object. */
/*
function classAttr(){
	var class_att = null;
	if (browser == IE ){
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}
	
	return class_att;
	
}*/
function classAttr(){
	var class_att = null;
	if (browser == IE ){
	  // IE8  css class attribute name is class instead of className
	  var rv = -1; // Return value assumes failure
	  var ua = navigator.userAgent;
	  var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	  if (re.exec(ua) != null)
	   rv = parseFloat( RegExp.$1 );
	   
	 if( rv == 8 )
		class_att = 'class';
	 else
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}	
	return class_att;	
}

/* Functions to add/remove event listeners to objects
	Written by John Resig, http://ejohn.org */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn ) {
	if (obj.removeEventListener) obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
/* Function to get img extension */
function getImgExt(obj){
	var src = obj.getAttribute('src');
	var imgExtPosition = src.lastIndexOf('.') + 1;	//Get the extension. Add 1 to get only the extension, not .extension
	
	var extension;
	
	if(src.match('clearpixel.gif')){	//If IE and the image is a PNG, return 'png', because the PNG transparency function causes the img src to be clearpixel.gif.
		extension = 'png';
	}
	
	else {
		var extension = src.slice(imgExtPosition);
	}
	return extension;
}

/* Function to get img src text */
function getImgSrc(obj){
	var src = obj.getAttribute('src');	
	return src;
}

/* Function to get img alt text */
function getImgAlt(obj){
	var alt_text = obj.getAttribute('alt');	
	return alt_text;
}

/* Function to get img height text */
function getImgHeight(obj){
	var img_h = obj.getAttribute('height');	
	return img_h;
}

/* Function to get img width text */
function getImgWidth(obj){
	var img_w = obj.getAttribute('width');	
	return img_w;
}

/* get the X location of an object */
function getX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x)	curleft += obj.x;
	return curleft;
}

/* get the Y location of an object */
function getY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)	curtop += obj.y;
	return curtop;
}

/* get the height of an element */
function getHeight(id){
    var elemHeight = _gel(id).offsetHeight;  
    
    return elemHeight;
}

/* get the width of an element */
function getWidth(id){
    var elemWidth = _gel(id).offsetHeight;  
    
    return elemWidth;
}

/* Begin get URL parameter by name function */
function getURLParameterByName(name) {
    var sURL = window.document.URL.toString();
	
    if (sURL.indexOf("?") > -1){
	    
	    //Split the url at the beginning of the query string.
	    var arrParams = sURL.split("?");
		
	    //Split the query string into name/value pairs.
	    var fullqs = arrParams[1];
	    var arrURLParams = fullqs.split("&");
		
	    for (var j=0;j<arrURLParams.length;j++) {
	    
	        if(arrURLParams[j].indexOf(name) > -1){
		        //Split the name/value pairs into name and value.
		        var qsValue =  arrURLParams[j].split("=")[1];
	            return qsValue;		            
		        break;
		    }
	    }
    }
}
/* End get URL parameter by name function */

/* Begin functions dealing with Cookies */
function getCookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name+"="+escape(value) +
		((expires) ? ";expires="+expires_date.toGMTString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
			((path) ? ";path=" + path : "") + 
			((domain) ? ";domain=" + domain : "") + 
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}
/* End functions dealing with Cookies */