function addEvent(obj, evType, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evType, fn, true);
		return true;
	} 
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} 
	else 
	{
		return false;
	}
}

document.getElementsByClassName = function (needle)
{
  var         my_array = document.getElementsByTagName("*");
  var         retvalue = new Array();
  var        i;
  var        j;

  for (i = 0, j = 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}

addEvent(window, 'load', function()
{
	var counts = document.getElementsByClassName('maxlength');
	var i, count, matches, countHolder;
	
	for (i=0; i<counts.length; i++)
	{
		count = counts[i];	
		matches = count.className.match(/max_([0-9]+)/);
		count.maxVal = RegExp.$1;
		count.holder = document.getElementById(count.id + 'Count');
		if (count.holder)
		{
			count.holder.innerHTML = count.maxVal - count.value.length;
			count.onkeyup = function()
			{
				if (this.value.length > this.maxVal)
					this.value = this.value.substring(0, this.maxVal);
	
				this.holder.innerHTML = this.maxVal - this.value.length;		
			}
		}
	}	
});

function checkpay()
{
	with(window.document.pay)
	{
		if(trim(meno.value)=="" || trim(meno.value)=="Meno")
		{
			alert("Vyplniť Meno a priezvisko (firma)");
			meno.focus();
			return false;
		}
		else if(trim(adresa.value)=="")
		{
			alert("Vyplniť Adresa");
			adresa.focus();
			return false;
		}
		else if(document.getElementById('z1').checked==false && document.getElementById('z2').checked==false )
		{ 
			alert("Označiť Zaradenie");
			return false;
		}
		else if(document.getElementById('d1').checked==false && document.getElementById('d2').checked==false )
		{ 
			alert("Označiť Doba zverejnenia");
			return false;
		}
		else return true;
	}
}

function zobrazcenu()
{
	var con_cena=0;
	with(window.document.pay)
	{
		if(document.getElementById('z1')!=null && document.getElementById('z1').checked==true && document.getElementById('d1').checked==true )
		{ 
			con_cena = 0.83;
		}
		else if(document.getElementById('z1')!=null && document.getElementById('z1').checked==true && document.getElementById('d2').checked==true )
		{ 
			con_cena = 2.49;
		}
		else if(document.getElementById('z2').checked==true && document.getElementById('d1').checked==true )
		{ 
			con_cena = 1.66;
		}
		else if(document.getElementById('z2').checked==true && document.getElementById('d2').checked==true )
		{ 
			con_cena = 4.98;
		}
		
		cena.value = con_cena;
	}
}

function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}


function vyplneniPole(prvekSelect, polozkaSeznamu, dobryDotaz, spatnyDotaz, vychoziPolozka) {
var i, j;
var dotaz;
for (i = prvekSelect.options.length; i >= 0; i--) {
prvekSelect.options[i] = null; 
}
dotaz = (polozkaSeznamu != null) ? dobryDotaz : spatnyDotaz;
if (dotaz == null) {
j = 0;
}
else {
prvekSelect.options[0] = new Option(dotaz);
j = 1;
}
if (polozkaSeznamu != null) {
for (i = 0; i < polozkaSeznamu.length; i++) {
prvekSelect.options[j] = new Option(polozkaSeznamu[i][0]);
if (polozkaSeznamu[i][1] != null) {
prvekSelect.options[j].value = polozkaSeznamu[i][1]; 
}
j++;
}
prvekSelect.options[0].selected = true;
   }
}

function emo(smajl) {
	document.formular.text.value += ' ' + smajl+ ' ';
	document.formular.text.focus();
	return;
}

function zobraz_skry(id){
	el=document.getElementById(id).style;
	el.display=(el.display == 'block')?'none':'block';
}

$(document).ready(function(){	   
						   
	$('#totop a').click(function()
	{
		$(document).scrollTo(0, 500);
		return false;
	});
		
    $('.images a, a.lightbox').lightBox();
});

$(window).scroll(function () { 
 if($(window).scrollTop()!=0) $("#totop a").css("display", "block"); 
 else $("#totop a").css("display", "none");
});

