//Definir Array com as pessoas de suporte
function SupportUser(name, status){
     this.name = name
     this.status = status
}
var supportUserArray = new Array(7);
supportUserArray[0]= new SupportUser("rsolipa",0);
supportUserArray[1]= new SupportUser("pfreitas",0);
supportUserArray[2]= new SupportUser("ipina",0);
supportUserArray[3]= new SupportUser("cpestana",0);
supportUserArray[4]= new SupportUser("ruferreira",0);
supportUserArray[5]= new SupportUser("esousa",0);
supportUserArray[6]= new SupportUser("acosta",0);

//Criar links invisiveis para os utilizadores
function writeHiddenQueueMembers() {
     for (var i =0;i<supportUserArray.length;i++)    {
         writeSametimeLink(supportUserArray[i].name,supportUserArray[i].name,true,"icon:no;onlineStyle:stHideLink;offlineStyle:stHideLink")
     }
}
function checkLoggedUsers() {
    var showSupportUser = false;
    var busyUser	= false;

    for (var i =0;i<supportUserArray.length;i++){
	//alert("name="+supportUserArray[i].name+" status="+supportUserArray[i].status);
    	 if (supportUserArray[i].status == 32){
	     	showSupportUser = true;
            break;
         }

	 if(!busyUser && supportUserArray[i].status != 32 && supportUserArray[i].status != 0){
	  	busyUser	= true;	
	 }
    }   
    if (showSupportUser){
    
    
    	document.all.chatInicial.className="HideSupportLink";
        document.all.chatLink.className="ShowSupportLink";
        document.all.chatNoLink.className="HideSupportLink";
	document.all.chatBusy.className="HideSupportLink";
    }
    else if(!busyUser){
    	document.all.chatInicial.className="HideSupportLink";
    	document.all.chatLink.className="HideSupportLink";
        document.all.chatNoLink.className="ShowSupport";
	document.all.chatBusy.className="HideSupportLink";
    }
    else{	
	//alert("estão todos ocupados!");
	document.all.chatInicial.className="HideSupportLink";
    	document.all.chatLink.className="HideSupportLink";
        document.all.chatNoLink.className="HideSupportLink";
	document.all.chatBusy.className="ShowSupport";
	setTimeout('checkLoggedUsers()',10000);
    }
}

//Quando algum user estiver logado
function STLinksUserStatusChanged(userId, displayName, status, statusMessage){
	   for (var i =0;i<supportUserArray.length;i++){
         if (supportUserArray[i].name.toLowerCase() == userId){
         	supportUserArray[i].status = status;
		    break;
         }   
     }
     checkLoggedUsers();
  }


//Inicar conversacao com o utilizador que estiver logado     
function chatwithSupportUser(){
	respondido=false;
     for (var i =0;i<supportUserArray.length && !respondido;i++){
	 //alert("nome="+supportUserArray[i].name+" status="+supportUserArray[i].status)
         if (supportUserArray[i].status == 32){
      	   STLinksCreateIM(supportUserArray[i].name.toLowerCase())
      	   respondido=true;
         }
      }
      if( ! respondido){
      	alert('Neste momento não podemos satisfazer o seu pedido. Por favor tente mais tarde.');
      }
}

