//this function show and hide product description
function showDescText(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("productsubdesc");
		if (ar)  //zpetna kompaktibilita v obecnem pouziti
		{
			ar = ar.getElementsByTagName("div");
		}

		if(el.style.display == "none"){
			if (ar) //zpetna kompaktibilita v obecnem pouziti
			{
				for (var i=0; i<ar.length; i++){
					ar[i].style.display = "block";
				}
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//this function show only select id with prefix. Others will be hidden
function divIsVisible( objid )
{
	if( document.getElementById )
	{
		var el = document.getElementById( objid );
		return  el.style.display != "none";
	}
	return true;
}

//this funciton hide description on start
function infoldItems(){
	var par = document.getElementById("productsubdesc");
	if (par){
		var ar = par.getElementsByTagName("div");
		for(var i=0; i<ar.length; i++){
			ar[i].style.display = "none";
		}
	}
}

/* funkce pro praci s tabs v e-shopu start */
function tabs_start () {

	var crttabs = document.getElementById("crttabs");
	crttabs.style.display = "block";

	var boxbuy = document.getElementById("boxbuy");
	boxbuy.className = "shpboxcrn";

	var tabbuy = document.getElementById("tabbuy");
	tabbuy.className =  "crttabla";

	var tabbuyin = document.getElementById("tabbuyin");
	tabbuyin.className = "crttabra";

	var abuy = document.getElementById("abuy");
	abuy.className = "shptaba";

	var boxrnw = document.getElementById("boxrnw");
	boxrnw.style.display = "none";

}

function sel_buy () {
	//window.alert("buy");
	tabs_start();
	var boxbuy = document.getElementById("boxbuy");
	boxbuy.style.display = "block";

	var tabrnw = document.getElementById("tabrnw");
	tabrnw.className =  "crttabl";

	var tabrnwin = document.getElementById("tabrnwin");
	tabrnwin.className = "crttabr";

	var arnw = document.getElementById("arnw");
	arnw.className = "shptab";

}


function sel_rnw () {
	//window.alert("rnw");

	var boxbuy = document.getElementById("boxbuy");
	boxbuy.style.display = "none";

	var boxrnw = document.getElementById("boxrnw");
	boxrnw.style.display = "block";
	boxrnw.className = "shpboxcrn";

	var tabbuy = document.getElementById("tabbuy");
	tabbuy.className =  "crttabl";

	var tabbuyin = document.getElementById("tabbuyin");
	tabbuyin.className = "crttabr";

	var abuy = document.getElementById("abuy");
	abuy.className = "shptab";

	var tabrnw = document.getElementById("tabrnw");
	tabrnw.className =  "crttabla";

	var tabrnwin = document.getElementById("tabrnwin");
	tabrnwin.className = "crttabra";

	var arnw = document.getElementById("arnw");
	arnw.className = "shptaba";

}


/* funkce pro paci s tabs v e-shopu konec */

function ieLinks()
{
	if (!window.ActiveXObject)
	{
		return true;
	}
	
	var links = document.getElementsByTagName('a');
	
	var images = new Array();
	
	if (links != null && links.length > 0)
	{
		
		for (var i = 0; i < links.length; i++)
		{
			if ( links[i].getAttribute('href') == null || links[i].currentStyle.backgroundImage == '' /* || links[i].childNodes.length > 1 */ )
			{
				continue;
			}
			
			replace = false;
			
			if (links[i].className != '')
			{
				switch(links[i].className)
				{
					case 'window':
					case 'dwn':
					case 'key':
					case 'srch':
					case 'show':
					case 'hide':
					case 'back':
					case 'cart':
					case 'updt':
					case 'del':
					case 'detail':
						replace = true;
					break;
				}
			}
			else if ( links[i].currentStyle.backgroundImage.indexOf('link_ico_default.gif') > 1 )
			{
				replace = true;
			}

			if (replace)
			{
				pos = links[i].currentStyle.backgroundImage.length - 2;
				imgUrl = links[i].currentStyle.backgroundImage.substring(5, pos);
			
				img = document.createElement('img');
				img.setAttribute('src', imgUrl);
				img.style.cssText = 'margin-bottom: -1px; margin-right: 3px;';
				
				linkText = links[i].innerHTML;
				links[i].innerHTML = '';
	
				span = document.createElement('span');
				span.innerHTML = linkText;
	
				links[i].style.backgroundImage = 'none';
				links[i].style.paddingLeft = '0px';
				//links[i].style.border = '1px solid red';
				links[i].appendChild(img);
				links[i].appendChild(span);
			}
			
			replace = false;
		}
	}
}

/*zalozky v obsahu*/
function setTabs(tabsId, contentId, activeTabId, activeContentId)
{
	var content = document.getElementById(contentId);
	
	/* skryti obsahu */
	if (content != null)
	{
		var nodes = content.childNodes;
		
		if (nodes != null)
		{
			for(var i = 0; i < nodes.length; i++)
			{
				if (nodes[i].nodeType == 1)
				{
					nodes[i].style.display = 'none';
				}
			}
		}
	}
	
	/* nastaveni neaktivity zalozek */
	var tabs = document.getElementById(tabsId);
	if (tabs != null)
	{
		var nodes = tabs.getElementsByTagName('li');
		
		if (nodes != null)
		{
			for(var i = 0; i < nodes.length; i++)
			{
				nodes[i].className = '';
			}
		}
		
	}
	
	/* zobrazeni obsahu pod aktivni zalozkou */
	var activeContent = document.getElementById(activeContentId);
	if (activeContent != null)
	{
		activeContent.style.display = 'block';
	}
	
	/* nastaveni stylu vybrane zalozky */
	var activeTab = document.getElementById(activeTabId);
	if (activeTab != null)
	{
		activeTab.className = 'active';
	}
	
	return true;
}

function IsTable(node)
{
	if (node.tagName != null && node.className != null &&
		node.tagName.toLowerCase() == "table" &&
		node.className.toLowerCase() == "norm")
	{
		return true;
	}
	return false;
}

function SetTables()
{
	var root = document.getElementById('mayor');
	
	if (root != null)
	{
		for(var index = 0; index < root.childNodes.length; index++)
		{
			if ( IsTable(root.childNodes[index]) )
			{
				tbbg = document.createElement('div');
				tbbg.className = 'tbbg';
				tbbgbtm = document.createElement('div');
				tbbgbtm.className = 'tbbgbtm';
				tbbgtop = document.createElement('div');
				tbbgtop.className = 'tbbgtop';
	
				table = root.childNodes[index].cloneNode(true);
	
				tbbgtop.appendChild(table);
				tbbgbtm.appendChild(tbbgtop);
				tbbg.appendChild(tbbgbtm);
				
				root.childNodes[index].parentNode.replaceChild(tbbg, root.childNodes[index]);
			}
		}
	}
	
	return true;
}

function postProcess()
{
	SetTables(); 
	ieLinks();
}

window.onload = postProcess;

