$(document).ready(function(){
	checkContentHeight();
	
	/*load kengu*/
	var flashvars = {};
		flashvars.autostart = "true";
		flashvars.showstop = "false";
		flashvars.allowSciptAccess = "never";
	var params = {};
		params.play = "true";
		params.loop = "false";
		params.menu = "true";
		params.quality = "best";
		params.allowfullscreen = "false";
		params.allowscriptaccess = "never";
		params.allownetworking = "internal";
		params.wmode = "transparent";
	var attributes = {};
		attributes.id = "box-flash";
	swfobject.embedSWF("/images/bellen.swf", "box-flash", "125", "265", "9.0.0", "/images/expressInstall.swf", flashvars, params, attributes);
	/*END load kengu*/

	$('#bellensubmit').click(function () {
		if($("#bellenNaam").val() == "Naam") {
			$("#bellenNaam").val("");
			$("#bellenNaam").css("color","#000");
		}
		if($("#bellenTel").val() == "Telefoonnummer") {
			$("#bellenTel").val("");
			$("#bellenTel").css("color","#000");
		}
		$("#bellenform").submit();
    });
	$("#bellenform").validate({
		setDefaults: $.validator.setDefaults({
			errorLabelContainer: "#messageBox",
			wrapper: "span"
		}),
		rules: {
			bellenNaam: "required",
			bellenTel: "required"
		},
		messages: {
			bellenNaam: "Vul a.u.b. uw naam in.",
			bellenTel: "Vul a.u.b. uw telefoonnummer in."
		}
	});
	
	$('#reageersubmit').click(function () {
		$("#reageerform").submit();
    });
	$("#reageerform").validate({
		setDefaults: $.validator.setDefaults({
			errorLabelContainer: "#reageerMessageBox",
			wrapper: "span"
		}),
		rules: {
			voornaam: "required",
			achternaam: "required",
			bedrijf: "required",
			eigen_functie: "required",
			telefoon: "required",
			traineefunc: "required",
			outplacementfunc: "required",
			mailadres: {
				required: true,
				email: true
			}
		},
		messages: {
			voornaam: "Vul a.u.b. uw voornaam in.",
			achternaam: "Vul a.u.b. uw achternaam in.",
			bedrijf: "Wat is uw huidige werknemer?",
			eigen_functie: "Wat is uw functie?",
			telefoon: "Vul a.u.b. uw telefoonnummer in.",
			traineefunc: "Vul a.u.b. uw gewenste trainee functie in.",
			outplacementfunc: "Vul a.u.b. uw gewenste outplacement in.",
			mailadres: "Vul a.u.b. een correct emailadres in."
		}
	});
});


function checkContentHeight(){
	var rightHeight = $('#right').height();
	var contentHeight = $('#content').height();
	var newHeight = contentHeight;
	
	if(contentHeight < 500)	newHeight = 500;
	if(rightHeight > 150) newHeight += (rightHeight - 150);

	if(newHeight > contentHeight) {
		$('#content').height(newHeight);
		$('#box').css("bottom","-1px");
	}
}

function cmtCheckChange(newUrl){
	var oldContent="";
	var newContent="";
	oldContent = $('#oldContent').html();
	if(oldContent!=null) {
		oldContent = nlstrip(oldContent.toLowerCase());
		newContent = nlstrip(tinyMCE.activeEditor.getContent().toLowerCase());
		
		//alert('old: '+oldContent+'\r\nnew: '+newContent);
		//alert(newUrl);
		
		if(oldContent != newContent){
			if(!confirm('U verlaat de pagina zonder de wijzigingen op te slaan.\r\n\r\nWeet u het zeker?'))	return false;
			else window.location = newUrl;
		} else window.location = newUrl;
		//$('#'+formName).submit();
	} else window.location = newUrl;
	//window.location = newUrl;
}


// Function to strip newlines!
function nlstrip(text){
	//extra replacement: &nbsp; -> spatie
	text = text.replace(/&nbsp;/,' ');
	text = escape(text);
	var re_nlchar;
	//alert(text);
	//text.replace(/%26nbsp%3B/,'%A0');
	
	if(text.indexOf('%0D%0A') > -1){
		re_nlchar = /%0D%0A/g ;
	}else if(text.indexOf('%0A') > -1){
		re_nlchar = /%0A/g ;
	}else if(text.indexOf('%0D') > -1){
		re_nlchar = /%0D/g ;
	}
	//now do the replacement with ''
	return unescape( text.replace(re_nlchar,'') );
}
