/* Auteur: mazedia*/

$(document).ready(function() {
        
//selection dernier element dans actu
$(".boucleActu:last").addClass("last");

//jquery uniform
$("select, input:checkbox, input:radio, input:file").uniform();

//pour le menu principal mainav
$(".mainNav .n1").hide();

$(".mainNav h2").mouseover(function(){
	$(".mainNav .n1").hide();
	//$(".mainNav 23").removeClass("active");
	$(this).nextAll(".n1").show();
	$(this).addClass("active");
	$(".home .mainNav .n1").hide();
	
});

$(".mainNav .grid_3pseudo").mouseleave(function(){
	$(".mainNav .n1").hide();
	$(".mainNav h2").removeClass("active");
	$(".home .mainNav .n1").hide();
});

// valeur des input text
$("input:text").each(function ()
        {
            // store default value
            var v = this.value;

            $(this).blur(function ()
            {
            
                // if input is empty, reset value to default
                if (this.value.length == 0)
                {
                	 this.value = v;
               	}
            }).focus(function ()
            {
                // when input is focused, clear its contents

                if (this.getAttribute('readonly')!="readonly")
                this.value = "";
            });
        });
});


//newsletter
function checkEmail(str) {
	if (/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function checkNumeroTel(str) {
	if (/^0[1-9][0-9]{8}$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function checkCodePostal(str) {
	if (/^[0-9]{5}$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function checkNumero(str) {
	if (/^[0-9]+$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function isEmpty(str) {
	return (str == "")
}

function inscription_particulier(politness, lastname, firstname, email, birthday, address, postal_code, city, phone, status, other_status, company, cil, projects){
	$.post(	'/newsletter/register', 
			{ _type:'particulier', _politness:politness, _lastname:lastname, _firstname:firstname, _email:email, _birthday:birthday, _address:address, _postal_code:postal_code, _city:city, _phone:phone, _status:status, _other_status:other_status, _company:company, _cil:cil, _projects:projects },
			function(data){
	    	if(data.substr(0, 2) == 'OK') 
	    	{
	    		$('#formulaire_newsletter').submit();
	    		//alert("Votre inscription a bien été prise en compte, merci.");
	    	} 
	    	else 
	    	{
	    		alert("Un problème est survenue lors de votre inscription, veuillez vérifier les données de ce formulaire, merci.");
	    	}
	    }
	);	
	return false;	
}

function inscription_entreprise(company, company_number, politness, lastname, firstname, email, postal_code, city, phone, cil, cil_responsible, company_function, other_function, demands){
	$.post(	'/newsletter/register', 
			{ _type:'entreprise', _company:company, _company_number:company_number, _politness:politness, _lastname:lastname, _firstname:firstname, _email:email, _postal_code:postal_code, _city:city, _phone:phone, _cil:cil, _cil_responsible:cil_responsible, _company_function:company_function, _other_function:other_function, _demands:demands},
			function(data){
	    	if(data.substr(0, 2) == 'OK') 
	    	{
	    		$('#formulaire_newsletter').submit();
	    		//alert("Votre inscription a bien été prise en compte, merci.");
	    	} 
	    	else 
	    	{
	    		alert("Un problème est survenue lors de votre inscription, veuillez vérifier les données de ce formulaire, merci.");
	    	}
	    }
	);
	return false;	
}

