var onMouseOutOpacity = 0.4;

$j(document).ready(function() {
	
	$j('#display_cart').bind('click', function() {

		showCart();
    });

	$j('#close_cart').click(function() {
		
		hideCart();
    });

	if(window.id_shop_type == undefined){
		
		id_shop_type	= 1;
	}
	
	//console.log(id_shop_type);

	viewCart(false, id_shop_type);
	
	/* superfish content pagina */
	$j('ul#nav_menu_top').superfish({ 
		delay:       500,
		animation:   {opacity:'show',height:'show'},
		speed:       'fast',
		autoArrows:  true,
		dropShadows: true
	});
	
	$j('ul#nav_menu_topnav li').hover(function(){
		$j(this).addClass('sfHover2');
	},
	function(){
		$j(this).removeClass('sfHover2');
	});
	/* */

	$j('ul#nav_menu_top_superfish').superfish({ 
		delay:       500,
		animation:   {opacity:'show',height:'show'},
		speed:       'fast',
		autoArrows:  true,
		dropShadows: true
	});
	
	$j('ul#nav_menu_topnav li').hover(function(){
		$j(this).addClass('sfHover2');
	},
	function(){
		$j(this).removeClass('sfHover2');
	});
	
	if(typeof jQuery('.merken_jcarousel_slider').jcarousel == 'function') {
		
	$j('.merken_jcarousel_slider').removeClass('mycarousel_width');
	jQuery('.merken_jcarousel_slider').jcarousel({
		scroll: 1,
		auto: 1,
		wrap: 'last'
	});
	
	}

	if(typeof jQuery('.merken_jcarousel_ticker').jcarousel == 'function') {
		
	$j('.merken_jcarousel_ticker').removeClass('mycarousel_width');
	jQuery('.merken_jcarousel_ticker').jcarousel({
		scroll: 1,
		auto: 0,
		wrap: 'last'
	});
	
	}

	if(window.zoekopdracht_html == undefined){
		
		zoekopdracht_html	= 'Zoekopdracht';
	}
	
	$j("#zoek").Watermark(zoekopdracht_html);	
	$j("#zoek_module_blok").Watermark(zoekopdracht_html);	
	
	$j('#zoek').attr('autocomplete', 'off');
	$j('#zoek_module_blok').attr('autocomplete', 'off');
	
	//$j('#breadcrumb_middle a:last').addClass('active_menu_breadcrumb');
	
	$j('#bel_mij_terug').click(function(){
		
		var action = $j(this).attr('title');
		
		if(action == 'close'){
			
			var action = $j(this).attr('title', 'open');
			$j('#div_bel_mij_terug').slideDown(500);
		}
		if(action == 'open'){
			
			var action = $j(this).attr('title', 'close');
			$j('#div_bel_mij_terug').slideUp(500);
		}		
	});
	
	$j('#button_zoek').click(function() {
		
		searchHeader();
	});
	
	
	$j('#zoek').keyup(function(e) {
		
		if (e.which == 13) {
			
			searchHeader();
		}
	});

	$j('#button_zoek_module_blok').click(function() {
		
		searchModuleBlok();
	});
	
	
	$j('#zoek_module_blok').keyup(function(e) {
		
		if (e.which == 13) {
			
			searchModuleBlok();
		}
	});

	$j('#button_zoek_venster').click(function() {
		
		searchVenster();
	});
	
	
	$j('#zoek_venster').keyup(function(e) {
		
		if (e.which == 13) {
			
			searchVenster();
		}
	});

	$j('#button_zoek_venster_bottom').click(function() {
		
		searchVensterBottom();
	});
	
	
	$j('#button_zoek_venster_bottom').keyup(function(e) {
		
		if (e.which == 13) {
			
			searchVensterBottom();
		}
	});

//	$j('#aantal_order').jStepper({decimalSeparator:"."});
//	//$j('#hoeveelheid_order').numeric('.');


	$j("#open").click(function(){
		$j("div#panel").slideDown("slow");
	
	});	
	
	// Collapse Panel
	$j("#close").click(function(){
		$j("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$j("#toggle a").click(function () {
		$j("#toggle a").toggle();
	});	

	$j('.load-1, .load-2').bstip({
		color:"bswrap",
		type:"menu",
		tack:50,
		hook:"top-mid",
		sticky:"none"
	});
	
	$j(".simple-tooltip").simpletooltip();

	$j('#thumbs-adv ul.thumbs li').addClass('opacity_thumbs-adv')
		.hover(
		function () {
			$j(this).not('.selected').removeClass('opacity_thumbs-adv');
		}, 
		function () {
			$j(this).not('.selected').addClass('opacity_thumbs-adv');
	});
		
	$j('#thumbs-adv ul.thumbs li:first').removeClass('opacity_thumbs-adv');	

	loadChangeProductAttribuut();
		
	/**/
	$j('.mainright_product_content_product_videos_container_right ul li').click(function() {
		
		$j('.mainright_product_content_product_videos_container_right ul li').each(function() {
			
			$j(this).removeClass('video_preview_active');
		});
		
		$j(this).addClass('video_preview_active');
		var video_id	= $j(this).attr('id').replace('video_', '');
		var video_type	= $j('#video_type_'+video_id+'').val();
		
		launchVideoProduct(video_id, video_type, 'true');
	});	

	$j('.movie_container_right ul li').click(function() {
		
		$j('.movie_container_right ul li').each(function() {
			
			$j(this).removeClass('video_preview_active');
		});
		
		$j(this).addClass('video_preview_active');
		var video_id	= $j(this).attr('id').replace('video_', '');
		var video_type	= $j('#video_type_'+video_id+'').val();
		
		launchVideoProduct(video_id, video_type, 'true');
	});	

	if(window.scroll_ticker == undefined){
		
		scroll_ticker	= 0;
	}
	if(scroll_ticker == 1){
	
		$j("ul#nav_menu_top").liScroll({travelocity: 0.10});
	}
	
	//$j("ul.merken_scroll_ticker").liScroll({travelocity: 0.10});

//		$j('.merken_jcarousel').removeClass('mycarousel_width');
//		jQuery('.merken_jcarousel').jcarousel({
//			scroll: 1
//		});

	if(window.slider_index_products == undefined){
		
		slider_index_products	= 0;
	}
	if(slider_index_products == 1){
	
		$j('.carousel_product_index').removeClass('mycarousel_width');
		jQuery('.carousel_product_index').jcarousel({
			scroll: 1
		});
		
		//if(jQuery.isFunction($j.fn.equalHeights)) {
	
			//$j(".mycarousel_img").equalHeights();
		//}
	}

	$j('body').find('img').each(function() {
										 
		$j(this).attr('oncontextmenu', 'return false;');
	});

});

function showCart() {
			
	$j('#winkelwagen_box').slideToggle(750, function(){
		
	});
	//setTimeout("$j('#close_cart').trigger('click');", 4000);
}

function hideCart() {

	if($j("#winkelwagen_box").is(":visible")) {
		
		$j("#winkelwagen_box").slideToggle("slow", function(){
			
		});

	}else{
	
	}
}

function loadChangeProductAttribuut() {

	$j('#aantal_order').keyup(function() {
		
		checkNumber('aantal_order');
		calculatePrijsModule();
		
		var aantal				= $j('#aantal_order').val();
		var prijs_per_hidden	= $j('#prijs_per_hidden').val();
		var inhoud_hidden		= $j('#inhoud_hidden').val();
		
		var totaal_hoeveelheid	= (aantal * inhoud_hidden);
		
		$j('#aantal').val(aantal);
		$j('#hoeveelheid_order').val(totaal_hoeveelheid);
		
		calculatePrijsModule();
	});
	
	$j('#hoeveelheid_order').keyup(function() {
		
		checkNumber('hoeveelheid_order');
		calculatePrijsModule();
		
		var hoeveelheid_order		= $j('#hoeveelheid_order').val();
		var prijs_per_hidden		= $j('#prijs_per_hidden').val();
		var inhoud_hidden			= $j('#inhoud_hidden').val();

		var afronden_aantal			= $j('#afronden_aantal').val();
		var afronden_hoeveelheid	= $j('#afronden_hoeveelheid').val();

		if(afronden_aantal == 0){
			
			var aantal = Math.ceil(hoeveelheid_order / parseFloat(inhoud_hidden.replace(/^[^\d.]*/,'')));
		}else{
			
			var aantal = hoeveelheid_order / parseFloat(inhoud_hidden.replace(/^[^\d.]*/,''));
		}

		$j('#aantal_order').val(aantal);
		$j('#aantal').val(aantal);
		
		calculatePrijsModule();
	});
	
	$j('#lengte_order, #breedte_order').keyup(function() {
		
		checkNumber('lengte_order');

		var lengte_order		= eval($j('#lengte_order').val());
		var breedte_order		= eval($j('#breedte_order').val());

		if(isNaN(lengte_order)){
			
			lengte_order		= 0;
		}
		if(isNaN(breedte_order)){
			
			breedte_order		= 0;
		}
		
		var hoeveelheid			= eval(lengte_order * breedte_order);
		
		$j('#hoeveelheid_order').val(hoeveelheid.toFixed(0));
		
		$j('#hoeveelheid_order').trigger('keyup');
	});

	$j('.product_detail_right_box select').change(function() {
		
		selectedCombination['input']	= 'select';
		findAttribuutCombinatie();
	});	
	
	$j('.product_detail_right_box input[type="radio"]').change(function() {
		
		selectedCombination['input']	= 'radio';
		findAttribuutCombinatie();
	});		

	$j('.product_detail_right_box_attributen select').change(function() {
		
		updatePriceProductAttribuut();
		
	});	

	$j('.product_detail_right_box_attributen input[type="radio"]').change(function() {
		
		updatePriceProductAttribuut();
		
	});	

	$j('.product_detail_right_box_attributen input[type="checkbox"]').change(function() {
		
		updatePriceProductAttribuut();
		
	});	

	$j('.product_detail_right_box_attributen input[type="text"]').keyup(function() {
		
		updatePriceProductAttribuut();
		
	});	

	$j('.product_detail_right_box_attributen textarea').keyup(function() {
		
		updatePriceProductAttribuut();
		
	});	

	$j('.colorVariations_1 li').click(function() {
		
		var id	= $j(this).attr('id');
		var id	= id.replace("color_picker_", "");

		$j('#select_color').val(id);
		
		findAttribuutCombinatie();
	});

	$j('.maatVariations_1 li').click(function() {
		
		var id	= $j(this).attr('id');
		var id	= id.replace("maat_picker_", "");

		$j('#select_maat').val(id);
		
		findAttribuutCombinatie();
	});

	$j('.colorVariations_2 li').click(function() {
		
		if($j(this).attr('class') != 'disabled'){
			
			changeColorPickerId($j(this).attr('id'));
		}
	});
	
	$j('.maatVariations_2 li').click(function() {
		
		if($j(this).attr('class') != 'disabled'){
			
			changeMaatPickerId($j(this).attr('id'));
		}
	});
}

Number.prototype.moneyFormat = function (pCurrency) { 
    var firstPart = String (this).split (".")[0]; 
    var secondPart = String (this).split (".")[1]; 
    while (secondPart.length < 2) { 
        secondPart += "0"; 
    } 
    if (secondPart == undefined) { 
        secondPart = "00"; 
    } 
    var tmpArr = firstPart.split (""); 
    for (var i in tmpArr) { 
        if ((tmpArr.length - i) % 4 == 3 && i > 0) { 
            tmpArr.splice (i, 0, "."); 
        } 
    } 
    return tmpArr.join ("") + "," + secondPart + " " + pCurrency; 
} 

Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

Number.prototype.toMoney = function() {
    //
    var nachkommastellen = arguments[0] == undefined ? 2 : arguments[0];
    var nachkommatrennzeichen = arguments[1] == undefined ? "." : arguments[1];
    var tausendtrennzeichen = arguments[2] == undefined ? "." : arguments[2];
    var tausendstelle = arguments[3] == undefined ? 3 : arguments[3];
    var waehrung = arguments[4] == undefined ? "" : arguments[4];
    
	var this_tmp	= this.toFixed(2);
	var str_tmp 	= String (this_tmp).split('.');
	
	//alert(this);
    //var zahl = Math.floor(this+0.01).toString();

	if(str_tmp[1] != undefined){
		
		//alert(str_tmp[1].length);
		if(str_tmp[1].length > 2){
			
			var zahl = Math.round(this).toString();
		}else{
			
			var zahl = str_tmp[0];
		}
	}
	if(str_tmp[1] == undefined){
		
		var zahl = this;
	}
	
	//var zahl = '1.325';
	
	//alert(str_tmp[1]+'=='+str_tmp[0]+'==='+this_tmp);

	//
    var i = tausendstelle;
    while (zahl.length>i) {
        tmp = zahl.substring(0, zahl.length-i) + tausendtrennzeichen + zahl.substring(zahl.length-i, zahl.length);
        zahl = tmp;
        i += (tausendstelle + 1);
    }
    //
	
    var ausgabe = zahl;
    ausgabe += nachkommatrennzeichen;
    ausgabe += Math.round(this*Math.pow(10, nachkommastellen)).toString().slice(-nachkommastellen);
    ausgabe += " "+waehrung;
    //
	
	if(eval(ausgabe) == '0.0'){
		
		ausgabe	= eval('0.00');
	}
	

    return ausgabe;
};

function closePopupMelding() {
	
	$j('#popup_melding').empty();
}

function IsNumeric(sText){
	
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function calculatePrijsModule() {
	
	var aantal		 		= $j('#aantal').val();
	var aantal_order 		= $j('#aantal_order').val();
	var prijs_per_hidden	= $j('#prijs_per_hidden').val();
	
	var totaal_prijs		= (aantal_order * eval(prijs_per_hidden.replace(',','.')));

	if(isNaN(totaal_prijs)){
			
		return;
	}
	
	var afronden_aantal			= $j('#afronden_aantal').val();
	var afronden_hoeveelheid	= $j('#afronden_hoeveelheid').val();
	
	var hoeveelheid_order		= $j('#hoeveelheid_order').val();
	var aantal_order 			= $j('#aantal_order').val();
	
	var hoeveelheid_orderArray 	= hoeveelheid_order.split('.');
	var aantal_orderArray 		= aantal_order.split('.');

	if(aantal_orderArray[1] != undefined){
		
		if(aantal_orderArray[1].length > 0){
		
			var a = aantal_orderArray[1].substr(0,afronden_aantal);
			var b = aantal_orderArray[1].replace(aantal_orderArray[1],a);
			var c = aantal_orderArray[0]+'.'+b;
			
			if(afronden_aantal == 0){
				
				c = c.replace('.','');
			}
		}
		
		$j('#aantal_order').val(c);
	}

	if(hoeveelheid_orderArray[1] != undefined){
		
		if(hoeveelheid_orderArray[1].length > 0){
		
			var a = hoeveelheid_orderArray[1].substr(0,afronden_hoeveelheid);
			var b = hoeveelheid_orderArray[1].replace(hoeveelheid_orderArray[1],a);
			var c = hoeveelheid_orderArray[0]+'.'+b;

			if(afronden_hoeveelheid == 0){
				
				c = c.replace('.','');
			}
		}
		
		$j('#hoeveelheid_order').val(c);
	}
		
	totaal_prijs	= eval(totaal_prijs);
	totaal_prijs 	= (totaal_prijs).formatMoney(2, ',', '.');
		
	$j('#totaalprijs_calc_html').html(valuta+' '+totaal_prijs);
}

function checkNumber(textBox) {
	
	var textBoxId			= textBox;
	var textBox 			= document.getElementById(""+textBox+"");
	var textBoxValue_tmp	= textBox.value;
	var textBoxValue		= textBoxValue_tmp.replace(',','.');
	
	$j('input[id="'+textBoxId+'"]').val(textBoxValue);
	
	//alert(textBox.value+'=='+textBoxValue);
	
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		
		textBox.value = textBox.value.substring(0, textBox.value.length - 1);
	}

	textBox.value = trim(textBox.value);

/*	if (textBox.value.length == 0) {
		textBox.value = 0;		

	} else {
		textBox.value = parseInt(textBox.value);
	}*/

	return textBox.value;
}

function checkNumberPrecision(textBox, precision) {
	
	var textBoxId			= textBox;
	var textBox 			= document.getElementById(""+textBox+"");
	var textBoxValue_tmp	= textBox.value;
	var textBoxValue		= textBoxValue_tmp.replace(',','.');

	if(precision == 1){
		
		var textBoxValue		= textBoxValue.replace('.','');
	}
	if(precision == 2){
	
		var textBoxValue_split	= textBoxValue.split(".");
		
		textBoxValue			= textBoxValue_split[0];
		if(textBoxValue_split[1] != undefined){
			
			textBoxValue		= textBoxValue_split[0]+'.'+textBoxValue_split[1].substring(0, 1);
		   	//console.log(textBoxValue_split[1]);
		}
	}
	if(precision == 3){
		
		var textBoxValue_split	= textBoxValue.split(".");
		
		textBoxValue			= textBoxValue_split[0];
		if(textBoxValue_split[1] != undefined){
			
			textBoxValue		= textBoxValue_split[0]+'.'+textBoxValue_split[1].substring(0, 2);
		   	//console.log(textBoxValue_split[1]);
		}
	}

	$j('input[id="'+textBoxId+'"]').val(textBoxValue);
	
	//alert(textBox.value+'=='+textBoxValue);
	
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		
		textBox.value = eval(textBox.value.substring(0, textBox.value.length - 1));
	}

	textBox.value = trim(textBox.value);

/*	if (textBox.value.length == 0) {
		textBox.value = 0;		

	} else {
		textBox.value = parseInt(textBox.value);
	}*/

	return textBox.value;
}

//function checkNumber(textBox) {
//	
//	var textBox = document.getElementById(""+textBox+"");
//
//	while (textBox.value.length > 0 && isNaN(textBox.value)) {
//		
//		textBox.value = textBox.value.substring(0, textBox.value.length - 1);
//	}
//
//	textBox.value = trim(textBox.value);
//
///*	if (textBox.value.length == 0) {
//		textBox.value = 0;		
//
//	} else {
//		textBox.value = parseInt(textBox.value);
//	}*/
//
//	return textBox.value;
//}

function checkOrderNumber(textBox, type) {
	
	var textBoxId			= textBox;
	var textBox 			= document.getElementById(""+textBox+"");
	var textBoxValue_tmp	= textBox.value;
	var textBoxValue		= textBoxValue_tmp.replace(',','.');
	
	//Alleen nummers geen cijfers achter de punt
	if(type == 1){
		
		var textBoxValue		= textBoxValue.replace('.','');
	}
	if(type == 2){
	
		var textBoxValue_split	= textBoxValue.split(".");
		
		textBoxValue			= textBoxValue_split[0];
		if(textBoxValue_split[1] != undefined){
			
			textBoxValue		= textBoxValue_split[0]+'.'+textBoxValue_split[1].substring(0, 1);
		   	//console.log(textBoxValue_split[1]);
		}
	}
	if(type == 3){
		
		var textBoxValue_split	= textBoxValue.split(".");
		
		textBoxValue			= textBoxValue_split[0];
		if(textBoxValue_split[1] != undefined){
			
			textBoxValue		= textBoxValue_split[0]+'.'+textBoxValue_split[1].substring(0, 2);
		   	//console.log(textBoxValue_split[1]);
		}
	}
	
	$j('input[id="'+textBoxId+'"]').val(textBoxValue);
	
	//alert(textBox.value+'=='+textBoxValue);
	
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		
		textBox.value = textBox.value.substring(0, textBox.value.length - 1);
	}

	textBox.value = trim(textBox.value);
	
	$j('input[id="'+textBoxId+'"]').blur(function() {
												  
		if(eval(textBox.value) < eval($j('#min_'+textBoxId+'').val())){
			
			alert('Minimaal aantal te bestellen is '+$j('#min_'+textBoxId+'').val()+'');
			textBox.value = trim($j('#min_'+textBoxId+'').val());
			return;
		}
	
		if(eval(textBox.value) > eval($j('#max_'+textBoxId+'').val())){
			
			alert('Maximaal aantal te bestellen is '+$j('#max_'+textBoxId+'').val()+'');
			textBox.value = trim($j('#max_'+textBoxId+'').val());
			return;
		}
	});
	
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		

	} else {
		textBox.value = parseInt(textBox.value);
	}*/

	return textBox.value;
}

function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  value = value.replace(/^\s+|\s+$/g,'');
  return value;
}

function changeUrlOption(value) {
	
	if(value != ''){
		
		window.location = value;
	}
}

function searchHeader() {

	var zoek = $j('#zoek').val();
	var url		= root_site+'zoeken/?searchterm='+zoek+'';
	
	if(vars_lang != 'nl'){
		
		url		= root_site+vars_lang+'/zoeken/?searchterm='+zoek+'';
	}
	
	if(shop_type == 'zakelijk'){
		
		url		= root_site+'zakelijk/zoeken/?searchterm='+zoek+''
	}
	
	window.location = url;
}

function searchModuleBlok() {

	var zoek = $j('#zoek_module_blok').val();
	var url		= root_site+'zoeken/?searchterm='+zoek+'';

	if(vars_lang != 'nl'){
		
		url		= root_site+vars_lang+'/zoeken/?searchterm='+zoek+'';
	}

	if(shop_type == 'zakelijk'){
		
		var url		= root_site+'zakelijk/zoeken/?searchterm='+zoek+''
	}
	
	window.location = url;
}

function searchVenster() {

	var zoek 	= $j('#zoek_venster').val();
	var url		= root_site+'zoeken/?searchterm='+zoek+'';

	if(vars_lang != 'nl'){
		
		url		= root_site+vars_lang+'/zoeken/?searchterm='+zoek+'';
	}

	if(shop_type == 'zakelijk'){
		
		url		= root_site+'zakelijk/zoeken/?searchterm='+zoek+''
	}
	
	window.location = url;
}

function searchVensterBottom() {

	var zoek 	= $j('#zoek_venster_bottom').val();
	var url		= root_site+'zoeken/?searchterm='+zoek+'';

	if(vars_lang != 'nl'){
		
		url		= root_site+vars_lang+'/zoeken/?searchterm='+zoek+'';
	}

	if(shop_type == 'zakelijk'){
		
		url		= root_site+'zakelijk/zoeken/?searchterm='+zoek+''
	}
	
	window.location = url;
}

function changePerPage(url,path) {
	
	var per_page	= $j('#pagenavPerpage :selected').val();
		
//	if(per_page == 5){
//		
//		var url_redirect = url;
//	}
//	if(per_page > 5){
//		
//		var url_redirect = url+path+'_1-'+per_page+'.htm';
//	}	
	
	var url_redirect = url+path+'_1-'+per_page+'.htm';
	
	window.location = url_redirect;
}

function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  value = value.replace(/^\s+|\s+$/g,'');
  return value;
}

function str_replace(search, replace, subject, count) {
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function validatePhoneNumber(value){
//	jQuery(function($j){
//	   $j("#"+value+"").mask("9999999999");
//	});
}

function validatePostcode(value){
	jQuery(function($j){
	   $j("#"+value+"").mask("9999 aa",{placeholder:" "});
	});
}


function validateKvkNumber(value){
	jQuery(function($j){
	   $j("#"+value+"").mask("99 99 99 99");
	});
}

function validateEmail(id){
	
	var value = $j('#'+id+'').val();

	 if(isValidEmailAddress(value)){
	 	
		$j('#'+id+'').removeClass('inputfield_error');
		return true;
	 }else{
	 	
		alert("Let op!\n\nEr is geen geldig e-mail adres ingevuld!");
		$j('#'+id+'').addClass('inputfield_error');
		
		return false;
	 }  
	
}

function isAlphanumeric(id){
	
	var value_id = $j('#'+id+'').val();
	
	var alphaExp = /^[zA-Z-0-9a]+$/;
	
	var elem = document.getElementById('adres');
	
	if(elem.value.match(alphaExp)){
		
		return true;
	}else{

		return false;
	}
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	
	return pattern.test(emailAddress);
}

function checkNumberJquery(textBoxName) {
	
	var textBox = $j('input[name="'+textBoxName+'"]').val();

	while (textBox.length > 0 && isNaN(textBox)) {
		
		textBox = textBox.substring(0, textBox.length - 1);
		
	}
	
	textBox = trim(textBox);
	
	$j('input[name="'+textBoxName+'"]').val(textBox);
	
	//$j($j('input[name="'+textBox+'"]')).autotab({ target: 'textBox', format: 'numeric' });
}

function viewMovie(){
	
	$j('#movie_div').css('display', 'block');
	$j('html,body').scrollTo( $j('div#header'), 800 );
}

function closeMovie(){
	
	$j('#movie_div').css('display', 'none');
}

function viewMovieOverzicht(id){
	closeMovieOverzicht();
	$j('#movie_div_'+id+'').css('display', 'block');
}

function closeMovieOverzicht(){
	
	$j('.movie_divs').each(function() {
									
		$j(this).css('display', 'none');								
	});
}

function setQuantity(aantal,minimale_aantal,maximale_aantal, action,id){
	
	if($j('#aantal').val() == ''){
		
		$j('#aantal').val('0');
	}
	
	var huidige_aantal	= eval($j('#'+id+'').val());
		
	if(action == 'less'){
		if(huidige_aantal > minimale_aantal){
			var new_aantal		= eval(huidige_aantal - eval(aantal));
		}
	}
	if(action == 'more'){
		var new_aantal		= eval(huidige_aantal + eval(aantal));
	}
						
	$j('#'+id+'').val(new_aantal);
}

function changeImg(img_obj) {
	
	var height_img	= $j('#product_detail_image img').height();
	
	//$j('#product_detail_image').css('height', height_img + 6);
	
	//$j('#product_detail_image-loading').css('display', 'block');
	$j('#product_detail_thumbs img').each(function() {
			
		$j(this).removeClass('product_detail_thumbs_active');
	});
		
	$j(img_obj).addClass('product_detail_thumbs_active');
		
	var img_src = $j(img_obj).attr('alt');
		
	var a = $j('#product_detail_image img').attr('src');
		
	$j('#product_detail_image img').fadeOut('fast', function(){
        	
		$j(this).attr('src', url1+img_src);
        $j(this).load(function() {
        $j(this).fadeIn('fast')
        $j('#product_detail_image-loading').css('display', 'none');
		});
		
    });

	$j('#product_detail_image a').attr({ href : url3+img_src});
	$j('#product_detail_image-vergroot a').attr({ href : url3+img_src});
	$j('#product_detail_img_vergroot a').attr({ href : url3+img_src});
}

function in_array(value, array)
{
	//alert(array);
	for (var i in array) if (array[i] == value) return true;
	return false;
}

function loadAttribuutCombinatie() {

	if(attribuutList[attribuut_id] == undefined){
		
		selectedCombination['available'] = false;
		updateDisplay(attribuut_id);			
		return;
	}
	
	selectedCombination['combination']				= attribuutList[attribuut_id][combination];
	selectedCombination['id_product_attribuut']		= attribuutList[attribuut_id][id_product_attribuut];
	
	for(i in selectedCombination['combination']){
		
		var attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
		
		if(attr_disabled == undefined){
					
			attr_disabled = $j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+attribuut_id+'"]').attr('disabled');
		}
		if(attr_disabled == undefined){
					
			attr_disabled = $j('.product_detail_right_box').find('input[type="radio"][value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
		}

		if(attr_disabled == undefined){
					
			attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').prop('disabled');
		}

		if(attr_disabled == false){
				
			$j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('selected', true);

			//$j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+selectedCombination['id_product_attribuut']+'"]').attr('checked', true);
			$j('.product_detail_right_box').find('input[type="radio"][value="'+selectedCombination['combination'][i]+'"]').attr('checked', true);
			$j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+attribuut_id+'"]').attr('checked', true);			
		}
	}
	
	findAttribuutCombinatie();
}

function setAttribuutCombinatie() {
	
	var teller_standaard	= 0;
	for(x in attribuutList) {
		
		if(attribuutList[x][standaard] == 1){
			teller_standaard++;
			selectedCombination['combination']		= attribuutList[x][combination];
						
			for(i in selectedCombination['combination']){
				
				var attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
				
				if(attr_disabled == undefined){
					
					attr_disabled = $j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+attribuut_id+'"]').attr('disabled');
				}
				if(attr_disabled == undefined){
							
					attr_disabled = $j('.product_detail_right_box').find('input[type="radio"][value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
					
					if(selectedCombination['input'] == 'radio'){
						
						$j('.product_detail_right_box').each(function(){
																	  
							$j(this).find('input[type="radio"]:first').attr('checked', true);
						});
					}
				}
				if(attr_disabled == undefined){
					
					attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').prop('disabled');
				}
				//alert(attr_disabled);
				
				if(attr_disabled == false){
					
					$j('.product_detail_right_box select :selected').each(function() {
						
						var selected_checked = $j(this).val();

						if(selected_checked != ''){
							
							$j(this).attr('selected', true);
						}else{
							
							$j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('selected', true);
							//$j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('selected', true);
						}
					
					});
					//alert($j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').val());
					
					//$j('#radio_attribuut_option_standaard_1').find('input[type="radio"]').attr('checked', true);
					$j('.product_detail_right_box').each(function(){
																	  
						$j(this).find('input[type="radio"]:first').attr('checked', true);
					});
				}
				if(attr_disabled == true){
					
					$j('.product_detail_right_box select').find('option:next').attr('selected', true);
				}
			}
		}
	}
	
	if(teller_standaard == 0){
		
		$j('.product_detail_right_box select').find('option:next').attr('selected', true);
	}
	
	findAttribuutCombinatie();
}

function findAttribuutCombinatie() {
	
	var findCombinationArray 			= new Array();
	
	if(selectedCombination['input'] == 'select'){
		
		$j('.product_detail_right_box select').each(function(){
			
//			findCombination	= $j(this).val();
//			
//			if(findCombination != ''){	
//					
//				findCombinationArray.push(findCombination);
//			}
			findCombination = trim($j(this).val());	
			
			//findCombination = findCombination_tmp.split("-");
			var match = /,/.test(findCombination)
			
			if(match == false){
				
				findCombination = Array(findCombination);
			}
			
			if(findCombination.length > 1){
				
				id_attribuut_groep	= findCombination.split("|");
				id_attribuut_groep	= id_attribuut_groep[1];
				
				$j('#hidden_attribuut_options_'+id_attribuut_groep+' input[type="hidden"]').each(function(){
					
					var id = $j(this).val();
					findCombinationArray.push(id);
				});
				
			}else{
				
				if(findCombination != ''){	
					
					findCombinationArray.push(findCombination);
				}
			}
		});
	}
	if(selectedCombination['input'] == 'radio'){
		
		$j('.product_detail_right_box input[type="radio"]:checked').each(function(){
			//alert($j(this).val());
			findCombination = trim($j(this).val());	
			
			//findCombination = findCombination_tmp.split("-");
			var match = /,/.test(findCombination)
			
			if(match == false){
				
				findCombination = Array(findCombination);
			}
			
			if(findCombination.length > 1){
				
				id_attribuut_groep	= findCombination.split("|");
				id_attribuut_groep	= id_attribuut_groep[1];
				
				$j('#hidden_attribuut_options_'+id_attribuut_groep+' input[type="hidden"]').each(function(){
					
					var id = $j(this).val();
					findCombinationArray.push(id);
				});
				
			}else{
				
				if(findCombination != ''){	
					
					findCombinationArray.push(findCombination);
				}
			}
		});
	}
	
	if(selectedCombination['input'] == 'array'){
		
		var a = attribuutList[attribuut_id][combination];
		findCombinationArray = a;
	}
	//alert(selectedCombination['input']);
	for(x in attribuutList) {
		
		check = 0;
		
		for(i in attribuutList[x][combination]){
			//alert(attribuutList[x][combination][i]+'='+findCombinationArray);
			if(in_array(attribuutList[x][combination][i],findCombinationArray)) {
				
				check++;
				//alert(check);
			}
		}

		if(selectedCombination['input'] == 'array'){
			
			var x = attribuut_id;
		}

		//alert(check+'='+findCombinationArray.length+'='+attribuutList[x][combination].length);
		//alert(attribuutList[x][combination].length);
		if(check == findCombinationArray.length && findCombinationArray.length == attribuutList[x][combination].length){
		//alert(x);	
			
			selectedCombination['available'] 			= true;
			selectedCombination['artikelnummer']		= attribuutList[x][artikelnummer];
			selectedCombination['id_combination']		= attribuutList[x][id_product_attribuut];
			selectedCombination['afbeelding']			= attribuutList[x][afbeelding];	
			selectedCombination['korting_prijs']		= attribuutList[x][korting_prijs];
			selectedCombination['prijs_default']		= attribuutList[x][prijs_default];
			selectedCombination['new_prijs']			= attribuutList[x][new_prijs];
			selectedCombination['product_prijs']		= attribuutList[x][product_prijs];
			selectedCombination['prijs']				= $j('#product_prijs').val();	
			selectedCombination['voorraad_aantal']		= attribuutList[x][voorraad];
			selectedCombination['levertijd_status']		= attribuutList[x][levertijd_status];
			selectedCombination['prijs_first']			= attribuutList[x][prijs_first];
			selectedCombination['prijs_second']			= attribuutList[x][prijs_second];
			selectedCombination['extra_velden_type']	= attribuutList[x][extra_velden_type];
			selectedCombination['prijs_verschil']		= attribuutList[x][prijs_verschil];
			selectedCombination['prijs_verschil_type']	= attribuutList[x][prijs_verschil_type];
			
			if(window.afname_info != undefined){
				
				selectedCombination['afname_info']		= attribuutList[x][afname_info];
			}
			updateDisplay();
			return;
		}
	}
		selectedCombination['available'] = false;
		updateDisplay();	
}

function updateDisplay() {
	
	changeColorPicker();
	changeMaatPicker();

	if(selectedCombination['extra_velden_type'] == 0){
		
		$j('.product_detail_right_box_invoervelden').slideUp(500);
	}

	if(selectedCombination['extra_velden_type'] == 1 || selectedCombination['extra_velden_type'] == 2){
		
		$j('.product_detail_right_box_invoervelden').slideDown(500);
	}	
	
	$j('#extra_velden_type').val(selectedCombination['extra_velden_type']);
	
	$j('.product_aanbieding').removeClass('hide');
	$j('#product_prijs_korting_html').removeClass('hide');
	$j('.aanbieding').removeClass('hide');
	
	if(selectedCombination['available'] == true){
				
		var prijs_first			= selectedCombination['prijs_first'];
		var prijs_second		= selectedCombination['prijs_second'];
		var product_prijs_html	= '<span class="productcategorie_blok_prijs_first">'+valuta+' '+prijs_first+'</span><span class="productcategorie_blok_prijs_second">'+prijs_second+'</span>';
		var product_prijs		= selectedCombination['product_prijs'];
		var new_prijs			= selectedCombination['new_prijs'];

		if(typeof(korting_afname_eenheid_array) !== 'undefined'){
			
			var aantal_tmp				= $j('#aantal').val();
			var prijs_verschil			= selectedCombination['prijs_verschil'];
			var prijs_verschil_type		= selectedCombination['prijs_verschil_type'];
			
			for(i in korting_afname_eenheid_array){
				
				var calc_korting_afname	= eval(korting_afname_eenheid_array[i][afname_korting]);
				if(prijs_verschil_type == 1){
					
					calc_korting_afname	= eval(calc_korting_afname - eval(prijs_verschil));
				}
				if(prijs_verschil_type == 2){
					
					calc_korting_afname	= eval(calc_korting_afname + eval(prijs_verschil));
				}
				
				if(eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(aantal_tmp) <= eval(korting_afname_eenheid_array[i][maximale_eenheid])
				   || eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(korting_afname_eenheid_array[i][maximale_eenheid]) == 0){
					
					new_prijs = eval(calc_korting_afname);

					if(typeof(korting_afname) != 'undefined'){
						
						if(eval(korting_afname_eenheid_array[i][korting_afname]) != '0.00'){
							
							new_prijs = eval(selectedCombination['new_prijs']) - eval(korting_afname_eenheid_array[i][korting_afname]);
						}
					}
				}				
			}	
		}

		if(selectedCombination['prijs_default'] <= new_prijs){

			$j('.product_aanbieding').addClass('hide');
			$j('#product_prijs_korting_html').addClass('hide');
			$j('.aanbieding').addClass('hide');
		}

		//alert(product_prijs);
		//alert(selectedCombination['levertijd_status']);
		//alert(selectedCombination['id_combination']);
		//$j('.mainright_product_top_content h1').html('sss');
		$j('#product_detail_right_box_error').fadeOut('fast');	
		$j('#product_artikelnummer_html').html(selectedCombination['artikelnummer']);
		if(selectedCombination['korting_prijs'] > product_prijs_html){
			
			$j('#product_prijs_korting_html').html('<del>'+selectedCombination['korting_prijs']+'</del>');	
			$j('#price_korting_html').html('<del>'+eval(selectedCombination['korting_prijs']).formatMoney(2, ',', '.')+'</del>');	
		}else{
			
			$j('#product_prijs_korting_html').html('<del>'+selectedCombination['prijs_default']+'</del>');	
			$j('#price_korting_html').html('<del>'+eval(selectedCombination['prijs_default']).formatMoney(2, ',', '.')+'</del>');	
		}

		//console.log(prijs_first);

		$j('#product_prijs_html').html(product_prijs_html);
		
		$j('.product_detail_right .pricetag .price').html(valuta+' '+eval(new_prijs).formatMoney(2, ',', '.'));
		
		$j('#voorraad_aantal_html_product').html(selectedCombination['voorraad_aantal']);
		$j('#voorraad_aantal_html').html(selectedCombination['voorraad_aantal']);
		
		$j('#product_prijs_per_pak_html').html(valuta+' '+product_prijs);
		$j('#prijs_per_hidden').val(new_prijs);
		
		if(selectedCombination['afname_info'] != undefined){
			
			$j('.product_detail_afname_info').html(selectedCombination['afname_info']);
			$j('.afname_info_ul').html(selectedCombination['afname_info']);
		}
		
		if(window.voorraad_tonen == undefined){
			
			voorraad_tonen = 0;
		}	
		
		if(voorraad_tonen != 0){
			if(selectedCombination['voorraad_aantal'] > 0 && heeft_voorraad != 0){
				
				$j('#tick-product').css('display', 'block');
				$j('#cross-product').css('display', 'none');
				
				$j('#availability_span').removeClass('out_of_stock');
				$j('#availability_span').addClass('in_stock');
				$j('#availability_span').html($j('#availability_op_voorraad_hidden').val());
	
				if($j('#melding_niet_voorraadig').val() == 0){
					
					$j('#bestellen_mogelijk_voorraad').val(1);
				}
				$j('#levertijd_status_html').css('display', 'none');
				
				var aantal = $j('#aantal :selected').val();
				
				if(aantal > selectedCombination['voorraad_aantal']){
					
					//alert(selectedCombination['voorraad_aantal']);
					return;
				}
			}
			if(selectedCombination['voorraad_aantal'] == 0  && heeft_voorraad != 0){
				
				$j('#tick-product').css('display', 'none');
				$j('#cross-product').css('display', 'block');

				$j('#availability_span').addClass('out_of_stock');
				$j('#availability_span').removeClass('in_stock');
				$j('#availability_span').html($j('#availability_niet_op_voorraad_hidden').val());

				if($j('#melding_niet_voorraadig').val() == 0){
					
					$j('#bestellen_mogelijk_voorraad').val(0);
				}
				$j('#voorraad_aantal_stuks_html').css('display', 'inline');
				
				$j('#levertijd_status_html').css('display', 'block');
			}	
		}
		
		if(voorraad_tonen == 0){
			
			if(selectedCombination['voorraad_aantal'] > 0 && heeft_voorraad != 0){
				
				if($j('#melding_niet_voorraadig').val() == 0){
						
					$j('#bestellen_mogelijk_voorraad').val(1);
				}
				$j('#levertijd_status_html').css('display', 'none');
			}
			if(selectedCombination['voorraad_aantal'] == 0  && heeft_voorraad != 0){
				
				if($j('#melding_niet_voorraadig').val() == 0){
					
					$j('#bestellen_mogelijk_voorraad').val(0);
				}
				$j('#levertijd_status_html').css('display', 'block');
			}
		}
		
		$j('#id_attribuut').val(selectedCombination['id_combination']);	
		
		$j('#bestellen_mogelijk').val(1);		
		if(selectedCombination['afbeelding'] != ''){
				
			var afbeelding		= selectedCombination['afbeelding'];
								
		}	

		var product_type	= $j('#product_type').val();

		if(product_type != undefined){
			
			if(product_type == 10){
				
				var prijs_per_type	= eval(product_prijs / $j('#inhoud_hidden').val()).toFixed(2);
				
				var prijs_per_type_tmp		= prijs_per_type.split('.');
				var product_prijs_type_html	= '<span class="productcategorie_blok_prijs_first">'+valuta+' '+prijs_per_type_tmp[0]+'.</span><span class="productcategorie_blok_prijs_second">'+prijs_per_type_tmp[1]+'</span>';
				$j('#product_prijs_html').html(product_prijs_type_html);
				
				$j('#productprijs_display_per').html(product_prijs);
				
				//product_korting_prijs_plain
				var price_korting	= (eval($j('#product_korting_prijs_plain').val())).formatMoney(2, ',', '');
				$j('#price_korting_html').html('<del>'+price_korting+'</del>');
				var price			= (eval($j('#product_prijs_plain').val())).formatMoney(2, ',', '');
				$j('.price').html(valuta+' '+price);
				calculatePrijsModule();
				
				//console.log(product_type);
			}
		}

	}
	if(selectedCombination['available'] == false){
	
		//alert("false");
		$j('#product_detail_right_box_error').fadeOut('fast');
		$j('#product_detail_right_box_error').fadeIn('fast');		
		$j('#id_attribuut').val(0);

		if(window.voorraad_tonen == undefined){
			
			voorraad_tonen = 0;
		}	
		if(voorraad_tonen != 0){
			
			$j('#bestellen_mogelijk').val(0);		
		}
	}	
}

function changeColorPicker() {
	
//	var check = $j('.colorVariations_1 li.selected');
//	alert(check);
	
	$j('.colorVariations_1 li').each(function() {
		
		var check = $j(this).attr('class');
		if(check == undefined){
			
			check = $j(this).prop('class');
		}
		if(check == 'selected'){
			
		}
	});
	
	var id_product_attribuut	= $j('#select_color :selected').val();

	$j('.colorVariations_1 li').each(function(){
					
		$j(this).removeClass('selected');
	});
				
	$j('#color_picker_'+id_product_attribuut+'').addClass('selected');
	
	$j('#color_picker_'+id_product_attribuut+'').fadeOut('fast', function(){
		
		
		$j(this).fadeIn('fast');
	
	});
}

function changeMaatPicker() {
		
	var id_product_attribuut	= $j('#select_maat :selected').val();

	$j('.maatVariations_1 li').each(function(){
					
		$j(this).removeClass('selected');
	});
				
	$j('#maat_picker_'+id_product_attribuut+'').addClass('selected');
	
	$j('#maat_picker_'+id_product_attribuut+'').fadeOut('fast', function(){
		
		
		$j(this).fadeIn('fast');
	
	});
}

function changeColorPickerId(id_product_attribuut_selected) {
	
	var id_product_attribuut_selected	= id_product_attribuut_selected.replace("color_picker_", "");
	
	$j('.colorVariations_2 ul li').each(function(){
					
		$j(this).removeClass('selected');
	});
	
	$j('#color_picker_'+id_product_attribuut_selected+'').addClass('selected');
	
	$j('.colorVariations_2 select').val(id_product_attribuut_selected);
	
	$j('#color_picker_'+id_product_attribuut_selected+'').fadeOut('fast', function(){
		
		
		$j(this).fadeIn('fast');
	});	
	updatePriceProductAttribuut();
}

function changeMaatPickerId(id_product_attribuut_selected) {
	
	var id_product_attribuut_selected	= id_product_attribuut_selected.replace("maat_picker_", "");
	
	$j('.maatVariations_2 ul li').each(function(){
					
		$j(this).removeClass('selected');
	});
	
	$j('#maat_picker_'+id_product_attribuut_selected+'').addClass('selected');
	
	$j('.maatVariations_2 select').val(id_product_attribuut_selected);
	
	$j('#maat_picker_'+id_product_attribuut_selected+'').fadeOut('fast', function(){
		
		
		$j(this).fadeIn('fast');	
	});	
	
	updatePriceProductAttribuut();
}

function setAttribuut() {
	
	//attribuut_id
	//alert(attribuutList[attribuut_id][afbeelding]);
	$j('#id_attribuut').val(attribuutList[attribuut_id][id_product_attribuut]);
	$j('#bestellen_mogelijk').val('1');
	
		if(window.voorraad_tonen == undefined){
			
			voorraad_tonen = 0;
		}	
		
		if(heeft_voorraad != 0){
			
			if(attribuutList[attribuut_id][voorraad] > 0 && heeft_voorraad != 0){
				
				$j('#tick-product').css('display', 'block');
				$j('#cross-product').css('display', 'none');

				$j('#availability_span').removeClass('out_of_stock');
				$j('#availability_span').addClass('in_stock');
				$j('#availability_span').html($j('#availability_op_voorraad_hidden').val());

				if($j('#melding_niet_voorraadig').val() == 0){
					
					$j('#bestellen_mogelijk_voorraad').val(1);
				}
				$j('#levertijd_status_html').css('display', 'none');
				
				var aantal = $j('#aantal :selected').val();
				
				if(aantal > selectedCombination['voorraad_aantal']){
					
					alert(selectedCombination['voorraad_aantal']);
					return;
				}
			}
			if(attribuutList[attribuut_id][voorraad] == 0  && heeft_voorraad != 0){
				
				$j('#tick-product').css('display', 'none');
				$j('#cross-product').css('display', 'block');

				$j('#availability_span').addClass('out_of_stock');
				$j('#availability_span').removeClass('in_stock');
				$j('#availability_span').html($j('#availability_niet_op_voorraad_hidden').val());

				if($j('#melding_niet_voorraadig').val() == 0){
					
					$j('#bestellen_mogelijk_voorraad').val(0);
				}
				$j('#voorraad_aantal_stuks_html').css('display', 'inline');
				
				$j('#levertijd_status_html').css('display', 'block');
			}	
		}
}

function updatePriceProductAttribuut() {

	var product_type = $j('#product_type').val();

	if(product_type == 20){
		
		return;
	}
			
	var findAttributenUitzonderingenArray 			= [];
	
	if(productProductAttribuutList != ''){
		
		var product_prijs						= $j('#product_prijs_plain').val();
		var product_prijs						= eval(product_prijs);

		if(typeof(korting_afname_eenheid_array) !== 'undefined'){
			
			var korting_afname_eenheid_array_tmp	= new Array();
			korting_afname_eenheid_array_tmp[0]		= product_prijs;
			
			var i_afname_korting	= 0;
			for(i in korting_afname_eenheid_array){
				
				i_afname_korting++;
				
				//console.log(product_prijs);
									
				korting_afname_eenheid_array_tmp[i_afname_korting]	= (eval(korting_afname_eenheid_array[i][afname_korting]));
			}	
		}
		
		$j('.class_product_attributen').each(function() {
				
			var type	= $j(this).attr('type');
			
			if(typeof(type) == 'undefined'){
				
				type	= $j(this).prop('type');
			}
			
			switch(type){
				
			case 'select-one':
				
				if($j(this).val() != 0){
					
					id_value = trim($j(this).val());
					findAttributenUitzonderingenArray.push(id_value);
				}
				
				break;
			
			case 'radio':
	
				if($j(this).val() != ''){
					
					if($j(this).attr('checked')){
						
						var id_tmp 	= $j(this).attr('id');
						id_tmp		= id_tmp.replace("select_","");
						findAttributenUitzonderingenArray.push(id_tmp);
					}
				}
	
			break;
	
			case 'checkbox':
	
				if($j(this).val() != ''){
					
					if($j(this).attr('checked')){
						
						var id_tmp 	= $j(this).attr('id');
						id_tmp		= id_tmp.replace("select_","");
						findAttributenUitzonderingenArray.push(id_tmp);
					}
				}
	
			break;
	
			case 'text':
	
				if($j(this).val() != ''){
					
					if($j(this).val() != ''){
						
						var id_tmp 	= $j(this).attr('id');
						id_tmp		= id_tmp.replace("select_","");
						findAttributenUitzonderingenArray.push(id_tmp);
					}
				}
	
			break;
	
			case 'textarea':
	
				if($j(this).val() != ''){
					
					if($j(this).val() != ''){
						
						var id_tmp 	= $j(this).attr('id');
						id_tmp		= id_tmp.replace("select_","");
						findAttributenUitzonderingenArray.push(id_tmp);
					}
				}
	
			break;
	
			default:
			  
			}
		});	

		var id_product_attribuut_color	= $j('.colorVariations_2 li.selected').attr('id');
		if(id_product_attribuut_color != null){

			var id_product_attribuut_color	= id_product_attribuut_color.replace("color_picker_", "");
			findAttributenUitzonderingenArray.push(id_product_attribuut_color);
		}
		var id_product_attribuut_maat	= $j('.colorVariations_2 li.selected').attr('id');
		if(id_product_attribuut_maat != null){
			var id_product_attribuut_maat	= id_product_attribuut_maat.replace("maat_picker_", "");
			
			findAttributenUitzonderingenArray.push(id_product_attribuut_maat);
		}

		for(i in productProductAttribuutUitzonderingenList){
				
			if(findAttributenUitzonderingenArray.length == productProductAttribuutUitzonderingenList[i].length){
					
				check = 0;
				for(x in findAttributenUitzonderingenArray){
						
					if(in_array(findAttributenUitzonderingenArray[x],productProductAttribuutUitzonderingenList[i])) {
							
						check++;
					}
				}
				
				//alert(check+'=='+productProductAttribuutUitzonderingenList[i].length);
				if(check == productProductAttribuutUitzonderingenList[i].length){
						
					$j('#product_detail_right_box_error').css('display', 'block');
					$j('#bestellen_mogelijk').val(0);
					return;
				}
			}
		}
			
		$j('#bestellen_mogelijk').val(1);
		$j('#product_detail_right_box_error').css('display', 'none');

		$j('.class_product_attributen').each(function() {
				
			var type	= $j(this).attr('type');
			if(typeof(type) == 'undefined'){
				
				type	= $j(this).prop('type');
			}
						
			switch(type){
				
			case 'select-one':
				
				if($j(this).val() != 0){
					
					product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[$j(this).val()][prijs_verhoging]));
					product_prijs	= eval(eval(product_prijs) - eval(productProductAttribuutList[$j(this).val()][prijs_verlaging]));
					if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[$j(this).val()][prijs_value]) != '0.00'){
						
						product_prijs = eval(productProductAttribuutList[$j(this).val()][prijs_value]);
					}

					if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
						
						var i_afname_korting	= 0;
						for(i in korting_afname_eenheid_array_tmp){
							
							//i_afname_korting++;
							korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) + eval(productProductAttribuutList[$j(this).val()][prijs_verhoging]));
							korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) - eval(productProductAttribuutList[$j(this).val()][prijs_verlaging]));
							if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[$j(this).val()][prijs_value]) != '0.00'){
											
								korting_afname_eenheid_array_tmp[i_afname_korting] = eval(productProductAttribuutList[$j(this).val()][prijs_value]);								
							}
							
							i_afname_korting++;
							//console.log(korting_afname_eenheid_array_tmp[i_afname_korting]);
						}						
					}

					//alert(productProductAttribuutList[$j(this).val()][prijs_verhoging]);
				}
				
				break;
			
			case 'radio':
	
				if($j(this).val() != ''){
					
					if($j(this).attr('checked')){
						
						var id_tmp 				= $j(this).attr('id');
						id_attribuut_options	= id_tmp.replace("select_","");
		
						product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
						product_prijs	= eval(eval(product_prijs) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
						if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
							
							product_prijs = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
						}

						if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
							
							var i_afname_korting	= 0;
							for(i in korting_afname_eenheid_array_tmp){
								
								//i_afname_korting++;
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
								if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
												
									korting_afname_eenheid_array_tmp[i_afname_korting] = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
								}
								
								i_afname_korting++;
							}
						}
					}
				}
	
			break;
	
			case 'checkbox':
				
				if($j(this).val() != ''){
					
					if($j(this).attr('checked')){
						
						var id_tmp 				= $j(this).attr('id');
						id_attribuut_options	= id_tmp.replace("select_","");
						
						//console.log(id_attribuut_options);
		
						product_prijs	+= eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]);
						product_prijs	-= eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]);
						if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
							
							product_prijs = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
						}
						
						if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
							
							var i_afname_korting	= 0;
							for(i in korting_afname_eenheid_array_tmp){
								
								//i_afname_korting++;
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
								if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
												
									korting_afname_eenheid_array_tmp[i_afname_korting] = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
								}
								
								i_afname_korting++;
							}
						}						
					}
				}
	
			break;
	
			case 'text':
	
				if($j(this).val() != ''){
					
					if($j(this).val() != ''){
						
						var id_tmp 				= $j(this).attr('id');
						id_attribuut_options	= id_tmp.replace("select_","");
		
						product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
						product_prijs	= eval(eval(product_prijs) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
						if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
							
							product_prijs = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
						}
						
						if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
							
							var i_afname_korting	= 0;
							for(i in korting_afname_eenheid_array_tmp){
								
								//i_afname_korting++;
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
								if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
												
									korting_afname_eenheid_array_tmp[i_afname_korting] = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
								}
								
								i_afname_korting++;
							}
						}						
					}
				}
	
			break;
	
			case 'textarea':
	
				if($j(this).val() != ''){
					
					if($j(this).val() != ''){
						
						var id_tmp 				= $j(this).attr('id');
						id_attribuut_options	= id_tmp.replace("select_","");
		
						product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
						product_prijs	= eval(eval(product_prijs) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
						if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
							
							product_prijs = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
						}		
						
						if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
							
							var i_afname_korting	= 0;
							for(i in korting_afname_eenheid_array_tmp){
								
								//i_afname_korting++;
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) + eval(productProductAttribuutList[id_attribuut_options][prijs_verhoging]));
								korting_afname_eenheid_array_tmp[i_afname_korting]	= eval(eval(korting_afname_eenheid_array_tmp[i]) - eval(productProductAttribuutList[id_attribuut_options][prijs_verlaging]));
								if(typeof(prijs_value) !== 'undefined' && eval(productProductAttribuutList[id_attribuut_options][prijs_value]) != '0.00'){
												
									korting_afname_eenheid_array_tmp[i_afname_korting] = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);
								}
								
								i_afname_korting++;
							}
						}						
					}
				}
	
			break;
	
			default:
			  
			}
		});	

		if(typeof(korting_afname_eenheid_array) !== 'undefined'){
			
			if(typeof(korting_afname_eenheid_array_tmp) == 'undefined'){
				
				var korting_afname_eenheid_array_tmp	= new Array();
			}
			
			var i_afname_korting	= 0;
			for(i in korting_afname_eenheid_array){
				
				i_afname_korting++;
				
				//console.log(product_prijs);
				if(typeof(korting_afname) !== 'undefined' && eval(korting_afname_eenheid_array[i][korting_afname]) != '0.00'){
							
					//console.log(korting_afname_eenheid_array[i][korting_afname]);	
					korting_afname_eenheid_array_tmp[i_afname_korting]	= (eval(product_prijs) - eval(korting_afname_eenheid_array[i][korting_afname]));
				}
			}	
		}
				
		if(typeof(korting_afname_eenheid_array) !== 'undefined'){
						
			var aantal_tmp			= $j('#aantal').val();
			var i_afname_korting	= 0;
			for(i in korting_afname_eenheid_array){
				
				i_afname_korting++;
				
				//console.log(product_prijs);
				
				if(eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(aantal_tmp) <= eval(korting_afname_eenheid_array[i][maximale_eenheid])
				   || eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(korting_afname_eenheid_array[i][maximale_eenheid]) == 0){
					
					if(eval(korting_afname_eenheid_array[i][korting_afname]) != '0.00'){
								
						//console.log(korting_afname_eenheid_array[i][korting_afname]);	
						product_prijs = eval(product_prijs) - eval(korting_afname_eenheid_array[i][korting_afname]);
					}else{
						
						product_prijs = eval(korting_afname_eenheid_array_tmp[i_afname_korting]);
					}
				}
			}	
		}


//		$j('.product_detail_right_box_attributen input[type="text"]').each(function() {
//			
//			if($j(this).val() != ''){
//				
//				var id_tmp 	= $j(this).attr('id');
//				id_tmp		= id_tmp.replace("select_","");
//				product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[id_tmp][prijs_verhoging]));
//			}
//		});	
//	
//		$j('.product_detail_right_box_attributen textarea').each(function() {
//			
//			if($j(this).val() != ''){
//				
//				var id_tmp 	= $j(this).attr('id');
//				id_tmp		= id_tmp.replace("select_","");
//				product_prijs	= eval(eval(product_prijs) + eval(productProductAttribuutList[id_tmp][prijs_verhoging]));
//			}
//		});
		
		//alert(product_prijs);
		//product_prijs	= 44.90;
//		alert(product_prijs);
				
		if(typeof product_prijs.toMoney == 'function') {
			
			product_prijs 	= (product_prijs).formatMoney(2, '.', '');
		}
		
		var split_product_prijs = product_prijs.split(".");
		
		if(split_product_prijs.length == 2){
			
			product_prijs_first		= split_product_prijs[0]+'';
			product_prijs_second	= '.'+split_product_prijs[1]+'';
		}
		if(split_product_prijs.length == 3){
			
			product_prijs_first		= split_product_prijs[0]+'.'+split_product_prijs[1];
			product_prijs_second	= '.'+split_product_prijs[2]+'';
		}
		
//		console.log(product_prijs);

//		if(typeof product_prijs.toMoney == 'function') {
//			
//			product_prijs 	= (product_prijs).formatMoney(2, ',', '.');
//		}
//		
//		var split_product_prijs = product_prijs.split(",");
//		
//		if(split_product_prijs.length == 2){
//			
//			product_prijs_first		= split_product_prijs[0]+'';
//			product_prijs_second	= ','+split_product_prijs[1]+'';
//		}
//		if(split_product_prijs.length == 3){
//			
//			product_prijs_first		= split_product_prijs[0]+'.'+split_product_prijs[1];
//			product_prijs_second	= ','+split_product_prijs[2]+'';
//		}

		var product_prijs_html	= '<span class="productcategorie_blok_prijs_first">'+valuta+' '+product_prijs_first+'</span><span class="productcategorie_blok_prijs_second">'+product_prijs_second+'</span>';
		$j('#product_prijs_html').html(product_prijs_html);
		
		//html5
		$j('.product_detail_right .pricetag .price').html(valuta+' '+eval(product_prijs).formatMoney(2, ',', '.'));
		
		$j('.aanbieding').css('display', 'block');
		if(eval($j('#product_korting_prijs_plain').val()) < eval(product_prijs)){
			
			$j('.aanbieding').css('display', 'none');
		}
		
		if(typeof(korting_afname_eenheid_array_tmp) !== 'undefined'){
			
			var korting_afname_eenheid_prijs_tmp	= korting_afname_eenheid_array_tmp[0];
			
			for(i in korting_afname_eenheid_array_tmp){
				
				//console.log(korting_afname_eenheid_array_tmp[i]);
				$j('#li_afname_'+i+' span.price_afname').html(eval(korting_afname_eenheid_array_tmp[i]).formatMoney(2, ',', '.'));
				
				if(korting_afname_eenheid_array_tmp[i] > korting_afname_eenheid_prijs_tmp){
					
					korting_afname_eenheid_prijs_tmp	= korting_afname_eenheid_array_tmp[i];
				}
			}
			
			if(typeof(korting_afname_eenheid_prijs_tmp) !== 'undefined'){
									
				$j('#li_afname_0 span.price_afname').html(eval(korting_afname_eenheid_prijs_tmp).formatMoney(2, ',', '.'));
			}
		}
	}else{
		
		if(typeof(korting_afname_eenheid_array) !== 'undefined'){
			
			var aantal_tmp	= $j('#aantal').val();
			for(i in korting_afname_eenheid_array){
					
				if(eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(aantal_tmp) <= eval(korting_afname_eenheid_array[i][maximale_eenheid])
					|| eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(korting_afname_eenheid_array[i][maximale_eenheid]) == 0){
						
					product_prijs = eval(korting_afname_eenheid_array[i][afname_korting]);
				}
				//alert(product_prijs);
			}	
		}
		
		$j('.product_detail_right .pricetag .price').html(valuta+' '+eval(product_prijs).formatMoney(2, ',', '.'));
	}
}

function updateProductAttribuutOpmaatMatrix() {
	
	$j('.class_product_attributen').change(function() {
		
		updateProductAttribuutOpmaatMatrixPrice();
	});
	
	$j('.class_product_attributen').keyup(function() {
		
		updateProductAttribuutOpmaatMatrixPrice();
	});

	$j('input.class_product_attributen').blur(function() {
		
		checkValueProductAttribuutOpmaatMatrixPrice($j(this).attr('id'));
	});	
}

function updateProductAttribuutOpmaatMatrixPrice() {
	
	var attribuutGroepValues 				= new Array();
	var attribuut_groep_value_array_tmp		= new Array();
	
	var teller	= 0;			
	var attribuut_groep_value_checkbox	= 0;
	
	var findAttributenUitzonderingenArray 			= [];
			
	var product_prijs	= $j('#product_prijs_plain').val();
	var product_prijs	= eval(product_prijs);

	$j('.class_product_attributen').each(function() {
				
		var type	= $j(this).attr('type');
		if(typeof(type) == 'undefined'){
				
			type	= $j(this).prop('type');
		}
			
		switch(type){
				
		case 'select-one':
				
		if($j(this).val() != 0){
					
			id_value = trim($j(this).val());
			findAttributenUitzonderingenArray.push(id_value);
		}
				
		break;
			
		case 'radio':
	
		if($j(this).val() != ''){
					
			if($j(this).attr('checked')){
						
				var id_tmp 	= $j(this).attr('id');
				id_tmp		= id_tmp.replace("select_","");
				findAttributenUitzonderingenArray.push(id_tmp);
			}
		}
	
		break;
	
		case 'checkbox':
	
		if($j(this).val() != ''){
					
			if($j(this).attr('checked')){
						
				var id_tmp 	= $j(this).attr('id');
				id_tmp		= id_tmp.replace("select_","");
				findAttributenUitzonderingenArray.push(id_tmp);
			}
		}
	
		break;
	
		case 'text':
	
		if($j(this).val() != ''){
					
			if($j(this).val() != ''){
						
				var id_tmp 	= $j(this).attr('id');
				id_tmp		= id_tmp.replace("select_","");
				findAttributenUitzonderingenArray.push(id_tmp);
			}
		}
	
		break;
	
		case 'textarea':
	
		if($j(this).val() != ''){
					
			if($j(this).val() != ''){
						
				var id_tmp 	= $j(this).attr('id');
				id_tmp		= id_tmp.replace("select_","");
				findAttributenUitzonderingenArray.push(id_tmp);
			}
		}
	
		break;
	
		default:
			  
		}
	});	
	
	for(i in productProductAttribuutUitzonderingenList){
				
		if(findAttributenUitzonderingenArray.length == productProductAttribuutUitzonderingenList[i].length){
					
			check = 0;
			for(x in findAttributenUitzonderingenArray){
						
				if(in_array(findAttributenUitzonderingenArray[x],productProductAttribuutUitzonderingenList[i])) {
							
					check++;
				}
			}
				
			//alert(check+'=='+productProductAttribuutUitzonderingenList[i].length);
			if(check == productProductAttribuutUitzonderingenList[i].length){
						
				$j('#product_detail_right_box_error').css('display', 'block');
				$j('#bestellen_mogelijk').val(0);
				return;
			}
		}
	}
			
	$j('#bestellen_mogelijk').val(1);
	$j('#product_detail_right_box_error').css('display', 'none');
	
	$j('.class_product_attributen').each(function() {
			
		var this_attribuut	= $j(this).val();
		var value			= $j(this).val();
		var type			= $j(this).attr('type');
		if(typeof(type) == 'undefined'){
				
			type	= $j(this).prop('type');
		}

		switch(type){
				
		case 'select-one':
			
			if($j(this).val() != 0){
			
				id_attribuut_options	= $j(this).val();
			}
				
		break;
			
		case 'radio':
			
			if($j(this).attr('checked')){
			
				var id_tmp 				= $j(this).attr('id');
				id_attribuut_options	= id_tmp.replace("select_","");
			}
	
		break;
	
		case 'checkbox':
	
			if($j(this).attr('checked')){
			
				var id_tmp 				= $j(this).attr('id');
				id_attribuut_options	= id_tmp.replace("select_","");
				teller++;
			}
	
		break;
	
		case 'text':
	
			var id_tmp 				= $j(this).attr('id');
			id_attribuut_options	= id_tmp.replace("select_","");
	
		break;
	
		case 'textarea':
	
			var id_tmp 				= $j(this).attr('id');
			id_attribuut_options	= id_tmp.replace("select_","");

		break;
	
		default:
			  
		}
			
		var key_id_product_attribuut_options_groep	= productProductAttribuutList[id_attribuut_options][id_product_attribuut_options_groep];
		
		
		if(type == 'select-one' && $j(this).val() != 0
		   || type == 'radio' && id_attribuut_options == $j(this).val()
		   || type == 'checkbox' && id_attribuut_options == $j(this).val()
		   || type == 'text'
		   || type == 'textarea'){
		   	
		   	if(type == 'select-one' || type == 'radio'){
		   		
				var attribuut_groep_value	 = eval(productProductAttribuutList[id_attribuut_options][prijs_value]);				
		   	}
			if(type == 'checkbox'){
				
				attribuut_groep_value					= "";
				attribuut_groep_value_array_tmp.push(Array(productProductAttribuutList[id_attribuut_options][prijs_value]));
			}
			if(type == 'text' || type == 'textarea'){
		   		
				var attribuut_groep_value	= $j(this).val();
				if(attribuut_groep_value == ''){
					
					attribuut_groep_value	= 0;
				}
		   	}
			
			//console.log('{'+attribuut_groep_value+'}');
			attribuutGroepValues[key_id_product_attribuut_options_groep]	= Array(attribuut_groep_input_value		= ""+$j(this).val()+"",
																					attribuut_groep_prijs_value		= ""+productProductAttribuutList[id_attribuut_options][prijs_value]+"",
																					attribuut_groep_value			= ""+attribuut_groep_value+"",
																					attribuut_groep_type			= ""+type+"",
																					attribuut_groep_value_array		= new Array(""+attribuut_groep_value_array_tmp+""));			
		}
		
		//alert(key_id_product_attribuut_options_groep);
		for(i in attribuutGroepValues){
			
			//alert(id_attribuut_options+'|'+attribuutGroepValues[i][attribuut_groep_input_value]+'=='+attribuutGroepValues[i][attribuut_groep_prijs_value]);
		}
		
	});

	var attribuut_groep_input_value		= 0;
	var attribuut_groep_prijs_value		= 1;
	var attribuut_groep_value			= 2;
	var attribuut_groep_type			= 3;
	var attribuut_groep_value_array		= 4;
		
	if(productOpmaatMatrixArray.length > 1){
		
		var productOpmaatMatrixRegel = new Array();
		var op_maat_matrix_regel_uitkomst	= 0;
		var teller 		= 0;
		var test_sum	= 0;
		var prijs_plain	= $j('#product_prijs_plain').val();
		for(i in productOpmaatMatrixArray){
			
			teller++;
			
			var sum_1	= 1;
			var sum_2	= 1;

			if(productOpmaatMatrixArray[i][op_maat_matrix_type_1] == 1){
				
				if(typeof(attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_1]]) !== 'undefined'){
				
					sum_1	= attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_1]][attribuut_groep_value];
					
					if(attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_1]][attribuut_groep_type] == 'checkbox'){
						
						for(i_in in attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_1]][attribuut_groep_value_array]){
							
							var attribuut_groep_value_array_tmp	=  attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_1]][attribuut_groep_value_array][i_in].split(',');
							
							for(x in attribuut_groep_value_array_tmp){
								
								sum_1  = eval(sum_1 + eval(attribuut_groep_value_array_tmp[x]));
							}
						}
					}
				}else{

					if(productOpmaatMatrixArray[i][som] == 'optellen' || productOpmaatMatrixArray[i][som] == 'atrekken'){
						
						sum_1	= 0;
					}				
				}			
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_1] == 2){
				
				sum_1	= uitkomst;
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_1] == 3){
				
				sum_1	= productOpmaatMatrixArray[i][value_1];
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_1] == 4){

				if(typeof(korting_afname_eenheid_array) !== 'undefined'){
					
					var aantal_tmp	= $j('#aantal').val();
					for(i in korting_afname_eenheid_array){
							
						if(eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(aantal_tmp) <= eval(korting_afname_eenheid_array[i][maximale_eenheid])
							|| eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(korting_afname_eenheid_array[i][maximale_eenheid]) == 0){
								
							prijs_plain = eval(korting_afname_eenheid_array[i][afname_korting]);
						}
						//alert(product_prijs);
					}	
				}

				sum_1	= prijs_plain;
			}

			if(productOpmaatMatrixArray[i][op_maat_matrix_type_2] == 1){
				
				if(typeof(attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_2]]) !== 'undefined'){
				
					sum_2	= attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_2]][attribuut_groep_value];
					
					if(attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_2]][attribuut_groep_type] == 'checkbox'){
						
						for(i_in in attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_2]][attribuut_groep_value_array]){
							
							var attribuut_groep_value_array_tmp	=  attribuutGroepValues[productOpmaatMatrixArray[i][id_product_attribuut_options_groep_2]][attribuut_groep_value_array][i_in].split(',');
							
							for(x in attribuut_groep_value_array_tmp){
								
								sum_2  = eval(sum_2 + eval(attribuut_groep_value_array_tmp[x]));
							}
						}
					}
				}else{
					
					if(productOpmaatMatrixArray[i][som] == 'optellen' || productOpmaatMatrixArray[i][som] == 'atrekken'){
						
						sum_2	= 0;
					}
				}
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_2] == 2){
				
//				if(productOpmaatMatrixRegel[teller - 1][op_maat_matrix_regel_uitkomst] != undefined){
//
//					sum_2	= productOpmaatMatrixRegel[teller - 1][op_maat_matrix_regel_uitkomst];
//				}		
				sum_2		= uitkomst;		
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_2] == 3){
				
				sum_2	= productOpmaatMatrixArray[i][value_2];
			}
			if(productOpmaatMatrixArray[i][op_maat_matrix_type_2] == 4){

				if(typeof(korting_afname_eenheid_array) !== 'undefined'){
					
					var aantal_tmp	= $j('#aantal').val();
					for(i in korting_afname_eenheid_array){
							
						if(eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(aantal_tmp) <= eval(korting_afname_eenheid_array[i][maximale_eenheid])
							|| eval(aantal_tmp) >= eval(korting_afname_eenheid_array[i][minimale_eenheid]) && eval(korting_afname_eenheid_array[i][maximale_eenheid]) == 0){
								
							prijs_plain = eval(korting_afname_eenheid_array[i][afname_korting]);
						}
						//alert(product_prijs);
					}	
				}

				sum_2	= prijs_plain;
			}
						
			sum_1	= eval(sum_1);
			sum_2	= eval(sum_2);
			
			if(isNaN(sum_1)){
				
				sum_1	= 1;
			}
			if(isNaN(sum_2)){
				
				sum_2	= 1;
			}
//			if(sum_1 == 0 || sum_1 == 0.00){
//				
//				sum_1	= 1;
//			}
//			if(sum_2 == 0 || sum_2 == 0.00){
//				
//				sum_2	= 1;
//			}		

			switch(productOpmaatMatrixArray[i][som]){
									
			case 'vermenigvulden':
			som_matrix	= '*';
			//uitkomst	= eval(sum_1 * sum_2);
			break;

			case 'optellen':
			som_matrix	= '+';
			//uitkomst	= eval(sum_1 + sum_2);
			break;

			case 'aftrekken':
			som_matrix	= '-';
			//uitkomst	= eval(sum_1 - sum_2);
			break;

			case 'delen':
			som_matrix	= '/';
			//uitkomst	= eval(sum_1 / sum_2);
			break;
		
			default:
				  
			}
			uitkomst	= eval(sum_1+som_matrix+sum_2);
						
			productOpmaatMatrixRegel[teller]	= Array(op_maat_matrix_regel_uitkomst =	""+uitkomst+"");

			//alert(productOpmaatMatrixArray[i][op_maat_matrix_type_1]);
			//alert(productOpmaatMatrixRegel[i][op_maat_matrix_regel_uitkomst]);
		}
		
		if(uitkomst < prijs_plain){
			
			uitkomst	= eval(prijs_plain);
		}

		if(typeof uitkomst.toMoney == 'function') {
			
			uitkomst 	= (uitkomst).formatMoney(2, ',', '.');
		}
		
		var uitkomst_html_5		= uitkomst;
		var uitkomst_tmp		= uitkomst.split(',');
		
		$j('#product_prijs_html').html('<span class="productcategorie_blok_prijs_first">'+valuta+' '+uitkomst_tmp[0]+'</span><span class="productcategorie_blok_prijs_second">,'+uitkomst_tmp[1]+'</span>');
		
		$j('.product_detail_right .pricetag .price').html(valuta+' '+uitkomst);	
		//alert(uitkomst);
	}	
}

function checkValueProductAttribuutOpmaatMatrixPrice(id) {
	
	var id_tmp 				= id;
	id_attribuut_options	= id_tmp.replace("select_","");
	
	var value_id			= eval($j('#'+id+'').val());
	
	if(!isNaN(value_id)){
		
		var value_input			= eval($j('#'+id+'').val());
		var min_value_input		= eval(productProductAttribuutList[id_attribuut_options][min_value]);	
		var max_value_input		= eval(productProductAttribuutList[id_attribuut_options][max_value]);	
		
		if(min_value_input != 0.00 && value_input.toFixed(2) < min_value_input.toFixed(2)){
				
			alert('Minimaal te bestellen '+productProductAttribuutList[id_attribuut_options][attribuut_naam]+' is: '+min_value_input+'');
			$j('#'+id+'').val(min_value_input);
			updateProductAttribuutOpmaatMatrixPrice();
		}
		if(max_value_input != 0.00 && value_input.toFixed(2) > max_value_input.toFixed(2)){
				
			alert('Maximaal te bestellen '+productProductAttribuutList[id_attribuut_options][attribuut_naam]+' is: '+max_value_input+'');
			$j('#'+id+'').val(max_value_input);
			updateProductAttribuutOpmaatMatrixPrice();
		}
		
		//console.log(id_attribuut_options+'|'+value_input+'--'+min_value_input+'--'+max_value_input);
	}
}

function scrollProductOmschrijving() {

	$j('html,body').scrollTo( $j('div#product_info_container'), 800 );
	//$j('#product_info_container').animate({scrollTop:0},'slow');
}

var md5 = function (string) {
 
	function RotateLeft(lValue, iShiftBits) {
		return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
	}
 
	function AddUnsigned(lX,lY) {
		var lX4,lY4,lX8,lY8,lResult;
		lX8 = (lX & 0x80000000);
		lY8 = (lY & 0x80000000);
		lX4 = (lX & 0x40000000);
		lY4 = (lY & 0x40000000);
		lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
		if (lX4 & lY4) {
			return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
		}
		if (lX4 | lY4) {
			if (lResult & 0x40000000) {
				return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			}
		} else {
			return (lResult ^ lX8 ^ lY8);
		}
 	}
 
 	function F(x,y,z) { return (x & y) | ((~x) & z); }
 	function G(x,y,z) { return (x & z) | (y & (~z)); }
 	function H(x,y,z) { return (x ^ y ^ z); }
	function I(x,y,z) { return (y ^ (x | (~z))); }
 
	function FF(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function GG(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function HH(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function II(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function ConvertToWordArray(string) {
		var lWordCount;
		var lMessageLength = string.length;
		var lNumberOfWords_temp1=lMessageLength + 8;
		var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
		var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
		var lWordArray=Array(lNumberOfWords-1);
		var lBytePosition = 0;
		var lByteCount = 0;
		while ( lByteCount < lMessageLength ) {
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
			lByteCount++;
		}
		lWordCount = (lByteCount-(lByteCount % 4))/4;
		lBytePosition = (lByteCount % 4)*8;
		lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
		lWordArray[lNumberOfWords-2] = lMessageLength<<3;
		lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
		return lWordArray;
	};
 
	function WordToHex(lValue) {
		var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
		for (lCount = 0;lCount<=3;lCount++) {
			lByte = (lValue>>>(lCount*8)) & 255;
			WordToHexValue_temp = "0" + lByte.toString(16);
			WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
		}
		return WordToHexValue;
	};
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var x=Array();
	var k,AA,BB,CC,DD,a,b,c,d;
	var S11=7, S12=12, S13=17, S14=22;
	var S21=5, S22=9 , S23=14, S24=20;
	var S31=4, S32=11, S33=16, S34=23;
	var S41=6, S42=10, S43=15, S44=21;
 
	string = Utf8Encode(string);
 
	x = ConvertToWordArray(string);
 
	a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
 
	for (k=0;k<x.length;k+=16) {
		AA=a; BB=b; CC=c; DD=d;
		a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
		d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
		c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
		b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
		a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
		d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
		c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
		b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
		a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
		d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
		c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
		b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
		a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
		d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
		c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
		b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
		a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
		d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
		c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
		b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
		a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
		d=GG(d,a,b,c,x[k+10],S22,0x2441453);
		c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
		b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
		a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
		d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
		c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
		b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
		a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
		d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
		c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
		b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
		a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
		d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
		c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
		b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
		a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
		d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
		c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
		b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
		a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
		d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
		c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
		b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
		a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
		d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
		c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
		b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
		a=II(a,b,c,d,x[k+0], S41,0xF4292244);
		d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
		c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
		b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
		a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
		d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
		c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
		b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
		a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
		d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
		c=II(c,d,a,b,x[k+6], S43,0xA3014314);
		b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
		a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
		d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
		c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
		b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
		a=AddUnsigned(a,AA);
		b=AddUnsigned(b,BB);
		c=AddUnsigned(c,CC);
		d=AddUnsigned(d,DD);
	}
 
	var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
	return temp.toLowerCase();
}

function belMijTerug() {
	
	var naam			= $j('#bel_mij_terug_naam').val();
	var telefoonnummer	= $j('#bel_mij_terug_telefoonnummer').val();
	
	if(naam == ''){
		
		alert("Vul een naam in!");
		return;
	}
	if(telefoonnummer == ''){
		
		alert("Vul een telefoonnummer in!");
		return;
	}	
	
	$j('#bel_mij_terug-loading').css('display', 'block');
	
		$j.ajax({url: ''+root_site+'docs/ajaxrequest/form_request.php',
				 type: "POST",
				 data: {action			: 'sendBelMijTerug',
				 		naam			: naam,
						telefoonnummer	: telefoonnummer},
				 success: function(response){
					
					$j('#bel_mij_terug-loading').css('display', 'none');
					
					$j('#bel_mij_terug_content').empty();
					
					$msg = 'Formulier is succesvol verzonden!<br />U wordt zo snel mogelijk terug gebeld!';
					$j('#bel_mij_terug_content').html($msg);
				}
		});	
}

function sendContactForm() {
	
	var check = 0;
	
	$j('#contact_form-loading').css('display', 'none');
	
	$j('#contact_form input').each(function(){
		
		$j(this).removeClass('inputfield_error');
				
		var name = $j(this).attr('name');

		if($j('#bedrijfsnaam').val() == ''){
			
			check++;
			$j('#bedrijfsnaam').addClass('inputfield_error');
			$j('#error_bedrijfsnaam').removeClass('hide');		
		}else{
			
			$j('#error_bedrijfsnaam').addClass('hide');	
		}
		
		if($j('#naam').val() == ''){
			
			check++;
			$j('#naam').addClass('inputfield_error');
			$j('#error_naam').removeClass('hide');			
		}else{
			
			$j('#error_naam').addClass('hide');	
		}

		if($j('#telefoonnummer').val() == ''){
			
			check++;
			$j('#telefoonnummer').addClass('inputfield_error');
			$j('#error_telefoonnummer').removeClass('hide');			
		}else{
			
			$j('#error_telefoonnummer').addClass('hide');	
		}

		if(isValidEmailAddress($j('#email').val())){
					
			$j('#email').removeClass('inputfield_error');
			$j('#error_email').addClass('hide');
		}else{
		
			check++;
			$j('#email').addClass('inputfield_error');
			$j('#error_email').removeClass('hide');
		}		
	});
	
	if(check == 0){
		
		$j('#contact_form-loading').css('display', 'block');
		
		var naam			= $j('#naam').val();
		var email			= $j('#email').val();
		var telefoonnummer	= $j('#telefoonnummer').val();
		var vraag			= $j('#vraag').val();
		
		$j.ajax({url: ''+root_site+'docs/ajaxrequest/form_request.php',
				 type: "POST",
				 data: {action			: 'sendContactForm',
				 		naam			: naam,
						email			: email,
						telefoonnummer	: telefoonnummer,
						vraag			: vraag},
				 success: function(response){
					
					$j('#contact_form-loading').css('display', 'none');
					
					$j('#contact_form_content').empty();
					
					$msg = 'Contactformulier is succesvol verzonden!';
					$j('#contact_form_content').html($msg);
				}
		});
	}
}

function addNieuwsbriefAanmelding() {
	
	var nieuwsbrief_aanmelding = $j('#nieuwsbrief_aanmelding').val();
	if(!isValidEmailAddress(nieuwsbrief_aanmelding)){
		
		alert('U heeft geen of geen geldig e-mail adres ingevuld!');
		return
	}else{
				
		if(id_shop_type == undefined){
			
			id_shop_type = 1;
		}
				
		$j.ajax({url: ''+root_site+'docs/ajaxrequest/form_request.php',
				 type: "POST",
				 data: {action			: 'addNieuwsbriefAanmelding',
						email			: nieuwsbrief_aanmelding,
						shop_type		: id_shop_type},
				 success: function(response){
					
					var response = trim(response);
					
					if(response != ''){
						
						alert(response);
					}
					if(response == ''){
						
						alert('Uw heeft zicht aangemeld voor de gratis nieuwsbrief!');
						$j('#nieuwsbrief_aanmelding').val('');
					}
				}
		});
	}
}

function removeNieuwsbriefAanmelding() {

	var nieuwsbrief_aanmelding = $j('#nieuwsbrief_aanmelding').val();
	
	if(!isValidEmailAddress(nieuwsbrief_aanmelding)){
		
		alert('U heeft geen of geen geldig e-mail adres ingevuld!');
		return
	}else{
				
		if(id_shop_type == undefined){
			
			id_shop_type = 1;
		}
				
		$j.ajax({url: ''+root_site+'docs/ajaxrequest/form_request.php',
				 type: "POST",
				 data: {action			: 'removeNieuwsbriefAanmelding',
						email			: nieuwsbrief_aanmelding,
						shop_type		: id_shop_type},
				 success: function(response){
					
					var response = trim(response);
					
					if(response != ''){
						
						alert(response);
					}
					if(response == ''){
						
						alert('Uw heeft zicht afgemeld voor de gratis nieuwsbrief!');
						$j('#nieuwsbrief_aanmelding').val('');
					}
				}
		});
	}
}

function removeNieuwsbriefAanmeldingMailingList() {

	$j.ajax({url: ''+root_site+'docs/ajaxrequest/form_request.php',
		type: "POST",
		data: {action			: 'removeNieuwsbriefAanmeldingMailingList',
				email			: $j('#email').val(),
				stamp			: $j('#stamp').val(),
				campagne		: $j('#campagne').val()},
		success: function(response){
					
			var response = trim(response);
			
			$j('.content_cms_pagina_content p').html(response);
			$j('.content_blok p').html(response);
		}
	});
}

function initializeGalleryProduct() {

	if(window.product_thumb_change == undefined){
		
		product_thumb_change	= 'click';
	}
	
	$j('.product_gallery .content').css('display','block');
		// Initialize Advanced Galleriffic Gallery
		var galleryAdv = $j('#gallery-adv').galleriffic('#thumbs-adv', {
			delay:                  0,
			numThumbs:              30,
			preloadAhead:           10,
			enableTopPager:         false,
			enableBottomPager:      false,
			imageContainerSel:      '#slideshow-adv',
			controlsContainerSel:   '#controls-adv',
			captionContainerSel:    '#caption-adv',
			loadingContainerSel:    '#loading-adv',
			renderSSControls:       false,
			renderNavControls:      false,
			playLinkText:           'Play Slideshow',
			pauseLinkText:          'Pause Slideshow',
			prevLinkText:           '&lsaquo; Previous Photo',
			nextLinkText:           'Next Photo &rsaquo;',
			nextPageLinkText:       'Next &rsaquo;',
			prevPageLinkText:       '&lsaquo; Prev',
			enableHistory:          false,
			autoStart:              false,
			thumbChange:			product_thumb_change,
			onChange:               function(prevIndex, nextIndex) {
				$j('#thumbs-adv ul.thumbs').children()
					.eq(prevIndex).addClass('opacity_thumbs-adv').end()
					.eq(nextIndex).removeClass('opacity_thumbs-adv');
			},
			onTransitionOut:        function(callback) {
				$j('#slideshow-adv, #caption-adv').fadeOut('fast', callback);
			},
			onTransitionIn:         function() {
				$j('#slideshow-adv, #caption-adv').fadeIn('fast');
			},
			onPageTransitionOut:    function(callback) {
				$j('#thumbs-adv ul.thumbs').fadeOut('fast', callback);
				},
			onPageTransitionIn:     function() {
				$j('#thumbs-adv ul.thumbs').fadeIn('fast');
			},
			zoomType:				''+zoom_type+''
		});
				
			$j('.product_detail_right_box select').change(function() {
				changeProductImage('');				
			});	
			
			$j('#thumbs-adv ul.thumbs li:first').removeClass('opacity_thumbs-adv');

			//Product settings default loading page
			if(attribuutList[attribuut_id] == undefined){
				
				selectedCombination['available'] = false;
				
				//updateDisplay(attribuut_id);			
				return;
			}

			selectedCombination['combination']				= attribuutList[attribuut_id][combination];
			selectedCombination['id_product_attribuut']		= attribuutList[attribuut_id][id_product_attribuut];
			
			for(i in selectedCombination['combination']){

				var attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
				if(attr_disabled == undefined){
					
					attr_disabled = $j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+attribuut_id+'"]').attr('disabled');
				}
				if(attr_disabled == undefined){
							
					attr_disabled = $j('.product_detail_right_box').find('input[type="radio"][value="'+selectedCombination['combination'][i]+'"]').attr('disabled');
				}				
				if(attr_disabled == undefined){
							
					attr_disabled = $j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').prop('disabled');
				}
				
				if(attr_disabled == false){
					
					$j('.product_detail_right_box select').find('option[value="'+selectedCombination['combination'][i]+'"]').attr('selected', true);	

					//alert(selectedCombination['combination'][i]);
					$j('.product_detail_right_box').find('input[type="radio"]:input[value="'+selectedCombination['combination'][i]+'"]').attr('checked', true);
					$j('.product_detail_right_box').find('input[type="radio"]:input[id="radio_'+attribuut_id+'"]').attr('checked', true);
				}
				//attribuut_id
			}
			
			//alert(combination_id);

			selectedCombination['afbeelding_volgorde'] 	= attribuutList[attribuut_id][afbeelding_volgorde];
			var volgorde								= selectedCombination['afbeelding_volgorde'];
			
			//alert(volgorde);
			
			galleryAdv.goto(volgorde);
			
			//Product settings change attribuut
			$j('.product_detail_right_box select').change(function() {
				changeProductImage('');				
			});	
			
			$j('.color_picker').click(function() {

				var id	= $j(this).attr('id');
				var id	= id.replace("color_picker_", "");

				changeProductImage(id);
			});
			
		function changeProductImage(id) {

			selectedCombination['input']	= 'select';
				
			var findCombinationArray 			= new Array();
	
			if(selectedCombination['input'] == 'select'){
		
				$j('.product_detail_right_box select').each(function(){
			
//					findCombination	= $j(this).val();
//			
//					if(findCombination != ''){	
//					
//						findCombinationArray.push(findCombination);
//					}
					findCombination = trim($j(this).val());	
			
					//findCombination = findCombination_tmp.split("-");
					var match = /,/.test(findCombination)
			
					if(match == false){
				
						findCombination = Array(findCombination);
					}
			
					if(findCombination.length > 1){
				
						id_attribuut_groep	= findCombination.split("|");
						id_attribuut_groep	= id_attribuut_groep[1];
				
						$j('#hidden_attribuut_options_'+id_attribuut_groep+' input[type="hidden"]').each(function(){
					
							var id = $j(this).val();
							findCombinationArray.push(id);
						});
				
					}else{
				
						if(findCombination != ''){	
					
							findCombinationArray.push(findCombination);
						}
					}
				});
			}
				
			if(selectedCombination['input'] == 'radio'){
		
				$j('.product_detail_right_box input[type="radio"]:checked').each(function(){

					findCombination = trim($j(this).val());	
			
					//findCombination = findCombination_tmp.split("-");
					var match = /,/.test(findCombination)
			
					if(match == false){
				
						findCombination = Array(findCombination);
					}
			
					if(findCombination.length > 1){
				
						id_attribuut_groep	= findCombination.split("|");
						id_attribuut_groep	= id_attribuut_groep[1];
				
						$j('#hidden_attribuut_options_'+id_attribuut_groep+' input[type="hidden"]').each(function(){
					
							var id = $j(this).val();
							findCombinationArray.push(id);
						});
				
					}else{
				
						if(findCombination != ''){	
					
							findCombinationArray.push(findCombination);
						}
					}
				});
			}
			
			if(id == ''){
				for(x in attribuutList) {
			
					check = 0;
			
						for(i in attribuutList[x][combination]){
						//alert(attribuutList[x][combination][i]+'='+findCombinationArray);
							if(in_array(attribuutList[x][combination][i],findCombinationArray)) {
					
								check++;
								//alert(check);
							}
						}
			
					//alert(check+'='+findCombinationArray.length+'='+attribuutList[x][combination].length);
					//alert(attribuutList[x][combination].length);
					if(check == findCombinationArray.length && findCombinationArray.length == attribuutList[x][combination].length){
				
						selectedCombination['afbeelding_volgorde'] 	= attribuutList[x][afbeelding_volgorde];
						var volgorde								= selectedCombination['afbeelding_volgorde'];
						//alert(volgorde);
	
						galleryAdv.goto(volgorde);
						return;
					}
				}	
			}else{
				
				colorCombination = Array(id);
				
				for(x in attribuutList) {
			
					check = 0;
			
						for(i in attribuutList[x][combination]){
						//alert(attribuutList[x][combination][i]+'='+findCombinationArray);
							if(in_array(attribuutList[x][combination][i],colorCombination)) {
					
								check++;
								//alert(check);
							}
						}
			
					//if(check == findCombinationArray.length && findCombinationArray.length == attribuutList[x][combination].length){
					if(check > 0){	
				
						selectedCombination['afbeelding_volgorde'] 	= attribuutList[x][afbeelding_volgorde];
						var volgorde								= selectedCombination['afbeelding_volgorde'];
						//alert(volgorde);
	
						galleryAdv.goto(volgorde);
						return;
					}
				}
			}
		}
}

function checkInputInvoerveld(input,action){
	
	if(action == 1){
		
		input.value	= input.value.toUpperCase();
	}
}

function checkInputInvoer(input,action) {

	if(action == 1){
		
		var objRegExp  = /[0-9]$/;
  		
		input.value	= input.value.replace(objRegExp, "");
	}

	if(action == 2){
		
		input.value	= input.value.toLowerCase();

		var objRegExp  = /[0-9]$/;
  		
		input.value	= input.value.replace(objRegExp, "");
	}
	if(action == 3){
		
		input.value	= input.value.toUpperCase();

		var objRegExp  = /[0-9]$/;
  		
		input.value	= input.value.replace(objRegExp, "");
	}
}

function rgbConvert(str, plain) {
	
	if(window.plain == undefined){
		
		plain = true;
	}
	
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   
   if(plain == false){
	
	return ('#' + str.join(""));   
   }if(plain == true){
   
    return ('' + str.join(""));
   }
}

function urldecode(str) {

	return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

jQuery.fn.removeHighlight = function() {
 function newNormalize(node) {
    for (var i = 0, children = node.childNodes, nodeCount = children.length; i < nodeCount; i++) {
        var child = children[i];
        if (child.nodeType == 1) {
            newNormalize(child);
            continue;
        }
        if (child.nodeType != 3) { continue; }
        var next = child.nextSibling;
        if (next == null || next.nodeType != 3) { continue; }
        var combined_text = child.nodeValue + next.nodeValue;
        new_node = node.ownerDocument.createTextNode(combined_text);
        node.insertBefore(new_node, child);
        node.removeChild(child);
        node.removeChild(next);
        i--;
        nodeCount--;
    }
 }

 return this.find("span.highlight").each(function() {
    var thisParent = this.parentNode;
    thisParent.replaceChild(this.firstChild, this);
    newNormalize(thisParent);
 }).end();
};

/*

DynaCloud v5

A dynamic JavaScript tag/keyword cloud with jQuery.

<http://johannburkard.de/blog/programming/javascript/dynacloud-a-dynamic-javascript-tag-keyword-cloud-with-jquery.html>

MIT license.

Johann Burkard
<http://johannburkard.de>
<mailto:jb@eaio.com>

*/

jQuery.fn.highlight = function(pat) {
 function innerHighlight(node, pat) {
  var skip = 0;
  if (node.nodeType == 3) {
   var pos = node.data.toUpperCase().indexOf(pat);
   if (pos >= 0) {
    var spannode = document.createElement('span');
    spannode.className = 'highlight';
    var middlebit = node.splitText(pos);
    var endbit = middlebit.splitText(pat.length);
    var middleclone = middlebit.cloneNode(true);
    spannode.appendChild(middleclone);
    middlebit.parentNode.replaceChild(spannode, middlebit);
    skip = 1;
   }
  }
  else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
   for (var i = 0; i < node.childNodes.length; ++i) {
    i += innerHighlight(node.childNodes[i], pat);
   }
  }
  return skip;
 }
 return this.each(function() {
  innerHighlight(this, pat.toUpperCase());
 });
};

jQuery.fn.removeHighlight = function() {
 return this.find("span.highlight").each(function() {
  this.parentNode.firstChild.nodeName;
  with (this.parentNode) {
   replaceChild(this.firstChild, this);
   normalize();
  }
 }).end();
};

jQuery.dynaCloud = {

 max: 20,
 sort: true,
 auto: true,
 single: true,
 wordStats: true,
 scale: 4,

// Adapted from <http://www.perseus.tufts.edu/Texts/engstop.html>

 stopwords: [ "a", "about", "above", "accordingly", "after",
  "again", "against", "ah", "all", "also", "although", "always", "am", "among", "amongst", "an",
  "and", "any", "anymore", "anyone", "are", "as", "at", "away", "be", "been",
  "begin", "beginning", "beginnings", "begins", "begone", "begun", "being",
  "below", "between", "but", "by", "ca", "can", "cannot", "come", "could",
  "did", "do", "doing", "during", "each", "either", "else", "end", "et",
  "etc", "even", "ever", "far", "ff", "following", "for", "from", "further", "furthermore",
  "get", "go", "goes", "going", "got", "had", "has", "have", "he", "her",
  "hers", "herself", "him", "himself", "his", "how", "i", "if", "in", "into",
  "is", "it", "its", "itself", "last", "lastly", "less", "many", "may", "me",
  "might", "more", "must", "my", "myself", "near", "nearly", "never", "new",
  "next", "no", "not", "now", "o", "of", "off", "often", "oh", "on", "only",
  "or", "other", "otherwise", "our", "ourselves", "out", "over", "perhaps",
  "put", "puts", "quite", "s", "said", "saw", "say", "see", "seen", "shall",
  "she", "should", "since", "so", "some", "such", "t", "than", "that", "the",
  "their", "them", "themselves", "then", "there", "therefore", "these", "they",
  "this", "those", "though", "throughout", "thus", "to", "too",
  "toward", "unless", "until", "up", "upon", "us", "ve", "very", "was", "we",
  "were", "what", "whatever", "when", "where", "which", "while", "who",
  "whom", "whomever", "whose", "why", "with", "within", "without", "would",
  "yes", "your", "yours", "yourself", "yourselves" ]

};

jQuery(function() {
 jQuery.dynaCloud.stopwords = new RegExp("\\s((" + jQuery.dynaCloud.stopwords.join("|") + ")\\s)+", "gi");
 if (jQuery.dynaCloud.auto) {
  jQuery('.dynacloud').dynaCloud();
 }
});

jQuery.fn.dynaCloud = function(outElement) {
 var cloud = {};
 return this.each(function() {

  var cl = [];
  var max = 0;

  if (jQuery.wordStats && jQuery.dynaCloud.wordStats) {
   jQuery.wordStats.computeTopWords(jQuery.dynaCloud.max, this);
   for (var i = 0, j = jQuery.wordStats.topWords.length; i < j && i <= jQuery.dynaCloud.max; ++i) {
    var t = jQuery.wordStats.topWords[i].substring(1);
    if (typeof cloud[t] == 'undefined') {
     cloud[t] = { count: jQuery.wordStats.topWeights[i], el: t };
    }
    else {
     cloud[t].count += jQuery.wordStats.topWeights[i];
    }
    max = Math.max(cloud[t].count, max);
   }
   jQuery.wordStats.clear();
  }
  else {
   var elems = jQuery(this).text().replace(/[^A-Z\xC4\xD6\xDCa-z\xE4\xF6\xFC\xDF0-9_]/g, ' ').replace(jQuery.dynaCloud.stopwords, ' ').split(' ');
   var word = /^[a-z\xE4\xF6\xFC]*[A-Z\xC4\xD6\xDC]([A-Z\xC4\xD6\xDC\xDF]+|[a-z\xE4\xF6\xFC\xDF]{3,})/;

   jQuery.each(elems, function(i, n) {
    if (word.test(n)) {
     var t = n.toLowerCase();
     if (typeof cloud[t] == 'undefined') {
      cloud[t] = { count: 1, el: n };
     }
     else {
      cloud[t].count += 1;
     }
     max = Math.max(cloud[t].count, max);
    }
   });
  }

  jQuery.each(cloud, function(i, n) {
   cl[cl.length] = n;
  });

  if (jQuery.dynaCloud.sort) {
   cl.sort(function(a, b) {
    if (a.count == b.count) {
     return a.el < b.el ? -1 : (a.el == b.el ? 0 : 1);
    }
    else {
     return a.count < b.count ? 1 : -1;
    }
   });
  }

  var out;
  if ((out = jQuery(outElement ? outElement : '#dynacloud')).length == 0) {
   jQuery(document.body).append('<p id="dynacloud"><\/p>');
   out = jQuery('#dynacloud');
  }

  out.empty();

  var l = jQuery.dynaCloud.max == -1 ? cl.length : Math.min(jQuery.dynaCloud.max, cl.length);

  for (var i = 0; i < l; ++i) {
   out.append('<a href="#' + cl[i].el + '" style="font-size: ' + Math.ceil((cl[i].count / max) * jQuery.dynaCloud.scale) + 'em"><span>' + cl[i].el + '</span></a> &nbsp; ');
  }
  
  var target = this;

  jQuery('a', out).each(function() {
   jQuery(this).click(function() {

    if (jQuery.dynaCloud.single) {
     jQuery(document.body).removeHighlight();
    }

    var text = jQuery(this).text().toUpperCase();
    jQuery(target).each(function() {
     jQuery(this).highlight(text);
    });
    return false;
   });
  });

 });
};

function strstr (haystack, needle, bool) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);
    // *     returns 4: 'name'
    var pos = 0;

    haystack += '';
    pos = haystack.indexOf(needle);
    if (pos == -1) {
        return false;
    } else {
        if (bool) {
            return haystack.substr(0, pos);
        } else {
            return haystack.slice(pos);
        }
    }
}
