function inloggen(){
	//shopWarning(1);
	$('#loginFast').css('display','block');
	$('#loginFast').css('z-index','20000');
	$('#Wmessage').css('display','none');
}
function loginlinks(){
	//shopWarning(1);
	$('#loginLinkers').css('display','block');
	$('#loginLinkers').css('z-index','20000');
	$('#Wmessage').css('display','none');
}

function closeloginLinkers(){
	$('#loginLinkers').css('display','none');
	$('#Wmessage').css('display','none');
}

function annuleerInlog(){
	$('#loginFast').css('display','none');
	$('#Wmessage').html('');
	$('#Wmessage').css('display','block');
	$('#warning').css('display','none');
}

$(document).ready(function() {	
	setLoginForm();
});



function setLoginForm(){
	
	$("#myLoginForm").submit(function(event){
		event.preventDefault(); //prevent default action 
		var post_url = document.mainUrl+'/ajax.php'; //get form action url
		var request_method = $(this).attr("method"); //get form GET/POST method
		var form_data = $(this).serialize(); //Encode form elements for submission
		$('#loginFormHolder').css('display','none');
		$('#loginLoading').html('<div style="text-align:center;"><img style="width:200px;" src="'+document.mainUrl+'/templates/images/spinner.gif" /></div>');
		$.ajax({
			url : post_url,
			type: request_method,
			data : form_data
		}).done(function(response){
			if(response==1){
				$('#loginLoading').html('');
				$('#loginFormHolder').html('<img style="width:200px;" src="'+document.mainUrl+'/templates/images/spinner.gif" /><br /><br />'+taalswap('EVEN GEDULD<br />U WORDT AANGEMELD','',''));
				$('#loginFormHolder').css('display','block');
				document.location.href='https://www.vds-groothandel.be/groothandel/winkelmandje?act=ingelogd&pwd=0';
			} else {
				$('#loginLoading').html('<div style="padding:10px 15px;background-color:#000;color:#fff;text-align:left;margin-bottom:5px;text-transform:uppercase;">'+response+taalswap('Verkeerde inlogpoging','mauvaise tentative de connexion','')+'</div>');
				$('#loginFormHolder').css('display','block');
			}
		});
	});

}

function annPop(){
	
	$('#addOver'+document.opener).slideUp("",function(){
		$("#addOver"+document.opener).html('');
	});
}

function searchList(val){
	$('.addRow').each(function() {
		if($(this).attr('id')==val){
			alert('ok');
		}
	});
}

function showAllBest(){
	$('#allBest').slideToggle();
}
function clearWarning(){
	$(".Wmessage2").html('');
	$(".Wmessage2").css('display','none');
}

//OPENT DE HERBESTEL POPUP
/////////////////////////////

function herbestel(id,date,nr,order,searchs,del){
	
	warning('','<span style="font-size:25px;">LOADING</span><br /><img src="https://www.vds-groothandel.be/templates/catimg/ajax-loader.gif" />');
	if(document.opener)$('#addOver'+document.opener).css('display','none');
	$('#addOver'+document.opener).html();
	document.opener=nr;
	$.ajax({url: 'https://www.vds-groothandel.be/addShop2.php?key='+id+'&date='+date+'&nr='+nr+'&order='+order+'&search='+searchs+'&search='+searchs, success: function(result){
		clearWarning();
		$("#addOver"+nr).html(result);
		$('#addOver'+nr).slideDown();
		$('html, body').animate({
			scrollTop:$('#addOver'+document.opener).offset().top-100
		});
	}});
	
}
function showHistDet(nr){
	$(".detail" ).each(function() {
		if($(this).attr('id')=='detail'+nr){
			if($(this).css('display')=='block'){
				$('#detail'+nr).slideUp();
			} else {
				$('#detail'+nr).slideDown();
			}
		} else {
			$(this).slideUp();
		}
	});
	
}

function warning(wat,txt){
	$("#warning").css( "display","block" );
	$('.Wmessage').html('<img src="https://www.vds-groothandel.be/templates/images/ajax-loader.gif" width="100%;" /><br /><br />'+txt);
}

function clearWarning(){
	$("#warning").css( "display","none" );
	$('.Wmessage').html('');
}
function clearZWarning(){
	$('#Zwarning').css( 'display','none' );
	$('#zkNewSpinner').css( 'display','none' );
	$('#zkNewForm').css('display','block');
	$('#zknew').val('');
}
function shopWarning(nr,txt){
	$('#warning').css( 'display','block' );
	switch (nr){
		case 1:
			txt='U BENT NU INGELOGD<br /><a href="http://www.vds-groothandel.be" class="shop_submit">OK</a>';
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			break;
	
	}
	$('.Wmessage').html(txt);
}
function zoekWarning(){
	$('#zkNewSpinner').css( 'display','none' );
	$("#Zwarning").css( "display","block" );
	$('#zknew').focus();
	
}
function zknew(){
	$('#zkNewSpinner').css('display','block');
	$('#zkNewForm').css('display','none');
	document.location.href=document.mainUrl+taalswap('/stock-artikelen-groothandel','/articles-stock-vente-en-gros','')+'?search='+$('#zknew').val();

}

function colorRow(teller){
	
	if($('#del'+teller).is(':checked')==true) {
		$('#shopRow'+teller).css('background','#ffc9cc');
	} else {
		$('#shopRow'+teller).css('background','none');
	}
	
}

function gotoDelStr(stap){
	if(stap!='')stap='stap='+stap+'&';
	window.location.href='?'+stap+'delStr='+$("#delstr").val();
}

function verwijderUitBasket(eenItem,titel,stap,taal){
	
	str='';
	ids='';
	wat=1;
	if(eenItem==0){
		$( ".delCheck" ).each(function() {
			if($(this).is(':checked')==true){
				ids+=$(this).attr("proid")+';';
				str+='<i class="fa fa-circle" aria-hidden="true"></i> '+$(this).attr("name")+'<br />';
			}
		});
	} else {
		ids+=eenItem+';';
		str+='<i class="fa fa-circle" aria-hidden="true"></i> '+titel+'<br />';
	}
	
	if(str==''){
		if(taal==''){
			str='geen items geselecteerd om te verwijderen';
		} else {
			str='aucun &eacute;l&eacute;ment s&eacute;lectionn&eacute; pour supprimer';
		}
		str+='<br /><a href="javascript:clearWarning();" class="shop_submit">OK</a>';
		warning(wat,str);
	} else {
		//alert(stap);
		//gotoDelStr(stap);
		if(taal==''){
			str='Bent u zeker dat u deze items wil verwijderen uit uw winkelmandje?<br /><br />'+str;
			ja='ja';
			nee='nee';
		} else {
			str='Voulez-vous vraiment supprimer ces &eacute;l&eacute;ments de votre panier??<br /><br />'+str;
			ja='oui';
			nee='non';
		}
		str+='<input type="hidden" value="'+ids+'" id="delstr"><br />';
		str+='<a href="javascript:gotoDelStr('+stap+');" class="shop_submit">'+ja+'</a> <a href="javascript:clearWarning();" class="shop_submit" >'+nee+'</a>';
		warning(wat,str);
	}
	
}



function setEmail(){
	$('#addEmail').slideToggle("fast", function() {});
	$('#emailTitel').slideToggle("fast", function() {});
	$('#postFields').slideToggle("fast", function() {});
}

function setAantalNu(taal){
	var tot=0;
	if($('#dropaantal1').css('width'))tot+=parseInt($('#dropaantal1').val());
	if($('#dropaantal2').css('width'))tot+=parseInt($('#dropaantal2').val());
	if($('#dropaantal3').css('width'))tot+=parseInt($('#dropaantal3').val());
	if($('#dropaantal4').css('width'))tot+=parseInt($('#dropaantal4').val());
	aantalGratisTxt='';
	if($("#grGrat").val()){
		//alert($("#grGrat").val()+' '+$("#grTot").val());
		GratisTmp=Math.floor(tot/$("#grTot").val());
		aantalGratis=GratisTmp*$("#grGrat").val();
		
		if(aantalGratis>0){
			if(taal==''){
				aantalGratisTxt='<br /><span id="plusGr">+ '+(GratisTmp*$("#grGrat").val())+' gratis = <b>'+((GratisTmp*$("#grGrat").val())+tot)+' stuks</b></span>';
			} else {
				aantalGratisTxt='<br /><span id="plusGr">+ '+(GratisTmp*$("#grGrat").val())+' gratuits = <b>'+((GratisTmp*$("#grGrat").val())+tot)+' pieces</b></span>';
			}
			if(taal==''){
				$('#totAant').html('Aantal');
			} else {
				$('#totAant').html('Quantit&eacute;');
			}
			$('#aantal').css('font-size','20px');
			//$('#aantal
		} else {
			if(taal==''){
				$('#totAant').html('Totaal aantal');
			} else {
				$('#totAant').html('Quantit&eacute; totale');
			}
			$('#aantal').css('font-size','30px');
		}
	} else {
		$('#aantal').css('font-size','30px');
	}
	num=(tot*$('#prBereken').val());
	$('#aantal').val(tot);
	$('#price2').html('<span style="font-size:30px;">= &euro; '+num.toFixed(2)+'</span>'+aantalGratisTxt);
}
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').val('');
		$('#err').html(error);
		var t=setTimeout('clearDiv("err")',3500);
	} else {
		warning('','<span style="font-size:25px;">LOADING</span><br /><img src="https://www.vds-groothandel.be/templates/catimg/ajax-loader.gif" />');
		document.forms.shop.submit();
	}
	
}
function delWarning(){
	warning('','<span style="font-size:25px;">LOADING</span><br /><img src=https://www.vds-groothandel.be/templates/catimg/ajax-loader.gif />');
}

function postforwardShopNew(error){
	
	if(realNumber($('#aantal').val())==false){
		$('#aantal').css('border','solid 2px #c00');
		$('#aantal').val('');
		$('#err').html(error);
		var t=setTimeout('clearDiv("err")',3500);
	} else {
		$('#choiceOverlay').fadeIn( "slow", function() {});
		$('#choiceOverlay2').fadeIn( "slow", function() {});
		$.ajax({url: 'http://www.vds-groothandel.be/addShop.php', success: function(result){
			//$("#shopSubmit").html(result);
		}});
	}
	
}
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 showPwd(){
	
	if($('#make_account').attr('checked')=="checked" || 1==1){
		$('#pswMeld').css("display","block");
		$(".pwd").css("display","table-row");
	} else {
		$('#pswMeld').css("display","none");
		$(".pwd").css("display","none");
	}
}
function sameAsShipping(chk){
	if(chk){
		//if(get_inStore){
		//same_as_shipping
		if(chk.checked==true){
			document.getElementById("div_ship_adres").style.display="none";
			document.getElementById("get_inStore").checked=false;
			document.getElementById("stores").style.display="none";
		} else {
			document.getElementById("div_ship_adres").style.display="block";
		}
		emptyFields(chk);
	}
	if(document.getElementById('get_inStore').checked==true){
		document.getElementById("div_ship_adres").style.display="none";
		document.getElementById("same_as_shipping").checked=false;
		document.getElementById("stores").style.display="block";
	}
}
function sameAsShipping2(chk){
	if(chk){
		if(chk.checked==true){
			document.getElementById("div_ship_adres").style.display="none";
			document.getElementById("stores").style.display="block";
			document.getElementById("same_as_shipping").checked=false;
		} else {
			document.getElementById("div_ship_adres").style.display="block";
			document.getElementById("stores").style.display="none";
			document.getElementById("storeSelect").value=0;
		}
		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){
	alert(document.getElementById('searchField').value);
	document.location.href=url+"?search="+document.getElementById('searchField').value;
}
function searchFor2(url){
	alert('2'+document.getElementById('searchField').value);
	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'
	}
}
});