/**
 * @author sebastiaan
 */



function PmsInputSet()
{
	if($('pmsSelect1').checked)
	{
		$('pms1').show();
		$('pms2').hide();
		$('pms3').hide();
		$('pms4').hide();
		$('pms5').hide();
	}
	else if($('pmsSelect2').checked)
	{
		$('pms1').show();
		$('pms2').show();
		$('pms3').hide();
		$('pms4').hide();
		$('pms5').hide();
	}
	else if($('pmsSelect3').checked)
	{
		$('pms1').show();
		$('pms2').show();
		$('pms3').show();
		$('pms4').hide();
		$('pms5').hide();
	}
	else if($('pmsSelect4').checked)
	{
		$('pms1').show();
		$('pms2').show();
		$('pms3').show();
		$('pms4').show();
		$('pms5').hide();
	}
	else if($('pmsSelect5').checked)
	{
		$('pms1').show();
		$('pms2').show();
		$('pms3').show();
		$('pms4').show();
		$('pms5').show();
	}	
}

function UpdateOrderForm()
{
	new Ajax.Request('/ajax.php?mode=calculate', {
        method:'get',
        parameters: $('orderFormFirstForm').serialize(true),
        evalJSON: 'force',
        onSuccess: function(calculation)
        {
            $('nextStep').title = '';
            if ($('sample').checked)
            {
                $('amount').hide();
                /*if($('amount').value == "")
                {
                    $('amount').value = "100";
                }*/
                $('amountSample').show();
                $('hasteCostTotal').hide();
                $('hasteCostTotalLabel').hide();
                $('halfSamplePrice').innerHTML = calculation.responseJSON[19];
                $('dhaste').hide();
                $('sampleText').show();
                $('print').hide();
                /*$('offerte').hide();*/
                $('nextStep').disabled = '';
                $('nextStep').removeClassName('isoff');
                $('nextStep').addClassName('ison');
            }
            else
            {
                $('amountSample').hide();
                $('amount').show();
                $('hasteCostTotal').show();
                $('hasteCostTotalLabel').show();
                $('sampleText').hide();
                $('dhaste').show();
                $('print').show();
                $('offerte').show();

                if($('amount').value == '')
                {
                    $('nextStep').removeClassName('ison');
                    $('nextStep').addClassName('isoff');
                    $('nextStep').disabled = 'disabled';
                    $('offerte').removeClassName('ison');
                    $('offerte').addClassName('isoff');
                    $('offerte').disabled = 'disabled';
                }
                else
                {
                    $('nextStep').disabled = '';
                    $('nextStep').removeClassName('isoff');
                    $('nextStep').addClassName('ison');
                    $('offerte').disabled = '';
                    $('offerte').removeClassName('isoff');
                    $('offerte').addClassName('ison');
                }
            }
            
            var queryString = document.location.toString().parseQuery();
            if(queryString.productID == 330858 || queryString.productID == 330857) { //ballen van the COW company waar geen spoed mogelijk is
                $$('#nohaste p').first().innerHTML = 'Zie voor levertijd <em>\'Extra informatie\'</em>.';
            }

            if(!$('printYes').checked || $('sample').checked)
            {
                $('dhaste').hide();
                $('nohaste').show();
            } else {
                if(queryString.productID != 330858 && queryString.productID != 330857) { //ballen van the COW company waar geen spoed mogelijk is
                    $('dhaste').show(); //normaal
                    $('nohaste').hide();
                } else { //geen spoed mogelijk
                    $('dhaste').hide();
                    $('nohaste').show();
                }
            }

            //spoedkosten niet weergeven indien nvt
            if($('printYes').checked && $('hasteOn').checked) {
                $('hasteOnly').show();
            } else {
                $('hasteOnly').hide();
            }

            //is amount the asked amount? or is the totalPrice on request?
            if ($('amount').value == calculation.responseJSON[15] || calculation.responseJSON[15] == undefined
                || calculation.responseJSON[15] == 'Sample' || calculation.responseJSON[15] == 'sample') {
                //is the totalprice not "on request"
                if (calculation.responseJSON[15] != undefined) {
                    if($('productID').value != '350000') {
                        $('productPricePiece').innerHTML = calculation.responseJSON[16];
                        $('amountTotal').innerHTML = calculation.responseJSON[15] + " x";
                        $('productPriceTotal').innerHTML = calculation.responseJSON[17];
                        $('hasteCostTotal').innerHTML = calculation.responseJSON[5] + " +";
                        $('grandTotal').innerHTML = calculation.responseJSON[18];
                    } else {
                        $('productPricePiece').innerHTML = "Prijs in overleg";
                        $('amountTotal').innerHTML = $('amount').value + " x";
                        $('productPriceTotal').innerHTML = "Prijs in overleg";
                        $('hasteCostTotal').innerHTML = "in overleg +";
                        $('grandTotal').innerHTML = "Prijs in overleg";
                        
                        $('offerte').removeClassName('ison');
                        $('offerte').addClassName('isoff');
                        $('offerte').disabled = true;
                    }
                    
                    $('invoice').removeClassName('ison');
                    $('invoice').addClassName('isoff');
                    $('invoice').disabled = true;
                    $('invoice').hide();

                    $('nextStep').disabled = false;
                    $('nextStep').removeClassName('isoff');
                    $('nextStep').addClassName('ison');
                    $('nextStep').show();
                }
                else {
                    //fill "on request"
                    $('productPricePiece').innerHTML = "Op aanvraag";
                    $('amountTotal').innerHTML = $('amount').value + " x";
                    $('productPriceTotal').innerHTML = "Op aanvraag";
                    $('hasteCostTotal').innerHTML = "Op aanvraag +";
                    $('grandTotal').innerHTML = "Op aanvraag";

                    //knoppen uitschakelen
                    $('nextStep').removeClassName('ison');
                    $('nextStep').addClassName('isoff');
                    $('nextStep').disabled = true;
                    $('nextStep').hide();

                    $('invoice').disabled = false;
                    $('invoice').removeClassName('isoff');
                    $('invoice').addClassName('ison');
                    $('invoice').show();

                    $('offerte').removeClassName('ison');
                    $('offerte').addClassName('isoff');
                    $('offerte').disabled = true;
                }
            }
            if(Load.SHOP_INCLUDE_ID == 'allgifts') {
                $('exBTWcomment').innerHTML = "Alle prijzen hierboven zijn incl.&nbsp;transport- en voorbereidingskosten bij opdruk.<br> Exclusief BTW.";
            } else {
                $('exBTWcomment').innerHTML = "Alle prijzen hierboven zijn incl. transport- en voorbereidingskosten bij opdruk.<br> Exclusief BTW.";
            }

            if(!$('amount').value && calculation.responseJSON[15] != 'Sample') {
                if(!$('productPricePiece').innerHTML.strip().match(/ 0,000/gi)) {
                    $('productPricePiece').innerHTML = "<strong>Al vanaf " + $('teasePrice').value + "</strong>";
                }

                if($('productPricePiece').innerHTML.strip().match(/ 0,000/gi)) {
                    $('productPricePiece').innerHTML = 'Op aanvraag';
                }

                $('nextStep').disabled = true;
                $('nextStep').removeClassName('ison');
                $('nextStep').addClassName('isoff');
                $('nextStep').disabled = 'disabled';
                $('nextStep').title = 'Vul uw gewenste aantal in en bereken uw prijs';
                $('nextStep').show();

                //alert('dus');

                $('invoice').disabled = true;
                $('invoice').removeClassName('ison');
                $('invoice').addClassName('isoff');
                $('invoice').disabled = 'disabled';
                $('invoice').hide();

                $('offerte').disabled = true;
                $('offerte').removeClassName('ison');
                $('offerte').addClassName('isoff');
                $('offerte').disabled = 'disabled';


                if(!$('productPricePiece').innerHTML.strip().match(/Op aanvraag/gi)) {
                    $('amountTotal').innerHTML = "0 x";
                    $('productPriceTotal').innerHTML = "&euro; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
                    $('hasteCostTotal').innerHTML = "&euro; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +";
                    $('grandTotal').innerHTML = "&euro; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
                } else {
                    OpAanvraagComment(true);
                }
            } else if($('amount').value && $('productPricePiece').innerHTML.strip().match(/Op aanvraag/gi)) {
                OpAanvraagComment();
            }
            TotalsUpdated();
        }
    });
}

var TotalsUpdatedTimeOut = null;
function TotalsUpdated() { //doet niets voor nu
//    clearTimeout(TotalsUpdatedTimeOut);
//    TotalsUpdatedTimeOut = setTimeout(
//        ShowTotalsUpdated,
//        500
//    );

//    ShowTotalsUpdated();
}

function ShowTotalsUpdated() {
    
    var block = $('totals');
    if(block.originalColor == undefined) {
        block.originalColor = block.getStyle('background-color');
//        block.morphFromColor = '#EBC11C';
        block.morphFromColor = '#F6DB73';
//        block.morphFromColor = '#ffffff';
    }

    if(block.effect != null) {
        block.effect.cancel();
        block.effect = null;
        block.setStyle('background-color:' + block.originalColor);
    }

//    alert(block.originalColor);
//    alert(block.morphFromColor);

    block.setStyle('background-color:' + block.morphFromColor)
    block.effect = new Effect.Morph(block, {
        style: 'background-color:' + block.originalColor,
//        startcolor: block.morphFromColor,
//        endcolor: block.originalColor,
        duration: 1.0, // Core Effect properties
        afterFinish: function() {
            block.effect = null;
        }
    });
}

function OpAanvraagComment(dontShowSpecial)
{
    if(!dontShowSpecial) {
        $('exBTWcomment').innerHTML = "Online berekening is bij dit aantal of configuratie op aanvraag.\n<br />";
        $('exBTWcomment').innerHTML += "Via onderstaande knop 'speciale prijs' kunt u de aanvraag naar ons sturen maar natuurlijk mag u ons ook bellen ("+Load.SHOP_TEL+").";
    } else {
        $('exBTWcomment').innerHTML = "Online berekening is bij dit product niet beschikbaar.\n<br />";
        $('exBTWcomment').innerHTML += "U kunt wel een aantal en configuratie van dit product opgeven voor een offerteaanvraag. U mag ons natuurlijk ook altijd bellen ("+Load.SHOP_TEL+").";
    }
    if(Load.SHOP_INCLUDE_ID == 'eco') {
        $('exBTWcomment').setStyle('bottom:10px;');
    }
}

function DeliverySame()
{
	formName = arguments[0] ? arguments[0] : 'laststep';
	if($('delSame').checked)
	{
		ValidateForm(formName);
	}
	else
	{
		ValidateForm(formName);
	}
}

