function loadScript(sScriptSrc, oCallback) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.src = sScriptSrc;
	
	//Callback
	if(typeof oCallback != 'undefined'){
		// most browsers
		oScript.onload = oCallback;
		// IE 6 & 7
		oScript.onreadystatechange = function() {
			if (this.readyState == 'complete') {
				oCallback();
			}
		}
	}
	oHead.appendChild(oScript);
}

function loadStyle(sStyletSrc) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('link');
	oScript.rel = 'stylesheet';
	oScript.href = sStyletSrc;
	oScript.type = 'text/css';
	oScript.media = 'screen';
	oHead.appendChild(oScript);
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  if (oldonload) {
		oldonload();
	  }
	  func();
	}
  }
}

//sleep, naptime, take a brake, pause
function pause(millis){
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

/* QueryString functionality to js
	usage: var roo = displayItem('action');
*/
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}

function displayItem(key){
	if(queryString(key)=='false')
	{
		//document.write("you didn't enter a ?name=value querystring item.");
		return '';
	}else{
		//document.write(queryString(key));
		return queryString(key);
	}
}
/*
 example usage:
 include your js file with params
 <script src="shortdatefunction.js?datedescription=DDMMYYYY&delimeter=/"></script>
 From inside your script:
 var datedescription = jsQuery.get('shortdatefunction','datedescription');
 datedescription now has the value 'DDMMYYYY'
 jsQuery.get takes two arguments
 jsFile: then name of the jsFile without .js
 param: the param two search for
 
 If nothing is found en empty string is returned
*/

var jsQuery = {
	get: function(jsFile,param) {
		var scripts = $A(document.getElementsByTagName('script'));
		var returnStr ="";
		scripts.each(function(node){
			  if(jsQuery.find(node.src,jsFile)>-1){
				returnStr = jsQuery.getparam(node,param);
			  }	
		});
		if(returnStr==false){returnStr='';}
		return returnStr;
	},	
	find: function(sSrc,jsFile){
		//alert('find');
		sSrc = sSrc.toLowerCase();
		jsFile = jsFile.toLowerCase();
		return sSrc.indexOf(jsFile);
	},
	getparam: function(node,param){
		var querystr = node.src.match(/\?.*([\S,]*)/);
		var objQuery = new PageQuery(querystr[0]);
		return objQuery.getValue(param);
	}
}

var pagePath 		= window.location.pathname;
var pageHostname 	= window.location.hostname;
var pageHref 		= window.location.href;
var pageHost 		= window.location.host;

getSystemParameter = function(paramname){
	var aLinkHref = jsQuery.get('breadcrumbs','urlbase');
	var paramvalue = "";
	var pars = {parameter: paramname
	}; 
	var url = aLinkHref+'SystemParameter.asp'; //url to processor
	new Ajax.Request(url, {
			asynchronous:false,
			encoding:'ISO-8859-1',
			method:'post',
			parameters: pars, 
			onSuccess: function(transport) {
				 paramvalue = transport.responseText;
				 
			}
	});
	return paramvalue;
}

