/** *  author:		Timothy Groves - http://www.brandspankingnew.net *	version:	1.2 - 2006-11-17 *              1.3 - 2006-12-04 *              2.0 - 2007-02-07 * */var useBSNns = true;var diakritikaCo = new Array(/[aáä]/ig, /[cč]/ig, /[dď]/ig, /[eéě]/ig, /[ií]/ig, /[lľĺ]/ig, /[nň]/ig, /[oó]/ig, /[rřŕ]/ig, /[sš]/ig, /[tť]/ig, /[uú]/ig, /[yý]/ig, /[zž]/ig);var diakritikaCim = new Array('[aáä]', '[cč]', '[dď]', '[eéě]', '[ií]', '[lľĺ]', '[nň]', '[oó]', '[rřŕ]', '[sš]', '[tť]', '[uú]', '[yý]', '[zž]');var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);if (useBSNns) {    if (typeof (bsn) == "undefined") bsn = {};    _bsn = bsn;} else {    _bsn = this;}if (typeof (_bsn.Autosuggest) == "undefined") _bsn.Autosuggest = {};_bsn.AutoSuggest = function (id, param) {    if (!document.getElementById) return false;    this.fld = _bsn.DOM.gE(id);    if (!this.fld) return false;    this.sInput = "";    this.nInputChars = 0;    this.aSuggestions = [];    this.iHighlighted = 0;    this.oP = (param) ? param : {};    var def = {        minchars: 3,        meth: "get",        varname: "input",        className: "sRslt",        timeout: 10000,        delay: 300,        offsety: -8,        shownoresults: false,        noresults: "Žiadny výsledok!",        maxheight: 250,        cache: true    };    for (k in def)    if (typeof (this.oP[k]) != typeof (def[k])) this.oP[k] = def[k];    var p = this;    this.fld.onkeypress = function (ev) {        return p.onKeyPress(ev);    }    this.fld.onkeyup = function (ev) {        return p.onKeyUp(ev);    }    this.fld.setAttribute("autocomplete", "off");}_bsn.AutoSuggest.prototype.onKeyPress = function (ev) {    var key = (window.event) ? window.event.keyCode : ev.keyCode;    var RETURN = 13;    var TAB = 9;    var ESC = 27;    var bubble = true;    switch (key) {    case RETURN:                                         	  if (!this.iHighlighted) {	  	if(($(this.fld).parents('form').length) > 0) {		  $(this.fld).parents('form').submit();		}        }                this.setHighlightedValue();        bubble = false;        break;    case ESC:        this.clearSuggestions();        break;    }    return bubble;}_bsn.AutoSuggest.prototype.onKeyUp = function (ev) {    var key = (window.event) ? window.event.keyCode : ev.keyCode;    var ARRUP = 38;    var ARRDN = 40;    var bubble = true;    switch (key) {    case ARRUP:        this.changeHighlight(key);        bubble = false;        break;    case ARRDN:        this.changeHighlight(key);        bubble = false;        break;    default:        this.getSuggestions(this.fld.value);    }    return bubble;}_bsn.AutoSuggest.prototype.getSuggestions = function (val) {    if (val == this.sInput) return false;    if (val.length < this.oP.minchars) {        this.sInput = "";        return false;    }    if (val.length > this.nInputChars && this.aSuggestions.length && this.oP.cache) {        var arr = [];        for (var i = 0; i < this.aSuggestions.length; i++) {            if (this.aSuggestions[i].value.substr(0, val.length).toLowerCase() == val.toLowerCase()) arr.push(this.aSuggestions[i]);        }        this.sInput = val;        this.nInputChars = val.length;        this.aSuggestions = arr;        this.createList(this.aSuggestions);        return false;    } else {        this.sInput = val;        this.nInputChars = val.length;        var pointer = this;        clearTimeout(this.ajID);        this.ajID = setTimeout(function () {            pointer.doAjaxRequest()        }, this.oP.delay);    }        $(this.fld).parent('.field').children('.loader').css('display','block');    return false;}_bsn.AutoSuggest.prototype.doAjaxRequest = function () {    var pointer = this;    if (typeof (this.oP.script) == "function") var url = this.oP.script(escape(this.fld.value));    else var url = this.oP.script + this.oP.varname + "=" + escape(this.fld.value);    if (!url) return false;        var elm = this.fld;        var meth = this.oP.meth;    var onSuccessFunc = function (req) {   		            pointer.setSuggestions(req)    				$(elm).parent('.field').children('.loader').css('display','none');        };    var onErrorFunc = function (status) {};    var myAjax = new _bsn.Ajax();    myAjax.makeRequest(url, meth, onSuccessFunc, onErrorFunc);}_bsn.AutoSuggest.prototype.setSuggestions = function (req) {    this.aSuggestions = [];    if (this.oP.json) {        var jsondata = eval('(' + req.responseText + ')');        for (var i = 0; i < jsondata.results.length; i++) {            this.aSuggestions.push({                'id': jsondata.results[i].id,                'value': jsondata.results[i].value,                'price': jsondata.results[i].price,                'availability_name': jsondata.results[i].availability_name,                'availability_color': jsondata.results[i].availability_color,                'url': jsondata.results[i].url,                'image': jsondata.results[i].image,                'type': jsondata.results[i].type,                'arrow': jsondata.results[i].arrow,                'noresult': jsondata.results[i].noresult            });        }    } else {        var xml = req.responseXML;        var results = xml.getElementsByTagName('results')[0].childNodes;        for (var i = 0; i < results.length; i++) {            if (results[i].hasChildNodes()) this.aSuggestions.push({                'id': results[i].getAttribute('id'),                'value': results[i].childNodes[0].nodeValue,                'price': results[i].getAttribute('price'),                'availability_name': results[i].getAttribute('availability_name'),                'availability_color': results[i].getAttribute('availability_color'),                'url': results[i].getAttribute('url'),                'image': results[i].getAttribute('image'),                'type': results[i].getAttribute('type'),                'arrow': results[i].getAttribute('arrow'),                'noresult': results[i].getAttribute('noresult')            });        }    }    this.idAs = "as_" + this.fld.id;    this.createList(this.aSuggestions);}_bsn.AutoSuggest.prototype.createList = function (arr) {    var pointer = this;    _bsn.DOM.remE(this.idAs);    this.killTimeout();    if (arr.length == 0 && !this.oP.shownoresults) return false;    var div = _bsn.DOM.cE("div", {        id: this.idAs,        className: this.oP.className    });    var em =  _bsn.DOM.cE("em", { }, "");    div.appendChild(em);    var ul = _bsn.DOM.cE("ul", {        id: "as_ul"    });        vyznacit = this.sInput.toLowerCase();    vyznacit = vyznacit.replace(/[^a-z0-9áäčďéěíľĺňóřŕšťúýž]/, '-');    vyznacit = vyznacit.replace(/\s/, '-');    vyznacit = vyznacit.replace(/--+/, '-');    vyznacit = vyznacit.replace(/^-+/, '-');    vyznacit = vyznacit.replace(/-+$/, '-');    tmp_arr = vyznacit.split("-");    vyznac_arr = new Array();    vyznac_dlzka = new Array();    for (i = 0; i < tmp_arr.length; i++) {        if (tmp_arr[i].length < 2) continue;        vyznac_dlzka[i] = tmp_arr[i].length;        vyznac_arr[i] = tmp_arr[i]        for (j = 0; j < diakritikaCo.length; j++)        vyznac_arr[i] = vyznac_arr[i].replace(diakritikaCo[j], diakritikaCim[j]);        vyznac_arr[i] = '(^' + vyznac_arr[i] + '|[ ,-]' + vyznac_arr[i] + ')';        vyznac_arr[i] = new RegExp(vyznac_arr[i], "i");    }        for (var i = 0; i < arr.length; i++) {        var aBody = _bsn.DOM.cE("a", { 	  	href: arr[i].url,	  	className: "ac"	  }, "");        	var val = arr[i].value;	for (j = 0; j < vyznac_arr.length; j++) {		var st = val.search(vyznac_arr[j]);		if (st >= 0) {			if (st > 0) st++;				val = val.substring(0, st) + "<u>" + val.substring(st, st + vyznac_dlzka[j]) + "</u>" + val.substring(st + vyznac_dlzka[j]);		}	}		var availability_name = _bsn.DOM.cE("b", {	}, arr[i].availability_name);		availability_name.style.color = arr[i].availability_color;		var value = _bsn.DOM.cE("strong", {	}, val, true);		var img = _bsn.DOM.cE("img", {		src: arr[i].image,		className: "imgR"	}, "");		var price = _bsn.DOM.cE("font", {	}, arr[i].price + ", ");		var arrow = _bsn.DOM.cE("i", {	}, arr[i].price + "");		if (arr[i].type == "v1") {		aBody.className = "v1 ac";		aBody.appendChild(img);		aBody.appendChild(value);				if ( arr[i].price != '' )		{			aBody.appendChild(price);		}					aBody.appendChild(availability_name);			} else if (arr[i].type == "v3") {		aBody.onClick = "$(this.fld).parents('form').submit();";		aBody.appendChild(value);		aBody.appendChild(arrow);	} else if (arr[i].type == "v4") {		var aBody = _bsn.DOM.cE("span", {		  	className: "noRes"		}, value, true);	} else {		aBody.appendChild(value);	}		if ( aBody && $(aBody).get(0).nodeName != 'SPAN' ) 	{		aBody.name = i + 1;		aBody.onclick = function () {			pointer.setHighlightedValue();			return false;		}		aBody.onmouseover = function () {			pointer.setHighlight(this.name);		}	}        var li = _bsn.DOM.cE("li", {}, aBody);        ul.appendChild(li);    }        if (arr.length == 0 && this.oP.shownoresults) {        var li = _bsn.DOM.cE("li", {            className: "as_warning"        }, this.oP.noresults);        ul.appendChild(li);    }          div.appendChild(ul);    var pos = _bsn.DOM.getPos(this.fld);        var box_classes = div.className;        if ( $(this.fld).parents('.hdr').length > 0 )    {		box_classes = box_classes + ' ashdr';    }        if ( $(this.fld).parents('.icl').length > 0 )    {		box_classes = box_classes + ' asicl';				var pos_icl = '1';    }         if ( $(this.fld).parents('.ncl').length > 0 )    {		box_classes = box_classes + ' asncl';		var pos_ncl = '1';    }        if ( $(this.fld).parents('.scon').length > 0 )    {		box_classes = box_classes + ' asscon';    }        if ( $(this.fld).parents('.con').length > 0 )    {		box_classes = box_classes + ' ascon';    }        if ( $(this.fld).parents('.llay').length > 0 )    {		box_classes = box_classes + ' asllay';		var pos_llay = '1';    }        if ( $(this.fld).parents('.rlay').length > 0 )    {		box_classes = box_classes + ' asrlay';		var pos_rlay = '1';    }    if ( $(this.fld).parents('.j0').length > 0 )    {		box_classes = box_classes + ' asj0';    }    if ( $(this.fld).parents('.j2').length > 0 )    {		box_classes = box_classes + ' asj2';    }    if ( $(this.fld).parents('.j3').length > 0 )    {		box_classes = box_classes + ' asj3';    }    if ( $(this.fld).parents('.c3').length > 0 )    {		box_classes = box_classes + ' asc3';    }    if ( $(this.fld).parents('.c2').length > 0 )    {		box_classes = box_classes + ' asc2';    }    if ( $(this.fld).parents('.c0').length > 0 )    {		box_classes = box_classes + ' asc0';    }    if ( ((pos_rlay == '1') && ( pos_ncl == '1')) || ((pos_llay == '1') && (pos_icl == '1')) ) {    	//alert($(this.fld).outerWidth());    	    	if ( ($(this.fld).parents('.j0').length > 0) || ($(this.fld).parents('.rlay.c3.j2').length > 0))    	{	    div.style.left = pos.x - (490 - $(this.fld).outerWidth()) + 1 + "px";	} else {	    div.style.left = pos.x - (490 - $(this.fld).outerWidth()) + "px";	}	div.style.top = (pos.y + 5 + this.fld.offsetHeight + this.oP.offsety) + "px";	box_classes = box_classes + ' posLft';    } else {	div.style.left = pos.x + 1 + "px";	div.style.top = (pos.y + 5 + this.fld.offsetHeight + this.oP.offsety) + "px";	box_classes = box_classes + ' posRft';    }    //div.style.width = 462 + "px";    div.className = box_classes;    div.onmouseover = function () {        pointer.killTimeout()    }    div.onmouseout = function () {        pointer.resetTimeout()    }    document.getElementsByTagName("body")[0].appendChild(div);    this.iHighlighted = 0;    var pointer = this;    this.toID = setTimeout(function () {        pointer.clearSuggestions()    }, this.oP.timeout);}_bsn.AutoSuggest.prototype.changeHighlight = function (key) {    var list = _bsn.DOM.gE("as_ul");    if (!list) return false;    var n;    if (key == 40) n = this.iHighlighted + 1;    else if (key == 38) n = this.iHighlighted - 1;    if (n > list.childNodes.length) n = list.childNodes.length;        if (n < 1) n = 1;        this.setHighlight(n);}_bsn.AutoSuggest.prototype.setHighlight = function (n) {    var list = _bsn.DOM.gE("as_ul");    if (!list) return false;    if (this.iHighlighted > 0) this.clearHighlight();    this.iHighlighted = Number(n);    if (this.aSuggestions[this.iHighlighted - 1].type != "v4") list.childNodes[this.iHighlighted - 1].className = "asCur";    else this.clearHighlight();    this.killTimeout();}_bsn.AutoSuggest.prototype.clearHighlight = function () {    var list = _bsn.DOM.gE("as_ul");    if (!list) return false;    if (this.iHighlighted > 0) {        list.childNodes[this.iHighlighted - 1].className = "";        this.iHighlighted = 0;    }}_bsn.AutoSuggest.prototype.setHighlightedValue = function () {    if (this.aSuggestions[this.iHighlighted - 1].type == "v3") {	  $(this.fld).parents('form').submit();	  return false;    }	      if (this.iHighlighted) {                this.sInput = this.fld.value = this.aSuggestions[this.iHighlighted - 1].value;        this.fld.focus();        if (this.fld.selectionStart) this.fld.setSelectionRange(this.sInput.length, this.sInput.length);        this.clearSuggestions();        if (typeof (this.oP.callback) == "function") this.oP.callback(this.aSuggestions[this.iHighlighted - 1]);        if (this.aSuggestions[this.iHighlighted - 1].url) {            document.location.href = "/" + this.aSuggestions[this.iHighlighted - 1].url;            return false;        } else if(($(this.fld).parents('form').length) > 0) {		  $(this.fld).parents('form').submit();	  }        //if (document.forms[form_name]) document.forms['catalog_search_form'].submit();    }}_bsn.AutoSuggest.prototype.killTimeout = function () {    clearTimeout(this.toID);}_bsn.AutoSuggest.prototype.resetTimeout = function () {    clearTimeout(this.toID);    var pointer = this;    this.toID = setTimeout(function () {        pointer.clearSuggestions()    }, 1000);}_bsn.AutoSuggest.prototype.clearSuggestions = function () {    this.killTimeout();    var ele = _bsn.DOM.gE(this.idAs);    var pointer = this;    if (ele) {        var fade = new _bsn.Fader(ele, 1, 0, 250, function () {            _bsn.DOM.remE(pointer.idAs)        });    }}if (typeof (_bsn.Ajax) == "undefined") _bsn.Ajax = {}_bsn.Ajax = function () {    this.req = {};    this.isIE = false;}_bsn.Ajax.prototype.makeRequest = function (url, meth, onComp, onErr) {    if (meth != "POST") meth = "GET";    this.onComplete = onComp;    this.onError = onErr;    var pointer = this;    if (window.XMLHttpRequest) {        this.req = new XMLHttpRequest();        this.req.onreadystatechange = function () {            pointer.processReqChange()        };        this.req.open("GET", url, true);        this.req.send(null);    } else if (window.ActiveXObject) {        this.req = new ActiveXObject("Microsoft.XMLHTTP");        if (this.req) {            this.req.onreadystatechange = function () {                pointer.processReqChange()            };            this.req.open(meth, url, true);            this.req.send();        }    }}_bsn.Ajax.prototype.processReqChange = function () {    if (this.req.readyState == 4) {        if (this.req.status == 200) {            this.onComplete(this.req);        } else {            this.onError(this.req.status);        }    }}if (typeof (_bsn.DOM) == "undefined") _bsn.DOM = {}_bsn.DOM.cE = function (type, attr, cont, html) {    var ne = document.createElement(type);    if (!ne) return false;        for (var a in attr)    ne[a] = attr[a];    if (typeof (cont) == "string" && type != "img" && !html) ne.appendChild(document.createTextNode(cont));    else if (typeof (cont) == "string" && type != "img" && html) ne.innerHTML = cont;    else if (typeof (cont) == "object") ne.appendChild(cont);    return ne;}_bsn.DOM.gE = function (e) {    if (typeof (e) == "undefined") return false;    else if (typeof (e) == "string") {        var re = document.getElementById(e);        if (!re) return false;        else if (typeof (re.appendChild) != "undefined") {            return re;        } else {            return false;        }    } else if (typeof (e.appendChild) != "undefined") return e;    else return false;}_bsn.DOM.remE = function (ele) {    var e = this.gE(ele);    if (!e) return false;    else if (e.parentNode.removeChild(e)) return true;    else return false;}_bsn.DOM.getPos = function (e) {    var e = this.gE(e);    var obj = e;    var curleft = 0;    if (obj.offsetParent) {        while (obj.offsetParent) {            curleft += obj.offsetLeft;            obj = obj.offsetParent;        }    } else if (obj.x) curleft += obj.x;    var obj = e;    var curtop = 0;    if (obj.offsetParent) {        while (obj.offsetParent) {            curtop += obj.offsetTop;            obj = obj.offsetParent;        }    } else if (obj.y) curtop += obj.y;    return {        x: curleft,        y: curtop    };}if (typeof (_bsn.Fader) == "undefined") _bsn.Fader = {}_bsn.Fader = function (ele, from, to, fadetime, callback) {    if (!ele) return false;    this.ele = ele;    this.from = from;    this.to = to;    this.callback = callback;    this.nDur = fadetime;    this.nInt = 50;    this.nTime = 0;    var p = this;    this.nID = setInterval(function () {        p._fade()    }, this.nInt);}_bsn.Fader.prototype._fade = function () {    this.nTime += this.nInt;    var ieop = Math.round(this._tween(this.nTime, this.from, this.to, this.nDur) * 100);    var op = ieop / 100;    if (this.ele.filters) {        try {            this.ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;        } catch (e) {            this.ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + ieop + ')';        }    } else {        this.ele.style.opacity = op;    }    if (this.nTime == this.nDur) {        clearInterval(this.nID);        if (this.callback != undefined) this.callback();    }}_bsn.Fader.prototype._tween = function (t, b, c, d) {    return b + ((c - b) * (t / d));};
