//====================================================
// Bibliotheque de fonctions de STEF
//====================================================

// Modified : 20051216
// Modified : 20110505

//====================================================
function clicMoi(url)
//====================================================
{
	if (url.search('/public') != -1)
	{
		window.location.href = url;
	}
	else
	{
		with (Math)
		{
			window.location.href = url+"|"+String(round(random()*1000000));
		}
	}
};

//====================================================
function clicMoiCentre(url)
//====================================================
{
	if (parent.frames.length == 0)
	{
		if (url.search('/public') != -1)
		{
			window.open(url);
		}
		else
		{
			with (Math)
			{
				window.open( url+"|"+String(round(random()*1000000)) );
			}
		}
	}
	else
	{
		if (url.search('/public') != -1)
		{
			parent.centre.location.href = url;
		}
		else
		{
			with (Math)
			{
				parent.centre.location.href = url+"|"+String(round(random()*1000000));
			}
		}
	}
};

//====================================================
function clicMoi2(url)
//====================================================
{
	if (url.indexOf('?') == -1)
	{
		with (Math)
		{
			window.location.href = url + "?rand=" + String(round(random()*1000000));
		}
	}
	else
	{
		with (Math)
		{
			window.location.href = url + "&rand=" + String(round(random()*1000000));
		}
	}
};

//====================================================
// GESTION DES ACCENTS DANS LES CHAINES JAVASCRIPTS
//====================================================

//	Ë	&#232;	&egrave;
//	È	&#233;	&eacute;
//	Í	&#234;	&ecirc;
//	Î	&#235;	&euml;

function replaceAccent(s, codeISO)
{
	return s;
}

function convertAccent(s)
{
	//var n = s.indexOf('&#');
	
	//if (s.indexOf('&#233;') != -1)
	{
		//var val = s.substr(n
		
	}
	
	while (s.indexOf('&#232;') != -1)
	{
		s = s.replace(/&#232;/, String.fromCharCode(232));
	}
	while (s.indexOf('&#233;') != -1)
	{
		s = s.replace(/&#233;/, String.fromCharCode(233));
	}
	while (s.indexOf('&#234;') != -1)
	{
		s = s.replace(/&#234;/, String.fromCharCode(234));
	}
	while (s.indexOf('&#235;') != -1)
	{
		s = s.replace(/&#235;/, String.fromCharCode(235));
	}
	
	return s;
}

//====================================================
function estEmailValide(email)
//====================================================
{
	if (email.length == 0) return false;
	
	var arobasePos = email.indexOf('@');
	if (arobasePos < 0) return false; // un @ au moins
	if (arobasePos == 0) return false; // pas en premier car
	if (email.lastIndexOf('@') != arobasePos) return false; // pas 2
	
	var pointPos = email.indexOf('.', arobasePos+1);
	if (pointPos < 0) return false; // un point au moins apres @
	if (pointPos == arobasePos+1) return false; // pas apres @
	if (email.lastIndexOf('.') == email.length-1) return false; // pas a la fin
	
	var alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-_@';
	for (var i=0; i<email.length; i++)
	{
		if ( alphabet.indexOf(email.charAt(i)) < 0) return false; // caractere interdit
	}
	
	return true;
}

