var postitPos=0;
var partneriPos = 0; 
var t;
var partneriT;
var submenuMove = 0;
var submenuPos = 0;
var submenuT;

var maxSubmenuScroll;


function pgInit(){
		document.getElementById('srchInfoText').style.display = 'inline';
		postitTimer();
		partneriTimer();
		
		var lastItemLeft = document.getElementById('lastSubmenuItem').scrollWidth;
		var lastItemWidth = document.getElementById('lastSubmenuItem').offsetLeft;

		maxSubmenuScroll = (lastItemLeft+lastItemWidth) - 970;
		if (maxSubmenuScroll < 0) maxSubmenuScroll = 0;
		
		submenuPos = -20;
		
		selectedSpan = document.getElementById('selectedSubMenuSpan');
		selectedItemPos = 0;
		if (selectedSpan){
			selectedItemPos = document.getElementById('selectedSubMenuSpan').scrollWidth + document.getElementById('selectedSubMenuSpan').offsetLeft;
		}
		submenuPos = 970 - selectedItemPos;

		moveSubMenuItems();
		
	}

function infoTextOn(obj){
	if (obj.value.length==0){
		document.getElementById('srchInfoText').style.display = 'inline';
	}
}

function infoTextOff(){
	document.getElementById('srchInfoText').style.display = 'none';
}

function detailVisibility(){
	document.getElementById('detailTable').style.display= (document.getElementById('prodTyp2').checked) ? 'block' : 'none';
	document.getElementById('neVinoInfo').style.display= (document.getElementById('prodTyp2').checked) ? 'none' : 'block';

	document.getElementById('detailKartonTable').style.display= (document.getElementById('prodTyp3').checked) ? 'block' : 'none';
	document.getElementById('neKartonInfo').style.display= (document.getElementById('prodTyp3').checked) ? 'none' : 'block';
}

function efMove(){
	//partneriCnt
	partneriPos++
	if (partneriPos > partneriCnt){
		partneriPos=1;
		$('partnerihref').style.left=0;
	}
	
	
	var obj = $("parId" + partneriPos); 
	if (obj!=null){
		var wid = parseInt(obj.style.width);
		new Effect.Move($('partnerihref'), { x: wid * (-1) , y: 0 }); 
	}
	partneriTimer();
	
	return false;
}



function partneriTimer()
{
	clearTimeout(t);
	t=setTimeout("efMove()",4000);
}



function postitTimer()
{
	clearTimeout(partneriT);
	partneriT=setTimeout("switchPostit(1)",15000);
}



function switchPostit(direction){
	postitLnt = postitCnt;
	postitPos += direction;
	if (postitPos < 0){
		postitPos += postitLnt;
	}
	postitPos = postitPos % postitLnt;
	
	hideAllPostit();
	document.getElementById('postitContent' + (postitPos+1)).style.display = 'block';
	document.getElementById('postitPage').innerHTML = postitPos+1;
	postitTimer();
}


function hideAllPostit(){
	for (i=1; i<= postitCnt; i++){
		document.getElementById('postitContent' + i).style.display = 'none';
	}
	
	
}


function aktivujZalozku(zalNum){
	var active = 'prDetailObecne';
	if (zalNum==2) active = 'prDetailVino';
	if (zalNum==3) active = 'prDetailHodnoceni';
	if (zalNum==4) active = 'prDetailKarton';
	
	//document.getElementById('prDetailObecneZal').style.fontWeight = 'normal';
	document.getElementById('prDetailObecneZal').className = '';
	document.getElementById('prDetailObecne').style.display = 'none';
	
	//document.getElementById('prDetailVinoZal').style.fontWeight = 'normal';
	document.getElementById('prDetailVinoZal').className = '';
	document.getElementById('prDetailVino').style.display = 'none';
	
	//document.getElementById('prDetailHodnoceniZal').style.fontWeight = 'normal';
	document.getElementById('prDetailHodnoceniZal').className = '';
	document.getElementById('prDetailHodnoceni').style.display = 'none';

	//document.getElementById('prDetailKartonZal').style.fontWeight = 'normal';
	document.getElementById('prDetailKartonZal').className = '';	
	document.getElementById('prDetailKarton').style.display = 'none';
	
	//document.getElementById(active + 'Zal').style.fontWeight = 'bold';
	document.getElementById(active + 'Zal').className = 'selected';
	document.getElementById(active).style.display = 'block';
	

	
	
}

function submitAction(formName, action){
	document.getElementById('pbAction').value=action;
	document.forms[formName].submit();
	
}

function spinInput(id, smer)
{
    idPocet=id;
    objPocet = document.getElementById(idPocet);
    pocet = parseInt(objPocet.value);
    if (pocet>=0)
    {
        pocet = pocet + smer;
        if (pocet < 1)
        {
            pocet=1;
        }
        
        if (pocet > 9999)
        {
            pocet=9999;
        }
        objPocet.value = pocet;
    }
    else
    {
        objPocet.value=0;   
    }

}

function setAction(val){
	a=document.getElementById('inTabAction')
	a.value=val;
	document.forms.gridForm.submit();
}


function moveSubMenuStart(step){
	submenuMove = step;
	subMenuTimer();
}


function subMenuTimer()
{
	clearTimeout(submenuT);
	if (submenuMove != 0){
		submenuT = setTimeout("moveSubMenuItems()",10);
	}
}


function moveSubMenuItems() {
	submenuPos += submenuMove;
	doMove = true;
	
	if (submenuPos > 0){
		submenuPos = 0;
		doMove = false;
	}
	
	if (submenuPos < (maxSubmenuScroll *-1)){
		submenuPos = (maxSubmenuScroll *-1);
		doMove = false;
	}

	if (doMove){
		document.getElementById('itemsWrapper').style.marginLeft = submenuPos+ "px";
		subMenuTimer();
	}
	
	submenuArrowsVisibility();
}

function submenuArrowsVisibility(){
	if ((maxSubmenuScroll > 0) && ((submenuPos * -1) < maxSubmenuScroll)){
		document.getElementById('scrRight').style.display = 'block';
	}
	else{
		document.getElementById('scrRight').style.display = 'none';
		if (submenuMove < 0) submenuMove = 0;
	}
	
	if (submenuPos < 0){
		document.getElementById('scrLeft').style.display = 'block';
	}
	else{
		document.getElementById('scrLeft').style.display = 'none';
		if (submenuMove > 0) submenuMove = 0;
	}

}



/***********************************************
* Cool DHTML tooltip script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function init(){
	
	offsetxpoint=-60 //Customize x offset of tooltip
	offsetypoint=20 //Customize y offset of tooltip
	ie=document.all
	ns6=document.getElementById && !document.all
	enabletip=false
	if (ie||ns6)
	tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
	
}	
	
	
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}


document.onmousemove=positiontip;
