﻿// JScript File
function popExternal(url) 
{
    // If 'intel.com' is found in the url open the link and don't display the warning.
    url = url.toLowerCase();
    var win;
    if (url.indexOf('intel.com',0) >= 0)
    { 
        win = window.open(url); 
    } 
    else
    { 
        win = window.open('external_popup.aspx?url='+escape(url),'externalPop','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=230'); 
    } 
    if (window.focus)
        win.focus(); 
}

function popEmail() 
{ 
    var win=window.open('email.aspx?url='+escape(document.location.href),'externalPop','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=530'); 
    if (window.focus)
        win.focus(); 
}

function popEmailUrl(url) 
{ 
    var win=window.open('email.aspx?url='+url,'externalPop','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=530'); 
    if (window.focus)
        win.focus(); 
}

function addToFavorites(url) 
{ 
    var pageTitle = 'Motherboard and Barebones Selector Guide';
	if (window.sidebar)
	{
	    window.sidebar.addPanel(pageTitle, url, "");
	    return false;
	}
	else if (window.external) 
	{ 
		window.external.AddFavorite(url, pageTitle);
		return false;
	} 
	else 
	{ 
		return true; 
	} 
} 

function convertUnits(numDimensions)
{
    var mmPerInch = 0.0393700787;
    
    //if mm radio button is checked
    if(document.aspnetForm.radioUnits[0].checked==true)
    {
        for(i=1; i <= numDimensions; i++)
        {
            //set visible mm values from hidden elements
            document.getElementById('specWidth' + i).innerHTML = document.getElementById('hiddenSpecWidth' + i).value;
            document.getElementById('specHeight' + i).innerHTML = document.getElementById('hiddenSpecHeight' + i).value;
            document.getElementById('specDepth' + i).innerHTML = document.getElementById('hiddenSpecDepth' + i).value;
            
            document.getElementById('specWidthUnits' + i).innerHTML = '&nbsp;mm';
            document.getElementById('specHeightUnits' + i).innerHTML = '&nbsp;mm';
            document.getElementById('specDepthUnits' + i).innerHTML = '&nbsp;mm';
        }
    }
    //if inches radio button is checked
    if(document.aspnetForm.radioUnits[1].checked==true)
    {
        for(i=1; i <= numDimensions; i++)
        {
            // if units are already set to inches we don't want to convert again.  Handles case of 
            // inches radio button being clicked multiple times.
            
            // If no measurements are available for the item "N/A" is displayed instead, so we must
            // test to make sure that the hidden values contain a number.
            if(document.getElementById('specWidthUnits' + i).innerHTML != '\"' 
                && !isNaN(document.getElementById('hiddenSpecWidth' + i).value)
            )
            {
                var width,height,depth;
                width = document.getElementById('hiddenSpecWidth' + i).value * mmPerInch;
                height = document.getElementById('hiddenSpecHeight' + i).value * mmPerInch;
                depth = document.getElementById('hiddenSpecDepth' + i).value * mmPerInch;
                
                // javascript's round function does not allow you to specify the number
                // of decimal digits to round to.  To get around this we multiply the 
                // raw converted value by 10 to move the decimal point, then do the round
                // and divide by 10 to move the decimal point back to the proper position
                document.getElementById('specWidth' + i).innerHTML = Math.round(width*10)/10;
                document.getElementById('specHeight' + i).innerHTML = Math.round(height*10)/10;
                document.getElementById('specDepth' + i).innerHTML = Math.round(depth*10)/10;
                
                document.getElementById('specWidthUnits' + i).innerHTML = '\"';
                document.getElementById('specHeightUnits' + i).innerHTML = '\"';
                document.getElementById('specDepthUnits' + i).innerHTML = '\"';
            }
        }
    }
}