Erweiterung der common.js um die function setupPoints(numberformat, wrongFormat)...
[kivitendo-erp.git] / js / common.js
1
2 function setupPoints(numberformat, wrongFormat) {
3   decpoint = numberformat.substring((numberformat.substring(1, 2).match(/.|,/) ? 5 : 4), (numberformat.substring(1, 2).match(/.|,/) ? 6 : 5));
4   if (numberformat.substring(1, 2).match(/.|,/)) {
5     thpoint = numberformat.substring(1, 2); 
6   }
7   else {
8     thpoint = null;
9   }
10   wrongformat = wrongFormat;  
11 }
12
13 function centerParms(width,height,extra) {
14   xPos = (screen.width - width) / 2;
15   yPos = (screen.height - height) / 2;
16
17   string = "left=" + xPos + ",top=" + yPos;
18
19   if (extra)
20     string += "width=" + width + ",height=" + height;
21
22   return string;
23 }
24
25 function set_longdescription_window(input_name) {
26   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
27   var name = document.getElementsByName(input_name)[0].value;
28   url = "common.pl?" +
29     "action=set_longdescription&" +
30     "login=" +  encodeURIComponent(document.getElementsByName("login")[0].value)+ "&"+
31     "password=" + encodeURIComponent(document.getElementsByName("password")[0].value) + "&" +
32     "path=" + encodeURIComponent(document.getElementsByName("path")[0].value) + "&" +
33     "longdescription=" + escape(document.getElementsByName(input_name)[0].value) + "&" +
34     "input_name=" + escape(input_name) + "&"
35   window.open(url, "_new_generic", parm);
36   }
37
38   function check_right_date_format(input_name) {
39     var decnumbers = input_name.value.split(decpoint);
40     if(thpoint) {
41       var thnumbers = input_name.value.split(thpoint);
42       if(thnumbers[thnumbers.length-1].match(/.+decpoint$/g)) {
43         thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-1);
44       }
45       if(thnumbers[thnumbers.length-1].match(/.+decpoint\d$/g)) {
46         thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-2);
47       }  
48       if(thnumbers[thnumbers.length-1].match(/.+decpoint\d\d$/g)) {
49         thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-3);
50       }  
51       for(var i = 1; i < thnumbers.length; i++) {
52         if(!thnumbers[i].match(/\d\d\d/g)) {
53           return show_alert_and_focus(input_name);
54         }
55         if(thnumbers[i].match(/.*decpoint.*|.*thpoint.*/g)) {
56           return show_alert_and_focus(input_name);
57         }
58       }
59       if(decnumbers.length > 2 || (decnumbers.length > 1 ? (decnumbers[1].length > 2) : false)) {
60         return show_alert_and_focus(input_name);
61       }
62     }
63     else {
64       if(decnumbers.length > 1 || decnumbers[0].length > 2) {
65         return show_alert_and_focus(input_name);
66       }
67     }
68   }
69   
70   function show_alert_and_focus(input_name) {
71     input_name.select();
72     alert(wrongformat + "\n\r\n\r--> " + input_name.value);
73     input_name.focus();
74     return false;
75   }
76