//This function preloads the global navigation elements
var navRoll = false;
//Set this variable to false so no global rollovers will work until all preloading is done.
function plGnav()
{
	plImages();
	navRoll = true;
}

function plImages()
{
    var linkArray = document.getElementsByTagName("img");
    for (var loop=0; loop<linkArray.length; loop++)
    {
        if (linkArray[loop].className == "pl")
        {
			var imgPath = linkArray[loop].src.substring( 0, linkArray[loop].src.lastIndexOf( '/' ) + 1 );
			uPreload( linkArray[loop].id, imgPath, linkArray[loop].src.substring( linkArray[loop].src.lastIndexOf( '.' ) ) );
        }
    }
}

//This function preloads rollover images with a & i suffixes for active and inactive
//The function can preload any number of images.
//usage: uPreload( object name, directory of image, extension of image )
var imgSuffix = new Array('i', 'a');
function uPreload(imgName, imgPath, imgExt)
{
	for (i=0; i < imgSuffix.length; i++) {
		eval( imgName + imgSuffix[i] + " = new Image();" );
		eval( imgName + imgSuffix[i] + ".src = '" + imgPath + imgName + imgSuffix[i] + imgExt + "';" );
    }
}

//This function is for navigation rollover images; uName is name of graphic, uState is on, off or over state
function nr(uName, uState)
{
   if(navRoll)
   {
      document.images[uName].src = self[uName + uState].src;
   }
}

function drp2(uName,uState)
{
	var pFam = uName.substring(0,3) //Get parent string
	var lName = 'd' + pFam; //Make div name to show or hide
	MM_showHideLayers(lName,'',uState);	
}

function checkIt(string) 
{
var detect = navigator.userAgent.toLowerCase();
return detect.indexOf(string) + 1;
}

function MM_showHideLayers()
{
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
if (checkIt('mac')&&v=='visible') obj.pixelTop = obj.pixelTop ;
obj.visibility=v; }
}

function MM_findObj(n, d) 
{
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;
}

function wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
      var rSize = 'no'
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
      var rSize = 'yes'
   }
   var iMyWidth;
   var iMyHeight;
   wHeight = wHeight + 12;
   //Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=" + rSize + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

// Detects if a parent window is open and loads URL into it.  Otherwise, pops a new window for URL.
function toParent(zUrl)
{
   // First check to see if there's a parent window, or a parent.parent window
   var pWin = 0;
   // Parent window is assumed closed
   if(window.opener != null && !window.opener.closed)
   {
      // One parent
      pWin = 1;
   }
   if(window.opener.opener != null && !window.opener.opener.closed)
   {
      // Two parents
      pWin = 2;
   }
   if(pWin == 0)
   {
      // Open a blank window
      var blankWin = window.open(zUrl, blankWin, "width=775,height=600,resizable=yes,left=10,top=10,screenX=10,screenY=10,scrollbars=yes,toolbar=yes,titlebar=yes,status=yes,menubar=yes,personalbar=yes,location=yes,directories=yes");
   }
   if(pWin == 1)
   {
      // Load into parent window
      opener.location.href = zUrl;
      opener.focus();
   }
   if(pWin == 2)
   {
      // Load into parent parent window
      opener.opener.location.href = zUrl;
      opener.opener.focus();
   }
}

function legal_window(url)
{
	var link = window.open(url,"legal",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=(20),left=(20),screenX=(20),screenY=(20),width=560,height=450');
	link.focus();
}

function wallpaper_prev(url)
{
	link = window.open(url,"wallpaper",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,top=(20),left=(20),screenX=(20),screenY=(20),width=360,height=480');
}

function phoneSelector(argURL){
        window.opener.location=argURL;  // redirect parent
        window.opener.focus();          // bring parent window to the top
        window.close();                 // close child
}

function pf() //pop-up printer friendly pages
{
	var url = window.location.href.split('#')[0];
	url += url.indexOf('?') != -1 ? '&' : '?';
	wPop( url + 'print=1', 'print', 610, 550, 'yes' );
}

function brandSelect( ddl ) {
	var s = ddl.options[ ddl.selectedIndex ].value;
	if ( s.length == 0 )
		return;
	if ( s.substring(0,11) == "javascript:" )
		eval( s.substring(11) );
	else if ( s.substring(0,4) == "http" )
		window.open( s, "_blank" );
	else
		document.location.href = s;
}

function brandPop( url ) {
	wPop( url,"brand",650,440,'yes' );
}

function brandPopLg( url ) {
	wPop( url,"brand",770,560,'yes' );
}

function emailFriend( url ) {
	wPop( url,'email_friend',310,520 );
}

function rndNum(max)
{
	return Math.floor(Math.random() * max);
}

function rndLyr(ttlLyrs)
{
	document.getElementById( 'rndLyr' + rndNum(ttlLyrs) ).style.display = 'block';
}

function toolPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
   }
   var iMyWidth;
   var iMyHeight;
   wHeight = wHeight + 12;
   //Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "toolbar=yes,status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

function contactPop( url ) {
	toolPop( url,"contact",700,600,'yes');
}

var prefix = "Step2.aspx?cid=";

function convertImagery(modelName, url, cid, mfgid, mid)
{	//this function builds out the full path to the large image, then creates the querystring values and url for step 2 on submit
	var path = url;
	document.images['featurePhone'].src = path;
	submitButton.style.display = 'block';
	prefix = "Step2.aspx?cid=";
	prefix += cid;
	prefix += "&mfg=";
	prefix += mfgid;
	prefix += "&mid=";
	prefix += mid;
	var submitUrl = document.getElementById( "submitUrl" );
	submitUrl.href = prefix;
}

function sfHover() 
{
	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer" && document.getElementById("tnav"))
	{
		var sfEls = document.getElementById("tnav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

AttachEvent(window, "load", sfHover);

function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{
  if (elementObj.addEventListener) 
  { // Non-IE browsers
    elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
  } 
  else if (elementObj.attachEvent) 
  { // IE 6+
    elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
  } 
  else 
  { // Older browsers 
    var currentEventHandler = elementObj['on' + eventName];
    if (currentEventHandler == null) 
    {
      elementObj['on' + eventName] = eventHandlerFunctionName;
    } 
    else 
    {
      elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
    }
  }
}

function divDisplay(divName, displayStyle)
{
	document.getElementById( divName ).style.display = displayStyle;
}