var lang = 1;
function poll_binder()
{
	
	$(".next_question").click(function(){
		//get the data
		var sel_data="0";
		$(".answer").each(function(){
			if($(this).attr("checked")){
				sel_data = $(this).attr("rel");
				}
			

			});
			
		$(".poll").html("<div class='ajax_loading'></div>");
		$.ajax({
						url:'http://www.degrootinternational.nl/include/poll.php',
						type:'POST',
						data:"qid=" + $(this).attr("qid") + "&data="+sel_data + "&lang=" + lang,
						dataType: 'html',
						complete: function(xhr){
							$(".ajax_loading").fadeOut(300,function(){							
							$(".poll").html(xhr.responseText);										
							poll_binder();
							});						
						},
						error: function(xhr){
							//alert('Error:'+xhr.statusText);
						}						
					});	
		
	});
	
	$(".prev_question").click(function(){
		$(".poll").html("<div class='ajax_loading'></div>");
		$.ajax({
						url:'http://www.degrootinternational.nl/include/poll.php',
						type:'POST',
						data:"qid=" + $(this).attr("qid") + "&lang=" + lang,
						dataType: 'html',
						complete: function(xhr){
							$(".ajax_loading").fadeOut(300,function(){														
							$(".poll").html(xhr.responseText);										
							poll_binder();		
							});				
						},
						error: function(xhr){
							//alert('Error:'+xhr.statusText);
						}						
					});	
		
	});
	
	$(".answer").click(function(){
		$(".next_question").fadeIn(200);
	});
	
	$(".poll_submit").click(function(){
		
		//get the vars
		var name = $("#poll_name").val();
		var mail = $("#poll_mail").val();
		if(name.length < 1 || mail.length < 1)
		{
			alert("Please fill in all fields!");
			return;
		}
		
		if(!checkemail(mail))
		{
			alert("This is not an valid email!");
			return;
		}
		
		var post = "name=" + name + "&mail=" + mail + "&dosend=1" + "&lang=" + lang; 
		
		
		$(".poll").html("<div class='ajax_loading'></div>");
		$.ajax({
						url:'http://www.degrootinternational.nl/include/poll.php',
						type:'POST',
						data:post,
						dataType: 'html',
						complete: function(xhr){
							$(".ajax_loading").fadeOut(300,function(){							
							$(".poll").html(xhr.responseText);										
							poll_binder();	
							});					
						},
						error: function(xhr){
							//alert('Error:'+xhr.statusText);
						}						
					});	
		
	});
	
	
	
	
}

function checkemail(str)
{

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{

testresults=false
}
return (testresults);
}


function start_binder()
{
	$(".start_question").click(function(){
		$(".poll").html("<div class='ajax_loading'></div>");
		$.ajax({
						url:'http://www.degrootinternational.nl/include/poll.php',
						type:'POST',
						data:"qid=" + $(this).attr("qid") + "&lang=" + lang,
						dataType: 'html',
						complete: function(xhr){
							$(".ajax_loading").fadeOut(300,function(){							
							$(".poll").html(xhr.responseText);										
							poll_binder();	
							});					
						},
						error: function(xhr){
							//alert('Error:'+xhr.statusText);
						}						
					});	
		
	});	
}

$(document).ready(function(){
	
	lang = $(".poll").attr("lang");
	$(".poll").html("<div class='ajax_loading'></div>");
	
		$.ajax({
						url:'http://www.degrootinternational.nl/include/poll.php',
						type:'POST',
						data:"qid=0&lang="+lang,
						dataType: 'html',
						complete: function(xhr){	
							$(".ajax_loading").fadeOut(300,function(){					
							$(".poll").html(xhr.responseText);										
							start_binder();	
							poll_binder();		
							});			
						},
						error: function(xhr){
							//alert('Error:'+xhr.statusText);
						}						
					});	
					
				
});

