$('document').ready(function(){
    
});

$('#contact-form-site').live('submit',function(){
	if($('input[name="phone"]').val().length != 10){
		alert("Le numéro de telephone saisie est incorrect");	
	}else{
		var formData = $(this).serialize();
		
		$.post("/contact_submit.php",formData,function(rData){
			if (rData.ok == "ok"){
				$(".contact_site_right").html(rData.message);
			} else {
				alert(rData.message);
			}
		})
	}
	return false;
});

/* Formulaire contact des annonce*/
$("form#contact-annonce-form").live('submit',function(){
    if($('input[name="phone"]').val().length != 10){
		alert("Le numéro de telephone saisie est incorrect");	
	}else{
		var formData = $(this).serialize();
		
		$.post("/contact_submit_annonce.php",formData,function(rData){
			if (rData.ok == "ok"){
				$(".description-occasion").html(rData.mesage);
			} else {
				alert(rData.mesage);
			}
		})
	}
    return false;
});

/* Captcha annonce */
$('img#img_captcha').live('click',function(){
    var newImg = "/img.php?v=" + randomString();
    // alert(newImg);
    $(this).attr("src",newImg);
});


$('#divers').live('click', function () {
   $.ajax({
	url: "/page.php?app=article&id=32&print=1",
	dataType: "html",
	type: "GET",
	success: function (getData) {
	    var w = $(document).width();
	    var h = $(document).height();
	    var s1 = window.pageYOffset + 30;
	    
	    $('<div style="background-color: #000000;height:'+h+'px;left: 0;position: absolute;top: 0;width:'+w+'px;z-index: 90;opacity: 0.8;"></div>').appendTo('body');
	    $('<div style="position:absolute; top: '+s1+'px; left:0; width:'+w+'px;z-index: 100;background-color: #FFF;height:200px;"></div>').appendTo('body');
	}
   });
   return false;
});

$('ul.level0 li').live('mouseover',function(){
    $('ul.level1',this).show();
    // alert(t);
});
$('ul.level0 li').live('mouseout',function(){
    $('ul.level1',this).hide();
    // alert(t);
});

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

$('#captcha').live('click',function(){
    $(this).attr('src',"/img.php?v="+randomString());
});


$("#rechercheroccasion").live('click',function(){
	$('#rechercheoccasion').toggleClass("hidden");
	return false;
});

