// http://www.dustindiaz.com/top-ten-javascript/ //

// Togle DIV
function Toggle(obj) {
  // close all
  closeAll();
  // open current
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

// close all
function closeAll(){
  var all_prod=getElementsByClass('product_list');
  for(var i=0; i<all_prod.length; i++){
    all_prod[i].style.display = 'none';
  }
}

// mark clicked link as selected
function selectLink(){
  this.style.background="#474747 url(../img/bullet.gif) no-repeat 20px 6px";
	this.style.textDecoration = "none";
  this.className="selected";	
}

/*
function setSelected(pid, pgp){
  Toggle(pgp);
  var all_prod_id=document.getElementById(pgp).getElementsByTagName('a');  
  all_prod_id[pid].className='selected';  	
}
*/
function setSelected(pgp_pid, pgp){
  Toggle(pgp);
  var all_prod_id=document.getElementById(pgp).getElementsByTagName('a');     
  prod_id = all_prod_id.namedItem(pgp_pid);
  prod_id.className='selected';  	
}
// get DOM element by class
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//Change product logo when clicking a tab: 
var IMG_LOGOS_BASE = "img/products/logos/";
var IMG_LOGOS_FILES = [ "Logo_GongDong.jpg", "Logo_Biosigma.gif", "Logo_Sanguis.jpg", "vitrex.gif", "Logo_Dragonmed.gif" ];

function changeImgPrdLogo (tabIdx)
{
	prdEl = document.getElementById("imgPrdLogo");
	if(prdEl != null)
	{
		prdElImg = prdEl.getAttribute("src");
		if(prdElImg != null)
		{
			prdElImg = IMG_LOGOS_BASE+IMG_LOGOS_FILES[tabIdx];
			prdEl.setAttribute("src", prdElImg);
		}
	}
	
}

