﻿function ValidTxMail(input)
{
	var elem = document.getElementById(input);
    if (elem.value.length == 0)
    {
        alert('Nie podano adresu e-mail!');
        return false;
    }
    else
    {
        if (!ValidMail(input))
        {
            alert('Błędny adres e-mail!');
            return false;
        }
        else
        {
            return true;
        }
    }
}

function ValidFormMail(inpSub, inpBody, inpMail)
{
	var elem = document.getElementById(inpMail);
    inpSub.className = "dane"
    inpBody.className = "dane"
    elem.className = "dane"
    
    if (inpSub.value.length == 0)
    {
        alert('Nie podano tematu e-maila!');
        inpSub.className="dane error"
        return false;
    }
    if (inpBody.value.length == 0)
    {
        alert('Nie podano treści e-maila!');
        inpBody.className="dane error"
        return false;
    }

    if (elem.value.length > 0)
    {
        if (!ValidMail(inpMail))
        {
            alert('Błędny adres e-mail!');
            return false;
        }
        else
        {
            return true;
        }
    }
}

function ValidFormMail(inpSub, inpBody, inpMail)
{
	var elem = document.getElementById(inpMail);
    inpSub.className = "dane"
    inpBody.className = "dane"
    elem.className = "dane"
    
    if (inpSub.value.length == 0)
    {
        alert('Nie podano tematu e-maila!');
        inpSub.className="dane error"
        return false;
    }
    if (inpBody.value.length == 0)
    {
        alert('Nie podano treści e-maila!');
        inpBody.className="dane error"
        return false;
    }

    if (elem.value.length > 0)
    {
        if (!ValidMail(inpMail))
        {
            alert('Błędny adres e-mail!');
            return false;
        }
        else
        {
            return true;
        }
    }
}

function ValidPolec(mod, mdo, pod)
{
    mod.className = "dane"
    if (!ValidTxMail("polOd"))
    {
        mod.className="dane error"    
        return false;
    }

    mdo.className = "dane"
    if (!ValidTxMail("polDo"))
    {
        mdo.className="dane error"    
        return false;
    }

    pod.className = "dane"
    if (pod.value.length == 0)
    {
        alert ("Nie podano podpisu!");
        pod.className="dane error"    
        return false;
    }
    return true;
}

function Polecenie()
{
	var mod = document.getElementById("polOd");
	var mdo = document.getElementById("polDo");
	var pod = document.getElementById("polPod");

    if (!ValidPolec(mod, mdo, pod))
    {
        return false;
    }
    
    document.getElementById('tabPolec').style.visibility='hidden';
    document.getElementById('polStart').style.visibility='visible';   
    BaseForm.Polecenie(mod.value, mdo.value, pod.value);
    mdo.value = "";

    var w = 500;
    var h = 350;

    var l = (screen.availWidth-w)/2;
    var t = (screen.availHeight-h)/2;
    window.open("Polec.html","","left=" + l + ",top= " + t + ",height=" + h + ",width=" + w + ",resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no,location=no");

}

function PolThx()
{
}
