var toid = null;
var menubasename = "NavMenu";  // Base name of all menu layers (ie. NavMenu0, NavMenu1, NavMenuX)
var menutimeout = 15000;  // Time that menus stay visible before automatically dissappearing.
var menuY = 108;  // Menu Top Pixel Setting. Where the top of the menu layers starts.

menu=0;menu=1;menu=2;menu=3;menu=4;menu=5;menu=6;menu=7;
	// Sets menu to be the number of menu items.  Has to be done this way because TeamSite wont tell you the Length or Count of items in a replicant

var cornerimage = new Array();  // An array of images to be randomly chosen for the top right corner.
var cornerimagecaption = new Array();  // An array of images caption
var cornerimagelink = new Array();  // An array of images links
var cornerimagelinknewwindow = new Array();  // An array of images new window links

	cornerimage[0] = "graphics/nav_right_top_pix.jpg";

	cornerimagecaption[0] = "John Deere - Lawn care from John Deere";
	cornerimagelink[0] = "";

	cornerimagelinknewwindow[0] = "";

// Browser Dectector cut down to get the basics
var agt=navigator.userAgent.toLowerCase(); 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
	&& (agt.indexOf('webtv')==-1)); 
var is_nav2 = (is_nav && (is_major == 2)); 
var is_nav3 = (is_nav && (is_major == 3)); 
var is_nav4 = (is_nav && (is_major == 4)); 
var is_nav408 = (is_nav && (is_minor == 4.08)); 
var is_nav4up = (is_nav && (is_major >= 4)); 
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) 
	|| (agt.indexOf("; nav") != -1)) ); 
var is_nav5 = (is_nav && (is_major == 5)); 
var is_nav5up = (is_nav && (is_major >= 5)); 
var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 4.")!=-1) ); 
var is_ie4up  = (is_ie  && (is_major >= 4)); 
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")!=-1) ); 
var is_ie55  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) ); 
if(!is_ie5){ var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) ); } 
	//quick fix for header so if ie6 then reports ie5 to js
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4); 
var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) ); 
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5); 
var is_opera = (agt.indexOf("opera") != -1); 
var is_webtv = (agt.indexOf("webtv") != -1); 
var is_gecko = (agt.indexOf("gecko") != -1);
var is_gecko5  = (is_gecko && (is_major == 5)); 
var is_gecko5up  = (is_gecko  && (is_major >= 5)); 

function is_pllayer(layername)
{
	islayer = null;
	if(is_gecko5up && document.getElementById(layername)){	islayer = 1;	}
	if(is_ie5 && document.all(layername)){	islayer = 1;	}
	if(is_ie4 && document.all(layername)){	islayer = 1;	}
	if(is_nav4 && document.layers[layername]){	islayer = 1;	}
	return islayer;
}	

//	change layers visibility to visible
function layerplshow(layername)
{
	if(is_pllayer(layername))
	{
		if(is_gecko5up || is_ie5){	document.getElementById(layername).style.visibility = 'visible';	}
		if(is_ie4){	document.all(layername).style.visibility = 'visible';	}
		if(is_nav4){	document.layers[layername].visibility = 'visible';	}
	}
}


//	change layers visibility to hidden
function layerplhide(layername)
{
	if(is_pllayer(layername))
	{
		if(is_gecko5up || is_ie5){	document.getElementById(layername).style.visibility = 'hidden';	}
		if(is_ie4){	document.all(layername).style.visibility = 'hidden';	}
		if(is_nav4){	document.layers[layername].visibility = 'hidden';
						document.layers[layername].visibility = 'hide';	}
	}
}

//	position layer at given coordinates
//	layerplpos('layername', xposition, yposition);
function layerplpos(layername, x, y)
{
	if(is_pllayer(layername))
	{
		x = parseInt(x);
		y = parseInt(y);
		if(is_gecko5up){	document.getElementById(layername).style.left =  x+'px';
							document.getElementById(layername).style.top =  y+'px';	}
		if(is_ie4 || is_ie5){	document.all(layername).style.top = y;
								document.all(layername).style.left = x;	}
		if(is_nav4){	document.layers[layername].top = y;
						document.layers[layername].left = x;	}
	}
}
		
function chooserandcornerimage()
{
	if(cornerimage.length > 0)
	{
		var cornerimagenum = Math.floor(Math.random()*cornerimage.length);
		if(cornerimagelink[cornerimagenum] != "")
		{
			if(cornerimagelinknewwindow[cornerimagenum] != "")
			{
				document.write('<a href="'+cornerimagelink[cornerimagenum]+'" target="CornerLink">');
			}
			else
			{
				document.write('<a href="'+cornerimagelink[cornerimagenum]+'">');
			}
			
		}
		if(cornerimagecaption[cornerimagenum] != "")
		{
			document.write("<img src='"+cornerimage[cornerimagenum]+"' alt='"+cornerimagecaption[cornerimagenum]+"' border=0><br />\n");
		}
		else
		{
			document.write("<img src='"+cornerimage[cornerimagenum]+"' border=0><br />\n");
		}
		if(cornerimagelink[cornerimagenum] != "")
		{
			document.write('</a>');
		}
	}
}

function showplMenu(menunum)
{
	hideplMenus();
	if(is_pllayer(menubasename+menunum)){	layerplpos(menubasename+menunum,  0, menuY);
											layerplshow(menubasename+menunum);	}
	toid = setTimeout("hideplMenus();", menutimeout);
}

function hideplMenus()
{
	for(i=0; i<menu+1; i++)
	{
		menunum = i;
		if(is_pllayer(menubasename+menunum)){	layerplhide(menubasename+menunum);	}
	}
	clearTimeout(toid);
}

function gonowhere(){} // Does Nothing

function redraw()
{
	// Fix bug for calling redraw() with old tpl generated pages.
}

function reloader()
{
	if(is_nav4 && !is_nav408)
	{	
		// Reloads/Refreshes the page if window is resized and is netscape.
		location.reload();
	}
}

function submitForm(command)
{
leavingSite = false;
if(command != null) document.forms[0].command.value=command;
document.forms[0].submit();
}

function jdCardPopup() {
	window.open('/collab/customer/FinanceTerms.do','','width=325,height=440,toolbar=no,location=no,directories=no,status=no,menubar=no,resizeable=yes,scrollbars=yes');
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addUnloadEvent(func) {
  var oldonunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  } else {
    window.onunload = function() {
      oldonunload();
      func();
    }
  }
}

/*

-- Function intended to open a popup window offering users a printable version of
-- their cart.  Intented for use as an on-unload handler.  Expects that links 
-- which don't want this to show up will have an onclick handler which sets
-- the value of 'leavingSite' to false.  Expects pages to have 'leavingSite'
-- as a page-scoped variable, which is handled in the "basicPage.jsp"
*/
var popupDebug = false;

function offerPrintableCart(evt)
{
    return false; // temporarily disable printable cart.
    try {
        var loc = "begin"
        if (leavingSite)
        {
			
            loc = "about to get result";
            var result = window.open('/collab/customer/OfferPrintableCart.do','OfferCart','width=300,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes');
            loc = "about to focus";
            if (result && result.focus) result.focus();
        } 
    } catch(e) {
        var msg = (e.message) ? e.message: e.description;
        if (popupDebug) alert("Error offering cart at " + loc + ": " + msg);
    }
}