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];}
    
}





//check if archive may be load un popup

function checkArchive(){
    
    if(window.document.logarchive != null)
        
        if(window.document.logarchive.addarchive.value=='y')
            
            addArchive();
    
}



//open popup window for archive page confirmation in autoload schem

function addArchiveAutoLoad() {
    
    if(window.document.logarchive != null) {
        
        if(window.document.logarchive.autoloadconfirm.value == 'y') {
            window.document.logarchive.nli.value ="";
            addArchive();
            
        }
        
    }
    
}



//open popup window for archive page confirmation

function addArchive(){
    
    //get ArchiveName and ArchiveIdentifier
    
    var ArchiveName = new String(window.document.logarchive.ArchiveName.value);
    
    var ArchiveIdentifier =new String( window.document.logarchive.ArchiveIdentifier.value);
    
    var ArchiveType =new String( window.document.logarchive.ArchiveType.value);
    
    var Address = "";
    
    if(window.document.sendtofriend.currentzone.value=="zonecatalogue" 
    || window.document.sendtofriend.currentzone.value=="zonelibrairie"
    || window.document.sendtofriend.currentzone.value=="zonedeco"){
        
        address=window.document.URL.substring(0,window.document.URL.indexOf('?')+1 )
        
        ArchiveIdentifier="pre?zone="+window.document.sendtofriend.currentzone.value+"&idEIPub="+window.document.sendtofriend.idEIPub.value+"&idLSPub="+window.document.sendtofriend.idLSPub.value;
        
        //alert(document.URL);
        
        // alert(ArchiveIdentifier);
        
    }
    if( window.document.sendtofriend.currentzone.value=="zonedecostatic")
        {
            ArchiveIdentifier = window.document.URL;
            }
    if(window.document.sendtofriend.currentzone.value=="zoneimpressionsl"){
        
        address=window.document.URL.substring(window.document.URL.indexOf('?')+1,window.document.URL.indexOf('&backurl'))
        ArchiveIdentifier="pre?zone="+window.document.sendtofriend.currentzone.value+"&idEIPub="+window.document.sendtofriend.idEIPub.value+"&idLSPub="+window.document.sendtofriend.idLSPub.value+"&zonetmp=zoneimpressionsl";
        ArchiveType="4";
    }
    
    
    //set name of window for back
    
    //window.name='mainwindow'; 
    
    //open new popup window 
    
    while( ArchiveName.indexOf('è')!=-1){   
        
        ArchiveName=ArchiveName.replace('è','&egrave;');
        
    }
    
    
    
    while( ArchiveName.indexOf('é')!=-1){   
        
        ArchiveName=ArchiveName.replace('é','&eacute;');
        
    }
    
    while( ArchiveName.indexOf('à')!=-1){   
        
        ArchiveName=ArchiveName.replace('à','&agrave;');
        
    }  
    
    while( ArchiveName.indexOf('&')!=-1){   
        
        ArchiveName=ArchiveName.replace('&','%26');
        
    }
    
    // alert('ArchiveName '+ArchiveName);
    
    // ArchiveName = URL.encode(ArchiveName);
    
    // var sURL=new String('srvuserfolderactionrequest?Action=addmemo&ArchiveType='+ArchiveType+'&ArchiveIdentifier='+ArchiveIdentifier+'&ArchiveName='+ArchiveName);
    
    var sURL="";
    if(window.document.logarchive.nli.value =="") {
        sURL= new String('srvuserfolderactionrequest?Action=addmemo&ArchiveType='+ArchiveType+'&ArchiveIdentifier='+ArchiveIdentifier+'&ArchiveName='+ArchiveName);
    }
    else {
        sURL= new String('srvuserfolderactionrequest?Action=addmemo&nli='+window.document.logarchive.nli.value+'&ArchiveType='+ArchiveType+'&ArchiveIdentifier='+ArchiveIdentifier+'&ArchiveName='+ArchiveName);
    }
    
    while( sURL.indexOf(' ')!=-1){   
        
        sURL=sURL.replace(' ','+');
        
    }
    
    while( sURL.indexOf('"')!=-1){  
        
        sURL=sURL.replace('"','&quot;');
        
    }
    
    
    
    //alert(sURL);
    //window.open(sURL,'addmemo','width=600,height=140,resizable=0,toolbar=0,menubar=0,status=0,scrollbars=0');
   //replace previous popup by ajax call
    var beanArchive =  { SArchiveIdentifier:ArchiveIdentifier, 
		  SArchiveName:ArchiveName, SArchiveType:ArchiveType};
    DwrArchivesService.saveArchive(beanArchive, callbackCreateArch);
    	   
}

// need dwrarchive and engine.js contains ajax fonction
function callbackCreateArch(dataz) {
   if (dataz == "doConnect"){
	openArchiveLogin();
   }else if (dataz == "OK"){
	showPopup('archiveAddOk');
   }else{	
	alert("Une erreur est survenue, impossible d'archiver ");
   }
}
// FIN ARCHIVE


//go to archive login or create account page

function openArchiveLogin(){
    // alert("openArchiveLogin");
    //get currenturl for back to this page
    // alert(window.name);
    if(window.document.sendtofriend.currentzone.value!="zonecatalogue"){
        window.document.unlogarchive.urlback.value=window.location.href;
    }
    else {
        window.document.unlogarchive.urlback.value=window.location.href+"&autoloadconfirm=y";
        //  window.document.unlogarchive.ArchiveIdentifier.value=window.document.URL.substring(window.document.URL.indexOf('pre'),window.document.URL.indexOf('&backurl'));
        window.document.unlogarchive.ArchiveIdentifier.value="pre?zone="+window.document.sendtofriend.currentzone.value+"&idEIPub="+window.document.sendtofriend.idEIPub.value+"&idLSPub="+window.document.sendtofriend.idLSPub.value;
        //window.document.unlogarchive.ArchiveType.value="4";
        //alert(window.document.unlogarchive.ArchiveIdentifier.value);
    }
    
    //alert(window.document.unlogarchive.urlback.value);
    
    
    
    
    //launch page archive login
    if(window.document.sendtofriend.currentzone.value=="zoneimpressionsl") {
        //  alert("zoneimpressionsl");
        window.document.unlogarchive.submit();
        window.close();
    }
    else {
        //    alert("pas bien");
        window.document.unlogarchive.submit();
    }
}





//use in zone compte == espace perso.

function checkPopupPseudoForum(){
    
    if(document.fident != null){
        
        if(document.fident.userid != null){
            
            if(document.fident.userid.value.length > 0)
                
                window.open('/mpng2-front/srvforumregistration?useraccounttodo=pseudoforum','pseudoforum','width=400,height=175,resizable=0,toolbar=0,menubar=0,status=0,scrollbars=0');
            
        }
        
    }
    
}



function clearUser() {
    
    if(document.clearuser != null){
        
        document.clearuser.currenturl.value=window.location.href;
        
        document.clearuser.submit();
        
    }
    
}



//utilisé dans la page des infos perso

function checkPseudoForumAlreadyUsed(){
    if(document.personalaccount!=null) {
        var sError = document.personalaccount.msgpseudoforumalreadyused.value;
        
        var sPseudo = document.personalaccount.pseudomixad.value;
        
        var sURL = '/mpng2-front/srvpersondataupdatesubmit?useraccounttodo=pseudoforum&error=' + sError + '&pseudomixad=' + sPseudo;
        
        if(document.personalaccount != null){
            
            if(document.personalaccount.pseudoforumalreadyused != null){
                
                if(document.personalaccount.pseudoforumalreadyused.value == 'y')
                    
                    window.open(sURL,'pseudoforum','width=400,height=175,resizable=0,toolbar=0,menubar=0,status=0,scrollbars=0');
                
            }
        }
    }
    
}



function clearText(thefield){
    
    if (thefield.defaultValue==thefield.value)
        
        thefield.value = ""
        
} 


function MM_openBrWindow(theURL,winName,features) { 
    window.open(theURL,winName,features);
}



function submitLink(chapitre) { 
    stmp = window.location.href;
    
    if(stmp.indexOf('#')>0)
        stmp = stmp.substring(0,stmp.indexOf('#'));
    
    itmp = stmp.indexOf('chapitre=');
    if(itmp >= 0) {
        surl = stmp.substring(0,itmp+9)+chapitre;
        if(stmp.indexOf(itmp,'&')>0) {
            surl = surl+stmp.substring(stmp.indexOf('&',itmp));
        }
    }
    else {
        surl = stmp+'&chapitre='+chapitre;
    }
    window.location.href=surl;
    
}

function submitLinkPopup(chapitre,alt,target,h,w) {
    stmp = window.location.href;
    
    if(stmp.indexOf('#')>0)
        stmp = stmp.substring(0,stmp.indexOf('#'));
    
    itmp = stmp.indexOf('chapitre=');
    if(itmp >= 0) {
        surl = stmp.substring(0,itmp+9)+chapitre;
        if(stmp.indexOf(itmp,'&')>0) {
            surl = surl+stmp.substring(stmp.indexOf('&',itmp));
        }
    }
    else {
        surl = stmp+'&chapitre='+chapitre;
    }
    surl=surl+"&zonetmp=zonepopup";
    var winl = (screen.width - 800) / 2;
    var wint = (screen.height - 600) / 2;
    window.open(surl,target,"height="+ h + ",width="+ w +",top=" + wint + ",left=" + winl + ",resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1").focus();
    
}

function PopupImage(img) { 
    titre="Agrandissement"; 
    var top=30;
    var left=30;
    w=open("",'image','top='+top+',left='+left+',width=400,height=400,toolbar=no,scrollbars=no,resizable=yes'); 
    w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>"); 
    w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+30); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>"); 
    w.document.write("<BODY onload='checksize()'   leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>"); 
    w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>"); 
    w.document.write("<TD valign='middle' align='center'><IMG src='"+img+"' border=0 alt=''>"); 
    w.document.write("</TD></TR></TABLE>"); 
    w.document.write("</BODY></HTML>"); 
    w.document.close(); 
} 

function ouvrir_popup(lien,alt,target,h,w) {			
    var winl = (screen.width - 800) / 2;
    var wint = (screen.height - 600) / 2;
    window.open(lien,target,"height="+ h + ",width="+ w +",top=" + wint + ",left=" + winl + ",resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1").focus();
}	

function openHelp(){
    sURL = "/html/1visite/index.html"
    fOpenNewWindow = false;
    fOpenPopUp = false ;
    var option = 'resizable=yes, resizable=1, location=no, menubar=no, status=no, scrollbars=no, menubar=no, width=800,height=800';
    window.open(sURL,'',option);
}
