/**
 * $Rev$
 * 
 */

// detekce IE kvuli opravam chyb v IE
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

var IEversion =  getInternetExplorerVersion();
var isIE = IEversion != -1 ? true : false;

// fix pro IE7 a starsi, ktery stale pouziva javascript 1.5 z roku 2000
if(!Array.indexOf){
  Array.prototype.indexOf = function(obj){
      for(var i=0; i<this.length; i++){
          if(this[i]==obj){
              return i;
          }
      }
      return -1;
  }
}


// objekt pro vyhledavani

function findItemsInStore() {
   this.cfg = {
        callbackObject : false,
        imgLoading  : false,
        queryInput  : false,
        offset      : 0,
        url         : false,
        idStoreNotIn: false,
        idCustomer  : false
   }
}

findItemsInStore.prototype.processQuery = function () {
    var self = this;
    if (this.cfg.queryInput.value == '') {
        this.cfg.callbackObject.process();
    } else {
        this.cfg.imgLoading.style.display = 'inline';
        var pom = '';
        for (i=0; i<this.cfg.idStoreNotIn.length; i++) {
            pom = pom + (pom?',':'') + this.cfg.idStoreNotIn[i].toString();
        }
        $.post(this.cfg.url, { query: this.cfg.queryInput.value, offset: this.cfg.offset, 
        		id_store_not_in: pom, id_customer: this.cfg.id_customer }, 
        	function(data) {
        		self.cfg.callbackObject.process(data);
        		self.cfg.imgLoading.style.display = 'none';
        	}, "json");
    }
}

// blikani

function blink(element, times, timeout, blinkClassName) {
    var self = this;
    this.element = element;
    this.times = times;
    this.timeout = timeout;
    this.blinkClassName = blinkClassName;
    this.oldClassName = element.className;
    this.blinkOne(1);
}

blink.prototype.blinkOne = function(on) {
    var self = this;
    if (on) {
        this.element.className = this.oldClassName + ' ' + this.blinkClassName;
    } else {
        this.element.className = this.oldClassName;
    }
    this.times--;
    if (this.times>0) {
        window.setTimeout(function() {
            self.blinkOne(!on);
        }, this.timeout);
    }
}

// pridavani udalosti
function addEvent(obj, type, fn)
{
	if (obj.attachEvent)
	{
	obj.attachEvent('on' + type, fn);
	}
	else
	obj.addEventListener(type, fn, false);
}

function removeEvent(obj, type, fn) {
	if( obj.detachEvent ) {
	obj.detachEvent( 'on' + type, fn);
	} else
	obj.removeEventListener( type, fn, false );
}



// dalsi uzitecne


