function none(){
}

// querystring functions
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return null;
}

function urlEncode(str){
	if (encodeURIComponent) {
	    return encodeURIComponent(str);
	} else {
	    return escape(str);
	}
}

function urlDecode(str){
	if (decodeURIComponent) {
	    return decodeURIComponent(str);
	} else {
	    return unescape(str);
	}
}

function utf8Encode(str){
  return unescape(encodeURIComponent(str));
}

function utf8Decode(str){
  return decodeURIComponent(escape(str));
}

String.prototype.stripHTMLTags = function(){
	
	return this.replace(/(<([^>]+)>)/ig," "); 
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		obj = obj.offsetParent;
		while (obj != null) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return [curleft,curtop];
}

function getPageSizeObject(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	return {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};
}

function getYScroll(){
	

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;

}

function setOpacity(obj, opacity) {
	if(typeof(obj) == "string"){
		obj = document.getElementById(obj);
	}
	obj.style.filter = "alpha(style=0,opacity:" + opacity + ")";	// IE
	obj.style.KHTMLOpacity = opacity / 100;						// Konqueror
	obj.style.MozOpacity = opacity / 100;							// Mozilla (old)
	obj.style.opacity = opacity / 100;							// Mozilla (new)
}

function changeOpacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--){
            setTimeout("setOpacity('" + id + "'," + i + ")",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++){
            setTimeout("setOpacity('" + id + "'," + i + ")",(timer * speed));
            timer++;
        }
    }
}


function getStyle(obj,styleProp){

	if (obj.currentStyle)
		var y = obj.currentStyle[styleProp];

	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);


	return y;
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function clearDropDown(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}


function addToDropDown(OptionList, OptionValue, OptionText, selected) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue, false, selected);
}


function numberFormat(num,decimalPlaces){
	decimalPlaces = (decimalPlaces == null) ? 2 : decimalPlaces;
	num = Math.round(num*Math.pow(10,decimalPlaces))/Math.pow(10,decimalPlaces);
	num = String(num);
	var decimals = null;
	
	if(num.indexOf(".") != -1){
		num = num.split(".");
		decimals = num[1];
		num = String(num[0]);
	}
	var str = "";
	var p;
	while(num.length > 3){
		str = ","+num.substr(num.length-3)+str;
		num = num.substr(0,num.length-3);
	}
	if(num.length > 0){
		str = num+str;
	}
	
	if(decimals){
		while(decimals.length < decimalPlaces){
			decimals += "0";
		}
		str = str + "." + decimals;
		
	}
	
	return str;
		
}

// JAVASCRIPT INCLUDE FUNCTIONS
// thanks to http://www.phpied.com/javascript-include/

function includeJS(script_filename) {
	document.write("<script language=\"JavaScript\" type=\"text/javascript\" src=\""+script_filename+"\"></script>\n");
}

function jsIncludeDom(script_filename) {
    var head = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    head.appendChild(js);
    return false;
}

var jsIncludedFiles = new Array();

function jsIncludeOnce(script_filename,method) {
    if (!isInArray(script_filename, jsIncludedFiles)) {
        jsIncludedFiles[jsIncludedFiles.length] = script_filename;
        if(method == "dom"){
        	jsIncludeDom(script_filename);
        }else{
       		includeJS(script_filename);
        }
    }
}

function isInArray(needle, haystack) {
    for (var i = 0; i < haystack.length; i++) {
        if (haystack[i] == needle) {
            return true;
        }
    }
    return false;

}


function loadCSS(fileName,pos){
	var fileref=document.createElement("link");
	var target = null;
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", fileName);
	if(pos < 0){
		if(document.getElementsByTagName("head")[0].getElementsByTagName("link").length >= 0-pos){
			target = document.getElementsByTagName("head")[0].getElementsByTagName("link")[document.getElementsByTagName("head")[0].getElementsByTagName("link").length+pos];
		}
	}else if (pos>0){
		if (document.getElementsByTagName("head")[0].getElementsByTagName("link").length > pos+1) {
			target = document.getElementsByTagName("head")[0].getElementsByTagName("link")[pos + 1];
		}
	}
	if (target) {
		document.getElementsByTagName("head")[0].insertBefore(fileref, target);
		
	} else {
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

// JSON Display function

function displayJSONData(data){
	
	if(data.module.target != null){
		var element = document.getElementById(data.module.target);
		if(element != null){
			element.innerHTML = data.module.html;
			window.evalScripts(data.module.target);
		}
		
	}
	
}


// File system functions

function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}


function dirname(path) {
    // http://kevin.vanzonneveld.net
    // +   original by: Ozh
    // +   improved by: XoraX (http://www.xorax.info)
    // *     example 1: dirname('/etc/passwd');
    // *     returns 1: '/etc'
    // *     example 2: dirname('c:/Temp/x');
    // *     returns 2: 'c:/Temp'
    // *     example 3: dirname('/dir/test/');
    // *     returns 3: '/dir'
    
    return path.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '');
}


// CLASS INHERITANCE

// Inheritance method
if(!Function.inherits){
	Function.prototype.inherits = function(superclass) {
		var x = function() {};
		x.prototype = superclass.prototype;
		this.prototype = new x();
	}
}


