var bamv3_g_ua = (navigator.userAgent.toLowerCase());
var bamv3_g_EE = false;
var bamv3_g_bIE6 = (bamv3_g_ua.indexOf("msie 6") > -1);
var bamv3_g_bMac = (bamv3_g_ua.indexOf("mac") > -1);
var bamv3_g_bSecurite;
var bamv3_g_bSansPopup;
var bamv3_g_sUrlSecurite;     

function bamv3_popupMailingEntreprise(msg){
	var hauteur = 320;
	var largeur = 290;
	var top = (screen.height - hauteur) / 2;
	var left = (screen.width - largeur) / 2;
	pop = window.open("","",'top=' + top + ',left=' + left + ',scrollbars=no,toolbar=no,status=no,width=' + largeur + ',height=' + hauteur + ',resizable=no');
	pop.document.open();
	
	pop.document.write('<html>');
	pop.document.write('<head>');
	pop.document.write('<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">');
	pop.document.write('<title>Espace entreprises</title>');
	
	var css="/Entreprise/ObjCommun/css/ie.css";
	if (navigator.appName=="Netscape") {
		if (navigator.appVersion.indexOf('4.78')!=-1){
			css="/Entreprise/ObjCommun/css/ns.css";
		}
		else if (navigator.appVersion.indexOf('5')!=-1){
			css="/Entreprise/ObjCommun/css/ie.css";
		}
		else {
			css="/Entreprise/ObjCommun/css/ns.css";
		}
	}
	
	if (navigator.appName=="Microsoft Internet Explorer") {
		css="/Entreprise/ObjCommun/css/ie.css";
	}
	
	pop.document.write("<LINK rel='StyleSheet' type='text/css' href='"+css+"'>");
	
	pop.document.write('<scr' + 'ipt>function swap(objName,picName){objName.src=picName;}</scr' + 'ipt>');
	pop.document.write('</head>');
	pop.document.write('<body marginwidth="0" marginheight="0">');
	pop.document.write('<div align="center">');
	pop.document.write('<table border="0" cellpadding="0" cellspacing="0" width="290" bgcolor="#eeeeee" align="center">');
	pop.document.write('<tr>');
	pop.document.write('<td width="290" height="55" align="center"><span class="f24ro1br">sécurité</span></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('<td width="290" align="center">');
	pop.document.write('<table border="0" cellpadding="20" cellspacing="0" width="290" bgcolor="white">');
	pop.document.write('<tr>');
	pop.document.write('<td width="248" height="209" valign="middle" align="center"><p align="justify" valign="middle"><span class="f9gr1rr">' + msg + '</span></p></td>');
	pop.document.write('</tr>');
	pop.document.write('</table>');
	pop.document.write('</td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('<td width="290" height="55" align="center" valign="middle"><a href="javascript:window.close();" OnMouseOver="swap(document.retour,\'/Entreprise/ObjCommun/Img/bouton/retour_on.gif\')"; OnMouseOut="swap(document.retour,\'/Entreprise/ObjCommun/Img/bouton/retour_of.gif\')";><img src="/Entreprise/ObjCommun/Img/bouton/retour_of.gif" width="65" height="21" border="0" name="retour"></a></td>');
	pop.document.write('</tr>');
	pop.document.write('</table>');
	pop.document.write('</div>');
	pop.document.write('</body>');
	pop.document.write('</html>');
	pop.document.close();
	pop.focus();
}

function bamv3_popupMailing(msg){
	var hauteur = 280;
	var largeur = 300;
	var top = (screen.height - hauteur) / 2;
	var left = (screen.width - largeur) / 2;
	pop = window.open("","",'top=' + top + ',left=' + left + ',scrollbars=yes,toolbar=no,status=no,width=' + largeur + ',height=' + hauteur + ',resizable=yes');
	pop.document.open();
	var navigateur= navigator.userAgent;
	IE4= (navigateur.indexOf("MSIE 4") > 0);
	if (IE4){
		pop.document.write('<title>Sécurité</title>');
	}else {
		pop.document.write('<title>Sécurité</title>');
		pop.document.write('<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/Vitrine/ObjCommun/Css/style.css\">');
		pop.document.write('<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"/Vitrine/ObjCommun/Css/style.css\">');
	}
	pop.document.write('<body bgcolor=\"\#FFFFFF\" alink=\"\#000000\" topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">');
	pop.document.write('<center>');
	pop.document.write('<table border=\"0\" width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">');
	pop.document.write('<tr>');
	pop.document.write('	<td width="30" rowspan="6"><img src="/Vitrine/ObjCommun/Img/pix_trans.gif" alt="" border="0" width="30" height="1" /></td>');
	pop.document.write('	<td width="240" height="25"><img src="/Vitrine/ObjCommun/Img/pix_trans.gif" alt="" border="0" width="240" height="25" /></td>');
	pop.document.write('	<td width="10" rowspan="6"><img src="/Vitrine/ObjCommun/Img/pix_trans.gif" alt="" border="0" width="10" height="1" /></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('	<td align="right"><span class="bordeauxgras12">SECURITE</span></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('	<td class="tdbordeaux"><img src="/Vitrine/ObjCommun/Img/pix_trans.gif" alt="" border="0" width="1" height="1" /></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('	<td><img src="/Vitrine/ObjCommun/Img/pix_trans.gif" alt="" border="0" width="1" height="25" /></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('	<td valign="top"><span class="vert12">' + msg + '</span></br></br></td>');
	pop.document.write('</tr>');
	pop.document.write('<tr>');
	pop.document.write('	<td align="right" valign="top"><a href="javascript:window.close();"><img src="/Vitrine/ObjCommun/Img/ensavoirplus/popups/fermez.gif" alt="" border="0" width="120" height="19" /></a></td>');
	pop.document.write('</tr>');
	pop.document.write('</table>');
	pop.document.write('</center>');
	pop.document.write('</body>');
	pop.document.close();
	pop.focus();
}

function bamv2_isNumerique(chaine){
	var rx = new RegExp("^\\d{6}$", "g");
	return rx.test(chaine);
}

function bamv2_isAlphaNum(chaine){
	var rx = new RegExp("^[A-Za-z0-9]{11}$", "g");
	return rx.test(chaine);
}

function bamv2_toucheEntreeBam(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){
		bamv2_validation();
	}
	return;
}

function bamv3_setCookie(nom, valeur) {
	var today = new Date();
	var expdate = new Date(); // crée un objet date indispensable 
	expdate = new Date(today.getTime() + ( 30 * 24 * 60 * 60 * 1000)); 
	// on rajoute trente jours en millisecondes 
	document.cookie = nom + "=" + escape(valeur) + ((expdate == null)?"":("; expires=" + expdate.toGMTString())) + ";path=/";
}

function bamv3_getCookie(nom) {
	var recherche = nom + "=";
	if (document.cookie.length > 0) {
		var offset=document.cookie.indexOf(recherche);
		// si le cookie existe
		if (offset != -1) {		
			// position début
			offset += recherche.length;
			// position fin
			var fin = document.cookie.indexOf(";", offset);
			if (fin == -1)
				fin = document.cookie.length;
			return unescape(document.cookie.substring(offset, fin));
		}
	}
}

function bamv3_updateCookie(nom) {
	var valeurCookie = (bamv2_getCookie(nom) != null)? bamv2_getCookie(nom) : 0;
	valeurCookie = escape(valeurCookie);
	bamv2_setCookie(nom, valeurCookie);
}
	
function bamv3_validation() {
	var f=document.bamaccess;

	var cookieSecurite;
	
	if(bamv3_g_bSecurite)
		cookieSecurite = (bamv3_getCookie("cookieSecurite") != null)? bamv3_getCookie("cookieSecurite") : 0;

	if(bamv3_g_bSecurite && cookieSecurite == 0) {
		bamv3_popupSecurite(bamv3_g_sUrlSecurite, '', 750, 550);						
		bamv3_setCookie("cookieSecurite", ++cookieSecurite);
	} else {			
		bamv3_redirectionBam();
	}
}

function bamv3_redirectionBam() {
	if(bamv3_g_bMac){
		bamv3_redirectionBamMac();
	}
	else{
		if(bamv3_g_bSansPopup){
			bamv3_redirectionBamSansPopUp();
		}
		else{
			bamv3_redirectionBamPopup();
		}
	}
}

function bamv3_redirectionBamSansPopUp() {
	var f=document.bamaccess;
	f.submit();
//	if(bamv3_g_bSecurite)
//		f.reset();
}

function bamv3_redirectionBamPopup() {
	var f=document.bamaccess;

	var BAM_fenetre = window.open("","BAM_fenetre","location=yes,menubar=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes");
	f.target="BAM_fenetre";
	f.submit();
//	f.reset();
	BAM_fenetre.focus();
}

function bamv3_redirectionBamMac() {
	var f=document.bamaccess;
	f.submit();
//	if(bamv3_g_bSecurite)
//		window.location.reload();
}

function bamv3_actionSecurite()
{
//	window.location.reload();
	bamv3_redirectionBam();
}

function bamv3_popup(page,nom,largeur,hauteur) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + ",toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no");
}

function bamv3_popupSecurite(page,nom,largeur,hauteur) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + ",toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no");
}

function actionSecurite()
{
	bamv3_actionSecurite();
}

function bamv2_actionSecurite()
{
	bamv3_actionSecurite();
}