function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if(strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for(var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if(aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
		return strReturn;		
	}
	return false;
} 

function cancelKey(evt) {
	if (evt.preventDefault) {
		evt.preventDefault();
		return false;
	}else{
		evt.keyCode = 0;
		evt.returnValue = false;
	}
}

function stopRKey(evt) {
	var evt=(evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if(evt.keyCode == 13 && node.type!='textarea' && node.type!='text'){
		return false;
	}
}

function get_base_href()	{
	if(window.document.getElementsByTagName('BASE'))	{
		aBase=window.document.getElementsByTagName('BASE');
		for(i=0;i<aBase.length;i++)	{
			if(aBase[i].href)
				return aBase[i].href;
		}
	}
	return '';
}

function setCookie(NameOfCookie, value, expiredays){
	expiredays=2;
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	try {
		myCookie=NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + ExpireDate.toGMTString())+ ";path=/" + "";
		document.cookie = myCookie;
	}
	catch(e){
		alert('Failed to set cookie: '+e.description+ ' ('+NameOfCookie+')');
	}
}

function getCookie(NameOfCookie){
	if(document.cookie.length > 0){ 
	begin = document.cookie.indexOf(NameOfCookie+"="); 
	if(begin != -1){ 
		begin += NameOfCookie.length+1; 
		end = document.cookie.indexOf(";", begin);
		if(end == -1) 
			end = document.cookie.length;
		return unescape(document.cookie.substring(begin, end)); } 
	}
	return null; 
}

function delCookie(NameOfCookie){
	if(getCookie(NameOfCookie)){
		document.cookie = NameOfCookie + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function checkCookie(){
	Set_Cookie('test','none','','/','','');	
	if(!Get_Cookie('test')){
		errorDialog.setTitle('');
		errorDialog.doShow('');
	}else{
			
	}
	
}

function image_swap(id,image){
	if(document.getElementById(id))
		document.getElementById(id).src=image;
}

function CurrencyFormatted(a){var i=parseFloat(a);if(isNaN(i)){i=0.00;}var m='';if(i<0){m='-';}i=Math.abs(i);i=Math.round(i*1000)/1000;i=Math.round(i*100)/100;s=new String(i);if(s.indexOf('.')<0){s+='.00';}if(s.indexOf('.')==(s.length-2)){s+='0';}s=s.replace('.',',');n=s.indexOf(',');if(n>3&&n<6){return m+s.substr(0,(n-3))+'.'+s.substr((n-3));}return m+s;}			
function IsNumeric(T){var V="0123456789.";var C;for(_i=0;_i<T.length;_i++){C=T.charAt(_i);if(V.indexOf(C)==-1){return false;}}return true;}	
function inArray(s,a){_f=false;_k=new Array(false,0);if(a.length==0)return false;for(_i=0;_i<a.length;_i++){_v=a[_i].toString();if(_v==s){_f=true;_k[1]++;if(_k[0]===false)_k[0]=_i;}}if(_f===true)return _k;return false;}
function sortNumber(a,b){return a-b;}
function preload_image(href){image=new Image();image.src=href;}		

errorDialog=function(){
	this.prefix='<li>';
	this.suffix='</li>';
	this.selector='#errorDialog';
	this.msg=null;
	this.returnURL=false;
	this.set=function(msg){
		this.msg=msg;
		$(this.selector+" .content").append(this.prefix+msg+this.suffix);
	}
	this.setTitle=function(Title){
		$(this.selector+" h2").html(Title);
	}
	this.reset=function(){
		$(this.selector+" .content").empty();
	}
	this.show=function(){
		var _this=this
		$(function(){
			$(_this.selector+" .ui-dialog-content").css('height',$(_this.selector+" .content").height());
			var buttons=[];
			buttons.push( {text:"OK",click:function(){$(this).dialog("close");}} );
			if(_this.returnURL!=false){
				buttons.push( {text:"Terug",click:function(){document.location.href=_this.returnURL}} );
			}
			$(_this.selector).dialog({
				closeOnEscape: true,
				dialogClass: "classError",
				draggable: false,
				resizable: false,
				width:475,
				buttons:buttons,
				position: 'top'
			});
			
			$(_this.selector).dialog("open");
			$('.ui-dialog').css('position','absolute').center();
		});			
	}
	this.doShow=function(msg){
		this.reset();
		this.set(msg);
		this.show();
	}

}
var errorDialog=new errorDialog();

// AF20100312: try to parse a XMLHttpRequest into a DOM parser
// BF20111216: fixed, http://www.w3schools.com/dom/dom_parser.asp 
function XMLDOM(xmlRpc){
	if(window.DOMParser){
  		parser=new DOMParser();
  		xmlDoc=parser.parseFromString(xmlRpc.responseText,"text/xml");
	}else{ // Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(xmlRpc.responseText);
	} 
	// backward comp, we just need an object with the responseXML as xmldoc  
	var rpc=new Object();
	rpc.responseXML=xmlDoc;
	return rpc;
}

// AF20100407: get scroll height 
function getScrollHeight() {
	var scrollHeight,
		offsetHeight;
	// handle IE 6
	if ($.browser.msie && $.browser.version < 7) {
		scrollHeight = Math.max(
			document.documentElement.scrollHeight,
			document.body.scrollHeight
		);
		offsetHeight = Math.max(
			document.documentElement.offsetHeight,
			document.body.offsetHeight
		);

		if (scrollHeight < offsetHeight) {
			return $(window).height();
		} else {
			return scrollHeight;
		}
	// handle "good" browsers
	} else {
		return $(document).height();
	}
}

// mostly used for radio groups
var inputGroups={
	items:[],
	add:function(radio){
		radio.data={};
		this.items.push(radio);
	},
	set:function(name,property,value){
		for(i=0;i<this.items.length;i++){
			if(this.items[i].name==name){
				this.items[i].data[property]=value;
			}
		}
	},
	get:function(name,property){
		for(i=0;i<this.items.length;i++){
			if(this.items[i].name==name && this.items[i].data[property]!==undefined){
				return this.items[i].data[property];
			}
		}
		return false;
	}
}

// AF20100407: get scroll width
function getScrollWidth() {
	var scrollWidth,
		offsetWidth;
	// handle IE 6
	if ($.browser.msie && $.browser.version < 7) {
		scrollWidth = Math.max(
			document.documentElement.scrollWidth,
			document.body.scrollWidth
		);
		offsetWidth = Math.max(
			document.documentElement.offsetWidth,
			document.body.offsetWidth
		);

		if (scrollWidth < offsetWidth) {
			return $(window).width();
		} else {
			return scrollWidth;
		}
	// handle "good" browsers
	} else {
		return $(document).width();
	}
}

function set_id_values(prefix,object){
	if(typeof(object)=='object'){
		for(key in object){
			if(document.getElementById(prefix+key)){
				document.getElementById(prefix+key).innerHTML=object[key];
			}
		}
	}
}

function set_form_values(id,object){
	if(document.getElementById(id) && typeof(object)=='object'){
		form=document.getElementById(id);
		for(key in object){
			if(form.elements[key]){
				form.elements[key].value=object[key];
			}
		}
	}
}
function getUrlVars(){var a=[],hash;var b=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');for(var i=0;i<b.length;i++){hash=b[i].split('=');a.push(hash[0]);a[hash[0]]=hash[1]}return a}
function fieldOnFocus(element){if(element.value==element.defaultValue){element.value='';}}
function fieldOnBlur(element){if(element.value==''){element.value=element.defaultValue;}}
function array_key_exists(a,b){if(!b||(b.constructor!==Array&&b.constructor!==Object)){return false}return a in b}
function urldecode(a){return decodeURIComponent((a+'').replace(/\+/g,'%20'))}
function implode(g,p){var i,r,G='';if(arguments.length===1){p=g;g='';}if(typeof(p)==='object'){if(p instanceof Array){return p.join(g);}else{for(i in p){r+=G+p[i];G=g;}return r;}}else{return p;}}

