var selectIndex_aSrchPrdKw = -1; var select_aSrchPrdKw = ''; var lastKwSearchNoResult = ''; var timeoutSrchPrdHide = null; function tbSearchKw_KeyDown(tbSearchKw, event) { try { //var evtobj = window.event ? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit. if (tbSearchKw.value.length == 0) { if (document.getElementById('dSrchPrd').style.display == 'block') srchPrd_Hide(); return // ESCAPE; } var evtobj = event; if (document.getElementById('dSrchPrd').style.display == 'block') { if (evtobj.keyCode == 38) { if (selectIndex_aSrchPrdKw == 0) return; // ESCAPE selectIndex_aSrchPrdKw -= 1; document.getElementById('aSrchPrdKw' + (selectIndex_aSrchPrdKw + 1)).className = 'aSrchPrdKw'; document.getElementById('aSrchPrdKw' + selectIndex_aSrchPrdKw).className += ' aSrchPrdKwSel'; srchPrd_Click(document.getElementById('aSrchPrdKw' + selectIndex_aSrchPrdKw), false); return; } else if (evtobj.keyCode == 40) { if (!document.getElementById('aSrchPrdKw' + (selectIndex_aSrchPrdKw + 1))) return; // ESCAPE selectIndex_aSrchPrdKw += 1; if (selectIndex_aSrchPrdKw > 0) { document.getElementById('aSrchPrdKw' + (selectIndex_aSrchPrdKw - 1)).className = 'aSrchPrdKw'; } document.getElementById('aSrchPrdKw' + selectIndex_aSrchPrdKw).className += ' aSrchPrdKwSel'; srchPrd_Click(document.getElementById('aSrchPrdKw' + selectIndex_aSrchPrdKw), false); return; } } var unicode = evtobj.charCode ? evtobj.charCode : evtobj.keyCode var actualkey = String.fromCharCode(unicode).toLowerCase() var _pattern = /^\w$/gi; if (!_pattern.test(actualkey)) return; // ESCAPE var actualKw = tbSearchKw.value.toLowerCase() + actualkey; prepareSrchPrdCall(actualKw); } catch (ex) { LogErrorInCookies('srchprd.js.tbSearchKw_KeyDown()', ex); } } function tbSearchKw_KeyUp(tbSearchKw, event) { try { //var evtobj = window.event ? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit. var evtobj = event; if (evtobj.keyCode == 38 || evtobj.keyCode == 40 || evtobj.keyCode == 13) return; // ESCAPE prepareSrchPrdCall(tbSearchKw.value); return; // ESCPAE } catch (ex) { LogErrorInCookies('srchprd.js.tbSearchKw_KeyUp()', ex); } } function prepareSrchPrdCall(actualKw) { try { if (actualKw.length < 2) { srchPrd_Hide(); lastKwSearch = ''; return; // ESCAPE } else if (lastKwSearch.toLowerCase() == actualKw.toLowerCase()) { return; // ESCAPE } else if (lastKwSearchNoResult.length > 0 && actualKw.indexOf(lastKwSearchNoResult) == 0 && lastKwSearchNoResult.length <= actualKw.length) { srchPrd_Hide(); return; // ESCAPE } //alert('lastKwSearch: ' + lastKwSearch + ' ; actualKw: ' + actualKw); var selCatSubcat = document.getElementById('selCatSubcat'); var idCat = 0; var idSubcat = 0; if (typeof (selCatSubcat.selectedIndex) !== 'undefined') { // DESKTOP if (selCatSubcat.selectedIndex > 0 && selCatSubcat.options[selCatSubcat.selectedIndex].id && selCatSubcat.options[selCatSubcat.selectedIndex].id != '') { if (selCatSubcat.options[selCatSubcat.selectedIndex].id.indexOf('optCat') == 0) { idCat = selCatSubcat.options[selCatSubcat.selectedIndex].id.replace('optCat', ''); } else if (selCatSubcat.options[selCatSubcat.selectedIndex].id.indexOf('optSCat') == 0) { idSubcat = selCatSubcat.options[selCatSubcat.selectedIndex].id.replace('optSCat', ''); } } } else { // MOBILE if (selCatSubcat.getAttribute('data-id') != '') { if (selCatSubcat.getAttribute('data-id').indexOf('optCat') == 0) { idCat = selCatSubcat.getAttribute('data-id').replace('optCat', ''); } else if (selCatSubcat.getAttribute('data-id').indexOf('optSCat') == 0) { idSubcat = selCatSubcat.getAttribute('data-id').replace('optSCat', ''); } } } srchPrd_Call(actualKw, idCat, idSubcat); lastKwSearch = actualKw; } catch (ex) { LogErrorInCookies('srchprd.js.prepareSrchPrdCall()', ex); } } function srchPrd_Call(kw, idCat, idSubcat) { //alert('srchPrd_Call : kw = ' + kw); var arrParams = new Array(); arrParams['kw'] = kw; arrParams['idCat'] = idCat; arrParams['idSubcat'] = idSubcat; _ajaxRequest(location.protocol + '//' + location.host + '/ajax/srchprd.aspx', arrParams, 'srchPrd_Callback', 'GET', true); //srchprd.1.1.js function call } function srchPrd_Callback(responseJson, responseStatus, url) { var srchPredResp = null; try { srchPredResp = eval("(" + responseJson + ")"); } catch (ex) { LogErrorInCookies('srchprd.js.srchPrd_Callback().createJSON.eval() | v4 | responseJson: ' + responseJson + ' | responseStatus : ' + responseStatus.toString() + ' | url: ' + url, ex); return; } try { if (srchPredResp.searchPredict.length == 0) { lastKwSearchNoResult = lastKwSearch; srchPrd_Hide(); return; // ESCAPE } var srchPrdHtml = ''; var kw = document.getElementById('tbSearch').value; var regEx = new RegExp('^' + kw, 'gi'); for (i = 0; i < srchPredResp.searchPredict.length; i++) { var srchPrdArgs = ''; var srchPrdInner = ''; var catSubcatRegProv = ''; var predictKw = srchPredResp.searchPredict[i].predictKw.replace(regEx, kw + '') + ''; srchPrdInner += '' + predictKw + ''; if (srchPredResp.searchPredict[i].idSubcat != 0) { catSubcatRegProv += ' in ' + srchPredResp.searchPredict[i].subcat; //srchPrdHtml += ''; } else if (srchPredResp.searchPredict[i].idCat != 0) { catSubcatRegProv += ' in ' + srchPredResp.searchPredict[i].category; //srchPrdHtml += ''; } if (srchPredResp.searchPredict[i].idProv != 0) { catSubcatRegProv += ' a ' + srchPredResp.searchPredict[i].prov; } else if (srchPredResp.searchPredict[i].idReg != 0) { catSubcatRegProv += ' in ' + srchPredResp.searchPredict[i].region; } if (catSubcatRegProv.length > 0) { srchPrdInner += ' ' + catSubcatRegProv + ''; } srchPrdArgs += ', ' + srchPredResp.searchPredict[i].idCat + ',\'' + srchPredResp.searchPredict[i].category + '\',\'' + srchPredResp.searchPredict[i].catUrl + '\', ' + srchPredResp.searchPredict[i].https; srchPrdArgs += ', ' + srchPredResp.searchPredict[i].idSubcat + ',\'' + srchPredResp.searchPredict[i].subcat + '\',\'' + srchPredResp.searchPredict[i].subcatUrl + '\''; srchPrdArgs += ', ' + srchPredResp.searchPredict[i].idReg + ',\'' + srchPredResp.searchPredict[i].region + '\',\'' + srchPredResp.searchPredict[i].regionUrl + '\''; srchPrdArgs += ', ' + srchPredResp.searchPredict[i].idProv + ',\'' + srchPredResp.searchPredict[i].prov + '\',\'' + srchPredResp.searchPredict[i].provUrl + '\''; srchPrdHtml += ''; srchPrdHtml += srchPrdInner; srchPrdHtml += ''; } if (document.getElementById('dSrchPrd').style.display != 'block') document.getElementById('dSrchPrd').style.display = 'block'; document.getElementById('dSrchPrd').innerHTML = srchPrdHtml; } catch (ex) { LogErrorInCookies('srchprd.js.srchPrd_Callback()', ex); } } function srchPrd_Click(aSrchPrdKw, submitSearch, idCat, category, catUrl, https, idSubcat, subcat, subcatUrl, idReg, region, regionUrl, idProv, prov, provUrl) { try { //if (navigator.userAgent.toLowerCase().indexOf("android") > -1) alert('clicked'); isMouseOverSrchPrd = true; if (timeoutSrchPrdHide != null) window.clearTimeout(timeoutSrchPrdHide); // TOUCH EVENT -> CLEAR TIMEOUT FORHIDING dSrchPrd ON BLURE EVENT var indexSearchKw = aSrchPrdKw.id.toString().replace('aSrchPrdKw', '') document.getElementById('tbSearch').value = document.getElementById('sSrchKw' + indexSearchKw).innerHTML.replace(/<\/?([A-Z][A-Z0-9]*)\b[^>]*>/gi, ''); if (idCat == 0 && idSubcat == 0 && idReg == 0 && idProv == 0) { if (typeof (document.getElementById('selCatSubcat').selectedIndex) !== 'undefined') { document.getElementById('selCatSubcat').selectedIndex = 0; // DESKTOP VERSION document.getElementById('selRegProv').selectedIndex = 0; // DESKTOP VERSION } else { var selCatSubcat = document.getElementById('selCatSubcat'); selCatSubcat.setAttribute('data-id', ''); selCatSubcat.setAttribute('data-value', ''); var selRegProv = document.getElementById('selRegProv'); selRegProv.setAttribute('data-id', ''); selRegProv.setAttribute('data-value', ''); } if (submitSearch) search_Submit(document.getElementById('formSearch'), false, false, true); return; // ESCAPE } if (typeof (document.getElementById('selCatSubcat').selectedIndex) !== 'undefined') { var optionTemp = document.createElement("option"); if (idSubcat > 0) { optionTemp.text = subcat; optionTemp.value = catUrl + '_' + subcatUrl; //alert('catSubcatUrlName ' + document.getElementById('hidSrchPrdSubcat' + indexSearchKw).value); } else if (idCat > 0) { if (document.getElementById('optCat' + idCat)) document.getElementById('selCatSubcat').remove(document.getElementById('optCat' + idCat).index); optionTemp.text = category; optionTemp.id = 'optCat' + idCat; optionTemp.value = catUrl; //alert('catUrlName ' + document.getElementById('hidSrchPrdCat' + indexSearchKw).value); } // while (document.getElementById('selCatSubcat').length > 1) { // document.getElementById('selCatSubcat').remove(1); // } if (optionTemp.text != null && optionTemp.text != '') { if (https == 1) optionTemp.setAttribute('data-https', '1'); document.getElementById('selCatSubcat').add(optionTemp, 1); document.getElementById('selCatSubcat').selectedIndex = 1; } var optionTemp2 = document.createElement("option"); if (idProv > 0) { if (document.getElementById('optProv' + idProv)) document.getElementById('selRegProv').remove(document.getElementById('optProv' + idProv).index); optionTemp2.text = prov; optionTemp2.id = 'optProv' + idProv; optionTemp2.value = '_' + provUrl; } else if (idReg > 0) { if (document.getElementById('optReg' + idReg)) document.getElementById('selRegProv').remove(document.getElementById('optReg' + idReg).index); optionTemp2.text = region; optionTemp2.id = 'optReg' + idReg; optionTemp2.value = regionUrl; } if (typeof optionTemp2.text !== 'undefined' && optionTemp2.text != '') { document.getElementById('selRegProv').add(optionTemp2, 1); document.getElementById('selRegProv').selectedIndex = 1; } } else { var selCatSubcat = document.getElementById('selCatSubcat'); if (idSubcat > 0) { //selCatSubcat.firstChild.innerHTML = document.getElementById('sSrchPrdSubcat' + indexSearchKw).innerHTML; selCatSubcat.setAttribute('data-id', ''); selCatSubcat.setAttribute('data-value', catUrl + '_' + subcatUrl); if (https == 1) selCatSubcat.setAttribute('data-https', '1'); } else if (idCat > 0) { //selCatSubcat.firstChild.innerHTML = document.getElementById('sSrchPrdCat' + indexSearchKw).innerHTML; selCatSubcat.setAttribute('data-id', 'optCat' + idCat); selCatSubcat.setAttribute('data-value', catUrl); if (https == 1) selCatSubcat.setAttribute('data-https', '1'); } var selRegProv = document.getElementById('selRegProv'); if (idProv > 0) { selRegProv.setAttribute('data-id', 'optProv' + idProv); selRegProv.setAttribute('data-value', '_' + provUrl); } else if (idReg > 0) { selRegProv.setAttribute('data-id', 'optReg' + idReg); selRegProv.setAttribute('data-value', regionUrl); } } if (submitSearch) search_Submit(document.getElementById('formSearch'), false, false, true); } catch (ex) { LogErrorInCookies('srchprd.js.srchPrd_Click()', ex); } } var isMouseOverSrchPrd = false; function dSrchPrd_MouseOver() { isMouseOverSrchPrd = true; } function dSrchPrd_MouseOut() { isMouseOverSrchPrd = false; } function tbSearchKw_Blure() { try { if (isMouseOverSrchPrd) return; // ESCAPE //if (navigator.userAgent.toLowerCase().indexOf("android") > -1) return; // ESCAPE timeoutSrchPrdHide = window.setTimeout(function () { srchPrd_Hide(); }, 80); //document.getElementById('dSrchPrd').innerHTML = ''; //document.getElementById('dSrchPrd').style.display = 'none'; } catch (ex) { LogErrorInCookies('srchprd.js.tbSearchKw_Blure()', ex); } } function srchPrd_Hide() { try { //alert('srchPrd_Hide()'); selectIndex_aSrchPrdKw = -1; select_aSrchPrdKw = ''; //lastKwSearch = ''; document.getElementById('dSrchPrd').innerHTML = ''; document.getElementById('dSrchPrd').style.display = 'none'; } catch (ex) { LogErrorInCookies('srchprd.js.srchPrd_Hide()', ex); } } //AJAX var unfinishedAjax = new Array(); function _ajaxRequest(url, arrParams, customAjaxCompletedAction, requestMethod, cacheBypass) { var http_request = false; try { // Prepare parameters var parameters = ''; for (var key in arrParams) { if (parameters.length > 0) { parameters = parameters + '&'; } //parameters = parameters + key + '=' + escape(arrParams[key]); parameters = parameters + key + '=' + encodeURIComponent(arrParams[key]); } http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!http_request) { var ex = new Error('Cannot create XMLHTTP instance', ''); LogErrorInCookies('srchprd.js._ajaxRequest() | AjaxUrl: ' + url, ex) return false; } if ('onload' in http_request) { // XHR2 http_request.onload = function () { _ajaxRequestCompleted(http_request, url, customAjaxCompletedAction); } // Attaching anonymous function to hanlde event, thats is capable to pass paramaters } else { // XHR1 http_request.onreadystatechange = function () { _ajaxRequestCompleted(http_request, url, customAjaxCompletedAction); } // Attaching anonymous function to hanlde event, thats is capable to pass paramaters } if ('onerror' in http_request) http_request.onerror = function (eventArgs) { xhrError(eventArgs, url, customAjaxCompletedAction); } if ('ontimeout' in http_request) http_request.ontimeout = function (eventArgs) { xhrTimeout(eventArgs, url, customAjaxCompletedAction); } if (requestMethod.toUpperCase() == 'POST') { http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.send(parameters); } else if (requestMethod.toUpperCase() == 'GET') { if (parameters.length > 0) { url += (url.indexOf('?') > -1) ? '&' : '?'; url += parameters if (cacheBypass) url += '&cacheBypass=' + (new Date()).getTime(); } else if (cacheBypass) { url += '?cacheBypass=' + (new Date()).getTime(); } http_request.open('GET', url, true); http_request.send(null); } unfinishedAjax[unfinishedAjax.length] = url; } catch (ex) { if (customAjaxCompletedAction != null) { try { window[customAjaxCompletedAction](null); // Call Custom Function After Ajax Call Crashed } catch (ex) { } } LogErrorInCookies('srchprd.1.1.js._ajaxRequest()', ex) } } function _ajaxRequestCompleted(http_request, url, customAjaxCompletedAction) { try { if (customAjaxCompletedAction == null) return; // ESCAPE if (http_request == null) throw new Error('variable http_request is null', ''); if (http_request.readyState != 4) return; // ESCAPE if (http_request.status == 200 || http_request.status == 304 || (http_request.status == 0 && http_request.responseText != null && http_request.responseText.length > 0)) { window[customAjaxCompletedAction](http_request.responseText, http_request.status, url); // Call Custom Function After Ajax Finished } if (unfinishedAjax.length > 0) { unfinishedAjax.splice(unfinishedAjax.length - 1, 1); } } catch (ex) { if (customAjaxCompletedAction == null) customAjaxCompletedAction = ''; LogErrorInCookies('srchprd.1.1.js._ajaxRequestCompleted() | AjaxUrl: ' + url + ' | customAjaxCompletedAction: ' + customAjaxCompletedAction.toString(), ex) } } function xhrError(eventArgs) { var source = eventArgs.getSource(); var ex = new Error('XHR_Error', source.toString()); LogErrorInCookies('srchprd.1.1.js.xhrError) | AjaxUrl: ' + url + ' | customAjaxCompletedAction: ' + customAjaxCompletedAction.toString(), ex) } function xhrTimeout(eventArgs) { var source = eventArgs.getSource(); var ex = new Error('XHR_Error', source.toString()); LogErrorInCookies('srchprd.1.1.js.xhrTimeout() | AjaxUrl: ' + url + ' | customAjaxCompletedAction: ' + customAjaxCompletedAction.toString(), ex) }