var boeketPrijs, boeketBloem, boeketMeer, addP, mustBe, prevP = 0, addPrice = 0;

function calcPrice()
{
	var totalPrice = boeketPrijs;	
	var qBloem = (document.getElementById('quanBloem') != null) ? document.getElementById('quanBloem').value : 0;
	var pMeer = (document.getElementById('quanMeer') != null) ? document.getElementById('quanMeer').value : 0;
	
	if(qBloem != 0)
	{
		totalPrice += (qBloem*boeketBloem);
	}

	if(pMeer != 0)
	{
		totalPrice += parseFloat(pMeer);
	}
	
	if(document.getElementById('factuur').checked == true)
	{
		totalPrice += 1.5;
	}
	
	if(document.getElementById('kraslot').checked == true)
	{
		totalPrice += 1;
	}
	
	totalPrice += parseFloat(addPrice);	
	if(totalPrice < 12 && mustBe == 1)
	{
		totalPrice = 12;
		document.getElementById('minP').style.backgroundColor = '#FFFD57';
	}
	else if(totalPrice > 12 && mustBe == 1)
	{
		document.getElementById('minP').style.backgroundColor = '';
	}
	
	document.getElementById('totalPrice').innerHTML = '&euro;'+formatAsMoney(totalPrice);
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;

    mnt = (mnt == Math.floor(mnt)) ? mnt + ',00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
    return mnt.replace('.', ',');
}

function adresOvereenCheck(keep)
{
	if(document.getElementById('overeen').checked == true)
	{
		document.getElementById('bezorgNaam').value = document.getElementById('voornaam').value;
		document.getElementById('bezorgAchternaam').value = document.getElementById('achternaam').value;
		document.getElementById('bezorgAdres').value = document.getElementById('adres').value;
		document.getElementById('bezorgPostcode').value = document.getElementById('postcode').value;
		document.getElementById('bezorgWoonplaats').value = document.getElementById('woonplaats').value;
		
		document.getElementById('bezorgNaam').disabled = true;
		document.getElementById('bezorgAchternaam').disabled = true;
		document.getElementById('bezorgAdres').disabled = true;
		document.getElementById('bezorgPostcode').disabled = true;
		document.getElementById('bezorgWoonplaats').disabled = true;
	}
	else
	{
		if(keep != 1)
		{
			document.getElementById('bezorgNaam').value = '';
			document.getElementById('bezorgAchternaam').value = '';
			document.getElementById('bezorgAdres').value = '';
			document.getElementById('bezorgPostcode').value = '';
			document.getElementById('bezorgWoonplaats').value = '';
		}
		
		document.getElementById('bezorgNaam').disabled = false;
		document.getElementById('bezorgAchternaam').disabled = false;
		document.getElementById('bezorgAdres').disabled = false;
		document.getElementById('bezorgPostcode').disabled = false;
		document.getElementById('bezorgWoonplaats').disabled = false;
	}
}

function enableFields()
{
		document.getElementById('bezorgNaam').disabled = false;
		document.getElementById('bezorgAchternaam').disabled = false;
		document.getElementById('bezorgAdres').disabled = false;
		document.getElementById('bezorgPostcode').disabled = false;
		document.getElementById('bezorgWoonplaats').disabled = false;
		
		document.getElementById('bezorgNaam').style.color = 'gray';
		document.getElementById('bezorgAchternaam').style.color = 'gray';
		document.getElementById('bezorgAdres').style.color = 'gray';
		document.getElementById('bezorgPostcode').style.color = 'gray';
		document.getElementById('bezorgWoonplaats').style.color = 'gray';
}

function kaartCheck()
{
	if(document.getElementById('kaartje').value.split(',')[1] == 'Nee')
	{
		document.getElementById('kaartTekst').value = '';
		document.getElementById('kaartTekst').disabled = true;
	}
	else
	{
		document.getElementById('kaartTekst').disabled = false;
	}
}

function MaxLength(Object, MaxLen)
{
	if(Object.value.length > MaxLen)
	{
		document.getElementById('kaartTekst').value = document.getElementById('kaartTekst').value.substring(0, MaxLen);
	}
	
	document.getElementById('kaartTekstTekens').innerHTML = MaxLen-Object.value.length;
}

function clearForm(formName)
{
	if (confirm("Weet u zeker dat u alle velden wilt legen?"))
	{
		document.forms[formName].reset();
	}
}

function knowSure(msg, url)
{
	if(confirm(msg))
	{
		window.location = url;
	}
}

function payChoice(payID)
{
	document.getElementById('payNotice').style.display = 'none';
	
	document.getElementById('iDeal').className = (payID == 'iDeal' ? 'active' : '');
	document.getElementById('iDeal_pay').style.display = (payID == 'iDeal' ? 'inline' : 'none');
	
	document.getElementById('PayPal').className = (payID == 'PayPal' ? 'active' : '');
	document.getElementById('PayPal_pay').style.display = (payID == 'PayPal' ? 'inline' : 'none');
	
	if(document.getElementById('Machtiging') != null)
	{
		document.getElementById('Machtiging').className = (payID == 'Machtiging' ? 'active' : '');
		document.getElementById('Machtiging_pay').style.display = (payID == 'Machtiging' ? 'inline' : 'none');
	}
}

function showTooltipThumb(bID, imgWidth)
{
	tooltip.show('<img src="/images/bloemen/'+bID+'_thumb.jpg" alt="" />', imgWidth+25);
}

var tooltip=function(){
 var id = 'tt';
 var top = 3;
 var left = 3;
 var maxw = 300;
 var speed = 10;
 var timer = 20;
 var endalpha = 95;
 var alpha = 0;
 var tt,t,c,b,h;
 var ie = document.all ? true : false;
 return{
  show:function(v,w,d){
   if(d == 1) { v = base64_decode(v); }
  	
   if(tt == null){
    tt = document.createElement('div');
    tt.setAttribute('id',id);
    t = document.createElement('div');
    t.setAttribute('id',id + 'top');
    c = document.createElement('div');
    c.setAttribute('id',id + 'cont');
    b = document.createElement('div');
    b.setAttribute('id',id + 'bot');
    tt.appendChild(t);
    tt.appendChild(c);
    tt.appendChild(b);
    document.body.appendChild(tt);
    tt.style.opacity = 0;
    tt.style.filter = 'alpha(opacity=0)';
    document.onmousemove = this.pos;
   }
   tt.style.display = 'block';
   c.innerHTML = v;
   tt.style.width = w ? w + 'px' : 'auto';
   if(!w && ie){
    t.style.display = 'none';
    b.style.display = 'none';
    tt.style.width = tt.offsetWidth;
    t.style.display = 'block';
    b.style.display = 'block';
   }
  if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  h = parseInt(tt.offsetHeight) + top;
  clearInterval(tt.timer);
  tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  },
  pos:function(e){
   var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
   var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
   tt.style.top = (u - h) + 'px';
   tt.style.left = (l + left) + 'px';
  },
  fade:function(d){
   var a = alpha;
   if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    var i = speed;
   if(endalpha - a < speed && d == 1){
    i = endalpha - a;
   }else if(alpha < speed && d == -1){
     i = a;
   }
   alpha = a + (i * d);
   tt.style.opacity = alpha * .01;
   tt.style.filter = 'alpha(opacity=' + alpha + ')';
  }else{
    clearInterval(tt.timer);
     if(d == -1){tt.style.display = 'none'}
  }
 },
 hide:function(){
  clearInterval(tt.timer);
   tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  }
 };
}();

function base64_decode( data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'
    
    // mozilla has this native 
    // - but breaks in 2.0.0.12!
    //if (typeof window['btoa'] == 'function') {
    //    return btoa(data);
    //}
    
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, dec = "", tmp_arr = [];
 
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
 
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
    
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
    
    return dec;
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    var tmp_arr = [], i = ac = c = c1 = c2 = 0;
 
    while ( i < str_data.length ) {
        c = str_data.charCodeAt(i);
        if (c < 128) {
            tmp_arr[ac++] = String.fromCharCode(c); 
            i++;
        } else if ((c > 191) && (c < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    
    return tmp_arr.join('');
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}