jQuery(document).ready(function() 
{
	var ajaxCall	=	null;
	var imgShow		=	true;
	
	//################################################### ONLOAD ###################################################//
	//################################################### ONLOAD ###################################################//
	//################################################### ONLOAD ###################################################//
	
	$('[class*=werkgever_cv]').live("mouseover", function(){
			$('[class*=werkgever_cv]').each(function(){
				if( $(this).data('qtip') ) { return true; }
				$(this).qtip(
				{
				  content: { text: $(this).attr("alt")},
				  position: { target: 'mouse' },
				  style: { width: { max: 250 } },
				  show: { delay: 0, ready: false },
				  hide: { delay: 0 }
				});
			});
		});	
			
	if($(".cv_vorige").attr("id") ==	'0'	|| $(".cv_vorige").attr("id") ==	0)
	{
		$(".cv_vorige").html("");
	}
	var cookie_postcodeZoeken = $.cookie("cookie_input_postcodezoeken");
	if (cookie_postcodeZoeken == null)
	{
		$("#input_postcodezoeken").attr("value", 'Uw postcode');
	}
	else
	{
		$("#input_postcodezoeken").attr("value", $.cookie("cookie_input_postcodezoeken"));
	}
	//################################################### CLICKS ###################################################//
	//################################################### CLICKS ###################################################//
	//################################################### CLICKS ###################################################//
	
		$(".folder_open").click(function() { 
			$("ul#[id^='" + $(this).attr('id') + "']").slideDown('slow');
		/*	if($(this).hasClass('folder')){
				$('li#' + $(this).attr('id')).removeClass('folder');
				$('li#' + $(this).attr('id')).addClass('folder_open');
			}else{
				$('li#' + $(this).attr('id')).removeClass('folder_open');
				$('li#' + $(this).attr('id')).addClass('folder');
			}*/
		});
	
		$("#gebruikersemail").click(function()
		{
			var value = $(this).val();
			if(value == "E-mailadres"){
				$(this).attr("value", "");
			}
		});
	
		$("#gebruikerswachtwoord").click(function()
		{
			var value = $(this).val();
			if(value == "password"){
				$(this).attr("value", "");
			}
		});
	
		$("#input_postcodezoeken").click(function()
		{
			$(this).attr("value", "");
		});
		
		$('#frontendZoeken').click(function(){
			var temp = $("#zoekenop").attr("value");
			temp =  temp.replace(/[^a-zA-Z 0-9 ]+/g,'+');
			document.location = base_url+'zoeken/'+temp;
		});
		
		$(".h_bar_middle").click(function()
		{
			var vacatureNr	=	$(this).attr("id");
			$(".vacature_bekijken_" + vacatureNr).slideToggle("fast");
			data = {"urlToAjax": base_url + 'ajax/vacatureGelezen/',  "vacatureNr": vacatureNr, 'windowLocation': '' + window.location }
			vacatureGelezen(data);
		});
		
		$(".cv_h_bar_middle").click(function()
		{
			var cvNr	=	$(this).attr("id");
			$(".cv_bekijken_" + cvNr).slideToggle("fast");
			data = {"urlToAjax": base_url + 'ajax/cvGelezen/',  "cvNr": cvNr, 'windowLocation': '' + window.location }
			cvGelezen(data);		
		});
		
		
		function rotatebranchetak()
		{
			if(imgShow){
				var holder1 	= 	$("#branchetak_holder1").attr("name");
				var holder2 	= 	$("#branchetak_holder2").attr("name");
				var holder3 	= 	$("#branchetak_holder3").attr("name");
				var holder4 	= 	$("#branchetak_holder4").attr("name");
				var newHolder1	=	'';
				var newHolder2	=	'';
				var newHolder3	=	'';
				var newHolder4	=	'';
				var current1	= 	$("#branchetak_holder1").css("background-image").split("/");
				var current2	= 	$("#branchetak_holder2").css("background-image").split("/");
				var current3	= 	$("#branchetak_holder3").css("background-image").split("/");
				var current4	= 	$("#branchetak_holder4").css("background-image").split("/");
				current1		=	current1[current1.length-1].replace("\")","");
				current2		=	current2[current2.length-1].replace("\")","");
				current3		=	current3[current3.length-1].replace("\")","");
				current4		=	current4[current4.length-1].replace("\")","");
				holder1 		= 	holder1.split(",");
				holder2 		= 	holder2.split(",");
				holder3 		= 	holder3.split(",");
				holder4 		= 	holder4.split(",");
				if(holder1.length > 1){
					newHolder1 = findClosest(holder1,array_search(current1, holder1));
					$("#branchetak_holder1").delay(5000).fadeOut('slow', function(){
						var tmp	=	$("#branchetak_holder1").css("background-image").replace(current1,holder1[newHolder1]);
						$("#branchetak_holder1").css("background-image", tmp);
						$("#branchetak_holder1").fadeIn('slow').delay(5000);
						if(holder2.length > 1){
							newHolder2 = findClosest(holder2,array_search(current2, holder2));
							$("#branchetak_holder2").delay(5000).fadeOut('slow', function(){
								var tmp	=	$("#branchetak_holder2").css("background-image").replace(current2,holder2[newHolder2]);
								$("#branchetak_holder2").css("background-image", tmp);
								$("#branchetak_holder2").fadeIn('slow').delay(5000);
								if(holder3.length > 1){
									newHolder3 = findClosest(holder3,array_search(current3, holder3));
									$("#branchetak_holder3").delay(5000).fadeOut('slow', function(){
										var tmp	=	$("#branchetak_holder3").css("background-image").replace(current3,holder3[newHolder3]);
										$("#branchetak_holder3").css("background-image", tmp);
										$("#branchetak_holder3").fadeIn('slow').delay(5000);
										if(holder4.length > 1){
											newHolder4 = findClosest(holder4,array_search(current4, holder4));
											$("#branchetak_holder4").delay(5000).fadeOut('slow', function(){
												var tmp	=	$("#branchetak_holder4").css("background-image").replace(current4,holder4[newHolder4]);
												$("#branchetak_holder4").css("background-image", tmp);
												$("#branchetak_holder4").fadeIn('slow');
											});
										}
									});
								}
							});
						}
					});
				}
				
				
				
				imgShow	= 	false;
			}
		}
		
		if(($("#branchetak_holder1").length) && ($("#branchetak_holder2").length) && ($("#branchetak_holder3").length) && ($("#branchetak_holder4").length)){
			imgShow = true;
			rotatebranchetak();
			rotateInterval	=	setInterval( function (){imgShow = true; rotatebranchetak();}, 25000);
		}

		$(".geplaatstevacature_positief").live('click', live_vacatureReactiePositief);		
		
		function live_vacatureReactiePositief()
		{
			if(confirm('Weet u het zeker?'))
			{		
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/reactieOpVacature/',  "cvVacNr": cvVacNr,"reactie_wn": 1,  'windowLocation': '' + window.location }
				reactieOpVacature(data);
			}
		}
		
		$(".geplaatstevacature_negatief").live('click', live_vacatureReactieNegatief);
		
		function live_vacatureReactieNegatief()
		{
			if(confirm('Weet u het zeker?'))
			{		
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/reactieOpVacature/',  "cvVacNr": cvVacNr,"reactie_wn": 0,  'windowLocation': '' + window.location }
				reactieOpVacature(data);
			}
		}
		
		
		$(".btn_vacature_duplicerenFE").live('click', function() 
		{  
			if(confirm("Weet u zeker dat u deze vacature wilt dupliceren?"))
			{
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/dupliceerVacatureFE/',  "cvVacNr": cvVacNr,"reactie_wn": 0,  'windowLocation': '' + window.location }
				dupliceerVacatureFE(data);
			}
		});
		
		$(".vacatureNaarPrullenbak").live('click', function() 
		{  
			if(confirm("Weet u zeker dat u deze vacature in de prullenbak wilt doen?"))
			{
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/vacatureNaarPrullenbak/',  "cvVacNr": cvVacNr,"reactie_wn": 0,  'windowLocation': '' + window.location }
				vacatureNaarPrullenbak(data);
			}
		});
		
		$(".geplaatstecv_positief").live('click', live_cvReactiePositief);	

		function live_cvReactiePositief()
		{
			if(confirm('Weet u het zeker?'))
			{		
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/reactieOpCv/',  "cvVacNr": cvVacNr,"reactie_wg": 1,  'windowLocation': '' + window.location }
				reactieOpCv(data);
			}
		}		
		
		$(".geplaatstecv_negatief").live('click', live_cvReactieNegatief);	

		function live_cvReactieNegatief()
		{
			if(confirm('Weet u het zeker?'))
			{			
				var cvVacNr	=	$(this).attr("id");			
				data = {"urlToAjax": base_url + 'ajax/reactieOpCv/',  "cvVacNr": cvVacNr,"reactie_wg": 0,  'windowLocation': '' + window.location }
				reactieOpCv(data);
			}
		}		
		
		
		
		$(".vacatureVerwijderen").click(function()
		{
			if(confirm('Weet u het zeker?'))
			{			
				var cvVacNr	=	$(this).attr("id");
				data = {"urlToAjax": base_url + 'ajax/reactieVacatureVerwijderen/',  "cvVacNr": cvVacNr, 'windowLocation': '' + window.location }
				reactieVacatureVerwijderen(data);			
			}
		});
		
		$(".cvVerwijderen").click(function()
		{
			if(confirm('Weet u het zeker?'))
			{		
				var cvVacNr	=	$(this).attr("id");
				data = {"urlToAjax": base_url + 'ajax/reactieCvVerwijderen/',  "cvVacNr": cvVacNr, 'windowLocation': '' + window.location }
				reactieCvVerwijderen(data);	
			}
		});		
		
		
		$('input[name="werkgevers_aanmelden_zondermetvacature"]').click(function()
		{
			var value = $(this).attr("value");
			if(value == 1)
			{
				$("#werkgevers_aanmelden_metvacature").slideUp("fast");
				$("#werkgevers_aanmelden_zondervacature").slideDown("fast");
			}
			else if(value == 0)
			{
				$("#werkgevers_aanmelden_zondervacature").slideUp("fast");
				$("#werkgevers_aanmelden_metvacature").slideDown("fast");
			}
		});
		
		$(".werkgever_cv_contactopnemen").live("click", function()
		{
			var form	=	$("#werkgever_werknemer_cv_contactOpnemen").html();
			$('#werkgever_werknemer_cv_contactOpnemen').dialog('open');
		});
		
		$('.werkgever_wn_contactopnemen').tipsy({ gravity: 'sw', fade: true, title: "alt", html: true });
		
		$(".werkgever_wn_contactopnemen").live("click", function()
		{
			var title	=	$(this).attr('title').split("_");
			apprise($(this).attr("alt"), {'verify':true, 'textYes':'Contact opnemen', 'textNo':'Verder kijken'}, function(contact){
				if(contact){
					//ze willen contact
					var nr		=	title[1];
					var wg		=	title[0];
					ajaxCall = $.ajax({
							type: 'POST',
							url: base_url + 'ajax/benader_kandidaat/',
							data :{"cvNr": nr, "wgNr": wg, 'frontend_backend': data['windowLocation'] },
							success:
								function(responseData)
								{
									apprise(responseData);
								},
							error:
								function(xhr, ajaxOptions, thrownError)
								{
										apprise(xhr.responseText);
								}
							});
				}else{
					//geen contact opnemen, move along!
				}
			});
			
			
			/*$("#Benader_een_werknemer_"+nr).dialog({
				bgiframe: true,
				autoOpen: true,
				resizable: false,
				width: 500,
				height: 120,
				title: "Benader kandidaat."
			});*/
		});
		
		$(".benader_license_ja").live("click", function()
		{
			var title	=	$(this).attr('title').split("_");
			var nr		=	title[1];
			var wg		=	title[0];
			ajaxCall = $.ajax({
					type: 'POST',
					url: base_url + 'ajax/benader_kandidaat/',
					data :{"cvNr": nr, "wgNr": wg, 'frontend_backend': data['windowLocation'] },
					success:
						function(responseData)
						{
							alert(responseData);
							$("#Benader_een_werknemer_"+nr).dialog('close');
						},
					error:
						function(xhr, ajaxOptions, thrownError)
						{
								alert(xhr.responseText);
						}
					});				
		});
		
		$(".benader_license_nee").live("click", function()
		{
			var title	=	$(this).attr('title').split("_");
			var nr		=	title[1];
			var wg		=	title[0];
			$("#Benader_een_werknemer_"+nr).dialog('close');
		});
		
		
		
		$(".werkgever_cv_contactopnemen_aanmelden").live("click", function()
		{
			window.location = base_url + 'werkgevers/aanmelden/stap1'
		});		
		

	$("#wachtwoordvergeten_submit").live('click', function()
	{
		//check of het nodig is eerst (mailinator check)
		if($("#my_email").val().search(/mailinator.com/i) > 0){
			apprise('U heeft een inactieve mailadres ingevoerd, naar welk mailadres mogen wij het wachtwoord sturen?<br/>(Na het invoeren kunt u inloggen met het ingelogde email adres.)', {'input':true}, function(r){
				if(!r){
					// niets verder doen.
					return false;
				}else{
					$("#newmail").val(r);
					$("#form_ww_vergeten").submit();
				}
			});
		}else{
			apprise('Uw gegevens worden opgevraagd');
			$("#form_ww_vergeten").submit();
		}
	});

	$('#frontend_pageLimits a').live("click", function(event)
	{
			event.preventDefault();
			var pagina			=	$(this).attr("pagina");
			var windowLocation	=	'' + window.location; //make a string out of it.
			var postcode		= 	$("#input_postcodezoeken").attr("value").replace(/[^\d.]/g, "");
			var soort			= 	$("#input_soortzoeken").attr("value");
			data				=	{ "urlToAjax": $(this).attr("href"), "postcode": postcode, "soort": soort, "pagina" : pagina,  'windowLocation': windowLocation };	
			zoeken(data);		 
	});

	$(".cv_volgende, .cv_vorige").live("click", function()
	{
		var className	=	$(this).attr("class");
		var arrayId		=	parseInt($(this).attr("id"));
		
		switch(className)
		{
			case 'cv_vorige':
				$(this).attr("id", (arrayId > 0)	?	arrayId - 1	:	0);
				data = {"urlToAjax": base_url + 'ajax/switchVanCv/',  "arrayid": arrayId, "vorigevolgende":'vorige' , 'windowLocation': '' + window.location }
				switchVanCv(data);				
				$(".cv_volgende").attr("id", (arrayId > 1)	?	arrayId	:	1);
			break;
			
			case 'cv_volgende':
				$(this).attr("id", arrayId + 1);
				data = {"urlToAjax": base_url + 'ajax/switchVanCv/',  "arrayid": arrayId, "vorigevolgende":'volgende','windowLocation': '' + window.location }
				//alert(data.urlToAjax);
				//alert(data.arrayid);
				//alert(data.windowLocation);				
				switchVanCv(data);					
				$(".cv_vorige").attr("id", arrayId -1);
			break;
		}
	});
		
	//################################################### END CLICKS ###################################################//
	//################################################### END CLICKS ###################################################//
	//################################################### END CLICKS ###################################################//
	
	//################################################### DIALOG VALIDATION ###################################################//
	//################################################### DIALOG VALIDATION ###################################################//
	//################################################### DIALOG VALIDATION ###################################################//
	
	// JDR: our form submit and valiation
	var aform = $("#form_wg_cv_contactopnemen").validate({
	
		// JDR: make sure we show/hide both blocks
		errorContainer: "#errorblock-div1, #errorblock-div2",
		// JDR: put all error messages in a UL
		errorLabelContainer: "#errorblock-div2 ul",
		// JDR: wrap all error messages in an LI tag
		wrapper: "li",
		// JDR: rules/messages are for the validation
		rules: {
	        input_bedrijfsnaam: 	"required",
			input_contactpersoon:	"required",
			input_telefoon:			"required",
	        input_email: 			{required: true, email: true},
			textarea_opmerking:		"required"
	    },
	    messages: {
	        input_bedrijfsnaam: 	"Bedrijfsnaam is verplicht.",
			input_contactpersoon: 	"Contactpersoon is verplicht.",
			input_telefoon:	 		"Telefoon is verplicht.",
	        input_email: 			{required: "Email is verplicht.",email: "Email is verplicht."},
			textarea_opmerking: 	"Opmerking is verplicht."
	    },
		
		// JDR: our form submit
	    submitHandler: function(form)
		{
			data	=	{ 'urlToAjax': base_url_fe + "ajax/werkgever_cv_contactOpnemen", 'windowLocation': '' + window.location, 'cvnummer': $("#cv_vac_top").attr("alt"), 'bedrijfsnaam': $("#input_bedrijfsnaam").attr("value"), 'contactpersoon': $("#input_contactpersoon").attr("value"), 'telefoon': $("#input_telefoon").attr("value"), 'email': $("#input_email").attr("value"), 'opmerking': $("#textarea_opmerking").attr("value")};
			werkgever_cv_contactOpnemen(data);
	    }
	});		
		
	// JDR: our modal dialog setup
	var amodal = $("#werkgever_werknemer_cv_contactOpnemen").dialog({
	   bgiframe: true,
	   autoOpen: false,
	   width: 500,
	   height: 350,
	   modal: true,
	   title: "Contact opnemen",
	   buttons: {
	      'Versturen': function() 
		  { 
		  	// JDR: submit the form
		  	$("#form_wg_cv_contactopnemen").submit(); 
		  },
	      "Afsluiten": function() 
		  { 
		  	// JDR: close the dialog, reset the form
		    $(this).dialog('close'); aform.resetForm(); 
		  }
	   }
	});
	
	//################################################### END DIALOG VALIDATION ###################################################//
	//################################################### END DIALOG VALIDATION ###################################################//
	//################################################### END DIALOG VALIDATION ###################################################//	

		
		
		
		
		
		function changeToValidText(field){
			var temp = document.getElementById(field).value;
			temp =  temp.replace(/[^a-zA-Z 0-9 ]+/g,'+');
			document.location = base_url+'zoeken/'+temp;
		}	

		$(function()
		{
			$('a[rel="external"]').attr('target','_blank');
		});	

		
	//################################################### FUNCTIONS ###################################################//
	//################################################### FUNCTIONS ###################################################//
	//################################################### FUNCTIONS ###################################################//		

		function openInfo(field,id){
			//closeList = document.getElementById(field);
			//closeList.style.display = 'none';
			$('.'+field).hide("fade", {}, 500);
			$('.'+field+id).show("fade", {}, 1000);
			//$('.'+field+id).show("slide", {direction: "right"}, 1000);
		}

		function nextInfo(field,id){
			var newfield = field.replace(/[^a-z]/gi, '');
			newfield = newfield+id;
			$('.'+field).hide("slide", {direction: "left"}, 500);
			$('.'+newfield).delay(1000).show("slide", {direction: "right"}, 1000);
		}

		function previousInfo(field,id){
			var newfield = field.replace(/[^a-z]/gi, '');
			newfield = newfield+id;
			$('.'+field).hide("slide", {direction: "right"}, 500);
			$('.'+newfield).delay(800).show("slide", {direction: "left"}, 1000);
		}
		
		function openDialog(id, titles, text)
		{
			$("#" + id).html(text);
			$("#" + id).dialog({
				modal: true,
				title: titles,
				width: '500',
				height: '200',
				resizable: true,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog("close");
					}
				}
			});		
		}
		
	//################################################### END FUNCTIONS ###################################################//
	//################################################### END FUNCTIONS ###################################################//
	//################################################### END FUNCTIONS ###################################################//		
		
		
	//################################################### AJAX ###################################################//
	//################################################### AJAX ###################################################//
	//################################################### AJAX ###################################################//	
		
		function reactieOpVacature(data)
		{
			//alert(data['urlToAjax']);
			//exit;
			var cvVacNr = data['cvVacNr'];
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data :{"cvVacNr": data['cvVacNr'],"reactie_wn": data['reactie_wn'],  'frontend_backend': data['windowLocation'] },
					  success:
						  function(responseData)
						  {
							openDialog("dialog", "Reactie", responseData);
							if(data['reactie_wn'] == 1)
							{
								$('.geplaatstevacature_positief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).attr("class","beantwoordevacature_positief");
									}
								});
								
								$('.geplaatstevacature_negatief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).fadeOut("fast");
									}
								});
								
								//$('.beantwoordvacature_positief').unbind('click');
							}
							else
							{
								$('.geplaatstevacature_negatief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).attr("class","beantwoordevacature_negatief");
									}
								});
								
								$('.geplaatstevacature_positief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).fadeOut("fast");
									}
								});
							}
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Reactie", xhr.responseText);
							}
					  
					});				
		}
		
		
		function reactieOpCv(data)
		{
			//alert(data['urlToAjax']);
			//exit;
			var cvVacNr = data['cvVacNr'];
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data :{"cvVacNr": data['cvVacNr'],"reactie_wg": data['reactie_wg'],  'frontend_backend': data['windowLocation'] },
					  success:
						  function(responseData)
						  {
							openDialog("dialog", "Reactie", responseData);
							if(data['reactie_wg'] == 1)
							{
								$('.geplaatstecv_positief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).attr("class","beantwoordevacature_positief");
									}
								});
								
								$('.geplaatstecv_negatief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).fadeOut("fast");
									}
								});
								
								//$('.beantwoordvacature_positief').unbind('click');
							}
							else
							{
								$('.geplaatstecv_negatief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).attr("class","beantwoordevacature_negatief");
									}
								});
								
								$('.geplaatstecv_positief').each(function()
								{
									if($(this).attr("id") == cvVacNr)
									{
										$(this).fadeOut("fast");
									}
								});
							}
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Reactie", xhr.responseText);
								$("#ajaxBeforeSend").fadeOut("fast");
							}
					  
					});				
		}
		
		function reactieVacatureVerwijderen(data)
		{
			var cvVacNr = data['cvVacNr'].split('-');
			var cvNr	=	cvVacNr[0];
			var vacNr	=	cvVacNr[1]; 			
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					  data :{"cvVacNr": data['cvVacNr'], 'frontend_backend': data['windowLocation'] },
					  success:
						  function(responseData)
						  {
							openDialog("dialog", "Reactie", 'Vacature verwijdert.');
							$(".geplaatstevacatures_"+vacNr).fadeOut("slow");
							$(".vacature_bekijken_"+vacNr).fadeOut("slow");
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Reactie", 'Er is iets verkeerd gegaan');
								$("#ajaxBeforeSend").fadeOut("fast");
							}
					  
					});		
		}
		
		function dupliceerVacatureFE(vacature_id)
		{
			 ajaxCall = $.ajax({
				  type: 'POST',
				  url:	data['urlToAjax'],
				  data: {"vacaturenummer": vacature_id},
				  beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
				  success:
					  function(responseData)
					  {
						openDialog("dialog", "Vacature dupliceren", responseData);
						$(".btn_vacature_duplicerenFE").fadeOut("slow");
						$("#ajaxBeforeSend").fadeOut("slow");
					  },
					error:
						function(xhr, ajaxOptions, thrownError)
						{
							$("#ajaxBeforeSend").fadeOut("slow");
							openDialog("dialog", "Vacature error", xhr.responseText);
						}
				  
				});
		}
		
		
		function vacatureNaarPrullenbak(vacature_id)
		{
			 ajaxCall = $.ajax({
				  type: 'POST',
				  url:	data['urlToAjax'],
				  data: {"vacaturenummer": vacature_id},
				  beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
				  success:
					  function(responseData)
					  {
						openDialog("dialog", "Vacature naar prullenbak", responseData);
						$(".vacatureNaarPrullenbak").fadeOut("slow");
						$("#ajaxBeforeSend").fadeOut("slow");
					  },
					error:
						function(xhr, ajaxOptions, thrownError)
						{
							$("#ajaxBeforeSend").fadeOut("slow");
							openDialog("dialog", "Vacature error", xhr.responseText);
						}
				  
				});
		}
		
		function reactieCvVerwijderen(data)
		{
			var cvVacNr = data['cvVacNr'].split('-');
			var cvNr	=	cvVacNr[0];
			var vacNr	=	cvVacNr[1];
			
 			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					  data :{"cvVacNr": data['cvVacNr'], 'frontend_backend': data['windowLocation'] },
					  beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
							$(".geplaatstecv_"+cvNr+"_"+vacNr).fadeOut("slow");
							$(".cv_bekijken_"+cvNr+"_"+vacNr).fadeOut("slow");
							openDialog("dialog", "Reactie", responseData);
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Reactie", xhr.responseText);
								$("#ajaxBeforeSend").fadeOut("fast");
							}
					  
					});	 	
		}		
		
		$('#zoekOpdracht').click(function(){
			var postcode	= $("#input_postcodezoeken").attr("value").replace(/[^\d.]/g, "");
			$.cookie("cookie_input_postcodezoeken", postcode);
			var soort		= $("#input_soortzoeken").attr("value");
			var extraparam	= $("#input_extraparamzoeken").attr("value");
			var data 		= {"urlToAjax": base_url + 'ajax/zoekOpdracht', 'postcode': postcode, 'extraparam' : extraparam, 'soort': soort, 'windowLocation': '' + window.location }
			
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					  data:	{ 'postcode': data['postcode'], 'soort': data['soort'], 'extraparam' : data['extraparam']},
					  beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
							$("#zoekOpdracht_result").html(responseData);
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								apprise(xhr.responseText);
								$("#ajaxBeforeSend").fadeOut("fast");
							}
					  
					});	
		});


		function zoeken(data)
		{
			ajaxCall = $.ajax({
					type: 'POST',
					url: data['urlToAjax'],
					data:	{ 'postcode': data['postcode'], 'soort': data['soort'], 'pagina': data['pagina']},
					 beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
							$("#zoekOpdracht_result").html(responseData);
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								apprise(xhr.responseText);
								$("#ajaxBeforeSend").fadeOut("fast");
							}
					  
					});			
		}		
		
		
		
		function vacatureGelezen(data)
		{
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data :{"vacatureNr": data['vacatureNr'], 'frontend_backend': data['windowLocation'] },
					 beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Vacature", xhr.responseText);
							}
					  
					});				
		}
		
		
		function cvGelezen(data)
		{
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data :{"cvNr": data['cvNr'], 'frontend_backend': data['windowLocation'] },
					 beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Vacature", xhr.responseText);
							}
					  
					});				
		}

		function werkgever_cv_contactOpnemen(data)
		{
			//alert(data['urlToAjax']);
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data:	{ 'cvnummer': data['cvnummer'], 'bedrijfsnaam': data['bedrijfsnaam'], 'contactpersoon': data['contactpersoon'], 'telefoon': data['telefoon'], 'email': data['email'], 'opmerking': data['opmerking']},
					 beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
						  function(responseData)
						  {
							$("#ajaxBeforeSend").fadeOut("fast");
							$('#werkgever_werknemer_cv_contactOpnemen').dialog('close');
							openDialog("dialog", "Contact opnemen", responseData);
							window.location = base_url_fe;
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Contact opnemen", xhr.responseText);
							}
					  
					});			
		}

		function switchVanCv(data)
		{
			ajaxCall = $.ajax({
					  type: 'POST',
					  url: data['urlToAjax'],
					 data:	{ 'arrayid': data['arrayid'], 'vorigevolgende':	data['vorigevolgende']},
					 beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
					  success:
					  	  function(responseData)
						  {
							switch(data['vorigevolgende'])
							{
								case "vorige":
									$('.divRight').hide("slide", {direction: "right"}).html("");
									$('.divRight').show("slide", {direction: "left"}).html(responseData);								
								break;
								
								case "volgende":
									$('.divRight').hide("slide", {direction: "left"}).html("");
									$('.divRight').show("slide", {direction: "right"}).html(responseData);								
								break;
							}
/* 							$(".divRight").fadeOut("fast").html("");
							$(".divRight").html(responseData).fadeIn("fast"); */
						  },
						error:
							function(xhr, ajaxOptions, thrownError)
							{
								openDialog("dialog", "Contact opnemen", xhr.responseText);
							}
					  
					});			
		}
		
	//################################################### END AJAX ###################################################//
	//################################################### END AJAX ###################################################//
	//################################################### END AJAX ###################################################//		


});

//##############Stand Alone Function##############//
function checkEnter(e)
{
	var key = "";
	if(window.event){ // IE
		key = String.fromCharCode(e.keyCode);
	}else if(e.which){ // Firefox
		key = String.fromCharCode(e.which);
	}
	if(key.charCodeAt(0) == 13){
		var temp = $("#zoekenop").attr("value");
		temp =  temp.replace(/[^a-zA-Z 0-9 ]+/g,'+');
		document.location = base_url+'zoeken/'+temp;
	}
} 

function checkPostcodeEnter(e)
{
	var key = "";
	if(window.event)
	{ // IE
		key = String.fromCharCode(e.keyCode);
	}
	else if(e.which)
	{ // Firefox
		key = String.fromCharCode(e.which);
	}
	if(key.charCodeAt(0) == 13)
	{
		var postcode	= $("#input_postcodezoeken").attr("value").replace(/[^\d.]/g, "");
		$.cookie("cookie_input_postcodezoeken", postcode);
		var soort		= $("#input_soortzoeken").attr("value");
		var data 		= {"urlToAjax": base_url + 'ajax/zoekOpdracht', 'postcode': postcode, 'soort': soort, 'windowLocation': '' + window.location }
		
		ajaxCall = $.ajax({
				  type: 'POST',
				  url: data['urlToAjax'],
				  data:	{ 'postcode': data['postcode'], 'soort': data['soort']},
				  beforeSend: function() { $('#ajaxBeforeSend').fadeIn("fast"); },
				  success:
					  function(responseData)
					  {
						//document.getElementById('map_nl').style.backgroundPosition = '0px '+responseData;
						$("#ajaxBeforeSend").fadeOut("fast");
						$("#zoekOpdracht_result").html(responseData);
					  },
					error:
						function(xhr, ajaxOptions, thrownError)
						{
							apprise(xhr.responseText);
							$("#ajaxBeforeSend").fadeOut("fast");
						}
				  
				});	
					
	}
}

function openClose(ulList, closeLists){
	$("ul #"+ulList).slideToggle('slow');
	if (typeof closeLists === 'undefined' || !closeLists) {
		//Hij is leeg dus doe niets
	}else{
		var explList	=	closeLists.split(",");
		for(var list in explList)
		{
			if($("ul #"+explList[list]).is(":hidden"))
			{
				//Niets doen omdat hij al ge-toggled is.
			}else{
				$("ul #"+explList[list]).slideToggle('slow');
			}
		}
	}
}




function findClosest(arr, id) 
{
	var max_id	=	(arr.length-1);
	if(id == max_id){
		return 0;
	}else{
		return (parseInt(id)+1);
	}
}

function array_search(needle, haystack, argStrict) 
{
	var strict = !! argStrict;
	var key = '';
	for (key in haystack) {
		if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) 
		{
			return key;
		}
	}
	return false;
}



