
$(document).ready(function() { 


});

function  moveon(px) {                         
        $('#header ul').stopTime('move');   
        $('#header ul').stopTime('remove');    
        $('#header ul').oneTime(0, 'move', function() {  
            $('#header ul').animate({backgroundPosition:"("+px+"px 0)"}, {duration:300});
        });      
}
function  moveout(px) {
        $('#header ul').oneTime(100, 'remove', function() {  
				    $('#header ul').animate({backgroundPosition:"("+px+"px 0)"}, {duration:500}); 
        });      
}

/* graphique ********************************************************************************************************************** */

function loadgraph() {
	var reg = /^[0-9\s]+$/    
    var caprevi	= $('#caprevi').val();
    var charges = $('#charges').val();
	if (reg.test(caprevi)  == false || reg.test(caprevi)  == false) alert('Veuillez n\'entrer que des chiffres ! Merci de corriger votre saisie.');
	else {
    	$('#chart').html('<div id="chart_div" style="height:260px; width:420px; text-align:center">&nbsp;<br /><br /><br /><br /><br /><br /><br /><br /><br /><img src="./img/loader.gif"></div>');
		$.ajax({
			type: "POST", url: 'lib/zinchart.php', 
			data:{ 'url':'lib/datas.php?caprevi='+caprevi+'&charges='+charges },
			success: function(msg){  $('#chart').html(msg); }
		});
	}
}   


/* functions bases ********************************************************************************************************************** */
 

function loadsondage(nb) { 
	$.ajax({
		type: "GET", url: './load.php?action=sondages&nb='+nb,
		success: function(msg){  $('#viewsondage'+nb).html(msg); }
	});
}

function repsondage(nb,rep) {
	$.ajax({
		type: "POST", url: './?load=sondages&nb='+nb,
		data:{ 'choix': rep },
		success: function(msg){  $('#viewsondage'+nb).html(msg); }
	});
}

function newsletter(mail) {      
    var mailtype = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;  
  	if (mailtype.test(mail) == false) $('#resultwebm').html('<span style="color:#C10000"> &nbsp; &nbsp; &nbsp; &nbsp; <b>Votre adresse <br> &nbsp; &nbsp; &nbsp; &nbsp; n\'est pas valide !</b></span>');      
    else {
      $.ajax({
					type: "POST", url: "/?newsletter=ok",
					data:({ 'newslmail' : mail }),
					success: function(msg){
  				      $('#resultwebm').html('<span style="color:#C10000"> &nbsp; &nbsp; &nbsp; &nbsp; <b>Votre inscription <br> &nbsp; &nbsp; &nbsp; &nbsp; a bien été prise en compte !</b></span>');
    	     }
		  });
		}
    setTimeout(function() { 
        $('#resultwebm').html('<input type="text" name="email" id="mailnewsletter" onclick="this.value =\'\'" value="Entrez votre email" /> <input type="submit" value="Valider" class="ok" onclick="newsletter($(\'#mailnewsletter\').val());">');
    },3000);
} 

function sendmail_contact() {  $('#resultmail').html('Envoie en cours....');      
    var mailtype = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;             
    var sender         = $('#sender').val();
    var sendermail     = $('#sendermail').val(); 
    var txtmail        = $('#txtmail').val(); 
    if (txtmail == '' || sendermail == '' || sender == '') { $('#resultmail').html('Veuillez remplir tous les champs'); }
    else if (mailtype.test(sendermail) == false ) { $('#resultmail').html('Votre adresse email est incorrecte.'); }
    else { 
  		$.ajax({
  					type: "POST", 
            url: './?sendmail_contact=ok',
            data:{ 'sender':sender, 'sendermail':sendermail, 'txtmail':txtmail },
  					success: function(msg){  $('#resultmail').html(msg); }
  		});
    }
}  


(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
 
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
