var configuratieDomeinTimer;

$(document).ready(function() {
  $('#nieuweWebsiteLink').click(function () {
     //$.scrollTo( '.nieuwsTekst', 800, {easing:'elasout'} );
  	$.scrollTo( '#bericht49', 800);
  });

  $('.FacebookTwitter a').click(function () {
    window.open($(this).attr('href'));
    return false;
  });
	
	$('#mcafeeLogo a, #mcafeepanel a').click(function (e) {
	  e.preventDefault();
		window.open($(this).attr('href'));
	});
	
	$('.facebookRating').html("<iframe src=\"http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2F%23%21%2Fpages%2FSoHosted%2F157754817579982&amp;layout=standard&amp;show_faces=false&amp;width=210&amp;action=recommend&amp;font=trebuchet+ms&amp;colorscheme=light&amp;height=72\" style=\"border:none; overflow:hidden; width:210px; height:72px;\" frameborder=\"0\" allowTransparency=\"true\"></iframe>");

	$('.bestelWizardInlineLaden').attr('target', '_blank');

	$('.bedankDelen a').click(function(e) {
	  e.preventDefault();
		
		window.open($(this).attr('href'));
  });
	
	$('.aliasToewijzenSelectie').change(function() {
	  var waarde = $(this).val();
		
		if (waarde == 'n1' || waarde == 'n2' || waarde == 'n3' || waarde == 'n4' || waarde == 'n10') {
		  $(this).parent().find('span:hidden').fadeIn('fast');
		} else {
		  $(this).parent().find('span:visible').fadeOut('fast');
		}
	});
	
	$('.promocodeOpslaan').click(function(e) {
	  e.preventDefault();
		
		if ($(this).hasClass('promocodeUpgradeOpslaan')) {
		  var isUpgrade = true;
		} else {
		  var isUpgrade = false;
		}
		
		if ($(this).hasClass('promocodePrivacyOpslaan')) {
		  var isPrivacy = true;
		} else {
		  var isPrivacy = false;
		}
		
		var code = $('.promocodeInvullen').val();

		$.ajax({
		  url: '/php/verwerk/ajax/promoCodeControleren.php',
			data: {
			  code: code
			},
			success: function(xml) {
			  var melding = $(xml).find('melding').text();
			  var succes = $(xml).find('succes').text();
				
				if(succes == 1) {
				  if (isUpgrade) {
					  document.location.href = '/klanten/upgraden/pakket';
					} else if(isPrivacy) {
					  document.location.href = '/klanten/privacyprotect/menu=mijnSohosted';
					} else {
				    document.location.href = '/wizard/afronden';
					}
				} else {
				  alert(melding);
				}
			}
		});
	});
	
	$('#privacyProtectForm').submit(function(e) {
	  e.preventDefault();
		
		var aantal = $('#privacyProtectForm .domeinenSelectie:checked').length;
		
		if(aantal > 0) {
		  LaadStatus();
		
		  $.ajax({
			  url: webadres + "php/verwerk/ajax/akkoordSPPVoorwaarden.php",
				dataType: 'html',
				data: $('#privacyProtectForm').serializeArray(),
				success: function(response) {
				  akkoordVoorwaardenResultaat(response);
				}
			});
		} else {
		  alert('Kies een (of meerdere) domeinnamen om Privacy Protect voor te bestellen.'); 
		}
	});
	
	$('.alternatiefFacturatieAdres').click(function() {
	  if($(this).hasClass('passiefIcon')) {
		  $(this).removeClass('passiefIcon').addClass('actiefIcon');
			facturatieAdres(true);
			$('.facturatieAdresForm:hidden').fadeIn('fast');
			$('#apart_facturatie_adres').attr('checked', true);
		} else {
		  $(this).removeClass('actiefIcon').addClass('passiefIcon');
			facturatieAdres(false);
			$('.facturatieAdresForm:visible').fadeOut('fast');
			$('#apart_facturatie_adres').attr('checked', false);
		}
	});
	
	$('.afrondenDomeinopties .contractSelect').change(function() {
	  winkelwagenDomeinOpties();
	});
	
	$('.afrondenDomeinopties .privacyCheckbox').click(function() {
	  var checked = $(this).attr('checked');
		
		if(checked) {
		  $(this).parent().parent().find('.kolomEigenaar a').fadeOut('fast');
		} else {
		  $(this).parent().parent().find('.kolomEigenaar a').fadeIn('fast');
		}
	
	  winkelwagenDomeinOpties();
	});
	
	$('.dataverkeerGrafiek img').click(function() {
	  var src = $(this).attr('src');
	
	  grafiekPopup(src);
	});
	
  VPSConfigurerenBinds();
});

function grafiekPopup(src) {
  box = document.getElementById('infocontainer');
	box.style.display = 'block';
  box.innerHTML = '<div id="witbg"></div>';	
	box.innerHTML += '<div class="adminGrafiekPopUp"><img src="' + src + '" alt="" /><a class="sluiten" href="javascript:popup_gegevens_sluiten(1)">[ sluiten ]</a></div>';
}

function popup_gegevens_sluiten(nietBevestigen) {
  if(nietBevestigen == 1) {
		$('#infocontainer').hide().html('');
	} else {
    if (confirm('Weet je zeker dat je dit venster wilt sluiten?')) {
  		$('#infocontainer').hide().html('');
    }
	}
}

function winkelwagenDomeinOpties() {
  var params = $('#rekening_formulier').serializeArray();
	
	$.ajax({
	  url: '/php/verwerk/ajax/wizardDomeinOpties.php',
		data: params,
		success: function(data) {
		  var winkelwagen = $(data).find('winkelwagen').text();
			
			$('.wizardPakkettenPart').html(winkelwagen);
			
			vernieuwMandje ();
		}
	});
}

function VPSConfigurerenBinds() {
	$('.configuratieOpties .optie').hover(function() {
	  if ($('.configuratieOpties .actieveOptie').length > 0 && $(this).hasClass('actieveOptie') == false) {
	    $('.configuratieOpties .actieveOptie').removeClass('actieveOptie');
			$('.configuratieOpties .optieProductenLijst').hide();
		}
		
		var optieUitleg = $(this).find('.uitlegNaam').val();
		
		$('.optieUitleg:visible').hide();
		$('.' + optieUitleg).fadeIn('fast');
		
	  $(this).addClass('actieveOptie');
	}, function() {
	  $(this).find('.optieProductenLijst').hide();
	});
	
	$('.configuratieOpties .optieSelectieKnop').click(function() {
//	  $(this).parent().find('.optieProductenLijst:hidden').slideDown('fast');
	  $(this).parent().find('.optieProductenLijst:hidden').show();
	});
	
	optieWaardeBinds();
	
	if ($('.configuratieOpties').length > 0) {
	  eigenServerPrijs();
	}
	
	$('.configuratieDomein .hostnaam').click(function() {
	  $(this).parent().find('.noborder').attr('checked', true);
		var waarde = $(this).val();
		
		if (waarde == 'Server-naam') { $(this).val(''); }
		if (waarde == 'Eigendomeinnaam.extensie') { $(this).val(''); }
		
	  configuratieDomeinTimer = setTimeout('eigenServerPrijs()', 1000);
	});
	
	$('.configuratieDomein .noborder').click(function() {
	  configuratieDomeinTimer = setTimeout('eigenServerPrijs()', 1000);
	});
	
	$('.configuratieDomein .hostnaamA .hostnaam').blur(function() {
		var waarde = $(this).val();
		
		if (waarde == '') { $(this).val('Server-naam'); }
	});
	
	$('.configuratieDomein .hostnaamB .hostnaam').blur(function() {
		var waarde = $(this).val();
		
		if (waarde == '') { $(this).val('Eigendomeinnaam.extensie'); }
	});
	
	$('.configuratieDomein .hostnaam').keyup(function() {
	  clearTimeout(configuratieDomeinTimer);
	  configuratieDomeinTimer = setTimeout('eigenServerPrijs()', 1000);
	});
	
	$('.configuratieBestellenForm').submit(function(e) {
	  e.preventDefault();

		LaadStatus();		
		
    var waardes = $('.configuratieForm').serialize();
		
  	$.ajax({
  	  url: '/php/verwerk/ajax/eigenServerPrijs.php',
  	  dataType: 'xml',
  		data: waardes,
  		success: function(data) {
  		  var geldig = $(data).find('geldig').text();
				
				document.getElementById('infocontainer').style.display = 'none';

				if (geldig == 1) {
				  InlinePopupDirectSluiten();
				  alert('Kies een besturingssysteem voor uw VPS');
				} else if (geldig == 3) {
				  InlinePopupDirectSluiten();
				  alert('Windows 2003 kunt u met maximaal 4 GB aan geheugen bestellen');
				} else if (geldig == 4) {
				  InlinePopupDirectSluiten();
				  alert('De gekozen hostnaam is al bezet');
				} else if (geldig == 5) {
				  InlinePopupDirectSluiten();
				  alert('Kies een hostnaam voor uw VPS');
				} else if (geldig == 2) {
				  $('.configuratieBestellenForm').unbind('submit').submit();
				}
			}
		});
	});
	
	$('.configuratieOpslaanForm').submit(function(e) {
	  e.preventDefault();
		
    var waardes = $('.configuratieForm').serialize();

  	$.ajax({
  	  url: '/php/verwerk/ajax/VPSconfigurerenOpslaan.php',
  	  dataType: 'html',
  		data: waardes,
			type: 'POST',
  		success: function(data) {
			  var succesCode = data.substr(0, 3);
				
				if(succesCode == 101) {
				  alert('Kies een besturingssysteem');
				} else if (succesCode == 99) {
				  alert('Onbekende pakket fout');
				} else {
				  $('.wizardPakkettenPart').html(data);
    			InlinePopupDirectSluiten();
      		vernieuwMandje ();
				}
			}
		});
	});
	
	$('.configuratieBestellen input').click(function() {
	  $('.configuratieBestellenForm .buttonType').val($(this).attr('class'));
	});
}

function optieWaardeBinds() {
	$('.configuratieOpties .optieWaarde').unbind('click').click(function() {
	  $('.configuratieOpties .optieActieveWaarde').removeClass('optieActieveWaarde');
		$(this).addClass('optieActieveWaarde');
		
	  var waarde = $(this).find('.text').text();
    		waarde = waarde.replace('Windows ', '');
				waarde = waarde.substr(0, 17);

				
	  var prijs = $(this).find('.prijs').text();

		$(this).parent().parent().parent().parent().parent().find('.optieInput').val($(this).find('.optieID').val());
		
	  $(this).parent().parent().parent().parent().find('.optieHuidigeWaarde').html(waarde + ' <span class="prijs">' + prijs + '</span>');
		$(this).parent().parent().parent().hide();
		
		var klasse = $(this).parent().parent().parent().parent().parent().attr('class');

		if(klasse == 'wijzigHuidigPakketBox') {
  		eigenServerPrijs();			
		} else {
  		eigenServerPrijs();
		}
	});
}

function eigenServerPrijs() {
  var waardes = $('.configuratieForm').serialize();
	
	$('.optiesPrijs').addClass('optiesPrijsLaden');
	
	$.ajax({
	  url: '/php/verwerk/ajax/eigenServerPrijs.php',
	  dataType: 'xml',
		data: waardes,
		success: function(data) {
		  var geldig = $(data).find('geldig').text();

			if (geldig > 0) {		
			  var overzicht = $(data).find('overzicht').text();
				var totaalPrijs = $(data).find('totaalPrijs').text();
				var totaalPrijsEuro = $(data).find('totaalPrijsEuro').text();
				
				$('.configuratieOverzicht .overzichtContent').html(overzicht);
				$('.optiesPrijs .prijs').html('&euro; ' + totaalPrijsEuro);
				$('.configuratieBestellen .prijsPerMaand .prijs').html('&euro; ' + totaalPrijsEuro);
				
				if (geldig == 2) {
				  $('.configuratieBestellen').show();				
				} else {
				  // Alleen opslaan knop verbergen (indien niet alles ingevuld is), in geval van configuratie wijzigen (niet bij nieuwe configuratie)
				  if ($('.configuratieOpslaanForm').length > 0 && geldig < 4) {
				    $('.configuratieBestellen').hide();
					} else {
					  $('.configuratieBestellen').show();
					}
				}
			} else {
  		  // Alleen opslaan knop verbergen (indien niet alles ingevuld is), in geval van configuratie wijzigen (niet bij nieuwe configuratie)			
  		  if ($('.configuratieOpslaanForm').length > 0 && geldig < 4) {
  		    $('.configuratieBestellen').hide();
  			} else {
  				$('.configuratieBestellen').show();				
				}
			}
			
				var hostGeldig = $(data).find('hostGeldig').text();
				var hostBeschikbaar = $(data).find('hostBeschikbaar').text();
				var hostIngevuld = $(data).find('hostIngevuld').text();
				
				if(hostIngevuld > 0) {
  				if(hostGeldig == 1 && hostBeschikbaar == 1) {
  				  $('.hostnaamBezet').hide();
  					$('.hostnaamOngeldig').hide();					
  				} else if (hostGeldig == 0) {
  				  $('.hostnaamBezet').hide();
  					$('.hostnaamOngeldig').show();
  				} else if (hostGeldig == 1 && hostBeschikbaar == 0) {
  				  $('.hostnaamBezet').show();
  					$('.hostnaamOngeldig').hide();
  				} else {
  				  $('.hostnaamBezet').hide();
  					$('.hostnaamOngeldig').hide();
  				}
				} else {
 				  $('.hostnaamBezet').hide();
 					$('.hostnaamOngeldig').hide();				
				}
			
			var backupDienstOpties = '<div class="optieWaarde"><input type="hidden" class="optieID" value="0" /><span class="text">geen</span></div>';
			var backupDienstHuidigePrijs = $(data).find('backupDienstHuidigePrijs').text();

			$(data).find('backupDienstOpties').find('optie').each(function() {
			  var titel = $(this).find('titel').text();
			  var id = $(this).find('id').text();
			  var prijs = $(this).find('prijs').text();
				
				backupDienstOpties += '<div class="optieWaarde"><input type="hidden" class="optieID" value="' + id + '" /><span class="text">' + titel + '</span><span class="prijs">&euro; ' + prijs + '</span></div>';
			});
			
			
			$('.optieCategorie9 .innerLijst').html(backupDienstOpties);
			
			if(backupDienstHuidigePrijs == '0,00') {
  			$('.optieCategorie9 .optieHuidigeWaarde .prijs').html('');
			} else {
			  if ($('.optieCategorie9 .optieHuidigeWaarde .prijs').length > 0) {
  			  $('.optieCategorie9 .optieHuidigeWaarde .prijs').html('&euro; ' + backupDienstHuidigePrijs);
				} else {
  			  $('.optieCategorie9 .optieHuidigeWaarde').html($('.optieCategorie9 .optieHuidigeWaarde').html() + '<span class="prijs">&euro; ' + backupDienstHuidigePrijs + '</span>');
				}
			}
			
			// Geheugen opties
  			var geheugenOpties = '<div class="optieWaarde"><input type="hidden" class="optieID" value="0" /><span class="text">geen</span></div>';
				
				$(data).find('geheugenOpties').find('optie').each(function() {
  			  var titel = $(this).find('titel').text();
  			  var id = $(this).find('id').text();
  			  var prijs = $(this).find('prijs').text();

  				geheugenOpties += '<div class="optieWaarde"><input type="hidden" class="optieID" value="' + id + '" /><span class="text">' + titel + '</span><span class="prijs">&euro; ' + prijs + '</span></div>';
				});

				$('.optieCategorie3 .innerLijst').html(geheugenOpties);
				
  			var geheugenHuidigePrijs = $(data).find('geheugenHuidigePrijs').text();
				var geheugenHuidigeOptie = $(data).find('geheugenHuidigeOptie').text();
				
				$('.optieCategorie3 .optieHuidigeWaarde').html(geheugenHuidigeOptie);				
				
  			if(geheugenHuidigePrijs == '0,00') {
    			$('.optieCategorie3 .optieHuidigeWaarde .prijs').html('');
  			} else {
  			  if ($('.optieCategorie3 .optieHuidigeWaarde .prijs').length > 0) {
    			  $('.optieCategorie3 .optieHuidigeWaarde .prijs').html('&euro; ' + geheugenHuidigePrijs);
  				} else {
    			  $('.optieCategorie3 .optieHuidigeWaarde').html($('.optieCategorie3 .optieHuidigeWaarde').html() + '<span class="prijs">&euro; ' + geheugenHuidigePrijs + '</span>');
  				}
  			}								

			// Processor opties
  			var processorOpties = '<div class="optieWaarde"><input type="hidden" class="optieID" value="0" /><span class="text">geen</span></div>';
				
				$(data).find('processorOpties').find('optie').each(function() {
  			  var titel = $(this).find('titel').text();
  			  var id = $(this).find('id').text();
  			  var prijs = $(this).find('prijs').text();
  				
  				processorOpties += '<div class="optieWaarde"><input type="hidden" class="optieID" value="' + id + '" /><span class="text">' + titel + '</span><span class="prijs">&euro; ' + prijs + '</span></div>';
				});
				
				$('.optieCategorie2 .innerLijst').html(processorOpties);
				
  			var processorHuidigePrijs = $(data).find('processorHuidigePrijs').text();
				var processorHuidigeOptie = $(data).find('processorHuidigeOptie').text();
				
				$('.optieCategorie2 .optieHuidigeWaarde').html(processorHuidigeOptie);
				
  			if(processorHuidigePrijs == '0,00') {
    			$('.optieCategorie2 .optieHuidigeWaarde .prijs').html('');
  			} else {
  			  if ($('.optieCategorie2 .optieHuidigeWaarde .prijs').length > 0) {
    			  $('.optieCategorie2 .optieHuidigeWaarde .prijs').html('&euro; ' + processorHuidigePrijs);
  				} else {
    			  $('.optieCategorie2 .optieHuidigeWaarde').html($('.optieCategorie2 .optieHuidigeWaarde').html() + '<span class="prijs">&euro; ' + processorHuidigePrijs + '</span>');
  				}
  			}					

			
			optieWaardeBinds();
			
			$('.optiesPrijsLaden').removeClass('optiesPrijsLaden');
			
  	  var processorMax = $(data).find('processorMax').text();
			
			if(processorMax > 0) {
    	  $('.optieCategorie2').show();
			} else {
    	  $('.optieCategorie2').hide();
			}			
		}
	});
	
	// In geval van pakket power de extra cpu optie verbergen

	  /*
  	if ($('.pakketID').val() == 14) {
  	  $('.optieCategorie2').hide();
			$('.optieCategorie2 .optieInput').val('0');
  	} else {
  	  $('.optieCategorie2').show();
  	}
		*/		
}
