var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
	}
}

function popUp(strURL,strName,strWidth,strHeight) {
larg=screen.width/2;
haut=screen.height/2;
test=haut-(haut/2);
closeWin();
var strOptions="";
strOptions="status,height="+strHeight+",width="+strWidth+",top="+test+",left="+(larg-larg/2);
newWin = window.open(strURL, strName, strOptions);
newWin.focus();
}

function popFen(strURL,strName) {
larg=screen.width;
haut=screen.height;
closeWin();
var strOptions="";
strOptions="height="+haut+",width="+larg+", resizable=yes,scrollbars=yes,location=yes,toolbar=yes,menubar =yes,directories =yes";
newWin = window.open(strURL, strName, strOptions);
newWin.focus();
}

function changeA(img)
{
		var centre = document.getElementById("listeImg");
		centre.innerHTML = '<img src="'+img+'" alt="Achat Maison 31100" width="371">';
}

function hide(id)
{
	if (document.getElementById(id).style.visibility=='hidden') return;
	document.getElementById(id).innerHTML = "";
	document.getElementById(id).style.visibility='hidden';
}

function enleve(id)
{
	switch (id)
	{
		case 1 : document.formContact.nom.style.background = '#FFFFFF'; break;
		case 2 : document.formContact.mail.style.background = '#FFFFFF'; break;
		case 3 : document.formContact.prenom.style.background = '#FFFFFF'; break;
		case 4 : document.formContact.mess.style.background = '#FFFFFF'; break;
		case 5 : document.formAmi.nom_visit.style.background = '#FFFFFF'; break;
		case 6 : document.formAmi.nom_ami.style.background = '#FFFFFF'; break;
		case 7 : document.formAmi.mail_ami.style.background = '#FFFFFF'; break;
		case 8 : document.formAmi.comments.style.background = '#FFFFFF'; break;
	}
}

function cache(id,snd)
{
	hide(id);
	hide(snd);
}

function verif_form_search()
{
	var erreur = true;
	
	if ((document.formRecherche.maison.checked != true)
		  &&(document.formRecherche.appart.checked != true)
		  &&(document.formRecherche.terrain.checked != true)
		  &&(document.formRecherche.parking.checked != true))
	{
		var notify_bien = document.getElementById("notify_bien");
		notify_bien.innerHTML = "Selectionnez un bien au moins";
		notify_bien.style.visibility='visible';
		erreur = false;
	}
	
	if (document.formRecherche.pieces_min.value != "")
	{
		for(i=0;i<document.formRecherche.pieces_min.value.length;++i)
		{
			if (document.formRecherche.pieces_min.value.charAt(i) < "0" ||document.formRecherche.pieces_min.value.charAt(i) > "9") 
			{ 
				var notify_pieces_min = document.getElementById("notify_pieces_min");
				notify_pieces_min.innerHTML = "Entrez un nombre de pièces ou rien";
				notify_pieces_min.style.visibility='visible';
				erreur = false;
			}
		}
	}
	
	if (document.formRecherche.chambres_min.value != "")
	{
		for(i=0;i<document.formRecherche.chambres_min.value.length;++i)
		{
			if (document.formRecherche.chambres_min.value.charAt(i) < "0" || document.formRecherche.chambres_min.value.charAt(i) > "9") 
			{
				var notify_chambres_min = document.getElementById("notify_chambres_min");
				notify_chambres_min.innerHTML = "Entrez un nombre de chambres ou rien";
				notify_chambres_min.style.visibility='visible';
				erreur = false;
			}
		}
	}
	
	var check_budget_min = 1;
	if (document.formRecherche.budget_min.value != "")
	{
		for(i=0;i<document.formRecherche.budget_min.value.length;++i)
		{
			if (document.formRecherche.budget_min.value.charAt(i) < "0" || document.formRecherche.budget_min.value.charAt(i) > "9") 
			{
				var notify_budget_min = document.getElementById("notify_budget_min");
				notify_budget_min.innerHTML = "Entrez un nombre de budget min. ou rien";
				notify_budget_min.style.visibility='visible';
				erreur = false;
				check_budget_min =-1;
			}
		}
	}
	
	var check_budget_max =1;
	if (document.formRecherche.budget_max.value != "")
	{
		for(i=0;i<document.formRecherche.budget_max.value.length;++i)
		{
			if (document.formRecherche.budget_max.value.charAt(i) < "0" || document.formRecherche.budget_max.value.charAt(i) > "9") 
			{
				var notify_budget_max = document.getElementById("notify_budget_max");
				notify_budget_max.innerHTML = "Entrez un nombre de budget max. ou rien";
				notify_budget_max.style.visibility='visible';
				erreur = false;
				check_budget_max =-1;
			}
		}
	}

	if (document.formRecherche.surface_terrain.value != "")
	{
		for(i=0;i<document.formRecherche.surface_terrain.value.length;++i)
		{
			if (document.formRecherche.surface_terrain.value.charAt(i) < "0" || document.formRecherche.surface_terrain.value.charAt(i) > "9") 
			{
				var notify_surface_terrain = document.getElementById("notify_surface_terrain");
				notify_surface_terrain.innerHTML = "Entrez un nombre de surface terrain ou rien";
				notify_surface_terrain.style.visibility='visible';
				erreur = false;
			}
		}
	}
	
	var check_surface_min =1;
	if (document.formRecherche.surface_min.value != "")
	{
		for(i=0;i<document.formRecherche.surface_min.value.length;++i)
		{
			if (document.formRecherche.surface_min.value.charAt(i) < "0" || document.formRecherche.surface_min.value.charAt(i) > "9") 
			{
				var notify_surface_min = document.getElementById("notify_surface_min");
				notify_surface_min.innerHTML = "Entrez un nombre de surface min. ou rien";
				notify_surface_min.style.visibility='visible';
				erreur = false;
				check_surface_min =-1;
			}
		}
	}
	
	var check_surface_max = 1;
	if (document.formRecherche.surface_max.value != "")
	{
		for(i=0;i<document.formRecherche.surface_max.value.length;++i)
		{
			if (document.formRecherche.surface_max.value.charAt(i) < "0" || document.formRecherche.surface_max.value.charAt(i) > "9") 
			{
				var notify_surface_max = document.getElementById("notify_surface_max");
				notify_surface_max.innerHTML = "Entrez un nombre de surface max. ou rien";
				notify_surface_max.style.visibility='visible';
				erreur = false;
				check_surface_max =-1;
			}
		}
	}
	
	if ((document.formRecherche.surface_max.value != "")&&(document.formRecherche.surface_min.value != ""))
	{
		if ((check_surface_max>0)&&(check_surface_min>0))
		{
			if ( parseInt(document.formRecherche.surface_max.value) < parseInt(document.formRecherche.surface_min.value) )
			{
				var notify_surface = document.getElementById("notify_surface");
				notify_surface.innerHTML = "Surface minimale > Surface maximale";
				notify_surface.style.visibility='visible';
				erreur = false;
			}
		}
	}
	
	if ((document.formRecherche.budget_max.value != "")&&(document.formRecherche.budget_min.value != ""))
	{
		if ((check_budget_max>0)&&(check_budget_min>0))
		{
			if ( parseInt(document.formRecherche.budget_max.value) < parseInt(document.formRecherche.budget_min.value) )
			{
				var notify_budget = document.getElementById("notify_budget");
				notify_budget.innerHTML = "Budget minimal > Budget maximal";
				notify_budget.style.visibility='visible';
				erreur = false;
			}
		}
	}
	
	if (document.formRecherche.dept_ville.value == "")
	{
		var notify_ville = document.getElementById("notify_ville");
		notify_ville.innerHTML = "Renseignez une ville, CP ou Departement";
		notify_ville.style.visibility='visible';
		erreur = false;
	}
	
	return erreur;
}

function verif_form_alerte()
{
	var erreur = true;
	
	if (document.formAlerte.email.value.indexOf('@') == -1)
	{
		var notify_mail = document.getElementById("notify_mail");
		notify_mail.innerHTML = "Ce n'est pas une adresse électronique!";
		notify_mail.style.visibility='visible';
		erreur = false;
	}
		
	return erreur;
}

function verif_form_contact()
{
	var erreur = true;
	
	if (document.formContact.mail.value == "")
	{
		document.formContact.mail.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formContact.mail.value.indexOf('@') == -1)
	{
		document.formContact.mail.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formContact.nom.value == "")
	{
		document.formContact.nom.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formContact.prenom.value == "")
	{
		document.formContact.prenom.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formContact.mess.value == "")
	{
		document.formContact.mess.style.background = '#FF8083';
		erreur = false;
	}
		
	return erreur;
}

function verif_form_ami()
{
	var erreur = true;
	
	if (document.formAmi.mail_ami.value == "")
	{
		document.formAmi.mail_ami.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formAmi.mail_ami.value.indexOf('@') == -1)
	{
		document.formAmi.mail_ami.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formAmi.nom_visit.value == "")
	{
		document.formAmi.nom_visit.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formAmi.nom_ami.value == "")
	{
		document.formAmi.nom_ami.style.background = '#FF8083';
		erreur = false;
	}
	
	if (document.formAmi.comments.value == "")
	{
		document.formAmi.comments.style.background = '#FF8083';
		erreur = false;
	}
		
	return erreur;
}
