/*v5.5 Implémentation AJAX*/
var dialNotify;
var dialLstPollTimer;

//MAJ du statut
function updateStatus(new_status)
{
	self.location = '../dial/c-naps_lstconnect.phpo?new_status='+new_status;
}

//Demarrage du polling liste
function checkDialMsgConStart()
{ 
	dialLstPollTimer = new PeriodicalExecuter(checkDialMsgCon, 25);
	checkDialMsgCon(1);
}

//Méthode qui sera appelée sur le setTimeOut : check nouvelles infos dial (nouveau message / nouveau contact connecté)
function checkDialMsgCon(forced_update) 
{
   new Ajax.Request('/dial/c-naps_poll_global.php',
      {
        method:'post',
		parameters: {forced_update: forced_update},
        onSuccess: function(transport) { checkDialMsgConProcess(transport) },
        onFailure: function(){ if(debug_status == 1) { alert('DBUG : Erreur xmlHttpRequest, appel echoue checkDialMsgCon...') } }
      });
}

function checkDialMsgConProcess(httpRequest) 
{
      var json_datas = httpRequest.responseText.evalJSON(false);
     
      nb_msg	     = json_datas['nbmsg'];
      nb_contact	 = json_datas['nb_contact'];
      notify_ankey   = json_datas['notif_an_key'];
      notify_pseudo  = json_datas['notif_pseudo'];
      notify_infos   = json_datas['notif_infos'];
      notify_photo   = json_datas['notif_photos'];	
      notify_txt   	 = json_datas['notif_txt'];	
      notify_titre   = json_datas['notif_titre'];	
      notification_msg_nb = json_datas['notification_msg_nb'];

      //Affichage de la zone de notification
      if(notify_ankey || notify_txt) 
      {
   			switch(notify_infos)
       		{
       		    //Alerte consultation fiche
   				case 'alertefiche':
   				
						if(IContact_frameset == 1)
						{
							notifyStart ("Consultation de votre fiche", "<a href=\"#\" onClick=\"top.liste.annu_view_detail('"+notify_ankey+"', '"+IContact_idsite+"')\" class='dialNotificationLink'>"+notify_photo+"<span style='color:black'>"+notify_pseudo+"</span><br>est en train de consulter votre fiche</a>", 15000);
						}
						else
						{
							notifyStart ("Consultation de votre fiche", "<a href=\"#\" onClick=\"annu_view_detail('"+notify_ankey+"', '"+IContact_idsite+"')\" class='dialNotificationLink'>"+notify_photo+"<span style='color:black'>"+notify_pseudo+"</span><br>est en train de consulter votre fiche</a>", 15000);
						}   				
   				
   				break;
   				
       		    //Mailing
   				case 'mailing':
   				
						notifyStart (notify_titre, notify_photo+notify_txt, 30000);
   				
   				break;
   				
   				//Classique, msgDial
   				default:
   				
						if(IContact_frameset == 1)
						{
							notifyStart ("Nouveau message dialogues", "<a href=\"#\" onClick=\"top.liste.liste_dials.dialOpen('"+notify_ankey+"', '"+IContact_idsite+"')\" class='dialNotificationLink'>"+notify_photo+"Vous avez reçu un nouveau message en dialogue de <br><span style='color:black'>"+notify_pseudo+"</span></a>", 15000);						
						}
						else
						{
							//notifyStart ("Nouveau message dialogues", "<a href=\"#\" onClick=\"top.liste_dials.dialOpen('"+notify_ankey+"', '"+IContact_idsite+"')\" class='dialNotificationLink'>"+notify_photo+"Vous avez reçu un nouveau message en dialogue de <br><span style='color:black'>"+notify_pseudo+"</span></a>", 15000);						
							notifyStart ("Nouveau message dialogues", "<a href=\"#\" onClick=\"top.dialOpen('"+notify_ankey+"', '"+IContact_idsite+"')\" class='dialNotificationLink'>"+notify_photo+"Vous avez reçu un nouveau message en dialogue de <br><span style='color:black'>"+notify_pseudo+"</span></a>", 15000);						
						}     				
						
   				break;
       		}
      }
      
      //MAJ filinfo
      /*
      //filinfo		 = json_datas['filinfo'];

      if(filinfo != -1 && top.$('divInfosContent'))//Si fil info actif
      {
	      	if(filinfo != '')
	      	{
	      		//MAJ info
	      		top.$('divInfosContent').update(filinfo);
	      	}
	      	else
	      	{
	      		//Pas d'info, on masque pour la session
	      		top.$('divInfos').style.display = 'none';
	      	}
      }
      */
      
      //MAJ conversations
      if (nb_msg && nb_msg > 0) 
      {
   		  	//On met toujours le nb a jour
   			if(parent.$('listeConvInfosNb'))
   			{
   				parent.$('listeConvInfosNb').update(nb_msg);
   			}
   			      
          	//Affichage de l'alerte message
          	if(notify_ankey && notify_infos != 'alertefiche') 
          	{
	       			//Nouveau message, on envoie le son
	   				var sound_file = 'averto.swf';
	   				if(sound_activated != '') 
	   				{
	   						$('sound').update('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="2" height="2" id="averto" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+sound_file+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'+sound_file+'" quality="high" bgcolor="#ffffff" width="2" height="2" name="averto" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
					}
					
	   				//On affiche le nb
	   				if(parent.$('listeConvInfos'))
	   				{
							if(IContact_frameset == 1)
							{
								parent.$('listeConvInfos').update('<span onClick="top.liste.liste_dials.dialOpen('+notify_ankey+', '+IContact_idsite+')"><span class="nbmessagelire" id="listeConvInfosNb">'+nb_msg+'</span> messages à lire</span>');
							}
							else
							{
								//parent.$('listeConvInfos').update('<span onClick="top.liste_dials.dialOpen('+notify_ankey+', '+IContact_idsite+')"><span class="nbmessagelire" id="listeConvInfosNb">'+nb_msg+'</span> messages à lire</span>');
								parent.$('listeConvInfos').update('<span onClick="top.dialOpen('+notify_ankey+', '+IContact_idsite+')"><span class="nbmessagelire" id="listeConvInfosNb">'+nb_msg+'</span> messages à lire</span>');
							}    				
	   				}

	   				if(parent.$('listeConvInfosNb'))
	   				{
		   				parent.$('listeConvInfosNb').update(nb_msg);
	   				}

	   				if(parent.$('dialMsgAlertTxt'))
	   				{
						if(IContact_frameset == 1)
	    				{
	    					parent.$('dialMsgAlertTxt').update('<a href="javascript:;" onClick="top.liste.liste_dials.dialOpen('+notify_ankey+', '+IContact_idsite+');">'+nb_msg+' message(s) en attente</a>');
	    				}
	    				else
	    				{
	    					//parent.$('dialMsgAlertTxt').update('<a href="javascript:;" onClick="top.liste_dials.dialOpen('+notify_ankey+', '+IContact_idsite+');">'+nb_msg+' message(s) en attente</a>');
							parent.$('dialMsgAlertTxt').update('<a href="javascript:;" onClick="top.dialOpen('+notify_ankey+', '+IContact_idsite+');">'+nb_msg+' message(s) en attente</a>');
	    				}
	   				}
          	} 


      } 
      else 
      {
      		if(parent.$('listeConvInfos'))
      		{
				if(IContact_frameset == 1)
				{
					parent.$('listeConvInfos').update('<span onClick="top.liste.liste_dials.dialOpen(\'\',\''+IContact_idsite+'\')"><span id="listeConvInfosNb" class="nbmessagelire">0</span> messages à lire</span>');
				}
				else
				{
					//parent.$('listeConvInfos').update('<span onClick="top.liste_dials.dialOpen(\'\',\''+IContact_idsite+'\')"><span id="listeConvInfosNb" class="nbmessagelire">0</span> messages à lire</span>');
					parent.$('listeConvInfos').update('<span onClick="top.dialOpen(\'\',\''+IContact_idsite+'\')"><span id="listeConvInfosNb" class="nbmessagelire">0</span> messages à lire</span>');
				}      		          		
         	}
         	
			if(parent.$('listeConvInfosNb'))
    		{
				parent.$('listeConvInfosNb').update(0);
    		}
    		
    		if(parent.$('dialMsgAlertTxt'))
   			{
				if(IContact_frameset == 1)
				{
					parent.$('dialMsgAlertTxt').update('Aucun message en attente');
				}
				else
				{
					parent.$('dialMsgAlertTxt').update('Aucun message en attente');
				}
    		}
         	
      }
      
      //MAJ contacts
      if (nb_contact > 0) 
      {      
   			if(parent.$('listeContactInfos'))
   			{
       			parent.$('listeContactInfos').update('<span class="nbcontactligne">'+nb_contact+'</span> contact(s) en ligne');
   			}

   			if(parent.$('nbContactOnline'))
   			{
   				parent.$('nbContactOnline').update(nb_contact);
   			}
      } 
      else 
      {
   			if(parent.$('listeContactInfos'))
   			{
       			parent.$('listeContactInfos').update('<span class="nbcontactligne" >0</span> contact(s) en ligne');
   			} 

   			if(parent.$('nbContactOnline'))
   			{
   				parent.$('nbContactOnline').update(0);
   				
   			}
      }
      
      //Notifications msg      
	  if(top.$("notificationsMsgNb"))
	  {
	  		top.$("notificationsMsgNb").update(notification_msg_nb);
	  }      
}


//Version sans ajax (en attendant qu'ie regle son pb de cache)
function checkDialLst(new_tri, forced_update) 
{
	 self.location = '../dial/c-naps_lstconnect.phpo?new_tri='+new_tri+'&forced_update='+forced_update;
}

//Fonctions XML
function xmlCleanerGo(c){
    if(!c.data.replace(/\s/g,''))
    			c.parentNode.removeChild(c);
}

function xmlClean(d){
    var bal=d.getElementsByTagName('*');
    
    for(i=0;i<bal.length;i++){
        a=bal[i].previousSibling;
        if(a && a.nodeType==3)
        		 xmlCleanerGo(a);
        b=bal[i].nextSibling;
        if(b && b.nodeType==3)
        		 xmlCleanerGo(b);
    }
    return d;
} 
//Fin fonctions XML

function stripslashes(ch) {
   return ch.replace(/(\\)([\\\'\"])/g,"$2")
}

//Gestion agrandissement femrmeture sections de la liste
function lstExpandCollapse (id_suffix) 
{
	var browser = navigator.appName;
	if (browser == "Netscape")
	{
		if ( document.getElementById("liste"+id_suffix+"Line").style.visibility == "hidden" ) 
		{
			document.getElementById("liste"+id_suffix+"Line").style.visibility = "visible";
			document.getElementById("liste"+id_suffix+"Line").style.height = "auto";
			document.getElementById("liste"+id_suffix+"Titre").className = "lstTitreActive";
		} else {
			document.getElementById("liste"+id_suffix+"Line").style.visibility = "hidden";
			document.getElementById("liste"+id_suffix+"Line").style.ove = "0";
			document.getElementById("liste"+id_suffix+"Titre").className = "lstTitre";
		}
	}
	else
	{
		if ( document.getElementById("liste"+id_suffix+"Line").style.display == "none" ) {
			document.getElementById("liste"+id_suffix+"Line").style.visibility = "visible";
			document.getElementById("liste"+id_suffix+"Titre").className = "lstTitreActive";
			document.getElementById("liste"+id_suffix+"Line").style.display = "block";
		} else {
			document.getElementById("liste"+id_suffix+"Line").style.visibility = "hidden";
			document.getElementById("liste"+id_suffix+"Titre").className = "lstTitre";
			document.getElementById("liste"+id_suffix+"Line").style.display = "none";
		}
	}
}



//MAJ et affichage de la zone de notification
function notifyStart (titleVal, txtVal, timeOutEnd) 
{
	 top.document.getElementById("notificationTitre").innerHTML = titleVal;
	 top.document.getElementById("notificationTxt").innerHTML = txtVal;	 
	 top.document.getElementById("notification").style.visibility = "visible";
     //Pour pas qu'il y ait multiplication des checkTimeout
     clearTimeout(dialNotify);
	 dialNotify = setTimeout('notifyEnd ()', timeOutEnd);	
}
function notifyEnd () 
{
     //Pour pas qu'il y ait multiplication des checkTimeout
     clearTimeout(dialNotify);
	 top.document.getElementById("notification").style.visibility = "hidden";
}

//Filtres de liste
function dialLstFiltre(filtre_type) 
{
	 action.location = "../dial/c-naps_liste_filtre_maj.php?filtre_type="+filtre_type;
}

//Fonctions d'ouverture de fenetres
function dialOpen(an_key, winname) 
{
	 //Gestion de l'ascenceur ou non fonction de la resolution
	 if(screen.width <= 900) 
	 {
	 			//800*600
	 			var scrollbar_val = 'yes';
				var win_width     = 656;
				var win_height 		= 510;
	 }  else {
	 			//1024 et +
	 			var scrollbar_val = 'no';
				var win_width     = 656;
				var win_height 		= 722;//667
	 }

	 window.open('../dial/c-naps_dial.php?dial_ref_dest='+an_key,'cnaps_dial_'+winname,'resizable=no,toolbar=no,menubar=no,statusbar=no,scrollbars='+scrollbar_val+',left='+(screen.width-win_width)/2+',top='+(screen.height-win_height)/2+',width='+win_width+',height='+win_height);	
}

//Fonctions d'ouverture de fenetres
function balOpen(pseu_dest) 
{
	window.open('../bal/ecrire_msg.php?pseu_dest='+pseu_dest,'','resizable=yes,toolbar=no,menubar=no,statusbar=no,scrollbars=no,width=560,height=537,left='+(screen.width-560)/2+',top='+(screen.height-537)/2+'');
}

//Fonctions d'ouverture de fenetres
function contactOpen() 
{
	window.open('../contacts/contact_liste.php','','width=300,height=390,top='+(screen.height-300)/2+',left='+(screen.width-390)/2);
}

//Clic sur icone profil
function ficheOpen (an_key) 
{
				 annu_view_detail(an_key, '');
}

//Ouverture de galerie photo
function photoOpen (an_key) 
{
				 docs_aff_lst(an_key,'');
}

//Fonctions d'ouverture de fenetres
function dialLstFiltreOpen() 
{
	window.open('../dial/c-naps_liste_filtre_form.php','select_tri','toolbar=no,menubar=no,statusbar=no,scrollbars=yes,width=480,height=580,left='+(screen.width-480)/2+',top='+(screen.height-580)/2+'');
}

function openPopup(url, winName, myWidth,myHeight, scrollbarVal) 
{
	 if (!scrollbarVal)
     		scrollbarVal = "no";
     window.open(url, winName,'resizable=yes,toolbar=no,menubar=no,statusbar=yes,scrollbars='+scrollbarVal+',left='+(screen.width-myWidth)/2+',top='+(screen.height-myHeight)/2+',width='+myWidth+',height='+myHeight+'');
}

function dialShowMinPho(ID_doc, an_key, ID_licence) 
{
     if($('phod'+an_key).innerHTML == '')
     {
     	  div_load_content ('phod'+an_key, '/dial/c-naps_liste_show_doc_min.php?id_doc='+ID_doc+'&an_key='+an_key);
     }	
	 $('phod'+an_key).style.visibility = 'visible';
}      

function dialHideMinPho(an_key) 
{
	 $('phod'+an_key).style.visibility = 'hidden';
} 

/*
//Fermeture d'une conversation
function convEnd(dial_ref_dest) 
{
		parent.action.location = "../dial/c-naps_conv_close.php?action=2&dial_ref_dest="+dial_ref_dest;
}
*/

