window.onload = formatFOM;
window.onresize = function ()
{
    // NOTE:  This dunction deliberately ignores IE6.0 and below.  Try to explicit set a
    // function for IE6 will cause the browser to crash.
    
    // Detects if a browser is not Internet Explorer and sends to formatLayout function
    if (navigator.userAgent.lastIndexOf("MSIE") <= 0)
    {
        formatLayout();
    }
    // Detects if a browser is Internet Explorer 7.0 and sends to formatLayout2 function
    if(navigator.userAgent.lastIndexOf("MSIE 7.0") >=0)
    {
        formatLayout2();
    }	       
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Detects browser on page load and sends to appropriate function
function formatFOM()
{
    // Detects if a browser is not Internet Explorer and sends to formatLayout function
    if(navigator.userAgent.lastIndexOf("MSIE") <=0){
        formatLayout();
    }
    else 
    {
        // Layout formatting of FOM section for IE only
        if (document.body.clientWidth > 975){
            MM_findObj('default-mode').disabled = true;
            MM_findObj('layout-mode').href = '/styles/layout-wide.css';
            MM_findObj('section-mode').href = '/styles/sections-wide.css';
        }
        else {
            MM_findObj('default-mode').disabled = true;
            MM_findObj('layout-mode').href = '/styles/layout-narrow.css';
            MM_findObj('section-mode').href = '/styles/sections-narrow.css';
        }
    }
}

// Formats layout for all browsers other than Internet Explorer
function formatLayout()
{
    if (document.body.clientWidth > 975){
        MM_findObj('default-mode').href = '/styles/layout-wide.css';
    }
    else {
        MM_findObj('default-mode').href = '/styles/layout-narrow.css';
    }
}

// Formats layout for Internet Explorer 7.0 only
function formatLayout2()
{
    if (document.body.clientWidth > 975){
        MM_findObj('layout-mode').href = '/styles/layout-wide.css';
        MM_findObj('section-mode').href = '/styles/sections-wide.css';
    }
    else {
        MM_findObj('layout-mode').href = '/styles/layout-narrow.css';
        MM_findObj('section-mode').href = '/styles/sections-narrow.css';
    }
}
