OSDN Git Service

- default spellingミスの修正
[elecoma/elecoma.git] / public / javascripts / application.js
1 // Place your application-specific JavaScript functions and classes here
2 // This file is automatically included by javascript_include_tag :defaults
3     
4 function fnSubWindow(URL,Winname,Wwidth,Wheight){
5 //サブウィンドウを表示
6   var WIN;
7   WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
8   WIN.focus();
9 }
10
11 function address_by_zip(zipcode_first, zipcode_second, prefecture_name, city_name, town_name, prefecture_id, controller){
12 //郵便番号から住所を自動入力
13   var first = $F(zipcode_first);
14   var second = $F(zipcode_second);
15   if (first.length != 3 || second.length != 4) {
16     alert("郵便番号を入力してください。");
17     return;
18   }
19   var params = $H({first: first, second: second});
20   new Ajax.Request('/'+controller+'/get_address?' + params.toQueryString(), {
21     method: "get",
22     onSuccess: function(request) { 
23       var data = request.responseText.split("/");
24       if($(prefecture_name) != null){
25         $(prefecture_name).value = data[0];
26       }
27       $(city_name).value = data[1] + data[2];
28       if($(prefecture_id) != null){
29         $(prefecture_id).value = data[3];
30       }
31     },
32     onFailure: function(request) { alert("該当する郵便番号がありません") 
33     }
34   });
35
36 }
37
38 Event.observe(window, 'load', function() {
39   var img = document.createElement('img');
40   document.body.appendChild(img);
41   img.id = 'loading-image';
42   img.alt = 'loading...';
43   with (img.style) {
44     display = 'none';
45     position = 'fixed';
46     top = '50%';
47     left = '50%';
48   }
49   img.src = '/images/indicator.gif';
50   if (img.width) {
51     img.style.marginLeft = String(-(img.width / 2)) + 'px';
52     img.style.marginTop = String(-(img.height / 2)) + 'px';
53   }
54 });
55
56 Ajax.Responders.register({
57   onCreate: function() {
58     Element.show('loading-image');
59     //document.body.style.cursor = 'wait';
60   },
61   onComplete: function() {
62     if(Ajax.activeRequestCount == 0){
63       Element.hide('loading-image');
64       //document.body.style.cursor = 'auto';
65     }
66   }
67 });