function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.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 eraseCookie(name) {
	createCookie(name,"",-1);
}



function sortby (what){
if (what == 'cena'){createCookie('ekoprodukty_sort','cena',7);}
if (what == 'nazov'){createCookie('ekoprodukty_sort','nazov',7);}
window.location.reload(false);
}


function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


var ii=0;
var tt_transparency = 0.7; //define tooltip div transparency 0.1 - 1
var tt_offsetright = -10;
var tt_offsettop = -8;
var tt_speed = 0.3;
var oldwhat;
var thiswhat;
var tt_workin=0;


function hide_tooltip(tooltipid) {
reset_ttips(tooltipid);
}


function reset_ttips(what) 
{
var browser=navigator.appName;
ii=0;
if (browser == "Netscape") {document.getElementById(what).style.opacity = ii;
}  else if  (browser == "Microsoft Internet Explorer") 
{document.getElementById(what).style.filter ="alpha(opacity="+ ii*100 + ")"; 
}  else if  (browser == "Opera") {document.getElementById(what).style.opacity = ii;
} else {
document.getElementById(what).style.opacity = ii;
}
document.getElementById(what).style.display = "none";
}

function show_tooltip(fieldid, tooltipid) {
document.getElementById(fieldid).style.zIndex = "1";

if (tt_workin == 1) {
 
reset_ttips(oldwhat);
}	
	
tt_workin=1;
thiswhat = tooltipid;

var obj = document.getElementById(fieldid);
//alert();
var coors = findPos(obj);

var otop = coors[1];
var oleft = coors[0];

//oleft = findPos(fieldid);
//alert (otop);
//alert (oleft);

//document.getElementById(tooltipid).style.top = otop+"px";
//document.getElementById(tooltipid).style.left = oleft+"px"; 

document.getElementById(tooltipid).style.top = otop + tt_offsettop + "px";
document.getElementById(tooltipid).style.left = -tt_offsetright + oleft + parseInt(document.getElementById(fieldid).style.width) + "px"; 

// OK
//document.getElementById(tooltipid).style.top = otop - (parseInt(document.getElementById(tooltipid).style.height)/2) + tt_offsettop + "px";
//document.getElementById(tooltipid).style.left = -tt_offsetright + oleft + parseInt(document.getElementById(fieldid).style.width) + "px"; 


//document.getElementById(tooltipid).style.top = "100px";
//alert (document.getElementById(tooltipid).style.top);
document.getElementById(tooltipid).style.display="block";
oldwhat = tooltipid;
//reset_ttips(tooltipid);
trans(tooltipid);
}

function trans(what) 
{

var browser=navigator.appName;
//document.getElementById("tf4").value=browser;
ii=ii+tt_speed;
//document.getElementById("div3").style.filter =":alpha(opacity="+ ii +")"; 
if (browser == "Netscape") {document.getElementById(what).style.opacity = ii;

}  else if  (browser == "Microsoft Internet Explorer") 
{document.getElementById(what).style.filter ="alpha(opacity="+ ii*100 + ")"; 

}  else if  (browser == "Opera") {document.getElementById(what).style.opacity = ii;

} else {
document.getElementById(what).style.opacity = ii;
}

if (ii < tt_transparency){
setTimeout("trans('" + what + "')", 100);
} else if (ii >= tt_transparency) {
	tt_workin=0;
	ii=tt_transparency;
	}

}


function showme(what) {  
document.getElementById(what).style.display="block";
}

function hideme(what) {  
document.getElementById(what).style.display="none";
}

function focus_to(what) { 
document.getElementById(what).focus();
}


var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var currentTime = new Date()
var cas = currentTime.getTime();
url = url + "&y="+ cas;
//alert (url);
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}




function validate(what, formm)	{

var ff=what.split(",");
er = 0;

for (i = 0; i < ff.length; i++) {	

var ffx = ff[i].split(":");

xx = trim(document.getElementById(ffx[0]).value);

if (xx == "") {
er = 1 ;
document.getElementById(ffx[0]).focus();
alert("Musíte vyplniť toto pole");
break;
}

er2 = 0;
er3 = 0;

if (ffx[1] == "datum") {
numb = document.getElementById(ffx[0]).value;

if ((numb.substr(0,1) < "0") || (numb.substr(0,1) > "9")){er2 = 1;}
if ((numb.substr(1,1) < "0") || (numb.substr(1,1) > "9")){er2 = 1;}

if (numb.substr(2,1) != "."){er2 = 1;}

if ((numb.substr(3,1) < "0") || (numb.substr(3,1) > "9")){er2 = 1;}
if ((numb.substr(4,1) < "0") || (numb.substr(4,1) > "9")){er2 = 1;}

if (numb.substr(5,1) != "."){er2 = 1;}
if (numb.substr(6,1) != " "){er2 = 1;}

if ((numb.substr(7,1) < "0") || (numb.substr(7,1) > "9")){er2 = 1;}
if ((numb.substr(8,1) < "0") || (numb.substr(8,1) > "9")){er2 = 1;}
if ((numb.substr(9,1) < "0") || (numb.substr(9,1) > "9")){er2 = 1;}
if ((numb.substr(10,1) < "0") || (numb.substr(10,1) > "9")){er2 = 1;}

}


if (er2 == 1) {
er = 1 ;
document.getElementById(ffx[0]).focus();
alert("Nesprávny dátum. Napíšte dátum v tvare: 01.01. 2007 \n(pred rokom nezabudnite na medzeru)");
}

}


if (er == 0){
document.getElementById(formm).submit();
}

}


function CenterToScreen(objwidth, objheight) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = (window.innerWidth - objwidth) / 2;
    myHeight = ((window.innerHeight - objheight) / 2) + document.documentElement.scrollTop;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = (document.documentElement.clientWidth - objwidth) / 2;
    myHeight = ((document.documentElement.clientHeight - objheight) / 2) + document.documentElement.scrollTop;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = (document.body.clientWidth - objwidth) / 2;
    myHeight = ((document.body.clientHeight - objheight) / 2) + document.body.scrollTop;
  }
 
  return [myWidth,myHeight];
}

var fade=0;
var fadeSpeed = 0.1;
var fadeWorkin=0;


function addToCart(IDvyrobku) {
	ajaxpage('a_order.php?action=add&id=' + IDvyrobku, 'ShopContent');
}


function addToCartAnim() {

	document.getElementById('add_cart').style.display="block";
	var centercor = CenterToScreen(200,100);
	document.getElementById('add_cart').style.left = centercor[0] + "px";
	document.getElementById('add_cart').style.top = centercor[1] + "px";
	fadeIn('add_cart');
}


function fadeIn(what) 
{
if (fadeWorkin == 0){
var browser=navigator.appName;
fade=fade+fadeSpeed;
if (browser == "Netscape") {document.getElementById(what).style.opacity = fade;
}  else if  (browser == "Microsoft Internet Explorer") 
{document.getElementById(what).style.filter ="alpha(opacity="+ fade*100 + ")"; 
}  else if  (browser == "Opera") {document.getElementById(what).style.opacity = fade;
} else {
document.getElementById(what).style.opacity = fade;
}
if (fade < 1){
setTimeout("fadeIn('" + what + "')", 10);
} else if (fade >= 1) {
	fadeWorkin=1;
	fade=1;
	setTimeout("fadeOut('" + what + "')", 1000);
}
}
}



function fadeOut(what) 
{
var browser=navigator.appName;
fade=fade-fadeSpeed;
if (browser == "Netscape") {document.getElementById(what).style.opacity = fade;
}  else if  (browser == "Microsoft Internet Explorer") 
{document.getElementById(what).style.filter ="alpha(opacity="+ fade*100 + ")"; 
}  else if  (browser == "Opera") {document.getElementById(what).style.opacity = fade;
} else {
document.getElementById(what).style.opacity = fade;
}
if (fade > 0){
setTimeout("fadeOut('" + what + "')", 10);
} else if (fade <= 0) {
	fadeWorkin=0;
	fade=0;
	document.getElementById(what).style.display="none";
}

}
