﻿// JScript File

function AjaxGetData(url, responseHandler)
{   
    
    if (window.XMLHttpRequest)
     {
         // browser has native support for XMLHttpRequest object
         req = new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
         // try XMLHTTP ActiveX (Internet Explorer) version
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     
     if(req)
     {
         req.onreadystatechange = responseHandler;
         req.open('GET', url, true);
         req.setRequestHeader("content-type","application/x-www-form-urlencoded");
         req.send('');
         
     }
     else
     {
         alert('Your browser does not seem to support XMLHttpRequest.');
     }
 } 
 
function show_handler_login()
 {
           if (req.readyState == 4 ||req.readyState == 'complete')
          {
                              
          var doc=req.responseXML;
           var qty="";
            if (doc.evaluate) {           
                    qty = doc.evaluate("//text()", doc, null,  XPathResult.STRING_TYPE, null).stringValue;
                    //XML Parsing in Mozilla
               }
                else {
                   //XML Parsing in IE
                   qty = doc.selectSingleNode("//text()").data;    
              }
   
// alert("hello " + qty);
   
      var ids=qty.split(';');
    //alert("Login_staus " + ids[0] + "Expert _id " + ids[1]);
        var expid="first" + ids[1];
        var expid_="second" + ids[1];
       
         if(ids[0]=="2")
         {
            document.getElementById(expid).innerHTML = "AVAILABLE"; 
            document.getElementById(expid_).innerHTML = "AVAILABLE"; 
            
            //top
            document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<input name='radiobutton_" + ids[1] + "' checked type='radio' value='1' />"; 
            document.getElementById('radiobutton2_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
            
            //bottom
            
             document.getElementById('radiobutton20_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
             document.getElementById('radiobutton10_'+ids[1]).innerHTML = "<input name='radiobutton30_" + ids[1] + "' checked type='radio' value='1' />"; 
                         
        }
         if(ids[0]=="1")
         {
             document.getElementById(expid).innerHTML = "BUSY"; 
              document.getElementById(expid_).innerHTML = "BUSY"; 
             //top
              document.getElementById('radiobutton2_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
            document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<input name='radiobutton_" + ids[1] + "' checked type='radio' value='1' />"; 
            
           //  document.getElementById('radiobutton2_'+ids[1]).innerHTML = "<input name='radiobutton_" + ids[1] + "' checked type='radio' value='2' />"; 
           //  document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
            //Bottom
             document.getElementById('radiobutton20_'+ids[1]).innerHTML = "<input name='radiobutton30_" + ids[1] + "' checked type='radio' value='2' />"; 
             document.getElementById('radiobutton10_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
         
         }
       if(ids[0]=="0")
         {
               document.getElementById(expid).innerHTML = "STEPPED OUT"; 
                document.getElementById(expid_).innerHTML = "STEPPED OUT"; 
               //top
                 document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
            document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<input name='radiobutton_" + ids[1] + "' checked type='radio' value='1' />"; 
            
               
             //  document.getElementById('radiobutton2_'+ids[1]).innerHTML = "<input name='radiobutton_" + ids[1] + "' checked type='radio' value='2' />"; 
           //    document.getElementById('radiobutton1_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
            //Bottom
             document.getElementById('radiobutton20_'+ids[1]).innerHTML = "<input name='radiobutton30_" + ids[1] + "' checked type='radio' value='2' />"; 
             document.getElementById('radiobutton10_'+ids[1]).innerHTML = "<img src='/images/cross.jpg'>"; 
         }
         
 
        }
      }
  
function show_refresh_login(xval)
{
// alert("User " + xval);
    var randomnumber=Math.floor(Math.random()*11)
    var qry="/exp_profile.asmx/get_expertid?userid="+ xval +"&randno="+randomnumber;
    AjaxGetData(qry, show_handler_login);
}

 function count_login_staus()
 {
show_refresh_login(document.getElementById('expert_id').value);
 // show_refresh_login(109);
 }
setInterval("count_login_staus()",5000);










