// Preload images of language selector
function preloadLngsel()
{
	auImg = new Image(16,11);
	auImg.src = '/common/images/flags/au.gif';
	brImg = new Image(16,11);
	brImg.src = '/common/images/flags/br.gif';
	caImg = new Image(16,11);
	caImg.src = '/common/images/flags/ca.gif';
	czImg = new Image(16,11);
	czImg.src = '/common/images/flags/cz.gif';
	deImg = new Image(16,11);
	deImg.src = '/common/images/flags/de.gif';
	frImg = new Image(16,11);
	frImg.src = '/common/images/flags/fr.gif';
	gbImg = new Image(16,11);
	gbImg.src = '/common/images/flags/gb.gif';
	ieImg = new Image(16,11);
	ieImg.src = '/common/images/flags/ie.gif';
	itImg = new Image(16,11);
	itImg.src = '/common/images/flags/it.gif';
	jpImg = new Image(16,11);
	jpImg.src = '/common/images/flags/jp.gif';
	laesImg = new Image(16,11);
	laesImg.src = '/common/images/flags/laes.gif';
	nlImg = new Image(16,11);
	nlImg.src = '/common/images/flags/nl.gif';
	plImg = new Image(16,11);
	plImg.src = '/common/images/flags/pl.gif';
	ptImg = new Image(16,11);
	ptImg.src = '/common/images/flags/pt.gif';
	skImg = new Image(16,11);
	skImg.src = '/common/images/flags/sk.gif';
	usImg = new Image(16,11);
	usImg.src = '/common/images/flags/us.gif';
	wwImg = new Image(16,11);
	wwImg.src = '/common/images/flags/ww.gif';
}

// Show/Hide language selector
function showLngsel()
{
	el = document.getElementById( 'lnglist' );
	if ( el.style.display == "block" )
		el.style.display = 'none';
	else
		el.style.display = 'block';
}

// Hide language selector
function hideLngsel()
{
	el = document.getElementById( 'lnglist' );
	if( el.className == "moveout" )
		el.style.display = 'none';
}

function moveonLngsel( el )
{
	el.className = "moveon";
}

function moveoutLngsel( el )
{
	el.className = "moveout";
}

// Disable hover behaviour
function nohoverLngsel()
{
	el = document.getElementById( 'lngactive' );
	el.className = '';
}

//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; margin-top: 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 whichTab( eprf , tprf , lst , dflt )
{
	var hsh = window.location.hash;
	var hst = '#' + tprf;
	if( hsh.length > hst.length && hsh.substring( 0 , hst.length ) == hst )
	{
		var nnn = hsh.substring( hst.length );
		if( lst.indexOf( ',' + nnn + ',' ) >= 0 )
			return eprf + nnn;
	}
	return eprf + dflt;
}

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;

