/***********************************************
 * ObjectCode JScript Core
 ***********************************************
 * The Found Corporation 2008
 ***********************************************/

//--------------------------------------------------
// Detect Browsers
//--------------------------------------------------
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
/***************************************************
 * BrowserDetect.browser
 * BrowserDetect.version
 * BrowserDetect.OS
 ***************************************************/

//--------------------------------------------------
// Get XML HTTP Request Object
//--------------------------------------------------
function getXmlHttpRequestObject() {
    /* Create a new XMLHttpRequest object to talk to the Web server */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    @end @*/
    
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

//--------------------------------------------------
// Do XML Request
//--------------------------------------------------
function doRequest(url,ajax_tagid) 
{
    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
    {       
        try {
            receiveReq.open("GET", url, true);
            
           receiveReq.onreadystatechange=function() {
               if (receiveReq.readyState==4) {
               
            	if (ajax_tagid == 'content')
            	ajax_tagid = 'trigger';
            	
                Element.update(ajax_tagid,receiveReq.responseText);
               }
            }
            receiveReq.send(null); 
        }
        catch (e) {
            alert("xml:http request failure to url "+url);
        }
    }
}

//--------------------------------------------------
// Do LONG XML Request
//--------------------------------------------------
function doLongRequest(ajax_url,ajax_params,ajax_tagid) 
{
    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
    {       
        try {
            receiveReq.open("POST", ajax_url);
            receiveReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            receiveReq.send(ajax_params); 
            
            receiveReq.onreadystatechange=function() {
               if (receiveReq.readyState==4) {
               
            	if (ajax_tagid == 'content')
            	ajax_tagid = 'trigger';
            	
                Element.update(ajax_tagid,receiveReq.responseText);
               }
            }
        }
        catch (e) {
            alert("xml:http request failure to url "+url);
        }
    }
}


//--------------------------------------------------
// Handle Name and Value XML Pairs
//--------------------------------------------------
function complainIE(name)
{
    switch(name)
    {
        case 'head':
            var msg = "<h1 style='color:#00FF00;text-decoration:blink;'> <a href='http://www.mozilla.com/en-US/firefox/' style='color:#00FF00;text-decoration:blink;' target='_blank'><span style='color:#00FF00;text-decoration:blink;'> &nbsp;&nbsp;Upgrade to FireFox (HIGHLY RECOMMENDED)</span></a></h1>";
            return msg;
        break; 
        case 'alert':
            if (BrowserDetect.browser == 'Explorer')
            {
            var msg = 'ATTENTION: You are using Internet Explorer '+BrowserDetect.version+
                      "\n\n"+'It is HIGHLY recommended that you upgrade to FireFox and use it'+
                      ' as your default web-browser.'+"\n\n"+'Found Corp. suggests this to all clients'+
                      ' because Internet Explorer currently has many open security vulnerabilities which'+
                      ' can be exploited by mailicious script writers.  Since this admin utility gives an authenticated user full administrative control over this website, it would be a very bad thing if the login to this website got into the wrong hands.  '+
                      ' Internet viruses are currently circulating for Internet Explorer that may make it possible for someone to compromise its data; and by doing so, also compromise the security of this website.'+
                      "\n\n"+'The features of this admin tool will work normally until you upgrade, but we would really appreciated it if you did!';
            alert (msg);
            }
            return;
        break;
    }
}

//--------------------------------------------------
// Handle Name and Value XML Pairs
//--------------------------------------------------
function handleData(name,value)
{
   var update = true;
   switch(name)
   {
       case 'content':
           return value;
       break; 
   }
   if(update) update_element(name,value);
   return true;
}

//--------------------------------------------------
// Handle Receiving Response Text for IE
//--------------------------------------------------
function handleReceiveRequest(url,ajax_tagid)
{
    //  0      Uninitated
    //  1      Loading
    //  2      Loaded
    //  3      Interactive
    //  4      Complete
    
    if (receiveReq.readyState == 4)
    {
            if (receiveReq.responseText)
                textResponse = receiveReq.responseText;
            else
                alert("No XML Response was received");
            
            Element.update(ajax_tagid,textResponse);
            return textResponse;
    } 
return false;
mTimer = setTimeout('Element.update(ajax_tagid,textResponse)',10000);
}

//--------------------------------------------------
// Handle Receiving XML Request for IE
//--------------------------------------------------
function handleXMLReceiveRequest(url)
{
    //  0      Uninitated
    //  1      Loading
    //  2      Loaded
    //  3      Interactive
    //  4      Complete
    
    if (receiveReq.readyState == 4)
    {
        var xmldoc = receiveReq.responseXML.documentElement;
        var root_node = xmldoc.getElementsByTagName('root').item(0);
        var nodes     = root_node.childNodes;
        var n         = nodes.length;
       
        for (i = 0; i < n; i++)
        {
            var node  = nodes[i];
            var name  = node.nodeName;
            var value = '';
            if(node.firstChild) value = node.firstChild.nodeValue;
            //alert(name + '=' + value);
            handleData(name,value);        
        }        
    return;
    } 
//mTimer = setTimeout('handleReceiveRequest()',10000);
}

//--------------------------------------------------
// Get Element by ID
//--------------------------------------------------
function getElement(id)
{
      var element = 0;
      if(document.getElementById)
      {
          element = document.getElementById(id);
      }
      else if (document.all)
      {
          element = document.all[id];
      }
      return element;
}