var Stoper = null;

function pokaz_warstwe(co)
{
	
	var w = 200;
	var h = 100;
	
	var wleft = (screen.width - w) / 2;
	var wtop = h;

	if(document.getElementById(co))
	{
		var obiekt=document.getElementById(co);
		if(obiekt.style.display=='block')
		{
			obiekt.style.display='none';  
		}
		else
		{
			obiekt.style.left=parseFloat(wleft)+"px";
			obiekt.style.top=parseFloat(wtop)+"px";	
			obiekt.style.display='block';  
		}
	}
	
}


function timeout()
{
     //clearTimeout(Stoper);
     //Stoper = setTimeout("schowaj_wszystkie()" , 2000 ); // po ile ms ma znikac 1000=1s
}


function pokaz_menu(id, typ)
{
	
	schowaj_wszystkie();
	
	var ktory='pmenu_'+id;
	
	var obiekt=document.getElementById(ktory);
	
	if(obiekt==null) return false;
	
	var a_ktory='link_'+id;
	var a_obiekt=document.getElementById(a_ktory)
	
	if (typ==0)
		a_obiekt.style.backgroundColor='#41A62A';
	else
		a_obiekt.style.backgroundColor='#0C2369';
	
	
	var x=0;
	var y=30;

	
	var pozycja=getAnchorPosition(a_ktory);

	document.getElementById(ktory).style.left=parseFloat(pozycja.x+x)+"px";
	document.getElementById(ktory).style.top=parseFloat(pozycja.y+y)+"px";	
	document.getElementById(ktory).style.display='block';  
	
	timeout();
}

function pokaz_pmenu(id)
{
	
	schowaj_podmenu_wszystkie();



	var ktory='ppmenu_'+id;
	
	var obiekt=document.getElementById(ktory);
	if(obiekt==null) return false;	
	var a_ktory='link_'+id;
	var a_obiekt=document.getElementById(a_ktory)
	var x=120;
	var y=5;
	var pozycja=getAnchorPosition(a_ktory);
	document.getElementById(ktory).style.left=parseFloat(pozycja.x+x)+"px";
	document.getElementById(ktory).style.top=parseFloat(pozycja.y+y)+"px";	
	document.getElementById(ktory).style.display='block';  
	timeout();
}

function schowaj_podmenu_wszystkie()
{
	var wezel = document.getElementsByTagName('div')
	var ilosc = wezel.length
	for(var i=0;i<ilosc;i++) {
			var nodeObj = wezel.item(i);                                
			if(nodeObj.id.indexOf('ppmenu_')!=-1) {
			   nodeObj.style.display = 'none';  			
			}
	}	
}


function schowaj_wszystkie()
{
	schowaj_podmenu_wszystkie();

	var wezel = document.getElementsByTagName('div')
	var ilosc = wezel.length
	for(var i=0;i<ilosc;i++) {
			var nodeObj = wezel.item(i);                                
			if(nodeObj.id.indexOf('pmenu_')!=-1) {
			   nodeObj.style.display = 'none';  			
			}
	}
	
	var wezel = document.getElementsByTagName('td')
	var ilosc = wezel.length
	for(var i=0;i<ilosc;i++) {
			var nodeObj = wezel.item(i);                                
			if(nodeObj.id.indexOf('link_')!=-1) {
			   nodeObj.style.backgroundColor = '';  			
			}
	}		
}

//pobieranie pozycji obiektu
function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}


//@pobieranie pozycji obiektu


function zatwiedz_produkty()
{
	document.getElementById('produkt').value=0;
	document.getElementById('kategorie_produktow').submit();
	
}
function zatwiedz_przepisy()
{
	document.getElementById('przepis').value=0;
	document.getElementById('kategorie_przepisow').submit();
	
}

function czysc_form(co)
{
	if(co=='zaloguj')
	{
		document.getElementById('formUsername').value='';
		document.getElementById('formPassword').value='';		
	}

	return false;
}



var globalID;
function addComment(){
  pid = 'ksok_left_menu';
  if(globalID!=null){
    document.getElementById(globalID).style.display = 'none';
  }
  if(document.getElementById(pid).style.display = 'none'){
    if(pid == globalID){ globalID=null; return; }
    document.getElementById(pid).style.display = 'block';
    globalID = pid;
  } else {
    document.getElementById(pid).style.display = 'none';
  }
}

function cytuj(cID){
  document.getElementById('ksok_left_menu').style.display = 'block';
  content = document.getElementById(cID).innerHTML;
  document.getElementById('comment').innerHTML = '[cytat]' + content + '[/cytat]';
}

function changeFontSize(inc)
{
  var p = document.getElementsByTagName('dt');
  for(n=0; n<p.length; n++){
    if(p[n].style.fontSize){
       var size = parseInt(p[n].style.fontSize.replace("px", ""));
    } else {
       var size = 12;
    }
    p[n].style.fontSize = size+inc + 'px';
   }
}




