// JavaScript Document
function search(){

  if(a = $('loginPass')){
    Event.observe($('loginPass'), 'focus', function(){
      if(this.value == "Heslo"){
        this.type = 'password';
        this.style.color='#000000';
        this.value = '';
        $('loginPass').focus();
      }
    });
    Event.observe($('loginPass'), 'blur', function(){
      if(this.value == ''){
        this.value = 'Heslo';
        this.type = 'text';
        this.style.color='#999999';
      }
    });
  }

}
Event.observe(window, 'load', function(){
  search();
  if($('loginPass')){
    if($('loginPass').value==''){
      $('loginPass').style.color='#999999';
      $('loginPass').value = 'Heslo';
      if(!Prototype.Browser.IE)$('loginPass').type = 'text';
    }
  }
  FormDefaultValue.add('loginName', 'Jméno', '#999999', '#000000');
  FormDefaultValue.add('searchText', 'Hledat...', '#E1E1E1', '#ffffff');
  
  FormDefaultValue.add('poznamkaSamolepkyV', 'Zde uvědte text, který chcete u samolepky mít nebo dotazy k objednávce.', '#999999', '#000000');
  //FormDefaultValue.add('poznamkaMagn', 'Zde uvědte text, který chcete u magnetky mít nebo dotazy k objednávce.', '#999999', '#000000');
  FormDefaultValue.add('poznamkaPlak', 'Zde uvědte text, který chcete u plakátu mít nebo dotazy k objednávce.', '#999999', '#000000');
  FormDefaultValue.add('poznamkaObr', 'Zde uvědte text, který chcete u obrazu mít nebo dotazy k objednávce.', '#999999', '#000000');
  
  FormDefaultValue.init();
  
});

Lupa = {
  findPosX : function(obj){
    var curleft = 0;
    if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
    else if(obj.x)
      curleft += obj.x;
    return curleft;
  },
  
  findPosY: function(obj){
    var curtop = 0;
    if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
    else if(obj.y)
      curtop += obj.y;
    return curtop;
  },
  
  show: function(id, img, width, height) {
  	obj=$('imgZbo'+id);
  		
    obr=$('lupa');
  	obrdiv=$('lupadiv');
  	obr.src = 'img/wait.gif';
  	
  	posx=this.findPosX(obj);
    posy=this.findPosY(obj);
    
    obrdiv.style.background='#ffffff';
    obrdiv.style.width=width+'px';
  	obrdiv.style.height=height+'px';
    
  	obr.src = 'img/zbozi/'+img;
  	
  	obrdiv.style.left=(posx-Math.round(width/2))+'px';
  	obrdiv.style.top=(posy-height+80)+'px';
  	
  	//obrdiv.appear({ duration: 1.0 });
  	obrdiv.show();
  },
  
  hide: function(){
    $('lupadiv').hide();
  }
}


function changeOrder(a){
  $('katalog_order').value = a;
  $('katalog_order').parentNode.parentNode.submit();
}

function changeLimit(a){
  $('katalog_limit').value = a;
  $('katalog_limit').parentNode.parentNode.submit();
}

var LoadingImg = {
  getPageSize: function() {
	        
	  var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	},
	
	st: function(obj){
    var arrayPageSize = this.getPageSize();
    $('loading').setStyle({
      'position': 'absolute',
      'top': '0px',
      'left': '0px',
      'width': arrayPageSize[0] + 'px',
      'height': arrayPageSize[1] + 'px',
      'background': 'black',
      'opacity': '0.8',
      'z-index': '30'
    });
    
    if(!Prototype.Browser.IE){
      obj.hide();
    }
    
    var arrayPageScroll = document.viewport.getScrollOffsets();
    var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
    var lightboxLeft = document.viewport.getWidth()/2-150;
    if(Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){
      lightboxLeft = $('loading').getHeight()/2
    }
    $('loadingImg').setStyle({ 
      'position': 'absolute',
      top: lightboxTop + 'px',
      left: lightboxLeft + 'px',
      'opacity': '0.8'
    });
    $('loadingText').setStyle({ 
      'position': 'absolute',
      top: (lightboxTop+190) + 'px',
      left: (lightboxLeft+160) + 'px',
      'opacity': '0.8'
    });
    if(Prototype.Browser.IE){
      $('loadingImg').src = 'img/wait.gif';
    }
    
    $('loading').show();
    
  }
}

FormDefaultValue = {
  items: new Array(),
  add: function(id, value, colorDefault, color){
    if($(id)){
      
      FormDefaultValue.items[FormDefaultValue.items.length] = new Array(id, value, colorDefault, color);
    
      Event.observe($(id), 'focus', function(){
      if(this.value == value){
        this.value = '';
        this.style.color=color;
      }
      });
      Event.observe($(id), 'blur', function(){
        if(this.value == ''){
          this.value = value;
          this.style.color=colorDefault;
        }
      });
    }
  },
  init: function(){
    for(i=0;i<FormDefaultValue.items.length;i++){
      if($(FormDefaultValue.items[i][0]).value==FormDefaultValue.items[i][1])
        $(FormDefaultValue.items[i][0]).style.color=FormDefaultValue.items[i][2];
      
      if($(FormDefaultValue.items[i][0]).value==''){
        $(FormDefaultValue.items[i][0]).value = FormDefaultValue.items[i][1];
        $(FormDefaultValue.items[i][0]).style.color=FormDefaultValue.items[i][2];
      }
    }
  }
}




