var BezigMetLaden = 2;
var MeerItemsAanwezig = 1;
var TaalEmail = '';
var TaalWachtwoord = '';
var TaalZoeken = '';

$(document).ready(function () {
	if(document.getElementById('PID').value == 1){
		$('#MainBannerContainer').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 4000,
			cleartype:  1,
			pager:  '#BannerNav'
		});
		var Breedte = $('#BannerNav').width();
		var Waarde = (600 - Breedte);
		$('#BannerNav').css({ 'margin-left' : Waarde });
	}
/*	$('a').click(function(){
		ToonLaadScherm();
	});*/
	/// ALLEEN NOG DOEN ALS DIT MOET!!!!
	if((document.getElementById('PID').value == '10' && document.getElementById('SubGroepID').value != '' && document.getElementById('ProductID').value == '') || document.getElementById('Aanbieding').value == 1 || document.getElementById('Nieuw').value == 1){
		/*ScrollStarten();*/
	} else if(document.getElementById('PID').value == 18){
		/*ScrollStarten();*/
	}
	
	if(document.getElementById('ProductID').value > 0){	
		/*$("#ScrollContainer").scrollable();*/
	}
	
	TaalEmail = document.getElementById('loginEmail').value;
	TaalWachtwoord = document.getElementById('loginWachtwoord').value;
	TaalZoeken = document.getElementById('Zoekwoorden').value;
	
	$('#loginEmail').focus(function(){
		if(this.value == TaalEmail){ this.value = ''; }
	}).blur(function(){
		if(this.value == ''){ this.value = TaalEmail; }
	});
	$('#loginWachtwoord').focus(function(){
		if(this.value == TaalWachtwoord){ this.value = ''; }
	}).blur(function(){
		if(this.value == ''){ this.value = TaalWachtwoord; }
	});
	$('#Zoekwoorden').focus(function(){
		if(this.value == TaalZoeken){ this.value = ''; }
	}).blur(function(){
		if(this.value == ''){ this.value = TaalZoeken; }
	});
	$('#Navbar').css({ 'padding-left' : ((980 - $('#Navbar').width()) / 2) });
});

function ToonLaadScherm(){
	ToonRefreshMessage = '1';
	document.getElementById('DivAlertBoxContent').innerHTML = '<center><img src="images/loading.gif" /></center>';
	$('#DivAlertBoxAchtergrond').css({ height : $(document).height(), width : $(document).width() });
	$('#DivAlertBoxAchtergrond').css({'display':'block'});
}

function ScrollStarten(){
	$(window).scroll(function(){
		var Top = (($(document).height() - $(window).height()) - 272);
		if  ($(window).scrollTop() >= Top){
		   lastPostFunc();
		}
	});	
}

/*function AfbeeldingenCentreren(){
	$('.ItmImg').each(function(){
		$(this).css({ 'margin-top': ((195 - $(this).height()) / 2) });
	});
}*/

function AfbeeldingenCentrerenPS(This, Hoogte){
	$(This).css({ 'margin-top': ((Hoogte - $(This).height()) / 2) });	
}

function lastPostFunc(){ 
	if(BezigMetLaden == 2 && MeerItemsAanwezig == 1 && (document.getElementById('SubGroepID').value != '' || document.getElementById('Aanbieding').value != '2' || document.getElementById('Nieuw').value != '2' || document.getElementById('PID').value == '18' )){
		BezigMetLaden = 1;
		$('div#lastPostsLoader').fadeIn(10);
		$.post("productoverzicht.php?SubGroepID="+document.getElementById('SubGroepID').value+"&Aanbieding="+document.getElementById('Aanbieding').value+"&Nieuw="+document.getElementById('Nieuw').value+"&Nav="+$(".ProductOverzichtRij:last").attr("id"), function(data){
			if (data != "") {
				$(".ProductOverzichtRij:last").after(data);
			} else {
				MeerItemsAanwezig = 2;
			}
			$('div#lastPostsLoader').fadeOut(10);
			BezigMetLaden = 2;
		});
	} 
}; 
function ToonMelding(Pagina){
	$('#DivAlertBoxAchtergrond').css({ height : $(document).height(), width : $(document).width() });
	$('#DivAlertBoxAchtergrond').fadeIn(200);
	
	var NieuweBreedteDiv = 600;
	var NieuweHoogteDiv = 200;
	
	var TopPos = ($(window).scrollTop() + 60);
	
	TopPositie = TopPos+'px';
	document.getElementById('DivAlertBoxContent').style.top = TopPositie;
	
	var LinkerPositie = (($(document).width() - NieuweBreedteDiv)/2);
	LinkerPositie = LinkerPositie+'px';
	document.getElementById('DivAlertBoxContent').style.left = LinkerPositie;
	
	LaadMeldingInDiv(Pagina, 'DivAlertBoxContent');
}

function LaadMeldingInDiv(option) {
	var urls = option;
	$.get(option, function(data){
		document.getElementById('DivAlertBoxContent').innerHTML = data;
		$('#DivAlertBoxAchtergrond').css({ backgroundColor: '#000', opacity: '0.7' }).fadeIn(200);
		$('#DivAlertBoxContent').fadeIn(300,function(){

		});	
	});
}

function MeldingSluiten(Pagina){
	$('#DivAlertBoxContent').fadeOut(200);
	$('#DivAlertBoxAchtergrond').fadeOut(200);
}

function AanmeldenNieuwsbrief(){
	if(document.getElementById('EmailAdresNieuwsbrief').value == ''){
		document.getElementById('EmailAdresNieuwsbrief').style.backgroundColor = '#cc0000';
	} else {
		if(document.getElementById('NieuwsbriefAanmelden').checked == true){
			var AanAfmelden = '1';
		} else {
			var AanAfmelden = '2';
		}
		$.post('nieuwsbrief.php', { 'Email': document.getElementById('EmailAdresNieuwsbrief').value, 'GroepID' : document.getElementById('NieuwsbriefGebruikersGroepID').value, 'AanAfmelden' : AanAfmelden }, function(data){
			document.getElementById('DivNieuwsbrief').innerHTML = data;
		});
	}
}

function Toevoegen(){
	if(document.getElementById('ProductAantal').value == ''){
		document.getElementById('ProductAantal').value = '1';
	}
	document.getElementById('formToevoegen').submit();	
}

function ToevoegenBon(){
	if(document.getElementById('ProductAantal').value == ''){
		document.getElementById('ProductAantal').value = '1';
	}
	if(document.getElementById('PrintOfMailMailB').checked == true){
		if(document.getElementById('NaamOntvanger').value == '' || validateEmail(document.getElementById('EmailOntvanger').value) == false){
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
	//
}

function validateEmail(elementValue){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
   return emailPattern.test(elementValue);  
 }

function WWWijzigAantal(Verder){
	document.getElementById('Verder').value = Verder;
	document.getElementById('formWinkelwagen').submit();
}
function WachtwoordOpvragen(){
	$.post('execute/wachtwoord_opvragen.exe.php', { 'Email': document.getElementById('WachtwoordVergetenEmail').value }, function(data){
		eval(data);
	});
}
function WWInloggen(){
	document.getElementById('formWWLogin').submit();
}
function Inloggen(){
	document.getElementById('formLogin').submit();
}

function Zoeken(){
	document.getElementById('formZoeken').submit();
}

function JeGegevens(){
	$.post('execute/controleer_gegevens.php', { 'Aanhef': document.getElementById('Aanhef').value,
	'Voornaam': document.getElementById('Voornaam').value,
	'Bedrijfsnaam': document.getElementById('Bedrijfsnaam').value,
	'Tussenvoegsel': document.getElementById('Tussenvoegsel').value,
	'Achternaam': document.getElementById('Achternaam').value,
	'Adres': document.getElementById('Adres').value,
	'Huisnummer': document.getElementById('Huisnummer').value,
	'Postcode': document.getElementById('Postcode').value,
	'Plaats': document.getElementById('Plaats').value,
	'Land': document.getElementById('Land').value,
	'Telefoon': document.getElementById('Telefoon').value,
	'Email': document.getElementById('Email').value,
	'Wachtwoord': document.getElementById('Wachtwoord').value,
	'WachtwoordNogmaals': document.getElementById('WachtwoordNogmaals').value }, function(data){
		eval(data);
	});
}

function WijzigJeGegevens(){
	$.post('execute/gegevens_wijzigen.php', { 'Aanhef': document.getElementById('Aanhef').value,
	'Voornaam': document.getElementById('Voornaam').value,
	'Bedrijfsnaam': document.getElementById('Bedrijfsnaam').value,
	'Tussenvoegsel': document.getElementById('Tussenvoegsel').value,
	'Achternaam': document.getElementById('Achternaam').value,
	'Adres': document.getElementById('Adres').value,
	'Huisnummer': document.getElementById('Huisnummer').value,
	'Postcode': document.getElementById('Postcode').value,
	'Plaats': document.getElementById('Plaats').value,
	'Land': document.getElementById('Land').value,
	'Telefoon': document.getElementById('Telefoon').value,
	'Wachtwoord': document.getElementById('Wachtwoord').value,
	'WachtwoordNogmaals': document.getElementById('WachtwoordNogmaals').value,
	'Email': document.getElementById('Email').value }, function(data){
		eval(data);
	});
}

function ClickAfleverVeld(){
	document.getElementById('AfleveringAnders').checked = true;
	AfleveringClick();
}

function AfleveringClick(){
	if(document.getElementById('AfleveringAnders').checked == true){
		$('.AfleverAdresAnders').fadeTo(100, 1);
		$('.AfleverAdresThuis').fadeTo(100, 0.1);
	} else {
		$('.AfleverAdresAnders').fadeTo(100, 0.1);
		$('.AfleverAdresThuis').fadeTo(100, 1);
	}
}

function Aflevering(){
	if(document.getElementById('AfleveringAnders').checked == true){
		var Aflevering = '2';
	} else {
		var Aflevering = '1';
	}
	$.post('execute/controleer_aflevering.php', { 'Aflevering': Aflevering,
	'Tav': document.getElementById('Tav').value,
	'Adres': document.getElementById('Adres').value,
	'Huisnummer': document.getElementById('Huisnummer').value,
	'Postcode': document.getElementById('Postcode').value,
	'Plaats': document.getElementById('Plaats').value,
	'Land': document.getElementById('Land').value, 
	'Opmerkingen': document.getElementById('Opmerkingen').value }, function(data){
		eval(data);
	});
}

function VeranderProductPrijs(PrijsID){
	$.post('product_prijs.php', { 'PrijsID': PrijsID }, function(data){
		eval(data);
	});
}

function NieuwsbriefAanmelden(){
	$.post('execute/nieuwsbrief_aanmelden.php', { 'Email': document.getElementById('VraagNieuwsbriefAan').value }, function(data){
		eval(data);
	});
}

var FotoPositie = 0;
function LaadFoto(FotoID, Positie){
	var ProductID = document.getElementById('ProductID').value;
	
	FotoPositie = Positie;
	if(FotoPositie < 0){
		FotoPositie = 0;
	} else if(FotoPositie > document.getElementById('FotosMax').value){
		FotoPositie = (FotoPositie - 1);
	}
	if(FotoPositie == 0){
		var Pos = 0;
	} else {
		var Pos = ((FotoPositie - 1) * 78);
	}
	
	$(".ScrollItems").animate({ 'margin-left' : '-'+Pos+'px' }, 250);
	$.post('product_foto.php', { 'ProductID': ProductID, 'FotoID': FotoID }, function(data){
		document.getElementById('FotoGroot').innerHTML = data;
		$('a[rel*=lightbox]').lightBox();
	});
}

function FotoNav(Button){
	if(Button == 'Vorige'){
		FotoPositie = (FotoPositie - 1);
	} else if(Button == 'Volgende'){
		FotoPositie = ((FotoPositie * 1) + 1);
	}

	if(FotoPositie < 0){
		FotoPositie = 0;
	} else if(FotoPositie > document.getElementById('FotosMax').value){
		FotoPositie = (FotoPositie - 1);
	}
	var FotoID = document.getElementById('FotoPos'+FotoPositie).value;
	LaadFoto(FotoID, FotoPositie);
}

function CheckKortingsCode(){
	var KortingsCodeA = document.getElementById('KortingsCodeA').value;
	var KortingsCodeB = document.getElementById('KortingsCodeB').value;
	var KortingsCodeC = document.getElementById('KortingsCodeC').value;
	var KortingsCodeD = document.getElementById('KortingsCodeD').value;
	
	$.post('execute/kortingscode.exe.php', { 'KortingsCodeA': KortingsCodeA, 'KortingsCodeB': KortingsCodeB, 'KortingsCodeC': KortingsCodeC, 'KortingsCodeD': KortingsCodeD }, function(data){
		eval(data);
	});
}

function JumpKortingsCode(ID, Max, Next){
	if(document.getElementById(ID).value.length == Max){
		document.getElementById(Next).focus();
	}
}
function JumpLastKortingsCode(){
	if(document.getElementById('KortingsCodeA').value.length == 2 && document.getElementById('KortingsCodeB').value.length == 3 && document.getElementById('KortingsCodeC').value.length == 3 && document.getElementById('KortingsCodeD').value.length == 4){
		CheckKortingsCode();
	}
}
