﻿function applyHovers(){
	$(".size").hover(
		function(){ 
			if(($(this).attr('class') !== 'act' ) && ($(this).attr('class') !== 'size disbld' )) { $(this).addClass('hover') }
		},
		function(){ $(this).removeClass('hover') }
	)
}

var IE = document.all?true:false

$(document).ready(function()
{
	
		//menu mouseover
	$("#menu li, #subnav li").hover(
		function(){	
			if ((this).className != 'act'){
				$(this).addClass('hover');
			}},
		function(){	$(this).removeClass('hover');	}
	);

	//menu mouseover
	$(".highlights a").hover(
		function(){	
//		alert ($(this).attr("id"));
			var block = $(this).closest('div');
			$(block).find('a').removeClass('act');
			var showItem = this.className.split('_').pop();

			$(this).addClass('act');
			$(block).find('.item').hide();
//			$(block).find('.price').hide();
			$(block).find('.showBlock_' + showItem).show();
//			$(block).find('.price_' + showItem).show();
//		$(this).addClass('hover');	
		}, 
		function(){	}
	);

	//menu mouseover
	$(".mOn").hover(
		function(){	$(this).addClass('hover');	}, 
		function(){	$(this).removeClass('hover');	}
	);

	$(".forgot-pass a").click(function(){
		if($("#showBlockLogin").css("display") == "none") {
			$('#showBlockPassword').hide();
			$('#showBlockLogin').show();
		}else{
			$('#showBlockPassword').show();
			$('#showBlockLogin').hide();
		};
		return false;
	});
	
	$(".check").click(function(){
			var imgsrc = $(this).find("img").attr("src");
			var input = $(this).find("input");
			if(imgsrc.indexOf('-on.gif')==-1){
				imgsrc = imgsrc.replace('.gif','-on.gif');
				$(this).find("img").attr('src',imgsrc);
				if ($(input).size() > 0){
					$(input).attr("value","true");
				}
				if ((this).id == "delivery"){
					$('#showBlockDelivery').show();
				}	

			}else{
				imgsrc = imgsrc.replace('-on.gif','.gif');
				$(this).find("img").attr('src',imgsrc);
				if ($(input).size() > 0){
					$(input).attr("value","");
				}
				if ((this).id == "delivery"){
					$('#showBlockDelivery').hide();
				}	
			}
		}
	);
	applyHovers();

});


function ShowMailaFriend() {AnimateThis('mailafriend')}

function AnimateThis(id) {
	if(!IE){ //werkt niet in IE ???
		$('#' + id).animate({opacity: 0}, 1).animate({opacity: 1}, 500);
	}
}

function showMessage(id){
	display('item-'+ id +'-ok','item-'+ id)
	setTimeout("display('item-"+ id +"','item-"+ id +"-ok')",3000)
}

function ShowShoppingcart() {
    /*
    $('#shoppingcart').animate({
        opacity: 0
    }, 1);
    $('#shoppingcart').animate({
        opacity: 1
    }, 500);
    */
}

function mOn(obj) {
	var ext = obj.src.slice(-3)
	if(obj.src.indexOf('-on.'+ ext)==-1){
		obj.src=obj.src.replace('.'+ ext,'-on.'+ ext)
	}
}
function mOut(obj) {
	var ext = obj.src.slice(-3)
	obj.src=obj.src.replace('-on.'+ext,'.'+ext)
}

function increaseAmount(textid) {
    if (isNaN($('#' + textid).val())) {
        $('#' + textid).val(1);
    } else {
        if (eval($('#' + textid).val()) < 99) {
            $('#' + textid).val(eval($('#' + textid).val()) + 1);
        }
    }
    return true;
}

function decreaseAmount(textid) {
    if (isNaN($('#' + textid).val())) {
        $('#' + textid).val(1);
    } else {
        if (eval($('#' + textid).val()) > 1) {
            $('#' + textid).val(eval($('#' + textid).val()) - 1);
        }
    }
    return true;
}

function toggleCheckbox(id, show, checked){
	//wanneer undefined, bepaal of checkbox aan of uitgezet moet worden...
	if(checked===undefined){
		if(document.getElementById('check_'+id).src.indexOf('_o.gif')>-1){
			checked = false;
		}else{
			checked = true;
		}
	}
	if(checked){
		$('#'+ id).attr('value','1');
		mOn(document.getElementById('check_'+ id));
		$('#'+ show).css('display','block');
	}else{
		$('#'+ id).attr('value','');
		mOut(document.getElementById('check_'+ id));
		$('#'+ show).css('display','none');
	}
}

function toggleTop(obj, id, arr){
	if(arr!=undefined) {
		var a = arr.split(',')
		for(i=0;i<a.length;i++){
			if(document.getElementById(a[i])) document.getElementById(a[i]).style.display='none'
			$('#'+ a[i]).parent().attr('class','');
		}
	}
	$('#'+ id).css('display', 'block');
	$(obj).parent().attr('class','active');
}

// Versie 1.2 (WdS)
function submitNewletterForm(inputId,trueCont,falseCont,wrongCont,path) {
	if(isEmail($('#' + inputId).attr('value'))){
    $.ajax({
        type: "POST",
        url: path + "xml/SubscribeNewsletter?mail=" + $('#' + inputId).attr('value'),
        dataType: "html",
				data: "{}",
        success: function(txt) {            
            if (txt.toUpperCase() == 'TRUE') {
								$('#' + wrongCont).css("display", "none");
                $('#' + trueCont).css("display","block");
                $('#' + falseCont).css("display","none");
            }
            else {
								$('#' + wrongCont).css("display", "none");
                $('#' + trueCont).css("display", "none");
                $('#' + falseCont).css("display", "block");                
            }
        }
    });
	}else{
		$('#' + wrongCont).css("display", "block");
		$('#' + trueCont).css("display", "none");
    $('#' + falseCont).css("display", "none");
	}
}

// Versie 1.2 (JS)
function RemoveSingleViewedArticles(path,id) {
		$.get(path + 'xml/RemoveSingleViewedArticles?id='+id);
		$('#viewedarticles-'+id).html('');
}

// Versie 1.2 (JS)
function RemoveViewedArticles(path) {
    $.get(path + 'xml/RemoveViewedArticles');
    $('#viewedarticles').html('');
}
/*
function printing(cmd){
	if (cmd) { // activate printing
		$('#cont_printing').css('display','block');
		$('#pricelisting').css('display','block');
	} else { // deactivate printing
		$('#cont_printing').css('display','none');
		$('#pricelisting').css('display','none');
		fill('printingText','naam,nr',1,'defaultNames');
	}
}
*/
// Versie 1.1 (MK)
function printing(obj){
	if(obj==0){ //activate printing
//		radio('1','radio0','bedrukking');
		$('#cont_printing').css('display','none');
		fill('printingText','naam,nr',1);
//		$('#containter_pricesum').css('display','block');

	}else{ //deactivate printing
//		radio('','radio1','bedrukking');
		$('#cont_printing').css('display','block');		
//		$('#containter_pricesum').css('display','none');
//		initializePricelisting();
		//clear
		//fill('printingText','naam,nr',1,'defaultNames');
		fill('printingText','naam,nr',1);
	}
}
// Versie 1.3 (GPS)
function fill(dest, source, clear, predefined){
	var arr = source.split(',');
	var textToInsert = ''; var currentValue = '';
	if(predefined){
		var predefinedObj = document.getElementById(predefined);
		var predefinedArr = predefinedObj.options[predefinedObj.selectedIndex].value.split(',');
	}
	if(!clear){
		$.each(arr, function(count, item){
			if(textToInsert!='') textToInsert += ', ';
			if(predefined){
				currentValue = predefinedArr[count];
				$('#'+ item).val(predefinedArr[count])
			}else{
				currentValue = $('#'+ item).val()
			}
			textToInsert += $('#'+ item +'title').val() + currentValue.toUpperCase();
		})
	}else{ //restore
		if(predefined){
			predefinedObj.selectedIndex = 0;
		}
		$.each(arr, function(count, item){
			$('#'+ item).val($('#'+ item +'value').val());
		});
	}
	$('#' + dest).val(textToInsert);
}

// Versie 1.2 (WdS)
function updateArticleDetail(articleId, orgSpec1, orgSpec2, htmlCont, path, viewname) {
		if(!viewname) viewname = ""
    var selectedSpec01, selectedSpec02, printing
    if (document.getElementById(orgSpec1)) {
				if (document.getElementById(orgSpec1).tagName == 'INPUT') {
	        selectedSpec01 = document.getElementById(orgSpec1).value
				} else {
	        selectedSpec01 = document.getElementById(orgSpec1).options[document.getElementById(orgSpec1).selectedIndex].value
				}
				if (document.getElementById('hsSpec_01')) {
					document.getElementById('hsSpec_01').value = selectedSpec01;
				}
    } else {
        selectedSpec01 = 0
    }
    if (document.getElementById(orgSpec2)) {
				if (document.getElementById(orgSpec2).tagName == 'INPUT') {
	        selectedSpec02 = document.getElementById(orgSpec2).value
				} else {
	        selectedSpec02 = document.getElementById(orgSpec2).options[document.getElementById(orgSpec2).selectedIndex].value
				}
				if (document.getElementById('hsSpec_02')) {
					document.getElementById('hsSpec_02').value = selectedSpec02;
				}
		} else {
        selectedSpec02 = 0
    }
		if(!printing) printing = 0
    $.ajax({
        type: "POST",
        url: path + 'xml/UpdateArticleDetail?Id=' + articleId + '&spec01Id=' + selectedSpec01 + '&spec02Id=' + selectedSpec02 + "&viewName=" + viewname,
        dataType: "html",
				data: "{}",
        success: function(html) {
					document.getElementById(htmlCont).innerHTML = html;
					applyHovers();

					//initializePricelisting();
        }
    });

}

// Versie 1.3.2 (JS)
function updateArticleFromAddToOrder(articleId, orgSpec1, orgSpec2, htmlCont, path) {
    var selectedSpec01, selectedSpec02
    if (document.getElementById(orgSpec1)) {
        selectedSpec01 = document.getElementById(orgSpec1).options[document.getElementById(orgSpec1).selectedIndex].value
    } else {
        selectedSpec01 = 0
    }
    if (document.getElementById(orgSpec2)) {
        selectedSpec02 = document.getElementById(orgSpec2).options[document.getElementById(orgSpec2).selectedIndex].value
    } else {
        selectedSpec02 = 0
    }
    $.ajax({
        type: "POST",
        url: path + 'xml/UpdateArticleDetail?Id=' + articleId + '&spec01Id=' + selectedSpec01 + '&spec02Id=' + selectedSpec02 + '&viewName=ArticleAddToOrder',
        data: {},
        dataType: "html",
        success: function(html) {            
            $('#' + htmlCont).html(html);
        }
    });
}

function AddRelatedArticlesToOrder(sender, path, checkout_url, related) {
    try {
        var timeout = 0;
        var id = 0;
        var tmpStr = '';

        if (attributesValid(sender)) {

            //Haal ook de gegevens op van het huidige product
            var articleId = $('#articleId').val();
            var articleSpecId = $('#specId').val();
            var articleAmount = $('#amount-' + articleId).val();
            var articleAttributes = getArticleAttributes();
            var articlePrintingText = $('#printingText').val();
            if (!articlePrintingText) articlePrintingText = '';
            timeout += 600;
            $.ajax({
                type: 'GET',
                url: path + 'xml/AddToShoppingCart',
                data: 'articleId=' + articleId + '&amount=' + articleAmount + '&printingText=' + articlePrintingText + '&specId=' + articleSpecId + "&attributes=" + escape(articleAttributes),
                success: function(html) {
                    showMessage(articleId)
                    document.getElementById('shoppingcart').innerHTML = html;
                }
            });
            //einde ophalen gegevens van het huidige product

            // Gerelateerde artikelen
            $("[name=addToOrder]:checked").each(function() {
                tmpStr = $(this).attr('id');
                id = tmpStr.substr(tmpStr.indexOf('_') + 1);

				var specId = $('#specId-' + id).val();
				var amount = $('#amount-' + id).val();
							
                //var specId = 0;
                //var amount = $('#amount-' + id).val();
                //if (amount > 0) {
                    //				if ($('#spec1-' + id).val() == '0' || $('#spec2-' + id).val() == '0') {
                    //					display('related_error_specs', 'related_button');
                    //					//alert('Specificatie is niet ingevuld')
                    //					error = true;
                    //				} else {
                    timeout += 600;
                    $.ajax({
                        type: 'GET',
                        url: path + 'xml/AddToShoppingCart',
                        data: 'articleId=' + id + '&amount=' + amount + '&printingText=&specId=' + specId
                    });
                    //				}
                //}
            });

            setTimeout("display('related_button','related_error_selected,related_error_specs')", 2000);
        }
        return false;

    } catch (err) {
        alert("Er is iets foutgegaan. Probeer het opnieuw door deze pagina te herladen. " + err.message);
    }
}

//// Versie 1.3 (JS)
//function AddRelatedArticlesToOrder(path, checkout_url, related) {
//    try {
//        var timeout = 0;
//        var error = false;
//				var id = 0;
//				var tmpStr = '';
//				var newCart = '';

//				//gegevens van hoofdartikel
//				var articleId = $('#articleId').val();
//				var articleSpecId = $('#specId').val();
//				var articleAmount = $('#amount-' + articleId).val();
//				var articlePrintingText = $('#printingText').val();
//				if(!articlePrintingText) articlePrintingText = '';

//				//check of alle specs ingevuld zijn...
//				$("[name=addToOrder]:checked").each(function() {
//					tmpStr = $(this).attr('id');
//				 	id = tmpStr.substr(tmpStr.indexOf('_') + 1);
//					if ($('#spec1-' + id).val() == '0' || $('#spec2-' + id).val() == '0') {

//						display('item-'+ articleId +'-ok-error','item-'+ articleId +'-ok-text');
//						display('item-'+ articleId +'-ok','item-'+ articleId);
//						error = true;
//					}
//				});

//				// Indien geen error, dan alle (eventueel) aangevinkte artikelen aan winkelwagen toevoegen.
//				if(!error) {
//					display('item-'+ articleId +'-ok-text','item-'+ articleId +'-ok-error');

//					$("[name=addToOrder]:checked").each(function() {
//							tmpStr = $(this).attr('id');
//							id = tmpStr.substr(tmpStr.indexOf('_') + 1);
//							var specId = $('#specId-' + id).val();
//							var amount = $('#amount-' + id).val();
//							if ($('#spec1-' + id).val() == '0' || $('#spec2-' + id).val() == '0') {
//									error = true;
//							} else {
//									timeout += 600;
//									$.ajax({
//											type: 'GET',
//											url: path + 'xml/AddToShoppingCart',
//											data: 'articleId=' + id + '&amount=' + amount + '&printingText=&specId=' + specId
//									});
//							}
//					});

//					//Haal ook de gegevens op van het huidige product
//					timeout += 600;
//					$.ajax({
//							type: 'GET',
//							url: path + 'xml/AddToShoppingCart',
//							data: 'articleId=' + articleId + '&amount=' + articleAmount + '&printingText='+ articlePrintingText +'&specId=' + articleSpecId,
//							success: function(html) {
//								document.getElementById('shoppingcart').innerHTML = html;
//							}
//					});
//					//einde ophalen gegevens van het huidige product
//					display('item-'+ articleId +'-ok','item-'+ articleId);
//        }
//				setTimeout("display('item-"+ articleId +"','item-"+ articleId +"-ok')", 2000);
//        if (!error){
//            //setTimeout(function() { location.href = checkout_url; }, timeout);
//            return false
//        }else{
//            return false;
//        }
//    } catch (err) {
//        alert("Er is iets foutgegaan. Probeer het opnieuw door deze pagina te herladen. " + err.message);
//    }
//}

function expandFlash(bool){
	if(bool){
		$('#container_info').css('display','none');
		$('#container_image').attr('class','flash_wide')
	}else{
		$('#container_image').attr('class','flash')
		$('#container_info').css('display','block')
	}
}

function openBig(url){
	if(url!='') $('#bigimage').attr('href',url);
	document.getElementById('bigimage').onclick();
}

function toggleOrder(id){
	$('#item-'+id).css('display','block');
	$('#line-'+id).css('color','#333333');
	var thisurl = $('#arrow-'+id).attr('src');
	if(thisurl.indexOf('_o.gif')==-1){
		$('#arrow-'+id).attr('src',thisurl.replace('.gif','_o.gif'));
	}
}

//functie voor setten van 1 checkbox, geen komma's in value
//v = waarde true
//w = waarde false
function checkThis(v, w, id, input) {
	var obj = document.getElementById(input)
	if(obj.value.indexOf(v)==-1){
		obj.value=v;
		document.getElementById(id).src = document.getElementById(id).src.replace('.gif','_o.gif')
	}else{
		obj.value=w;
		document.getElementById(id).src = document.getElementById(id).src.replace('_o.gif','.gif')
	}
}

//Versie 1.5 (WdS)
function UpdateSpecInShoppingcart(articleId,spec1,spec2,htmlCont,path,oldRelId,isCheckout) {
    var selectedSpec01, selectedSpec02
    if (document.getElementById(spec1)) {
        selectedSpec01 = document.getElementById(spec1).options[document.getElementById(spec1).selectedIndex].value
    } else {
        selectedSpec01 = 0
    }
    if (document.getElementById(spec2)) {
        selectedSpec02 = document.getElementById(spec2).options[document.getElementById(spec2).selectedIndex].value
    } else {
        selectedSpec02 = 0
    }

    try {
        $.ajax({
            type: 'GET',
            url: path + 'xml/ChangeSpecs',
            data: 'articleId=' + articleId + '&OldRelId=' + oldRelId + '&spec1=' + selectedSpec01 + '&spec2=' + selectedSpec02 + '&isCheckout=' + isCheckout,
            success: function(html) {
                //alert(html);
                //alert('#' + htmlCont)
                $('#' + htmlCont).html(html);
            }            
        });
    } catch (err) {
    alert("Er is iets foutgegaan. Probeer het opnieuw door deze pagina te herladen. " + err.message);
    }    
}

// Versie 1.7 (JS)
function addCouponCode(val, path) {
	$('#error-coupon').hide();
	$.ajax({
		type: "POST",
		url: path + 'xml/AddCouponCode?typeid=4&code=' + val,
		data: {},
		dataType: "html",
		success: function(html) {
			if (html == 'True') {
				location.reload(true);
			} else {
				$('#error-coupon').show();
			}
		}
	});
}

// Versie 1.7 (JS)
function removeCouponCode(val, path) {
	$('#error-coupon').hide();
	$.ajax({
		type: "POST",
		url: path + 'xml/RemoveCouponCode?code=' + val,
		data: {},
		dataType: "html",
		success: function(html) {
			if (html == 'True') {
				location.reload(true);
				
			} else {
				$('#error-coupon').show();
			}
		}
	});
}	

function readMore() {
	$(".readmore").hide();
	$(".hiddendesc").show();
	return false;
}