

_siInit=false;
var _na = "NA";

var _spScanType;

var _spFailtUrl;


function searchSvcTag()
{
var svcTag = getQueryVariable("SvcTag");
if (svcTag)
{
 var svcTagID = document.getElementById("svcTagTB");
 if (svcTagID)
  {
   svcTagID.value = svcTag;
   DoSvcTag();
  }
}
}


$j(document).bind ( 'sReady' , searchSvcTag );

function pfydAutoCheck ( failUrl, isLoaded )
{
    if ( failUrl )
    {
        _spFailtUrl = failUrl;
    }
    _spScanType="auto";
    if  ( !isLoaded )
    {
       
       addOnLoad ( function (){ pfydAutoCheck ( failUrl, true );});
       return;
    }
    document.body.style.cursor='wait';
    UpdateScannerProgress("startingscan");
    setTimeout (  "pfydAutoCheck2()" , 1000 );
} 

 
function pfydAutoCheck2 ()
{
    
     var info = siInfo(); 
     if ( info == null || info.SvcTag == null || info.SvcTag.length == "")
     {
        var msg = getScString( "svctagerror" , "We were unable to find information about your system");
        
        alert ( msg );
        window.location.href= _spFailtUrl;
        return;
     }

     var tb = document.getElementById('svcTagTB');
     if ( tb != null )
     {
        tb.value = info.SvcTag 
     }
     _pfydSvc = info.SvcTag;
     UpdateScannerProgress("queryingdb");
     DoSvcTag();
     
    
}

function UpdateScannerProgress(step) {
    
    var scanProgressImage = document.getElementById("scanProgressImage");
    if ( !scanProgressImage ||  
        ( !isNaN(  scanProgressImage.Progress) && (scanProgressImage.Progress > scanProgressImage.NextProgress )   ))
    {
        return;
    }
    
    if ( step )
    {
        window.status = step;
        var incrementValue = 1;
        var nextStep = 0;
        if (  step == "startingscan")
        {
            nextStep = 30;
        }
        if (  step == "downloadingcommands")
        {
            nextStep = 80;
        }
        if (  step == "downloadingcommandscomplete")
        {
            nextStep = 80;
        }
        if (  step == "scannerdataextracted")
        {
            nextStep = 80;
        }
        if (  step == "queryingdb")
        {
            nextStep = 98;
            incrementValue = 1;
        }
        scanProgressImage.NextProgress = nextStep;
        scanProgressImage.IncrementValue = incrementValue;
    }
    
    if ( isNaN(scanProgressImage.Progress))
    {
        scanProgressImage.Progress = 1;
    }
    scanProgressImage.Progress +=  scanProgressImage.IncrementValue ;
    
    scanProgressImage.style.width = scanProgressImage.Progress + "%";
    setTimeout ( "UpdateScannerProgress()" , 200 );
}


function renderScannerListing ( id,  full, height , isLoaded)
{
    
    if  ( !isLoaded )
    {
       addOnLoad ( function (){ renderScannerListing (  id,  full, height , true );});
       return;
    }
    var cookieVal = getCookie ( "siid");
    if ( cookieVal != null && cookieVal.length > 0 )
    {
        renderScannerListing2( id,  full, height );
    }
    else
    {
        setTimeout ( function (){renderScannerListing2 (  id,  full, height )} , 1000 );
    }
}

function renderScannerListing2 ( id,  full, height )
{
    var container = document.getElementById (id);
    if ( container != null )
    {
        try
        {
            var render = new scannerRenderer ();
            
            var info = render.getScannerMarkup(full);
            if ( info != null && info.length > 0 ) 
            {
                var markup=  "<table width='100%' height='22' cellspacing='0' cellpadding='0'  border='0'><tr class='rowsolid'><td width='100%'  class='fragsolid'><h2 class='titlestylesolid'>Your Scan Results</h2></td>";
                if ( !full )
                {
                    var url = "javascript:winopen('/sna/scanner.aspx?~lt=print&mfgpid="+ getQueryVariable("mfgpid")+"','popup575x505','WIDTH=575,HEIGHT=500,RESIZABLE=YES,SCROLLBARS=YES,TOOLBAR=NO,LEFT=20,TOP=20');";
                    markup +="<td align='right' class='fragvall'><a href=\"" + url + "\" >View All</a></td>";
                }
                markup +="</tr></table>";
                markup +="<div id='scannerListingFull' style='position:absolute;dispay:none;background-color:white;z-index:5;top:150px;left:150px'></div><div style='float:right'></div>";
                
                markup +="<div style='padding:6px;";
                if ( height > 1 )
                {
                    markup += "overflow:scroll;height:" + height ;
                }
                markup += "' >" + info+ "</div>";
                
                container.innerHTML =markup;
                container.style.display="block";
            }
            
        }
        catch ( e )
        {}
    }
    
}
function siInfo ()
{
    
    if ( _spScanType != "auto" )
    {
        var autoCheckCookie = getCookie ( "siid" );
        if ( autoCheckCookie == null || autoCheckCookie.length == 0 )
        {
            return null;
        }
      
    }
       
    
    var si = document.getElementById("siCtl");
    if ( si == null  )
    {
        return null;
    }
    if ( si.ModuleVersion )
    {
        return siInfo1();
    }
   
    if  ( !si.DateTime )
    {
        window.status = "ctrl not loaded";
        return;
    }
    var issueObj = si.IssueObj;
    if ( issueObj != null )
    {
        return issueObj;
    }
    if ( si.HadError )
    {
        return null;
    }
    try
    {
       
        var issueId = getCookie ( "siid");
        
        if ( issueId == null || issueId.length == 0 )
        {
            UpdateScannerProgress("downloadingcommands");
            issueId = si.SetData();
            SetCookie( "siid"  , issueId );
            UpdateScannerProgress("downloadingcommandscomplete");
            
        }
        var resultData = si.GetData(issueId);
        
       
        var issueObj = new scannerInfo(resultData, 2);
        oXMLDOMDocument = null;
        issueObj.RawXml = issueId;
        si.IssueObj = issueObj;
        return si.IssueObj;
    }
    catch ( error )
    {
        si.HadError = true;
        window.status = error.message;
    }
    return null;
   
    
}



function siInfo1 ()
{
    
    if ( _spScanType != "auto" )
    {
        var autoCheckCookie = getCookie ( "siid" );
        if ( autoCheckCookie == null || autoCheckCookie.length == 0 )
        {
            return null;
        }
      
    }
       
    
    var si = document.siCtl;
    if ( si == null || !si.ModuleVersion )
    {
        return null;
    }
    
    var issueObj = si.IssueObj;
    if ( issueObj != null )
    {
        return issueObj;
    }
    if ( si.HadError )
    {
        return null;
    }
    try
    {
       
        var issueId = getCookie ( "siid");
        
        
        si.SetCurrentServer(window.location.hostname);			
        si.SetDataDirectory("%TEMP%");		
        
        
        if ( issueId == null || issueId.length == 0 )
        {
            UpdateScannerProgress("downloadingcommands");
            si.SetDataSpecFile ( m_scannerInstructions );
            issueId = si.NewIssue("pfyd scan");	
            SetCookie( "siid"  , issueId );
            UpdateScannerProgress("downloadingcommandscomplete");
        }
       
        var issueFile = si.GetIssueFile(issueId) ;
        
        si.StartXMLIO(issueFile);
      
        UpdateScannerProgress("scannerdataextracted");
        
        issueObj = new scannerInfo(si);
        issueObj.RawXml = issueFile;
        
        si.EndXMLIO();
        si.IssueObj = issueObj;
        return si.IssueObj;
    }
    catch ( error )
    {
        si.HadError = true;
        window.status = error.message;
    }
    return null;
    
        
}

function scannerInfo (  scannerCtrl , ver )
{
    this.SI = scannerCtrl; 
    if ( ver != 2 )
    {
        this.GetValues = this.GetValues1;
    }
    
    this.initComp ();
    this.initProc ();
    this.initMem ();
    this.initKB ();
    this.initIDE ();
    this.initOS ();
    this.initSysSlot ();
    this.initCD ();
    this.initNetwork();
    this.initMon ();
    this.initHD();
    this.initBios ();
    this.initSound ();
    this.initVid ();
    this.initPorts ();
}


scannerInfo.prototype.TrimString =function( sInString )
{
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
}

scannerInfo.prototype.GetValues =function( classID )
{
    var retval = new Object()
    retval.Count = 0;
    var lines= this.SI.split( '\n');
    var classLine = "[class="+ classID + "]";
    var inClass = false;
    for ( var i = 0;i<lines.length ; i++ )
    {
        var line =  this.TrimString (lines[i]);
        if ( line == classLine  )
        {
            inClass = true;
            continue;
        }
        if ( inClass )
        {
            if ( line.indexOf ( "[class" ) > -1 )
            {
                break;
            }
            if ( line == "[INSTANCE]" )
            {
                retval.Count++;
                retval[retval.Count-1]= new Object();
                continue;
            }
            if ( line.indexOf ( "[pname]=" ) == 0 )
            {   
                var propName = line.substr ( 8 );
                i ++;
                if ( i<lines.length && lines[i].indexOf ( "[pvalue]=") == 0 )
                {
                    var propValue = lines[i].substr ( 9 );
                    propValue   = this.TrimString ( propValue );
                    retval[retval.Count-1][propName ] = propValue;
                }
            }
        }
    }
    return retval;
}



scannerInfo.prototype.GetValues1 =function( wKey )
{

    var retval = new Object()

    retval.Count = 0;
   
    var tmp = this.SI.GetXMLSections( wKey );
    if ( tmp == null || tmp.length ==0  )
    {
        return retval;
    }
    var sections = tmp.split (',');
    retval.Count = sections.length; 
    for ( i = 0 ; i < sections.length ;i++ )
    {
        
        var instanceID = sections[i];
        retval[i]= new Object();
        retval[i].ID = instanceID;
        tmp =    this.SI.GetXMLKeys ( wKey , sections[i] );
        if ( tmp == null )
        {
            continue;
        } 
        var keys = tmp.split ( ',');
        for ( j=0 ; j < keys.length ; j++ )
        {
            
            var keyName = keys[j];
            var value  = this.SI.GetXMLValue( wKey  , instanceID ,keyName );
            retval[i][keyName] = value;
          
        }
    } 
    return retval;
}
scannerInfo.prototype.initComp=function() 
{
    
    var cspData = this.GetValues("Win32_ComputerSystemProduct");
    var csData= this.GetValues("Win32_ComputerSystem");
    if ( cspData.Count > 0 )
    {
        if ( csData[0]["Model"] != null )
        {
            var _family = csData[0]["Model"].split(' ')[0];
            var _model = csData[0]["Model"].substring(_family.length);
        }
        this.System  = new Object();
        this.System.Name = csData[0]["Model"];
        this.System.Family = _family;
        this.System.Model = _model;
        this.SvcTag = cspData[0]["IdentifyingNumber"];
    }
    
}
scannerInfo.prototype.initProc =function () 
{
    var procData= this.GetValues("Win32_Processor");
    if ( procData.Count> 0 )
    {
        this.Processor  = new Object(); 
        this.Processor.Name = procData[0]["Name"]
        this.Processor.Speed = new scannedValue  ("GHz"  , procData[0]["MaxClockSpeed"] )
        this.Processor.CacheSize = new scannedValue ( "Kb" , procData[0]["L2CacheSize"] );
        
    }
    
}
scannerInfo.prototype.initMem  =function ()
{
    var memData = this.GetValues("Win32_PhysicalMemory");
    var memPerfData = this.GetValues("Win32_PerfFormattedData_PerfOS_Memory");
    var memArrayData  = this.GetValues("Win32_PhysicalMemoryArray");
    if ( memData.Count> 0 )
    {
        this.Memory  = new Object(); 
        this.Memory.Dims = new Array();
        var totalMB = 0;
        for (  i = 0 ; i < memData.Count ; i ++ )
        {
            var memItem = new Object();
            var memSize  = new scannedValue ("mb" , memData[i]["Capacity"] );
            var memSpeed =  new scannedValue ( "Mhz" , memData[i]["Speed"]);
            var memSlot   = memData[i]["DeviceLocator"];
            var memType   =  new scannerEnum  ("Mem", memData[i]["MemoryType"]);
            memItem.Speed = memSpeed;
            memItem.Size = memSize;
            memItem.Slot = memSlot;
            memItem.Type = memType;
            totalMB+= memItem.Size.RawValue;
            this.Memory.Dims[i] = memItem;
               
        }
        this.Memory.Total = new scannedValue("mb", totalMB);
    }
    if ( memPerfData.Count> 0 )
    {
        if (this.Memory  == null)
        {
            this.Memory  = new Object(); 
        }
        this.Memory.Available = new scannedValue("mb", (1024 * 1024) * memPerfData[0]["AvailableMBytes"]);
        this.Memory.PercentAvailable = new scannedValue("%", this.Memory.Available.RawValue / this.Memory.Total.RawValue);
    }
    
    if ( memArrayData.Count > 0 )
    {
        if (this.Memory  == null)
        {
            this.Memory  = new Object(); 
        }
       
        var count=parseInt ( memArrayData[0]["MemoryDevices"]);
      
        if ( !isNaN ( count ))
        {
            this.Memory.SlotCount =count;
            this.Memory.AvailableSlots = count - memData.Count;
        }
        this.Memory.MaxCapacity =  new scannedValue( "mb" , memArrayData[0]["MaxCapacity"]);
    }
   
}
scannerInfo.prototype.initKB  =function ()
{
    var kbData = this.GetValues("Win32_Keyboard");
    
}
scannerInfo.prototype.initIDE  =function ()
{
    var ideData= this.GetValues("Win32_IDEController");
    
}
scannerInfo.prototype.initOS  =function ()
{
    osData= this.GetValues("Win32_OperatingSystem");
    if ( osData.Count > 0 )
    {
        this.OS = new Object();
        this.OS.Name = osData[0]["Caption"];
    } 
}
scannerInfo.prototype.initSysSlot  =function ()
{
    ssData = this.GetValues("Win32_SystemSlot");
    if ( ssData.Count > 0 )
    {
        this.SystemSlots = new Object();
        this.SystemSlots.Slots = new Array ();
        for (  i = 0 ; i < ssData.Count ; i ++ )
        {
            var name = ssData[i]["Tag"];
            var usageID = ssData[i]["CurrentUsage"];
            var SlotDesignation = ssData[i]["SlotDesignation"];
            var slot = new Object();
            slot.Name = name;
            slot.UsageID = usageID;
            slot.Usage =  new scannerEnum ( "Slot",slot.UsageID);
            slot.SlotDesignation = SlotDesignation;
            this.SystemSlots.Slots[this.SystemSlots.Slots.length] = slot;
        }
    }
}
scannerInfo.prototype.initCD  =function ()
{
    var cdromData = this.GetValues("Win32_CDROMDrive");
    if(cdromData.Count > 0)
    {
        this.CD = new Object();
        this.CD.Drives = new Array();
        for(i = 0; i < cdromData.Count; i++)
        {
            var drive = new Object();
            drive.Drive = cdromData[i]["Drive"];
            drive.Caption = cdromData[i]["Caption"];
            this.CD.Drives[this.CD.Drives.length] = drive;
        }
    }
}
scannerInfo.prototype.initNetwork  =function ()
{
    networkData = this.GetValues("Win32_NetworkAdapter");
    if ( networkData.Count > 0 )
    {
        this.Network = new Object();
        this.Network.Adapters = new Array ();
        for (  i = 0 ; i < networkData.Count ; i ++ )
        {
            var desc = networkData[i]["Description"];
            var statusID = networkData[i]["NetConnectionStatus"];
            var adapter = new Object();
            adapter.Name = desc;
            adapter.StatusID = statusID;
            this.Network.Adapters[this.Network.Adapters.length] = adapter;
        }
    }
}

scannerInfo.prototype.initMon  =function ()
{
    var monitorData = this.GetValues("Win32_DesktopMonitor");
    
}
scannerInfo.prototype.initHD =function ()
{
    logDiskData = this.GetValues("Win32_LogicalDisk");
    scsiData = this.GetValues("Win32_SCSIController");
    if ( logDiskData.Count > 0 )
    {
       this.HD = new Object();
       this.HD.Drives = new Array();
       for (  i = 0 ; i < logDiskData.Count ; i ++ )
       {         
            var hdID = logDiskData[i]["DeviceID"];
            var hdSize  =  parseInt (  logDiskData[i]["Size"] ) ;
            var hdFs =  parseInt ( logDiskData[i]["FreeSpace"]) ;
            hdFs =  new scannedValue ("gb" , hdFs) ;
            hdSize = new scannedValue ("gb" , hdSize) ;
            var hdI = new Object ();
            hdI.Size = hdSize;
            hdI .ID = hdID;
            hdI .FreeSpace = hdFs;
            hdI.PercentUsed= new scannedValue("%", (hdSize.RawValue - hdFs.RawValue) / hdSize.RawValue );
            
            this.HD.Drives[this.HD.Drives.length]= hdI;
        }
    }    
    if ( scsiData.Count > 0 )
    {
       this.SCSI = new Object();
       
       this.SCSI.Controlers = new Array();
       for (  i = 0 ; i < scsiData.Count ; i ++ )
       {         
            var controler = new Object ();
            controler.Name =   scsiData[i]["Description"];
            this.SCSI.Controlers[this.SCSI.Controlers.length]= controler;
       }
    }     
   
}
scannerInfo.prototype.initPorts = function()
{
    ppData = this.GetValues("Win32_ParallelPort");
    pointData = this.GetValues("Win32_PointingDevice");
    usbCData = this.GetValues("Win32_USBController");
    
    if ( usbCData.Count > 0 )
    {
        this.USB = new Object();
        this.USB.Controlers = new Array ();
        for (  i = 0 ; i < usbCData.Count ; i ++ )
        {
            var controler = new Object();
            controler.Name =usbCData[i]["Caption"];
            controler.Protocol =  ( controler.Name != null && controler.Name.toLowerCase().indexOf ("enhanced")>-1)?"USB2":"USB";
            
            this.USB.Controlers[this.USB.Controlers.length] = controler;
        }
    }
    
}
scannerInfo.prototype.initBios  =function ()
{
    var biosData = this.GetValues("Win32_BIOS");
    if(biosData.Count > 0)
    {
        var _biosDateFull = biosData[0]["ReleaseDate"];
        var _biosDate = _biosDateFull.substr(0, 4) + "-" + 
                        _biosDateFull.substr(4, 2) + "-" + 
                        _biosDateFull.substr(6, 2);

        this.Bios = new Object();
        this.Bios.Manufacturer = biosData[0]["Manufacturer"];
        this.Bios.ReleaseDate = _biosDate;
        this.Bios.Version = biosData[0]["SMBIOSBIOSVersion"];
    }
}
scannerInfo.prototype.initSound  =function ()
{
    soundData = this.GetValues("Win32_SoundDevice");
    if ( soundData.Count > 0 )
    {
        this.Sound = new Object();
        this.Sound.Name = soundData[0]["Caption"];
    }
}

scannerInfo.prototype.initVid  =function ()
{
    
    vidData = this.GetValues("Win32_VideoController");
    if ( vidData.Count > 0 )
    {
        this.Video = new Object();
        this.Video.Adapters = new Array ();
        for (  i = 0 ; i < vidData.Count ; i ++ )
        {
            var mem = new scannedValue ( "mb" , vidData[i]["AdapterRAM"] );
            var name = vidData[i]["Caption"];
            var memType = new scannerEnum ("VidMem", vidData[i]["VideoMemoryType"] );
            
            var adapter = new Object();
            adapter.Name = name;
            adapter.MemorySize = mem;
            adapter.MemoryType = memType;
            this.Video.Adapters[this.Video.Adapters.length] = adapter;
            
        }
        
    }
    
}
function escText ( txt )
{
    return "<![CDATA[" + txt + "]]>";
}
function getSCData ()
{
   
    var info = siInfo ();
    if ( info == null )
    {
        return "";
    }
    var _output = "";
   
    if ( info.Processor )
    {
        _output += "<item><header>Processor</header>";
        _output += "<line>" + escText ( info.Processor.Name ) + "</line>";
        _output += "</item>"
        
    }
    
    if ( info.OS != null )
    {
        _output += "<item><header>OS</header>";
        _output += "<line>" + escText (info.OS.Name  ) + "</line>";
        _output += "</item>"
        
    } 
   
    if ( info.HD && info.HD.Drives.length > 0 )
    {
        _output += "<item><header>Hard Drive(s)</header>";
       for (  i = 0 ; i < info.HD.Drives.length ; i ++ )
       {
            var line = info.HD.Drives[i].ID  + ", Size: " +  info.HD.Drives[i].Size +  ", Utilized: " +  info.HD.Drives[i].PercentUsed  ;
            _output += "<line>" + escText ( line ) + "</line>";
            
       }
       
        _output += "</item>"
       
         
    }
    
    if ( info.Memory != null && info.Memory.Dims.length >0  )
    {
       _output += "<item><header>Memory</header>";
      
       for (  i = 0 ; i < info.Memory.Dims.length ; i ++ )
       {
            var line = info.Memory.Dims[i].Slot + ", Capacity: " + info.Memory.Dims[i].Size+ ", Speed: " + info.Memory.Dims[i].Speed ;
            _output += "<line>" + escText ( line ) + "</line>";
            
       }
       _output += "</item>"
     }
     if ( _output.length > 0 )
     {
        _output = "<root>" + _output + "</root>";
        return ( encodeBase64 ( _output ));
     }
     return "";
    
}




function siUpgradLink ( categoryID , mod )
{
   
    var configForm= null;
    if ( typeof ( m_pfydOcs ) != "undefined")
    {
        for ( var i =0; i < m_pfydOcs.length ; i ++ )
        {
           if ( m_pfydOcs[i].Usage != null && m_pfydOcs[i].Usage.toLowerCase() =="pfyd-b")
           {
                configForm = document.getElementById  ( "form_" + m_pfydOcs[i].OC );
                break;
           }
        }
        
    }
   
    if ( categoryID =="exthd")
    {
        categoryID = "5683";
        mod  = "858"
    }
    if ( categoryID =="mem")
    {
        categoryID = "4325";
        mod  = "852"
    }
    
    if ( mod != null && mod.length > 0 && configForm != null )
    {
        configForm.action += "&sm=" + mod ;
        linktoConfig( configForm.id );
    }
    else
    {
        var c = getQueryVariable("c") ;
        var l = getQueryVariable("l") ;
        var cs =getQueryVariable("cs");
        var mfgpid = getQueryVariable("mfgpid");
        var chassisid = getQueryVariable("chassisid");
        c = c == null ?"" : c;
        l = l == null ?"" : l;
        cs = cs == null ?"" : cs;
        mfgpid = mfgpid == null ?"" : mfgpid;
        chassisid = chassisid == null ?"" : chassisid;
       
        
        var url  = "/sna/category.aspx?c=" + c
        + "&l=" + l
        + "&cs="+ cs
        + "&mfgpid="+ mfgpid
        + "&chassisid="+ chassisid
        + "&category_id=";
        window.location.href = url  + categoryID;
    }
    
    return;
    
}

function scannerRenderer ()
{
    this.Info = siInfo ();
    this.InnerTableStart = "<tr><td colspan='2'><table width='100%'>";
    this.InnerTableEnd= "</table></td></tr>";
}
scannerRenderer.prototype.showScanRule = function( actionID , el)
{
    
    var action = this.getScString ( actionID +"RuleAction");
    if ( action != null )
    {
        this.showScanModal( "Upgrade?", action , el );
    }
}
scannerRenderer.prototype.showScanModal = function (title, html , el)
{
   
    try
    {
        var config = { modal:false,fixedcenter:true, width:"300px", visible:true, constraintoviewport:true ,makeFade:true};
       // config.context =new Array ( el , "br","tl");
        html = "<div style='padding:4px' class='para'>"+ html+ "</html";
        showYPanel ( "scannerupgrade" , title , html ,"" , config);
        return;
        
    }
    catch ( e )
    {
      window.status = e.description ;
    }
}



scannerRenderer.prototype.getRuleMarkup= function  ( system , item,  line , ruleID )
{
    var rule = this.getScString (ruleID+"Rule");
   if ( rule != null && rule)
   {
        try
        {
            if (  eval ( rule ))
            {
                return "<div style='position:relative;margin-bottom:1px'><span class='glossaryitem' onmouseover=\"new scannerRenderer().showScanRule('" + ruleID +"', this)\">"+line+ "</span></div>";
            }
        }
        catch( e ){}
       
   }
   return line;
      
}

scannerRenderer.prototype.createTwopleRow = function ( label, value )
{
    return "<tr><td style='padding-left:2px;'>" + label +"</td><td>" + value + "</td></tr>";  
}
 

scannerRenderer.prototype.createPercentage = function (  percent )
{
    return "<div style='height:16px;background-color:#cccccc;width:98%;overflow:hidden;'><div style='valign:center;position:relative;top:0;color:white;z-index:2;margin-left:5px'>"
    +percent+"</div><div style='height:16px;position:relative;top:-14px;background-color:#0066cc;width:" 
    + percent + "'>&nbsp;</div></div>"

}
scannerRenderer.prototype.createRowTitle = function ( label )
{
    return "<tr><td colspan='2'><b>" + label +"</b></td></tr>";  
}
 
scannerRenderer.prototype.createInnerRow = function ( isTitle, vars )
{
    var retVal ="<tr>";
    for ( var ii = 0 ; ii < vars.length ;ii++)
    {
        retVal += "<td ";
        if ( isTitle )
        {
             retVal += "style='border-bottom:dotted 1px'";
        }
        retVal +=">" + vars[ii]  +"</td>"
    }
    retVal +="</tr>";
    return retVal;
}
scannerRenderer.prototype.getScString = function ( id, defaultValue )
{
    return getScString ( id , defaultValue );
}
function getScString ( id, defaultValue )
{
    if  ( typeof ( m_scannerVocab ) != "undefined" && m_scannerVocab !=null )
    {
        for( var i =0; i < m_scannerVocab.length ; i ++ )
        {
            if ( id == m_scannerVocab[i].Key )
            {
                return m_scannerVocab[i].Value;
            }
            
        }
    }
    return defaultValue;
}
scannerRenderer.prototype.renderScannerListingPopup = function ()
{
    var container = document.getElementById ("scannerListingFull");
    if ( container != null )
    {
        try
        {
            
            var info = getScannerMarkup(true);
            var markup= "<table width=300 cellpadding='0' style='background-color:#dddddd;margin:0px;padding:0px;border-style=solid;border-width:1px;border-color:#666666;' >"
                + "<tr><td style='padding:0px;margin:0px;background-color:#dddddd'><a align='right' href=\"javascript:var x = document.getElementById ('scannerListingFull').style.display='none';\">"
                + "<img border='0' align='right' src='public/images/tipclose.gif'></a></td></tr>"
                + "<tr><td style='padding:20px;margin:0px;background-color:#ffffff'>"
                + info 
                + "</td></tr>"
                + "</table>";
            container.innerHTML = markup;
            container.style.display = "block";
        }
        catch ( e )
        { 
        
        }
        
    }
}

scannerRenderer.prototype.getScannerMarkup = function( full)
{
    
     _output = "";
    if ( this.Info == null )
    {
        return null;
    } 
     
     var info = this.Info;
    if ( info.System != null && info.System.Name != null )
    {
        _output += "<b class='para'>" + info.System.Name +"</b><br />";
    }
    
    _output += "<table class='scanner_table' style='border:1px' border='0' cellspacing='0' cellpadding='0'><tr><td colspan='2'><b>General</b></td></tr>";
    
    if ( info.SvcTag != null  )
    {
        _output += this.createTwopleRow( "ServiceTag", info.SvcTag );
    }
    
    if ( full && info.System != null && info.System.Name != null)
    {
        _output += this.createTwopleRow("Family Name", info.System.Family);
        _output += this.createTwopleRow("Family Model", info.System.Model);
    }

    if ( info.OS != null )
    {
        _output += this.createTwopleRow( "Windows Version" , this.getRuleMarkup( info, info.OS , info.OS.Name ,"os") );
    }
    
    if ( full && info.Bios)
    {
        _output += this.createRowTitle("BIOS");
        _output += this.createTwopleRow("Version", info.Bios.Version);
        _output += this.createTwopleRow("Vendor", info.Bios.Manufacturer);
        _output += this.createTwopleRow("Date", info.Bios.ReleaseDate);
    }
    
    if ( info.Processor )
    {
        _output += this.createRowTitle  ("Processor");  
        _output += this.createTwopleRow("Model" , info.Processor.Name );
        if (full) 
        {
            _output += this.createTwopleRow("Speed",  info.Processor.Speed  );
            if ( info.Processor.CacheSize.HasValue && info.Processor.CacheSize.RawValue > 0  )
            {
                _output +=  this.createTwopleRow("Cache Size" , info.Processor.CacheSize );
            }
        }
    }
    
    if ( info.HD && info.HD.Drives.length > 0 )
    {
       _output += this.createRowTitle  ("Hard Drive"); 
       _output += this.InnerTableStart;
       
        _output +=  this.createInnerRow( true, new Array ( "Drive", "Size" ,"Free Space","Utilized"));
       
       for (  i = 0 ; i < info.HD.Drives.length ; i ++ )
       {
           var freeSpace = this.getRuleMarkup (info,  info.HD.Drives[i] , info.HD.Drives[i].FreeSpace , "hd");
           
           var hdAvail = this.createPercentage( info.HD.Drives[i].PercentUsed );
           
           _output += this.createInnerRow( false ,
                    new Array ( info.HD.Drives[i].ID, info.HD.Drives[i].Size , freeSpace , hdAvail  )
                    );
             
               
       }
       _output += this.InnerTableEnd; 
         
    }
    
    if( full && info.CD && info.CD.Drives.length > 0)
    {
        _output += this.createRowTitle("CD/Optical Drives")
        _output += this.InnerTableStart;
        _output += this.createInnerRow(true, new Array("Drive", "Type"))
        for(i = 0; i < info.CD.Drives.length; i++)
        {
            _output += this.createInnerRow(false, new Array(info.CD.Drives[i].Drive, info.CD.Drives[i].Caption))
        }
        _output += this.InnerTableEnd;
    }
    
    if ( full && info.Sound  )
    {
        _output += this.createRowTitle  ("Sound Card"); 
        _output += this.createTwopleRow("Model", info.Sound.Name );
    }
    
    if ( full && info.SystemSlots && info.SystemSlots.Slots.length > 0 )
    {
        _output += this.createRowTitle  ("Card Slots");
       _output += this.InnerTableStart;
        _output += this.createInnerRow( true ,
                    new Array ("Slot ID","Designation" ,"Usage" )
                    );
       for (  i = 0 ; i < info.SystemSlots.Slots.length ; i ++ )
       {
          var slot = info.SystemSlots.Slots[i];
           _output += this.createInnerRow( false ,
                    new Array ( slot.Name , slot.SlotDesignation, slot.Usage)
                    );
             
       }
       _output += this.InnerTableEnd;
       
    }
    
            
    if ( full && info.SCSI && info.SCSI.Controlers.length > 0 )
    {
        _output += this.createRowTitle ("SCSI Controlers");
       _output += this.InnerTableStart;
       
       for (  i = 0 ; i < info.SCSI.Controlers.length ; i ++ )
       {
          
           _output += this.createInnerRow( false ,
                    new Array ( info.SCSI.Controlers[i].Name )
                    );
             
               
       }
       _output += this.InnerTableEnd;
        
    }
    if ( full && info.Network && info.Network.Adapters.length > 0 )
    {
       _output += this.createRowTitle ("Network Adapters");
       _output += this.InnerTableStart;
       
       //_output +=  this.createInnerRow( true, new Array ( "Name"));
       
       for (  i = 0 ; i < info.Network.Adapters.length ; i ++ )
       {
          _output += this.createInnerRow( false ,
                    new Array ( info.Network.Adapters[i].Name  )
                    );
       }
       _output += this.InnerTableEnd;
         
    }
    if ( full && info.USB && info.USB.Controlers.length > 0 )
    {
       _output += this.createRowTitle ("USB Controlers"); 
       _output += this.InnerTableStart;
       
       _output +=  this.createInnerRow( true, new Array ( "Name" , "Version"));
       
       for (  i = 0 ; i < info.USB.Controlers.length ; i ++ )
       {
          _output += this.createInnerRow( false ,
                    new Array ( info.USB.Controlers[i].Name , info.USB.Controlers[i].Protocol  )
                    );
       }
       _output += this.InnerTableEnd;
    }
    
    if (  info.Video != null  && info.Video.Adapters.length >0 )
    {
        _output += this.createRowTitle ("Video Adapters");
        _output += this.InnerTableStart;
        
        _output +=  this.createInnerRow( true, new Array ( "Model", "Memory" ));
       
        for (  i = 0 ; i < info.Video.Adapters.length ; i ++ )
        {
            _output +=  this.createInnerRow( false, new Array ( info.Video.Adapters[i].Name, info.Video.Adapters[i].MemorySize+ " " + info.Video.Adapters[i].MemoryType ));
        }
        _output += this.InnerTableEnd;
       
       
    }
    if ( info.Memory != null && info.Memory.Dims.length >0  )
    {
       _output += this.createRowTitle (this.getScString ("memory","Memory"));
       
       if (   info.Memory.Available && info.Memory.Available.HasValue  )
       {
            _output += this.createTwopleRow("Total",info.Memory.Total);
            var memAvailCaption = this.getRuleMarkup( info, info.Memory , "Available" , "mem");
            var memAvail = this.createPercentage( info.Memory.PercentAvailable );
            _output += this.createTwopleRow(memAvailCaption, memAvail );
           
       }

       _output += this.InnerTableStart;
       _output +=  this.createInnerRow( true, new Array ( "Slot", "Size" ,"Speed","Type"));
       for (  i = 0 ; i < info.Memory.Dims.length ; i ++ )
       {
           _output +=  this.createInnerRow( false, new Array ( "Slot " + (i+1), info.Memory.Dims[i].Size ,info.Memory.Dims[i].Speed,info.Memory.Dims[i].Type));
       }
       
       if ( info.Memory.SlotCount )
       {
            for ( i= info.Memory.Dims.length ; i < info.Memory.SlotCount   ; i ++ )
           {
                _output += this.createInnerRow(false, new Array("Slot " + (i+1), "Empty", "", ""));
           }
       }
       _output += this.InnerTableEnd;
       
        _output += this.createTwopleRow("Available Slots", info.Memory.AvailableSlots);
    }
    if ( window.location.search.indexOf("rawxml")> -1 )
    {
        _output += "<tr><td  ><b><a href=\""+ info.RawXml+"\">rawxml</b></td></tr>";
    }
    
    
    _output +="</table>";
    return _output;
}

function scannedValue ( type, value )
{
    type = type.toLowerCase ( );
    this.Unit = type.toLowerCase ( );;
     
    var size   = parseFloat( value );
    this.RawValue =size;
    this.HasValue = true;
    
    
    if ( isNaN ( size ))
    {
        this.HasValue = false;
        return;
    }
    if ( type == "ghz")
    {
        this.Unitized = (Math.round  ( size /10) )  /100;
        this.Unit="Ghz";
        return;
    }
    if ( type == "mb" )
    {
        this.Unitized = Math.round (  size /(1024 * 1024) ) ;
        this.Unit = "Mb";
        return;
    }
    if ( type == "mhz" )
    {
         this.Unitized =  Math.round ( size ) ;
         this.Unit = "Mhz";
         return;
    }
    if ( type == "gb" )
    {
        size = size / (1024 * 1024 * 1024);
        size = Math.round ( size*100 )/100;
        this.Unitized = size;
        this.Unit = "Gb";
        return;
    }
    if ( type == "%" )
    {
        this.Unitized = Math.round  (size  * 100);;
        this.Unit = "%";
        return;
    }
    if ( type == "kb" )
    {
        this.Unitized = size;
        this.Unit = "Kb";
        return;
    }
    
}

scannedValue.prototype.toString = function()
{
    if ( !this.HasValue)
    {
        return _na;
    }
    return this.Unitized + " " + this.Unit;
    
};
function scannerEnum ( type, value )
{
    this.ID  = parseInt ( value );
    if ( !isNaN ( this.ID ))
    {
        var fn = "this.convert"+ type +"(" + this.ID  +")";
        this.Value = eval( fn );
    }
}
scannerEnum.prototype.toString = function()
{
    return this.Value 
};

scannerEnum.prototype.convertSlot= function  ( typeID )
{
    var lookup = new Array ("Reserved","Other","Unknown","Available","In use");
    return lookup[typeID];
}
scannerEnum.prototype.convertDrive= function  ( typeID )
{
    var lookup = new Array ("Unknown","No Root Directory","Removable Disk","Local Disk","Network Drive","Compact Disc","RAM Disk");
    return lookup[typeID];

}
scannerEnum.prototype.convertPort= function  ( typeID )
{
    var lookup = new Array ("Unknown","Other","Unknown","EISA","ISA","PCI","ATA/ATAPI","Flexible Diskette","1496","SCSI Parallel Interface","SCSI Fibre Channel Protocol","SCSI Serial Bus Protocol","SCSI Serial Bus Protocol-2 (1394)","SCSI Serial Storage Architecture","VESA","PCMCIA","Universal Serial Bus","Parallel Protocol","ESCON","Diagnostic","I2C","Power","HIPPI","MultiBus","VME","IPI","IEEE-488","RS232","IEEE 802.3 10BASE5","IEEE 802.3 10BASE2","IEEE 802.3 1BASE5","IEEE 802.3 10BROAD36","IEEE 802.3 100BASEVG","IEEE 802.5 Token-Ring","ANSI X3T9.5 FDDI","MCA","ESDI","IDE","CMD","ST506","DSSI","QIC2","Enhanced ATA/IDE","AGP","TWIRP (two-way infrared)","FIR (fast infrared)","SIR (serial infrared)","IrBus"); 
    return lookup[typeID];
}
scannerEnum.prototype.convertMem = function (typeID )
{
    var lookup = new Array ("Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM","RAM","ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR");
    return lookup[typeID];
}
scannerEnum.prototype.convertVidMem= function  ( typeID )
{
    var lookup = new Array ("","","","VRAM","DRAM","SRAM","WRAM","EDO RAM","Burst Synchronous DRAM","Pipelined Burst SRAM","CDRAM","3DRAM","SDRAM","SGRAM");
    return lookup[typeID];
}





var END_OF_INPUT = -1;
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);
var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n'); 
            lineCount = 0;
        }
    } 
    return result;
}


