

var ns4 = (document.layers)? true:false;   //NS 4 
var ie4 = (document.all)? true:false;   //IE 4 
var dom = (document.getElementById)? true:false;   //DOM 
var ici;
var gLay = "";

// test
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

var gsConnexionAction = "show";


//Pas Utilisé

/*
function redirectUrl()
{
  
    var sHref = new String(location.href);
    var sHost = new String(location.host);
    var iHostLen = 0;
    var sNewLien = new String("");
   
    iResult = sHref.indexOf("viPage.aspx");
    
    if(iResult == -1)
    {
        iHostLen = sHost.length;
        sNewLien = sHref.substr(sHref.indexOf(sHost) + iHostLen);
        goToPage(sNewLien);
        return;     
    }
   
   return;
    
}
*/

function WBPrint() {
	window.focus();
	if(window.print)
		window.print();

}

function WBLogUrlRequest(strUrl) {
	window.open('/_system/services/logUrlRequest.asp?page='+strUrl,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes,width=1,height=1,left=0,top=0')	
}

function golien(intNoLien) {
	window.open("/lien/lien-redirect.asp?xnolien="+intNoLien);
}

function WBGoLien(intNoLien, intNoType, strUrl) {
	//if (intNoType == 11){
		//WBLogUrlRequest(strUrl)
		window.open(strUrl);
	//}else{
	//	location.href = strUrl
	//}
}

function WBSendPage() {
	window.open('/_system/services/sendpage.asp?page='+location.pathname,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes,width=650,height=440,left=0,top=0')	
}


function WBPrintPage() {
	window.open('/_system/services/printpage.asp?page='+location.pathname,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes,width=620,height=740,left=0,top=0')
}

function WBPrintPageTheme() {
	window.open('/_system/services/printpage.asp?theme='+document.all.xthemecourant.value,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes,width=620,height=740,left=0,top=0')
}

function conseillerVirtuel(strUrl){
	window.open(strUrl,'','toolbar=no,status=no,titlebar=yes,menubar=no,resizable=yes,scrollbars=no,width=600,height=300,left=500,top=20')
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function WB_showHideLayers() { //v6.0
  var i,p,v,obj,args=WB_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function WB2_showHideLayers() { //v6.0
  var i,p,v,obj,args=WB_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
		if (v=='show')
		{
			v='block';
			gsConnexionAction = 'hide';
			WB_placerDiv(obj.id);
		}
		else
		{
			v='none';
			gsConnexionAction = 'show';
		}
		v=(v=='show')?'block':(v=='hide')?'none':v; 
		obj.style.display=v; 
	}
  }
  window.event.cancelBubble = true;
}

function setToAnchor(ID_Anchor,Name_Anchor,ID_Div)
//Fonction permettant de positionner un DIV à une position occupée par une ancre
    {
var DivLeft  = 0;   //Position du Div par rapport au côté gauche de la page 
var DivTop = 0 ;   //Position du Div par rapport au haut de la page 
    if (dom)
        {
        pos = document.getElementById(ID_Anchor);
        DivLeft = getLeft(pos);
        DivTop = getTop(pos);
        document.getElementById(ID_Div).style.left = DivLeft-12;
        document.getElementById(ID_Div).style.top = DivTop+ 16;
//		document.getElementById(ID_Div).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)" ;
        }
    else if (ie4) 
        {
        pos = document.all[ID_Anchor];
        DivLeft = getLeft(pos);
        DivTop = getTop(pos);
        document.all[ID_Div].style.posLeft = DivLeft-12;
        document.all[ID_Div].style.posTop = DivTop+ 16;
        }
    else if (ns4)
        {
        pos = document.anchors[Name_Anchor];
        DivLeft = pos.x;
        DivTop = pos.y;
        document.layers[ID_Div].pageX = DivLeft-12;
        document.layers[ID_Div].pageY = DivTop+ 16;
        }
    }

function getLeft(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord gauche de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else 
        return (MyObject.offsetLeft);
    }
	
function getTop(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord haut de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
		
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }

function openLay(lay) {
	gLay = lay;
	layer = MM_findObj(lay);
	//Cache = MM_findObj('SMnucache');
	if (document.layers) {
		//layer.visibility="show";
		//Cache.visibility="show";
		if (layer.visibility=="show")
		{
			layer.visibility="hide";
		}else{
			layer.visibility="show";
			fermer(1);
		}
	} else {
		//alert("layer.style");
		if (layer.style.visibility=="visible")
		{
			layer.style.visibility="hidden";
		}else{
			layer.style.visibility="visible";
			fermer(1);
		}
		//Cache.style.visibility="visible";
	}
	if (window.event)
	{
		window.event.cancelBubble = true;
	}
}

function WB_placerDiv(psDivId){
	var intOffsetTop = 0;
	var intOffsetWidth = 0;

	intOffsetTop = document.body.scrollTop;
	intOffsetWidth = document.body.scrollLeft;
	var oClicked = window.event.srcElement;
	var oTD
	if (oClicked.tagName == 'A')
	{
		//alert("Parent :" + oClicked.parentElement.tagName);
		oTD = oClicked.parentElement;
	}else{
		//alert("Current :" + oClicked.tagName);
		oTD = oClicked
	}

    alert("tdtop:" + document.getElementById(psDivId).style.top);
    alert("tdleft:" + document.getElementById(psDivId).style.left);

}

function goToPage(psUrl){
	if ((dom) || (ie4))
	{
		var sResolution = screen.availWidth;
		//alert(sResolution);
		location.href="/_irm/irm-cms/viPage.aspx?xresolution=" + sResolution + "&xurl=" + psUrl;
	}else{
		location.href=psUrl;
	}
}

function goToPopPage(psUrl){
	window.open(psUrl, null, "height=500,status=yes,toolbar=no,menubar=no,location=no,top=200");
}

function WBEnvUserInfo(){
	//alert("WBEnvUserInfo");
	var br=new Array(4);
	var os=new Array(2);
	//var flash=new Array(2);
	br=getBrowser();
	os=getOS();
	//flash=hasFlashPlugin();
	var fox = (br[0]=='firefox')? true:false; //FIREFOX 
	var win = (os[0]=='win')? true:false; //WIN OS

	
	var strLinkId = String();
	var sHref = String();
	var sHost = String("http://" + location.host);

	/*alert("dom :" +dom);
	alert("ie4 :" +ie4);
	alert("ns4 :" +ns4);
	alert("fox :" +fox);
	alert("win :" +win);*/

	var linkArray;
	if (((ie4) && (win)))
	{
		linkArray = document.all.tags("a");
	}
	if ((dom) || (fox))
	{
		linkArray = document.getElementsByTagName("a");
	}
	if (((ie4) && (win)) || (dom) || (fox))
	{
		for (var intCpt = 0; intCpt < linkArray.length; intCpt++)
		{
		  strLinkId = linkArray[intCpt].id;
		  //alert(strLinkId);
		  if(strLinkId.substr(1,5) != "link_"){
			sHref = linkArray[intCpt].href;
			sHref = sHref.substr(sHost.length);
			// alert(sHref);
			if(sHref.substr(1,10) != 'javascript'){
				sHref = "javascript:goToPage('" + sHref + "')"; 
				linkArray[intCpt].href = sHref;
			}
		  }
		}

	}
}

function ChangeConnexionAction(){
	if (gsConnexionAction=='hide')
	{
		gsConnexionAction = 'show';
	}else{
		gsConnexionAction = 'hide';
	}
}

function fermer(statut){
switch(statut){
case 1:
case "1":
	//alert("clean");
	ici = window.setTimeout("clean();closeLay('" + gLay + "');",1000)
	break;
case 0:
case "0":
	window.clearTimeout(ici)
	break;
	}
}

function closeLay(lay) {
	if (lay!="")
	{
		layer = MM_findObj(lay);
		//Cache = MM_findObj('SMnucache');
		if (document.layers) {
			layer.visibility ="hide";
			//Cache.visibility ="hide";
		} else {
			layer.style.visibility="hidden";
			//Cache.style.visibility="hidden";
		}
	}
}

function changeLanguage(oSelect){
	sUrl = oSelect.item(oSelect.selectedIndex).value;
	//alert(sUrl);
	goToPage(sUrl);
}


function getSoapRequest(psUrl, psParams){
	var strXMLCode;
	var strHOST;
	var oXMLHTTP = xmlhttp;
	
	strHOST = location.host;

	oXMLHTTP.open("POST", "http://" + strHOST + psUrl , false);

	//alert("http://" + strHOST + psUrl);
	if (psParams.length > 0)
	{
		oXMLHTTP.send(psParams);
	}else{
		oXMLHTTP.send();
	}

	strXMLCode = oXMLHTTP.responseText;
	//alert("XML: " + strXMLCode);
	
	return strXMLCode;
}

function vilogoffIRM()
{
    var sUrl = new String("")
    sUrl = "/_irm/irm-cms/viLogoff.aspx?xgabarit=irm_logoff.xsl"
    window.open(sUrl,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=no,scrollbars=yes,width=450,height=230,left=0,top=0')
}

function logOffIRM()
{
    var sUrl = new String("");
    var sRetour = new String("");
    
    sUrl = "/_irm/irm-cms/logoff.aspx"
    sRetour = getSoapRequest(sUrl, "");
    
    if(sRetour == "off")
    {
        window.opener.location.reload(true);
        window.close();
    }
    else
    {
        alert(sRetour);
    }
}

function viloginIRM()
{
    var sUrl = new String("")
    sUrl = "/_irm/irm-cms/viLogin.aspx?xgabarit=irm_login.xsl"
    window.open(sUrl,'','toolbar=no,status=no,titlebar=no,menubar=no,resizable=no,scrollbars=yes,width=450,height=290,left=0,top=0')	
}

function loginIRM()
{

    if(document.getElementById("txtLogin").value == "")
    {
        alert("Vous devez entrer votre nom d'utilisateur");
        return;
    }
    
    if(document.getElementById("txtPasswd").value == "")
    {
        alert("Vous devez entrer votre mot de passe");
        return;
    }
    		
	sUid = document.getElementById("txtLogin").value;
	sPwd = document.getElementById("txtPasswd").value;
	oLanguage = document.getElementById("sltLanguage");
	sLanguage = oLanguage.options[oLanguage.selectedIndex].value;
	
	sUrl = "/_irm/irm-cms/login.aspx?uid=" + sUid + "&pwd=" + sPwd+ "&lang=" + sLanguage;
	sRetour = getSoapRequest(sUrl, "");

	if (sRetour=="OK")
	{
		//alert(sRetour);
		window.opener.location.reload(true);
		window.close();
	}else{
		alert(sRetour);
	}

}

function login(){
	
	if (document.getElementById("pwd").value == document.getElementById("pwd2").value)
	{
		if (document.getElementById("pwd").value.length > 4)
		{
			sPwd = document.getElementById("pwd").value;
			sUid = document.getElementById("uid").value;
			
			sUrl = "/_irm/irm-cms/login.aspx?uid=" + sUid + "&pwd=" + sPwd;
			sRetour = getSoapRequest(sUrl, "");

			if (sRetour=="OK")
			{
				//alert(sRetour);
				location.reload(true);
			}else{
				alert(sRetour);
			}

		}else{
			alert("Votre mot de passe doit contenir plus de 4 caractères.");
		}
	}else{
		alert("Votre mot de passe doit être identique...");
	}
	
}