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+$/,"");
}
function UpdateLenghtValue(value) {


    /*
    em (ems, the height of the element's font) 
    ex (x-height, the height of the letter "x") 
    px (pixels, relative to the canvas resolution) 
    Absolute length units are highly dependent on the output medium, and so are less useful than relative units. The following absolute units are available:

    in (inches; 1in=2.54cm) 
    cm (centimeters; 1cm=10mm) 
    mm (millimeters) 
    pt (points; 1pt=1/72in) 
    pc (picas)
    */
    if (value == null || value.trim() == "") {
        value = "100%";
    } else {
        pos = value.search(/^[0-9]*[0-9,.][0-9]*[" "]*(em|ex|px|in|cm|mm|pt|pc|%)$/);
        number = parseFloat(value)
        if (isNaN(number)) {
            value = "100%";
        } else if (pos == -1) {
            value = number + "px";
        }
    }
    return value;


}
var sFinalObject;
var refControlObject;

function DisplayTrackingControl(object_id, network_id, width, height, align, border, color_index, login, password) {
    tracking_control_version = "1,0,1,29";

    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;
    }

    width = UpdateLenghtValue(width);
    height = UpdateLenghtValue(height);

    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 = "";
    }

    if (password == null) {
        password = "";
    }


    if (navigator.appName == "Microsoft Internet Explorer") {
        sFinalObject = "<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 + "\" " +
                            "style=\"width:" + width +
                            ";height:" + height +
                            ";border-style:none" +
                            ";border-width:" + 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>";
        ControlObject.innerHTML += sFinalObject;
        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;border: solid 1px #000099;background-color:White;padding: 10px 10px 10px 10px;text-align: center;vertical-align:middle; \">" +
                                                "<br/><br/><br/><br/><br/><br/><br/><br/><br/><H1>The Magaya LiveTrack control is only compatible with Microsoft Internet Explorer browser.<br/></H1>" +
                                                "</div>";
        }
        else
            ControlObject.innerHTML += "<div  style=\"height:400px;border: solid 1px #000099;background-color:White;padding: 10px 10px 10px 10px;text-align: center;vertical-align:middle; \">" +
                                            "<br/><br/><br/><br/><br/><br/><br/><br/><br/><H1>The Magaya LiveTrack control is only compatible with Microsoft Internet Explorer browser.<br/></H1>" +
                                            "</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\" style=\"position:absolute; top: 0px; left:300px; border: solid 1px #000099; background-color:White; padding: 10px 10px 10px 10px;\">"+
    "<h2>1. Click on the bar at the top."+ 
    "<img alt=\"install\" style=\"Z-INDEX: 2; POSITION: absolute; TOP: -15px; left: 350px\" 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);        
    }
}

