function verifCommune(obj)
{
	$('#alertInscAnn').html('');
	if(obj.civil.options[obj.civil.selectedIndex].value == "")
	{
		txt = "Vous devez renseigner votre le champ civilit&eacute; !";
		afficheAlerte(txt);
		obj.civil.focus();
		return false;
	}
	if(obj.nom.value == "")
	{
		txt = "Vous devez renseigner votre nom !";
		afficheAlerte(txt);
		obj.nom.focus();
		return false;
	}
	if(obj.prenom.value == "")
	{
		txt = "Vous devez renseigner votre pr&eacute;nom !";
		afficheAlerte(txt);
		obj.prenom.focus();
		return false;
	}
	if(obj.adresse.value == "")
	{
		txt = "Vous devez renseigner votre adresse !";
		afficheAlerte(txt);
		obj.adresse.focus();
		return false;
	}
	if(obj.ville.value == "")
	{
		txt = "Vous devez renseigner votre ville !";
		afficheAlerte(txt);
		obj.ville.focus();
		return false;
	}
	if(obj.cp.value == "")
	{
		txt = "Vous devez renseigner le code postal de votre ville !";
		afficheAlerte(txt);
		obj.cp.focus();
		return false;
	}
	return verifMail(obj);
}
function verifMail(obj)
{
	indice = 0;
	if(obj.email.value == "")
	{
		txt = "Vous devez renseigner votre adresse email !";
		afficheAlerte(txt);
		obj.email.focus();
		return false;
	}
	if(obj.email.value.indexOf("@") == "-1" || obj.email.value.indexOf(".") == "-1")
	{
		txt = "Votre adresse email n'est pas valide !";
		afficheAlerte(txt);
		obj.email.value = '';
		obj.email.focus();
		return false;
	}
	return true;
}
function verifInscAnnonceur(obj)
{
	if(verifCommune(obj))
	{
		if(obj.pass.value.length < 6)
		{
			txt = "Votre mot de passe n'est pas valide !";
			afficheAlerte(txt);
			obj.pass.value = '';
			obj.pass.focus();
			return false;
		}
		if(obj.pass.value != obj.passb.value)
		{
			txt = "Erreur lors de la saisie du mot de passe !";
			afficheAlerte(txt);
			obj.pass.value = '';
			obj.passb.value = '';
			obj.pass.focus();
			return false;
		}
		if(obj.codeCap.value == "")
		{
			txt = "Vous devez recopier le code affich&eacute; !";
			afficheAlerte(txt);
			obj.codeCap.focus();
			return false;
		}
		if(obj.email.value.indexOf("@") != "-1" && obj.email.value.indexOf(".") != "-1" && obj.email.value != '')
		{
			if(obj.annonceur)
			ann = obj.annonceur.value;
			else
			ann = '';
			$.ajax({
		  	type : 'POST', 
			url : "moduleParamAnnonces/client/moteur.php5" ,
			data : 'verifMailModANN='+obj.email.value+'&ann='+ann ,
			success : function(data){ 
			if(parseInt(data) > 0)
			{
				txt = "Cette adresse email existe d&eacute;j&agrave; pour un autre annonceur !!";
				afficheAlerte(txt);
				return false;
			}
			else
			return true;
			}
	      });
	      
		}
	}
	else
	return false;
}
function verifModCivilAnn(obj)
{
	if(verifCommune(obj))
	{
		if(obj.email.value.indexOf("@") != "-1" && obj.email.value.indexOf(".") != "-1" && obj.email.value != '')
		{
			if(obj.annonceur)
			ann = obj.annonceur.value;
			else
			ann = '';
			$.ajax({
		  	type : 'POST', 
			url : "moduleParamAnnonces/client/moteur.php5" ,
			data : 'verifMailModANN='+obj.email.value+'&ann='+ann ,
			success : function(data){ 
			if(parseInt(data) > 0)
			{
				txt = "Cette adresse email existe d&eacute;j&agrave; pour un autre annonceur !!";
				afficheAlerte(txt);
				return false;
			}
			else
			return true;
			}
	      });
	      
		}
		else
		return false;
	}
	else
	return false;
}
function afficheAlerte(txt)
{
	$('#alertInscAnn').html(txt).hide().fadeIn('slow');
}
function retourneHauteur()
{
	var scrollH = 0;	// scrollY
	var windowH = 0;	// largeur de la fenêtre
	if (document.doctype == null || document.documentElement.clientHeight == 0)
	{
		if (window.innerWidth || (document.body.offsetHeight == document.documentElement.offsetHeight))
		{
			scrollH = document.body.scrollTop;
			windowH = document.body.clientHeight;
		}
		else
		{
			scrollH = document.documentElement.scrollTop;
			windowH = document.documentElement.clientHeight;
		}

	}
	else
	{
		if (document.doctype.publicId.search(/xhtml/i) != -1)
		scrollH = document.documentElement.scrollTop;
		else
		scrollH = document.body.scrollTop;
	}
	if (window.innerHeight)
	windowH = window.innerHeight;
	return windowH+scrollH;
}
function fenetreImage(obj)
{
	var table = $(obj).attr("rel").split('|');
	var large = parseFloat(table[1]) + 10;
	var longue = parseFloat(table[2]) + 10;
	creationFondSombre();
	$('body').append('<div id = "boxlo" style = "display:none;"></div>');
	$('#boxlo').css('width',large+'px');
	$('#boxlo').css('height',longue+'px');
	$('#boxlo').css('backgroundColor','#000000');
	$('#boxlo').css('padding','5px');
	$('#boxlo').css("position","absolute");
	$('#boxlo').css("top", ( $(window).height() - $('#boxlo').height() ) / 2+$(window).scrollTop() + "px");
	$('#boxlo').css("left", ( $(window).width() - $('#boxlo').width() ) / 2+$(window).scrollLeft() + "px");
	$('#boxlo').css("zIndex","3000");
	$('#boxlo').css("textAlign","center");
	$('#boxlo').hide();
	$('#boxlo').html('<img src = "'+table[0]+'" />');
	$('#boxlo').append('<div id = "fermetureBoxLo"></div>');
	$('#fermetureBoxLo').css("width","30px");
	$('#fermetureBoxLo').css("height","30px");
	$('#fermetureBoxLo').css("float","right");
	$('#fermetureBoxLo').css("margin-right","-17px");
	$('#fermetureBoxLo').css("margin-bottom","-17px");
	$('#fermetureBoxLo').css("cursor","pointer");
	$('#fermetureBoxLo').css("color","#ffffff");
	$('#fermetureBoxLo').html('<img src = "images/close.png" />');
	$('#fermetureBoxLo').click(function(){supprimeModaleImage();})
	$('#boxlo').animate({
    width: ['toggle', 'swing'],
    height: ['toggle', 'swing'],
    opacity: 'toggle'
  }, 500, 'swing');
}
function supprimeModaleImage()
{
	$('#boxlo').fadeOut('slow',function(){
	$('#lefondmodal').fadeOut('slow').remove();
	$('#boxlo').remove();
	});
	
}
function verifContactAnnonceur(f)
{
	f.nom.style.backgroundColor = "#ffffff";
	f.prenom.style.backgroundColor = "#ffffff";
	f.email.style.backgroundColor = "#ffffff";
	f.mess.style.backgroundColor = "#ffffff";
	if(f.nom.value == '')
	{
		f.nom.style.backgroundColor = "red";
		f.nom.focus();
		return false;
	}
	if(f.prenom.value == '')
	{
		f.prenom.style.backgroundColor = "red";
		f.prenom.focus();
		return false;
	}
	if(f.email.value == '')
	{
		f.email.style.backgroundColor = "red";
		f.email.focus();
		return false;
	}
	if(f.email.value.indexOf("@") == "-1" || f.email.value.indexOf(".") == "-1")
	{
		f.email.value = '';
		f.email.style.backgroundColor = "red";
		f.email.focus();
		return false;
	}
	if(f.mess.value == '')
	{
		f.mess.style.backgroundColor = "red";
		f.mess.focus();
		return false;
	}
	return true;
}
function creationFondSombre()
{
	hauteur = retourneHauteur();
	hauteur += 400;
	$('body').append('<div id = "lefondmodal"></div>');
	$('#lefondmodal').css("backgroundColor","#000000");
	$('#lefondmodal').css("position","absolute");
	$('#lefondmodal').css("zIndex","2000");
	$('#lefondmodal').css("top","0px");
	$('#lefondmodal').css("left","0px");
	$('#lefondmodal').css("bottom","0px");
	$('#lefondmodal').css("right","0px");
	$('#lefondmodal').css("width","100%");
	$('#lefondmodal').css("height",hauteur+"px");
	$('#lefondmodal').hide();
	$('#lefondmodal').fadeOut("fast").fadeTo("slow", 0.7);
	$('#lefondmodal').click(function(){supprimeModaleImage();})
}
function merci(chaine)
{
	creationFondSombre();
	$('body').append('<div id = "boxlo" style = "display:none;"></div>');
	$('#boxlo').css('width','530px');
	if(chaine.indexOf("verifContactAnnonceur") == -1)
	$('#boxlo').css('height','280px');
	else
	$('#boxlo').css('height','475px');
	$('#boxlo').css('backgroundColor','#ffffff');
	$('#boxlo').css('padding','15px');
	$('#boxlo').css("position","absolute");
	$('#boxlo').css("top", ( $(window).height() - $('#boxlo').height() ) / 2+$(window).scrollTop() + "px");
	$('#boxlo').css("left", ( $(window).width() - $('#boxlo').width() ) / 2+$(window).scrollLeft() + "px");
	$('#boxlo').css("zIndex","3000");
	$('#boxlo').css("textAlign","left");
	$('#boxlo').hide();
	$('#boxlo').html(chaine);
	$('#boxlo').animate({
    width: ['toggle', 'swing'],
    height: ['toggle', 'swing'],
    opacity: 'toggle'
  }, 500, 'swing');
}
function verifNombre(obj)
{
	$('#alertInscAnn').html('');
	nb = obj.value.replace(',','.');
	obj.value = nb;
	if(isNaN(obj.value))
	{
		obj.value = "";
		obj.focus();
		txt = "Seulement des valeurs num&eacute;riques !!";
		afficheAlerte(txt);
	}
}
function analyseType(obj)
{
	if(obj.value != '0' && obj.value.indexOf("-") != "-1")
	{
		var t = obj.value.split('-');
		if(t[1] == '1')
		$('#periodePaiement').css('display','inline');
		else
		$('#periodePaiement').css('display','none');
	}
	else
	$('#periodePaiement').css('display','none');
}
function verifAnnGratos(obj)
{
	$('#alertInscAnn').html('');
	if(obj.nom.value == '')
	{
		obj.nom.focus();
		txt = "Vous devez donner un nom ou titre &agrave; votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.typeb.value == '0')
	{
		obj.typeb.focus();
		txt = "Vous devez choisir un \"type de bien\" pour votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.typet.value == '0')
	{
		obj.typet.focus();
		txt = "Vous devez choisir un \"type de transaction\" pour votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.typel.value == '0')
	{
		obj.typel.focus();
		txt = "Vous devez choisir un \"type de lieu\" pour votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.ville.value == '')
	{
		obj.ville.focus();
		txt = "Vous devez renseigner la ville pour votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.cp.value == '')
	{
		obj.cp.focus();
		txt = "Vous devez renseigner le code postal de votre annonce !!";
		afficheAlerte(txt);
		return false;
	}
	if(obj.image.value.length > 0)
	{
		tabExt = obj.image.value.split('.');
		var ind = tabExt.length - 1;
		var ext = tabExt[ind].toLowerCase();
		if(ext != 'jpg' && ext != 'jpeg' && ext != 'gif' && ext != 'png')
		{
			obj.image.value = '';
			obj.image.focus();
			txt = "Votre image n'a pas une extension valide !!";
			afficheAlerte(txt);
			return false;
		}
		
	}
	return true;
}
function verifImage(obj)
{
	if(obj.value.length > 0)
	{
		tabExt = obj.value.split('.');
		var ind = tabExt.length - 1;
		var ext = tabExt[ind].toLowerCase();
		if(ext != 'jpg' && ext != 'jpeg' && ext != 'gif' && ext != 'png')
		{
			obj.value = '';
			obj.focus();
			txt = "Votre image n'a pas une extension valide !!";
			afficheAlerte(txt);
		}
	}
}
function verifPassEtLog(f)
{
	if(f.ancienP.value == "")
	{
		f.ancienP.focus();
		txt = "Vous devez renseigner votre ancien mot de passe !!";
		afficheAlerte(txt);
		return false;
	}
	if(f.email.value.indexOf("@") == "-1" || f.email.value.indexOf(".") == "-1" || f.email.value == '')
	{
		f.email.focus();
		txt = "Votre adresse email n'est pas valide !!";
		afficheAlerte(txt);
		return false;
	}
	if(f.passA.value != "")
	{
		if(f.passA.value.length < 6)
		{
			f.passA.value = ""
			f.passB.value = ""
			f.passA.focus();
			txt = "Votre nouveau mot de passe n'est pas valide !!";
			afficheAlerte(txt);
			return false;
		}
		if(f.passA.value != f.passB.value)
		{
			f.passB.value = ""
			f.passB.focus();
			txt = "Vous n'avez pas saisi le m&ecirc;me mot de passe !!";
			afficheAlerte(txt);
			return false;
		}
	}
	return true;
}
var timerLog = null;
var timerPass = null;
function clickConnectionLog(obj)
{
	if(obj.value == "email")
	obj.value = "";
	timerLog = setTimeout("remiseDefautLog(\"l\");",5000);
}
function clickConnectionPass(obj)
{
	if(obj.value.length == 4)
	obj.value = "";
	timerLog = setTimeout("remiseDefautLog(\"p\");",5000);
}
function remiseDefautLog(obj)
{
	chemin = document.fConnectionAnn;
	if(obj == "l")
	{
		if(chemin.login.value == '')
		chemin.login.value = "email";
		if(timerLog != null)
		clearTimeout(timerLog);
	}
	else
	{
		if(chemin.pass.value == '')
		chemin.pass.value = "pass";
		if(timerPass != null)
		clearTimeout(timerPass);
	}
}
