1 function setupPoints(numberformat, wrongFormat) {
2 decpoint = numberformat.substring((numberformat.substring(1, 2).match(/\.|\,|\'/) ? 5 : 4), (numberformat.substring(1, 2).match(/\.|\,|\'/) ? 6 : 5));
3 if (numberformat.substring(1, 2).match(/\.|\,|\'/)) {
4 thpoint = numberformat.substring(1, 2);
9 wrongNumberFormat = wrongFormat + " ( " + numberformat + " ) ";
12 function setupDateFormat(setDateFormat, setWrongDateFormat) {
13 dateFormat = setDateFormat;
14 wrongDateFormat = setWrongDateFormat + " ( " + setDateFormat + " ) ";
15 formatArray = new Array();
16 if(dateFormat.match(/^\w\w\W/)) {
17 seperator = dateFormat.substring(2,3);
20 seperator = dateFormat.substring(4,5);
24 function centerParms(width,height,extra) {
25 xPos = (screen.width - width) / 2;
26 yPos = (screen.height - height) / 2;
28 string = "left=" + xPos + ",top=" + yPos;
31 string += "width=" + width + ",height=" + height;
36 function check_right_number_format(input_name) {
37 if(decpoint && thpoint && thpoint == decpoint) {
38 return show_alert_and_focus(input_name, wrongNumberFormat);
40 var test_val = input_name.value;
41 if(thpoint && thpoint == ','){
42 test_val = test_val.replace(/,/g, '');
44 if(thpoint && thpoint == '.'){
45 test_val = test_val.replace(/\./g, '');
47 if(thpoint && thpoint == "'"){
48 test_val = test_val.replace(/\'/g, '');
50 if(decpoint && decpoint == ','){
51 test_val = test_val.replace(/,/g, '.');
53 var forbidden = test_val.match(/[^\s\d\(\)\-\+\*\/\.]/g);
54 if (forbidden && forbidden.length > 0 ){
55 return show_alert_and_focus(input_name, wrongNumberFormat);
61 return show_alert_and_focus(input_name, wrongNumberFormat);
66 function check_right_date_format(input_name) {
67 if(input_name.value == "") {
71 if ( ( input_name.value.match(/^\d+$/ ) ) && !(dateFormat.lastIndexOf("y") == 3) ) {
72 // date shortcuts for entering date without separator for three date styles, e.g.
73 // 31122014 -> 12.04.2014
74 // 12312014 -> 12/31/2014
75 // 31122014 -> 31/12/2014
77 if (input_name.value.match(/^\d{8}$/)) {
78 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
79 } else if (input_name.value.match(/^\d{6}$/)) {
80 // 120414 -> 12.04.2014
81 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
82 } else if (input_name.value.match(/^\d{4}$/)) {
84 var today = new Date();
85 var year = today.getYear();
86 if (year < 999) year += 1900;
87 input_name.value = input_name.value.replace(/^(\d\d)(\d\d)$/, "$1" + seperator + "$2");
88 input_name.value = input_name.value + seperator + year;
89 } else if ( input_name.value.match(/^\d{1,2}$/ ) ) {
90 // assume the entry is the day of the current month and current year
91 var today = new Date();
92 var day = input_name.value;
93 var month = today.getMonth() + 1;
94 var year = today.getYear();
95 if( day.length == 1 && day < 10) {
101 if (year < 999) year += 1900;
102 if ( dateFormat.lastIndexOf("d") == 1) {
103 input_name.value = day + seperator + month + seperator + year;
105 input_name.value = month + seperator + day + seperator + year;
110 var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
111 if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
112 matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
113 if(!matching.test(input_name.value)) {
114 return show_alert_and_focus(input_name, wrongDateFormat);
118 if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) {
119 return show_alert_and_focus(input_name, wrongDateFormat);
124 function show_alert_and_focus(input_name, errorMessage) {
126 alert(errorMessage + "\n\r\n\r--> " + input_name.value);
131 function get_input_value(input_name) {
132 var the_input = document.getElementsByName(input_name);
133 if (the_input && the_input[0])
134 return the_input[0].value;
138 function set_cursor_position(n) {
139 $('[name=' + n + ']').focus();
142 function focussable(e) {
143 return e && e.name && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
146 function set_cursor_to_first_element(){
147 var df = document.forms;
148 for (var f = 0; f < df.length; f++)
149 for (var i = 0; i < df[f].length; i++)
150 if (focussable(df[f][i]))
151 try { df[f][i].focus(); return } catch (er) { }
154 function getElementByIndirectName(name){
155 var e = document.getElementsByName(name)[0];
156 if (e) return document.getElementsByName(e.value)[0];
159 function focus_by_name(name){
160 var f = getElementByIndirectName(name);
162 set_cursor_position(f.name);
169 $('input').focus(function(){
170 if (focussable(this)) window.focused_element = this;
173 // setting focus inside a tabbed area fails if this is encountered before the tabbing is complete
174 // in that case the elements count as hidden and jquery aborts .focus()
175 setTimeout(function(){
176 // Lowest priority: first focussable element in form.
177 set_cursor_to_first_element();
179 // Medium priority: class set in template
180 var initial_focus = $(".initial_focus").filter(':visible')[0];
182 $(initial_focus).focus();
184 // special: honour focus_position
185 // if no higher priority applies set focus to the appropriate element
186 if ($("#display_row")[0] && kivi.myconfig.focus_position) {
187 switch(kivi.myconfig.focus_position) {
188 case 'last_partnumber' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="partnumber"]').focus(); break;
189 case 'last_description' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="description"]').focus(); break;
190 case 'last_qty' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="qty"]').focus(); break;
191 case 'new_partnumber' : $('#display_row tr:gt(1) input[name*="partnumber"]').focus(); break;
192 case 'new_description' : $('#display_row tr:gt(1) input[name*="description"]').focus(); break;
193 case 'new_qty' : $('#display_row tr:gt(1) input[name*="qty"]').focus(); break;
197 // all of this screws with the native location.hash focus, so reimplement this as well
199 var hash_name = location.hash.substr(1);
200 var $hash_by_id = $(location.hash + ':visible');
201 if ($hash_by_id.length > 0) {
202 $hash_by_id.get(0).focus();
204 var $by_name = $('[name=' + hash_name + ']:visible');
205 if ($by_name.length > 0) {
206 $by_name.get(0).focus();
211 // legacy. some forms install these
212 if (typeof fokus == 'function') { fokus(); return; }
213 if (focus_by_name('cursor_fokus')) return;
217 $('form').submit(function(){
218 if (window.focused_element)
219 document.forms[0].cursor_fokus.value = window.focused_element.name;