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;
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
}


var initHeight = new Array();
var slidedownContentBox=new Array();
var slidedownContent=new Array();
var slidedownActive=new Array();
var contentHeight=new Array();
var slidedown_direction=new Array();

var slidedownSpeed = 10; 			// Higher value = faster pull down
var slidedownTimerTick =10;	  // Lower value = faster pull down
var zidx=100;



function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (1) {
			curleft+=obj.offsetLeft;
			if (!obj.offsetParent) {
				break;
			}
			obj=obj.offsetParent;
		}
	} else if (obj.x) {
		curleft+=obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
	curtop += obj.y;
	return curtop;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	//return [curleft,curtop];
	return curleft;
}

function s_SH(nmb,el)
{
	if(initHeight[nmb]== undefined) initHeight[nmb]=0;
	if(initHeight[nmb]==0)  {slidedown_direction[nmb]=slidedownSpeed;}
	else 			{slidedown_direction[nmb]=-1*slidedownSpeed;}

	//alert(document.getElementById('pd_content'+nmb).innerHTML);
	//if (document.getElementById('pd_content'+nmb).innerHTML=='')contentHeight[nmb]=0;

	if(slidedownContentBox[nmb]== undefined){
		slidedownContentBox[nmb] = document.getElementById('pd_box'+nmb);
		slidedownContent[nmb] = document.getElementById('pd_content'+nmb);
		contentHeight[nmb] = document.getElementById('pd_content'+nmb).offsetHeight;
		//alert(slidedownContentBox[nmb].style.width);
		slidedownContentBox[nmb].style.left=findPosX(document.getElementById('_cart'))-290;//slidedownContentBox[nmb].style.width;
	}


	zidx++;	slidedownContentBox[nmb].style.zIndex=zidx;
	slidedownContentBox[nmb].style.visibility='visible';

	slidedownActive[nmb] = true;

	//if(el.innerHTML=='<!--[$local.plus_icon]-->'){el.innerHTML='<!--[$local.minus_icon]-->';el.style.color='blue'} else {el.innerHTML='<!--[$local.plus_icon]-->';el.style.color='black'}
	slidedown_showHide_start(nmb);
	return false;
}

function slidedown_showHide_start(nmb)
{
	if( (!slidedownActive[nmb]) || (slidedownActive[nmb]==undefined) )return;

	initHeight[nmb] = initHeight[nmb]/1 + slidedown_direction[nmb];

	if(initHeight[nmb] <= 0){
		slidedownActive[nmb] = false;
		slidedownContentBox[nmb].style.visibility='hidden';
		initHeight[nmb] = 0;
	}
	if(initHeight[nmb]>contentHeight[nmb]){slidedownActive[nmb] = false;}

	slidedownContentBox[nmb].style.height = initHeight[nmb] + 'px';
	slidedownContent[nmb].style.top = initHeight[nmb] - contentHeight[nmb] + 'px';
	setTimeout('slidedown_showHide_start('+nmb+')',slidedownTimerTick);
}

function setslidedownWidth(nmb,newWidth)
{
	document.getElementById('pd_sl_down'+nmb).style.width = newWidth + 'px';
	document.getElementById('pd_box'+nmb).style.width = newWidth + 'px';
}

var mywin=null;

function	open_win(url)
{
	mywin=window.open(url,'FileWin','left=40,top=40,width=250,height=200,toolbar=0,resizable=1');
	mywin.focus();
	return false;
}

function checksubmit(submitbtn){
	submitbtn.form.submit();
	checksubmit=blocksubmit;
	return false
}

function blocksubmit(){
	if (typeof formerrormsg!="undefined")
	alert(formerrormsg)
	return false
}
//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
}
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
}
//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val){return(val==null);}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
	}
	return true;
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
	}
}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
		}
		return true;
	}
	return false;
}

//-------------------------------------------------------------------
// disallowModify(input_object[,message[,true]])
//   Checks a form field for a value different than defaultValue.
//   Optionally alerts and focuses
//-------------------------------------------------------------------
function disallowModify(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (getInputValue(obj)!=getInputDefaultValue(obj)){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
		}
		setInputValue(obj,getInputDefaultValue(obj));
		return true;
	}
	return false;
}

//-------------------------------------------------------------------
// commifyArray(array)
//   Take an array of values and turn it into a comma-separated string
//-------------------------------------------------------------------
function commifyArray(obj){
	var s="";
	if(obj==null||obj.length<=0){return s;}
	for(var i=0;i<obj.length;i++){
		s=s+((s=="")?"":",")+obj[i].toString();
	}
	return s;
}

//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
		if (obj.options==null) { return null; }
		if(use_default){
			var o=obj.options;
			for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
			return o[0].value;
		}
		if (obj.selectedIndex<0){return null;}
		return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple':
		if (obj.options==null) { return null; }
		var values=new Array();
		for(var i=0;i<obj.options.length;i++) {
			if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
				values[values.length]=obj.options[i].value;
			}
		}
		return (values.length==0)?null:commifyArray(values);
	}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
}

//-------------------------------------------------------------------
// getSingleInputText(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputText(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': 	return "";
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
		if (obj.options==null) { return null; }
		if(use_default){
			var o=obj.options;
			for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].text;}}
			return o[0].text;
		}
		if (obj.selectedIndex<0){return null;}
		return(obj.options.length>0)?obj.options[obj.selectedIndex].text:null;
		case 'select-multiple':
		if (obj.options==null) { return null; }
		var values=new Array();
		for(var i=0;i<obj.options.length;i++) {
			if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
				values[values.length]=obj.options[i].text;
			}
		}
		return (values.length==0)?null:commifyArray(values);
	}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
}


function CC(what)
{
	if (isChanged(what))
	{what.style.background='yellow';
	a='document.getElementById("is"+what.name).value="yes"';
	eval(a);
	}
	else
	{what.style.background='white';
	a='document.getElementById("is"+what.name).value="no"';
	eval(a);
	}
}

function getInputValue(obj) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default);
			if(v!=null){values[values.length]=v;}
		}
		return commifyArray(values);
	}
	return getSingleInputValue(obj,use_default);
}

function getInputDefaultValue(obj){return getInputValue(obj,true);}
function isChanged(obj){return(getInputValue(obj)!=getInputDefaultValue(obj));}

function Check(what,type)
{

	AlertText = "";
	expr = what.value;

	if (type=="mny") {
		RegTest =/^\d*\.\d{2}$/ ;
		AlertText = "2 digits agter decimapl point pls";
	};
	if (type=="mail") {
		RegTest =/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		AlertText = "valid å-mail please";
	};
	if (type=="day") {
		RegTest = /^(\d{4})\-(\d{2})\-(\d{2})$/;
		AlertText = "date in  'yyyy-mm-dd'";
	};
	if (type=="tim") {
		RegTest = /^([0-1]\d|2[0-3]):([0-4]\d|5[0-9]):([0-4]\d|5[0-9])$/;
		AlertText = "time in format 'hh:mm:ss'";
	};
	if (type=="int") {
		RegTest = /^\d*$/;
		AlertText = "digits only";
	};
	if (type=="fin") {
		RegTest = /^([*]|[?]|\d)*$/;
		AlertText = "only digits or  '*' è '?'";
	};
	if (type=="rea") {
		RegTest = /^([.]|\d)*$/;
		AlertText = "only digits or '.'";
	};
	if (type=="txt") {
		RegTest = /^(.*)$/;
		AlertText = "only letters or digits";
	};

	if (isChanged(what)){what.style.background='yellow';needToConfirm = true; };

	if ((AlertText == "") || RegTest.exec(expr))
	{
		return true;
	}

	var t11 =what.id;//=== undefined
	if (!t11) {t11=what.title};
	AlertText='You can use here '+AlertText;
	alert(AlertText);
	what.value =expr;
	what.focus();
	//what.select();
	return false;
};

function changeListingModeLoaded(display)
{
	
	if(document.getElementById('weergavez'))
	{
		k=document.getElementById('weergavez');
	
		for(i=0;i<k.length;i++)
		{
			if(k[i].value==display) k[i].selected=true;
		}
	}
}
