var isdirty=false;
var hoofdmenu="";
var submenu="";
var timeoutID = 0;
NS4 = (document.layers) ? true : false;

var strEmail="E-mail";
var strPassword="Wachtwoord";
var strAlertAchternaam="Vul a.u.b. uw achternaam in.";
var strAlertVoornaam="Vul a.u.b. uw voornaam in";
var strAlertStraat="Vul a.u.b. de straatnaam in.";
var strAlertHuisnr="Vul a.u.b. het huisnummer in.";
var strAlertPostcode="Controleer a.u.b. de postcode, voorbeeld: 1234 AA.";
var strAlertPlaats="Vul a.u.b. de plaatsnaam in.";
var strAlertTel="Vul a.u.b. het telefoonnummer in.";
var strAlertEmail="Controleer a.u.b. uw email-adres.";
var strAlertWachtwoord="Vul a.u.b. het wachtwoord in.";
var strAlertWachtwoordHerhaal="Herhaal a.u.b. het wachtwoord.";
var strAlertWachtwoordIdentiek="De wachtwoorden komen niet overeen.";
var strAlertBetaalwijze="Kies a.u.b. een betaalmogelijkheid!";

$(document).ready(function() { 
	$("#headermenu-sub-login-invulveldemail").val(strEmail) ;
	$("#headermenu-sub-login-invulveldemail").bind({
		focus: function() {if ($(this).val()==strEmail){$(this).val("")}},
		blur: function() {if ($(this).val()==""){$(this).val(strEmail)}},
		keypress: function(event) {checkEnter("login",event)}
	}) ;
	$("#headermenu-sub-login-invulveldww").val(strPassword) ;
	$("#headermenu-sub-login-invulveldww").bind({
		focus: function() {if ($(this).val()==strPassword){$(this).val("");this.type='password'}},
		blur: function() {if ($(this).val()==""){$(this).val(strPassword);this.type='text'}},
		keypress: function(event) {checkEnter("login",event)}
	}) ;
});

$(document).ready(function() { 
	$('.hoofdmenu').hover(function()
	{
		window.clearTimeout(timeoutID);
		if (hoofdmenu.length>0 && "#"+this.id!=hoofdmenu) {
			$(hoofdmenu).removeClass('active'); 
			if (submenu.length>0) {
				$(submenu).hide();
			}
		}
		hoofdmenu="#"+this.id; 
		$(hoofdmenu).addClass('active');
		submenu="#"+this.id.replace('hoofd','sub');
		$(submenu).fadeIn('fast');
	}, function()
	{
		hoofdmenu="#"+this.id; 
		submenu="#"+this.id.replace('hoofd','sub');
		timeoutID = window.setTimeout(function() 
		{ 
			$(hoofdmenu).removeClass('active'); 
			$(submenu).fadeOut(); 
		}, 500);
});

	$('.submenu').hover(function()
	{
		window.clearTimeout(timeoutID);
	}, function()
	{
		submenu="#"+this.id; 
		hoofdmenu="#"+this.id.replace('sub','hoofd');
		timeoutID = window.setTimeout(function() 
		{ 
			$(hoofdmenu).removeClass('active'); 
			$(submenu).fadeOut(); 
		}, 500);
	});

	});

$(document).ready(function()
		{
			$("#showcase").awShowcase(
			{
				content_width:			490,
				content_height:			450,
				auto:					true,
				interval:				2500,
				continuous:				true,
				loading:				true,
				arrows:					false,
				pauseonover:			true,
				transition:				'hslide', /* hslide/vslide/fade */
				transition_delay:		0,
				transition_speed:		400,
				show_caption:			'onload', /* onload/onhover/show */
				thumbnails_position:	'outside-last', /* outside-last/outside-first/inside-last/inside-first */
				thumbnails_direction:	'vertical', /* vertical/horizontal */
				thumbnails_slidex:		1, /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
				buttons:				false
			});
		});

function VerzendScript(FormiName, TeDoen)	{
	isdirty = false
	document.forms[FormiName].opdracht.value = TeDoen;
	document.forms[FormiName].submit();
}

function checkEnter(FormaName,event)
{ 	
	var code = 0;
	
	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
	if (code==13) {
		if (FormaName == 'login') {
			document.forms[FormaName].submit();}
		else {
			VerzendScript(FormaName,"opslaan");
		}
	}
}

function checkform() {
	if(document.getElementById("contactpersoon").value == "") {
		alert(strAlertAchternaam) ;
		document.getElementById("contactpersoon").focus()
		return false
	}
	if (document.getElementById("isbedrijf").checked==false) {
		if(document.getElementById("cpvoornaam").value == "") {
			alert(strAlertVoornaam) ;
			document.getElementById("cpvoornaam").focus()
			return false
		}
	}
	if(document.getElementById("straat").value == "") {
		alert(strAlertStraat) ;
		document.getElementById("straat").focus()
		return false
	}
	if(document.getElementById("huisnr").value == "") {
		alert(strAlertHuisnr) ;
		document.getElementById("huisnr").focus()
		return false
	}								
	if(checkPostcode(document.getElementById("postcode").value)==false) {
		alert(strAlertPostcode) ;
		document.getElementById("postcode").focus()
		return false
	}
	if(document.getElementById("plaats").value == "") {
		alert(strAlertPlaats) ;
		document.getElementById("plaats").focus()
		return false
	}
	if(document.getElementById("telefoon").value == "") {
		alert(strAlertTel) ;
		document.getElementById("telefoon").focus()
		return false
	}
	//alert(document.getElementById("email").value);
	if(checkEmail(document.getElementById("email").value)==false) {
		alert(strAlertEmail) ;
		document.getElementById("email").focus()
		return false
	}
	if (document.getElementById("wachtwoord")){
		if(document.getElementById("wachtwoord").value == "") {
			alert(strAlertWachtwoord) ;
			return false
		}
		if(document.getElementById("wachtwoordherhaal").value == "") {
			alert(strAlertWachtwoordHerhaal) ;
			return false
		}
		if(document.getElementById("wachtwoord").value != document.getElementById("wachtwoordherhaal").value) {
			alert(strAlertWachtwoordIdentiek) ;
			return false
		}
	}
	return true
}

function checkformBetaalwijze(cRadioName) {
var ingevuld = false;
	for(i=0;i<document.getElementsByName(cRadioName).length;i++){
		 if(document.getElementsByName(cRadioName)[i].checked){
			  ingevuld=true;
			  break;
		 }
	}
	if(ingevuld) {
		return true ;
	} else {
		alert(strAlertBetaalwijze);
		return false ;
	}
}

function checkenter4(FormaName,event)
{ 	
	var code = 0;
	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
	if (code==13) {
		if (checkform()==true) {
		document.forms[FormaName].submit();
		}
	}
}	

function checkEmail( email ) {
   //alert('checkemail: email='+email);
   emailRegex = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
 if( !email.match( emailRegex ) ) {
  return false;
 }
 return true;
}

function checkPostcode(postcode) {
	// Voor nederlandse postcodes
	postcodeRegex=  /^[1-9]{1}[0-9]{3}[ ]?[a-z]{2}/i;
	if (!postcode.match(postcodeRegex)){
		return false;
	}
	return true;
} 

function toggle(id,id2) {
	var cdisplay = document.getElementById(id2).checked ? '' : 'none';
	document.getElementById(id).style.display = cdisplay
}
