1 function centerParms(width,height,extra) {
2 xPos = (screen.width - width) / 2;
3 yPos = (screen.height - height) / 2;
5 string = "left=" + xPos + ",top=" + yPos;
8 string += "width=" + width + ",height=" + height;
13 function check_right_number_format(input_name) {
14 var decpoint = kivi._number_format.decimalSep;
15 var thpoint = kivi._number_format.thousandSep;
17 var test_val = input_name.value;
18 if(thpoint && thpoint == ','){
19 test_val = test_val.replace(/,/g, '');
21 if(thpoint && thpoint == '.'){
22 test_val = test_val.replace(/\./g, '');
24 if(thpoint && thpoint == "'"){
25 test_val = test_val.replace(/\'/g, '');
27 if(decpoint && decpoint == ','){
28 test_val = test_val.replace(/,/g, '.');
30 var forbidden = test_val.match(/[^\s\d\(\)\-\+\*\/\.]/g);
31 if (forbidden && forbidden.length > 0 ){
32 return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
38 return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
41 return annotate(input_name);
44 function check_right_date_format(input_name) {
45 if(input_name.value == "") {
50 var dateFormat = kivi.myconfig.dateformat;
51 var seperator = kivi._date_format.sep;
53 if ( ( input_name.value.match(/^\d+$/ ) ) && !(dateFormat.lastIndexOf("y") == 3) ) {
54 // date shortcuts for entering date without separator for three date styles, e.g.
55 // 31122014 -> 12.04.2014
56 // 12312014 -> 12/31/2014
57 // 31122014 -> 31/12/2014
59 if (input_name.value.match(/^\d{8}$/)) {
60 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
61 } else if (input_name.value.match(/^\d{6}$/)) {
62 // 120414 -> 12.04.2014
63 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
64 } else if (input_name.value.match(/^\d{4}$/)) {
66 var today = new Date();
67 var year = today.getYear();
68 if (year < 999) year += 1900;
69 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)$/, "$1" + seperator + "$2");
70 input_name.value = input_name.value + seperator + year;
71 } else if ( input_name.value.match(/^\d{1,2}$/ ) ) {
72 // assume the entry is the day of the current month and current year
73 var today = new Date();
74 var day = input_name.value;
75 var month = today.getMonth() + 1;
76 var year = today.getYear();
77 if( day.length == 1 && day < 10) {
83 if (year < 999) year += 1900;
84 if ( dateFormat.lastIndexOf("d") == 1) {
85 input_name.value = day + seperator + month + seperator + year;
87 input_name.value = month + seperator + day + seperator + year;
92 var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
93 if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
94 matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
95 if(!matching.test(input_name.value)) {
96 return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
100 if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) {
101 return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
104 return annotate(input_name);
107 function annotate(input_name, error, expected) {
108 var $e = $(input_name);
110 $e.addClass('kivi-validator-invalid');
111 var tooltip = error + ' (' + expected + ')';
112 if ($e.hasClass('tooltipstered'))
113 $e.tooltipster('destroy');
117 theme: 'tooltipster-light',
119 $e.tooltipster('show');
121 $e.removeClass('kivi-validator-invalid');
122 if ($e.hasClass('tooltipstered'))
123 $e.tooltipster('destroy');
127 function get_input_value(input_name) {
128 var the_input = document.getElementsByName(input_name);
129 if (the_input && the_input[0])
130 return the_input[0].value;
134 function set_cursor_position(n) {
135 $('[name=' + n + ']').focus();
138 function focussable(e) {
139 return e && e.name && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
142 function set_cursor_to_first_element(){
143 var df = document.forms;
144 for (var f = 0; f < df.length; f++)
145 for (var i = 0; i < df[f].length; i++)
146 if (focussable(df[f][i]))
147 try { df[f][i].focus(); return } catch (er) { }
150 function getElementByIndirectName(name){
151 var e = document.getElementsByName(name)[0];
152 if (e) return document.getElementsByName(e.value)[0];
155 function focus_by_name(name){
156 var f = getElementByIndirectName(name);
158 set_cursor_position(f.name);
165 $('input').focus(function(){
166 if (focussable(this)) window.focused_element = this;
169 // setting focus inside a tabbed area fails if this is encountered before the tabbing is complete
170 // in that case the elements count as hidden and jquery aborts .focus()
171 setTimeout(function(){
172 // Lowest priority: first focussable element in form.
173 set_cursor_to_first_element();
175 // Medium priority: class set in template
176 var initial_focus = $(".initial_focus").filter(':visible')[0];
178 $(initial_focus).focus();
180 // special: honour focus_position
181 // if no higher priority applies set focus to the appropriate element
182 if ($("#display_row")[0] && kivi.myconfig.focus_position) {
183 switch(kivi.myconfig.focus_position) {
184 case 'last_partnumber' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="partnumber"]').focus(); break;
185 case 'last_description' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="description"]').focus(); break;
186 case 'last_qty' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="qty"]').focus(); break;
187 case 'new_partnumber' : $('#display_row tr:gt(1) input[name*="partnumber"]').focus(); break;
188 case 'new_description' : $('#display_row tr:gt(1) input[name*="description"]').focus(); break;
189 case 'new_qty' : $('#display_row tr:gt(1) input[name*="qty"]').focus(); break;
193 // all of this screws with the native location.hash focus, so reimplement this as well
195 var hash_name = location.hash.substr(1);
196 var $hash_by_id = $(location.hash + ':visible');
197 if ($hash_by_id.length > 0) {
198 $hash_by_id.get(0).focus();
200 var $by_name = $('[name=' + hash_name + ']:visible');
201 if ($by_name.length > 0) {
202 $by_name.get(0).focus();
207 // legacy. some forms install these
208 if (typeof fokus == 'function') { fokus(); return; }
209 if (focus_by_name('cursor_fokus')) return;
213 $('form').submit(function(){
214 if (window.focused_element)
215 document.forms[0].cursor_fokus.value = window.focused_element.name;