jQuery(document).ready(function(){

	$('input').focusin(function(){
		p=$(this).offset();
		movearrow(p.top);
	});
	
	
	$('textarea').focusin(function(){
			p=$(this).offset();
			movearrow(p.top);
	});

	$('a').hover(function(){
			p=$(this).offset();
			movearrow(p.top);
	});
	
	function movearrow(y){
			q=y - $(document).scrollTop()-62;
			$('#arrowright').animate({	top:q		},300);
    }


      	
});

function subscribe(email,voornaam,achternaam){
	$.ajax({
	 	url: 'pages/sub.php?email='+escape(email)+'&voornaam='+escape(voornaam)+'&achternaam='+escape(achternaam),
  		success: function(data) {
	    	$('#newsletterform').html(data);
    	}
  	});
}

function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   return reg.test(address);
}


function validateme(){
	var email = document.forms['newsletter'].email.value;
	var voornaam  = document.forms['newsletter'].voornaam.value;
	var achternaam  = document.forms['newsletter'].achternaam.value;
	
	error='';
	if(email=='' || validate(email)==false || email=='Your email address'){		error += "Email address \n";	}
	if(voornaam=='' || voornaam=='Your first name'){							error += "First Name \n";				}
	if(achternaam=='' || achternaam=='Your last name'){							error += "Last Name \n";				}
	
	if(error==""){
		//document.forms['newsletter'].submit();
		subscribe(email,voornaam,achternaam);
	} else {
		alert("Vul aub de onderstaande velden juist in:\n Please enter the following field(s) correctly:\n\n"+error);
	}
}
