function formRedirect(url, nextState, param) {
	document.SwissimoForm.action = url;
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	document.SwissimoForm.submit();
}

function formRedirectWithCheck(url, nextState, param) {
	document.SwissimoForm.action = url;
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	if (genericCheckForm(document.SwissimoForm)) {document.SwissimoForm.submit();}
}

function formSubmit(nextState, param){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	document.SwissimoForm.submit();
}

function formSubmitWithOffersState(nextState, param, offers_state){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	document.SwissimoForm.offers_state.value = offers_state;
	document.SwissimoForm.submit();
}

function formSubmitWithCheck(nextState, param){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	if (genericCheckForm(document.SwissimoForm)) {
		document.SwissimoForm.submit();}
}

function formSubmitWithCheck(nextState, param){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	if (genericCheckForm(document.SwissimoForm)) {
		document.SwissimoForm.submit();}
}

function formSubmitWithJeSuisInteresseCheck(nextState, param){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
	if (genericCheckForm(document.SwissimoForm)) {
		if (document.SwissimoForm.contact_portable.checked && document.SwissimoForm.CHK_TX_portable.value.length==0) {
			alert("Si vous cochez la case 'Portable', il est nécessaire d'indiquer un numéro de portable.")
		}
		else if (document.SwissimoForm.contact_tel.checked && document.SwissimoForm.CHK_TX_telephone.value.length==0) {
			alert("Si vous cochez la case 'Téléphone', il est nécessaire d'indiquer un numéro de téléphone.")
		} 
		else if (document.SwissimoForm.contact_fax.checked && document.SwissimoForm.CHK_TX_fax.value.length==0) {
			alert("Si vous cochez la case 'Fax', il est nécessaire d'indiquer un numéro de fax.")
		} 
		else if ((!document.SwissimoForm.contact_fax.checked) && (!document.SwissimoForm.contact_tel.checked) && 
						 (!document.SwissimoForm.contact_portable.checked) && (!document.SwissimoForm.contact_email.checked)) {
						 alert("Veuillez cocher au moins un moyen de communication parmi téléphone, fax, portable et e-mail.")
		}
		else {		
			document.SwissimoForm.submit();
		}
	}
}

function formSubmitSwisscaution(nextState, param, id,swc,root_url){
	document.SwissimoForm.nextState.value = nextState;
	document.SwissimoForm.param.value = param;
		if (document.SwissimoForm.MAN_TX_SwisscautionNom1.value.length==0) {
			alert("Veuillez indiquer votre Nom.");
			document.SwissimoForm.MAN_TX_SwisscautionNom1.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionPrenom1.value.length==0) {
			alert("Veuillez indiquer votre Prénom.");
			document.SwissimoForm.MAN_TX_SwisscautionPrenom1.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionNaissance1.value.length==0) {
			alert("Veuillez indiquer votre date de naissance.");
			document.SwissimoForm.MAN_TX_SwisscautionNaissance1.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionNationalite1.value.length==0) {
			alert("Veuillez indiquer votre nationalité.");
			document.SwissimoForm.MAN_TX_SwisscautionNationalite1.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionNPA.value.length==0) {
			alert("Veuillez indiquer le NPA de votre ville.");
			document.SwissimoForm.MAN_TX_SwisscautionNPA.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionVille.value.length==0) {
			alert("Veuillez indiquer votre ville.");
			document.SwissimoForm.MAN_TX_SwisscautionVille.focus();
		}
		else if (document.SwissimoForm.MAN_TX_SwisscautionTelPrive.value.length==0) {
			alert("Veuillez indiquer votre numéro de téléphone privé.");
			document.SwissimoForm.MAN_TX_SwisscautionTelPrive.focus();
		}
		else {		
			document.SwissimoForm.submit();
			window.open(root_url + '/si_popup_swisscaution.php','popup','width=300,height=200,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no');
			formRedirect('/Accueil/offre_immobiliere/location/index.php?Page_ID=3209','FRM_SEARCH','&locvente_id=' + id + '&mailswc=' + swc);
		}
}

function EnvoiAmiNotLoggedMail(){
	var emailExp = document.SwissimoForm.EmailExp.value;
}

function EnvoiAmiNotLoggedIdentite(){
	var expIdentite = document.SwissimoForm.EmailExp.value;
}

function emptyCombo(comboName) {
	document.SwissimoForm.elements[comboName].value = '';
}

function formSubmitWithUserConfirmation(next_state, param, message){
	var verify = false;
	verify = confirm (message);
	if (verify){
		formSubmit(next_state, param);
	} /* if (verify) */
}
var error_type

var err_mandatory = "Champ obligatoire"
var err_bad_char = "Caractère interdit dans la zone"
var err_several_dots = "Plusieurs points dans la zone"
var err_no_digits = "Pas de chiffres"

// var err_mandatory = "Champ obligatoire"
// var err_empty = "Zone vide"
// var err_bad_char = "Caractère interdit dans la zone"
// var err_several_dots = "Plusieurs points dans la zone"
// var err_no_digits = "Pas de chiffres"

var err_wrong_long = "N'utiliser que des chiffres"
var err_wrong_real = "N'utiliser que des chiffres et un point (.)"
var err_wrong_date = "Entrer une date valide au format JJ-MM-AAAA"
var err_wrong_text = "Champ incorrect"
var err_wrong_pass = "5 caractères au minimum"
var err_wrong_alph = "Saisie uniquement alphanumérique"
var err_wrong_mail = "Format e-mail incorrect"

var err_wrong_year	= "l'année doit avoir 4 chiffres"
// var err_wrong_long = "Entier non valide"
// var err_wrong_real = "Réel non valide"
// var err_wrong_date = "Date non valide"
// var err_wrong_text = "Champ incorrect"

var help_long = "Erreur Entier :"
var help_real = "Erreur Décimal :"
var help_date = "Erreur Date : "
var help_text = "Erreur Texte : "
var help_pass = "Erreur Mot de passe : "
var help_mail = "Erreur e-mail : "
var help_year = "Erreur sur l'année :"

// var help_long = "N'utiliser que des chiffres"
// var help_real = "N'utiliser que des chiffres et un point (.)"
// var help_date = "Entrer une date valide au format jj-mm-yyyy"
// var help_text = "Entrer du texte"

function genericDescription(eltName, nameStart)
{
// Return a string describing the element (from the name)
var eltDesc = ""
eltDesc = eltName.substring(nameStart, eltName.length)

while ((indChar = eltDesc.indexOf("_")) > -1)
{
		// Remove object id from description
		if (genericCheckLong(eltDesc.substring(indChar+1, eltDesc.length)))
		{
			eltDesc = eltDesc.substring(0, indChar)
		}
		else
		{
			eltDesc = eltDesc.substring(0, indChar) + " " + eltDesc.substring(indChar+1, eltDesc.length)
		}
}

return eltDesc
}

function genericCheckText(eltValue,elementtype)
{
//si le type de l'élément est facultatif, on ne vérifie pas la non-existence

if ((elementtype == "MAN") && (eltValue == null || eltValue == "" || eltValue.length == 0))
{
		// Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
}

if (isAlphaNum(eltValue))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_alph
		return false
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckPass(eltValue,elementtype)
{
//si le type de l'élément est facultatif, on ne vérifie pas la non-existence

if ((elementtype == "MAN") && (eltValue == null || eltValue == "" || eltValue.length == 0 ))
{
		// Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
}

else if ((elementtype == "MAN") && (eltValue.length < 5 ) || (elementtype == "CHK") && (eltValue.length > 0 ) && (eltValue.length < 5 )){

		// Le mot de passe contient moins de 5 caractères
		error_type = err_wrong_pass
		return false
		}

//else if (elementtype == "CHK")
	//		{// Le champ est vide mais il n'est pas obligatoire
	//	return true
			//}

if (isAlphaNum(eltValue))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_alph
		return false
}


// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckLong(eltValue,elementtype)
{
if ((eltValue == null) || (eltValue == "") || (eltValue.length == 0))
{
		if (elementtype == "MAN")
			{
			 // Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
			}
		else if (elementtype == "CHK")
			{// Le champ est vide mais il n'est pas obligatoire
		return true
			}
}

if (!isInteger(eltValue))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_long
		return false
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}


function genericCheckYear(eltValue,elementtype)
{
if ((eltValue == null) || (eltValue == "") || (eltValue.length == 0))
{
		if (elementtype == "MAN")
			{
			 // Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
			}
		else if (elementtype == "CHK")
			{// Le champ est vide mais il n'est pas obligatoire
		return true
			}
}

if ( (!isInteger(eltValue)) || (eltValue > 2100) || (eltValue < 1000) || (eltValue.length != 4))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_year
		return false
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}


function genericCheckReal(eltValue,elementtype)
{
if (eltValue == null || eltValue == "" || eltValue.length == 0)
{
		if (elementtype == "MAN")
			{
			 // Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
			}
		else if (elementtype == "CHK")
			{// Le champ est vide mais il n'est pas obligatoire
		return true
			}
}

if (!isDecimal(eltValue))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_real
		return false
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckDate(eltValue,elementtype)
{
if (eltValue == null || eltValue == "" || eltValue.length == 0)
{
		if (elementtype == "MAN")
			{
			 // Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
			}
		else if (elementtype == "CHK")
			{// Le champ est vide mais il n'est pas obligatoire
		return true
			}
}
if (eltValue.length == 10)
	{if (!isDate(eltValue.substring(6,10),eltValue.substring(3,5),eltValue.substring(0,2)))
	{
	// Pas de bon caracteres : Erreur !!!!
	error_type = err_wrong_date
	return false
	}
	}
 else
	{
	// Pas de bon caracteres : Erreur !!!!
	error_type = err_wrong_date
	return false
	}


// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckElement(eltObj)
{

//L'élément peut être obligatoire (mandatory, man) ou facultatif (chk)
var elementtype = "MAN";

// On test l'element de la forme si son Name commence par CHK_
eltName = eltObj.name



if (eltName.length > 0)
{
		if ((eltName.indexOf("CHK_", 0) == 0) || (eltName.indexOf("MAN_", 0) == 0))
		{
	if (eltName.indexOf("CHK_", 0) == 0)
		{var elementtype = "CHK";
		}

	// Element a verifier
	// On teste le type de l'element
	if (eltName.substring(4, 7) == "TX_")
	{
			// Texte Type
			if (genericCheckText(eltObj.value,elementtype) == false)
			{
		alert (help_text + "\n" + error_type + "\n")
		return false
			}
			else return true
	}
	if (eltName.substring(4, 7) == "LG_")
	{
			// Long Type
			if (genericCheckLong(eltObj.value,elementtype) == false)
			{
			 alert (help_long + "\n" + error_type + "\n")
		return false
			}
			else return true
	}
	if (eltName.substring(4, 7) == "RL_")
	{
			// Real Type
			if (genericCheckReal(eltObj.value,elementtype) == false)
			{
		alert (help_real + "\n" + error_type + "\n")
		return false
			}
			else return true
	}
	if (eltName.substring(4, 7) == "DT_")
	{
			// Date Type
			if (genericCheckDate(eltObj.value,elementtype) == false)
			{
		alert (help_date + "\n" + error_type + "\n")
		return false
			}
			else return true
	}
	if (eltName.substring(4, 7) == "PW_")
	{
			// Texte Type
			if (genericCheckPass(eltObj.value,elementtype) == false)
			{
		alert (help_pass + "\n" + error_type + "\n")
		return false
			}
			else return true
	}
	if (eltName.substring(4, 7) == "EM_")
	{
			// EMail Type
			if (genericCheckMail(eltObj.value,elementtype) == false)
			{
					alert (help_mail + "\n" + error_type + "\n")
					return false
			}
			else return true
		}
	if (eltName.substring(4, 7) == "YY_")
	{
			// Year Type
			if (genericCheckYear(eltObj.value,elementtype) == false)
			{
					alert (help_year + "\n" + error_type + "\n")
					return false
			}
			else return true
		}
		}
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckForm(formObj)
{
// On test chaque element du form
// Note that indexes start at 0, not 1!

for(eltInd = 0; eltInd < formObj.elements.length ; eltInd=eltInd+1 )
{
		if (genericCheckElement(formObj.elements[eltInd]) == false)
		{
	// Erreur - Selectionner l'element :
	formObj.elements[eltInd].focus()
	formObj.elements[eltInd].select()
	return false
		}
}
// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function genericCheckMail(eltValue,elementtype)  //créée le 21/06/2001
{
//si le type de l'élément est facultatif, on ne vérifie pas la non-existence

if ((elementtype == "MAN") && (eltValue == null || eltValue == "" || eltValue.length == 0))
{
		// Le champs est vide : Erreur !!!!
		error_type = err_mandatory
		return false
}

if (isEmail(eltValue))
{
		// Pas de bon caracteres : Erreur !!!!
		error_type = err_wrong_mail
		return false
}

// S'il y a eu une erreur, on n'arrive pas la... (i.e. return false)
return true
}

function isDate(mm,dd,yy)
{
	var d;
	d = new Date();

	d.setMonth(mm);
	d.setDate(dd);
	d.setFullYear(yy);
	if (d.getMonth()==mm && d.getDate()==dd && d.getFullYear()==yy)
		{return true;}
	else
	{
		if (mm==1 && dd==29 && (yy==2000 || yy==2004))
		{return true;}
		else {return false;}
	}
}





// Fonctions de vérification
////////////////////////////////////////////
// LIST OF AVAILABLE FUNCTIONS :
//
// function makeArray(n)
// function isEmpty(s)
// function isWhitespace (s)
// function isInteger (s)
// function isSignedInteger (s)
// function isNonnegativeInteger (s)
// function isEmail (s)
// function isYear (s)
// function isIntegerInRange (s, a, b)
// function isDecimal(s)
// function isMonth (s)
// function isDay (s)
// function daysInFebruary (year)
// function isDate (year, month, day)
// function prompt (s)
// function promptEntry (s)
// function warnEmpty (theField, s)
// function warnInvalid (theField, s)
// function checkEmail (theField, emptyOK)
// function checkYear (theField, emptyOK)
// function checkMonth (theField, emptyOK)
// function checkDay (theField, emptyOK)
// function checkDate (yearField, monthField, dayField, labelString, EmptyOK)
// function checkDecimal(theField)



// REGULAR EXPRESSION DECLARATIONS
// Notes which apply to all the regexps below:
// (1) We want to only match strings exactly. In other words,
//		 we only want to return true if the string being tested
//		 matches the regular expression with no leading or trailing
//		 unmatched characters. So, we begin each regexp with
//		 the special character ^ (which matches beginning of input)
//		 and end each regexp with the special character $ (which
//		 matches end of input).
// (2) In the below comments we use these abbreviations:
//		 BOI = Beginning Of Input
//		 EOI = End Of Input
// (3) For explanations of the regexp special characters such as
//		 ^ $ \s + [] \d * ! ? \ .
//		 see http://developer.netscape.com/library/documentation/communicator/jsguide/regexp.htm

// BOI, followed by one or more whitespace characters, followed by EOI.
var reWhitespace = /^\s+$/;

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/;

// BOI, followed by an optional + or -, followed by one or more digits,
// followed by EOI.
//var reSignedInteger = /^(+|-)?\d+$/ 		 // PROBLEME SOUS IE

// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by .,
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/;
//var reEmail =/^[a-z.0-9_-]+@[a-z0-9_-]+\.([a-z]{2,3})$/i;  // créée par jfl le 21/06/01

//var reDecimal = /^\d*\.?\d*$/;
var reDecimal = /^(((\d{1,3})(\'?))*)(\d{1,3})(\.?)(\d*)$/; // 1'234'567.89 ou 1234567.89
//var reAlphaNum= /^[^\<]/;
var reAlphaNum= /[^A-Za-z0-9\\<>\|_éèàêâùûüöäô$£çëîâê«»\&\/()\=\?.,;:\’'"()?!*¨&@\n\r\&\/\-&#8217;+ ]/ ; //créée par jfl le 01/06/01
//var reAlphaNum= /\W/g;


// VARIABLE DECLARATIONS

// whitespace characters as defined by this sample code
var whitespace = " \t\n\r";


// Global variable defaultEmptyOK defines default return value
// for many functions when they are passed the empty string.
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default,
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.),
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.

var defaultEmptyOK = false;




// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.	If you're using
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//	 this.length = n;
for (var i = 1; i <= n; i++) {
this[i] = 0;
}
return this;
}


var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;	 // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;




// Check whether string s is empty.

function isEmpty(s)
{ 	return ((s == null) || (s.length == 0));
}



// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s)

{ 	// Is s empty?
return (isEmpty(s) || reWhitespace.test(s));
}


// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//			the default behavior which is specified globally by
//			defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//			the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL: 		RESULT:
// isInteger ("5")						true
// isInteger ("") 						defaultEmptyOK
// isInteger ("-5") 					false
// isInteger ("", true) 			true
// isInteger ("", false)			false
// isInteger ("5", false) 		true


function isInteger (s)
{ 	var i;

if (isEmpty(s))
if (isInteger.arguments.length == 1) return defaultEmptyOK;
else return (isInteger.arguments[1] == true);

return reInteger.test(s);
}



// isSignedInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL: 				 RESULT:
// isSignedInteger ("5")					 true
// isSignedInteger ("") 					 defaultEmptyOK
// isSignedInteger ("-5") 				 true
// isSignedInteger ("+5") 				 true
// isSignedInteger ("", false)		 false
// isSignedInteger ("", true) 		 true

function isSignedInteger (s)
{ 	if (isEmpty(s))
if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
else return (isSignedInteger.arguments[1] == true);


else {
return reSignedInteger.test(s);
}
}



// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isNonnegativeInteger (s)
{ 	var secondArg = defaultEmptyOK;

if (isNonnegativeInteger.arguments.length > 1)
secondArg = isNonnegativeInteger.arguments[1];

// The next line is a bit byzantine.	What it means is:
// a) s must be a signed integer, AND
// b) one of the following must be true:
//		i)	s is empty and we are supposed to return true for
//				empty strings
//		ii) this is a number >= 0

return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg)	|| (parseInt (s,10) >= 0) ) );
}



function isDecimal (s)
{ 	var i;
if (isEmpty(s))  {
	if (isDecimal.arguments.length == 1) {
		return defaultEmptyOK;
	} else {
		return (isDecimal.arguments[1] == true);
	}
}
return reDecimal.test(s);
}


function isAlphaNum (s)
{ 	var i;
if (isEmpty(s))  {
	if (isAlphaNum.arguments.length == 1) {
		return defaultEmptyOK;
	} else {
		return (isAlphaNum.arguments[1] == true);
	}
}
return reAlphaNum.test(s);
}



// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)	//modifiée par jfl le 21/06/01
{ 	var i;
if (isEmpty(s)) {
	if (isEmail.arguments.length == 1) {
		return defaultEmptyOK;
	}
	else {
		return (isEmail.arguments[1] == true);
	}
}
return !reEmail.test(s);
}

// isYear (STRING s [, BOOLEAN emptyOK])
//
// isYear returns true if string s is a valid
// Year number.  Must be 2 or 4 digits only.
//
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

/*function isYear (s)
{ 	if (isEmpty(s))
if (isYear.arguments.length == 1) return defaultEmptyOK;
else return (isYear.arguments[1] == true);
if (!isNonnegativeInteger(s)) return false;
return ((s.length == 2) || (s.length == 4));
}*/
function isYear (s)
{ 	if (isEmpty(s))
if (isYear.arguments.length == 1) return defaultEmptyOK;
else return (isYear.arguments[1] == true);
if (!isInteger(s)) return false;
return (s.length == 4);
}



// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
//
// isIntegerInRange returns true if string s is an integer
// within the range of integer arguments a and b, inclusive.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isIntegerInRange (s, a, b)
{ 	if (isEmpty(s))
if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
else return (isIntegerInRange.arguments[1] == true);

// Catch non-integer strings to avoid creating a NaN below,
// which isn't available on JavaScript 1.0 for Windows.
if (!isInteger(s, false)) return false;

// Now, explicitly change the type to integer via parseInt
// so that the comparison code below will work both on
// JavaScript 1.2 (which typechecks in equality comparisons)
// and JavaScript 1.1 and before (which doesn't).
var num = parseInt (s,10);
return ((num >= a) && (num <= b));
}




// isMonth (STRING s [, BOOLEAN emptyOK])
//
// isMonth returns true if string s is a valid
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isMonth (s)
{ 	if (isEmpty(s))
if (isMonth.arguments.length == 1) return defaultEmptyOK;
else return (isMonth.arguments[1] == true);
return (isIntegerInRange (s, 1, 12) && s.length == 2);
}



// isDay (STRING s [, BOOLEAN emptyOK])
//
// isDay returns true if string s is a valid
// day number between 1 and 31.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isDay (s)
{ 	if (isEmpty(s))
if (isDay.arguments.length == 1) return defaultEmptyOK;
else return (isDay.arguments[1] == true);
return (isIntegerInRange (s, 1, 31) && s.length == 2);
}



// daysInFebruary (INTEGER year)
//
// Given integer argument year,
// returns number of days in February of that year.
function daysInFebruary (year)
{ 	// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (	((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}



// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day
// form a valid date.
//
function isDate (year, month, day)
{ 	// catch invalid years (not 2- or 4-digit) and invalid months and days.

if( !isDay(day) || !isMonth(month) || !isYear(year) ) {
	return false;
} else {
	//if (!(isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

	// Explicitly change type to integer to make code work in both
	// JavaScript 1.1 and JavaScript 1.2.
	var intYear = parseInt(year,10);
	var intMonth = parseInt(month,10);
	var intDay = parseInt(day,10);

	// catch invalid days, except for February
	if (intDay > daysInMonth[intMonth])
		return false;
	if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
		return false;
}
return true;
}




/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */


// Display prompt string s in status bar.
function prompt (s)
{ 	window.status = s;
}



// Display data entry prompt string s in status bar.
function promptEntry (s)
{ 	window.status = pEntryPrompt + s;
}




// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.
function warnEmpty (theField, s)
{
alert(mPrefix + s + mSuffix);
theField.focus();
return false;
}



// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.
function warnInvalid (theField, s)
{
alert(theField.name + "\n" + s);
theField.focus();
//		theField.select();
return false;
}




/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkEmail (theField, emptyOK)
{ 	if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
if ((emptyOK == true) && (isEmpty(theField.value))) return true;
else if (!isEmail(theField.value, false))
return warnInvalid (theField, iEmail);
else return true;
}



// Check that string theField.value is a valid Year.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkYear (theField, emptyOK)
{ 	if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
if ((emptyOK == true) && (isEmpty(theField.value))) return true;
if (!isYear(theField.value, false))
return warnInvalid (theField, iYear);
else return true;
}


// Check that string theField.value is a valid Month.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkMonth (theField, emptyOK)
{ 	if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
if ((emptyOK == true) && (isEmpty(theField.value))) return true;
if (!isMonth(theField.value, false))
return warnInvalid (theField, iMonth);
else return true;
}


// Check that string theField.value is a valid Day.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function checkDay (theField, emptyOK)
{ 	if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
if ((emptyOK == true) && (isEmpty(theField.value))) return true;
if (!isDay(theField.value, false))
return warnInvalid (theField, iDay);
else return true;
}



// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
//
// Check that yearField.value, monthField.value, and dayField.value
// form a valid date.
//
// If they don't, labelString (the name of the date, like "Birth Date")
// is displayed to tell the user which date field is invalid.
//
// If it is OK for the day field to be empty, set optional argument
// OKtoOmitDay to true.  It defaults to false.

/*
function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{ 	// Next line is needed on NN3 to avoid "undefined is not a number" error
// in equality comparison below.
if (checkDate.arguments.length == 4) OKtoOmitDay = false;
if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
else if (!isDay(dayField.value))
return warnInvalid (dayField, iDay);
if (isDate (yearField.value, monthField.value, dayField.value))
return true;
alert (iDatePrefix + labelString + iDateSuffix)
return false
}

function checkDate (yearField, monthField, dayField, labelString, EmptyOK)
{ 	// Next line is needed on NN3 to avoid "undefined is not a number" error
// in equality comparison below.
if (checkDate.arguments.length == 4) EmptyOK = defaultEmptyOK;
if ( (EmptyOK == true) && isEmpty(dayField.value) && isEmpty(monthField.value) && isEmpty(yearField.value))
return true;
else
{
if (!isDay(dayField.value)) return warnInvalid (dayField, iDay);
if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
if (isDate (yearField.value, monthField.value, dayField.value))
	return true;
alert (iDatePrefix + labelString + iDateSuffix);
return false;
}
}
*/

function checkDecimal(theField)
{
if (!isDecimal(theField.value))
return warnInvalid (theField, iDecimal);
else return true;
}


function checkInteger(theField)
{
if (!isInteger(theField.value))
return warnInvalid (theField, iInteger);
else return true;
}


function checkDateString(theField)
{
var date=toStandardDate(theField);
var dateArray = date.split("/");
if(!isDate(dateArray[2], dateArray[1], dateArray[0])) {
	return warnInvalid (theField, iDate);
} else {
	return true;
}
}

function toStandardDate(theField){
var str=theField.value;
return str.replace(/\./g , "/");
}


function checkAlphaNum(theField)
{
if (!isAlphaNum(theField.value))
return warnInvalid (theField, iAlphaNum);
else return true;
}


function checkPercentage(theField)
{
if (isDecimal(theField.value) ) {
	var floatPercentage  = parseFloat(theField.value);
	if ( (floatPercentage>=0.00) && (floatPercentage<=100.00) ) {
		return true;
	} else {
		return warnInvalid (theField, iPercentage);
	}
} else {
	return warnInvalid (theField, iPercentage);
}
}


function OuvrirPopup(page,nom,option)
{
this.open(page,nom,option);
}


function initId() //initialise les formulaires de la pop-up
{
for (i=0; i < document.SwissimoForm.iregsel.length; i++)
{
document.SwissimoForm.iregsel[i].checked = false;
}

for (i=0; i < document.SwissimoForm.iregsel.length; i++)
{
opener.document.retourId.regionsel.value = "";
}
}


function selectreg(ireg) //sélectionne les Id lorsque l'on clique sur une région de la carte
{
	var master = document.SwissimoForm.usemap.value;

	if(document.SwissimoForm.iregsel.length){
		for (i=0; i < document.SwissimoForm.iregsel.length; i++)
		{
			if (document.SwissimoForm.iregsel[i].value == ireg)
			{
				 document.SwissimoForm.iregsel[i].checked = !document.SwissimoForm.iregsel[i].checked;
			}
		}
	}
	else{
		document.SwissimoForm.iregsel.checked = !document.SwissimoForm.iregsel.checked;
	}
	
	eval("masterChkBox(master);");
}

function manageUrlParameters(aKey, aNewValue){
	// Récupération de la requête contenue dans l'URL (sans le ?)
	var req = window.location.search.substr(1,window.location.search.length);
	// Récupération des paires paramètre=valeur
	var dbl = req.split('&');
	var newParams;
		
	var objQS = new Array();	// Pour stock. le nom + valeur des paramètres
	var aPrm = new Array();		// Pour stock. le nom des paramètres
	var aVal = new Array();		// Pour stock. la valeur des paramètres
	for (i=0;i<dbl.length;i++) {
		// Recup. le nom des parametres (Attention : elem.1 du tab. = param.1)
		aPrm[i+1] = dbl[i].substring(0,dbl[i].indexOf('='));
		// Recup. la valeur des parametres (Attention : elem.1 du tab. = val.param.1)
		if(aPrm[i+1] == aKey){
			aVal[i+1] = unescape(aNewValue);
		}
		else{
			aVal[i+1] = unescape(dbl[i].substring(dbl[i].indexOf('=')+1,dbl[i].length));
		}
		
		objQS[i+1] = aPrm[i+1] + "=" + aVal[i+1]; // Stock la valeur des paramètres sous forme de propriété
	}
	newParams = objQS.join('&').substr(1,objQS.join('&').length);
	return newParams;
}

function selectmap(ireg) //sélectionne les Id lorsque l'on clique sur une région de la carte
{
	var params = manageUrlParameters("usemap", ireg);
	location.href = "si_cartes.page.php?" + params;
}

function allChkBoxes(aBoolean) {
	for (i=0, n=document.SwissimoForm.elements.length; i<n; i++){
		if (document.SwissimoForm.elements[i].name.indexOf('iregsel') != -1){
			document.SwissimoForm.elements[i].checked = aBoolean;
		}
	}
}

function masterChkBox(ireg) {
	var isToChk = true;
	var master = "master" + ireg;
	var oneAtLeast = false;
	
	for (i=0, n=document.SwissimoForm.elements.length; i<n; i++){
		if (document.SwissimoForm.elements[i].name.indexOf('iregsel') != -1){
			oneAtLeast = true;
			if(!document.SwissimoForm.elements[i].checked){
				isToChk = false;
			}
		}
	}
	if(!oneAtLeast) 
		isToChk = oneAtLeast;
		
	eval("document.SwissimoForm."+master+".checked = isToChk;");
}

function sendData() //envoi à la fenêtre parente les Id sélectionnés dans la pop-up
{
var regIdSelect = "";
var temp="";
var nbCheckBox = 0;

if(document.SwissimoForm.iregsel.length){
	for (i = 0; i < document.SwissimoForm.iregsel.length; i++)
	{
		if (document.SwissimoForm.iregsel[i].checked)
		{
		 temp += "'" + document.SwissimoForm.iregsel[i].value + "',";
		 nbCheckBox++;
		}
		regIdSelect = temp.substring(0,temp.length-1); //pour supprimer le séparateur en fin de ligne
	}
}
else{
	if(document.SwissimoForm.iregsel.checked){
		regIdSelect = "'" + document.SwissimoForm.iregsel.value + "'";
		nbCheckBox++;
	}
}

if (nbCheckBox==0){ //si aucune cas n'est cochée : on renvoi l'Id de la région parente
//regIdSelect = "'" + document.SwissimoForm.iidregion.value + "'";
regIdSelect = '';
alert('Aucun district sélectionné !');
return false;
}

opener.document.SwissimoForm.localisation_carte.value = regIdSelect;
opener.ListeRegion();
//opener.document.SwissimoForm.submit();
opener.formSubmit('INITIAL','');
this.close();
}




function ListeRegion() {

var nb = document.SwissimoForm.localisation.length;

if (document.SwissimoForm.localisation.options[nb-1] != "votre_selection") {

var opt = new Option(document.SwissimoForm.libelle_votreselection.value,"votre_selection");
document.SwissimoForm.localisation.options[nb] = opt ;
}

document.SwissimoForm.localisation.options[nb].selected = true;
return true;
}

function CheckAll() {

 if (document.SwissimoForm.delete_all_agents.checked) {
   for (eltInd = 0; eltInd < document.SwissimoForm.elements.length ; eltInd=eltInd+1) {
      eltObjt = document.SwissimoForm.elements[eltInd];
      eltName = eltObjt.name;
	if (eltName.length > 0) {
		if ((eltName.indexOf("delete_agent_", 0) == 0)){
		  document.SwissimoForm.elements[eltInd].checked = true; 
		}
	}
   }	
 	
 }
 else {
   for (eltInd = 0; eltInd < document.SwissimoForm.elements.length ; eltInd=eltInd+1) {
      eltObjt = document.SwissimoForm.elements[eltInd];
      eltName = eltObjt.name;
	if (eltName.length > 0) {
		if ((eltName.indexOf("delete_agent_", 0) == 0)){
		  document.SwissimoForm.elements[eltInd].checked = false; 
		}
	}
   }	
 	
 }
}

function fillTbxPays(cur_pays){
	var lv_pays;
	var selected_pays;
	
	lv_pays = document.SwissimoForm.elements['pays'].options[document.SwissimoForm.elements['pays'].selectedIndex].text;
	selected_pays = document.SwissimoForm.elements['pays'].options[document.SwissimoForm.elements['pays'].selectedIndex].text;
	
	if(cur_pays != '' && selected_pays == 'Autre'){
		lv_pays = cur_pays;
	}
	
	document.SwissimoForm.MAN_TX_pays.value = lv_pays;
	
	if(selected_pays != "Suisse" && selected_pays != "France"){
		//document.SwissimoForm.MAN_TX_pays.disabled = false;
		alert('Vous pouvez spécifier le pays exact dans le champ situé à droite');
		document.SwissimoForm.MAN_TX_pays.focus();
	}
	/*else{
		document.SwissimoForm.MAN_TX_pays.disabled = true;
	}*/
}

function emptyInput(chkBoxLibelle){
	var chkBxItem = eval("document.SwissimoForm.elements['" + chkBoxLibelle + "'].checked");
	
	if(chkBxItem == false)
		eval ("document.SwissimoForm.CHK_TX_" + chkBoxLibelle + "_lib.value='';");
}