
document.onmousemove=function(e){GetXY(e);}


$(document).ready(function() {

    $('#worldwide').change(function() {
      window.location.href = $(this).val();
    });

    $('.prodejci').find('img').each(function(){
      $(this).hover(
        function () {
          $(this).attr('src',$(this).attr('rel2'));
        }, 
        function () {
          
          $(this).attr('src',$(this).attr('rel'));
          
        }
      );
      
    });


    // kotvy na detailu produktu
    $('.kotvy').find('img').each(function(){

      $(this).hover(
        function () {
          $(this).attr('src',$(this).attr('src').replace('.png','-a.png'));
        }, 
        function () {
          $(this).attr('src',$(this).attr('src').replace('-a.png','.png'));
        }
      );

    });

    // leve kategorie pozadi
    $('.category').find('li').each(function(){

      $(this).hover(
        function () {
          $(this).addClass('sel');
        }, 
        function () {
          $(this).removeClass('sel');
        }
      );

    });



    /*
    / odeslani emailu a dalsi formulare v detailu zbozi, provazani se zalozkama
    */
    
    $('.buttons').find('a').each(function(){
      
      $(this).click(function(){
         $('.bookmarks li').each(function(){
            $(this).removeClass('bm-active');
         });
         $.get('/detail.php'+$(this).attr('href')+'&j=1', function(data){
              $('#param-content').html(data);
         });
         return false;
      });
    });
    
    
    /*
    * pridani focus a blur na pole hledani
    */    
    $("#words").focus(function () {
      if ($(this).val() == 'Hledat...'){
        $(this).val('');
      }
    });
    $("#words").blur(function () {
      if ($(this).val() == ''){
        $(this).val('Hledat...');
      }
    });


    /*
    * pridani focus a blur na logovaci formular
    */    
    $("#logininput").focus(function () {
      if ($(this).val() == 'jméno'){
        $(this).val('');
      }
    });
    $("#logininput").blur(function () {
      if ($(this).val() == ''){
        $(this).val('jméno');
      }
    });
    

    /*
    * pridani focus a blur na logovaci formular
    */    
    $("#passwordinput").focus(function () {
      if ($(this).val() == 'heslo'){
        $(this).val('');
      }
    });
    $("#passwordinput").blur(function () {
      if ($(this).val() == ''){
        $(this).val('heslo');
      }
    });


    
        
});


/*
* kontrola formularu
*/
function ControlForm(form){
  var errorMessage = '';
  $('#'+form).find('input').each(function(){
    if ($(this).attr('mandatory') > ''){
      if (($(this).attr('type') == 'text')||($(this).attr('type') == 'password')){
        if ($(this).val() == ''){
          if ($(this).attr('name').search('mail') != -1){
            if(!EmailControl($(this).val())){
              errorMessage = errorMessage + $(this).attr('mandatory');
            }
          }else{
              errorMessage = errorMessage + $(this).attr('mandatory');
          }
        } 
      }else if ($(this).attr('type') == 'checkbox'){
        if (!$(this).is(':checked')){
          errorMessage = errorMessage + $(this).attr('mandatory');
        } 
      }  
    }
  });
  
  if (errorMessage > ''){
    alert(errorMessage);
    return false;
  }else{
    return true;
  }
}


function EmailControl(f){
    if ((f=='' || f=='vas@email.cz') || f.indexOf('..') != -1 || f.indexOf('.@') != -1 || f.indexOf('@.') != -1 || (f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
       return false;
      }
    if ((f.indexOf('ř') > -1) || (f.indexOf('ě') > -1) || (f.indexOf('š') > -1) || (f.indexOf('č') > -1) || (f.indexOf('ž') > -1) || (f.indexOf('ý') > -1) || (f.indexOf('á') > -1) || (f.indexOf('í') > -1) || (f.indexOf('é') > -1) || (f.indexOf('ů') > -1) || (f.indexOf('ú') > -1)){
       return false;
    }
    return true;
}

function DelCountBasket(ID){
  document[ID].count.value = 0;
  document[ID].submit();
}

function printDetail(url){
  window.open(url);
  //alert(url);
}

function ControlNumber(){
     if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}

function GetXY(e){
	var ie = navigator.appName == "Microsoft Internet Explorer";
	M_x = ie?window.event.clientX:e.clientX;
	M_y = ie?window.event.clientY:e.clientY;
}
function ShowBox(id){
	var temx=M_x;
	var temy=M_y+document.documentElement.scrollTop;;
	obj=$('#ShowBoxContent');
	if(temx+320>window.screen.width){temx=temx-310;}else{temx+=20;}
	if(temy+240>document.documentElement.offsetHeight){temy=temy-230}else{temy+=20;}
	$('#ShowBoxContent').css('left',temx+'px');
	$('#ShowBoxContent').css('top',temy+'px');
}
function GetShowInfo(id){
	$('#ShowBoxContent').html("<img src='/img/loader.gif' id='load' border='0' />");
  $.get('/jquery/info.php?id='+id, function(data){
    $('#ShowBoxContent').html(data);
    
  });
  $('#ShowBoxContent').css('display','block');
}
function HideBox(){
  $('#ShowBoxContent').css('display','none');
  $('#ShowBoxContent').html('');
}

