over = 500;

function pointerCondOn(obj) {
	if (ie) obj.style.cursor='hand';
}

function pointerOn(obj) {
	if (ie()) obj.style.cursor='hand';
	else obj.style.cursor='pointer';
}

function linkOn(obj) {
	if (ie()) obj.style.cursor='hand';
	else obj.style.cursor='pointer';
	obj.style.textDecoration="underline";
}

function linkOff(obj) {
	obj.style.textDecoration="none";
}

function helpOn(obj) {
	obj.style.cursor='help';
}

function textOn(obj){
	obj.style.cursor='text';
}
function bOver(o) {
	if (window.event) {
		window.event.srcElement.style.border="1px solid #696969";
		pointerOn(window.event.srcElement);
	} else if (t=o.currentTarget) {
		//t.className="buttonOver";
		t.style.border="1px solid #696969";
		pointerOn(t);
	} else {
		//alert(this);
		//o.className="buttonOver";
		o.style.border="1px solid #696969";
		pointerOn(o);
	}
}

function bOverAdv(o,cname) {
	o.className=cname;
	if (arguments[2]) pointerOn(o);
}

function bOut(o) {
	if (window.event) {
		window.event.srcElement.style.border="1px solid #d0d0d0";
	} else if (t=o.currentTarget) {
		t.style.border="1px solid #d0d0d0";
	} else {
		//alert(this);
		o.style.border="1px solid #d0d0d0";
	}
}

function toggleDisabled(_name) {
	o=gId(_name);
	if (o.getAttribute("disabled")!=null)
		o.removeAttribute("disabled");
	else
		o.setAttribute("disabled",true);
	}

function ieDivExit(o) {
	if (ie())
		o.parentNode.parentNode.removeChild(o.parentNode);
}

function hideAllSelects() {
	_options = document.getElementsByTagName("select");
	 	for (i=0;i<_options.length;i++)
	 		_options[i].style.visibility="hidden";
}

function showAllSelects() {
	if (getClasses("loginDialog").length<1) {
	_options = document.getElementsByTagName("select");
	for (i=0;i<_options.length;i++)
		_options[i].style.visibility="visible";
	}
}

function closeShadowDiv(tgt) {
	var o;
	if (typeof(tgt)=='string')
		o=gId(tgt);
	else
		o=tgt;
	//alert(o.className);
	if (o!=null) {
		//alert(this);
		//alert(this.getAttribute("class"));
		if (o.previousSibling)
			var prevS=o.previousSibling;
		if (o.previousSibling.previousSibling)
			var prevSS=o.previousSibling.previousSibling;
		if (prevS)
			o.parentNode.removeChild(prevS);
		if (prevSS)
			o.parentNode.removeChild(prevSS);
		//if (o.nextSibling && o.nextSibling.nextSibling) o.parentNode.removeChild(o.nextSibling.nextSibling);
		//if (o.nextSibling) o.parentNode.removeChild(o.nextSibling);
		o.parentNode.removeChild(o);
	}
	if (ie6tweaks)
		showAllSelects();
}

function closeShadeWin(e) {
	var o;
	if (window.event && (window.event.srcElement.getAttribute("class") == "exitButton" || window.event.srcElement.className == "exitButton"))
		o=window.event.srcElement.parentNode;
	else if(e.originalTarget && e.originalTarget.getAttribute("class") == "exitButton")
		o=this;
	//alert(window.event.srcElement.getAttribute("class"));
	if (o!=null) {
		if (o.previousSibling && o.previousSibling.previousSibling && o.previousSibling.previousSibling.className=="fog")
			o.parentNode.removeChild(o.previousSibling.previousSibling);
		if (o.previousSibling && o.previousSibling.className=="loginDialog")
			o.parentNode.removeChild(o.previousSibling);
		o.parentNode.removeChild(o);
	}
	if (ie6tweaks)
		showAllSelects();
}


function closeShDiv() {
	var o;
	if (window.event && window.event.srcElement == src)
		alert(window.event.currentElement);
	else if(e.originalTarget && e.originalTarget == src)
		o=this;
	if (o!=null) {
		if (o.nextSibling && o.nextSibling.nextSibling) o.parentNode.removeChild(o.nextSibling.nextSibling);
		if (o.nextSibling) o.parentNode.removeChild(o.nextSibling);
		o.parentNode.removeChild(o);
	}
}

function xcloseShadowDiv() {
	var o;
	if (arguments.length>0) {
		o	= arguments[0];
	} else if (window.event && window.event.srcElement.getAttribute('class')=="exitButton")
		o=event.srcElement.parentNode;
	if (o!=null) {
		//alert(this);
		//alert(this.getAttribute("class"));
		if (o.nextSibling && o.nextSibling.nextSibling) o.parentNode.removeChild(o.nextSibling.nextSibling);
		if (o.nextSibling) o.parentNode.removeChild(o.nextSibling);
		o.parentNode.removeChild(o);
		//var pres=gId('present');
		//alert(pres);
		//pres.style.visibility=="visible";
// 		var pres = gId('present');
// 		pres.style.visibility="visible";
	}
}

function correctX(w,x) {
	var r = windowWidth();
	return w+x>r-40 ? r-w-80 : x;
}

function getPopup(evt) {
	var win = elm("div");
	win.className="miniAdd2";
	var ww = 160;
	var off = ww/2;
	var x=trueX(evt)-off;
	var sx = correctX(ww,x);
	win.style.cssText+="top:"+(trueY(evt)-40)+"px;left:"+sx+"px;width: "+ww+"px";
	document.body.appendChild(win);
	win.onmouseout=close;
	win.onclick=close;
	return win;
}

function under(o) {
	o.style.textDecoration="underline";
	}
function ununder(o) {
	o.style.textDecoration="none";
	}

function color(o,color) {
	o.style.color="#"+color;
}

function uncolor(o) {
	o.style.color="";
}

function getBlankShadeWindow(_name,width,height,x,y,shadowOffset,noScroll,fog,_top) {
	if (noScroll)	document.body.style.overflow='hidden';
	if (_top)
		window.over += 3;
	
	if (ie6tweaks)
		hideAllSelects();

	
	if (!y && height && height<windowHeight())
		mytop=(windowHeight()-height)/2+yOffset();
	else if (!y)
		mytop=0;
	else
		mytop = y;
	if (!x && width)
		myleft=(windowWidth()-width)/2;
	else if (!x)
		myleft=0;
	else
		myleft=x;
// 	alert(myleft);
	if (myleft+width>windowWidth()) {
		myleft-=width+60;
	}
		
		
	div=elm("div",{clas:"loginDialog"});
	//div.className="loginDialog";
	//alert(div.getAttribute('class'));
	//div.style.styleFloat="right"
	if (width)
		div.style.width=width+"px";
// 	else
// 		div.style.width="100px";
	if (height)	
		div.style.height=height+"px";
// 	else
// 		div.style.height="100px";
	div.style.top=mytop+"px";
	div.style.left=myleft+"px";
	div.style.zIndex=window.over;
	//if (ie()) {
	//  div.style.padding="10px";
	//  div.style.position="absolute";
	//  div.style.backgroundColor="white";
	//  div.style.padding="10px";
	//  div.style.border="1px solid #a7a7a7";
	//}
	
	div2=div.cl(true);
	div.id=_name;
//	div2.removeAttribute("id");
	div2.st({top:(mytop+shadowOffset)+"px",left:(myleft+shadowOffset)+"px",backgroundColor:"#494949",borderWidth:0});
	div2.style.zIndex=window.over-1;
	//alert(nexttop-10);
	//div2.style.zIndex= _top-10;
// 	else {
// 		div2.style.top=mytop+shadowOffset+"px";
// 		div2.style.left=myleft+shadowOffset+"px";
// 		div2.style.backgroundColor="#494949";
// 	}

	var div3;

	if (fog) {
		div3=elm("div",{clas:"fog"});
		div3.style.height=trueHeight()+"px";
		//div3.st({width:"100%",height:"100%"});
		div3.style.zIndex=window.over-2;
	}
	//alert(window.over);
// 	 else {
// 		div3.style.backgroundColor="white";
// 		div3.style.zIndex=498;
// 		div3.style.position="absolute";
// 		div3.style.top=0;
// 		div3.style.left=0;
// 		div3.style.width="100%";
// 		div3.style.height="1000px";
// 		div3.style.filter="alpha(opacity=40)";
		//gId('present').style.visibility="hidden";
// 	}

	exitButton=elm("input",{value: "Zavřít",clas: "exitButton", type: "button"});
	if (ie() || document.implementation.hasFeature("Events","2.0")) {
		exitButton.listenTo('mouseover',bOver,false);
		exitButton.listenTo('mouseout',bOut,false);
		div.listenTo('click',closeShadeWin,false);
// 		exitButton.listenTo('click',function () {closeShadowDiv(div)},false);
	}
	//exitButton.style.styleFloat="right";
	if (!ie() && !document.implementation.hasFeature("Events","2.0")) {
		//exitButton.onclick= function () {closeShadowDiv(_name)};
		div.onclick = closeShadeWin;
		exitButton.onmouseover=bOver;
		exitButton.onmouseout=bOut;
	}
	//exitButton.style.styleFloat="right";
	div.ac(exitButton);

	//reloadButton=el("input",{value: "Reload",type: "button", clas: "regButton", style: "float:right",name: '_reload',id: '_reload'});
	//div.ac(reloadButton);
	//if (document.implementation.hasFeature("Events","2.0"))
	//  div.addEventListener("click",function () {return true},false);
	
	
	if (fog)
		document.body.appendChild(div3);
	document.body.appendChild(div2);
	document.body.appendChild(div);
	return div;
}

function getBlankShadowWindow(_name,width,height,shadowOffset,noScroll) {
	if (noScroll)	document.body.style.overflow='hidden';
	if (height<windowHeight())
		mytop=(windowHeight()-height)/2+yOffset();
	else 
		mytop=10;
	myleft=(windowWidth()-width)/2;
	if (ie()) {
// 		var pres = gId('present');
// 		pres.style.visibility="hidden";
		mytop+=70;
 		myleft-=45;
	}
	
	div=elm("div",{clas:"loginDialog",id: _name});
	div.style.width=width+"px";
	div.style.height=height+"px";
	div.style.top=mytop+"px";
	div.style.left=myleft+"px";
	if (ie()) {
		div.style.zIndex=500;
		div.style.position="absolute";
		div.style.backgroundColor="white";
		div.style.padding="10px";
		div.style.border="1px solid gray";
	}
	if (ie())
		shadowOffset-=2;
	
	div2=div.cl(false);
	div2.removeAttribute("id");
	div2.st({top:(mytop+shadowOffset)+"px",left:(myleft+shadowOffset)+"px",backgroundColor:"#494949",borderWidth:0,zIndex:499});

	div3=elm("div",{clas:"fog"});
	if (!ie()) {
		div3.st({width:"100%",height:"100%",zIndex:498});
	} else {
		div3.style.backgroundColor="white";
		div3.style.zIndex=498;
		div3.style.position="absolute";
		div3.style.top=0;
		div3.style.left=0;
		div3.style.width="100%";
		div3.style.height="1000px";
		div3.style.filter="alpha(opacity=40)";
		//gId('present').style.visibility="hidden";
	}

	exitButton=elm("input",{value: "Zavřít",clas: "exitButton", type: "button", style: "float:right",onmouseover: "bOver(this)",onmouseout: "bOut(this)"});
	if (ie()) {
		exitButton.style.styleFloat="right";
		exitButton.attachEvent('onmouseover',bOver);
		exitButton.attachEvent('onmouseout',bOut);
		exitButton.attachEvent("onclick",function () {closeShadowDiv(div)});
	} else if (document.implementation.hasFeature("Events","2.0")) {
		exitButton.addEventListener("click",function () {closeShadowDiv(div)},false);
		//div.addEventListener("click",function () {closeShDiv(exitButton)},false);
		exitButton.addEventListener("mouseover",bOver,false);
		exitButton.addEventListener("mouseout",bOut,false);
	} else {
		exitButton.setAttribute("onclick","closeShadowDiv(_name)");
		exitButton.setAttribute("onmouseover","bOver");
		exitButton.setAttribute("onmouseout","bOut");
		exitButton.style.styleFloat="right";
	}
	div.ac(exitButton);

	//reloadButton=el("input",{value: "Reload",type: "button", clas: "regButton", style: "float:right",name: '_reload',id: '_reload'});
	//div.ac(reloadButton);
	//if (document.implementation.hasFeature("Events","2.0"))
	//  div.addEventListener("click",function () {return true},false);
	
	if (ie6tweaks)
		hideAllSelects();
	document.body.appendChild(div);
	if (!ie()) {
		document.body.appendChild(div2);
		document.body.appendChild(div3);
	}
		
	return div;
}

function toggleCheck(o) {
	o.checked = o.checked ? false : true;
	try {
		if (o.checked) {
			//alert("is checked");
			orangeOver(o.nextSibling);
		} else {
			orangeOut(o.nextSibling);
		}
	} catch (e) {
		alert (e);
	}
}

function toggle(o) {
	o.checked = o.checked ? false : true;
}

function toggleOnId(s) {
	var o = gId(s);
	if (o)
		o.checked = true;
}


function isChecked(o) {
	return o.checked ? true : false;
}

function orangeOver(o) {
	o.style.color="rgb(247,78,0)";
	o.style.textDecoration="underline";
}
function orangeOut(o) {
	if (!isChecked(o.previousSibling)) {
		o.style.color="#979797";
		o.style.textDecoration="none";
	}
}


function condCheck(o) {
	if (document.URI)
		if (document.documentURI.search(/co\/all/)!=-1)
			o.setAttribute("checked","true");
		else
			o.removeAttribute("checked");
	else
		if (document.URL.search(/co\/all/)!=-1)
			o.setAttribute("checked","true");
		else
			o.removeAttribute("checked");
}

function showSingle(o) {
	//document.location=o.src.replace(/full\//,"h/"+(windowHeight()-20)+"/");
	document.location=o.src.replace(/full\//,"fullscreen/");
	return;
	var im = document.createElement('img');
	var dim = document.createElement('div');
	var parts = o.src.split('.jpg');
	dim.className='singleShow';
	im.src=o.src.replace(/full\//,"");
	im.title='Zavřít';
	im.alt='Pokud vidíte tento text, vybraný obrázek nemá variantu ve vysokém rozlišení. Pro návrat klikněte.';
	im.onclick=function () {this.parentNode.parentNode.removeChild(this.parentNode); document.body.firstChild.style.display='block';}
	im.style.border="1px solid #a7a7a7";
	//im.onmouseover = function () {pointerOn(this)};
	//dim.style.cursor='not-allowed';
	dim.appendChild(im);
	document.body.firstChild.style.display='none';
	document.body.appendChild(dim);
}

function checkOn(o) {
// 	alert(o.nodeName);
	var a,tgt;
	if (ie()) {
		if (o.childNodes.item(1).childNodes.item(0)) {
			tgt = o.childNodes.item(1).childNodes.item(0);
				if (tgt.nodeName=='INPUT') { // && !tgt.getAttribute('checked')) {
					tgt.checked='checked';
					if (window.event.srcElement.nodeName=="TD")
						fireSingleMouseEventAt(tgt);
				}
		}
	}	else {
		if (o.childNodes.item(3).childNodes.item(1)) {
			tgt = o.childNodes.item(3).childNodes.item(1);
				if (tgt.nodeName=='INPUT') { // && !tgt.getAttribute('checked')) {
					tgt.checked='checked';
					fireSingleMouseEventAt(tgt);
				}
		}
	}
}

var oldColor;

function select(o,color) {
	oldColor=o.style.backgroundColor;
	o.style.backgroundColor=color;
}

function unSelect(o) {
	if (!oldColor)	
		o.style.backgroundColor='white';
	else
		o.style.backgroundColor=oldColor;
}

	function holdOn () {
		var overlay = gId('overlayDiv');
		if (!overlay) {
			overlay = elm("div",{clas: "overlay",id: "overlayDiv"});
			overlay.style.height=trueHeight()+"px";
			document.body.appendChild(overlay);
		}
	}

	function holdOff () {
		var overlay;
		if (overlay = gId('overlayDiv')) {
			overlay.parentNode.removeChild(overlay);
		}
	}

	function waitOn () {
		var overlay = gId('overlayDiv');
		if (!overlay) {
			displayOverlay(0,1000);
			//alert("overlay");
		}
	}

	function waitOff () {
		if (overlay = gId('overlayDiv')) {
			removeEl(overlay);
		} else "neni tam";
	}

function displayOverlay(n,z) {
	var overlay = document.createElement("div");
	//overlay.style.cssText='position: absolute;top: 0px;left: 0px;background-color: white;width:100%;height: '+trueHeight()+'px;cursor:wait;';
	overlay.id="overlayDiv";
	overlay.className="overlay";
	overlay.style.height=trueHeight()+"px";
	document.body.appendChild(overlay);
}


function trueY() {
	if (ie())
		return event.clientY+document.getElementsByTagName('html').item(0).scrollTop;
	else if(arguments[0] && arguments[0].pageY)
		return arguments[0].pageY;
}

function trueX() {
	if (ie())
		return event.clientX+document.getElementsByTagName('html').item(0).scrollLeft;
	else if(arguments[0] && arguments[0].pageX)
		return arguments[0].pageX;
}

function addOn(evt) {
	if (window.event)
		var o = window.event.srcElement;
	else if (evt.originalTarget)
		var o = evt.originalTarget;
	o.src=docRoot()+"/image/ikona_basket_click.png";
}
function addOff(evt) {
	o.src=docRoot()+"/image/ikona_basket.png";
}

function toggleDealerChoice(o) {
	if (!o)
		return;
	if (o.nextSibling.id=='dchoice')
		o.nextSibling.close();
	else {
//	input type="checkbox" name="dealprep" comp="true" onclick="toggleSCond(this);addDealerChoice(this)" onmouseover="pointerOn(this)" class='noline1'
		var mydiv=elm("div",{id: 'dchoice', style: 'margin: 1ex 0 0 0;'},
				elm("span",'',"Vaše velkoobchodní registrace bude aktivní do\u00A048 hodin po ověření. Podrobnosti ve Velkoobchodních podmínkách níže."));

/*		var mydiv=elm("span",{id: 'dchoice', style: 'margin-bottom: 0'},
				elm("span",{onmouseover: "this.style.cursor='help'"},"Varianty:"),
				elm("span",{clas: "moneml",onclick: "toggle(this.nextSibling);chooseSCond('d');", onmouseover: 'pointerOn(this)'},"Dealer"),
				elm("input",{name: "dealtype", value: "retail",clas: "noline2", type: "radio",onmouseover: "pointerOn(this)"}),
				elm("span",{clas: "moneml",onclick: "toggle(this.nextSibling);chooseSCond('r');", onmouseover: 'pointerOn(this)'},"Retailer"),
				elm("input",{name: "dealtype", value: "dealer",clas: "noline2", type: "radio", onmouseover: "pointerOn(this)", checked: "checked"}));
*/
		o.parentNode.insertBefore(mydiv,o.nextSibling);
	}
}

function showDealerNote() {
	var dn = gId('dnote');
	if (dn)
		return;
	var mydiv=elm("div",{id: 'dnote', style: 'margin: 1ex 0 0 0;'},
				elm("span",'',"Vaše velkoobchodní registrace bude aktivní do\u00A048 hodin po ověření. Podrobnosti ve Velkoobchodních podmínkách výše."));
//	var mytr = elm("tr",'',
//		elm("td",{id: 'dnote', style: 'text-align:left', colspan: "3"},"Vaše velkoobchodní registrace bude aktivní do\u00A048 hodin po ověření. Podrobnosti ve Velkoobchodních podmínkách níže."));
	var mt = gId('conds');
	if (mt)
		mt.parentNode.insertBefore(mydiv,mt.nextSibling);
//		mt.appendChild(mytr);
}

function closeDealerNote() {
	var dn = gId('dnote');
	if (dn)
		dn.parentNode.removeChild(dn);
}	

function toggleSCond(obj) {
	if (!obj)
		return;
	if (obj.checked) {
		gId("scond").setAttribute("href","/data/documents/Velkoobchodni_podminky.php");
		gId("scond").firstChild.nodeValue="Velkoobchodními podmínkami";
	}	else {
		gId("scond").setAttribute("href","/data/documents/Obchodni_podminky.php");
		gId("scond").firstChild.nodeValue="Obchodními podmínkami";
	}
}

function chooseSCond(c) {
	switch (c){
		case 'e':
			gId("scond").setAttribute("href","/data/documents/Obchodni_podminky.php");
			gId("scond").firstChild.nodeValue="Obchodními podmínkami";
			break;
		case 'd':
			gId("scond").setAttribute("href","/data/documents/Dealerske_podminky.php");
			gId("scond").firstChild.nodeValue="Dealerskými podmínkami";
			break;
		case 'w':
			gId("scond").setAttribute("href","/data/documents/Velkoobchodni_podminky.php");
			gId("scond").firstChild.nodeValue="Velkoobchodními podmínkami";
			break;
		default:
			break;
	}
}

function scaleBanner() {
return ;
	var banner = gId("banner1");
	var frac =banner.getAttribute("width")/banner.getAttribute("height");
	var nw = windowWidth()-(185+2*30);
	var nh = nw/frac;
	banner.setAttribute("height",nh);
	banner.setAttribute("width",nw);
}

function displayTip(_name) {
 	var xml = jXquery("fetch=dummy");
	var p;
	switch (_name) {
		case 'mo':
		 	xsl = jXquery("fetch=xsl&name=tipMO");
			p=gId('tip').parentNode;
			p.replaceChild(transXML(xml,xsl),gId('tip'));
			break;
		case 'vo':
		 	xsl = jXquery("fetch=xsl&name=tipVO");
			p=gId('tip').parentNode;
			p.replaceChild(transXML(xml,xsl),gId('tip'));
			break;
		default:
			break;
	}
}

function geckoSharp() {
	if (gecko()) {
		var i,s = new String(window.location);
		if ((i = s.indexOf("#"))!=-1)
			window.location=s.substr(i);
	}
}

function geckoSharpGo() {
	window.setTimeout('geckoSharp()',200);
}

var timeout;

function rotateBanner(place,time,hrefs,filename) {
	var mybanner = gId('banner');
	if (!mybanner) {
		var placement = gId(place);
		if (!placement)
			return;
		genericElementMethods.apply(placement);
		var parts = filename.split('.jpg');
		var parts2 = parts[0].split("_");
		if (parts2.length<2) {
			alert("Jméno banneru by mělo být ve formátu JMÉNO_XXX.jpg, kde XXX je kladné celé číslo.");
			clearInterval(timeout);
			return;
		}
		var prefix = "/image/fx/"+(windowWidth()-(185+2*30))+"/";
		if (window.ActiveXObject && navigator.appName.indexOf('Explorer')!=-1)
			var banner = el("img",{src: prefix+parts2[0]+"_1.jpg", id: 'banner',border: 0});
		else
			var banner = el("img",{src: prefix+parts2[0]+"_1.jpg", style: "border: 1px solid #454545",id: 'banner'});
		var href = el("a",{href: hrefs[0], style: 'border:0'});
		href.ac(banner);
		placement.ac(href);
	}
	var i;
	var images = new Array();
	for (i=0;i<hrefs.length;i++) {
		images[i] = new Image;
		images[i].src = prefix+parts2[0]+"_"+(i+1)+".jpg";
		//alert(images[i].src);
	}
	if (hrefs.length>1)
		timeout = setInterval(function () {goRotate(banner,hrefs)},time*1000);
}

function goRotate(banner,hrefs) {
	//alert(arguments[2].length);
	var parts = banner.src.split('.jpg');
	var parts2 = parts[0].split("_");
	if (parts2.length<2) {
		alert("Jméno banneru by mělo být ve formátu JMÉNO_XXX.jpg, kde XXX je kladné celé číslo.");
		clearInterval(timeout);
		return;
	}
	var next = parts2[1]%hrefs.length+1;

	//alert(parts2[0]+"_"+next+".jpg");
	banner.src = parts2[0]+"_"+next+".jpg";
	if (hrefs.length>1)
		banner.parentNode.href=hrefs[next-1];
}
