var email_pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(function() {

  $.preloadImages("images/menu_active_bg.gif");

  var lheight = $('#left_frame').outerHeight();
  var rheight = $('#right_frame').outerHeight();
  if( rheight > lheight ) {
    $('.content_inner:first').css('height',(rheight - 30)+'px');
  }

  $('.has_sub a').mousemove(function(){
    var this_position = $(this).position();
    var this_height = $(this).outerHeight();
    $('#' + $(this).attr('id') + 'sub').css({
      'top':(this_position.top + this_height + 'px'),
      'left':(this_position.left)
    }).show();
  }).mouseout(function(){
    $('#' + $(this).attr('id') + 'sub').hide();
  });;

  $('.submenu').mouseover(function(){
    $(this).show();
  }).mouseout(function(){
    $(this).hide();
  });

});

function form_section(section_name) {
  if( $('#'+section_name).length == 1 ) {
    $('.depends:visible').hide();
    $('#'+section_name).show();
  } else {
    alert('sekcja nie znaleziona');
  }
}

function inne_uslugi_check() {
  var errors = '';
  if( $('#nazwa_podmiotu').val() == '' ) {
    errors += "Podaj nazwę podmiotu!\n";
  }
  if( $('#osoba_kontaktowa').val() == '' ) {
    errors += "Podaj osobę kontaktową!\n";
  }
  if( $('#telefon').val() == '' ) {
    errors += "Podaj telefon!\n";
  }
  if( !email_pattern.test($('#email').val()) ) {
    errors += "Niepoprawny adres e-mail!\n";
  }
  if( $('#przedmiot_dzialalnosci').val() == '' ) {
    errors += "Podaj przedmiot działalności!\n";
  }
  if( $('#forma_prawna').val() == '' ) {
    errors += "Podaj formę prawną!\n";
  }
  if( errors != '' ) {
    alert( errors + "\nProsimy o poprawienie błędów." )
    return false;
  } else {
    return true;
  }
}

function pelna_ksiegowosc_check() {
  var errors = '';
  if( !/^[0-9]+$/.test($('#ilosc_dokumentow').val()) ) {
    errors += "Ilość dokumentów powinna być liczbą!\n";
  }
  if( !email_pattern.test($('#email').val()) ) {
    errors += "Niepoprawny adres e-mail!\n";
  }
  if( errors != '' ) {
    alert( errors + "\nProsimy o poprawienie błędów." )
    return false;
  } else {
    return true;
  }
}

function kpir_check() {
  var errors = '';
  if( !/^[0-9]+$/.test($('#ilosc_dokumentow').val()) ) {
    errors += "Ilość dokumentów powinna być liczbą!\n";
  }
  if( !email_pattern.test($('#email').val()) ) {
    errors += "Niepoprawny adres e-mail!\n";
  }
  if( errors != '' ) {
    alert( errors + "\nProsimy o poprawienie błędów." )
    return false;
  } else {
    return true;
  }
}

function ryczalt_check() {
  var errors = '';
  if( !/^[0-9]+$/.test($('#ilosc_dokumentow').val()) ) {
    errors += "Ilość dokumentów powinna być liczbą!\n";
  }
  if( !email_pattern.test($('#email').val()) ) {
    errors += "Niepoprawny adres e-mail!\n";
  }
  if( errors != '' ) {
    alert( errors + "\nProsimy o poprawienie błędów." )
    return false;
  } else {
    return true;
  }
}


