$form->{path} entfernt und hardcodiert auf bin/mozilla gesetzt.
[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   wrongNumberFormat = wrongFormat + " ( " + numberformat + " ) ";  
11 }
12
13 function setupDateFormat(setDateFormat, setWrongDateFormat) {
14   dateFormat = setDateFormat;
15   wrongDateFormat = setWrongDateFormat + " ( " + setDateFormat + " ) ";
16   formatArray = new Array();
17   if(dateFormat.match(/^\w\w\W/)) {
18     seperator = dateFormat.substring(2,3);
19   }
20   else {
21     seperator = dateFormat.substring(4,5);
22   }
23 }
24
25 function centerParms(width,height,extra) {
26   xPos = (screen.width - width) / 2;
27   yPos = (screen.height - height) / 2;
28
29   string = "left=" + xPos + ",top=" + yPos;
30
31   if (extra)
32     string += "width=" + width + ",height=" + height;
33
34   return string;
35 }
36
37 function set_longdescription_window(input_name) {
38   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
39   var name = document.getElementsByName(input_name)[0].value;
40   url = "common.pl?" +
41     "action=set_longdescription&" +
42     "login=" +  encodeURIComponent(document.getElementsByName("login")[0].value)+ "&"+
43     "password=" + encodeURIComponent(document.getElementsByName("password")[0].value) + "&" +
44     "longdescription=" + escape(document.getElementsByName(input_name)[0].value) + "&" +
45     "input_name=" + escape(input_name) + "&"
46   window.open(url, "_new_generic", parm);
47   }
48
49 function check_right_number_format(input_name) {
50   var decnumbers = input_name.value.split(decpoint);
51   if(thpoint) {
52     var thnumbers = input_name.value.split(thpoint);
53     if(thnumbers[thnumbers.length-1].match(/.+decpoint$/g)) {
54       thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-1);
55     }
56     if(thnumbers[thnumbers.length-1].match(/.+decpoint\d$/g)) {
57       thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-2);
58     }  
59     if(thnumbers[thnumbers.length-1].match(/.+decpoint\d\d$/g)) {
60       thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-3);
61     }  
62     for(var i = 1; i < thnumbers.length; i++) {
63       if(!thnumbers[i].match(/\d\d\d/g)) {
64         return show_alert_and_focus(input_name, wrongNumberFormat);
65       }
66       if(thnumbers[i].match(/.*decpoint.*|.*thpoint.*/g)) {
67         return show_alert_and_focus(input_name, wrongNumberFormat);
68       }
69     }
70     if(decnumbers.length > 2 || (decnumbers.length > 1 ? (decnumbers[1].length > 2) : false)) {
71       return show_alert_and_focus(input_name, wrongNumberFormat);
72     }
73   }
74   else {
75     if(decnumbers.length > 1 || decnumbers[0].length > 2) {
76       return show_alert_and_focus(input_name, wrongNumberFormat);
77     }
78   }
79 }
80
81 function check_right_date_format(input_name) {
82   if(input_name.value == "") {
83     return true;
84   }
85   var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
86   if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
87     matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
88     if(!matching.test(input_name.value)) {
89       return show_alert_and_focus(input_name, wrongDateFormat);
90     }
91   }
92   else {
93     if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) { 
94       return show_alert_and_focus(input_name, wrongDateFormat);
95     }
96   }
97 }
98
99 function validate_dates(input_name_1, input_name_2) {
100   var tempArray1 = new Array();
101   var tempArray2 = new Array();
102   tempArray1 = getDateArray(input_name_1);
103   tempArray2 = getDateArray(input_name_2);
104   if(check_right_date_format(input_name_1) && check_right_date_format(input_name_2)) {
105     if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(tempArray1[0], tempArray1[1], tempArray1[2])).getTime())) {
106       show_alert_and_focus(input_name_1, wrongDateFormat);
107       return show_alert_and_focus(input_name_2, wrongDateFormat);
108     }
109     if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(1900, 1, 1)).getTime())) {
110       show_alert_and_focus(input_name_1, wrongDateFormat);
111       return show_alert_and_focus(input_name_2, wrongDateFormat);
112     }
113   }
114 }
115
116 function getDateArray(input_name) {
117   formatArray[2] = input_name.value.substring(dateFormat.indexOf("d"), 2);
118   formatArray[1] = input_name.value.substring(dateFormat.indexOf("m"), 2);
119   formatArray[0] = input_name.value.substring(dateFormat.indexOf("y"), (dateFormat.length == 10 ? 4 : 2));
120   if(dateFormat.length == 8) {
121     formatArray[0] += (formatArray[0] < 70 ? 2000 : 1900);
122   }
123   return formatArray;
124 }
125
126 function show_alert_and_focus(input_name, errorMessage) {
127   input_name.select();
128   alert(errorMessage + "\n\r\n\r--> " + input_name.value);
129   input_name.focus();
130   return false;
131 }
132