// JavaScript Document

$(document).ready(function(){

	$('a[rel=external]').attr('target','_blank');

	$('#small tr .bedrag').keyup(function(event){
		var bedrag = $(this).val();
		bedrag = bedrag.replace(',', '.');
		var intrest = $(this).parent('td').parent('tr').find('.intrest').val();
		intrest = intrest.replace(',', '.').replace('%', '');
		var bruto = (bedrag/100)*intrest;
		var rv = (bruto/100)*15;
		var netto = bruto-rv;
		$(this).parent('td').parent('tr').find('.bruto')[0].innerHTML = '&euro;'+bruto.toFixed(2).replace('.', ',');
		$(this).parent('td').parent('tr').find('.rv')[0].innerHTML = '&euro;'+rv.toFixed(2).replace('.', ',');
		$(this).parent('td').parent('tr').find('.netto')[0].innerHTML = '&euro;'+netto.toFixed(2).replace('.', ',');
		

		var totaal = 0;
		var totaalbedrag = 0;
		$('#small .jaar').each(function(){
			var con1 = $(this).find('.netto')[0].innerHTML;
			convert1 = con1.replace(',','.').replace('€', '').replace('&euro;','').replace('&#8364;','').replace('\u20ac', '');
			convert1 = parseFloat(convert1);
			if(!isNaN(convert1)){
				totaal = totaal+convert1;
			}
			
			var con2 = $(this).find('.bedrag').val();
			convert2 = parseFloat(con2);
			if(!isNaN(convert2)){
				totaalbedrag = totaalbedrag+convert2;
			}
		})
		$('#small #totaalbedrag')[0].innerHTML = '&euro;'+totaalbedrag.toFixed(2).replace('.', ',');
		
		$('#small #totaal')[0].innerHTML = '&euro;'+totaal.toFixed(2).replace('.', ',');
		
	});
	
	$('#big tr .bedrag').keyup(function(event){
		var bedrag = $(this).val();
		bedrag = bedrag.replace(',', '.');
		var intrest = $(this).parent('td').parent('tr').find('.intrest').val();
		intrest = intrest.replace(',', '.').replace('%', '');
		var bruto = (bedrag/100)*intrest;
		var rv = (bruto/100)*15;
		var netto = bruto-rv;
		$(this).parent('td').parent('tr').find('.bruto')[0].innerHTML = '&euro;'+bruto.toFixed(2).replace('.', ',');
		$(this).parent('td').parent('tr').find('.rv')[0].innerHTML = '&euro;'+rv.toFixed(2).replace('.', ',');
		$(this).parent('td').parent('tr').find('.netto')[0].innerHTML = '&euro;'+netto.toFixed(2).replace('.', ',');
		
		var totaal = 0;
		var totaalbedrag = 0;
		$('#big .jaar').each(function(){
			var con1 = $(this).find('.netto')[0].innerHTML;
			convert1 = con1.replace(',','.').replace('€', '').replace('&euro;','').replace('&#8364;','').replace('\u20ac', '');
			convert1 = parseFloat(convert1);
			if(!isNaN(convert1)){
				totaal = totaal+convert1;
			}
			
			var con2 = $(this).find('.bedrag').val();
			convert2 = parseFloat(con2);
			if(!isNaN(convert2)){
				totaalbedrag = totaalbedrag+convert2;
			}
		})
		$('#big #totaalbedrag')[0].innerHTML = '&euro;'+totaalbedrag.toFixed(2).replace('.', ',');
		
		$('#big #totaal')[0].innerHTML = '&euro;'+totaal.toFixed(2).replace('.', ',');
		
		
	});
	
	//buttons in footer
	$('#footer .left a').hover(function(){$(this).find('img').attr('src',$(this).find('img').attr('src').replace('.gif','_over.gif'));},function(){$(this).find('img').attr('src',$(this).find('img').attr('src').replace('_over',''));});
	
})

function checkContactValues(){
	
	var naam = document.getElementById('naam');
	var voornaam = document.getElementById('voornaam');
	var tel = document.getElementById('tel');
	var email = document.getElementById('email');
	var opmerkingen = document.getElementById('opmerkingen');
	
	if(voornaam.value.length==0){window.alert("Vul uw voornaam in aub.");return false;}
	if(naam.value.length==0){window.alert("Vul uw naam in aub.");return false;}
	if(tel.value.length==0){window.alert("Vul uw telefoon nummer in aub.");return false;}
	if(!validMail(email.value)){window.alert("Vul een correct e-mailadres in aub");return false;}
	if(opmerkingen.value.length==0){window.alert("Vul uw opmerkingen in aub.");return false;}

	return true;
}
//contact mail validate
function validMail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){return false;}
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if(str.indexOf(at,(lat+1))!=-1){return false;}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if(str.indexOf(dot,(lat+2))==-1){return false;}	
	if(str.indexOf(" ")!=-1){return false;}
	return true;		
}

function loadVideo(id, flv){
		
	var params = {wmode: "transparent"};
	var flashvars = {flvurl: flv, skinurl: "/media/swf/ClearOverPlaySeekMute.swf"};
	swfobject.embedSWF("/media/swf/video.swf", id, "100%", "100%", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params);
}