
// --------- JQUERY  ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------
var mY, mX;

  function WD(nID, sCode, nPrice, sName, sLink, chbStore)
  {
    $('#haf, #askseller').css('display', 'block');
    $('#wdname, #asname').html(sName);
    $('#wdprice, #asprice').val(nPrice);
    
    $('#nID, #nID1').val(nID);
    $('#nPrice, #nPrice1').val(nPrice);
    $('#sCode, #sCode1').val(sCode);
    $('#sName, #sName1').val(sName);
    
    if(chbStore == 0){$('#wdchbstore').css('display','none');} 
  }
  
  function WD1(nID, sCode, nPrice, sName, sLink, chbStore)
  {
  
    //alert('xx')
    //$('.tabsproduct', top.document).css('background-color', 'yellow');
    
    //parent.getElementById("tabdata_1").style.display = 'none';
    
  }
  
  function WD2(nID, sCode, nPrice, sName, sLink, chbStore)
  {
    $('#haf, #askseller', window.parent.document).css('display', 'block');
    $('#wdname, #asname', window.parent.document).html(sName);
    $('#wdprice, #asprice', window.parent.document).val(nPrice);
    
    $('#nID, #nID1', window.parent.document).val(nID);
    $('#nPrice, #nPrice1', window.parent.document).val(nPrice);
    $('#sCode, #sCode1', window.parent.document).val(sCode);
    $('#sName, #sName1', window.parent.document).val(sName);
    
    if(chbStore == 0){$('#wdchbstore', window.parent.document).css('display','none');} 
  }
  
$(document).ready(function() 
{
  
  $('#fadata').click(function(){
    if(!$('#fadata').attr('checked'))
    {
      $('#faosobniodber').css({'display':'none'})
    }
    else
    {
      $('#faosobniodber').css({'display':'block'})
    }
  })
  
  $('#wdCancel').click(function(){ $('#haf').css('display', 'none'); })
  $('#asCancel').click(function(){ $('#askseller').css('display', 'none'); })
  $('#wdSubmit').click(function(){
  
    $('#haf').css({'display': 'block'});
    if($('#wdinputemail').val() != '')
    {         
      var url = "http://www.huramobil.cz/ajxWatchDog.asp?email=" + $('#wdinputemail').val() + '&';
      url+= "nID=" + $('#nID').val() + "&sCode=" + $('#sCode').val() + "&sName=" + $('#sName').val() + "&nBorderPrice=" + $('#wdprice').val();
      url+= "&chbstore=" + ($('#chbstore').attr('checked') ? "1" : "0")+ "&chbprice=" + ($('#chbprice').attr('checked') ? "1" : "0")+ "";
      
      if(!$('#chbstore').attr('checked') && !$('#chbprice').attr('checked'))
      {
        alert('Nemáte vybráno, co má hlídací pes hlídat!');
      }
      else
      {
        //alert(url)
        
        $.ajax({
          url: url,
          type: 'GET',
          timeout: 3000,
          beforeSend: function( xhr ) {
            $('#wdreturn').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
          },
          error: function(){
            $('#wdreturn').html( 'Chyba.' );
          },
          success: function(html){
            $('#wdreturn').css({'display': 'block'})
            $('#wdbtns').css({'display': 'none'})
            $('#wdreturn').html(html)
            
            $('#haf').delay(4000).fadeOut( 3000 );
          }
      });
      
      }
    }
    else
    {
      alert('Vyplňte Váš e-mail!')
    }
  });
  
  $('#asSubmit').click(function(){
  
    $('#haf').css({'display': 'block'});
    if($('#asinputemail').val() != '')
    {         
      var url = "/ajxAskSeller.asp";
      
      if($('#asktxtarea').val()=='')
      {
        alert('Vyplňte Váš dotaz!');
      }
      else
      {
        //alert(url)
        
        $.ajax({
          url: url,
          type: 'POST',
          data: {
                  'email' : $('#asinputemail').val(), 
                  'txt' : $('#asktxtarea').val(),
                  'name' : $('#sName1').val(),
                  'code' : $('#sCode1').val()
                },
          timeout: 3000,
          beforeSend: function( xhr ) {
            $('#asreturn').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
          },
          error: function(){
            $('#asreturn').html( 'Chyba.' );
          },
          success: function(html){
            $('#asreturn').css({'display': 'block'})
            $('#asbtns').css({'display': 'none'})
            $('#asreturn').html(html)
            
            $('#haf').delay(4000).fadeOut( 3000 );
          }
      });
      
      }
    }
    else
    {
      alert('Vyplňte Váš e-mail!')
    }
  });
  
  $('#mainimg').click(function(){ self.close();});
  $('.addmidimg').click(function(){
    var src = $(this).children('img').attr('src').replace('/addmid', '/addbig');
    $('#mainimg').children('img').attr('src', src);
  });
  
  $('.mainmidimg').click(function(){
    var src = $(this).children('img').attr('src').replace('/mid', '/bigorig');
    $('#mainimg').children('img').attr('src', src);
  });
  
  
  $('.winMainImage').click(function(){
  
    var strURL = $(this).attr('rel');
    var nWidthScreen = screen.width;
    var nHeightScreen = screen.height;
     
    var nWidthWindow = nWidthScreen * 0.7;
    var nHeightWindow = nHeightScreen * 0.9;

    var l = (nWidthScreen/2)-(nWidthWindow/2);
     
    var d = (strURL.indexOf('?')>-1 ? '&d=' + (new Date).getTime() : '?d=' + (new Date).getTime());
  	var objWnd = window.open(strURL+d,"InfoDetail","scrollbars=yes,height="+nHeightWindow+",width="+nWidthWindow+",left="+l+",top=10");
  	objWnd.focus();
  });
  
   $(document).mousemove(function(e){
      mY = e.pageY; mX = e.pageX;
   });
  
  $('#emailfirst').blur(function(){
    if($(this).val().length>6)
    {
      var email = $(this).val();
      pos   = $(this).offset();
      var url = '/ajxDataByEmail.asp?email='+email+"&d="+(new Date).getTime();
       
      var top = (pos.top + 25) + 'px';
      
      $('#divDataByEmail').css({'top': top})
      
      $.ajax({
          url: url,
          type: 'GET',
          timeout: 3000,
          beforeSend: function( xhr ) {
            $('#divDataByEmail').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
          },
          error: function(){
            $('#divDataByEmail').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator"><br/><br/>Nepodařilo se najít data.' );
          },
          success: function(html){
            //alert(html)
            if(html=="[OK]")
            {
              
              $('#divDataByEmail').css({'display': 'block'})
              $('#divDataByEmail').html(
                "<div style='text-align:right; color: #fff; cursor:pointer; padding:0 5px 0 0;' onclick=\"document.getElementById('divDataByEmail').style.display='none'\">X zavřít</div>" +
                "<div style='padding:5px; color: yellow;'>Data pro tento e-mail byla nalezena, k jejích načtení potřebujeme heslo, které jste získal(a) v předchozím nákupu.</div>" +
                "<div class='padding:5px;'>"+
                " <form>"+
                "   Heslo: <input type='password' name='password' id='dataPswd'/>"+
                "   <input type='hidden' name='email' value='"+email+"' id='dataEmail'/>&nbsp;"+
                "   <input type='button' name='btnSendPswd' value='Přihlásit' id='dataSendPswd'/>"+
                " </form>"+
                " <div style='padding:3px;' id='divForgot'><a id='aSendForgot' style='color:#fff;' href='javasctipt:void()'>Na uvedený e-mail Vám můžeme zaslat zapomenuté heslo.</a></div>"+
                "</div>"
              
              )
            }
            if(html.indexOf("[KO]")>-1)
            {
              $('#divDataByEmail').css({'display': 'block', height:'50px'})
              $('#divDataByEmail').html( '<br/><br/>Klient s tímto e-mailem neexistuje.' );
              
              $('#email').val($('#emailfirst').val())
              
              $('#divDataByEmail').fadeOut(10000);
            }
          }
      });
    }
  });
    
  $('#aSendForgot').live('click', function(){
    var url = '/ajxLostPass.asp?email='+$('#emailfirst').val();
    
    $("#divForgot").html('<br/>Heslo bylo odesláno na Váš e-mail: '+$('#emailfirst').val())
    
    //alert(url);
    
    /*$("#divForgot").load(url, function(response, status, xhr) {
      if (status == "error") {
        var msg = "Sorry but there was an error: ";
        $("#divForgot").html(msg + xhr.status + " " + xhr.statusText);
      }
      else
      {
        alert(response)
      }
    });*/

    $.ajax({
          url: url,
          type: 'GET',
          timeout: 3000,
          beforeSend: function( xhr ) {
            $('#divForgot').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
          },
          error: function(){
            $('#divForgot').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator"><br/><br/>Nepodařilo se najít data.' );
          },
          success: function(html){
            $('#divForgot').html(html);
            
          }
      }); 
  });
  
  $('#dataSendPswd').live('click', function(){
    if($('#dataPswd').val().length>0)
    {
    
      var url = '/ajxDataByEmail.asp?email='+$('#dataEmail').val()+ '&psw=' + $('#dataPswd').val();
      //alert(url)
      $.ajax({
          url: url,
          type: 'GET',
          timeout: 3000,
          beforeSend: function( xhr ) {
            $('#divDataByEmail').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
          },
          error: function(){
            $('#divDataByEmail').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator"><br/><br/>Nepodařilo se najít data. Pozměňte dotaz nebo klikněte na Hledej a dostanete výsledky fulltextového hledání.' );
          },
          success: function(html){
            //alert(html)
            if(html.indexOf("[OK]")==0)
            {
              var arr = html.split('|');
              $('#firm').val(arr[1]);
              $('#firstname').val(arr[2]);
              $('#lastname').val(arr[3]);
              $('#city').val(arr[4]);
              $('#zipcode').val(arr[5]);
              $('#street').val(arr[6]);

              $('#deliveryfirm').val(arr[7]);
              $('#deliveryfirstname').val(arr[8]);
              $('#deliverylastname').val(arr[9]);
              $('#deliverycity').val(arr[10]);
              $('#deliveryzipcode').val(arr[11]);
              $('#deliverystreet').val(arr[12]);
              
              $('#phone').val(arr[13]);
              $('#ico').val(arr[14]);
              $('#dic').val(arr[15]);
              $('#news').checked = (arr[16] == 'True' ? true : false);
              
              $('#password').val($('#dataPswd').val());
              $('#passwordagain').val($('#dataPswd').val());
              
              $('#bankaccount').val(arr[17]);
              $('#bankcode').val(arr[18]);
              $('#spec').val(arr[19]);

              $('#divDataByEmail').css({'display': 'none'})
              $('#label_big_pswinfo').css({'display': 'none'});
              
              $('#email').val($('#emailfirst').val())
              
              $('#label_passwordX').css({'display':'none'});
              $('#input_passwordX').css({'display':'none'});
              $('#required_passwordX').css({'display':'none'});
            
              $('#label_passwordagainX').css({'display':'none'});
              $('#input_passwordagainX').css({'display':'none'});
              $('#required_passwordagainX').css({'display':'none'});
              
              location.reload();
              
            }
            if(html=="[KO]")
            {
              $('#divDataByEmail').css({'display': 'block'})
              $('#divDataByEmail').html( '<br/><br/>Klient s tímto e-mailem a heslem neexistuje.' );
            }
          }
      });
    }
    else
    {
      alert('Nevložil(a) jste heslo!');
    }
  });
  
  $('.pswinfo').click(function(){
    
    $('#label_passwordX').css({'display':'block'});
    $('#input_passwordX').css({'display':'block'});
    $('#required_passwordX').css({'display':'block'});

    $('#label_passwordagainX').css({'display':'block'});
    $('#input_passwordagainX').css({'display':'block'});
    $('#required_passwordagainX').css({'display':'block'});
  });
  
  var search_timeout = 200;
  var data = '';
  var bSuccess = false;
  //------------MY AUTOCOMPLETE--------------------------------------------------------------------------------
  $("#EXPS").bind('keypress', function() 
  {
  
    if(search_timeout != undefined) {
            clearTimeout(search_timeout);
    }
    
    
    search_timeout = setTimeout(function() 
    {
      
      search_timeout = undefined;
            
      if($("#EXPS").val().length > 1)
      {
        
        var url = '/ajxWhisper.asp?exps='+$("#EXPS").val();
              
        $.ajax({
            url: url,
            type: 'GET',
            timeout: 3000,
            beforeSend: function( xhr ) {
              $('#divwhisper').html( '<img class="ind" src="/Script_new/jquery-autocomplete/demo/indicator.gif" alt="indicator">' );
            },
            error: function(){
              $('#divwhisper').html( '<br/><br/><div style="text-align:center; padding:0 40px; ">Přímý produkt nenalezen. Pokračujte kliknutím na tlačitko Hledej k výsledkům fulltextového hledání.</div>' );
            },
            success: function(html){
              //alert(html)
              if(html!='')
              {
                $('#divwhisper').css({'display': 'block'})
                $('#divwhisper').html(html)
              }
              else
              {
                $('#divwhisper').html( '<br/><br/><div style="text-align:center; padding:0 40px; font-weight: bold; ">Přímý produkt nenalezen. Pokračujte kliknutím na tlačitko Hledej k výsledkům fulltextového hledání.</div>' );
              }
            }
        });
      }   
    
    }, 700);
         
  });
  //------------------------------------------------------------------------------------------------
  /*$("#EXPSXXXX").bind('keypress', function() 
  {
    if(search_timeout != undefined) {
            clearTimeout(search_timeout);
    }
    //var $this = this; // save reference to 'this' so we can use it in timeout function
    search_timeout = setTimeout(function() {
            search_timeout = undefined;

            var url = 'http://www.huramobil.cz/ajxWhisper.asp?exps='+$("#EXPS").val();
                  
            $.ajax({
                url: url,
                type: 'GET',
                timeout: 3000,
                error: function(){
                    //alert('Error loading document\n' + url);
                    bSuccess = false;
                    data = '';
                },
                success: function(html){
                  //alert(html)
                  data = html.split(';');
                  bSuccess = true;
                }
            });
            
            $("#EXPS").autocomplete(data, {
          		matchContains: true,
          		minChars: 2
          	});
          	
    }, 100);
  });
  
  $("#EXPSSSSSSSSSS").autocomplete('http://www.huramobil.cz/ajxWhisper.asp?exps=', {
		matchContains: true,
		minChars: 2
	});
          
  $("#EXPSSSSS").keydown( function() 
  {

    var url = 'http://www.huramobil.cz/ajxWhisper.asp?exps='+$(this).val();
          
    $.ajax({
        url: url,
        type: 'GET',
        timeout: 3000,
        error: function(){
            alert('Error loading document\n' + url);
        },
        success: function(html){
          //alert(html)

          var html = html.split(';');
          $("#EXPS").autocomplete(html, {
        		matchContains: true,
        		minChars: 2
        	});
        }
    });
      
    
  });
  
  function ajax_delay(str){
    setTimeout("str", 1000);
  }

  //$("#EXPS").focus().autocomplete('http://www.huramobil.cz/ajxWhisper.asp?exps='+$(this).val());
  
  $("#EXPSSSS").change( function() {
    $('body').append("<div id='whisper' class='whisper'>&nbsp;</div>");
    $('#whisper').css({'display':'block', top: (mY)+'px', left: (mX)+'px'});//.load(url);
  });*/

  $('.cont').click(function () {
      $('.contacts').css({'display' : 'block'});
  });
  
  $('.news').click(function () {
      $('.newsletter').css({'display' : 'block'});
  });
  
  $('.aLogin').click(function () {
      $('#LoginForm').css({'display' : 'block'});
  });
    

  $('.zoomD' ).click(function(){
  
    var nID = $(this).attr('id').replace('moreimgs_', '');
    $('.tabdata').css({'display':'none'});
    
    $('#tabdata_' + nID).css({'display':'block'});
    $('.aOneTabsel').removeClass('aOneTabsel').addClass('aOneTab');
    $('#tab_' + nID).removeClass('aOneTab').addClass('aOneTabsel');
    
    $('.tabcentersel').removeClass('tabcentersel').addClass('tabcenter');
    $('.tableftsel').removeClass('tableftsel').addClass('tableft');
    $('.tabrightsel').removeClass('tabrightsel').addClass('tabright');
    $('#tabc_' + nID).removeClass('tabcenter').addClass('tabcentersel');
    $('#tabl_' + nID).removeClass('tableft').addClass('tableftsel');
    $('#tabr_' + nID).removeClass('tabright').addClass('tabrightsel');
  });
  
  $('.aOneTab, .aOneTabsel, #moreimgs' ).click(function(){
  
    var nID = $(this).attr('id').replace('tab_', '');
    $('.tabdata').css({'display':'none'});
    
    $('#tabdata_' + nID).css({'display':'block'});
    $('.aOneTabsel').removeClass('aOneTabsel').addClass('aOneTab');
    $('#tab_' + nID).removeClass('aOneTab').addClass('aOneTabsel');
    
    $('.tabcentersel').removeClass('tabcentersel').addClass('tabcenter');
    $('.tableftsel').removeClass('tableftsel').addClass('tableft');
    $('.tabrightsel').removeClass('tabrightsel').addClass('tabright');
    $('#tabc_' + nID).removeClass('tabcenter').addClass('tabcentersel');
    $('#tabl_' + nID).removeClass('tableft').addClass('tableftsel');
    $('#tabr_' + nID).removeClass('tabright').addClass('tabrightsel');
  });
  
  $('.product').mouseleave(function(){
    $('#floatavail').fadeOut(2000, function(){$('#floatavail').remove();})
  });
  
  $('a.ajxOnlineAvail').click(function(){
    var code = $(this).attr('id');
    var url = 'http://www.huramobil.cz/ajxOnlineAvail_DEV.asp?sCode='+code+'&t=0';
    $('body').append("<div id='floatavail' class='floatAvail'>&nbsp;</div>");
    $('#floatavail').css({'display':'block', top: (mY-130)+'px', left: (mX-225)+'px'}).load(url);

  });

   /*
   $('a.ajxOnlineAvail[id]').each(function()
   {
      var code = $(this).attr('id');
      $(this).qtip({
         content: {url:'http://www.huramobil.cz/ajxOnlineAvail_DEV.asp?sCode='+code+'&t=0'},//$(this).attr('tooltip'), 
         position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }},
         style: {
            border: {
               color:'#000',
               width: 1,
               radius: 3
            },
            width:550,
            background:'#FAFAED',
            color:'#000',
            padding: 10, 
            textAlign: 'center',
            tip: true
          }
      });
   });
   */
});
