

function topsearch()
{
	if ($F('q').length>2)
	{
		//$('searchform').submit();
		window.location.href=site_root+'Search/'+$F('q')+"/";
	}
	else alert('Search phrase must be at least 3 letters long');
}


function bookmark_this_site()
{
	//var chr = 'CTRL-D'; 
	//var agt=navigator.userAgent.toLowerCase(); 
	//if(agt.indexOf("opera")!= -1) chr = 'CTRL-T'; 
	if (window.sidebar)
		window.sidebar.addPanel(document.title,self.location, "");
	else if (document.all || window.external) 
		window.external.addFavorite(self.location,document.title); 
	else if (window.opera && window.print) 
	{ 
		var elem = document.createElement('a');
		 elem.setAttribute('href',self.location);
		 elem.setAttribute('title',document.title);
		 elem.setAttribute('rel','sidebar');
		 elem.click();
	}
	//else
		//alert('Press '+chr+' to bookmark this page.'); 
}

function bookmarkthis(title,url) {
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
}







function startList() {
	if ($('nav')!=null)
	{
		if (document.all&&document.getElementById) 
		{
			navRoot = document.getElementById("nav");
			//alert(navRoot);
			if (navRoot!=null)
			{
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}
					}
				}
			}
		}
	}
}

function init_menu() 
{
	var theli = $('nav').getElementsByTagName('LI');
	var navRoot = $A(theli);
	navRoot.each(
		function(node)
		{
			//if (node.className!='fakeLink') 
			//{
					Event.observe(node,'mouseover',function(ev){Event.element(ev).className+=" over";},false);
					Event.observe(node,'mouseout',function(ev){Event.element(ev).className=Event.element(ev).className.replace(" over", "");},false);
			//}
		});
}





function navcloudinit(menuElement) {
	menuElement.childElements().each(function(node){
		// if there is a submenu
		var submenu = $A(node.getElementsByTagName("ul")).first();
		if(submenu != null){
			// make sub-menu invisible
			Element.extend(submenu).setStyle({display: 'none'});
			// toggle the visibility of the submenu
			node.onmouseout = function(){
				Element.hide(submenu);
			}
			node.onmouseover = function(){
					Element.show(submenu);
			}
		}
	});
}



function center_popup(popupid)
{
     var elt = $(popupid);
      // retrieve required dimensions
      var eltDims = elt.getDimensions();
     // var browserDims = getWindowSize();
      // calculate the center of the page using the browser and element dimensions
	  var iebody=(window.document.compatMode && window.document.compatMode != "BackCompat")? window.document.documentElement : window.document.body;
	  //var xextra=document.all? iebody.scrollLeft : w.pageXOffset;
	 // alert(getViewportHeight());
      //var y = (getDocHeight()/2) -(eltDims.height/2) + (document.all? iebody.scrollTop : window.pageYOffset);
	  var y = (document.all? iebody.scrollTop : window.pageYOffset)+50;
	  //+ (eltDims.height/2);
      var x = (getDocWidth()/2) -(eltDims.width/2) + (document.all? iebody.scrollLeft : window.pageXOffset);
     // var x = (browserDims[0] - eltDims.width) / 2;
      // set the style of the element so it is centered
	  //was postition:fixed;
	  
	  var styles = { position : 'absolute',
      top : y + 'px',
      left : x + 'px' };
      elt.setStyle(styles);
}


function product_popupclose(productid)
{
	$('productpopup'+productid).remove();
	//$('product_outeroverlay').remove();
	productshroud_off();
}

//called to perform a dynamic DB operation
function popuppart(partid)
{
	product_shroudon();
	var pars = 'rpc=display_product&partid='+partid;
		var myAjax = new Ajax.Request(
			mod_sensors_datafeed, 
			{
				method:'post', 
				postBody:pars, 
				onComplete:function(transport){
					json = transport.responseJSON;
					if (json)
					{
						if (json.status=='success')
						{	
							if (json.content)
							{
								if (json.content!='')
								{
									$(document.body).insert(json_decode(json.content));
									center_popup('productpopup'+partid);
									new Effect.Appear('productpopup'+partid);
								}
							}
							//alert(json.execute);
							if (json.execute)
							{
								if (json.execute!='')
								{
									eval(json_decode(json.execute));
								}
							}
							
							
						}
						else
						{
							//product_shroudoff();
						}
					}
					else
					{
						//product_shroudoff();
					}
				}
			});	
}

function popupfitting(id,bladetitle)
{
	var tmp = window.open('/fitting/'+id+'/'+bladetitle+'/','fitting','width=650, height=600, resizable=1, scrollbars=1,location=0');
	tmp.moveTo(200,100);
}

function product_shroudon()
{
	//dims = document.viewport.getDimensions();
	//scrolls = document.viewport.getScrollOffsets();
	//var dims = getWindowSize();
	if ($('productshroud')==null)
	{
		$(document.body).insert('<div id="productshroud" style="display:none"></div>');
		//<iframe src="javascript:false" id="productshroudiframe" style="display:none"></iframe>');
	}
	//$('productshroudiframe').setStyle({position : 'fixed',top:'0px',left:'0px',width:dims[0]+'px',height:dims[1]+'px'});
	$('productshroud').setStyle({position : 'absolute',top:'0px',left:'0px',width:getDocWidth()+'px',height:getDocHeight()+'px'});
	//$('productshroud').setStyle({position : 'fixed',top:'0px',left:'0px',width:dims[0]+'px',height:dims[1]+'px'});
	//Element.show('productshroudiframe');	
	Element.show('productshroud');
}

function productshroud_off()
{
	Element.hide('productshroud');
	//Element.hide('productshroudiframe');
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}
function getViewportHeight() {
    var D = document;
    return Math.max(
		window.innerHeight
    );
}

function getViewportWidth() {
    var D = document;
    return Math.max(
		window.innerWidth
    );
}




function getWindowSize(w) 
{
	w = w ? w : window;
    var array = [];
	//var iebody=(w.document.compatMode && w.document.compatMode != "BackCompat")? w.document.documentElement : w.document.body;
	//var xextra=document.all? iebody.scrollLeft : w.pageXOffset;
	//var yextra=document.all? iebody.scrollTop : w.pageYOffset;
    
    array.width = array[0] = (w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth))+xextra;
    array.height = array[1] =( w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight))+yextra;
    return array;
 }





function checkvform()
{
	
	retval = false;
	if($F('sendername').length>0)
	{
		if (($F('senderphone').length>0) || ($F('senderemail').length>0))
		{
			retval = true;
		}
		if (retval==false)
		{
			alert('You must enter a phone number or email address so we can contact you');
		}
	}
	else
		alert('You must enter your name');
	return retval;
}



function init_carousel()
{
	if ($('carousel-wrapper')!=null)
	{
		new Carousel('carousel-wrapper', $$('#carousel-content .slide'), null,{duration:2,auto:true,frequency:2,circular:true});
	}
		
}

function chainload()
{
	init_carousel();
}

document.observe("dom:loaded",chainload);
