// Secure this javascript from being called and executed on behalf of outside websites. var d=new Array("chocomap.com"); var domaincheck=document.location.href; //retrieve the current URL of user browser var accepted_ok=false; //set acess to false by default if(domaincheck.indexOf("http")!=-1) { //if this is a http request for(r=0;r 1) { return result.childNodes[1].nodeValue; } else { if(result.firstChild == null) return ""; return result.firstChild.nodeValue; } } else { return "n/a"; } } function loadXML(url) { if(window.XMLHttpRequest) { // Native XMLHttpRequest call req = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE/Windows ActiveX call req = new ActiveXObject("Microsoft.XMLHTTP"); } if(req) { req.open("POST", "http://chocomap.com/_secureXMLReq.php", true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.onreadystatechange = processReq; req.send(url); // if the request doesn't complete in 10 seconds, something is up. //this.timeout = window.setTimeout("abort();", 10000); /* Add temporary feedback that the request has been sent */ /* var loadingImg = document.createElement('img'); loadingImg.src = '/_rs/img/working.gif'; target.getElementsByTagName('p')[0].appendChild(loadingImg); target.ajaxInProgress = true; */ } } function processReq() { if(req.readyState==4) { if(req.status==200) { //GLog.write(req.responseText); //GLog.write(req.responseXML.firstChild.nextSibling.nodeName); //var node = req.responseXML.getElementsByTagName("session"); //if(node && (node.length > 0)) var session = GXml.value(node[0]); //var session = req.responseXML.getElementsByTagName("session")[0].firstChild.data; //if(session == "1") { // session 1 means it was a good connection, within the alowed session time. var node = req.responseXML.getElementsByTagName("errorMessage") if(node && (node.length > 0)) { errorMessage = GXml.value(node[0]); alert(errorMessage); } else { var node = req.responseXML.getElementsByTagName("method") if(node && (node.length > 0)) { method = GXml.value(node[0]); eval(method+"(req)"); } } //} } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } } function searchByContactCity(a) { if(a) { // Error messages are stopped before getting back here at processReqChangeMain(). //GLog.write(a.responseText); //alert(a.responseText); map.clearOverlays(); GEvent.addListener(map, "moveend", function(){center = map.getCenter();}); GEvent.addListener(map, "zoomend", function(){zoom = map.getZoom();}); GEvent.addListener(map, "mouseover", function(){map.showControls();}); GEvent.addListener(map, "mouseout", function(){map.hideControls();}); // ===== Start with an empty GLatLngBounds object ===== var bounds = new GLatLngBounds(); var prop = a.responseXML.getElementsByTagName("prop"); for(var i = 0; i < prop.length; i++) { var company_id = ""; var contact_id = ""; var lat = ""; var lng = ""; var name = ""; var url = ""; var company_note = ""; var aptUnit = ""; var address = ""; var city = ""; var prov_stat = ""; var post_zip = ""; var point = ""; company_id = prop[i].getAttribute("company_id"); contact_id = prop[i].getAttribute("contact_id"); lat = prop[i].getAttribute("lat"); lng = prop[i].getAttribute("lng"); name = getElementTextNS("", "name", prop[i], 0); url = getElementTextNS("", "url", prop[i], 0); company_note = getElementTextNS("", "company_note", prop[i], 0); aptUnit = getElementTextNS("", "aptUnit", prop[i], 0); address = getElementTextNS("", "address", prop[i], 0); city = getElementTextNS("", "city", prop[i], 0); prov_stat = getElementTextNS("", "prov_stat", prop[i], 0); post_zip = getElementTextNS("", "post_zip", prop[i], 0); point = new GLatLng(parseFloat(lat), parseFloat(lng)); map.addOverlay(searchCreateMarker(point, company_id, contact_id, lat, lng, name, url, company_note, aptUnit, address, city, prov_stat, post_zip)); // ==== Each time a point is found, extent the bounds to include it. ===== bounds.extend(point); openTip("map", 390, 25); } // ===== Determine the zoom level from the bounds ===== map.setZoom(map.getBoundsZoomLevel(bounds)); // ===== Determine the centre from the bounds. ====== var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2; var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2; map.panTo(new GLatLng(clat, clng)); center = new GLatLng(clat, clng); // Save the maps possition after 1.5 seconds have gone by to allow for panning. window.setTimeout(function() {map.savePosition();}, 1500); } else { var url = "pid=1"; if(document.getElementById("contactCity").value.length > 0) { url += "&contactCity=" + encodeURIComponent(document.getElementById("contactCity").value); } //GLog.write(url); //loadXML("/_secureXMLReq.php?" + url); loadXML(url); } } function searchByCompanyName(a) { if(a) { // Error messages are stopped before getting back here at processReqChangeMain(). //GLog.write(a.responseText); //alert(a.responseText); map.clearOverlays(); GEvent.addListener(map, "moveend", function(){center = map.getCenter();}); GEvent.addListener(map, "zoomend", function(){zoom = map.getZoom();}); GEvent.addListener(map, "mouseover", function(){map.showControls();}); GEvent.addListener(map, "mouseout", function(){map.hideControls();}); // ===== Start with an empty GLatLngBounds object ===== var bounds = new GLatLngBounds(); var prop = a.responseXML.getElementsByTagName("prop"); for(var i = 0; i < prop.length; i++) { var comID = ""; var conID = ""; var lat = ""; var lng = ""; var name = ""; var url = ""; var company_note = ""; var aptUnit = ""; var address = ""; var city = ""; var prov_stat = ""; var post_zip = ""; var point = ""; comID = prop[i].getAttribute("company_id"); conID = prop[i].getAttribute("contact_id"); lat = prop[i].getAttribute("lat"); lng = prop[i].getAttribute("lng"); name = getElementTextNS("", "name", prop[i], 0); url = getElementTextNS("", "url", prop[i], 0); company_note = getElementTextNS("", "company_note", prop[i], 0); aptUnit = getElementTextNS("", "aptUnit", prop[i], 0); address = getElementTextNS("", "address", prop[i], 0); city = getElementTextNS("", "city", prop[i], 0); prov_stat = getElementTextNS("", "prov_stat", prop[i], 0); post_zip = getElementTextNS("", "post_zip", prop[i], 0); point = new GLatLng(parseFloat(lat), parseFloat(lng)); map.addOverlay(searchCreateMarker(point, comID, conID, lat, lng, name, url, company_note, aptUnit, address, city, prov_stat, post_zip)); // ==== Each time a point is found, extent the bounds to include it. ===== bounds.extend(point); openTip("map", 390, 25); } // ===== Determine the zoom level from the bounds ===== map.setZoom(map.getBoundsZoomLevel(bounds)); // ===== Determine the centre from the bounds. ====== var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2; var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2; map.panTo(new GLatLng(clat, clng)); center = new GLatLng(clat, clng); // Save the maps possition after 1.5 seconds have gone by to allow for panning. window.setTimeout(function() {map.savePosition();}, 1500); } else { var url = "pid=2"; if(document.getElementById("companyName").value.length > 0) { url += "&companyName=" + encodeURIComponent(document.getElementById("companyName").value); } //GLog.write(url); //loadXML("/_secureXMLReq.php?" + url); loadXML(url); } } function searchCreateMarker(point, comID, conID, lat, lng, name, url, company_note, aptUnit, address, city, prov_stat, post_zip) { //GLog.write(company); var marker = new GMarker(point, {icon:icon}); GEvent.addListener(marker, "click", function() { if(map.getInfoWindow().getPoint() && map.getInfoWindow().getPoint().equals(marker.getPoint()) && !map.getInfoWindow().isHidden()) { map.closeInfoWindow(); //map.panTo(center); } else { // Next we need to trim off any var pos = ""; var urlPub = ""; if(url.indexOf("/") != -1) { pos = url.indexOf("/"); urlPub = url.substring(0, pos); } else { urlPub = url; } var buf = '' + '' + '' + '' + '' + '' + '' + '
' + name + '
'; if(url != "") { buf += 'http://' + urlPub + ''; } else { buf += 'Website address not posted yet.'; } buf += '
'; if(company_note != "") { buf += company_note; } else { buf += 'Chocolate products note not posted yet.'; } buf += '
' + aptUnit + ' ' + address + '
' + city + ', ' + prov_stat; if(post_zip != "") { buf += ', ' + post_zip; } buf += '
Review & Ratelat:' + lat + ' lng:' + lng + 'Edit
'; marker.openInfoWindowHtml(buf,{maxWidth:350}); } }); return marker; } function closeTip() { document.getElementById('tip').style.display='none'; document.getElementById('ifrm_tip').style.display='none'; } var open_tip = false; function openTip(theBtn, X, Y) { if(open_tip == false) { if(!X) X = 10; if(!Y) Y = 10; var DivWait = document.getElementById('tip'); var IfrWait = document.getElementById('ifrm_tip'); var posXY = getoffset(document.getElementById(theBtn)); posX = posXY[0] + parseInt(X); posY = posXY[1] + parseInt(Y); DivWait.style.top = posX + "px"; DivWait.style.left = posY + "px"; DivWait.style.display = "block"; DivWait.style.zindex = "9"; IfrWait.style.width = DivWait.offsetWidth; IfrWait.style.height = DivWait.offsetHeight; IfrWait.style.top = DivWait.style.top; IfrWait.style.left = DivWait.style.left; IfrWait.style.zIndex = DivWait.style.zIndex - 1; IfrWait.style.display = "block"; setTimeout("closeTip();", 10000); open_tip = true; } }