/* 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;
}
/* Function to handle cross-browser HTTPRequest calls.
 Written by Dan Bogaard, www.rit.edu/~dsbics */
function getHTTP() {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		try {
			xmlhttp = new XMLHttpRequest();
			xmlhttp.overrideMimeType("text/xml"); 
		} catch(e) { xmlhttp = false;	}
	} else if(window.ActiveXObject) {	// if this is IE,
		// try to set the variable to activeX xmlhttp object
		try {	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch(e) {
			try {	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	} 
			catch(e) { xmlhttp = false;	}
		}
	}
	return xmlhttp;
}

/* 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((versionInfo.match(IE6)!= null)||(versionInfo.match(IE7)!= null)){
		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;
	}
}
/* 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;
}
/* 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;
	//alert(curleft);
	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;
	//alert(curtop);
	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).offsetWidth;  
    
    return elemWidth;
}

function getKey(e) {
	code = false;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	return code;
}
// this function is used to stop events from acting normally. 
// NOTE: Safari supports these functions, but does not work properly!
function killKey(e) {
	(e.preventDefault) ? e.preventDefault() : window.event.returnValue = false;
	(e.stopPropagation) ? e.stopPropagation() : window.event.cancelBubble = true;	
	return false;
}

/* Function to get object attribute text */
function getObjectAttribute(obj,attr){
	var attrValue = obj.getAttribute(attr);	
	return attrValue;
}

/* 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;
}

/* 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 */

/* Begin get URL parameter functions */
function getURLParameters(action) {
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0){
		var qsvs;
		//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("&");
		
		//Create 2 new arays to hold the parameter name and parameter value.
		var paramNames = new Array();
		var paramValues = new Array();
		
		for (var j=0;j<arrURLParams.length;j++) {
			//Split the name/value pairs into name and value.
			var sParam =  arrURLParams[j].split("=");
			
			//Set the value of the parameter name array.
			var arrParamNames = sParam[0];
			//Set the value of the parameter value array.
			var arrParamValues = unescape(sParam[1]);
			
			//Generate the arrays using the parameter names and parameter values.
			paramNames.push(arrParamNames);
			paramValues.push(arrParamValues);
		}
		qsvs = paramValues[0];
	}
	
	else {
		qsvs;
	}
	
	/*******************
	If action equals 'split', we want to return the value of the split query string. Currently, we are only concerned with the value of the position.
	If action does not equal 'split', we want to return the entire query string as one long string to be passed to a Flash movie. 05/03/06
	********************/
	if (action == 'split'){
		return qsvs;
	}
	else {
		return fullqs;
	}
}
/* End get URL parameter functions */

/* 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 */

function getCurrentPage() { //Get the page
	var sURL = window.document.URL.toString();

	var arrURL = sURL.split("http://");
	var arrURLParts = arrURL[1].split("/");
	var arrURLPage = arrURLParts.length;
	arrURLPage--;
	
	switch(arrURLParts[arrURLPage]) {
		case "file name":
			//Do something
			break
		default:
		;
	}
}
