﻿function SaveContact()
{
    errors = "";
    
    if (trim($("txName").value).length <= 0)
    {
        errors +=  getJSPH("Contact_CompletatiNumePrenume");
    }
    
    if (trim($("txCompany").value).length <= 0)
    {
        errors +=  getJSPH("Contact_CompletatiFirma");
    }
    
    if (trim($("txJob").value).length <= 0)
    {
        errors += getJSPH("Contact_CompletatiFunctia");
    }
    
    if (trim($("txAdress").value).length <= 0)
    {
        errors += getJSPH("Contact_CompletatiAdresa");
    }            
    
    if (trim($("txCity").value).length <= 0)
    {
        errors += getJSPH("Contact_CompletatiLocalitate");
    }   
   
    if (trim($("txPhone").value).length <= 0)
    {
        errors += getJSPH("Contact_CompletatiTelefon");
    }   
    else
    {
        if( !isPhoneValid( $("txPhone").value) )
        {
            errors += getJSPH("Contact_TelefonValid");
        }
    }
    
    if (trim($("txFax").value).length <= 0)
    {
        errors += getJSPH("Contact_CompletatiFax");
    }   
    else
    {
        if( !isPhoneValid( $("txFax").value) )
        {
            errors += getJSPH("Contact_FaxValid");
        }
    }
    
    if (trim($("txEmail").value).length > 0)
    {
        if( !isEmail( $("txEmail").value) )
        {
            errors += getJSPH("Contact_EmailValid");
        }
    }
    
    if( !($("rbYes").checked) && !($("rbNo").checked) )
      {
            errors += getJSPH("Contact_CompletatiPrimaIntrebare");
      }
    else
        if( ($("rbNo").checked) && (trim($("txAnswer").value).length <= 0) )
          {
                errors += getJSPH("Contact_CompletatiADouaIntrebare");
          }
    
    ckProduse = $("frmMain").ckScule;
    produse ="";
    for( i = 0; i < ckProduse.length; i++)
    {                           
        if( ckProduse[i].checked )
        {
            if( i == ckProduse.length-1 )
                if ( trim($("txDescription").value).length <= 0)
                {
                     errors += getJSPH("Contact_CompletatiDescriere");
                }
                else
                    produse += "<b>Altele : </b><br /> - " + $("txDescription").value;
         
            produse += " - "+ckProduse[i].value+ "<br />";
        }
                      
    }  
    if( produse == "" )
    {
            errors += getJSPH("Contact_BifatiProdus");
    }
    
    if ($("ddAddressee") && $("ddAddressee").value=="0")
    {
        errors += " - Trebuie sa alegeti un destinatar;\n ";
    }   
    
    if (errors.length > 0)
    {
        alert(getJSPH("Contact_RemediatiProblemele")+errors);
        //rollback the culture tab
      //  $("hSelectedTab").value = $("hPreviousSelectedTab").value;     
    }
    else
    {
        document.getElementById("hAction").value = "SaveContact";
        document.getElementById("hProduse").value = produse;
        document.getElementById("frmMain").submit();
    }
}


