if (document.createElement) {	// img element for product details tabs
    var previousImage = document.createElement("img");
    previousImage.setAttribute("src", "../common/images/backs/details_tab_bottom.gif");
    previousImage.setAttribute("class", "previousImage");
}

function showInitialTab() {
    document.getElementById("productDetailsTab").className = "selectedDetailTab";
}

function hideTabs() {
    document.getElementById("CheckAvailability").style.display = 'none';
    document.getElementById("checkAvailabilityTab").className = "lastDetailTabOff";
    
    if (document.getElementById("productDetailsTab") != null) {
	document.getElementById("ProductDetails").style.display = 'none';
	document.getElementById("productDetailsTab").className = "detailTab";
    }
    
    if (document.getElementById("technicalSpecsTab") != null) {
	document.getElementById("TechnicalSpecs").style.display = 'none';
	document.getElementById("technicalSpecsTab").className = "detailTab";
    }
    
    if (document.getElementById("cadDrawingsTab") != null) {
	document.getElementById("cadDrawings").style.display = 'none';
	document.getElementById("cadDrawingsTab").className = "detailTab";
    }
}
    
function showTab(tab) {
    document.getElementById(tab).style.display = 'block';
    
    var tabID = tab.substring(0, 1).toLowerCase() + tab.substring(1, tab.length) + "Tab";
    
    var selectedTab = document.getElementById(tabID);
    
    if (tabID == "checkAvailabilityTab") {
	selectedTab.className = "lastDetailTabOn";
    } else {
	selectedTab.className = "selectedDetailTab";
    }
    
    var container = selectedTab.parentNode;
    
    if (tabID != "productDetailsTab") {
	//previousImage.className = "previousImage";
	
	previousImage.style.display = 'inline';
	previousImage.style.height = '25px';
	//previousImage.style.marginLeft = '-17px';
	previousImage.style.position = 'relative';
	//previousImage.style.left = '-12px';
	//previousImage.style.float = 'left';
	previousImage.style.top = '9px';
	previousImage.style.left = "-12px";
	previousImage.style.marginTop = '-12px';
	previousImage.style.marginRight = '-15px';
	
	container.insertBefore(previousImage, selectedTab);
    } else {
	previousImage.style.display = 'none';
    }
    
    /*if (tabID == "technicalSpecsTab") {
	document.getElementById("productDetailsTab").background = "url(../images/backs/details_tab_bottom.gif) right bottom no-repeat;";
    }*/
}

function showImages() {

    if (hideThis.style.display != '') {
	hideThis.style.display = '';
            
	var x = (window.innerWidth / 2) - (hideThis.offsetWidth / 2);
	var y = (window.innerHeight / 2) - (hideThis.offsetHeight / 2); 
	
	//alert(window.innerWidth / 2 + " - " + hideThis.offsetWidth / 2);
	
	hideThis.style.top = y + "px";
	hideThis.style.left = x + "px";
	
	//alert(x + ":" + y);
    }
    else { 
	hideThis.style.display = 'none'
    }
}

function changeImage(source) {
    document.getElementById("displayImage").innerHTML = "<img src=" + source.src + ">";
}

// open a popup window with params
function popupUrl() {
	var newWindow = window.open(SITE_ROOT + "products/includes/greenProducts.html");
	newWindow.focus();
}

function showDetailTab(tab, obj) {
    allTabsUnselected = document.getElementsByClassName('productTab');
    allTabsSelected = document.getElementsByClassName('productTabSelected');
    allTabs = new Array();
    allTabContent = document.getElementsByClassName('productTabContent');
    
    if (document.getElementById('initialProductTab') != null) {
      var initialTab = document.getElementById('initialProductTab')
      initialTab.setAttribute("id", "");
    }
    
    for (i = 0; i < allTabsUnselected.length; i++) {
      allTabs.push(allTabsUnselected[i]);
    }
    
    for (i = 0; i < allTabsSelected.length; i++) {
      allTabs.push(allTabsSelected[i]);
    }
    
    for (i = 0; i < allTabs.length; i++) {
	/*allTabs[i].style.backgroundColor = '#00599c';
	allTabs[i].style.borderBottomColor = '#00599c';*/
	allTabs[i].className = 'productTab';
    }
    
    if (document.getElementById(tab) != null) {
	var selectedTab = document.getElementById(tab);
	
	for (i = 0; i < allTabContent.length; i++) {
	    
	    if (allTabContent[i] == selectedTab) {
		selectedTab.style.display = 'block';
		
		/*obj.style.backgroundColor = '#003b69';
		obj.style.borderBottomColor = '#003b69';*/
		
		obj.className = 'productTabSelected';
	    } else {
		allTabContent[i].style.display = 'none';
	    }
	}
    }
}

function displayQueryString() {
    fullURL = parent.document.URL;
    //alert(fullURL.substring(fullURL.indexOf('?'), fullURL.length));
    queryString = fullURL.substring(fullURL.indexOf('?')+1, fullURL.length);
    document.writeln('<a href="../products.ex?' + queryString + '#productResults" class="seeAllProducts">See Product Results</a>');
}

function validateAddToCart(form, qtyField) {
  if (document.getElementById) {
    var cartErrors = document.getElementById("addCartErrors");
    var qty = document.getElementById("addCartQty");
    
    if (cartErrors != null && qty != null) {
    
      if (isNaN(parseInt(qty.value))) {
	  cartErrors.innerHTML = "<ul><h4>The following errors occurred</h4><li>Quantity must be numeric</li><ul>";
	  cartErrors.style.display = "block";
	  
	  return false;
      } else if ((qty.value % 1) != 0) {
	  cartErrors.innerHTML = "<ul><h4>The following errors occurred</h4><li>Quantity must be an integer</li><ul>";
	  cartErrors.style.display = "block";
	  
	  return false;
      }else if (qty.value <= 0) {
	  cartErrors.innerHTML = "<ul><h4>The following errors occurred</h4><li>Quantity must be greater than zero</li><ul>";
	  cartErrors.style.display = "block";
	  
	  return false;
      }
    }
  }
  return true;
}

function submitFormLink(formName) {
  document.forms[formName].submit();
}

function showAllRefinements(ref) {
  var refinement = document.getElementById(ref);
  var showAllLink = document.getElementById(ref + "SeeAll");
  
  if (refinement && showAllLink) {
    refinements = refinement.getElementsByTagName("li");
  
    for (i = 0; i < refinements.length; i++) {
      refinements[i].style.display = "block";
    }
  
    showAllLink.style.display = "none";
  }
}













































