function clearInput(el)
{
    if(el.value != "")
    {
        el.value = "";
    }
}

function skryj(objekt){
    document.getElementById(objekt).style.visibility="hidden";
}
function zobraz(objekt){
    document.getElementById(objekt).style.visibility="visible";
}

/* Záložky */
var obsah1;
var obsah2;
var pocet = 0;

function onload_zalozky(){
    obsah1 = document.getElementById("podlefirmy").innerHTML;
    obsah2 = document.getElementById("podleoboru").innerHTML;
  
    document.getElementById("podleoboru").innerHTML = "";
}

function zmen(){
    document.getElementById("active").style.background = "url('../images/design/reference_pasive.png')";
    document.getElementById("pasive").style.background = "url('../images/design/reference_active.png')";
    document.getElementById("lefttop").style.background = "url('../images/design/reference_left2.png')";
    document.getElementById("activenon").style.background = "url('../images/design/reference_actnon2.png')";
    document.getElementById("pasiveright").style.background = "url('../images/design/reference_right2.png')";
   
    document.getElementById("podlefirmy").style.visibility = "hidden";
    document.getElementById("podlefirmy").style.height = "0px";
    document.getElementById("podlefirmy").innerHTML = "";
  
    document.getElementById("podleoboru").style.visibility = "visible";
    document.getElementById("podleoboru").style.height = "auto";
    document.getElementById("podleoboru").innerHTML = obsah2;
}
function zmen2(){ 
    document.getElementById("active").style.background = "url('../images/design/reference_active.png')";
    document.getElementById("pasive").style.background = "url('../images/design/reference_pasive.png')";
    document.getElementById("lefttop").style.background = "url('../images/design/reference_left.png')";
    document.getElementById("activenon").style.background = "url('../images/design/reference_actnon.png')";
    document.getElementById("pasiveright").style.background = "url('../images/design/reference_right.png')";
  
    document.getElementById("podleoboru").style.visibility = "hidden";
    document.getElementById("podleoboru").style.height = "0px";
    document.getElementById("podleoboru").innerHTML = "";
  
    document.getElementById("podlefirmy").style.visibility = "visible";
    document.getElementById("podlefirmy").style.height = "auto";
    document.getElementById("podlefirmy").innerHTML = obsah1;
}




function podtrzeni(objekt){
    if (document.getElementById(objekt).style.textDecoration == "none"){
        document.getElementById(objekt).style.textDecoration = "underline";
    } else{
        document.getElementById(objekt).style.textDecoration = "none";
    }
}


function checkForm(formular) {
    c = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");

    if (formular.jmeno.value == "") {
        alert("Musíte vyplnit Vaše jméno!");
        formular.jmeno.style.borderColor = "#f0522b";
        formular.jmeno.focus();
        return false;
    }
    else if(formular.prijmeni.value == "") {
        alert("Musíte vyplnit Vaše příjmení!");
        formular.prijmeni.style.borderColor = "#f0522b";
        formular.prijmeni.focus();
        return false;
    }
    else if(formular.email.value == "") {
        alert("Musíte vyplnit Váš email!");
        formular.email.style.borderColor = "#f0522b";
        formular.email.focus();
        return false;
    }
    else if (!c.test(formular.email.value)) {

        alert("Zadaný email neodpovídá správnému formátu.");
        formular.email.style.borderColor = "#f0522b";
        formular.email.focus();
        return false;
    }
    else if(formular.message.value == "") {
        alert("Musíte vyplnit text zprávy!");
        formular.message.style.borderColor = "#f0522b";
        formular.message.focus();
        return false;
    }
    else{
        return true;
    }
}
 
function checkForm2(formular) {
    c = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");

    if (formular.yourname.value == "") {
        alert("Musíte vyplnit Vaše jméno!");
        formular.yourname.style.borderColor = "#f0522b";
        formular.yourname.focus();
        return false;
    }
    else if(formular.emailtosend.value == "") {
        alert("Musíte vyplnit Váš email!");
        formular.emailtosend.style.borderColor = "#f0522b";
        formular.emailtosend.focus();
        return false;
    }
    else if (!c.test(formular.emailtosend.value)) {

        alert("Zadaný email neodpovídá správnému formátu.");
        formular.emailtosend.style.borderColor = "#f0522b";
        formular.emailtosend.focus();
        return false;
    }
    else{
        return true;
    }
}


// odesilani emailu
function send_mail() {
    $("#yourname").css({
        "border": ""
    });
    $("#emailtosend").css({
        "border": ""
    });

    var odesilatel = $("#yourname").val();
    var prijemce = $("#emailtosend").val();

    c = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");

    if (odesilatel == "" || odesilatel == "(Vaše jméno)") {
        alert("Musíte vyplnit Vaše jméno!");
        $("#yourname").css({
            "border": "1px solid #f0522b"
        });
        $("#yourname").focus();
        return false;
    }
    else if(prijemce == "") {
        alert("Musíte vyplnit Váš email!");
        $("#emailtosend").css({
            "border": "1px solid #f0522b"
        });
        $("#emailtosend").focus();
        return false;
    }
    else if (!c.test(prijemce)) {
        alert("Zadaný email neodpovídá správnému formátu.");
        $("#emailtosend").css({
            "border": "1px solid #f0522b"
        });
        $("#emailtosend").focus();
        return false;
    }
    /*
		$().ajaxSend(function(r,s){
			$("#contentLoading").animate({ opacity: 0 }, 0, "swing", function () {
				$(this).show().animate({ opacity: 0.5 }, 0, "swing");
			});
		});
 
		$().ajaxStop(function(r,s){
			$("#contentLoading").fadeOut(50);
		});
		*/
    $.post("sendMail.php", {
        from: odesilatel,
        to: prijemce
    },
    function(data){
				if (data == 'send_ok') {
            $("#doporucte").html('<div class="odsazeni">Doporučení bylo odesláno na adresu '+prijemce+'. <br /><br /><a href="javascript:;" class="next_mail" id="show_mail_form" style="color: black">Poslat dalšímu známému</a>');
        } else if (data == 'nonvalid_mail') {
            alert("Zadaný email neodpovídá správnému formátu.");
        } else {
            $("#doporucte").html('<div class="odsazeni">Omlouváme se, nastala chyba při odesílání e-mailu. Chyba: '+data+'</div>');
        }
        $("#show_mail_form").click(function(){
            $("#doporucte").html('<div class="odsazeni"><form onsubmit="return false"><div id="sendmail"><div class="mail"><div>Pomohly Vám tyto stránky?</div><div class="black">Doporučte je svému známému!</div></div><table><tr><td><input type="text" name="yourname" id="yourname" value="(Vaše jméno)" onclick="clearInput(this)" /></td></tr><tr><td><input type="text" name="emailtosend" value="(Email příjemce) @" id="emailtosend" onclick="clearInput(this)" /></td></tr><tr><td><input type="submit" name="mailsubmit" id="odesli-mail" class="submit" value="odeslat" onclick="send_mail()" /></td></tr></table></div></form></div>')
        });

    });
    

    
}


