$(document).ready(function() {
	$('#loginblok').css('height','0px !important');		
	
	$('input').each(function() {
		if($(this).attr("altvalue")!=null) {
			if($(this).val()=='') { $(this).val($(this).attr("altvalue"));	}
			
			
			$(this).focus(function() {
				
				if($(this).val()==$(this).attr("altvalue")) {
					$(this).val('');	
				}
			}).blur(function() {
				if($(this).val()=='') {
					$(this).val($(this).attr("altvalue"));	
				}
				
			});
		}
	});
	
	$('#menu li').mouseenter(function() {
		//alert('test');
		$(this).find("div").removeClass('hidden');						 
	}).mouseleave(function() {
		$(this).find("div").addClass('hidden');						 
	});

});

function unfold(id) {
	
	$('#testimonial'+id+' .bar_inner').hide();
	$('#testimonial'+id+' .compleet').show();

	
	
}

function fold(id) {
	$('#testimonial'+id+' .bar_inner').show();
	$('#testimonial'+id+' .compleet').hide();

	
}

function togglelogin(login) {
	if(login==null) {
		var login=0;	
	}
	
	if(login==0) {
		if($('#loginblok').is(':visible')) {
			$('#loginblok').hide();				   
			
		} else {
			
			$('#loginblok').show();
			
		}
	} else {
		if($('#profielblok').is(':visible')) {
			$('#profielblok').hide();				   
			
		} else {
			
			$('#profielblok').show();
			
		}

	}
	
}

function toggle_subs(id) {
	if($("#subtypes"+id).is(":visible")) {
		$("#subtypes"+id).hide();	
		$("#togglesub"+id).removeClass('active');	
	} else {
		$("#subtypes"+id).show();	
		$("#togglesub"+id).addClass('active');	
	}
}
var req;

function searchvacatures(p) {
	if(req!=null) {
		req.abort();	
	}
	
	if(p==null) {
		var p = '';	
	}
	
	$.post(baseurl+"includes/search.php", $('#search_box').serialize()+'&p='+p,
		function(data) {
			//alert(data);
			$('#mainContent').html(data);
		}
	);	
}

function solliciteer() {

	
	$.post(baseurl+"includes/solliciteer.php", $('#solliciteer_form').serialize(),
		function(data) {
			//alert(data);
			$('#solliciteerblok').hide();
			calert("Uw sollicitatie is verzonden");
		}
	);	
}


function tellafriend() {

	
	$.post(baseurl+"includes/tellafriend.php", $('#tellafriend_form').serialize(),
		function(data) {
			if(data=='succes') {
				//alert(data);
				$('#tellafriend').hide();
				calert("Uw bericht is verzonden");
			} else {
				calert(data);
			}
		}
	);	
}


function registreer() {

	
	$.post(baseurl+"includes/registreer.php", $('#registreer_form').serialize(),
		function(data) {
			if(data=='success') {
				
				$('#registreerblok').hide();
				calert("U bent succesvol geregistreerd",refreshpage);
			} else {
				calert(data);
			}
		}
	);	
}

function change_data() {

	
	$.post(baseurl+"includes/change_data.php", $('#profiel_form').serialize(),
		function(data) {

			calert("De wijzigingen zijn opgeslagen");
		}
	);	
}

function show_matches() {

	
	$.post(baseurl+"includes/show_matches.php", {'test':'1'},
		function(data) {
			//alert(data);
			
			document.location=baseurl+'vacatures';

		}
	);	
}

function update_match() {

	
	$.post(baseurl+"includes/update_match.php", false,
		function(data) {
			calert('Uw zoekcriteria zijn opgeslagen');

		}
	);	
}

function login() {

	
	$.post(baseurl+"includes/login.php", $('#login_form').serialize(),
		function(data) {
			if(data=='success') {
				
				$('#loginblok').hide();
				calert("U bent succesvol ingelogd",refreshpage);
				
			} else {
				calert('De ingevoerde gegevens zijn niet bekend binnen het systeem.');
			}
		}
	);	
}

function refreshpage() {
	window.location = window.location;
}

function quicksearch() {
	$.post(baseurl+"includes/quick.php", $('#search_box').serialize(),
		function(data) {
			document.location=baseurl+'vacatures';;
		}
	);	
}



function load_recent(p) {
	
	if(p==null) {
		var p = 1;	
	}
	
	$.post(baseurl+"includes/recent.php", '&p='+p,
		function(data) {
			//alert(data);
			$('#recent').html(data);
		}
	);	
}

function load_results(p) {
	
	if(p==null) {
		var p = 1;	
	}
	
	$.post(baseurl+"includes/searchsmall.php", '&p='+p,
		function(data) {
			//alert(data);
			$('#gevonden').html(data);
		}
	);	
}

function calert(tekst, actie) {
	$('#calert span.calerttekst').html(tekst);
	$('#calert').show();
	$('#calert .btn_blue').click(function() {
		$('#calert').hide();
		if(typeof(actie)=='function') {
			actie();
		}
	});

}

