jQuery(document).ready(function(){


 $('#myForm').ajaxForm( { beforeSubmit: validate } );
 
 
 
 function wycz()
 {
   $('input[name=imie]').removeClass("in_red");
   $('input[name=firma]').removeClass("in_red");
   $('input[name=adres]').removeClass("in_red");
   $('input[name=nip]').removeClass("in_red");
   $('input[name=telefon]').removeClass("in_red");
 }
 
 
       function validate(formData, jqForm, options) {
       wycz();
    // fieldValue is a Form Plugin method that can be invoked to find the
    // current value of a field
    //
    // To validate, we can capture the values of both the username and password
    // fields and return true only if both evaluate to true

    var imieValue = $('input[name=imie]').fieldValue();
    var firmaValue = $('input[name=firma]').fieldValue();
    var adresValue = $('input[name=adres]').fieldValue();
    var nipValue = $('input[name=nip]').fieldValue();
    var telValue = $('input[name=telefon]').fieldValue();
    
    var mess="";
    var ok = true;

    // usernameValue and passwordValue are arrays but we can do simple
    // "not" tests to see if the arrays are empty
    if (!imieValue[0]) {mess +="\n\nImie"; ok = false;$('input[name=imie]').addClass("in_red");}
    if (!firmaValue[0]) {mess +="\nNazwa firmy"; ok = false;$('input[name=firma]').addClass("in_red");}
    if (!adresValue[0]) {mess +="\nAdres "; ok = false;$('input[name=adres]').addClass("in_red");}
    if (!nipValue[0]) {mess +="\nNIP "; ok = false;$('input[name=nip]').addClass("in_red");}
    if (!telValue[0]) {mess +="\nTelefon "; ok = false;$('input[name=telefon]').addClass("in_red");}


        if(!ok){
        alert('Podaj dane:'+mess);
        return false;
        }
        return true;
    }




      jQuery("#wyslij").bind("click", function() {


          if(validate()){

           var p1 = $("#imie").val();
           var p2 = $("#firma").val();
           var p3 = $("#adres").val();
           var p4 = $("#nip").val();
           var p5 = $("#telefon").val();
             var ile1 = $("#ilosc1").val();
      var ile2 = $("#ilosc2").val();
      var ile3 = $("#ilosc3").val();
      var ile4 = $("#ilosc4").val();

           $.post('a/message.php', {"p1":p1,"p2":p2,"p3":p3,"p4":p4, "p5":p5,"ilosc1":ile1,"ilosc2":ile2,"ilosc3":ile3,"ilosc4":ile4  }, function(data){
     alert(""+ data);
   });
        $("#go_home").show();
           }
      
      });

      jQuery("#przelicz").bind("click", function() {
      
      $.ajaxSetup({cache: false});
      
      var ile1 = $("#ilosc1").val();
      var ile2 = $("#ilosc2").val();
      var ile3 = $("#ilosc3").val();
      var ile4 = $("#ilosc4").val();
          $.getJSON('a/', {"ilosc1":ile1,"ilosc2":ile2,"ilosc3":ile3,"ilosc4":ile4 },function(data){
          
          
          
     $("#ilosc1a").val(data.n1);
     $("#ilosc1b").val(data.b1);
     
     
     $("#ilosc2a").val(data.n2);
     $("#ilosc2b").val(data.b2);
     
     $("#ilosc3a").val(data.n3);
     $("#ilosc3b").val(data.b3);
     
     $("#ilosc4a").val(data.n4);
     $("#ilosc4b").val(data.b4);
     
      $("#s0").val(data.s0);
     $("#s1").val(data.s1);
      $("#s2").val(data.s2);

     
   });
          


      });

   $('.in_rej').focus(function() {
$(this).removeClass();
$(this).addClass('in_rej_on');
});

 $('.in_rej').blur(function() {
$(this).removeClass();
$(this).addClass('in_rej');
});


  jQuery("#to-top").bind("click", function() {
                     jQuery('html,body').animate({scrollTop: jQuery("body").offset().top}, 500);
                      return false;
     });

   jQuery("#ashow-more").bind("click", function() {
                     jQuery('#show-more').show('slow');
                      return false;
     });



         $(function() {
        $('.images').lightBox();
    });



             $(function() {
        $('.obrazek').lightBox();
    });


 });
 
 function res()
 {
  alert("");
 }




function on(co,styl)
{
var styl2=styl+'_on';
co.className=styl2;
}

function off(co,styl)
{
co.className=styl;
}

function poz(){
var divBe = document.getElementById("made");
divBe.innerHTML='Realizacja: www.Belart.pl';
}


function rollover(obj, img) {
        obj.src = 'i/' + img+'_on.gif';
}
function rollout(obj, img) {
        obj.src = 'i/' + img+'.gif';
}

function go(adres)
{
if(adres!=0){
location.href=adres;}
}

function menu_on(id)
{

nazwa='t'+id;
cel = document.getElementById(nazwa);

cel.className='typy_on';
}

function menu_off(id)
{
nazwa='t'+id;
cel = document.getElementById(nazwa);

cel.className='typy';
}

function zom(obr)
{

 cel=document.getElementById("cart_img_pro");
 cel.innerHTML='<img src="produkty/'+obr+'" >';
}



function showDiv(celW)
{
var stylW="faq_open";


var divW = document.getElementById(celW);


divW.className=stylW;


}

function closeDiv(celW)
{

var stylN="faq_close";

var divW = document.getElementById(celW);


divW.className=stylN;


}


