$(function(){
	var IE6 = false;
	if($.browser.msie && parseInt($.browser.version, 10)<=6){IE6 = true;}
	
	if(!IE6){
		var firstTime = true;
		var arrTop = ["url(../images/top1.jpg)", "url(../images/top2.jpg)", "url(../images/top3.jpg)", "url(../images/top4.jpg)"];
		(function recurse(counter) {
			var bgImage = arrTop[counter];
			if (firstTime == false) {				
				$("#bgtop").fadeOut(1500, function(){
					$('#bgtop').css('background-image', bgImage);
				});
				$("#bgtop").fadeIn(1500);
			} else {
				firstTime = false;
			}               
			setTimeout(function(){
				if(counter==arrTop.length-1){counter=0}else{counter++}
				recurse(counter);
			}, 9000);
		})(0);
	}
		
	// rechter nav verbergen
	if($(".hostingpakketinfo").length>0){
		$("#rightblock").slideUp();
	}
	if($('#inpHosting').length>0){
		$("#rightblock").slideUp();
	}
	
	$("#btnMeerInfoHosting").click(function(){
		document.location = '/hosting';
		switchContent('hosting');
	});
	$("#btnMeerInfoRegistratie").click(function(){
		document.location = '/check';
		switchContent('registratie');
	});
	$("#btnCheckDomein,#btnHosting3,#btnHosting6,#btnHostingA,#btnHostingB,#btnHostingC").click(function(){document.location = '/check';});
	$("#btnActiveHosting,#btnActiveMail,#btnActiveForward,#btnActiveNameserver").click(function(){document.location = '/activeer';});
	$("#btnWebmail").click(function(){document.location = 'http://mail.registratie.nl';});
	$("#btnControlpanel").click(function(){document.location = 'http://klant.registratie.nl';});
	$("#btnPdf").click(function(){document.location = 'Domeinregistratie_DR.pdf';});
	$("#btnWord").click(function(){document.location = 'Domeinregistratie_DR.doc';});
	$("#btnAlgVoorwaarden").click(function(){document.location = '/voorwaarden';});	
	$("#btnCheck").click(function(e){
		if(document.location.pathname.indexOf("/check") != 0){
			document.location = "/check?d="+encodeURI($("#inpCheck").val());
		}else{
			domeincheck($("#inpCheck").val());
		}
	});
	$("#btnCheck2").click(function(e){
		if(document.location.pathname.indexOf("/check") != 0){
			document.location = "/check?d="+encodeURI($("#inpCheck2").val());
		}else{
			domeincheck($("#inpCheck2").val());
		}
	});
	$("#inpCheck,#inpCheck2").keypress(function(e){
		if(e.which==8 || e.which==32 || e.which==45 || e.which==46 || (e.which>47 && e.which<58) || (e.which>64 && e.which<91) || (e.which>96 && e.which<123) ){
			return true;
		}else if(e.which==13){
			if(document.location.pathname.indexOf("/check") != 0){
				document.location = "/check?d="+encodeURI($(this).val());
			}else{
				domeincheck($(this).val());
			}
			return false;
		}else{
			$("#errmsg").html("Dat teken mag niet").show().fadeOut("slow");
			return false;
		}
	});
	
	// --
	$('#infoemail,#infoforward,#infonameserver,#infoverkoop,#infobescherming').hide();
	$(".hostingInfo").hide();
	$(".hostingpakketinfo")
		.click(function(e){
			tmp = $(this).parent().parent();
			if($(".hostingSpec",tmp).is(':visible')){
				$(".hostingSpec",tmp).fadeOut('fast',function(){
					$(".hostingInfo",tmp).fadeIn('fast');
				});
			}else{
				$(".hostingInfo",tmp).fadeOut('fast',function(){
					$(".hostingSpec",tmp).fadeIn('fast');
				});
			}
		})
		.mouseleave(function(e){
			tmp = $(this).parent().parent();
			if($(".hostingInfo",tmp).is(':visible')){
				$(".hostingInfo",tmp).fadeOut('fast',function(){
					$(".hostingSpec",tmp).fadeIn('fast');
				});
			}
		});

	// --
	
	function switchContent(showThis){
		$('#infodomeinregistratie,#infohosting,#infoemail,#infoforward,#infonameserver,#infoactiveerhosting,#infoactiveeremail,#infoactiveerforward,#infoactiveernameserver').hide();
		
		if(showThis.indexOf("registratie") != -1){
			$("#infodomeinregistratie").slideToggle("normal");
			
		}else if(showThis.indexOf("hosting") != -1){
			$("#infohosting").slideToggle("normal");
			$("#infoactiveerhosting").slideToggle("normal");
			
		}else if(showThis.indexOf("mail") != -1){
			$("#infoemail").slideToggle("normal");
			$("#infoactiveeremail").slideToggle("normal");
			
		}else if(showThis.indexOf("forward") != -1){
			$("#infoforward").slideToggle("normal");
			$("#infoactiveerforward").slideToggle("normal");
			
		}else if(showThis.indexOf("nameserver") != -1){
			$("#infonameserver").slideToggle("normal");
			$("#infoactiveernameserver").slideToggle("normal");
		}else{
			$(this).hide();
		}
	}
	
	if($("#linkemail,#linkactiveeremail").length>0){
		$('#infohosting,#infoemail,#infoforward,#infonameserver,#infoactiveerhosting,#infoactiveeremail,#infoactiveerforward,#infoactiveernameserver').hide();
		$("#linkregistratie,#linkhosting,#linkemail,#linkforward,#linknameserver,#linkactiveerhosting,#linkactiveeremail,#linkactiveerforward,#linkactiveernameserver")
		.click(function (e){
			switchContent($(this).attr('id'));
		});

		if(window.location.hash){
			switchContent(window.location.hash.substring(1));
	  	}
	}
	
	// pak alle inhoud en maak een betere lijst.
	if($("div[id^='helpdeskquestion'] div").length>0){
		$("div[id^='helpdeskquestion']").nextAll().hide();
		
		var FaqList = $('<select id="faqlist"></select>')
		.bind('change keyup', function(event){
				$("div[id^='helpdeskquestion']").not($(this).val()).slideUp('fast');
				$("div[id^='helpdeskquestion']").eq($(this).val()).slideToggle("normal");
				
				// extra opties
				if(Number($(this).val())+1==16
				||Number($(this).val())+1==17
				||Number($(this).val())+1==18
				||Number($(this).val())+1==19
				||Number($(this).val())+1==20
				||Number($(this).val())+1==21
				){ // outlook
					$("#rightblock").slideUp();
					
					var faqId 	= Number($(this).val())+1;
					faqArr 		= getFaqInfo(faqId);
					if($("#faqHolder"+faqId).length>0){
						$("#faqHolder"+faqId).empty();
					}else{
						$("div[id^='helpdeskquestion']").eq($(this).val()).append($('<div>',{'id':'faqHolder'+faqId}));	
					}
					
					for(faqindex in faqArr){
						$("#faqHolder"+faqId)
							.append($('<p>')
									  	.append($('<strong>').text('Stap '+(Number(faqindex)+1)))
										.append($('<br />'))
										.append(faqArr[faqindex][1])
										.append($('<br />'))
										.append($('<br />'))
										.append($('<img>',{'src':faqArr[faqindex][0]})));
					}
				}else{
					$("#rightblock").slideDown();
				}
			})
		;

		$("div[id^='helpdeskquestion'] div").each(function(index){
			$("<option />").val(index).text($(this).text()).appendTo(FaqList);		
		});
		$("div[id='content']").after().append(FaqList);
	}
	
	// hostingpakket info
	if($("div[id^='hostingpakketinfo']").length>0){
		$("div[id^='hostingpakketinfo']").hide();
		$("#btnInfoHosting3,#btnInfoHosting6,#btnInfoHostingA,#btnInfoHostingB,#btnInfoHostingC").click(function(){
			$(this).parent().parent().next("div[id^='hostingpakketinfo']").slideDown('fast',function(){
				$(this).prevAll("div[id^='hostingpakketinfo']").slideUp();
				$(this).nextAll("div[id^='hostingpakketinfo']").slideUp();
  			});
		})
	}
});

var extensie 		= new Array('.nl','.com','.eu','.info','.nu','.biz','.net','.org','.co.uk','.be');
var historyFreeDom 	= new Array();
var ajaxRequests 	= Array(extensie.length);
var url_adddomain	= '/registreer?';

if(document.location.search.indexOf("add") != -1){
	url_adddomain = '/input?';
}

function domeincheck(inpDomein){

	// prepare input
	inpDomein = String(inpDomein.toLowerCase().replace(/(http)|(:)|(www.)|(\/)|( )/gi,"").split(".",1));
	if(inpDomein.length<3){
		alert('de opgegeven domeinnaam is te kort.');
		return;
	}

	// prepare output
	if($('#domeincheckResults').length==0){
		$('#domeincheck').after()
		.append($('<div>',{id:'domeincheckResults'}))
		.append($('<input />',{'type':'button'})
					.val('Geselecteerde registreren')
					.click(function(){
						if($('#domeincheckResults :checkbox:checked, #domeincheckResultsHistory :checkbox:checked').length>0){
							if(document.location.search.indexOf("add") != -1){
								$('#form1').attr('action','/input');
							}
							$('#form1').submit();
						}else{
							alert('U moet minimaal 1 checkbox aanvinken.\nU kunt ook op de domeinnaam link klikken.');
						}						
					})
				);
	}else{
		$('#domeincheckResults').empty();
	}
	
	if(historyFreeDom.length>0
	&& $('#domeincheckResults').length!=0
	&& $('#domeincheckResultsHistory').length==0){
		$('#domeincheck').before().append($('<div>',{id:'domeincheckResultsHistory'}))
	}else if($('#domeincheckResultsHistory').length>0){
		$('#domeincheckResultsHistory').empty()
	}
	
	for(var extId = 0; extId < extensie.length; extId++){
		rowid = extensie[extId].replace(/\./gi,"");

		$('#domeincheckResults')
		.append($('<div>',{'class':'row','id':rowid})
			.append($('<div>',{'class':'cell'}).append($('<input />',{
														 	'type'	: 'checkbox',
														 	'name'	: 'inpSelectedDomein['+$('#domeincheckResults :checkbox').length+']'
														 }).val(inpDomein+''+extensie[extId])
													   ))
			.append($('<div>',{'class':'cell'}).append($('<img>',{src:'images/progressbar_busy.gif'})))
			.append($('<div>',{'class':'cell'}).append(inpDomein+''+extensie[extId]))
		)  
	}
	
	historyFreeDom.reverse();
	for(var historyFreeDomI in historyFreeDom){
		$('#domeincheckResultsHistory')
		.append($('<div>',{'class':'row','HistoryId':historyFreeDomI})
			.append($('<div>',{'class':'cell'}).append($('<input />',{
														 	'type'	: 'checkbox',
														 	'name'	: 'inpSelectedDomein['+$('#domeincheckResultsHistory :checkbox, #domeincheckResults :checkbox').length+']'
														 }).val(historyFreeDom[historyFreeDomI])
													   ))
			.append($('<div>',{'class':'cell'}).append($('<img>',{src:'images/progressbar_green.png'})))
			.append($('<div>',{'class':'cell'}).append($('<a>',{
								href	: url_adddomain+'d='+historyFreeDom[historyFreeDomI],								
								text	: historyFreeDom[historyFreeDomI]
							})
						))	  
		)
	}
	
	// prepare requests
	
	// stop eerdere requests
	for(var extId = 0; extId < extensie.length; extId++){
		if(ajaxRequests[extId] !== undefined){
			if(ajaxRequests[extId]["status"] === undefined){
				ajaxRequests[extId].abort();
			}			
		}
	}
	
	var ajaxRequestErrors = 0;
	var ajaxRequestReady = 0;
	for(var extId = 0; extId < extensie.length; extId++){
		ajaxRequests[extId] = $.ajax({ 
		url		:'/class/check.class.php',
		data	:{d:encodeURI(inpDomein+''+extensie[extId])},
		async	:true,
		cache	:false,
		dataType:'json',
		global	:false,
		type	:'POST',
		beforeSend:function(){},
		success	: function(ar){
			if(ar
			&& ar["domain"] !== undefined
			&& ar["extension"] !== undefined
			&& ar["status"] !== undefined
			&& ar["msg"] !== undefined){
				
				var rowExt = $('#'+String(ar.extension).replace(/\./gi,""), $('#domeincheckResults'));
				if(ar.status==1){
					historyFreeDom[historyFreeDom.length] = ar.domain+""+ar.extension;
					
					$('div',rowExt).eq(0).find('input').prop({disabled:false,checked:false})
					$('div',rowExt).eq(1).find('img').attr({src:'images/progressbar_green.png'});
					$('div',rowExt).eq(2).empty().append($('<a>',{
								href	: url_adddomain+'d='+ar.domain+""+ar.extension,								
								text	: ar.domain+""+ar.extension,
								title	: ar.domain+""+ar.extension+ ' registreren'
							})
					);
				}else if(ar.status==2){
					$('div',rowExt).eq(0).find('input').prop({disabled:true,checked:false});
					$('div',rowExt).eq(1).find('img').attr({src:'images/progressbar_red.png'});
					
				}else{
					$('div',rowExt).eq(0).find('input').prop({disabled:true,checked:false});
					$('div',rowExt).eq(1).find('img').attr({src:'images/progressbar_orange.png'});
					$('div',rowExt).eq(2).text(ar.domain+""+ar.extension+" = "+ar.msg)
				}
			}else{
				ajaxRequestErrors++;
			}
		},
		error 	: function(jqXHR, textStatus, errorThrown){
			ajaxRequestErrors++;
		},
	    complete: function(){
			ajaxRequestReady++;
			if(ajaxRequestReady == extensie.length){
				if(ajaxRequestErrors>0){}
			}
		}
		})
	}
}

// oude functie
function emailaccount(val){
	if(val){
		content = '<font size=1>hosting 6 inclusief 1 e-mail account<br>hosting A inclusief 5 e-mail accounts <br>hosting B inclusief 10 e-mail accounts <br>hosting C inclusief 25 e-mail accounts <br><br>geen hosting: e-mail account 1,- euro pmd <br>extra e-mail accounts + 1,- euro pmd</font><hr noshade size=1><p>Aangeven wat u voor de @ wilt hebben, <font size=1>(bijv info of admin) </font><br><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td><input type=text name=pop1 size=15 class=box></td><td><input type=text name=pop2 size=15 class=box></td><td><input type=text name=pop3 size=15 class=box></td></tr><tr><td><input type=text name=pop4 size=15 class=box></td><td><input type=text name=pop5 size=15 class=box></td><td><input type=text name=pop6 size=15 class=box></td></tr><tr><td> <input type=text name=pop7 size=15 class=box></td><td><input type=text name=pop8 size=15 class=box></td><td><input type=text name=pop9 size=15 class=box></td></tr><tr><td><input type=text name=pop10 size=15 class=box></td><td colspan=2></td></tr></table>';
		document.getElementById('emailadresopt').innerHTML = content;
	}else{
		document.getElementById('emailadresopt').innerHTML = "";
	}
}

function getFaqInfo(what){
	if(what==16){
		return [
		["images/helpdesk/ws_1.gif","Vul de gegevens in die u van ons heeft ontvangen.<br />Klik OK"],
		["images/helpdesk/ws_3.gif","De verbinding met de webserver wordt tot stand gebracht."],
		["images/helpdesk/ws_3.gif","In het linkerframe staan de bestanden van uw website.<br />U selecteert links de bestanden en plaatst deze met de pijl naar rechts.<br />Uw website staat hiermee direct online."]
		]
	}else if(what==17){
		return [
		["images/helpdesk/outlookexpress0.jpg","Klik op de knop Extra (bovenin, naast Beeld)"],
		["images/helpdesk/outlookexpress1.jpg","Kies dan de knop Accounts"],
		["images/helpdesk/outlookexpress2.jpg","1.) Klik op het tabblad E-mail.<br />Hier staan de reeds bestaande mailaccounts.<br />2.) Klik op Toevoegen en daarna E-mail om een account toe te voegen"],
		["images/helpdesk/outlookexpress3.jpg","1.) Vul hier uw naam of emailadres in<br />2.) Klik op volgende >"],
		["images/helpdesk/outlookexpress4.jpg","1.) Vul hier uw emailadres in<br />2.) Klik op volgende >"],
		["images/helpdesk/outlookexpress5.jpg","1.) Vul in bij inkomende e-mail (pop3): www4.nederlandweb.nl<br />2.) Voor het verzenden gebruikt u de smtp van uw inbelverbinding.<br />3.) Klik op volgende>"],
		["images/helpdesk/outlookexpress6.jpg","1.) Vul uw accountnaam en wachtwoord in (uw accountnaam is meestal uw emailadres).<br />Let op hoofdletters en kleine letters<br />2.) Klik op volgende>"],
		["images/helpdesk/outlookexpress7.jpg","Klik op voltooien ><br />Uw nieuwe mail-account is toegevoegd aan de lijst."]
		]
	}else if(what==18){
		return [
		["images/helpdesk/windowmail0.jpg","1.) Klik op de knop Extra (bovenin, naast Beeld)<br />2.) Kies dan de knop Accounts"],
		["images/helpdesk/windowmail1.jpg","Klik op de knop toevoegen"],
		["images/helpdesk/windowmail2.jpg","1.) Kies als accounttype E-mailaccount<br />2.) Klik dan op de knop volgende >"],
		["images/helpdesk/windowmail3.jpg","1.) Vul hier uw naam of emailadres in<br />2.) Klik op volgende >"],
		["images/helpdesk/windowmail4.jpg","1.) Vul hier uw emailadres in<br />2.) Klik op volgende >"],
		["images/helpdesk/windowmail5.jpg","1.) Vul in bij inkomende e-mail (pop3): www4.nederlandweb.nl<br />2.) Voor het verzenden gebruikt u de smtp van uw inbelverbinding.<br />3.) Klik op volgende>"],
		["images/helpdesk/windowmail6.jpg","1.) Vul uw accountnaam en wachtwoord in (uw accountnaam is meestal uw emailadres).<br />Let op hoofdletters en kleine letters<br />2.) Klik op volgende>"],
		["images/helpdesk/windowmail7.jpg","Klik op voltooien ><br />Uw nieuwe mail-account is toegevoegd aan de lijst."]
		]
	}else if(what==19){
		return [
		["images/helpdesk/outlook20070.jpg","1.) Klik op de knop Extra<br />2.) Kies dan de knop Accountinstellingen"],
		["images/helpdesk/outlook20071.jpg","Klik op de knop nieuw"],
		["images/helpdesk/outlook20072.jpg","Klik dan op de knop volgende >"],
		["images/helpdesk/outlook20073.jpg","1.) vink de optie, Serverinstellingen of extra servertype handmatig configuren aan<br />2.) Klik op volgende >"],
		["images/helpdesk/outlook20074.jpg","Klik op volgende >"],
		["images/helpdesk/outlook20075.jpg","1.) Server voor inkomende e-mail: www4.nederlandweb.nl<br />2.) Server voor uitgaande e-mail: smtp van uw inbelverbinding.<br />3.) Vul ook de rest in en klik op volgende>"],
		["images/helpdesk/outlook20076.jpg","Klik op voltooien<br />Uw nieuwe mail-account is toegevoegd aan de lijst."]
		]		
	}else if(what==20){
		return [
		["images/helpdesk/macmail.jpg","Gebruik de volgende instellingen"],
		]
	}else if(what==21){
		return [
		["images/helpdesk/iphone.jpg","Gebruik de volgende instellingen"],
		]
	}
	return [];
}
