﻿var EN_GB = "en-GB";
var EN_US = "en-US";
var SK_SK = "sk-SK";
var AT_year = 2000;
var AT_month = 1; // 1-based (as opposed to JavaScript 0-based months)
var AT_id = "";
var AT_visible = false;
var AT_format = SK_SK; //EN_US;

function month_length(m,y)
{
    if (m==4 || m==6 || m==9 || m==11) return 30;
    if (m!=2) return 31;
    if (y % 4 !=0) return 28;
    if (y % 100 == 0 && y % 400 != 0) return 28;
    return 29;
}

function ATclose()
{
    ATupdate("");
    AT_visible = false;   
    return false;
}

function ATtoggle( id )
{
    if (AT_visible) return ATclose();
    AT_id = id;
    ATparse( document.getElementById(AT_id).value );
    ATredraw(0);
    AT_visible = true;
    return false;
}

function ATparse( s )
{
    var today = new Date();
    var reset = false;
    var parts = s.split("/");
    if (parts.length>=2)
    {
        if (parts.length==2) 
        {
            AT_year = today.getFullYear();
        }
        else 
        { 
            AT_year = eval(parts[2]); 
            if (AT_year<100) { AT_year += 2000; }
            reset = !AT_year || AT_year<1900 || AT_year>2100; 
        }

        AT_month = (AT_format==EN_GB) ? eval(parts[1]) : eval(parts[0]);
        reset = reset || !AT_month || AT_month<1 || AT_month>12;
    }
    else
    {
        reset = true;
    }    
    if (reset)
    {
        AT_month = today.getMonth()+1;
        AT_year = today.getFullYear();
    }
}

function ATupdate( s )
{    
    document.getElementById(AT_id+'_div').innerHTML = s;
}

function ATformat2( y,m,d )
{
    if (AT_format==EN_GB) return d+"/"+m+"/"+y;
    if (AT_format==SK_SK) return d+"."+m+"."+y;
    return m+"/"+d+"/"+y;
}

function ATsel( dd )
{
    document.getElementById(AT_id).value = ATformat2( AT_year, AT_month, dd );
    ATupdate("");
    AT_visible = false;
    return false;
}

function ATredraw(delta_months)
{
    //var mths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var mths = new Array("Január","Február","Marec","Apríl","Máj","Jún","Júl","August","September","Október","November","December");
    //var dows = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
    var dows = new Array("NE","PO","UT","ST","ŠT","PI","SO");
    nm = delta_months + AT_year*12 + AT_month-1;
    AT_month = (nm %12) + 1;
    AT_year = (nm + 1 - AT_month) / 12;
    c = "<table border=0 cellpadding=0 cellspacing=0>";
    c += "<tr><td align=center class=AT_dpy>";   
    c += "<a class=AT_dpy href=# onClick='return ATredraw(-12)'>&lt;</a> <b class=AT_dpy >"+AT_year+"</b> <a class=AT_dpy href=#  onClick='return ATredraw(12)'>&gt;</a></td></tr>";        
    dt = new Date(AT_year,AT_month-1,1);
    dow = (dt.getDay()+6) % 7;
    days = month_length(AT_month,AT_year);    
    c += "<tr><td align=center class=AT_dpm><a class=AT_dpm href=#  onClick='return ATredraw(-1)'>&lt;</a> <b class=AT_dpm>"+mths[AT_month-1].substring(0,3)+"</b> <a href=#  onClick='return ATredraw(1)' class=AT_dpm >&gt;</a></td></tr>";
    c += "<tr><td>";
    c += "<table bgcolor=#909090 border=0 cellpadding=1 cellspacing=1>";
    offset = -dow;    
    for (var row=-1;row<=(dow+days)/7;row++)
    {
        c += "<tr>";
        for (var col=0;col<7;col++)
        {
            if (row==-1)
            {
                c += "<td style='width:2em' align=center class=AT_dp bgcolor=#ffffff>" + dows[col].substring(0,2);
            }
            else 
            {
                if (offset>0 && offset<=days) 
                {
                    c += "<td style='cursor:pointer;cursor:hand' align=right class=AT_dp bgcolor=#ffffff onClick='return ATsel("+offset+")' onMouseOver=\"this.bgColor='#d0d0d0'\" onMouseOut=\"this.bgColor='#ffffff'\">"+offset+"";
                }
                else
                {
                    c += "<td bgcolor=#ffffff class=AT_dp>&nbsp;";
                }
                offset++;
            }
            c += "</td>";
        }
        c += "</tr>";
    }
    c += "</table>";
    c += "</td></tr></table>";   
    ATupdate( "<table border=0 bgcolor=#909090 cellpadding=0 cellspacing=1><tr><td><table border=0 cellspacing=0 cellpadding=1 bgcolor=white><tr><td>"+c+"</td></tr></table></td></tr></table>" );
    return false;
}


//////////////////////////////////////


function menu_onload(){
	var verticals=new simpleMenu('menu_vertical','vertical');
	var horizontals=new simpleMenu('menu_horizontal','horizontal');
}

function simpleMenu(navid, orient){
	if(typeof document.getElementById == 'undefined' || /opera[\/ ][56]/i.test(navigator.userAgent)){ return; }
	
	this.iskde = navigator.vendor == 'KDE';

	this.isie = typeof document.all != 'undefined' && typeof window.opera == 'undefined' && !this.iskde;

	this.isoldsaf = navigator.vendor == 'Apple Computer, Inc.' && typeof XMLHttpRequest == 'undefined';

	this.tree = function(){
	  return document.getElementById(navid);
	}
	
	if(this.tree() != null)
	{
		this.items = this.tree().getElementsByTagName('li');
		this.itemsLen = this.items.length;

		var i = 0; 
		do
		{
			this.init(this.items[i], this.isie, this.isoldsaf, this.iskde, navid, orient);
		}
		while (++i < this.itemsLen);
	}
}

simpleMenu.prototype.init = function(trigger, isie, isoldsaf, iskde, navid, ishoriz)
{
	
	trigger.menu = 
	  trigger.getElementsByTagName('ul').length ? 
	  trigger.getElementsByTagName('ul')[0] : null;

	trigger.link = trigger.getElementsByTagName('a')[0];

	
	trigger.issub = trigger.parentNode.id == navid;
	
	trigger.ishoriz = ishoriz == 'horizontal';
	
	
	this.openers ={ 'm' : 'onmouseover', 'k' : (isie ? 'onactivate' : 'onfocus') };

	for(var i in this.openers)
	{
		trigger[this.openers[i]] = function(e)
		{
			
			if(!iskde){ this.link.className += (this.link.className == '' ? '' : ' ') + 'rollover'; }

			if(this.menu != null)
			{
				
				if(this.ishoriz){ this.menu.style.left = ((isie || isoldsaf) && (navigator.userAgent.toLowerCase().indexOf("msie 7")<0)) ? this.offsetLeft + 'px' : 'auto'; }
				
				
				
				
				this.menu.style.top = (this.ishoriz && this.issub) ? 
				  ((isie || (this.ishoriz && isoldsaf))&& (navigator.userAgent.toLowerCase().indexOf("msie 7")<0)) ? 
				    this.link.offsetHeight + 'px' : 'auto' : 
				  ((isie || (this.ishoriz && isoldsaf))&& (navigator.userAgent.toLowerCase().indexOf("msie 7")<0)) ? 
				    this.offsetTop + 'px' : '0';
			}
		};
	}


	this.closers ={ 'm' : 'onmouseout', 'k' : (isie ? 'ondeactivate' : 'onblur') };

	
	for(i in this.closers)
	{
		trigger[this.closers[i]] = function(e)
		{
			
			this.related = (!e) ? window.event.toElement : e.relatedTarget;

			
			if(!this.contains(this.related))
			{
				
				if(!iskde){ this.link.className = this.link.className.replace(/[ ]?rollover/g, ''); }
				
				if(this.menu != null)
				{
					
					this.menu.style[(this.ishoriz ? 'left' : 'top')] = 
					  this.ishoriz ? '-10000px' : '-100em';
				}
			}
		};
	}

	if(!isie)
	{
		trigger.contains = function(node)
		{
			if (node == null){ return false; }
			if (node == this){ return true; }
			else{ return this.contains(node.parentNode); }
		};
	}
	trigger = null;
}




///////////////////////



/***********************************************
* 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 ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ShowTooltip(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 HideTooltip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip;



//////////////////////////


function show_category(obj){
	cat_id=obj.value;
	if(cat_id!="")
		location.href="http://www.bubo.sk/katalog/?catalog_category="+cat_id+"#list";
}
