﻿// JScript File
// external js file:
var rwc_ids=null;
// called when this HTML page is loaded in browser; see <body>
function initlinks(){
    if(rwc_ids==null) {
        return;
    }
	var head=document.getElementsByTagName('head').item(0);
    for(i=0;i<rwc_ids.length;i++){
        // called to fetch the current status from the server
	    var script=document.createElement('script');
	    script.type='text/javascript';
	    script.id='myscript'+i;
	    script.defer=true;
	    script.src='http://'+rwc_server+'/status/js?im='+rwc_ids[i];
	    head.appendChild(script);
    }
}
// called when the server responds to the fetch with the status
function rwc_statusUpdated(pid,status)
    {
    
    var fontsize = readCookie("fontsize");
    
	var o=document.getElementById("rwc_id_"+pid.replace(/\@/g,":"));
	if(o){
		var html='';
		var sPath= new String(window.location); // the whole background image swapping out dependent on the state of the chat --- this is MN only so I'm kind of hacking in something for the path issue.
        var sImg = '';
        if(sPath.indexOf("/auth/")>0)
            sPath = "."
        else
            sPath = "";
        switch(status)
	        {
	        
	        
	        
	        
	        case 'online':
	        {
	        html += '<a href="#" onclick=\'javascript:window.open("prechatform.aspx?fontsize='+ fontsize +'","rev_chatPopupWindow","scrollbars=yes,menubar=no,status=no,resizable=no,location=yes,width=450,height=452,left=200,top=100");return false;\'>';
	        //html+='<a href="#" onclick=\'javascript:window.open("https://'+rwc_server+'/chat/?im='+pid+'","rev_chatPopupWindow","scrollbars=no,menubar=no,status=no,resizable=no,location=no,width=450,height=452,left=200,top=100");return false;\'>';
	        html+='<img src="'+strImgOnline+'" alt="'+strOnline+'"></a>';
	        if (document.getElementById('header'))
	            {
	            sImg = "url(" + sPath + "./images/specialist1.jpg)";
	            document.getElementById('header').style.backgroundImage = sImg;
			    document.getElementById('header').style.backgroundRepeat = "no-repeat"; 
			    document.getElementById('header').style.backgroundPosition = "right top";
			    }
			
	        break;
    	    }
	        //case 'busy':
	        //case 'onthephone': 
	        //case 'berightback': 
	        //case 'outtolunch': 
            case 'minnesota is not using busy right now':
	        {
	        html+='<img src="'+strImgBusy+'" alt="'+strBusy+'">';
	        if ( document.getElementById('header') )
			    {
			    sImg = "url(" + sPath + "./images/specialist1.jpg)";
                document.getElementById('header').style.backgroundImage = sImg;
			    document.getElementById('header').style.backgroundRepeat = "no-repeat"; 
			    document.getElementById('header').style.backgroundPosition = "right top";

			    }
			 	        
			 break;
            }
            case 'busy':
	        case 'onthephone': 
	        case 'berightback': 
	        case 'outtolunch': 
	        case 'away':
	        case 'offline': 
	        case 'declined':
	        default:
	        {
	        html+='<a target="_blank" href="https://'+rwc_server+'/'+rwc_emailform+'">';
		    html+='<img src="'+strImgOffline+'" alt="'+strOffline+'"></a>';
			if (document.getElementById('header'))
              {
              sImg = "url(" + sPath + "./images/specialist2.jpg)";
			  document.getElementById('header').style.backgroundImage = sImg;
			  document.getElementById('header').style.backgroundRepeat = "no-repeat"; 			        
			  document.getElementById('header').style.backgroundPosition = "right top";
			  }
		    break;
		    }
	       } // end switch 
	        
		o.innerHTML=html;
	}
}



// called to write a clickable link into the document
function rwc_writeLink(pid){
    if(rwc_ids==null)
        rwc_ids=new Array();
    rwc_ids[rwc_ids.length]=pid;
    document.write("<span id='rwc_id_"+pid.replace(/\@/g,":")+"'><img alt='Loading Status...' src='images/offline.gif' /></span>");    
}


