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 validate_dates(input_name_1, input_name_2) {
 
 125   var tempArray1 = new Array();
 
 126   var tempArray2 = new Array();
 
 127   tempArray1 = getDateArray(input_name_1);
 
 128   tempArray2 = getDateArray(input_name_2);
 
 129   if(check_right_date_format(input_name_1) && check_right_date_format(input_name_2)) {
 
 130     if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(tempArray1[0], tempArray1[1], tempArray1[2])).getTime())) {
 
 131       show_alert_and_focus(input_name_1, wrongDateFormat);
 
 132       return show_alert_and_focus(input_name_2, wrongDateFormat);
 
 134     if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(1900, 1, 1)).getTime())) {
 
 135       show_alert_and_focus(input_name_1, wrongDateFormat);
 
 136       return show_alert_and_focus(input_name_2, wrongDateFormat);
 
 141 function getDateArray(input_name) {
 
 142   formatArray[2] = input_name.value.substring(dateFormat.indexOf("d"), 2);
 
 143   formatArray[1] = input_name.value.substring(dateFormat.indexOf("m"), 2);
 
 144   formatArray[0] = input_name.value.substring(dateFormat.indexOf("y"), (dateFormat.length == 10 ? 4 : 2));
 
 145   if(dateFormat.length == 8) {
 
 146     formatArray[0] += (formatArray[0] < 70 ? 2000 : 1900);
 
 151 function show_alert_and_focus(input_name, errorMessage) {
 
 153   alert(errorMessage + "\n\r\n\r--> " + input_name.value);
 
 158 function get_input_value(input_name) {
 
 159   var the_input = document.getElementsByName(input_name);
 
 160   if (the_input && the_input[0])
 
 161     return the_input[0].value;
 
 165 function set_cursor_position(n) {
 
 166   $('[name=' + n + ']').focus();
 
 169 function focussable(e) {
 
 170   return e && e.name && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
 
 173 function set_cursor_to_first_element(){
 
 174   var df = document.forms;
 
 175   for (var f = 0; f < df.length; f++)
 
 176     for (var i = 0; i < df[f].length; i++)
 
 177       if (focussable(df[f][i]))
 
 178         try { df[f][i].focus(); return } catch (er) { }
 
 181 function getElementByIndirectName(name){
 
 182   var e = document.getElementsByName(name)[0];
 
 183   if (e) return document.getElementsByName(e.value)[0];
 
 186 function focus_by_name(name){
 
 187   var f = getElementByIndirectName(name);
 
 189     set_cursor_position(f.name);
 
 196   $('input').focus(function(){
 
 197     if (focussable(this)) window.focused_element = this;
 
 200   // setting focus inside a tabbed area fails if this is encountered before the tabbing is complete
 
 201   // in that case the elements count as hidden and jquery aborts .focus()
 
 202   setTimeout(function(){
 
 203     // Lowest priority: first focussable element in form.
 
 204     set_cursor_to_first_element();
 
 206     // Medium priority: class set in template
 
 207     var initial_focus = $(".initial_focus").filter(':visible')[0];
 
 209       $(initial_focus).focus();
 
 211     // special: honour focus_position
 
 212     // if no higher priority applies set focus to the appropriate element
 
 213     if ($("#display_row")[0] && kivi.myconfig.focus_position) {
 
 214       switch(kivi.myconfig.focus_position) {
 
 215         case 'last_partnumber'  : $('#display_row tr.row:gt(-3):lt(-1) input[name*="partnumber"]').focus(); break;
 
 216         case 'last_description' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="description"]').focus(); break;
 
 217         case 'last_qty'         : $('#display_row tr.row:gt(-3):lt(-1) input[name*="qty"]').focus(); break;
 
 218         case 'new_partnumber'   : $('#display_row tr:gt(1) input[name*="partnumber"]').focus(); break;
 
 219         case 'new_description'  : $('#display_row tr:gt(1) input[name*="description"]').focus(); break;
 
 220         case 'new_qty'          : $('#display_row tr:gt(1) input[name*="qty"]').focus(); break;
 
 224     // all of this screws with the native location.hash focus, so reimplement this as well
 
 226       var hash_name = location.hash.substr(1);
 
 227       var $hash_by_id = $(location.hash + ':visible');
 
 228       if ($hash_by_id.length > 0) {
 
 229         $hash_by_id.get(0).focus();
 
 231         var $by_name = $('[name=' + hash_name + ']:visible');
 
 232         if ($by_name.length > 0) {
 
 233           $by_name.get(0).focus();
 
 238     // scroll to the active element. jQuery.focus doesn't do this
 
 239     // TODO: find out how to reliably frame the active element
 
 240     window.scrollTo(0, document.activeElement.getBoundingClientRect().top);
 
 242     // legacy. some forms install these
 
 243     if (typeof fokus == 'function') { fokus(); return; }
 
 244     if (focus_by_name('cursor_fokus')) return;
 
 248 $('form').submit(function(){
 
 249   if (window.focused_element)
 
 250     document.forms[0].cursor_fokus.value = window.focused_element.name;