function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  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')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function submitform() {
  document.searchsite.submit();
}

function locatedealer() {
	document.locatedealer.submit();
}

function locatormap_redirect(country,provstate) {
	var destination = '/dealers';
	
	if (country == 'namerica') {
		destination = '/locator/northamerica';
	}
	else {
		if (country) {
			destination = destination + '/' + country;	
		}
		if (provstate!=0) {
			destination = destination + '/' + provstate;
		}
	}
	location.href = destination;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function update_country() {
	var countrybox = document.locatedealer.opt_country;
	var country = countrybox.options[countrybox.selectedIndex].value;

	var destination = '/locator';
	
	if (country) {
		destination = destination+'/'+country;
		location.href = destination;
	}
}

function update_provstate() {
	var countrybox = document.locatedealer.opt_country;
	var country = countrybox.options[countrybox.selectedIndex].value;
	
	if (document.locatedealer.opt_provstate != null) {
		var provstatebox = document.locatedealer.opt_provstate;
		var provstate = provstatebox.options[provstatebox.selectedIndex].value;
	}
	
	var destination = '/locator';
	
	if (country) {
		destination = destination+'/'+country;
		
		if(provstate) {
			destination = destination+'/'+provstate;	
		}
		location.href = destination;
	}
}

function popup(url,x,y) {
window.open(url,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width='+x+',height='+y+',left=0,top=0');
}

function clickProductMenuButton(a,b) {
	var obja,objb;
	obja=MM_findObj(a);
	objb=MM_findObj(b);
	
	if (a=='category_btn_div') {
		obja.className='productmenu_option_button_left_b';
		objb.className='productmenu_option_button_right';
	}
	else if (a=='application_btn_div') {
		obja.className='productmenu_option_button_right_b';
		objb.className='productmenu_option_button_left';
	}
}

function initPanelCells() {
	var cellid = document.getElementById("pline_products");
	if (cellid) {
		var cellgroup = cellid.getElementsByTagName("td");
			for(i=0;i<cellgroup.length;i++) {
				  var link = cellgroup[i].getElementsByTagName("a")
				  if (link.length == 1) {
					cellgroup[i].onclick = clickCell;
					cellgroup[i].onmouseover = mouseoverCell;
					cellgroup[i].onmouseout = mouseoutCell;
				  }
			}
	}
  
	var cellid = document.getElementById("subcategory_panels");
	if (cellid) {
		var cellgroup = cellid.getElementsByTagName("td");
			for(i=0;i<cellgroup.length;i++) {
				  var link = cellgroup[i].getElementsByTagName("a")
				  if (link.length == 1) {
					cellgroup[i].onclick = clickCell;
					cellgroup[i].onmouseover = mouseoverCell;
					cellgroup[i].onmouseout = mouseoutCell;
				  }
			}
	}
}

function clickCell() {
	var link = this.getElementsByTagName("a");
	window.location=link[0].href;
}

function mouseoverCell() {
	this.className="highlight";
	if(this.getAttribute('rollover')!='') {
		MM_swapImage('subcat_rollover','',this.getAttribute('rollover'),1);
//	if(this.getAttribute('title')!='') {
//		MM_swapImage('subcat_rollover','',this.getAttribute('title'),1);

	}	
}

function mouseoutCell() {
	this.className="panel";
	MM_swapImgRestore();
}

function initProductTabs() {
	var tabgroup = document.getElementById("product_tabwrapper");
	if(tabgroup) {
		var tabs = tabgroup.getElementsByTagName("div");
		for(i=0;i<tabs.length;i++) {
			  var link = tabs[i].getElementsByTagName("a")
			  if (link.length == 1) {
				tabs[i].onclick = clickTab;
				tabs[i].onmouseover = mouseoverTab;
				tabs[i].onmouseout = mouseoutTab;
			  }
		}
	}
}

function clickTab() {
	var link = this.getElementsByTagName("a");
	window.location=link[0].href;
}

function mouseoverTab() {
	var link = this.getElementsByTagName("a");
	link.className="selected";
	this.style.cursor="pointer";
}

function mouseoutTab() {
	var link = this.getElementsByTagName("a");
	link.className="";
	this.style.cursor="default";
}

function productTabRollover(url) {
	window.location = url;	
}

function show_related(pos) {
	var sections = getElementsByClassName(document,"*","related_products_section");
	var sectiondivs;
	var sectionlinks;
	for(i=0;i<sections.length;i++) {
		sectiondivs = sections[i].getElementsByTagName("div");
		if (i==pos) {
			sectiondivs[0].style.backgroundImage == "url(images/product_downarrow.gif)"

			for(x=1;x<sectiondivs.length;x++) {
				sectiondivs[x].style.position = "relative";
				sectiondivs[x].style.visibility = "visible";
			}
		}
		else {
			sectiondivs[0].style.backgroundImage = "url(images/slideshow_rightarrow.gif)";
			for(x=1;x<sectiondivs.length;x++) {
				sectiondivs[x].style.position = "absolute";
				sectiondivs[x].style.visibility = "hidden";	
			}
		}
	}
}

function getAbsPos( oId, tl ) {
var o = ( typeof oId == 'String' ) ? document.getElementById( oId ) : oId;
var val = 0;
while ( o.nodeName != "BODY" ) {
val += parseInt( ( tl == 'top' ) ? o.offsetTop : o.offsetLeft );
o = o.parentNode;
}
return val;
}

function move_lineup_left() {
	var lineup = document.getElementById("image_lineup");
	var pos_left = lineup.offsetLeft;
	if (pos_left < 0) {
		pos_left += 42; 
		lineup.style.left = pos_left + "px";
	}
}

function move_lineup_right(maxitems) {
	var max_left = 0-((maxitems - 4)*42)
	var lineup = document.getElementById("image_lineup");
	var pos_left = lineup.offsetLeft;
	if (pos_left > max_left) {
		pos_left -= 42;
		lineup.style.left = pos_left + "px";
	}
}

function show_photo(displaypath, originalpath) {
	var imageobj = document.getElementById("image_display_box");
	var imagelink = document.getElementById("image_display_link");
	// alert(displaypath+' and '+originalpath);
	imageobj.src = displaypath;
	imagelink.href = originalpath;
}