var url='http://www.in-de-wolken.nl/v2/';

var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

function objMaxHeight(obj, val, dots, frontpage) {
 var startLen = $(obj).html().length;
 var meer = '... <span class="bold wit">meer &gt;</span>';
 
 while ($(obj).height() > val) {
  $(obj).html( $(obj).html().substr(0, $(obj).html().length-5) );
 }
 
 if (frontpage) {
  $(obj).html( $(obj).html().substr(0, $(obj).html().length-2) + meer );
  while ($(obj).height() > val) {
   $(obj).html( $(obj).html().substr(0, $(obj).html().length-2-meer.length) + meer );
  }
 } else if (dots && startLen > $(obj).html().length) {
  $(obj).html( $(obj).html().substr(0, $(obj).html().length-3) + '...' );
 }
 
 $(obj).css('height', val+'px');
}


// JavaScript Document

function checkform(){
	
	var check = new Array;
	
	check[0] = "checkverplicht('verplicht')";
	check[1] = "validation(	'validate_postcode','checkpostcode',	'De postcode is niet correct (Nederland:1234 AB / Belgie: 1234)', 			'land')";
	check[2] = "validation(	'validate_email', 	'checkmail', 		'Het emailadres is niet correct')";
	check[3] = "validation(	'aantal', 			'checknum', 		'Dit is geen geldig aantal')";
	check[4] = "compare(	'password',			'U dient tweemaal hetzelfde wachtwoord op te geven.')";
	check[5] = "check_keuze( 'voorwaarden', 'voorwaarden', 'U dient akkoord te gaan met de algemene voorwaarden')";
	check[6] = "checkverplicht('verplicht_std1', 'Jouw vraag...')";
if($('#factuur').attr('checked')){
	check[7] = "checkverplicht('verplicht2')";
	check[8] = "validation(	'validate_postcode2','checkpostcode',	'De postcode is niet correct', 			'land2')";
}
	var count=0;
	while(count<check.length){
		if(eval(check[count])){
			count++;
		} else {
			return false;
		}
	}
	return true;
}


function checkmail(email){
	var regExp= new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
	if(!regExp.test(email)){
		return false;
	} else {
		return true;
	}
}

function checkpostcode(postcode, id){
	var land = $('#'+id).val();
	if(land=='BE' || land=='DU'){
		var regExp= new RegExp("^[0-9]{4}$");
	} else {
		var regExp= new RegExp("^[1-9][0-9]{3}\\s[a-zA-Z]{2}$");
	}
	if(!regExp.test(postcode)){
		return false;
	} else {
		return true;
	}
}


function check_zakelijk() {
	var check2 = true;
	$('#bedrijfsnaam').css('border-color','');
	$('#btw').css('border-color','');
	if($('#zakelijk1').is(':checked')==true) {
		if($('#bedrijfsnaam').val()=='') {
			$('#bedrijfsnaam').css('border-color','red');
			check2 = false;
		}
		
		if($('#btw').val()=='') {
			$('#btw').css('border-color','red');
			check2 = false;
		}
	}
	
	var check = checkform();
	
	if(check2==false||check==false) {
		return false;	
	}
}


function checknum(value, convert){

	if(convert==null){
		convert=true;
	}
	
	if(convert){
		value=value.replace(',', '.');
	}
	
	if(isNaN(value)){
		return false;
	} else {
		return true;
	}
}

function checkverplicht(c, stnd){

	if(stnd==null){
		stnd='';
	}
	var error = false;
	$('.'+c).each( 
		function(){
			if($(this).val()==stnd || $(this).val()==''){
				$(this).css('border-color', 'red');
				error=true;
			} else {
				$(this).css('border-color', '');
			}
		}
	);

	if(error){
		alert('Niet alle verplichte velden zijn ingevuld');
		return false;
	} else {
		return true;
	}
}


function validation(c, func, msg, extra){
	var error = false;
	if(extra){
		func+='($(this).val(),"'+extra+'")';
	} else {
		func+='($(this).val())';
	}
	$('.'+c).each( 
		function(){
			if(this.value && !eval(func)){
				$(this).css('color', 'red');
				error=true;
			} else {
				$(this).css('color', '');
			}
		}
	);

	if(error){
		alert(msg);
		return false;
	} else {
		return true;
	}
	
}

function check_keuze(naam, c, msg){
	
	var onpage = false;
	$('.'+c).each( 
		function(){
			onpage = true;
		}
	);
	if(onpage){
		if(!$("input[name='"+naam+"']:checked").val()){
			$('.'+c).each( 
				function(){
					$(this).css('color', 'red');
				}
			);
			alert(msg);
			return false;
		} else {
			$('.'+c).each( 
				function(){
					$(this).css('color', '');
				}
			);
			return true;
		};
	} else {
		return true;
	}
}

function compare(c, msg){
	var error = false;
	var values = new Array;
	$('.'+c).each( 
		function(){
			values[values.length]=$(this).val();
		}
	);

	for(var i=0;i<values.length;i++){
		for(var j=(i+1);j<values.length;j++){
			if(values[i]!=values[j]){
				error = true;
			}
		}
	}
	if(error){
		alert(msg);
		return false;
	} else {
		return true;
	}
	
}

$(document).ready(function() {

  $('.inleiding').each(function() {
   objMaxHeight($(this), 80, true, false);
  });

  $('.inleiding').css('overflow', 'hidden');

	if($(".popup")){
	  $(".popup").fancybox({
			'overlayShow':	true,
			'overlayOpacity':0.5,
			'zoomSpeedIn':	500, 
			'zoomSpeedOut':	0
	  });
	}

	$("a.switch_thumb").toggle(function(){
		$(this).addClass("swap");
		$("#products").fadeOut("fast", function() {
			$(this).fadeIn("fast").addClass("vertical");
		});
	}, function () {
		$(this).removeClass("swap");
		$("#products").fadeOut("fast", function() {
			$(this).fadeIn("fast").removeClass("vertical");
		});
	}); 

});

function switchform(id1, id2){
	$("#"+id1).toggle();
	$("#"+id2).toggle();
}

var lastid='';
function showdiv(id){
	if(lastid && lastid!=id){
		$('#'+lastid).css('backgroundImage', 'url('+url+'images/maximise.gif)');
		$('#div_'+lastid).hide("slow");
	}
	if($('#div_'+id).css('display')=='none'){
		$('#'+id).css('backgroundImage', 'url('+url+'images/minimise.gif)');
	} else {
		$('#'+id).css('backgroundImage', 'url('+url+'images/maximise.gif)');
	}
	$('#div_'+id).toggle("slow", function() {
		lastid=id;
	});
}

