function couleur(obj) {
     obj.style.backgroundColor = "#FFFFFF";
}

function emailcheck(mail)

{
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(reg.test(mail))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function check() {
	var erreur = true;
	if (contactform.last_name.value == "")	{
		contactform.last_name.style.backgroundColor = "#F3C200";
		erreur = false;
	} else couleur(contactform.last_name);
	
	if (contactform.first_name.value == "")	{
		contactform.first_name.style.backgroundColor = "#F3C200";
		erreur = false;
	} else couleur(contactform.first_name);
	
	var email = contactform.email.value
	if (email == "" || !emailcheck(email))	{
		contactform.email.style.backgroundColor = "#F3C200";
		erreur = false;
	} else couleur(contactform.email);
	
	if (contactform.description.value == "")	{
		contactform.description.style.backgroundColor = "#F3C200";
		erreur = false;
	} else couleur(contactform.description);
 
	if (erreur) return(true);
	else	{
		return(false);
	}
}

    function choice(question,checkbox, value){
     
        var box = document.getElementById(question+'-'+value);
        var pageid = document.getElementById('pageid').value;
        var version = document.getElementById('version').value;
        $.ajax({
            url: '/feedback',
            data: "name="+box.name+"&value="+value+"&pageid="+pageid+"&version="+version,
            type: "POST",
            success: function(data) {
                $('#'+checkbox).html(data);
                if(value=='yes'){
                    showstuff('hidden-questions');} else {
                         showstuff('hidden-textarea');}
                    }
              });
    }

     function submitComment(){
          var pageid = document.getElementById('pageid').value;
          var version = document.getElementById('version').value;
          var comment = document.getElementById('helpful-input').value;
          var mail = document.getElementById('mail').value;
          $.ajax({
            url: '/feedback',
            data: "pageid="+pageid+"&version="+version+"&comment="+comment+"&email="+mail,
            type: "POST",
            success: function(data) {
                $('#feedback-wrapper').html('Thank you, we will do our best to improve this document !');
            }
          });
     }
     
    function showstuff(boxid){
        document.getElementById(boxid).style.visibility="visible";
        document.getElementById(boxid).style.height="auto";
    }