﻿

// validace dokumentu
function oValidateForm() {

    var inputs = document.getElementsByTagName("input");

    var focInx = -1;
    var err = 0;
    var oReturn = true;
    var errMessage = "";

   // alert(inputs.length);

    //Průchod do konce pole
    for (var i = 0; i < inputs.length; i++) 
    {
       // alert('OK 1 - ' + inputs[i].id + ' - ' + inputs[i].getAttribute("type"));

        if ((inputs[i].getAttribute("type") == "text") && (inputs[i].getAttribute("joatt") == "japos") && (inputs[i].getAttribute("joattNN") != "japos")) 
        {
           
            try
            {
               inputs[i].RefreshValue();

               if (!inputs[i].IsValid) 
               {
                   if (inputs[i].Validators.length > 0) 
                   {
                   
                        for(var k = 0; k<inputs[i].Validators.length; k++)
                        {
                            var idLabelText = "";
                            var validator = inputs[i].Validators[k];
                            var errorText = document.getElementById(validator.ErrorMessageBox.id + "_Error");

                            var idLabel = validator.ErrorMessageBox.id.replace("_Validators", "");
                            var idLabelTemp = validator.ErrorMessageBox.id;
                            
                            idLabel = idLabel.replace("pc_", "");

                            if (idLabel.length > 0) 
                            {
                            
                                if (idLabelTemp.substring(0, 3) == "pc_") {
                                    idLabel = "pc_l" + idLabel.substring(1, idLabel.length);
                                }
                                else {
                                    idLabel = "l" + idLabel.substring(1, idLabel.length);
                                }
                                
                                idLabelText = document.getElementById(idLabel).innerHTML;
                            }

                            errMessage += "<b>" + idLabelText + "</b><BR />" + errorText.innerHTML + "<BR /><BR />";
                        }                    
                   
                   
                   
                       inputs[i].Validators[0].ErrorMessageBox.Show();
                       
                   } 
                   
                   err = err + 1;

                   if (oReturn) 
                   {
                       if (focInx < 0) 
                       {
                         oReturn = false;
                         focInx = i;
                       }
                   } 
                                   
                            
               }  //if IsValid   
             }
             catch(e) 
             {
             }         
        } //if type

    } // for

    var errorPanel = document.getElementById("PanelError");
    var errorPanelA = document.getElementById("PanelErrorA");
    var errorPanelImgA = document.getElementById("PanelErrorImgA");
    if (focInx > -1) 
    {

        errorPanel.style.display = "";
        errorPanelA.innerHTML = "Počet nalezených chyb: " + err;

        
        PopupGlobal.SetSize(300, 100);
        PopupGlobal.SetHeaderImageUrl('Images/0140269.png');
        PopupGlobal.SetHeaderText("Počet nalezených chyb: " + err);

        errMessage = "<div style='padding:10px;'> " + errMessage + "</div>";
        
        PopupGlobal.SetContentHTML(errMessage);

        errorPanelA.href = "javascript:PopupGlobal.Show();";
        errorPanelImgA.href = "javascript:PopupGlobal.Show();";
        inputs[focInx].Focus();
    }
    else {
        errorPanel.style.display = "none";
        errorPanelA.innerHTML = "";
    }

  //  alert(err);
    
    
   return  oReturn;

}


