﻿
 function openLiveChat(domain) {
    if(domain == '' || domain == undefined){
       domain = 'www.messagelabs.co.uk';
    }
    window.open('http://' + domain +'/LiveChat.aspx?domain=' + domain ,'LiveChat','width=480,height=360,toolbar=no,scrollbars=no,location=no,resizable=no');
  }  
 
  function openSupportChat(domain)
 {
    if(domain == '' || domain == undefined){
       domain = 'support.messagelabs.co.uk';
    }
    window.open('http://sandbox.messagelabs.com/SupportChat.aspx?domain=' + domain ,'LiveSupportChat','width=480,height=360,toolbar=no,scrollbars=no,location=no,resizable=no');
  }  

 
 
 //Call the server code to display the correct live chat button
        function CallServerForLiveChatStatus(){
            CallServerForLiveChatStatus('en-GB');        
        }
        
        //Call the server code to display the correct live chat button
        function CallServerForLiveChatStatus(culture){

          var url= 'LiveChatOperatorStatus.get?culture='+ culture + '&rand=' + new Date().getTime();
          var req = newXMLHttpRequest_ForChat();
          
          var callbackHandler = getReadyStateHandler_ForChat(req, culture);
          
          req.onreadystatechange = callbackHandler;
          req.open("GET", url, true);
          req.setRequestHeader("Content-Type", "text/xml");
      
          req.send("");
        }
        
        //create a XmlHttp object
        function newXMLHttpRequest_ForChat() {
        var xmlreq = false;
        //if support XmlHttp, then create the XmlHttp object
        if (window.XMLHttpRequest) {
	        xmlreq = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
		        // judge whether to support the XmlHttp ActiveX
	        try { 
		        xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch (e1) { 
		        // fail in creaing the first ActiveX control
		        try {
			        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
		        } catch (e2) {
			         // both failed, then return false
		        } 
	        }
        }
        return xmlreq;
        } 

        //the server side callback function
        function getReadyStateHandler_ForChat(req, isSupport) {
	        return function () {
	        if (req.readyState == 4) {//already loaded
		        if (req.status == 200) {//return successfully
		         
		           if(isSupport == 'support'){
    		        if(req.responseText == "True"){
    		            document.getElementById("supportChatGB").style.display = 'inline'; 
    		            document.getElementById("supportChat").style.display = 'inline';
		                document.getElementById("supportChatOffline").style.display = 'none';
		                document.getElementById("headerChatDisplay").style.display = 'inline';
    		        }else{
    		            document.getElementById("supportChatGB").style.display = 'none'; 
    		            document.getElementById("supportChat").style.display = 'none';
		                document.getElementById("supportChatOffline").style.display = 'inline';
		                document.getElementById("headerChatDisplay").style.display = 'none';
    		        }
    		        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
                        var ieversion=new Number(RegExp.$1) 
                         if (ieversion==6 || ieversion==7){
                            document.getElementById("headerChatDisplay").style.display = 'none';
                        }
                     }
		           }
		           else if(isSupport == 'support_homepage'){
		          
                  
    		        if(req.responseText == "True"){
    		            document.getElementById("headerChatDisplay").style.display = 'inline';
    		        }else{
    		            document.getElementById("headerChatDisplay").style.display = 'none';
    		        }
    		        
    		         if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
                        var ieversion=new Number(RegExp.$1) 
                         if (ieversion==6 || ieversion==7){
                            document.getElementById("headerChatDisplay").style.display = 'none';
                        }
                     }
                    
    		         
		           }
		           else
		           {
		           if (document.getElementById('liveChat')) {
		  
		                if(req.responseText == "True"){		            
    		                document.getElementById("liveChat").style.display = 'block';
		                    document.getElementById("contactSales").style.display = 'none';
    		            }else{
		                   document.getElementById("liveChat").style.display = 'none';
		                    document.getElementById("contactSales").style.display = 'block';
		                }
		              }
		            }
		          } 
    	        }
 	        }
        }
        
       
