(function(funcName, baseObj) { funcName = funcName || "docReady"; baseObj = baseObj || window; var readyList = []; var readyFired = false; var readyEventHandlersInstalled = false; function ready() { if (!readyFired) { readyFired = true; for (var i = 0; i < readyList.length; i++) { readyList[i].fn.call(window, readyList[i].ctx); } readyList = []; } } function readyStateChange() { if ( document.readyState === "complete" ) { ready(); } } baseObj[funcName] = function(callback, context) { if (typeof callback !== "function") { throw new TypeError("callback for docReady(fn) must be a function"); } if (readyFired) { setTimeout(function() { callback(context); }, 1); return; } else { readyList.push({fn: callback, ctx: context}); } if (document.readyState === "complete") { setTimeout(ready, 1); } else if (!readyEventHandlersInstalled) { if (document.addEventListener) { document.addEventListener("DOMContentLoaded", ready, false); window.addEventListener("load", ready, false); } else { document.attachEvent("onreadystatechange", readyStateChange); window.attachEvent("onload", ready); } readyEventHandlersInstalled = true; } } })("docReady", window); docReady(function() { var uniqueID = 'ej_widget'; o=document.getElementById(uniqueID); if(o) { var code = '{\"passback\":0,\"code\":\"\"}', output = JSON.parse(code); if ((!output.code || 0 === output.length) && !output.passback) { o.style.display='none'; } else { if (output.passback && (!output.width || 0 === output.width.length)) { var pbs = document.createElement("script"); pbs.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"; pbs.onload = function() { (adsbygoogle=window.adsbygoogle || []).push({ }); }; document.getElementsByTagName("head")[0].appendChild(pbs); o.innerHTML = output.code; } else { var iframeID = 'ejw_ifwc_' + uniqueID; function resizeIframe(iframe) { obj = document.getElementById(iframe); obj.style.height = ""; obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; initPagination(); initCitiesSelect(); initFormSubmit(); } function refrashContent (page) { obj = document.getElementById(iframeID); var form = obj.contentWindow.document.getElementById("widget-search-form"); var xhttp = new XMLHttpRequest(); xhttp.open("POST", form.action, true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.onload = function () { if (this.readyState === this.DONE && this.status === 200) { var response = JSON.parse(this.responseText); obj.contentWindow.document.getElementById("results").innerHTML = response.code; resizeIframe(iframeID); } }; var keyword = '', location = 0, url = 'uniqueid='+ obj.contentWindow.document.getElementById("uniqueid").value; if (null !== obj.contentWindow.document.getElementById("keyword") && 'undefined' !== typeof obj.contentWindow.document.getElementById("keyword").value) { keyword = obj.contentWindow.document.getElementById("keyword").value; } if (null !== obj.contentWindow.document.getElementById("location") && 'undefined' !== typeof obj.contentWindow.document.getElementById("location").value) { location = obj.contentWindow.document.getElementById("location").value; } if (2 <= keyword.length) { url += '&q='+ keyword; } if (0 < parseInt(location)) { url += '&location='+ location; } if (0 < page) { url += "&page="+ page; } xhttp.send(url); } function refrashContentOnPageChange (e) { if (e) { e.preventDefault(); } var page = this.getAttribute("data-page"); refrashContent(page); return false; } function refrashContentOnLocationChange (e) { if (e) { e.preventDefault(); } refrashContent(0); return false; } function refrashContentOnSubmit (e) { if (e) { e.preventDefault(); } obj = document.getElementById(iframeID); var keyword = obj.contentWindow.document.getElementById("keyword").value; if (0 === keyword.length || 2 <= keyword.length) { refrashContent(0); } return false; } function initPagination () { obj = document.getElementById(iframeID); // Init pagination if in order var pager = obj.contentWindow.document.getElementById("pagination"); if (pager) { var etc_link = pager.querySelector('a[name="etc"]'); var pages = pager.getElementsByTagName("li"); for (var i=0; i < pages.length; i++) { if (!pages[i].contains(etc_link)) { pages[i].addEventListener("click", refrashContentOnPageChange); } } } } function initCitiesSelect () { obj = document.getElementById(iframeID); var select = obj.contentWindow.document.getElementById("location"); if (select) { select.addEventListener("click", refrashContentOnLocationChange); } } function initFormSubmit () { obj = document.getElementById(iframeID); var form = obj.contentWindow.document.getElementById("widget-search-form"); if (form) { form.addEventListener("submit", refrashContentOnSubmit); } } function initSubmitButton () { obj = document.getElementById(iframeID); var button = obj.contentWindow.document.getElementById("submit-button"); if (button) { button.addEventListener("submit", refrashContentOnSubmit); } } var f = document.createElement('iframe'); f.width = output.width;; f.id = iframeID; f.src = 'about:blank'; f.frameBorder = '0'; f.scrolling = 'no'; o.appendChild(f); f.onload = function(){ resizeIframe(iframeID); } f.contentWindow.document.write(output.code); f.contentWindow.document.close(); } } } });