
//---------------------------------------------------------------------------------------------------

   function beforeSend_formInstruction()
   {
      $.getJSON('control.php5?op=formLogin_getInstructionJson',
                 {},
                 function getData(json){
                                          folderName=json.templateFolder
                                          language=json.language
                                          $('#instruction').load(folderName+'/instruction_'+language+'.html');
                                       }
               )
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formChangePassword()
   {
      var rules={retypePasswordUser: {equalTo:'#passwordUser'}}
      var messages={retypePasswordUser:MSG_PASSWORDS_MUST_BE_EQUALS}
      var customBehavior=new Array(rules,messages)

      passwordPolicy('formChangePassword','passwordUser')

      return customBehavior
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formUserAll()
   {
      var rules={retypePasswordUser: {equalTo:'#passwordUser'}}
      var messages={retypePasswordUser:MSG_PASSWORDS_MUST_BE_EQUALS}

      var customBehavior=new Array(rules,messages)

      passwordPolicy('formUserAll','passwordUser')
      editOnlyOwnDataJson()
      showHideContractNumber()

      return customBehavior
   }

//---------------------------------------------------------------------------------------------------

   function editOnlyOwnDataJson()
   {
      $.getJSON('control.php5?op=formUserAll_editOnlyOwnDataJson',
                 {},
                 function checkUser(json){
                                            if($('#key').val()!=json.user)
                                               $('#edit,#delete').css('display','none');
                                         }
               )
   }

//---------------------------------------------------------------------------------------------------

   function showHideContractNumber()
   {
      $('#permissionUser').change(function(e){
                                               if(this.selectedIndex<='1')
                                                  $('#contractNumberUserOuter').css('display','block');
                                               else
                                                  $('#contractNumberUserOuter').css('display','none');
                                             })
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formCauseAll()
   {
      $('#pass').click(function(){
                                    $('#idDept,#idReferee').attr('disabled','')
                                    $(this).css('display','none')
                                 })
      clientInfoOnCauseForm()
      autoListboxPopulate('#idDept','#idReferee','formCause_getRefereeListContentJson')
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formCauseClient()
   {
      $('#pass').click(function(){
                                    $('#idDept,#idReferee').attr('disabled','')
                                    $(this).css('display','none')
                                 })
      clientInfoOnCauseForm()
      autoListboxPopulate('#idDept','#idReferee','formCause_getRefereeListContentJson')
   }

//---------------------------------------------------------------------------------------------------

   function disabledIfNoPassing(both)
   {
      $(document).ready(function(){
	                                 $('#idDept').attr('disabled','disabled')
									 if(both==true) 
                                        $('#idReferee').attr('disabled','disabled')
                                  })
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formPassChooseDestination()
   {
      autoListboxPopulate('#idDept','#idReferee','formCause_getRefereeListContentJson')
   }

//---------------------------------------------------------------------------------------------------

   function getClientPesel(client)
   {
      $.getJSON('control.php5?op=formCause_getClientPeselJson&client='+client,
                 {},
                 function getCardClient(json){
                                                $('#infoClient').html(json.peselClient)
                                             }
               )
   }

//---------------------------------------------------------------------------------------------------

   function clientInfoOnCauseForm()
   {
      $('#idClient').change(function(){
                                        getClientPesel($(this).val())
                                      })
      $('#idClient').keyup(function(){
                                        getClientPesel($(this).val())
                                      })
      $('#idClient').ready(function(){
                                        getClientPesel($('#idClient').val())
                                      })
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formJobAll()
   {
      clientInfoOnJobForm()
   }

//---------------------------------------------------------------------------------------------------

   function beforeSend_formJobCause()
   {
      clientInfoOnJobForm()
   }

//---------------------------------------------------------------------------------------------------

   function getClientName(cause)
   {
      $.getJSON('control.php5?op=formJob_getClientNameJson&cause='+cause,
                 {},
                 function getCardClient(json){
                                                $('#infoClient').html(json.nameClient)
                                             }
               )
   }


//---------------------------------------------------------------------------------------------------

   function clientInfoOnJobForm()
   {
      $('#idCause').change(function(){
                                        getClientName($(this).val())
                                      })
      $('#idCause').keyup(function(){
                                        getClientName($(this).val())
                                      })
      $('#idCause').ready(function(){
                                        getClientName($('#idCause').val())
                                      })
      $('#idCause').click(function(){
                                        getClientName($(this).val())
                                    })
									  }

//---------------------------------------------------------------------------------------------------
   function beforeSend_formClientAll()
   {
      $(document).ready(function(){
                                     if($('input[name="_search"]').val()!='true')
									 {
									    $('#phoneClient').mask("999 999 999")
                                        $('#mobileClient').mask("999 999 999")
									 }	

                                     $('#companyData').click(function(){
                                                                          if($(this).attr('checked')==true)
                                                                          {
                                                                             $('#companyClient').parent().css('display','block');
                                                                             if($('input[name="_search"]').val()!='true')
                                                                                $('#companyClient').addClass('required');
                                                                             else
                                                                                $('#companyClient').attr('title','')
                                                                             $('#firstNameClient').parent().css('display','none');
                                                                             $('#lastNameClient').parent().css('display','none');
                                                                             $('#peselClient').parent().css('display','none');
                                                                             $('#identityClient').parent().css('display','none');
                                                                             $('#lastNameClient').removeClass('required');
																			 $('#firstNameClient').removeClass('required');
                                                                          }
                                                                          else
                                                                          {
                                                                             $('#companyClient').parent().css('display','none');
                                                                             $('#companyClient').removeClass('required');
                                                                             $('#firstNameClient').parent().css('display','block');
                                                                             $('#lastNameClient').parent().css('display','block');
                                                                             $('#peselClient').parent().css('display','block');
                                                                             $('#identityClient').parent().css('display','block');
                                                                             if($('input[name="_search"]').val()!='true')
																			 {
                                                                                $('#lastNameClient').addClass('required');
																				$('#firstNameClient').addClass('required');
																		     }		
                                                                          }
                                                                       })
                                  })
   }

//---------------------------------------------------------------------------------------------------

