// Anti-mail non prévu
function NoMail( s1, s2 )
{
	document.write( s2 + s1 );
}

// Vérifie que le champ de formulaire "s" n'est pas vide, affiche un message d'erreur et renvoie true ou false
// Note : si le champ n'existe pas, renvoie automatiquement true
function checkNotEmpty( s, msg )
{
	if( document.getElementById( s ) && document.getElementById( s ).value == "" )
	{
		alert( msg );
		return false;
	}
	return true;
}

// Vérifie que le champ de formulaire "s" contient un entier, affiche un message d'erreur et renvoie true ou false
// Note : si le champ n'existe pas, renvoie automatiquement true
function checkInt( s, msg )
{
	if( document.getElementById( s ) && isNaN( document.getElementById( s ).value ) )
	{
		alert( msg );
		return false;
	}
	return true;
}

// Vérifie que la dropdownlist "s" a une valeur sélectionnée non nulle, affiche un message d'erreur et renvoie true ou false
// Note : si le champ n'existe pas, renvoie automatiquement true
function checkSelected( s, msg )
{
	if( document.getElementById( s ) && document.getElementById( s ).selectedIndex == 0 )
	{
		alert( msg );
		return false;
	}
	return true;
}

// Vérifie que la liste "s" a au moins une valeur sélectionnée, affiche un message d'erreur et renvoie true ou false
// Note : si le champ n'existe pas, renvoie automatiquement true
function checkOneItemSelected( s, msg )
{
	if( !document.getElementById( s ) )
		return true;

	var selected=false;
	with( document.getElementById( s ) )
		for( var i=0; i < length; i++ )
			if( options[ i ].selected )
			{
				selected=true;
				break;
			}
	if( !selected )
	{
		alert( msg );
		return false;
	}
	return true;
}

// Validation de la recherche simple
function SearchFrmSubmit()
{
	if(document.getElementById("SearchTxt").value=="")
	{
		alert( SearchFrmSubmitAlert );
		return false;
	}
	return true;
}

// Validation du formulaire de login
function LoginFrmSubmit()
{
	if(document.getElementById("LoginTxt").value==""||document.getElementById("PwdTxt").value=="")
	{
		alert( LoginFrmSubmitAlert);
		return false;
	}
	return true;
}

// Clic sur "Déconnexion"
function NavLogoutClick()
{
	if(confirm( NavLogoutClickConfirm ))
		return true;
	else	
		return false;
}

// Notification d'envoi de mail
function MailSent()
{
	alert( MailSentAlert );
	window.close();
}

// Suppression d'une Recherche Avancée
function DeleteAdvSearch()
{
	return confirm( NavDeleteConfirm );
}

// Validation du formulaire "mes coordonnées"
function MyAccountFrmSubmit()
{
	// Vérifie que les champs obligatoires sont présents

	if(!checkNotEmpty( GetFormField( "LastName" ), LastNameCheckAlert))
		return false;
	if(!checkNotEmpty( GetFormField( "FirstName" ), FirstNameCheckAlert))
		return false;
	if(!checkNotEmpty( GetFormField( "Email" ), EmailCheckAlert))
		return false;

	return true;
}

// Impression d'un Bien
function PrintGood()
{
	print();
}

// Impression d'une Actu
function PrintNews()
{
	print();
}

// Découpe le nom d'un champ "à la ASP.NET"
function GetFormField( s )
{
	// Tags input
	var tags = document.getElementsByTagName( "INPUT" );

	for( var i=0; i<tags.length; i++ )
		if( tags[ i ].name.lastIndexOf( s ) > -1 )
			return tags[ i ].id;

	// Tags textarea
	tags = document.getElementsByTagName( "TEXTAREA" );

	for( var i=0; i<tags.length; i++ )
		if( tags[ i ].name.lastIndexOf( s ) > -1 )
			return tags[ i ].id;

	// Tags select
	tags = document.getElementsByTagName( "SELECT" );

	for( var i=0; i<tags.length; i++ )
		if( tags[ i ].name.lastIndexOf( s ) > -1 )
			return tags[ i ].id;
}

// Inutile
/*
function SwitchVisible( id, imgf, imgu )
{
	if( document.getElementById( "n" + id ) )
	{
		if( document.getElementById( "n" + id ).style.display == "none" )
		{
			document.getElementById( "n" + id ).style.display = "block";
			document.getElementById( "img" + id ).src = imgu;
		}
		else
		{
			document.getElementById( "n" + id ).style.display = "none";
			document.getElementById( "img" + id ).src = imgf;
		}
	}
}
*/

/* Fonctions qui peuvent être réécrites par site */

// Validation du formulaire "Recherche Avancée"
function AdvSearchFrmSubmit()
{
	// Vérifie que les champs obligatoires sont présents

	/*if(!checkSelected("GoodType", GoodTypeCheckAlert))
		return false;
	if(!checkSelected("SectorId", SectorIdCheckAlert))
		return false;*/

	if(document.getElementById("SaveAdvSearch"))
		if(document.getElementById("SaveAdvSearch").checked && !checkNotEmpty("AdvSearchName", AdvSearchNameCheckAlert))
			return false;

	// Vérifie que les valeurs sont bien numériques

	if(!checkInt("PriceMin", PriceMinCheckAlert))
		return false;
	if(!checkInt("PriceMax", PriceMaxCheckAlert))
		return false;
	if(!checkInt("SurfaceMin", SurfaceMinCheckAlert))
		return false;
	if(!checkInt("SurfaceMax", SurfaceMaxCheckAlert))
		return false;

	return true;
}

// Validation du formulaire "Faire une Demande"
function MakeRequestFrmSubmit()
{
	// Vérifie que les champs obligatoires sont présents

	if(!checkNotEmpty("LastName", LastNameCheckAlert))
		return false;
	if(!checkNotEmpty("FirstName", FirstNameCheckAlert))
		return false;
	if(!checkNotEmpty("Email", EmailCheckAlert))
		return false;
	if(!checkSelected("GoodType", GoodTypeCheckAlert))
		return false;
	if(!checkOneItemSelected("SectorIdList", SectorIdListCheckAlert))
		return false;

	// Vérifie que les valeurs sont bien numériques

	if(!checkInt("Price", PriceCheckAlert))
		return false;
	if(!checkInt("Rooms", RoomsCheckAlert))
		return false;

	return true;
}

// Validation du formulaire "Proposer un Bien à la vente"
function ProposeOfferFrmSubmit()
{
	// Vérifie que les champs obligatoires sont présents

	if(!checkNotEmpty("LastName", LastNameCheckAlert))
		return false;
	if(!checkNotEmpty("FirstName", FirstNameCheckAlert))
		return false;
	if(!checkNotEmpty("Email", EmailCheckAlert))
		return false;
	if(!checkSelected("GoodType", GoodTypeCheckAlert))
		return false;
	if(!checkSelected("SectorId", SectorIdCheckAlert))
		return false;

	// Vérifie que les valeurs sont bien numériques

	if(!checkInt("Price", PriceCheckAlert))
		return false;
	if(!checkInt("LiveSurface", LiveSurfaceCheckAlert))
		return false;
	if(!checkInt("GroundSurface", GroundSurfaceCheckAlert))
		return false;
	if(!checkInt("Rooms", RoomsCheckAlert))
		return false;

	return true;
}