function shopWarning(wat,tekst2,id){
	$('#warning').css('display','block');
	tekst		=	'';
	if(wat==1){
		tekst	=	tekst2;
		tekst	+=	'<br /><br /><a href="javascript:warningLoading();location.href=\'?act=empty\'" class="shop_submit" id="ok">OK</a> <a href="javascript:clearShopWarning();" class="shop_submit">'+taalswap('annuleren','annuler','cancel')+'</a>';
	}
	if(wat==2){
		tekst	=tekst2;
		tekst	+=	'<br /><br /><a href="javascript:warningLoading();location.href=\'?del='+id+'\'" class="shop_submit" id="ok">OK</a> <a href="javascript:clearShopWarning();" class="shop_submit">'+taalswap('annuleren','annuler','cancel')+'</a>';
	}
	if(wat==3){
		tekst	=	tekst2;
	}
	if(wat==4){
		tekst	=	tekst2;
		tekst	+=	'<br /><br /><a href="javascript:clearShopWarning();" class="shop_submit">OK</a>';
	}
	if(wat==5){
		tekst	=	'<div style="text-align:center;width:100%;"><b>'+tekst2;
		tekst	+=	'</b><img src="'+document.mainUrl+'/templates/images/loading_ring.gif" style="width:100%;;" /></div>';
	}
	if(wat==6){
		tekst	=	'<div style="text-align:center;width:100%;"><b>'+tekst2;
		tekst	+=	'</b><img src="'+document.mainUrl+'/templates/images/loading_ring.gif" style="width:100%;;" /></div>';
	}$('#Wmessage').html(tekst);
	
}


function plusNumber(field){
	$('#err').html('');
	$('#err').css('display','none');
	val=parseInt($('#'+field).val());
	if($('#'+field).val()=='')val=0;
	val=val+1;
	$('#'+field).val(val);
	if($('#maat').length){
		if(isNaN($('#maat').val()) || $('#maat').val()==''){
			
		} else {
			if($('#maatStockAantal'+$('#maat').val()).length){
				if($('#maatStockAantal'+$('#maat').val()).val()<$('#aantal').val()){
					$('#aantal').val($('#maatStockAantal'+$('#maat').val()).val());
					shopWarning(4,'maar '+$('#maatStockAantal'+$('#maat').val()).val()+' stuk(s) meer voorradig');
				}
			}
		}
	}
	bereken();
}

function minNumber(field){
	$('#err').html('');
	$('#err').css('display','none');
	val=parseInt($('#'+field).val());
	if($('#'+field).val()=='')val=0;
	if(val>1)val=val-1;
	$('#'+field).val(val);
	if($('#maat').length){
		if(isNaN($('#maat').val()) || $('#maat').val()==''){
			
		} else {
			if($('#maatStockAantal'+$('#maat').val()).length){
				if($('#maatStockAantal'+$('#maat').val()).val()<$('#aantal').val()){
					$('#aantal').val($('#maatStockAantal'+$('#maat').val()).val());
					$('#err').html('maar '+$('#maatStockAantal'+$('#maat').val()).val()+' stuk(s) meer voorradig');
					$('#err').css('display','block');
					var t=setTimeout('clearDiv("err")',3500);
				}
			}
		}
	}
	bereken();
}

function herbestelpro(id,error){
	if(realNumber($('#proAantal'+id).val())==false){
		$('#proAantal'+id).css('border','solid 2px #c00');
		$('#proAantal'+id).val('');
		$('#proErr'+id).html(error);
		var t=setTimeout('clearDiv("err")',3500);
	} else {
		$('#proErr'+id).html('');
		$('#proAantal'+id).css('border','solid 1px #ccc');
		prod=id;
		aantal=	$('#proAantal'+id).val();
		$('#addpro'+id).html('<img style="width:200px;" src="'+document.mainUrl+'/templates/images/Loading_icon.gif" />');
		url=''+document.mainUrl+'/ajax.php?prod='+prod+'&aantal='+aantal;
		$.ajax({
		  url: url
		}).done(function(response) {
			window.document.location.href=$('#actualLink').val()+'&wat=pro&reconstruct='+id;
		});
	}
}
function showAllBest(){
	$('#allBest').slideToggle();
}

function showLogin(){
	$('.loginBox').slideDown('slow');
}

function checkAlgVwdn(){
	if($('#alg').prop('checked')==false){
		$('#algmv').css('border','solid 3px #c00');
		$('#algmv').css('padding','3px');
		$('#algmv').css('color','#c00');
		$('#algmv div').html('gelieve akkoord te gaan met de alg. vwdn');
		$('#algmv div').css('background-color','#c00');
		$('#algmv div').css('color','#fff');
		$('#algmv div').css('padding','3px');
		var returnVal=false;
	} else {
		var returnVal=true;
	}
	return returnVal;
}

function showSearch(){
	$('#mobSearch').toggle();
}

function showAccount(){
	$('#loginLnks').toggle();
}

function postforwardShopMaten(txt,txt2){
	$('#aantal').removeClass('inpErr');
	$('#matenSel').removeClass('inpErr');
	posten=1;
	if(realNumber($('#aantal').val())==false){
		posten=0;
		$('#aantal').val('');
		$('#aantal').addClass('inpErr');
		txt=txt2;
	}
	if(realNumber($('#maat').val())==false){
		if($('#maat').val()!="0"){
			$('#matenSel').addClass('inpErr');
			posten=0;
		}
	}
	if(posten==0){
		$('#err').html(txt);
		$('#err').css('display','block');
		var t=setTimeout('clearDiv("err")',3500);
	} else {
		document.forms.shop.submit();
	}
}
function clearMsg(){
	var t=setTimeout("clearDiv('msg')",3500);
}
function postforwardShop(error){
	if(realNumber($('#aantal').val())==false){
		$('#aantal').css('border','solid 2px #c00');
		$('#aantal').val('');
		$('#err').html(error);
		var t=setTimeout('clearDiv("err")',3500);
	} else {
		shopWarning(5,'');
		document.forms.shop.submit();
	}
	
}
function clearDiv(elem){
	$('#'+elem).slideUp();
}
function realNumber(nr){
	ret=true;
	if(nr == "")ret=false;
	if(nr < 1)ret=false;
	if(isNaN(nr))ret=false;
	if(nr.indexOf(".")>0)ret=false;
	if(nr.indexOf(",")>0)ret=false;

	return ret;
}
function setMaat(pos,id,aantal){
	for(a=0;a<aantal;a++){
		$('#maat'+a).removeClass('selected').addClass( "" );
	}
	$('#maat'+pos).addClass('selected');
	$('#maat').val(id);
}
function setMaatSel(){
	$('#maat').val($('#matenSel').val());
}
function checkMaat(tot){
	gevonden=0;
	tmp="";
	for(a=0;a<tot;a++){
		//alert($('#maat'+a).css('background-color'));
		tmp+=$('#maat'+a).css('background-color')+'<br />';
		if($('#maat'+a).css('background-color')=='rgb(245, 183, 121)'){
			gevonden=1;
		} else {//alert ("wit");
		}
	}
	if(gevonden==0){
		document.getElementById('errMaat').innerHTML='gelieve een maat te kiezen';
		return false;
	} else {
		return true;
	}
}


function prdn2(){
	if(document.getElementById("ik").value=="2"){
		if(document.getElementById("deel"))document.getElementById("deel").innerHTML="delen";
		if(document.getElementById("deel2"))document.getElementById("deel2").innerHTML="wij";
		if(document.getElementById("herroep"))document.getElementById("herroep").innerHTML="herroepen";
		if(document.getElementById("part"))document.getElementById("part").innerHTML="soussign&eacute;s notifions";
		if(document.getElementById("part2"))document.getElementById("part2").innerHTML="notre";
		if(document.getElementById("teil"))document.getElementById("teil").innerHTML="widerrufen";
		if(document.getElementById("teil2"))document.getElementById("teil2").innerHTML="uns";
	}
	if(document.getElementById("ik").value=="1"){
		if(document.getElementById("deel"))document.getElementById("deel").innerHTML="deel";
		if(document.getElementById("deel2"))document.getElementById("deel2").innerHTML="ik";
		if(document.getElementById("herroep"))document.getElementById("herroep").innerHTML="herroep";
		if(document.getElementById("part"))document.getElementById("part").innerHTML="soussign&eacute; notifie";
		if(document.getElementById("part2"))document.getElementById("part2").innerHTML="ma";
		if(document.getElementById("teil"))document.getElementById("teil").innerHTML="widerrufe";
		if(document.getElementById("teil2"))document.getElementById("teil2").innerHTML="mir";
	}
}

function prdn(){
	if(document.getElementById("prod").value=="1"){
		if(document.getElementById("het"))document.getElementById("het").innerHTML="het";
	}
	if(document.getElementById("prod").value=="2"){
		if(document.getElementById("het"))document.getElementById("het").innerHTML="de";
	}
}

function postforwardShop2(id){
	if(realNumber2(document.getElementById("aantal"+id).value)==false){
		document.getElementById("aantal"+id).style.border="solid 2px #c00";
		document.getElementById("aantal"+id).value="";
		document.getElementById("err"+id).innerHTML="'.$TXTCAT['ERRORTXT2'].'";
		var t=setTimeout("clearErr2("+id+")",3500);
	} else {
		document.getElementById("err"+id).innerHTML="";
		document.getElementById("form"+id).submit();
		document.getElementById("prodDiv"+id).innerHTML="";
	}
	
}
function clearErr2(id){
	alert(id);document.getElementById("err"+id).innerHTML="";
}
function realNumber2(nr){
	ret=true;
	if(nr == "")ret=false;
	if(nr < 1)ret=false;
	if(isNaN(nr))ret=false;
	
	if(nr.indexOf(".")>0)ret=false;
	if(nr.indexOf(",")>0)ret=false;
	return ret;
}

function emptyFields(chk){
	if(document.getElementById("shipping_voornaam"))document.getElementById("shipping_voornaam").value="";
	if(document.getElementById("shipping_name"))document.getElementById("shipping_name").value="";
	if(document.getElementById("shipping_adres"))document.getElementById("shipping_adres").value="";
	if(document.getElementById("shipping_postcode"))document.getElementById("shipping_postcode").value="";
	if(document.getElementById("shipping_gemeente"))document.getElementById("shipping_gemeente").value="";
	if(document.getElementById("shipping_telefoon"))document.getElementById("shipping_telefoon").value="";
	if(document.getElementById("shipping_land"))document.getElementById("shipping_land").value=0;
	if(document.getElementById("shipping_bedrijf"))document.getElementById("shipping_bedrijf").value="";
	if(document.getElementById("shipping_telefoon"))document.getElementById("shipping_telefoon").value="";
	if(document.getElementById("shipping_adres_2"))document.getElementById("shipping_adres_2").value="";
	
}

function metPasw(){
	$('#showForm').slideDown('slow');
	$('#sChoice').slideUp('slow');
	$('#pswMeld').css("display","block");
	$('.pwd').css("display","block");
	$('.jouwK2').slideDown('slow');
	$('.jouwK1').slideUp('slow');
	$('#make_account').prop('checked', true);
}

function showChoice(){
	$('#showForm').slideUp('slow');
	$('#sChoice').slideDown('slow');
	$('.jouwK2').slideUp('slow');
	$('.jouwK1').slideUp('slow');
	
}

function zonderPasw(){
	$('#showForm').slideDown('slow');
	$('#sChoice').slideUp('slow');
	$('#pswMeld').css("display","none");
	$('.pwd').css("display","none");
	$('.jouwK1').slideDown('slow');
	$('.jouwK2').slideUp('slow');
	$('#make_account').prop('checked', false);
}
function showPwd(chk){
	if(chk){
		if(chk.checked==true){
			$(".pwd").slideDown('slow');
		} else {
			$(".pwd").slideUp('slow');
			$("#paswoord").val('');
			$("#paswoord_2").val('');
			$("#result").html('');
		}
	}
}


function otherDelivery(chk){
	if(chk){
		if(chk.checked==true){
			if($("#div_ship_adres"))$("#div_ship_adres").slideDown('slow');
			if($('#get_inStore'))document.getElementById("get_inStore").checked=false;
			clearStores();
		} else {
			if($("#div_ship_adres"))$("#div_ship_adres").slideUp('slow');
		}
		emptyFields(chk);
	}
	if(document.getElementById('get_inStore').checked==true){
		if($("#div_ship_adres"))$("#div_ship_adres").slideUp('slow');
		if($("#other_delivery_adress"))document.getElementById("other_delivery_adress").checked=true;
		if($("#stores"))$("#stores").css('display','block');
	}
}

function getInStore(chk){
	if(chk){
		if(chk.checked==true){
			if($("#div_ship_adres"))$("#div_ship_adres").slideUp('slow');
			if($("#other_delivery_adress"))document.getElementById("other_delivery_adress").checked=false;
			if($("#stores"))$("#stores").css('display','block');
		} else {
			clearStores();
		}
		emptyFields(chk);
	}
}
function working(){
	if($("#shop_view"))$("#shop_view").css('display',"none");
	if($("#formWrap"))$("#formWrap").css('display',"none");
	if($("#working"))$("#working").css('display',"block");
}


function showSelect(id)
{
    //alert(document.getElementById(id));
	document.getElementById('searchField').focus();
    document.getElementById('searchField').select();
}
function searchFor(url){
	document.location.href=url+"?search="+document.getElementById('searchField').value;
}
function searchFor2(url){
	document.location.href=url+"?search="+document.getElementById('searchField2').value;
}

function showCart(url,div){
	document.getElementById(div).style.display='block';
	xmlhttpPost(url,div);
}
function hideCart(div){
	document.getElementById(div).style.display='none';
}
function xmlhttpPost(strURL,div) {
	
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            //alert('found')
            updatepage(self.xmlHttpReq.responseText,div);
        }
        //else{alert('not found')}
    }
    
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    qstr = 'w='
    return qstr;
   
}

function updatepage(str,div){
    document.getElementById(div).innerHTML = str;
}


$(document).ready(function() {

	$('#paswoord').keyup(function(){
		$('#result').html(checkStrength($('#paswoord').val()))
	})	
	
	function checkStrength(password){
    
	//initial strength
    var strength = 0
	
    //if the password length is less than 6, return message.
    if (password.length < 6) { 
		$('#result').removeClass()
		$('#result').addClass('short')
		return 'Too short' 
	}
    
    //length is ok, lets continue.
	
	//if length is 8 characters or more, increase strength value
	if (password.length > 7) strength += 1
	
	//if password contains both lower and uppercase characters, increase strength value
	if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  strength += 1
	
	//if it has numbers and characters, increase strength value
	if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  strength += 1 
	
	//if it has one special character, increase strength value
    if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))  strength += 1
	
	//if it has two special characters, increase strength value
    if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
	
	//now we have calculated strength value, we can return messages
	
	//if value is less than 2
	if (strength < 2 ) {
		$('#result').removeClass()
		$('#result').addClass('weak')
		return 'Weak'			
	} else if (strength == 2 ) {
		$('#result').removeClass()
		$('#result').addClass('good')
		return 'Good'		
	} else {
		$('#result').removeClass()
		$('#result').addClass('strong')
		return 'Strong'
	}
}
});