
/*******************
*** QUICK ORDER ***
*******************/

var sepID, sepURL = '';
function cSeptej(name, lang) {


    this.lang = lang;
    this.selElement = null;
    this.fadeID = null;
    this.counter = 0;
    this.lastsearch = "";
    this.inProgress = false;
    this.data = null;
    this.div = getE('septej');
    this.name = name;
    this.cbf = function(JScode) { eval(JScode); }
    this.ajax = new Ajax("/exec/naseptavac.aspx","get",this.cbf);
    this.ajax.errorJScode = "";
    this.send = function(e) {
        var keynum;

        if (window.event) { keynum = window.event.keyCode; }
        else if (e.which) { keynum = e.which; }

        if (keynum == 40 && this.div.style.display != 'none') { this.div.focus(); return true; }
        if (getE('iexps').value.trim().length >= 3 && this.inProgress == false && (this.lastsearch = "" || this.lastsearch != getE('iexps').value.trim())) {
            this.lastsearch = getE('iexps').value.trim();
            this.inProgress = true;
             
            // Typ vyhledavani 
            var serarchTypeNodes = getF('searchFormMain').SearchType;            
            var searchType = 'Fulltext';
            for(var i = 0; i < serarchTypeNodes.length; i++) {
            		if(serarchTypeNodes[i].checked) {
            			searchType = serarchTypeNodes[i].value;
            		}
            	}

            // jen skladem            
            var onStore = '0'; 
            if (getE('OnStore').checked == true) {onStore='1'} else {onStore='0'}

            this.ajax.sendRQ([["search", getE('iexps').value.trim()], ["owner", this.name], ["row", 0], ["searchType", searchType], ["onstore", onStore]], true);
        }
        else if (this.lastsearch != getE('iexps').value.trim()) {

            this.clear();
        }
        return true;

    }
    this.setStat = function(id) {
        var url = getE(id).getAttribute('url');
        //alert(url);
        this.inProgress = false;
        this.clear();
        this.ajax.sendRQ([["id", id], ["owner", this.name], ["row", 0]], true);

        window.location.href = url;
        return false;
    }
    this.fill = function(row, aData) {
        this.inProgress = false;
        if (aData.length == 0) { this.clear(); return; }
        this.data = aData;
        this.draw();
    }
    this.stateOk = function() {
    }
    this.stateNok = function() {
    }
    this.draw = function() {
        this.clear();
        var sHtml = '<table><tbody><tr><td style="text-align:right;" colspan="3"><img src="/img/bt-close_septej.gif" title="Zavřít" onclick="septej.clear();" /></td>';
        var sBuyForm = '';

        for (var i = 0; i < this.data.length; i++) {        
            sHtml += '<tr><td class="name"><a href=' + this.data[i].url + ' title='+ this.data[i].longName +'>' + this.data[i].name + '</a></td><td class="price">' + this.data[i].price + ' ,-</td><td class="bsket"><a onclick="getE(\'comFSearch\').value=' + this.data[i].commodityID + ';getF(\'FormBuySearchF\').submit();" title="vložit do košíku">vložit do košíku</a></td></tr>';
        }


        this.div.innerHTML = sHtml;
        this.div.style.display = 'block';
        this.startTimer();
    }
    this.clear = function() {
        this.clearTimer;
        this.counter = 0;
        this.selElement = null;
        this.div.style.display = 'none'; this.div.innerHTML = '';
    }
    this.clearTimer = function() {
            window.clearTimeout(this.fadeID);
        }
    this.startTimer = function() {
        this.fadeID = setTimeout(this.name + ".clear()", 18000);
    }
    this.naviKeySuggest = function(e, type) {

        var keynum;
        if (window.event) { keynum = window.event.keyCode; }
        else if (e.which) { keynum = e.which; }

        if (this.selElement == null) {
            if (getE('aid_0')) { this.selElement = getE('aid_0'); }
        }
        else if (keynum == 40 && this.selElement.id != 'aid_0') {
            this.selElement = getNextEl();
        }
  //      else if (keynum == 38 && this.selElement.id != 'aid_' + (this.counter - 1)) {
    //        this.selElement = this.selElement.nextSibling();
      //  }
        for (var i = 0; i < this.counter; i++) {
            getE('aid_' + i).className = (this.selElement.id == 'aid_' + i ? 'sel' : '');
        }
        this.selElement.focus();
    }
    this.getNextEl = function() {
        var id = this.selElement.id.split('_')[1];
        return getE('aid_'+(id+1) );
    }

}
function hideSuggest() {
    septej.clear(); 
}
function clearTimerSuggest() {
    septej.clearTimer();
}
function startTimerSuggest() {
    septej.startTimer();
}
function naviKeySuggestPress(e) {
    septej.naviKeySuggest(e,0);
}
function naviKeySuggestUp(e) {
    if (getE('septej') == null || getE('septej').style.display == 'none') return true;
    septej.naviKeySuggest(e, 1);
    return false;
}
function addAnEvent(target, eventName, functionName) {
    try {
        if (Br.IE) eval('target.on' + eventName + '=functionName');
        else target.addEventListener(eventName, functionName, false);
    }
    catch (e) { }
}

