/**
 * (c) 2007 by Michal Ruzicka (admin@teenage.cz, http://php.teenage.cz)
 */

function opop(path){
	newWindow = window.open("opop.php?path="+path,"foto","height=400,width=500,top=0,left=50,status=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no");
	return false;
}

function isOk(el)
{
    if(el.type=='checkbox')
        return (el.checked?true:false);
    var val = el.value;
    if(val == '' || val == 0 || val == '0000-00-00' || val == '0000-00-00 00:00:00')
        return false;
    if(el.name.indexOf('email') > -1){
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        return emailPattern.test(val);
    }
    return true;
}
function validateform(form, required){
	var first = 0;
	var form = document.forms[form];
	var elm = form.elements;
	var to = required.length;
	checkit(form, required);

    for(i=0;i<to;i++){
    	if(!elm[required[i]])
    		continue;

        var tmp = (elm[required[i]].className.indexOf('inpdp') > -1 ? 'inpdp' : 'inp');

    	if(!isOk(elm[required[i]])){
    		first = (first == 0 ? i : first);
    		if(elm[required[i]].type == 'checkbox')
    		   elm[required[i]].parentNode.className = 'rqrd';
    		else
    		   elm[required[i]].className = tmp+' rqrd';
    	}

    	elm[required[i]].onchange = elm[required[i]].onkeyup = function(){
            if(this.type == 'checkbox')
                this.parentNode.className = (isOk(this) ? '' : 'rqrd');
            else
                this.className = (isOk(this) ? tmp : tmp+' rqrd');
    		checkit(this.form, required);
    	}
    }
}
function checkit(form, required){
	var fck = false;
	var elm = form.elements;
	form.onsubmit = function(){return true};
	for(i=0;i<required.length;i++){
		if(!isOk(elm[required[i]])){
            form.onsubmit = function(){alert('Prosím vyplňte všechna pole označená hvězdičkou!');return false;};
			return;
        }
	}
    $(form).unbind('submit');
}

function getJS(url, callback)
{
    $.ajax({
        type: "GET",
        cache: true,
        url: url,
        dataType: "script",
        success: callback
    });
}

$(function (){
    $('#favlink').jFav();
    function foo(){
        $('#rlink').fadeOut('slow').fadeIn('slow', function(){foo()});
    }
    foo();

    var lboxes = $('.lb');
    if(lboxes.length < 1)
        return;

    $('head').append('<scr'+'ipt type="text/javascript" src="js/lightbox/lightbox.js"></sc'+'ript>').append('<li'+'nk rel="stylesheet" type="text/css" href="js/lightbox/lightbox.css" media="screen" />');
    lboxes.lightBox({
        	imageLoading: '/js/lightbox/loading.gif',
        	imageBtnClose: '/js/lightbox/close.gif',
        	imageBtnPrev: '/js/lightbox/prev.gif',
        	imageBtnNext: '/js/lightbox/next.gif',
            //txtImage: 'Obrázek',
            //txtOf: 'ze',
            containerResizeSpeed: 0
    });
    
    if(!$.support.noCloneEvent)
        $('.menu li').hover(function(){$(this).addClass('sfhover')},function(){$(this).removeClass('sfhover')});
});

