$(document).ready(function(){

$(".nav03 li").mouseout( function(){
  if($.browser.msie)
    $(".prodBox1").css("visibility", "visible");
});


$(".nav03 li").mouseover( function(){
  if($.browser.msie)
    $(".prodBox1").css("visibility", "hidden");
});

$("a.koszyk_ajax").click(function(){
  idtowaru = $(this).attr("href");
  idtowaru = idtowaru.substr(18,8);

  var offset = $(this).offset();
  $("#info").css({ position: "absolute", top: offset.top-80, left: offset.left+30 });
  $("#info").show();
  
  $.post( "/ajax.php", {C:"KOSZ",xml:"T",P:idtowaru}, function( xml ){
    $("#gora").html( $("gora", xml).text() );
    $("#info").html( $("info", xml).text() );

    $("#info").css({ position: "absolute", top: offset.top-80, left: offset.left+30 });
//    $("#info").css({ position: "fixed" });
    $("#info").show();
    ukryj=document.getElementById("info");
    var t=setTimeout('ukryj.style.display="none"',7000);

  });

  return false;
//zawsze na końcu
});

$("#news").click(function(){

//var strPost = $("#news_form").serialize();
      wartosc = $("input:checked[@name=reg]").val();
//      alert(wartosc);
//      alert(email);
//      alert(strPost);



      if( $("#email_first").val().search( /@/ ) == -1 ){
        alert("Email is not valid");
      } else {

        if( wartosc == 'yes' ) {
          $("a").attr("href",'/x_C_X__P_NEWSLETTER_SUBMIT__email_'+$("#email_first").val()+'.html');
        } else {
          $("a").attr("href",'javascript:document.news.submit();');
        }

        if( $("#news_email").val().search( /@/ ) == -1 ){
          $("#alert_email").attr("style", 'color: red; display: block;');
          }
      }
   
});

$("#news_submit").click(function(){

      if( $("#news_email").val().search( /@/ ) == -1 ){
        $("#email_alert").attr("style", 'color: red; display: block;');
      } else {
        $("#email_alert").attr("style", 'color: red; display: none;');
      }

      if ($("#agreement").attr("checked")) { $("#1_alert").attr("style", 'color: red; display: none;'); } else { $("#1_alert").attr("style", 'color: red; display: block;');}
      if ($("#agreement2").attr("checked")) { $("#2_alert").attr("style", 'color: red; display: none;'); } else { $("#2_alert").attr("style", 'color: red; display: block;');}

      if ($("#agreement").attr("checked")) {
        if ($("#agreement2").attr("checked")) {
          if( $("#news_email").val().search( /@/ ) != -1 ){
            $("a").attr("href",'javascript:document.news2.submit();');
          }
        }
      }

});

//formularz kontaktowy z validacją -> promocje.ini obszar KONTAKT
$("#contact_submit").click(function(){

if(sprawdz() != false) {

 $.post( 'form.php', {
   klucz : $("#contact_klucz").val(),
   temat : $("#contact_temat").val(),
   mailto : $("#contact_mailto").val(),  
   email : $("#contact_email").val(),
   imie : $("#contact_imie").val(),
   nazwisko : $("#contact_nazwisko").val(),
   firma : $("#contact_firma").val(),
   ulica : $("#contact_ulica").val(),
   miasto : $("#contact_miasto").val(),
   telefon : $("#contact_phone").val(),
   tresc : $("#contact_mes").val()
 }, function() {
   $("#contact").html( 'Thank you for sending your question!' );
 });
 };
 return false;
});

//formularz do recenzji -> promocje.ini obszar RECENZJE_DODAJ
$("#recenzje_dodaj").click(function(){
  
  $.post( 'pz.php', {
    emailfrom : $("#recenzje_emailfrom").val(),
    tresc : $("#recenzje_tresc").val(),
    jezyk : $("#recenzje_jezyk").val(),
    wyslij : $("#recenzje_wyslij").val()
  }, function() {
    $("#recenzje_content").html( 'Thank you for your testimonial!' );
  });
  return false;
});

//formularz do pytania o produkt -> wynik.ini
$("#product_query").click(function(){
  
  if( $("#product_query_email").val().search( /@/ ) == -1 ){
    alert('There is not valid e-mail');
  } else {

  $.post( 'form.php', {
    klucz : $("#product_query_klucz").val(),
    temat : $("#product_query_temat").val(),
    mailto: $("#product_query_mailto").val(),
    tresc : $("#product_query_tresc").val(),
    email : $("#product_query_email").val(),
    towar : $("#product_query_towar").val(),
    kod : $("#product_query_kod").val()
  }, function() {
    $("#product_query_div").html( 'Thanks for question. We answer you on Your e-mail.' );
  });
  }
  return false;
});

//formularz opini do sklepu -> 21_opinia.html
$("#commentsbutton").click(function(){
  
  $.post( 'form.php', {
    klucz : $("#opinions_comment_klucz").val(),
    temat : $("#opinions_comment_temat").val(),
    mailto: $("#opinions_comment_mailto").val(),
    tresc : $("#opinions_comment_content").val()
  }, function() {
    $("#opinions_comment_content_span").html( 'Thank you for your opinion.' );
  });
  return false;
});

$("input.radio_sd").click(function(){
  $("#form_sdid_sdid").val( $(this).val() );
  $("#form_sdid_Uwagi").val( $("#Uwagi").text() );
  $("#form_sdid").submit();
});

//Nazwa=.{2,255}
//Miejscowosc=.{2,255}
//KodPocztowy=.{5,6}
//Telefon=.{7,255}
//Email=@

$("#rej_dane_submit").click(function(){
//  alert( 'xxx' );
//        <input id="rej_dane_Nazwisko" name="Nazwisko" value="{@Nazwisko}" onfocus="this.select()" type="text" />
//        <input id="rej_dane_Ulica" name="Ulica" value="{@Ulica}" onfocus="this.select()" type="text" />
//        <input id="rej_dane_KodPocztowy" name="KodPocztowy" value="{@KodPocztowy}" onfocus="this.select()" class="code" type="text" />
//        <input id="rej_dane_Miejscowosc" name="Miejscowosc" value="{@Miejscowosc}" onfocus="this.select()" class="city" type="text" />
//        <input id="rej_dane_Telefon" name="Telefon" value="{@Telefon}" onfocus="this.select()" type="text" />
//        <select id="rej_dane_Kraj" name="IdKraju" size="1" style="width: 200px;"><option value="">-- wybierz --</option>{%~KRAJ2~IdKraju}</select>
//        <input id="rej_dane_Email" name="Email" value="{@Email}" onfocus="this.select()" type="text" />


  if( $("#rej_dane_Nazwisko").val().search( /.{2}/ ) == -1 ){ 
    alert( 'Enter your surname' );
  }else{
    if( $("#rej_dane_Miejscowosc").val().search( /.{2}/ ) == -1 ){
      alert( 'Enter your city' );
    }else{
      if( $("#rej_dane_NrDomu").val() == '' ){
        alert( 'Enter your building no' );
      }else{
        if( $("#rej_dane_Ulica").val() == '' ){
          alert( 'Enter your street' );
        }else{
            if( $("#rej_dane_Telefon").val().search( /.{7}/ ) == -1 ){
              alert( 'Enter your phone' );
            }else{ 
              if( $("#rej_dane_Email").val().search( /@/ ) == -1 ){
                alert( 'Enter your email' );
              }else{ 
                if( $("#rej_dane_Kraj").val() == 0 ){
                  alert( 'Enter your country' );
                }else{
//              alert( 'yyy' );
                  $("#rej_dane").submit(); 
                }
              }
            }
          }
        }
      }
    }
  return false;
});

//zawsze na końcu
});
