/**
 * Author: Akshay Bhurtun
 * Date: 12 Feb 2009
 *
 * ConnectionUtils list of utils function related to connecting to a server
 *
 * $Id: ConnectionUtils.js,v 1.1 2009/02/23 05:55:12 vpulla Exp $
 */


function ConnectionUtils()
{}


ConnectionUtils.getXmlHttpObject=function getXmlHttpObject()
{
   var objXmlHttp=null;

   if (navigator.userAgent.indexOf("Opera")>=0)
   {
      alert("This example doesn't work in Opera")
      return;
   }
   else if (navigator.userAgent.indexOf("MSIE")>=0)
   {
      var strName="Msxml2.XMLHTTP";
      if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
      {
         strName="Microsoft.XMLHTTP";
      }
      try
      {
         objXmlHttp=new ActiveXObject(strName);
      }
      catch(e)
      {
         alert("Error. Scripting for ActiveX might be disabled");
         return;
      }
   }
   else if (navigator.userAgent.indexOf("Mozilla")>=0)
   {
      objXmlHttp=new XMLHttpRequest();
      if (objXmlHttp.overrideMimeType)
      {
         objXmlHttp.overrideMimeType('text/xml');
      }
   }
   return objXmlHttp;
}

/**
 * Utils method to invoke a server through JS RPC
 */
ConnectionUtils.invokeServerViaRPC = function invokeServerViaRPC(scriptId, scriptSrc)
{
   var head=document.getElementsByTagName('head').item(0);
   var script=document.createElement('script');
   
   script.id=scriptId;
   script.src=scriptSrc + "&scriptId=" + scriptId;
   script.type='text/javascript';
   script.defer=true;
   void(head.appendChild(script));
}

