(function () { var scriptName = "enquirywidget.js"; //name of this script, used to get reference to own tag var jQuery; //noconflict reference to jquery var jqueryPath = "https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"; var jqueryVersion = "1.8.3"; var scriptTag; //reference to the html script tag /******** Get reference to self (scriptTag) *********/ var allScripts = document.getElementsByTagName('script'); var targetScripts = []; for (var i in allScripts) { var name = allScripts[i].src if(name && name.indexOf(scriptName) > 0) targetScripts.push(allScripts[i]); } scriptTag = targetScripts[targetScripts.length - 1]; /******** helper function to load external scripts *********/ function loadScript(src, onLoad) { var script_tag = document.createElement('script'); script_tag.setAttribute("type", "text/javascript"); script_tag.setAttribute("src", src); if (script_tag.readyState) { script_tag.onreadystatechange = function () { if (this.readyState == 'complete' || this.readyState == 'loaded') { onLoad(); } }; } else { script_tag.onload = onLoad; } (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } /******** helper function to load external css *********/ function loadCss(href) { var link_tag = document.createElement('link'); link_tag.setAttribute("type", "text/css"); link_tag.setAttribute("rel", "stylesheet"); link_tag.setAttribute("href", href); (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link_tag); } /******** load jquery into 'jQuery' variable then call main ********/ if (window.jQuery === undefined || window.jQuery.fn.jquery !== jqueryVersion) { loadScript(jqueryPath, initjQuery); } else { initjQuery(); } function initjQuery() { jQuery = window.jQuery.noConflict(true); main(); } function main() { function PopupCenter(url, title, w, h) { // Fixes dual-screen position Most browsers Firefox var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var left = ((width / 2) - (w / 2)) + dualScreenLeft; var top = ((height / 2) - (h / 2)) + dualScreenTop; var newWindow = window.open(url, title, 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); // Puts focus on the newWindow if (window.focus) { newWindow.focus(); } } function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email.toLowerCase()); } var respondBtn = document.getElementsByClassName("respond-enquire-button"); if (respondBtn) { [].forEach.call(respondBtn, function(btn) { btn.addEventListener("click", function() { var agencyid = btn.getAttribute("data-agencyid"); var agentemail = btn.getAttribute("data-agentemail"); var propertyaddress = btn.getAttribute("data-propertyaddress"); var okcontinue = true; if (agencyid && !isNaN(agencyid) && agencyid > 0) { //ok } else { okcontinue = false; } if (agentemail && validateEmail(agentemail) == false) { agentemail = ""; } if (propertyaddress && propertyaddress.length < 15) { okcontinue = false; } if (okcontinue == true) { var enquiryURL = "https://respond.realmatic.com.au/api/agencyenquiry.php?a="+agencyid+"&e="+agentemail+"&p="+propertyaddress; PopupCenter(encodeURI(enquiryURL), "Property Enquiry", 500, 665); } else { alert("This button is not configured correctly. Please contact us directly."); } }); }); } } })();