jQuery.noConflict();

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

(function($) { 
  $(function() {
    

	
	
$(document).ready(function () {
    
    // Give forgot password table parent a class for styling
    $("#dnn_ctr_SendPassword_tblSendPassword").closest("#dnn_contentpane").addClass("forgot-password");

// Start search form script
$(".searchformfield").focus(function () {
	if ($(this).val() == $(this).attr("title")) {
		$(this).val("");
	}
}).blur(function () {
	if ($(this).val() == "") {
		$(this).val($(this).attr("title"));
	}
});

// End search form script click*/

// Start stuurdoor form script

var mouse_is_inside = false;

function toggleStuurDoor(){
	$("#stuurdoor_form").toggle();
	clearStuurDoorForm();
	$('#stuurdoor').toggleClass('active');

}

function clearStuurDoorForm(){
	$("#stuurdoor_form fieldset").show();
	$("#stuurdoor_fail").hide();
	$("#stuurdoor_success").hide();
	$("#email_receiver").val($("#email_receiver").attr("title"));
	$("#email_sender").val($("#email_sender").attr("title"));
	$("#toelichting").val($("#toelichting").attr("title"));
}

    $('#stuurdoor').hover(function(){ mouse_is_inside=true; }, function(){ mouse_is_inside=false; });
    $('#stuurdoor_form').hover(function(){ mouse_is_inside=true; }, function(){ mouse_is_inside=false; });
	
	$('body').mouseup(function(){ if(! mouse_is_inside && $('#stuurdoor_form').is(':visible')){
		toggleStuurDoor();
	}});

	
	$("#email_receiver").focus(function () {if ($(this).val() === $(this).attr("title")) {$(this).val("");}}).blur(function () {if ($(this).val() === "") {$(this).val($(this).attr("title"));}});
	$("#email_sender").focus(function () {if ($(this).val() === $(this).attr("title")) {$(this).val("");}}).blur(function () {if ($(this).val() === "") {$(this).val($(this).attr("title"));}});
	$("#toelichting").focus(function () {if ($(this).val() === $(this).attr("title")) {$(this).val("");}	}).blur(function () {if ($(this).val() === "") {$(this).val($(this).attr("title"));}});

	$('.stuurdoor_toggle').click(function() {
		toggleStuurDoor();
	});
 
	$('#stuurdoor_form .submit').click(function() {
	//declare vars
    var email_receiver = $("#email_receiver").val();
    var email_sender = $("#email_sender").val();
    var toelichting = $("#toelichting").val();
	if (toelichting == "Toelichting"){toelichting = "";}
	var url = window.location.href;
	var pageTitle = $("h1").text();
	//start validation
	$('#stuurdoor_form .error').remove();
	var hasError = false;
	$('.required').each(function() {
		if($(this).hasClass('email')) {
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;	
			if(!emailReg.test(jQuery.trim($(this).val()))) {
				$(this).parent().append('<span class="error">Het e-mail adres klopt niet.</span>');
				hasError = true;
			}
		}
	});
	if(!hasError) {
		$("#stuurdoor_loading").show();
	//submit form
		$.ajax({
		url: '/Portals/_default/kgservices/NonUiServices.aspx',
		data: ("formID=stuurdoor&pageTitle=" + pageTitle + "&url=" + url + "&email_receiver=" + email_receiver + "&email_sender=" + email_sender + "&toelichting=" + toelichting),
		success: function() {$("#stuurdoor_loading").hide();$("#stuurdoor_success").show();},
		error: function() {$("#stuurdoor_loading").hide();$("#stuurdoor_fail").show();},
		timeout: function() {$("#stuurdoor_loading").hide();$("#stuurdoor_fail").show();}
		});
	//hides the form
		$("#stuurdoor_form fieldset").hide(); 
	}
	return false;
	});

	$('.stuurdoor_again').click(function() {
		clearStuurDoorForm();
	});
// End stuur door form script*/

// Start text resize script
// credit: http://trevordavis.net/blog/simple-jquery-text-resizer/

	if($.cookie('TEXT_SIZE')) {
		$('body').addClass($.cookie('TEXT_SIZE'));	
	}
	$('.resizer span').click(function() {
		var textSize = $(this).parent().attr('class');
		$('body').removeClass('small medium large').addClass(textSize);
		$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
		return false;
	});
	
// End text resize script click

});



  });
})(jQuery);
