function brand_links(targ,selObj,restore){
if (selObj.options[selObj.selectedIndex].value.length>0)
    {
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
     }
}


//for IE6 flyout nav
var className = "iehover";
function on(which) {
	if(which.className == 'more flyOutParent'){
		which.className='more flyOutParent iehover';
	}
	else{
		which.className='flyOutParent iehover';
	}
}
function off(which) {
	if(which.className == 'more flyOutParent'){
		which.className='more flyOutParent';
	}
	else{
		which.className='flyOutParent';
	}
}


function rollout() {
 var img;
 img = document.getElementById('ctl00_ContentPlaceHolder_hidImagedefault').value
 document.getElementById('ctl00_ContentPlaceHolder_imgProduct').src = img

 }

 function showrolloverimage(imagenumber)
 {
 var img;
 if (imagenumber==1){
 img = document.getElementById('ctl00_ContentPlaceHolder_hidImage1').value;
 document.getElementById('ctl00_ContentPlaceHolder_imgProduct').src = img;
 //set thumb to previous img
 }
 if (imagenumber==2){
img = document.getElementById('ctl00_ContentPlaceHolder_hidImage2').value;
document.getElementById('ctl00_ContentPlaceHolder_imgProduct').src = img;
}
}

// Grab all classes by classname
function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//addLoadEvent(runBookmark);
function runBookmark(){
	var bookmark = document.getElementById("bookmark");
	var title = bookmark.getAttribute("title");
	bookmark.onclick = function(){
		return addBookmark(title, bookmark);
    }
}

// Add bookmark for both browser engines...
function addBookmark(title,url) {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
  } else if( document.all ) {
    window.external.AddFavorite( url, title);
  } else if( window.opera && window.print ) {
    return true;
  }
} 

addLoadEvent(openPopup);
function openPopup(){
	
	var popupLinks = getElementsByClassName("openPopup");
	
	for ( var i=0; i < popupLinks.length; i++ ){
		var trigger = popupLinks[i].getAttribute("className") || popupLinks[i].getAttribute("class");
		//alert(trigger);
		switch(trigger)
		{
		case "openPopup prodPopup":
			popupLinks[i].onclick = function(){
				return openProductPopup(this);
			}
		break;
		case "openPopup emailPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "EmailFriend", "470", "440", "" );
			}
		break;
		case "openPopup passPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "Forgotten", "470", "300", "" );
			}
		break;
		case "openPopup securityCode":
			popupLinks[i].onclick = function(){
				return popup( this, "seccode", "520", "380", "" );
			}
		break;
		case "openPopup termsPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "Terms", "520", "380", "" );
			}
		break;
		case "openPopup printOrder":
			popupLinks[i].onclick = function(){
				return popup( this, "Purchase", "590", "650", "1" );
			}
		break;
		case "openPopup spareParts":
			popupLinks[i].onclick = function(){
				return popup( this, "Spare_Parts", "487", "650", "1" );
			}
		break;
		}
	}
}


function popup( vURL, vWinName, vWidth, vHeight, vScrollbar)
{
	if (! window.focus)return true;
	
	var vhref;
	var vSWidth = screen.width
	var vSHeight = screen.height
	
	if(vScrollbar == "yes")
	{
		vWidth = new Number(vWidth) + 16
	}
	
	var vleftPos = (vSWidth / 2) - (vWidth / 2)
	var vtopPos = (vSHeight / 2) - (vHeight / 2)
	
	if (typeof(vURL) == 'string')
	{
		vhref = vURL;
	} else {
		vhref = vURL.href;
	}
	window.open(vhref, vWinName, 'scrollbars=' + vScrollbar + ',statusbar=no,menubar=0,width=' + vWidth + ',height=' + vHeight + ',left=' + vleftPos + ',top=' + vtopPos);
	
	return false;
}

function openProductPopup(source)
{
   	var popupPage = source.href + '?x=y';
	popup(popupPage, 'Product', productPopupWidth, productPopupHeight, 'no');
	return false;
}

function setProductPopup(width, height)
	{
		productPopupWidth = width;
		productPopupHeight = height;
	}

function ValidateQty()
{		
	var bError = false;
	var quantity = document.getElementById("prod_quantity")

	if (quantity.value == "0" || quantity.value == "" || isNaN(quantity.value) )
	{
		alert("Please enter a quantity");
		//qty.value = "";
		quantity.focus();
		bError = true;
	}

	if (bError == false)
	{
		//Validation OK submit to basket	
		document.product_infoForm.submit();
	}
	else
	{
		return false;	
	}
}

function handleEnter (field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
	   return false;
    }
    else
    return true;
}

 function doGoClick(buttonName,postBack,e)
    {
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
        var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13)
        {
            //Get the button the user wants to have clicked
           
               __doPostBack(postBack,'');
                event.keyCode = 0
        }
   }
   
/* function to reset all checkboxes to unchecked */
function accessoriesClearCheck()
	{
	var container = document.getElementById("ctl00_ContentPlaceHolder_divAccessories");
	var checkBoxes = container.getElementsByTagName("input");
	
	for ( var i=0; i<checkBoxes.length; i++ ) 
		{
		if ( checkBoxes.checked == true )
			{
			checkBoxes[i].checked = true;
			}
		else
			{
			checkBoxes[i].checked = false;
			}
		}
	}  
	
	
	function clearAllFields(){
        var texts=document.getElementsByTagName('input')
        for (var i_tem = 0; i_tem < texts.length; i_tem++)
        if (texts[i_tem].type=='text')
        texts[i_tem].value=''
        
        
        
        var brandDD = document.getElementById('brndDrop').selectedIndex = 0;
        var engineBrandDD = document.getElementById('engineBrand').selectedIndex = 0;
        
        } 