﻿
$(document).ready(function() {

	$(".articleItem").hover(function() {
        $(".articleItem-header", this).addClass("articleItem-header-active");
        $(".articleItem-content", this).addClass("articleItem-content-active");
        $("a:first", this).addClass("active");
    }, function() {
        $(".articleItem-header", this).removeClass("articleItem-header-active");
        $(".articleItem-content", this).removeClass("articleItem-content-active");
        $("a:first", this).removeClass("active");
    }).click(function() {
        location.href = $("a:first", this).attr("href");
    });

	$("#accordion").accordion({
		event: "mouseover", animated: "easeslide"
	});

	// Benodigd voor bestel formulieren (orderconfirmation).
	$('.ajaxform').bind("submit",function() {
		var f = $(this);
		var action = f.attr("action");
		var serializedForm = f.serialize();
		$.post(action,serializedForm,function(){});
		return false;
	});

});


function SubmitOrder(o,formId,a) {
	//alert(a);
	o.href = o.href.replace("{AMOUNT}",eval(a));
	hs.htmlExpand(o, { objectType: 'ajax',preserveContent:false,cacheAjax:false,outlineType:'storagestore2'} );
	$('#'+formId).submit();
	return false;
}



// Versie 1.3 (JS)
function FillShoppingCart(o, id, amount, text, specId) {
	//alert(id);
    // PATH_LANG is gedefinieerd.
    var path = PATH_LANG;
    // Printingtext opslaan als: Naam: Test, Nr: 1
    //alert(path + 'xml/AddToShoppingCart?articleId=' + id + '&amount=' + amount + '&printingText=' + text + '&specId=' + specId + '');
    alert(path + 'xml/AddToShoppingCart?articleId=' + id + '&amount=' + amount + '&printingText=' + text + '&specId=' + specId + '');
	$.get(path + 'xml/AddToShoppingCart?articleId=' + id + '&amount=' + amount + '&printingText=' + text + '&specId=' + specId + '');
}


function ShowShoppingCartMessage(o, i, t, a) {
	/*
    $("#highslide-producttitle").html('' + t + '');
	$("#highslide-productamount").html('' + a + '');
	$("#highslide-productimage").html('' + '<img src="' + i + '" alt="" />' + '');
	hs.htmlExpand(document.getElementById('my-content-addedtoshoppingcart'), {  outlineType:'storagestore2', contentId: 'my-content-addedtoshoppingcart', align: 'center', wrapperClassName: 'borderless' , preserveContent: false, cacheAjax:false }, {myImage:'<img src="' + i + '" alt="" />',myTitle:t,myAmount:a});	
	*/
	hs.htmlExpand(document.getElementById('my-content-addedtoshoppingcart'), {  objectType: 'ajax', outlineType:'storagestore2', backgroundColor: '#fff9e7', align: 'center', wrapperClassName: 'borderless', preserveContent: false, cacheAjax:false } );
}

function showMessage(id){
	display('item-'+ id +'-ok','item-'+ id)
	setTimeout("display('item-"+ id +"','item-"+ id +"-ok')",2000)
}

function ShowShoppingcart() {
    $('#shoppingcart').animate({
        opacity: 0
    }, 1);
    $('#shoppingcart').animate({
        opacity: 1
    }, 100);
}


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 showTab(id, cnt) {
	for (var c=1; c<=cnt; c++) {
		$('#specs_h_'+ c).attr('class','');
		$('#specs_cont_'+ c).css('display','none');
	}
	$('#specs_h_'+ id).attr('class','active');
	$('#specs_cont_'+ id).css('display','block');
}

function printme(show) {
    var objOut = document.getElementById("output");
    var out = objOut.innerHTML;
		if(show){
			out = out.replace('display: none','')
			out = out.replace('DISPLAY: none','')
		}

    var wh = window.open("", "wh", "width=640px,height=480px,scrollbars=yes");
    wh.document.open();
    var output = '<link href="' + PROJECT_URL + 'shared/print.css" rel="stylesheet" type="text/css">';
    output = '<html><head>' + output + '</head><body>' + out.replace('<object', '<!--object').replace('/object>', '/object-->') + '</body></html>';
    output += '<' + 'script type="text/javascript">';
    output += 'setTimeout("window.print()",1000);';
    output += '</' + 'script>';
    wh.document.writeln(output);
    wh.document.close();
}

function showImage(nr){
	var cnt = document.getElementById('images-count').value
	for (var c=1; c<=cnt; c++) {
		$('#articleimage-'+ c).css('display','none');
	}
	$('#articleimage-'+ nr).css('display','block');
}

function toggleCheckbox(id, show, hide){
	if($('#'+ id).attr('checked')){
		$('#'+ show).css('display','block');
		if(hide) $('#'+ hide).css('display','none');
	}else{
		$('#'+ show).css('display','none');
		if(hide) $('#'+ hide).css('display','block');
	}
}

// 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('');
}

// Versie 1.2 (WdS)
function updateArticleDetail(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,
        dataType: "html",
				data: "{}",
        success: function(html) {                    
            $('#' + htmlCont).html(html);
						initSIFR();
        }
    });
}

//Versie 1.3 (WdS)
function DoLanguageActions(path){
		$.ajax({
        type: "POST",
        url: path + "xml/LangChangedActions",
		dataType: "html",
		data: "{}",
		success: function(){
		
		}
		});
}

//Versie 1.3.1 (WdS)
function showPreOrderResult(modelId) {    
    $('#mailform_' + modelId).hide();
    $('#mailFormResult_' + modelId).show();
    $('#preOrderBtn_' + modelId).hide();    
}



// 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");
	}
}

function hideCheckoutButton()
{
	if ($('#shoppingcartcheckout').html().length < 100) {
		$('#checkoutbutton').css('visibility','hidden');
	}
}

function toggleLi(groupId) {
    $('.toHide' + groupId).toggleClass('hidden');
    return false;
}

