function setCookie(name, value, expires) {
	var deCookie = name + "=" + escape(value);
	if (expires) {
		expires = expires.toGMTString();
		deCookie += "; expires=";
		deCookie += expires;
	}
	deCookie += "; path=/";
	document.cookie = deCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if(begin == -1) {
		begin = dc.indexOf(prefix); 
		if(begin != 0) {
			return null;
		}
	} else {
		begin = begin + 2; 
	}
	var end = document.cookie.indexOf(";", begin);
	if(end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function delCookie(name) {
	expires = new Date(1970,1,1);
	expires = expires.toGMTString();
	deCookie = name;
	deCookie += "=delete; expires=";
	deCookie += expires;
	document.cookie = deCookie;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.ucfirst = function () {
   return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}

function numberFormat(a, b, c, d) {
	// numberFormat(number, decimals, comma, formatSeparator)
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b){
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if(d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	return f[0] + c + f[1];
}

/* http://cass-hacks.com/articles/code/js_url_encode_decode/ */
function urlencode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

$(document).ready(function () {
	$("div.lijst").each(function() {
		var height_lijst_body = $("div.lijst_body",this).height();
		if(height_lijst_body > 450) {
			$("div.lijst_body",this).css({
				'max-height': '400px',
				'overflow': 'auto',
				'overflow-x': 'hidden'
			});
			var old_width_lijst_body = $("div.lijst_body",this).width();
			var new_width_lijst_body = $("div.lijst_body_lijn",this).width();
			var verschil = old_width_lijst_body - new_width_lijst_body;
			$("div.lijst_head",this).css('margin-right',verschil+'px');
		}
	});

	$("a.winkelwagen").click(function() {
		var l = (screen.width-460)/4;
		var t = (screen.height-200)/4;
		var href = $(this).attr("href");
		var attributen = 'top='+t+',left='+l+',height=200,width=460,';
		attributen += 'location=no,status=no,directories=no,';
		attributen += 'toolbar=no,resizable=yes,scrollbars=yes';
		var venster = window.open(href, 'MyPopup', attributen);
		venster.focus();
		return false;
	});

	$("div.marquee").each(function() {
		var html = $(this).html();
		$(this).html('<marquee>'+html+'</marquee>');
	});

	$("a.afbeeldingLink").click(function() {
		var l = (screen.width-800)/4;
		var h = screen.height/4*3;
		var href = $(this).attr("href");
		var attributen = 'top=80,left='+l+',height='+h+',width=800,';
		attributen += 'location=no,status=no,directories=no,';
		attributen += 'toolbar=no,resizable=yes,scrollbars=yes';
		var venster = window.open(href, 'MyPopup', attributen);
		venster.focus();
		return false;
	});
});
