/* for use with suckerfish menus */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		
		if(sfEls[i].parentNode.id != 'nav')
		{
			sfEls[i].parentNode.style.marginLeft = -sfEls[i].parentNode.parentNode.clientWidth+"px";
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
/* end for use with suckerfish menus */

/* popup for product images */
function CreatePopupWindow(img,width,height) {
	window.open(img,'_new','width='+width+',height='+height+',status=no,scrollbars=no,toolbar=no,location=no,menubar=no,directories=no,resizable=no');
	return;
}

var button = 1;

/* form checker */
function CheckForm(f) {
	
	if (document.getElementsByName("factuurgegevens[firstname]")[0].value == "") {
		alert('Vul aub uw voornaam in.');
		document.getElementsByName("factuurgegevens[firstname]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[lastname]")[0].value == "") {
		alert('Vul aub uw achternaam in.');
		document.getElementsByName("factuurgegevens[lastname]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[address]")[0].value == "") {
		alert('Vul aub uw adres in.');
		document.getElementsByName("factuurgegevens[address]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[postcode]")[0].value == "") {
		alert('Vul aub uw postcode in.');
		document.getElementsByName("factuurgegevens[postcode]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[city]")[0].value == "") {
		alert('Vul aub uw woonplaats in.');
		document.getElementsByName("factuurgegevens[city]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[phone]")[0].value == "") {
		alert('Vul aub uw telefoonnummer in.');
		document.getElementsByName("factuurgegevens[phone]")[0].focus();
		return(false);
	} else if (document.getElementsByName("factuurgegevens[email]")[0].value == "") {
		alert('Vul aub uw e-mail adres in.');
		document.getElementsByName("factuurgegevens[email]")[0].focus();
		return(false);
	}
	else if (document.getElementsByName("factuurgegevens[terms]")[0].checked != true) {
		alert('Verklaar aub dat u akkoord gaat met de leveringsvoorwaarden.');
		document.getElementsByName("factuurgegevens[terms]")[0].focus();
		return(false);
	}
	
	return(true);
}

function CheckFormPayment(f) {
	
	if((f.issuerID.value == 0) && (button == 3))
	{
		alert('Kies aub uw bank om de iDeal transactie te voltooien.');
		f.ideal_bank.focus();
		return false;
	}
	return true;
}

function CreatePopupWindow(url,width,height) {
	window.open(url,'_new','width='+width+',height='+height+',status=no,scrollbars=no,toolbar=no,location=no,menubar=no,directories=no,resizable=no');
	return;
}

function CheckCursussenForm() {
	// FORM
	var f = document.cursusform;
	
	// MESSAGE
	var header = 'De volgende velden zijn niet correct ingevuld:\n\n';
	
	// CHECK FIELDS
	var message = '';
	message += CheckField(f.T70, 'Achternaam');
	message += CheckField(f.T71, 'Roepnaam');
	message += CheckField(f.T72, 'Adres');
	message += CheckField(f.T73, 'Postcode');
	message += CheckField(f.T74, 'Woonplaats');
	message += CheckField(f.T75, 'Geboorte datum');
	message += CheckField(f.T76, 'Telefoonnummer');
	message += CheckField(f.T77, 'Mobiel nummer');
	message += CheckEmail(f.T78, 'Email adres');
	message += Checkbox(f.T79, 'Geslacht');
	
	if (f.T81[0].checked) {
		message += CheckField(f.T83, 'Ten naamstelling');
		message += CheckField(f.T82, 'Rekeningnummer');
	}
	
	if (message != "") {
		alert(header+''+message);
		return false
	}
}

function CheckField(fieldname, message) {
	if(fieldname) {
		var v = new RegExp();
		v.compile("^([A-Za-z]|[0-9]){1,}");
		
		if (!v.test(fieldname.value)) {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+'\n';
			return message;
		} else {
			SetFFStyle(fieldname, 'Good');
			return '';
		}
	} else {
		return '';
	}
}

function SetFFStyle(el, status) {
	if (status == 'Bad') {
		// Change classname to bad
		el.className = 'FormCheckBad';
	} else {
		// Restore to default class
		el.className = 'FormCheckGood';
	}
}

function Checkbox(fieldname, message) {
	if(fieldname) {
		if (fieldname.checked == false) {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+'\n';
			return message;
		} else {
			SetFFStyle(fieldname, 'Good');
			return '';
		}
	} else {
		return '';
	}
}

function CheckEmail(fieldname, message) {
	if(fieldname) {
		if (fieldname.value == "") {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+'\n';
			return message;
		} else if (IsEmail(fieldname.value) == false) {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+fieldname.value+' is geen geldig e-mailadres !\n';
			return message;
		} else {
			SetFFStyle(fieldname, 'Good');
			return '';
		}
	} else {
		return '';
	}
}

function IsEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

