 //if you link this script from site in not-root directory, define aRootPath variable (ex: aRootPath='../../';)
var aRootPath;
if (!aRootPath) aRootPath='./';
//alert(aRootPath);
var aImgPath=aRootPath+'images/';
//alert(aImgPath);
var aImgBtnPath=aImgPath+'buttons/';
//alert(aImgBtnPath);
var aCookieEverLast=365*50;
var D=document;

function external_links() {
	//relies on JQuery, so load it before this script
	$('a[href^="http"]').click(function () {window.open(this.href);return false;});
}

function bdetect()
{
  var browser = new Array;
  browser['IE4']  = (document.all && !document.getElementById) ? true : false;
  browser['IE5']  = (document.all && document.getElementById) ? true : false;
  browser['N4'] = (document.layers) ? true : false;
  browser['N6'] = (document.getElementById && !document.all)? true : false;
  return browser;
}
//preload
//	array variable "aImgs" example (zoom.png,map.png):
//		var aImgs=[[aImgPath+'zoom','png'],[aImgPath+'map','png']];
function img_preload(aImgs) {
	for (aLoop=0;aLoop<aImgs.length;aLoop++) {
		eval('gImg'+aLoop+'= new Image();');
		eval('gImg'+aLoop+'.src="'+aImgs[aLoop][0]+'.'+aImgs[aLoop][1]+'"');
		eval('gImg'+aLoop+'_o= new Image();');
		eval('gImg'+aLoop+'_o.src="'+aImgs[aLoop][0]+'_o.'+aImgs[aLoop][1]+'"');
	}
}

function img_preload2(aImgs) {
	for (aLoop=0;aLoop<aImgs.length;aLoop++) {
		eval('gImg2'+aLoop+'= new Image();');
		eval('gImg2'+aLoop+'.src="'+aImgs[aLoop][0]+'.'+aImgs[aLoop][1]+'"');
	}
}

//goto() - redirects page
function a_goto (aWhere) {
	if (aWhere) {
		if (isNaN(aWhere)) {
			if (aWhere) window.location.href=aWhere;
		}
		else history.go(aWhere);
	}
	else window.location.reload();
}

//img mouse out src swap
function imo(aImg,aImgIndex,aImgIndexAlt) {
	aImg.src=eval('gImg'+(aImg.aImgIndex?aImg.aImgIndex:aImgIndex)+'.src');
}

//img mouse out src swap
function imo2(aImg,aImgIndex,aImgIndexAlt) {
	D.getElementById('imgz_'+aImg.id.substr(aImg.id.indexOf('_')+1)).src=eval('gImg'+aImgIndex+'.src');
}

//img mouse out src swap
function imo3(aImg,aDoOnBackgroundUrl) {
  if (aDoOnBackgroundUrl) {
		aPos=aImg.style.backgroundImage.lastIndexOf('.');
		aImg.style.backgroundImage=aImg.style.backgroundImage.substr(0,aPos-2)+aImg.style.backgroundImage.substr(aPos);
	}
	else {
		aPos=aImg.src.lastIndexOf('.');
		aImg.src=aImg.src.substr(0,aPos-2)+aImg.src.substr(aPos);
	}
}

//img mouse out src swap
function imo4(aImg,aImgIndex,ind) {
  aImg = D.getElementById(aImg);
  if(ind != -1)
    aImgIndex = 0;
  else
    aImgIndex = 8;

	   //alert('gImg2'+aImgIndex+'.src');
     aImg.src=eval('gImg2'+aImgIndex+'.src');

}

//img mouse over src swap
function imi(aImg,aImgIndex,aImgIndexAlt) {
	aImg.src=eval('gImg'+(aImg.aImgIndex?aImg.aImgIndex:aImgIndex)+'_o.src');
}

//img mouse over src swap
function imi2(aImg,aImgIndex,aImgIndexAlt) {
  D.getElementById('imgz_'+aImg.id.substr(aImg.id.indexOf('_')+1)).src=eval('gImg'+aImgIndex+'_o.src');
}

//img mouse over src swap

function imi3(aImg,aDoOnBackgroundUrl) {
	if (aDoOnBackgroundUrl) {
		aPos=aImg.style.backgroundImage.lastIndexOf('.');
		aImg.style.backgroundImage=aImg.style.backgroundImage.substr(0,aPos)+'_o'+aImg.style.backgroundImage.substr(aPos);
	}
	else {
		aPos=aImg.src.lastIndexOf('.');
		aImg.src=aImg.src.substr(0,aPos)+'_o'+aImg.src.substr(aPos);
	}
}

//img mouse over src swap
function imi4(aImg,aImgIndex,ind) {
  aImg = D.getElementById(aImg);
  if(ind != -1)
    aImgIndex = aImgIndex;
  else
    aImgIndex = aImgIndex+8;

	   //alert('gImg2'+aImgIndex+'.src');
     aImg.src=eval('gImg2'+aImgIndex+'.src');


}


//onMouseOver, onMouseEnter
function mi(aThis,aBgColor,aColor,aBorderColor,aSetPointerCursor) {
	with (aThis.style) {
		//cursor=(aSetPointerCursor?'pointer':'default');
		if (aBgColor) {
			aThis.backgroundColorOrig=backgroundColor;
			backgroundColor=aBgColor;
		}
		if (aBorderColor) {
			borderColorOrig=borderColor;
			borderColor=aBorderColor;
		}
		if (aColor) {
			colorOrig=color;
			color=aColor;
		}
	}
}

//onMouseOut
function mo (aThis) {
	with (aThis.style) {
		backgroundColor=(aThis.backgroundColorOrig)?aThis.backgroundColorOrig:'';
		borderColor=(aThis.style.borderColorOrig)?borderColorOrig:'';
		color=(aThis.style.colorOrig)?colorOrig:'';
	}
}

function mo2 (aThis, aBgColor) {
	with (aThis.style) {
		backgroundColor=(aBgColor)?aBgColor:'';
		borderColor=(aThis.style.borderColorOrig)?borderColorOrig:'';
		color=(aThis.style.colorOrig)?colorOrig:'';
	}
}

//inner app onFocus (input tag)
function appOf (aThis) {
	with (aThis.style) {
		aThis.backgroundColorOrig=backgroundColor;
		backgroundColor='#ff7777';
    borderColorOrig=borderColor;
    colorOrig=color;
		borderColor=color='#fff';
	}
}
//inner app onBlur (input tag)
function appOb (aThis) {
	with (aThis.style) {
		borderColor=borderColorOrig;
		backgroundColor=aThis.backgroundColorOrig;
		color=colorOrig;
	}
}

function appTabMi(aThis) {
	with (aThis.parentNode.style) {
		aThis.backgroundColorOrig=backgroundColor;
		backgroundColor='#646464';
	}
}

function appTabMo(aThis) {
	with (aThis.parentNode.style) {
		backgroundColor=aThis.backgroundColorOrig;
	}
}

function appTabClick(aThis,aClickArray){
	aTable=aThis.parentNode.parentNode.parentNode.parentNode;
	//hide actual visible inputs
	if (aActualClickAray=aTable.appTabClickArayActive) {
		for (aLoop=0;aLoop<aActualClickAray.length;aLoop++)
			D.getElementById(aActualClickAray[aLoop]).parentNode.style.display='none';
	}
	aTable.appTabClickArayActive=aClickArray[1];
	D.getElementById(aClickArray[0][0]).value=aClickArray[0][1];
	D.getElementById('submit_create').disabled=(aClickArray[0][1]!=D.getElementById('tDo').value);
	//show these inputs
	for (aLoop=0;aLoop<aClickArray[1].length;aLoop++)
		D.getElementById(aClickArray[1][aLoop]).parentNode.style.display='block';
	//deactivate actual tab
	if (aActual=aTable.appTabActive) {
		with (aActual.parentNode.style) {borderRightColor=borderRightColorOrig;}
		with (aActual.style) {
			background=backgroundOrig;border=borderOrig;borderRight=borderRightOrig;padding=paddingOrig;
		}
	}
	aTable.appTabActive=aThis;
	//activate this tab
	with (aThis.parentNode.style) {
    borderRightColorOrig=borderRightColor;
		borderRightColor='#646464';
	}
	with (aThis.style) {
    backgroundOrig=background;borderOrig=border;borderRightOrig=borderRight;paddingOrig=padding;
		background='#646464';border='1px solid #C7C7C7';borderRight='none';padding='5px';
	}
}

// PRODUCT-CATEGORIES --------------

gPCBorderColorActive='#8C8D8F';
gPCBackgroundColorActive='#DF2823';
gPCColorActive='#FFFFFF';

//onMouseOver, onMouseEnter
function pc_mi (aThis) {
	with (aThis.style) {
		//cursor='default';
		aThis.backgroundColorOrig=backgroundColor;
		backgroundColor=gPCBackgroundColorActive;
		borderColorOrig=borderColor;
		borderColor=gPCBorderColorActive;
		padding='0px 4px 2px 2px';
		colorOrig=color;
		color=gPCColorActive;
	}
	return (true);
}

//onMouseOut
function pc_mo (aThis) {
	with (aThis.style) {
		backgroundColor=aThis.backgroundColorOrig;
		borderColor=borderColorOrig;
		padding='1px 3px 1px 3px';
		color=colorOrig;
	}
	return (true);
}

function pc_p2pp (aProdCatNode) {//parented from PRODUCT_CATEGORY to parent PRODUCT_CATEGORY
	a= (aProdCatNode.parentNode.id='tree')? aProdCatNode.parentNode: aProdCatNode.parentNode.parentNode.parentNode;
	return (a);
}

function pc_c2p (aCaptionNode) {//parented from CAPTION to PRODUCT_CATEGORY
	a=aCaptionNode.parentNode.parentNode.parentNode;
	//alert(a.tagName);
	return (a);
}

function pc_p2c (aProdCatNode) {//from PRODUCT_CATEGORY to CAPTION
	aDivs=aProdCatNode.getElementsByTagName('DIV');
	a=aDivs[2];
	//alert(a.tagName);
	return (a);
}

function pc_i2c (aImgNode) {//from caption_icon to CAPTION
	aDivs=aImgNode.parentNode.getElementsByTagName('DIV');
	return (aDivs[aDivs.length-1]);//caption;
}

function pc_p2cp (aProdCatNode,aIndex) {//gets child PRODUCT_GATEGORY based on aIndex
	var aCount=0;
	aChilds=(aProdCatNode.id=='tree')?aProdCatNode:D.getElementById('pc_det_'+aProdCatNode.id.substr(aProdCatNode.id.indexOf('_')+1));
	if (aChilds) {
		if (!aIndex) aIndex=0;
		aChilds=(aProdCatNode.id=='tree')?aProdCatNode.childNodes:aChilds.getElementsByTagName('DIV')[0].childNodes;
		with (aChilds) {
			if (aIndex > (aChilds.length-1)) return (null);
			else {
				for (aLoop=0;aLoop<aChilds.length;aLoop++) {
					if ((item(aLoop).tagName) && (item(aLoop).tagName=='DIV')) {
						if (aIndex>aCount) aCount++;
						else	return (item(aLoop));
					}
				}
				return (null);
			}
		}
	}
	else return (null);
}

//go to certain node
function pc_expand_node(aNodeId) {
	if (aNodeId && (aNodeId!='')) pc_mc(pc_p2c(D.getElementById(aNodeId)));
}

function pc_expand_node2(aNodeId) {
	if (aNodeId && (aNodeId!='')) pc_p2c(D.getElementById(aNodeId)).onclick();
}

//onMouseClick
//aThis = caption div or img (icon)
//aUrl = if any then redirect
function pc_mc (aThis,aUrl,aUrlTarget) {
	if (!aThis) return (false);
	aThisIsIcon=aThis.tagName.toUpperCase()=='IMG';
	if (aThisIsIcon) aThis=pc_i2c(aThis);//aThis is now caption

	if (D.aNodeSelected&&(!aThisIsIcon)) {//uncolor selected
		with (D.aNodeSelected.style) {
			backgroundColor=aThis.backgroundColorOrig;
			borderColor=borderColorOrig;
			color=colorOrig;
		}
	}

	if (!aThisIsIcon) D.aNodeSelected=aThis;

	if (!aThisIsIcon) {
		with (aThis.style) {//colors to selected (now red)
			if (!aThis.backgroundColorOrig) { // if some node selected just after load (see pc_mi();)
				backgroundColor=gPCBackgroundColorActive;
				color=gPCColorActive;
				borderColor=gPCBorderColorActive;
			}
			aThis.backgroundColorOrig=gPCBackgroundColorActive;
			colorOrig=gPCColorActive;
			borderColorOrig=gPCBorderColorActive;
		}
	}

	pc_clps(pc_c2p(aThis),(aThisIsIcon)?undefined:((D.aNodeSelected==aThis)?0:1),true);

	if (!aThisIsIcon) {
		if (aUrl&&(aUrl.length>0)) {
			aInput=D.getElementById('search_text');
			if (aInput) aInput.value='';
			aInputPC=D.getElementById('ipc');
			if (aInputPC) {
				aInputPC.value=pc_c2p(aThis).id;
				aInputPC.value=aInputPC.value.substr(aInputPC.value.indexOf('_')+1);
			}

			if (aUrlTarget&&(aUrlTarget.length>0)) aFrm=eval(aUrlTarget);
			else aFrm=window;
			/*aStr=aFrm.location.href;
			alert(aStr);
			if (aStr.indexOf(aUrl)!=(aStr.length-aUrl.length)) ... ;*/

			aFrm.location.href=aUrl;
		}
	}
	return (true);
}

//returns True if aProdCatNode has collapsed
//colapse if (aColapse not defined and it is expanded) or if (aColapse == 1)
//aSiblings if true, colapse all siblings
function pc_clps(aProdCatNode,aColapse,aSiblings) {
	var aResult = false;
	var aLoop=0;
	var aParent=(aProdCatNode && (aProdCatNode.id!='tree'))?pc_p2pp(aProdCatNode):'';
	var aCurProd=aProdCatNode;
	var aChilds,aImg;
	//var aaa=D.getElementById('search_text');
	
	aSiblings=aSiblings&&aProdCatNode&&(aProdCatNode.id!='tree');//top node has no siblings
	if (aSiblings) {		
		aProdCatNode=pc_p2cp(aParent,aLoop++);//first child ProdCatNode
	}
	
	//aaa.value=((aaa.value=='')?0:aaa.value)+aProdCatNode.id.substr(aProdCatNode.id.indexOf('_')+1);

//alert(aCurProd.id + '|'+ aParent.id );
	
	do {
		if (aProdCatNode) {
			aChilds=D.getElementById('pc_det_'+aProdCatNode.id.substr(aProdCatNode.id.indexOf('_')+1));
			//alert(aChilds.id);
			if (aChilds) {
				aImg=aProdCatNode.getElementsByTagName('IMG')[0];
				if ((aCurProd==aProdCatNode)&&((aColapse==0) || ((!aColapse) && ((!aChilds.style.display)||(aChilds.style.display!='block'))))) {
					aChilds.style.display='block';
					aImg.src=aImgPath+'prod/tree_minus.gif';
				}
				else {
					aChilds.style.display='none';
					aImg.src=aImgPath+'prod/tree_plus.gif';
					aResult=true;
				}
			}
		}
		if (aSiblings) {
			aProdCatNode=pc_p2cp(aParent,aLoop++);
		}
	} while (aSiblings && aProdCatNode);

	while (aParent) {//if expand, expand all parents too
		aChilds=(aParent.id='tree')?false:D.getElementById('pc_det_'+aParent.id.substr(aParent.id.indexOf('_')+1));
		if (aChilds) {
			aChilds.style.display='block';
			aImg=aParent.getElementsByTagName('IMG')[0];
			aImg.src=aImgPath+'prod/tree_minus.gif';
			aParent=pc_p2pp(aParent);
		}
		else aParent=false;
	}

	return (aResult);
}

// PRODUCTS --------------

//aCollapse = not assigned => switch, 1 => expand, 2 => collapse
function detail(aThis,aCollapse,aImgSrc) {
  var aImg=aThis.getElementsByTagName('IMG')[0];
  var aID=aThis.id.substr(aThis.id.indexOf('_')+1);
  var aDetail=D.getElementById('detail_'+aID);
	if (
		((!aCollapse) && (aImg.style.display=='none')) ||
		(aCollapse=='1')) {
			aDisplay='block';			
			aImgP=D.getElementById('imgs_'+aID);			
			if ((!aImgP.src) || (aImgP.src!=aImgP.alt)) aImgP.src=aImgP.alt; 
			aImgO=D.getElementById('pr_img_'+aID);		  
		  if (aImgO && ((!aImgO.src) || (aImgO.src!=aImgO.alt))) aImgO.src=aImgO.alt;
		}
  else aDisplay='none';
  aDetail.style.display=aDisplay;
  aImg.style.display=aDisplay;
}

//aCollapse = not assigned => switch, 1 => expand, 2 => collapse
function detail2(aThis,aID, aCollapse,aImgSrc) {
  var aDetail=D.getElementById('detail_'+aID);
  var aBreef=D.getElementById(aID);
  br = bdetect();
	if (aCollapse=='0') {
		  if (br['IE4'] || br['IE5'])	aDisplay='block';
			else aDisplay='table-row';
			bDisplay = 'none';
	}
  else {
	  if(br['IE4'] || br['IE5'])	bDisplay='block';
		else	bDisplay='table-row';
	  aDisplay='none';
  }
  aDetail.style.display=aDisplay;
  aBreef.style.display=bDisplay;
}


//aCollapse = not assigned => switch, 1 => expand, 2 => collapse
function detail_all(aThis,aCollapse,aDoNotWriteCookie) {
  var aDisplayA='0';
  var aCap;
	if ((aCollapse=='1')||((aThis) && (aThis.src.substr(aThis.src.length-19,11)=='detailview_'))) {
    aDisplayA='1';
  }
  else { aDisplayA='2'; }
  
  p=D.getElementById('products').childNodes;
  for (aLoop=0;aLoop < p.length;aLoop++) {
		if (p.item(aLoop).tagName=='DIV') {
			aCap=p.item(aLoop).getElementsByTagName('DIV')[1];
			if (aCap) {detail(aCap,aDisplayA)};
		}
  }
  if (!aDoNotWriteCookie) writeCookie('prod_view',aDisplayA,aCookieEverLast);
  if (aThis.focus) aThis.focus();//<<scroll na zacatek nebo na konec;
}

function img_big(aURL) {
  window.open(aURL,'','scrollbars=yes');
}

//aDirection: -1 = previous chunk, 1 = next chunk
function go(aDirection) {
  var aS1='chunk=';
	var aStr='&'+aS1;
	var aPos=0;
	var aUrl,aChunk='';
	if(isNaN(aDirection)) alert('"'+aDirection+'" is not a number!');
  else {
    aUrl=window.location.href;
		aPos=aUrl.indexOf(aStr);
    if (aPos==-1) {
			if (aUrl.indexOf('?')==-1)	window.location.href+=('?'+aS1+'2');
			else	window.location.href+=(aStr+'2');
		}
    else {
		  aChunk=aUrl.substr(aPos+aStr.length);
		  aChunk=(isNaN(aChunk.substr(0,1))?((aDirection==1)?1:2):parseInt(aChunk));
			window.location.href=(aUrl.substr(0,aPos)+aStr+(aChunk+aDirection));//<<dodelat !!!
		}
  }
}

//stores
function store_detail(aThis,aCollapse) {
  var aDet=D.getElementById('det_'+aThis.id);
	if (
		((!aCollapse) && ((!aDet.style.display) || (aDet.style.display=='none'))) ||
		(aCollapse=='1')) {
	    br = bdetect();
			if (br['IE4'] || br['IE5'])	aDisplay='block';
			else aDisplay='table-row';
  }
  else {
    aDisplay='none';
  }
  aDet.style.display=aDisplay;
}

//aDitrection: -1 = collapse, 1 = expand
function store_detail_all(aThis) {
/*  aTmp=mouse_text('...pracuji...','mouse_text');
  D.appendChild(aTmp);
  var aDisplayA='0';
	if (aThis.src.substr(aThis.src.length-19,11)=='detailview_') {
    aDisplayA='1';
    //aSrc=aThis.src.substr(0,aThis.src.length-17)+'listview_'+gLang+'.png';
  }
  else {
    aDisplayA='2';
    //aSrc=aThis.src.substr(0,aThis.src.length-15)+'detailview_'+gLang+'.png';
  }

  p=D.getElementById('doc').childNodes(1).childNodes;
  for (aLoop=0;aLoop < p.length;aLoop++) {
    with (p.item(aLoop).firstChild) {
      detail(firstChild,aDisplayA);
			/*firstChild.src=aSrc;
      lastChild.style.display=aDisplay;
    }
  }
  aThis.focus();
  //scroll(0,0);*/
}

//aDoCheck not assigned => switch, 1 => check it, 2 => uncheck it
function check_click(aThis,aImgIndexNotCh,aImgIndexCh,aCookieName,aCookieValue,aDoCheck) {
	if ((aThis) && (aThis.tagName=='IMG')) {
		if (((!aDoCheck) && (aThis.src.indexOf('check_ch') != -1)) || (aDoCheck==2)) {
			aThis.aImgIndex=aImgIndexNotCh;
			aVal=((aCookieValue || (aCookieValue==''))?aCookieValue:'2');
			if (aCookieName) writeCookie(aCookieName,aVal,aCookieEverLast);
		}
		else {
			aThis.aImgIndex=aImgIndexCh;
			aVal=((aCookieValue || (aCookieValue==''))?aCookieValue:'1');
			if (aCookieName) writeCookie(aCookieName,aVal,aCookieEverLast);
		}
		if (!aDoCheck) {imi(aThis); }
		else imo(aThis);
	}
	return (aVal);
}

function prn_list(aItemToAddOrRemove,aDoNotRemove) {
	if (aItemToAddOrRemove) {
		if (!gPrnMarked) gPrnMarked='';
		aPos=gPrnMarked.indexOf(aItemToAddOrRemove);
		if ((aPos>0) && (!aDoNotRemove)) {
			gPrnMarked=gPrnMarked.substring(0,aPos-1)+gPrnMarked.substring(aPos+aItemToAddOrRemove.length,gPrnMarked.length);
		}
		else {
			gPrnMarked=gPrnMarked+','+aItemToAddOrRemove;
		}
	}
	if (!gPrnMarked) gPrnMarked='';
	//alert(gPrnMarked)
	return (gPrnMarked);
}

//login
function login13(aInputTag,aEvent) {
	if (aEvent.keyCode==13) {
		aInputTag.form.submit();
		return(false);
	}
}

//do order
function key13o(aInputTag,aEvent) {
	if (aEvent.keyCode==13) {
		aInputTag.form.do_order.click();
		return(false);
	}
}

//do order in order_detail.xsl
function key13oo(aInputTag,aEvent) {
	if (aEvent.keyCode==13) {
		aInputTag.form.do_order.click();
		return(false);
	}
	else {
		keyc=aEvent.which||aEvent.keyCode;
		//alert(keyc);
		if(({46:1,44:1,8:1,9:1,37:1,39:1}[keyc])||((keyc>47/*0*/)&&(keyc<58/*9*/))) {
			mi(aInputTag.form.do_order,'#DF2823',null,'#C4142F');
		}
		else {
			return(false);
		}
	}
}

function check_form_field(aFormField,aErrStr) {
	aR=false;
	if ((aFormField) && (aFormField.value)) {
		v=aFormField.value;
		e=v.substr(v.length-4);
		if (e) {
			e=e.toLowerCase();
			aR=((e.length==4)&&((e=='.xls')||(e=='.txt')||(e=='.csv')));
		}
	}
	if (!aR) alert(aErrStr);
	return aR;
}

//cookies

function writeCookie(name,value,days,aPath) {
	if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else {var expires = ""};
  if (!(aPath)) aPath="/";
	D.cookie = name+"="+value+expires+"; path="+aPath;
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = D.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function deleteCookie(name)
{
	writeCookie(name,'',-1);
}

//expects <select> with transport methods. It changes tr.meth. in order header and shows correct description to this tr.meth.
function transport_methods_change(aSelectElement)
{	
	if (aSelectElement) {
		a=aSelectElement.options[aSelectElement.selectedIndex];		
		b=_getElementsByName('div','TrDesc');
		if ((b) && (b.length>0)) {
			for (i=0; i<b.length; i++) {
				b[i].style.display=((b[i].id=='TrDesc_'+a.value)?'block':'none');
			}
			//select correct tarif
			c=document.getElementById('id_tarif');			
			if (c) {
				c.selectedIndex=-1;
				d=-1;							
				if ((c.TransportCurrTarifs) && (c.TransportCurrTarifs[a.value])) {d=c.TransportCurrTarifs[a.value];}
				//mark options enabled and disabled
				for (i=0; i<c.options.length; i++) {						
					//if not have the right yet, select the frst match
					if ((d==-1)&&(c.options[i].value.substr(0,c.options[i].value.indexOf('_'))==a.value)) {d=c.options[i].index}
					c.options[i].disabled=((c.options[i].value.substr(0,c.options[i].value.indexOf('_'))!=a.value)?'disabled':null);
				}
				c.selectedIndex=d;
				//trigger event (because assigning to selectedIndex does not trigger it)
				transport_method_tarifs_change(c);
			}
		}
	}
}

//expects <select> with transport method tarifs. It changes tr.meth. in order header and shows correct description to this tr.meth.
function transport_method_tarifs_change(aSelectElement)
{
	if (aSelectElement) {
		a=aSelectElement.options[aSelectElement.selectedIndex];
		//test for correctness of selected tarif 
		iddd=document.getElementById('iddrdop');
		//should not be triggered anytime for not IE browsers
		if (a.value.substr(0,a.value.indexOf('_'))!=iddd.options[iddd.selectedIndex].value) {
			alert('Špatný tarif: pro tuto dopravu nelze tento tarif vybrat.');
			transport_methods_change(iddd);//selects the right tarif
			return;
		} 
		document.getElementById('sp_transport').innerHTML=a.text;
		b=_getElementsByName('div','TrTaDesc');
		if ((b) && (b.length>0)) {
			for (i=0; i<b.length; i++) {
				b[i].style.display=((b[i].id=='TrTaDesc_'+a.value)?'block':'none');
			}
		}
		//store this index for eventual re-use		
		if (!aSelectElement.TransportCurrTarifs) {aSelectElement.TransportCurrTarifs=[];} 
		aSelectElement.TransportCurrTarifs[a.value.substr(0,a.value.indexOf('_'))]=a.index;
	}
}

function _getElementsByName(aTagName,aName)
{
	b=bdetect();
	if (b['IE4'] || b['IE5']) {
		arr=document.getElementsByTagName(aTagName);		
		var a = new Array();
		for(i = 0,iarr = 0; i < arr.length; i++) {			
			att = arr[i].getAttribute("name");
			if(att == aName) {
				a[iarr] = arr[i];
				iarr++;
			}
		}
	}
	else a=document.getElementsByName(aName);
	return a;
}

