// JScript File

var xmlHttp;
var tDiv;
var r;

//params srcVal=0,1 or 2, rowID=The row which cause the event. targetID=returned results
function GetBreakingNews(servicePath, targetID, trID) { 
  if(document.getElementById(targetID) != null) {
      tDiv=targetID; 
  }
  r = document.getElementById(trID);
 
  //Get a reference to the browser specific XMLHttpObject.
  //Retruns null if not supported by client browser.
   xmlHttp = GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX functionality! \n To see Breaking News, please update your browser if you wish to see this feature.");
  return;
  }
   
   var url=servicePath;
   //var url="/services/news.asmx/BreakingNews";
    xmlHttp.onreadystatechange= stateChanged;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   //send the paramters to the web service via post method 
    xmlHttp.send('k=xor!');


   //xmlHttp.onreadystatechange= stateChanged;
   //xmlHttp.open("GET",url,true);
   //xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   //send the paramters to the web service via post method 
   //xmlHttp.send(null);
 
}

function stateChanged() {
  if (xmlHttp.readyState==1) {
  //request initialized
   //  document.getElementById(tDiv).innerHTML = "<img src='/images/loading.gif' alt='loading' />"
    }
  
  if (xmlHttp.readyState==2) {
 //request sent
 
  }
  
  if (xmlHttp.readyState==3) {
  //request being processed
 
   }
 
 
    if (xmlHttp.readyState==4) {
      //request is here
                                
                //The div container where the results will be loaded into.
                //Clear the old information
               try 
                {  
                  var docXML = xmlHttp.responseXML; 
                  var root_node = docXML.getElementsByTagName('string').item(0);
                    if(root_node.firstChild.data!='') {
                        document.getElementById(tDiv).innerHTML = ChangeUTF8(root_node.firstChild.data);
                        if(r!=null) { r.style.display = ''; }
                    } 
                         
                }
                catch (err)
                {
                 if(r!=null) { r.style.display = 'none'; }   
                }
              
                   
       
     }
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer //ie7 use XMLHttpRequest()
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function ChangeUTF8(str) {
     var s;
     s = str.replace( new RegExp( "&lt;" ), "<");
     s = str.replace( new RegExp( "&rt;" ), ">");
     return s;   
    }   


function GetUTF8(utftext) {   
        var string = "";   
        var i = 0;   
        var c = c1 = c2 = 0;   
  
        while ( i < utftext.length ) {   
  
            c = utftext.charCodeAt(i);   
  
            if (c < 128) {   
                string += String.fromCharCode(c);   
                i++;   
            }   
            else if((c > 191) && (c < 224)) {   
                c2 = utftext.charCodeAt(i+1);   
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));   
                i += 2;   
            }   
            else {   
                c2 = utftext.charCodeAt(i+1);   
                c3 = utftext.charCodeAt(i+2);   
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));   
                i += 3;   
            }   
  
        }   
  
        return string;   
    }   
  
