Advertisement
Guest User

Untitled

a guest
Nov 10th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. //##layne## shipping js
  2. $(document).ready(function () {
  3. $("input[name='postcode']").keyup(function(){
  4. var tmptxt=$(this).val();
  5. $(this).val(tmptxt.replace(/\D|^0/g,''));
  6. if(tmptxt.length > 4){
  7. $(this).val(tmptxt.substring(-1,4));
  8. }
  9. }).bind("paste",function(){
  10. var tmptxt=$(this).val();
  11. $(this).val(tmptxt.replace(/\D|^0/g,''));
  12. if(tmptxt.length > 4){
  13. $(this).val(tmptxt.substring(-1,4));
  14. }
  15. }).css("ime-mode", "disabled");
  16. $("input[name='postcode'], #postcode").each(function (index,e) {
  17. $(this).after('<input name="suburb" type="hidden">');
  18. var cache = {};
  19. $(e).autocomplete({
  20. source: function(request, response ) {
  21. var postcode = request.term;
  22. if ( postcode in cache ) {
  23. response( $.map( cache[ postcode ], function( item ) {
  24. return {
  25. label: item.label,
  26. value:item.value,
  27. suburb:item.suburb,
  28. }
  29. }));
  30. return;
  31. }
  32. $.ajax({
  33. url: 'index.php?route=information/dealers/suburb',
  34. dataType: "json",
  35. data:{
  36. postcode: request.term,
  37. },
  38. success: function( data ) {
  39. cache[ postcode ] = data;
  40. response( $.map( data, function( item ) {
  41. return {
  42. label: item.label,
  43. value:item.value,
  44. suburb:item.suburb,
  45. }
  46. }));
  47. }
  48. });
  49. },
  50. minLength: 3,
  51. select: function( event, ui ) {
  52. $("#search_dealer input[name='suburb']").val(ui.item.suburb);
  53. getDealers(ui.item.value, ui.item.suburb);
  54. }
  55. });
  56. });
  57.  
  58.  
  59. function getDealers(postcode,suburb){
  60. var postcode = postcode ? postcode : $("#search_dealer input[name='postcode']").val();
  61. var suburb = suburb ? suburb : $("#search_dealer input[name='suburb']").val();
  62.  
  63. /*
  64. var weight = $("#shipping input[name='weight']").val();
  65. var length = $("#shipping input[name='length']").val();
  66. var width = $("#shipping input[name='width']").val();
  67. var height = $("#shipping input[name='height']").val();
  68. */
  69.  
  70. $.post(
  71. "index.php?route=information/dealers/query",
  72. {postcode:postcode, suburb:suburb},
  73. function(result){
  74. $("#result").html(result);
  75. }
  76. );
  77. createMaps();
  78.  
  79. }
  80.  
  81. function createMaps(){
  82. var map = new google.maps.Map(document.getElementById("map"), {
  83. center: new google.maps.LatLng(-37.814107, 144.963280),
  84. zoom: 13,
  85. mapTypeId: 'roadmap'
  86. });
  87. var infoWindow = new google.maps.InfoWindow;
  88.  
  89. // Change this depending on the name of your PHP file
  90. // downloadUrl("catalog/controller/information/dealers.php", function(query) {
  91. /*
  92.  
  93. if (window.XMLHttpRequest)
  94. {// code for IE7+, Firefox, Chrome, Opera, Safari
  95. xmlhttp=new XMLHttpRequest();
  96. }
  97. else
  98. {// code for IE6, IE5
  99. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  100. }
  101. xmlhttp.open("GET","catalog/view/javascript/data.xml",false);
  102. xmlhttp.send();
  103.  
  104. xmlDoc=xmlhttp.responseXML;
  105. //alert(xmlDoc.documentElement.tagName)
  106. alert(xmlDoc);
  107. */
  108.  
  109. /*
  110. var xmlDoc=loadXMLDoc("data.xml");
  111. alert(xmlDoc);
  112. */
  113.  
  114. /*
  115. var error = "";
  116. var file = "data.xml";
  117. try //Internet Explorer
  118. {
  119. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  120. xmlDoc.async=false;
  121. xmlDoc.load(file);
  122. }
  123. catch(e)
  124. {
  125. //alert("1");
  126. try //Firefox, Mozilla, Opera, etc.
  127. {
  128. xmlDoc=document.implementation.createDocument("","",null);
  129. xmlDoc.async=false;
  130. xmlDoc.load(file);
  131. }
  132. catch(e)
  133. {
  134. try //Google Chrome
  135. {
  136. //alert("2");
  137. var xmlhttp = new window.XMLHttpRequest();
  138.  
  139. xmlhttp.open("GET","data.xml",false);
  140.  
  141. xmlhttp.send(null);
  142. //alert(xmlhttp.getResponseHeader("Content-Length"));
  143. //alert("3");
  144. //alert(xmlhttp.readyState);
  145. //alert(xmlhttp.getAllResponseHeaders());
  146.  
  147. xmlDoc = xmlhttp.responseXML.documentElement;
  148.  
  149. }
  150. catch(e)
  151. {
  152. error=e.message;
  153. //alert(error);
  154. }
  155. }
  156. }
  157. */
  158.  
  159. //downloadUrl("data.xml", function(data) {
  160. downloadUrl("http://www.goskitz.com.au/index.php?route=information/dealers", function(data) {
  161. //downloadUrl("http://www.goskitz.com.au/catalog/view/javascript/data.xml", function(data) {
  162. // alert("1");
  163. var xml = data.responseXML;
  164. // alert("2");
  165. //var xml = parseXml(data);
  166. //alert(xml);
  167. var markers = xml.documentElement.getElementsByTagName("marker");
  168. //alert(markers);
  169. //alert("3");
  170. //alert("length is : "+ markers.length);
  171. for (var i = 0; i < markers.length; i++) {
  172. alert("ssas");
  173. var name = markers[i].getAttribute("name");
  174. var address = markers[i].getAttribute("address");
  175. var point = new google.maps.LatLng(
  176. parseFloat(markers[i].getAttribute("lat")),
  177. parseFloat(markers[i].getAttribute("lng")));
  178. var html = "<b>" + name + "</b> <br/>" + address;
  179. var icon = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
  180.  
  181. var marker = new google.maps.Marker({
  182. map: map,
  183. position: point,
  184. icon: icon.icon
  185. });
  186. bindInfoWindow(marker, map, infoWindow, html);
  187. }
  188. });
  189. }
  190.  
  191. function bindInfoWindow(marker, map, infoWindow, html) {
  192. google.maps.event.addListener(marker, 'click', function() {
  193. infoWindow.setContent(html);
  194. infoWindow.open(map, marker);
  195. });
  196. }
  197.  
  198. function downloadUrl(url, callback) {
  199. var request = window.ActiveXObject ?
  200. new ActiveXObject('Microsoft.XMLHTTP') :
  201. new XMLHttpRequest;
  202.  
  203. request.onreadystatechange = function() {
  204. if (request.readyState == 4) {
  205. request.onreadystatechange = doNothing;
  206. callback(request, request.status);
  207. }
  208. };
  209. //alert(url);
  210. request.open('GET', url, true);
  211. request.send(null);
  212. //alert(request.responseText);
  213. //alert(request);
  214. //alert(request.getAllResponseHeaders());
  215. }
  216.  
  217. function parseXml(str) {
  218. if (window.ActiveXObject) {
  219. var doc = new ActiveXObject('Microsoft.XMLDOM');
  220. doc.loadXML(str);
  221. return doc;
  222. } else if (window.DOMParser) {
  223. return (new DOMParser).parseFromString(str, 'text/xml');
  224. }
  225. }
  226.  
  227. function doNothing() {}
  228.  
  229. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement