﻿var menuClass = "";
function showMenu(id){
  document.getElementById('sm'+id).style.display='block';
  menuClass = document.getElementById('m'+id).className;
  document.getElementById('m'+id).className='hover';
};
function hideMenu(id){
  document.getElementById('sm'+id).style.display='none';
  document.getElementById('m'+id).className=menuClass;
};

function showImg(url, id, width, height) {
    width += 50;
    height += 50;

    if (height + 50 > screen.height)
        height = screen.height - 200;

    if (width + 50 > screen.width)
        width = screen.width - 100;

    x = (screen.width - width) / 2;
    y = (screen.height - height) / 2;

    var a = window.open(url + id, "imgDialog", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,left=" + x + ",top=" + y + ",resizable=yes,width=" + (width) + ",height=" + (height));
};


function isEmpty(value) {

    if (value == null || value == "") {
        return true;
    }
    else {
        return false;
    }
}

// Validace emailu
function validateEmail(str) {
    var regex = new RegExp(/[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+\.[a-zA-Z0-9_.-]*[a-zA-Z]/);

    if (regex.test(str) == true) {
        return true;
    }
    else {
        return false;
    }
}


// Validace formuláře
// Povinné položky jsou nadefinovány v regform.xsl a certform.xsl
function validateForm() {
    var L_ALERT_TEXT = "Vyplňte povinné pole";
    var L_ALERT_TEXT_EMAIL = "Chybný formát e-mailu!";

    for (var i = 0; i < arrID.length; i++) {

        if (isEmpty(document.getElementById(arrID[i]).value)) {
            alert(L_ALERT_TEXT + ': ' + arrName[i]);
            document.getElementById(arrID[i]).focus();
            return false;
        }

    }
    
    var email = document.getElementById('euserMail').value;
    if(validateEmail(email)){
        return true;
    }
    else {
        alert(L_ALERT_TEXT_EMAIL);
        document.getElementById("euserMail").focus();
        return false;
    }
};


function captchaFailure() {
    alert('Opište prosím správně kód z obrázku.');
    document.getElementById('captcha').focus();
};


function adaptRightBox() {
    var middleH = $("#middle").height();
    var rightBoxH = $("#rightBox").height();
    var rightH = $("#middle .right").height();

    var rbMargin = Math.floor(middleH - rightH + 50);
    $("#rightBox").css("margin-top", rbMargin + "px");
};




jQuery(document).ready(function() {

    //adaptRightBox();

    // Preload obrazku
    img1 = new Image();
    img1.src = "design/images/img11.jpg";

    img2 = new Image();
    img2.src = "design/images/img21.jpg";

    img3 = new Image();
    img3.src = "design/images/img31.jpg";

    img4 = new Image();
    img4.src = "design/images/img32.jpg";




    $('#middle .left .img1 img')
    .mouseover(function() {
        $(this).attr('src', 'design/images/img11.jpg');
        $('#middle .right .img3').prepend('<img src="design/images/img31.jpg" alt="" style="display:none">');
        $('#middle .right .img3 img').fadeIn(300);
    })
    .mouseout(function() {
        $(this).attr('src', 'design/images/img1.jpg');
        $('#middle .right .img3 img').hide();
    });

    $('#middle .left .img2 img')
    .mouseover(function() {
        $(this).attr('src', 'design/images/img21.jpg');
        $('#middle .right .img3').prepend('<img src="design/images/img32.jpg" alt="" style="display:none">');
        $('#middle .right .img3 img').fadeIn(300);
    })
    .mouseout(function() {
        $(this).attr('src', 'design/images/img2.jpg');
        $('#middle .right .img3 img').hide();
    });

});