 $(document).ready(function(){
	
	var rInputs = new Array ();
	
	$("#formSol #contact-form").click(function () {
			if (checkFields($("#formSol input"))) {
				return true;
			}else{
				return false;
			}
	});
	
	function checkFields(form) {
			var error = 0;
			form.change(function () {
					if ($(this).val() == "" ||  $(this).val() == null) {
						error++;
						$(this).addClass("errorFields");
						$(this).removeClass("goodField");
					}else{
							if ($(this).hasClass('email')) {
									if (echeck($(this).val())) {
											$(this).removeClass("errorFields");
											$(this).addClass("goodField");
									}else{
											error++;
											$(this).addClass("errorFields");
											$(this).removeClass("goodField");
									}
							}else{
								$(this).removeClass("errorFields");
								$(this).addClass("goodField");
							}
					}
			});

			form.each(function (){

					if ($(this).val() == "" ||  $(this).val() == null) {
						error++;
						$(this).addClass("errorFields");
						$(this).removeClass("goodField");
					}else{
							if ($(this).hasClass('email')) {
									if (echeck($(this).val())) {
											$(this).removeClass("errorFields");
											$(this).addClass("goodField");
									}else{
											error++;
											$(this).addClass("errorFields");
											$(this).removeClass("goodField");
									}
							}else{
								$(this).removeClass("errorFields");
								$(this).addClass("goodField");
							}
					}
					
					
			})
			
			if (error > 0) {
				return false;
			}else{
				return true;
			}
					
	}
	

	
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true	;			
	}
	$('#zoekenVac').click(function () {
		window.location = "?&p=0&search="+$(this).parent().find('input').val();
	});
	$("#regio").change(function () { 
		window.location = "?&p=0&search="+$(this).val();
	});
	$("#opleiding").change(function () { 
		window.location = "?&p=0&search="+$(this).val();
	});
	$("#functie").change(function () { 
		window.location = "?&p=0&search="+$(this).val();
	});
	$("#sFields").click (function (){
			$("#searchHolder").slideToggle();
	});
		
 });

