String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
var sFinalObject;
var refControlObject;

function DisplayTrackingControl(object_id, network_id, width, height, align, border, color_index, login, password)
{
     tracking_control_version = "1,0,1,24";
     
     if(object_id == null || object_id.trim() == "")
     {
       alert ("You must specify the Object ID where you want to show the control");
       return;
     }

     ControlObject = document.getElementById(object_id);
     if(ControlObject == null)
     {
        alert("The Object you specified does not exist");
        return;
     }
     
     if(width == null || width.trim() == "")
     {
        width =  "100%"; 
     }
     
     if(height == null || height.trim() == "")
     {
        height =  "100%"; 
     }
     
     if(border == null || border.trim() == "")
     {
        border =  "0"; 
     }
     
     if(color_index == null || color_index.trim() == "")
     {
        color_index =  "1"; 
     }
     
     if(network_id == null || network_id.trim() == "")
     {
        network_id =  ""; 
     }
     
     if(align == null || align.trim() == "")
     {
        align =  "center"; 
     } 

     if(login == null)
     {
        login =  (usernameinput); 
     }

     if(password == null)
     {
        password =  (passwordinput); 
     }	
	

     if (navigator.appName == "Microsoft Internet Explorer")
     { 
        ControlObject.innerHTML += "<object id=\"MSXML4\" "+
        "classid=\"clsid:88d969c0-f192-11d4-a65f-0040963251e5\" "+
		"codebase=\"http://www.magaya.com/downloads/msxml4.cab#version=4,20,9818,0\" "+
		"type=\"application/x-oleobject\" "+
		"STYLE=\"display: none\"> </object>"+
		"<object classid=\"clsid:D96CB906-CEE6-4774-8768-63FEC183D24E\" "+ 
		"codebase=\"http://www.magaya.com/downloads/WebLvTk.cab#version="+tracking_control_version+"\" "+
		"width=\""+width+"\" "+
        "height=\""+height+"\" "+
   		"border=\""+border+"\" "+
 		"id=\"WebLiveTrackControl\" "+
		"The Magaya LiveTrack control is not installed yet. <br/> "+
		"Please make sure that you allowed the installation of the ActiveX control  <br/> "+
		"<param name=\"AgentID\" value=\""+network_id+"\">"+
		"<param name=\"ColorIndex\" value=\""+color_index+"\">"+		 
		"<param name=\"Login\" value=\""+login+"\">"+
		"<param name=\"Password\" value=\""+password+"\">"+
		"</object>";		
		sFinalObject = ControlObject.innerHTML;
		
		ControlObject.focus();
        ControlObject.align = align;
        readystatechange();
        try{
        var control = document.getElementById( "WebLiveTrackControl" );
        control.focus();
        }catch(err)
        {}
        
       
    }else
    {
        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
         { //test for Firefox/x.x or Firefox x.x and detect the OS of the user;
             var ffversion = new Number(RegExp.$1)
             // capture x.x portion and store as a number
             if ((ffversion >= 3) && (navigator.userAgent.indexOf('Win') != -1))
              {
                 var isPlugin = false;
                 for (i = 0; i < navigator.plugins.length; i++)
                  {
                      if (navigator.plugins[i].name == "LiveTrack Plug-in")
                       {
                          ControlObject.innerHTML += "<div  style=\"height:300px;border: solid 1px #000099;font-family: Arial, Helvetica, sans-serif; background-color:White;padding: 10px 10px 10px 10px;text-align: center;vertical-align:middle; \">" +
                                   "<br/><br/><br/><br/><br/><br/><br/><br/><br/><H1>You are trying to view the Magaya LiveTrack control in Mozilla Firefox 3.0 or higher, if you wish to continue, please click on the container.<br/></H1>" +
                                   "</div>";
                          isPlugin = true;         
                          break;
                       }
                  }
                 
                 if(!isPlugin)
                 ControlObject.innerHTML += "<div  style=\"height:300px;border: solid 1px #000099;font-family: Arial, Helvetica, sans-serif; background-color:White;padding: 10px 10px 10px 10px;text-align: center;vertical-align:middle; \">" +
                                   "<br/><br/><br/><br/><br/><br/><br/><br/><br/><H1>You are trying to view the Magaya LiveTrack control in Mozilla Firefox 3.0 or higher, if you wish to continue, please install the following plugin:<br/></H1>" + "<br/><br/><a href='http://www.magaya.com/downloads/LiveTrackPlugin.xpi' style=\"color : #FF7F50;font-style : italic;font-weight : bold;text-decoration : none;ont-size: 100%;\">Install Now</a>" +
                                   "</div>";
             }
             else
                 ControlObject.innerHTML += "<div  style=\"height:400px;background-color:White;padding: 10px 10px 10px 10px;text-align: center;\" class=\"bodytype\">" +
                                   "<br/><br/><br/><br/><br/><br/><br/>The Magaya LiveTrack control is only compatible with Microsoft Internet Explorer browser." +
                                   "</div>";
        }
        else
        ControlObject.innerHTML += "<div  style=\"height:400px;border: none;background-color:White;padding: 10px 10px 10px 10px;text-align: center;vertical-align:middle; \">"+
                                   "<br/><br/><br/><br/><br/><br/><br/><br/><br/><font class=\"bodytypelarge\">The Magaya LiveTrack control is only compatible with Microsoft Internet Explorer browser.</font>"+
                                   "</div>";
    }
}


//The below script will detect the OS of the user, and display it.

function checkOS() {
  if(navigator.userAgent.indexOf('IRIX') != -1)
    { var OpSys = "Irix"; }
  else if((navigator.userAgent.indexOf('Win') != -1) &&
  (navigator.userAgent.indexOf('95') != -1))
    { var OpSys = "Windows95"; }
  else if(navigator.userAgent.indexOf('Win') != -1)
    { var OpSys = "Windows3.1 or NT"; }
  else if(navigator.userAgent.indexOf('Mac') != -1)
    { var OpSys = "Macintosh"; }
  else { var OpSys = "other"; }
  return OpSys;
}



function readystatechange()
{   
    sActiveXNotLoaded = "<div id=\ActiveXNotLoaded\" class=\"bodytype\" style=\"position:absolute; top: 0px; left:300px; border: solid 1px #7653A2; background-color:White; padding: 10px 10px 10px 10px;\">"+
            "<h2>1. Click on the bar at the top."+ 
            "<img alt=\"install\" src=\"http://www.magaya.com/images/activex_top2.gif\"/></h2>"+                        
            "<h2>2. Click 'Install ActiveX Control...' from the dropdown.</h2>"+
            "<br />"+
            /*"<p style=\"MARGIN-LEFT: 21px\"><b>If you do not see the option to install de ActiveX control, <br/> please click on the following link for installation instructions."+ 
            "</b></p>"+
            "<p style=\"MARGIN-LEFT: 21px\"><a class=\"go\""+
            "href=\"http://www.magaya.com/downloads/ActiveXInstallationInstructions.doc\">"+ 
            "ActiveX installation instructions</a></p>"+*/
            "&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://www.magaya.com/images/activex_bottom.gif\" alt=\"Click 'Install ActiveX Control...' from the dropdown.\" />"+ 
            "<h2>3. Click 'Install' when the security warning pops up.</h2></div>";
     
    
    pos = ControlObject.innerHTML.indexOf("ActiveXNotLoaded");      
    if (pos >= 0)
        sActiveXNotLoaded = "";
                       
    WebLiveTrackControlObj = document.getElementById("WebLiveTrackControl");
    if (WebLiveTrackControlObj && WebLiveTrackControlObj.readyState > 0)   
    {    
        try{ 
            var liveTrackObj = new ActiveXObject("WEBLIVETRACK.WebLiveTrackCtrl.1");  
            ActiveXNotLoaded = document.getElementById("ActiveXNotLoaded");        
            ControlObject.innerHTML = sFinalObject;
            ControlObject.focus();
            try{ 
                WebLiveTrackControlObj.focus(); 
            }
            catch(err)
            {
            }        
           
        }
        catch(err)
        {
            if (sActiveXNotLoaded.length > 0)
                ControlObject.innerHTML += sActiveXNotLoaded; 
            setTimeout(readystatechange, 500);
        }             
    }
    else
    {
        if (sActiveXNotLoaded.length > 0)
            ControlObject.innerHTML += sActiveXNotLoaded; 
        setTimeout(readystatechange, 500);        
    }
}
