













function ResourceBundleValidate() {
   //Fields
   this.bundle = new Array();
   // Methods
   this.getString         = function(resourceJava) {return this.bundle[resourceJava];}
   //Array fuellen 
   
   this.bundle['invalidFormat2'] = '\nA valid format is "{1}" , for instance';
   
   this.bundle['formatDateISOGTT'] = 'YYYY-MM-DD (From today)';
   
   this.bundle['date_of_mess'] = 'Date of Message';
   
   this.bundle['javaDateFormat'] = 'yyyy-MM-dd';
   
   this.bundle['formatDateMMYYYY'] = 'MM.YYYY';
   
   this.bundle['methodGetMinute'] = 'parseInt(value.substr(3, 2), 10)';
   
   this.bundle['invalidFormat'] = 'The input of the field "{0}" does not comply with the required format.';
   
   this.bundle['name02'] = 'Name';
   
   this.bundle['methodGetHour'] = 'parseInt(value.substr(0, 2), 10)';
   
   this.bundle['formatHNR'] = '[0-9][a-z,A-Z]';
   
   this.bundle['hintFocusMandatoryField'] = 'One of the fields has not been filled out correctly. Please click on the appropriate hint to check your input:';
   
   this.bundle['formatCurrency'] = '0-9.,0-9';
   
   this.bundle['formatName'] = '[a-z,A-Z,-,.,space,special characters]';
   
   this.bundle['//'] = '2007-03-12 O.Niekrenz: ISO date and ISO future date';
   
   this.bundle['formatNumeric8Digits'] = '[0-9]{8}';
   
   this.bundle['currencyField'] = 'You should enter only a valid currency into the field "{0}".';
   
   this.bundle['formatCity'] = '[a-z,A-Z,-,.,space,special characters]';
   
   this.bundle['formatFloat'] = '0-9.,0-9';
   
   this.bundle['expirationDate'] = 'Expiration date of News for the front page';
   
   this.bundle['formatFon'] = '[0-9]/[0-9]';
   
   this.bundle['description'] = 'Description';
   
   this.bundle['methodGetMonth'] = 'parseInt(value.substr(5, 2), 10)';
   
   this.bundle['mandatoryField'] = 'The field "{0}" is mandatory and should not be empty.';
   
   this.bundle['formatAscii'] = 'a-z, A-Z, 0-9, -, ., space, special characters';
   
   this.bundle['formatText'] = '[a-zA-Z-. \u00c4\u00d6\u00dc\u00e4\u00f6\u00fc\u00df]';
   
   this.bundle['SVR_invalidFormat_root'] = 'The input of the field "{0}" does not comply with the required format.';
   
   this.bundle['SVR_mandatoryField'] = 'The field "{0}" is mandatory and should not be empty.';
   
   this.bundle['hintHiddenMandatoryField'] = '(mandatory field)  ';
   
   this.bundle['numberField'] = 'You should enter only figures into the field "{0}".';
   
   this.bundle['methodGetYearMMYYYY'] = 'parseInt(value.substr(0, 4))';
   
   this.bundle['regexpIsTime'] = '/\d\d\:\d\d/';
   
   this.bundle['formatDateGTT'] = 'TT.MM.YYYY (From today)';
   
   this.bundle['dateField'] = 'You should enter a valid date (Format: YYYY-MM-DD) into the field "{0}".';
   
   this.bundle['format'] = 'a-z, A-Z, -, ., space, special characters';
   
   this.bundle['SVR_noFormWhenArt2'] = '';
   
   this.bundle['regexpIsDateMMYYYY'] = '/\d\d\d\d\-\d\d/';
   
   this.bundle['regexpIsDate'] = '/\d\d\d\d\-\d\d\-\d\d/';
   
   this.bundle['SVR_invalidFormat'] = 'A valid format is "{0}" , for instance';
   
   this.bundle['SVR_datedif'] = '';
   
   this.bundle['SVR_noFormWhenArt'] = '';
   
   this.bundle['methodGetMonthMMYYYY'] = 'parseInt(value.substr(5, 2), 10)';
   
   this.bundle['formatTime'] = 'HH:MM';
   
   this.bundle['formatDateISO'] = 'YYYY-MM-DD';
   
   this.bundle['formatPLZ'] = '[0-9]';
   
   this.bundle['methodGetYear'] = 'parseInt(value.substr(0, 4))';
   
   this.bundle['formatDate'] = 'YYYY-MM-DD';
   
   this.bundle['js_format_date'] = 'YYYY-MM-DD';
   
   this.bundle['formatDateYYYY'] = 'YYYY';
   
   this.bundle['formatGpn'] = '[0-9]{10}';
   
   this.bundle['formatPersnrSE'] = '811218-9876';
   
   this.bundle['formatTextNum'] = '[a-z,A-Z,0-9,-,.,space,special characters]';
   
   this.bundle['formatNumber'] = '0-9';
   
   this.bundle['formatEMail'] = 'name@domain.topdomain';
   
   this.bundle['formatPLZ_DE'] = '[0-9]{5}';
   
   this.bundle['formatPLZ_PL'] = '[0-9],[-]';
   
   this.bundle['emailField'] = 'You should enter a valid email address into the field "{0}".';
   
   this.bundle['methodGetDay'] = 'parseInt(value.substr(8, 2), 10)';
   
   this.bundle['time_of_message'] = 'Time of Message';
   
   this.bundle['regexpIsDateYYYY'] = '/\d\d\d\d/';
   
  }


var resourceBundleValidate     = new ResourceBundleValidate();  
  
  
  
//
// Prueft ob ein Element ueberhaupt existiert.
//
function exists(field) {
  if (document.getElementsByName(field)[0]) return true;
  return false;
}

//
// Pruef ob eine Eingabe in ein Textfeld gemacht worden ist.
// Leereichen werden ignoriert.
//
function isEmpty(field) {
  var value = document.getElementsByName(field)[0].value;
  if(trim(value) == '') return true;
  return false;
}

//
// Prueft ob ein Textfeld irgend eine Eingabe enthaelt.
//
function containsChars(field) {
  var value = document.getElementsByName(field)[0].value;
  if(value == '') return false;
  return true;
}

//
// Fuer Klick-Buttons, Checkboxen, Radio-Buttons
//
function isChecked(field) {
  var fieldObj = document.getElementsByName(field);
  var i=0;
  for(i=0; i<fieldObj.length; i++) {
    if (fieldObj[i].checked) return true;
  }
  return false;
}

//
// Fuer Selectbox
//
function isSelected(field) {
  if (document.getElementsByName(field)[0].selectedIndex > -1) return true;
  return false;
}



    function isDate(field) {
      var value = document.getElementsByName(field)[0].value;
      var regExp = /\d\d\d\d\-\d\d\-\d\d/;
      if(regExp.exec(value) != value) return false;
    
    
    
      var year = parseInt(value.substr(0, 4));
      if(year<1900 || year>2100) return false;
      var month = parseInt(value.substr(5, 2), 10);
      if(month<1 || month>12) return false;
      var day = parseInt(value.substr(8, 2), 10);
      if(day<1 || day>31) return false;
      return true;
    }
    
    
    function isDateMMYYYY(field) {
      var value = document.getElementsByName(field)[0].value;
      var regExp = /\d\d\d\d\-\d\d/;
      if(regExp.exec(value) != value) return false;
    
      var year = parseInt(value.substr(0, 4));
      if(year<1900 || year>2100) return false;
      var month = parseInt(value.substr(5, 2), 10);
      if(month<1 || month>12) return false;
      return true;
    }
    
    function isDateYYYY(field) {
      var value = document.getElementsByName(field)[0].value;
      var regExp = /\d\d\d\d/;
      if(regExp.exec(value) != value) return false;
    
      var year = parseInt(value);
      if(year<1900 || year>2100) return false;
      return true;
    }
    
    //
    // Ueberprueft den Wert des Feldes auf das Format 'HH:MM'.
    // Liefert false falls der Wert keiner gueltigen Uhrzeit entspricht, sonst true.
    //
    function isTime(field) {
      var value = document.getElementsByName(field)[0].value;
      var regExp = /\d\d\:\d\d/;
      if(regExp.exec(value) != value) return false;
    
      var hour = parseInt(value.substr(0, 2), 10);
      if(hour<0 || hour>23) return false;
      var min = parseInt(value.substr(3, 2), 10);
      if(min<0 || min>59) return false;
      return true;
    }
    
    // 2007-11-29, jpwand: copied function to this position
    /* BEGIN @CR3611 M. Grabe 2007/01/24 - date gt today - new additional check here */
    
    function isDateGTT( field ){ //alert(field);
    
      // get the value of the form text element
      // 2007-11-29, jpwand: changed name of variable from "v" to "value"
      var value = document.getElementsByName(field)[0].value;
      if( value == null ){ //alert('isDateGTT: Invalid input!');
            return false;
      } //alert(value);
    
      // first check given date being valid
      if( !isDate(field) ){ //alert('isDateGreaterThanCurrent: Invalid date format: TT.MM.YYYY');
        return false;
      }
    
      // set up given date
      // 2007-11-29, jpwand: added resourceBundle methods
      var thisDate = new Date(
        parseInt(value.substr(0, 4)),
        parseInt(value.substr(5, 2), 10)-1,
        parseInt(value.substr(8, 2), 10)
      ); //alert('this date: '+thisDate);
      // 2007-11-29, jpwand: END added resourceBundle methods
    
      // get the current date
      var currentDate = new Date();
    
      // forget about any minutes, seconds and so to be able to compare numerically
      currentDate = new Date(
        currentDate.getFullYear(),
        currentDate.getMonth(),
        currentDate.getDate()
      ); //alert('Compare:\n'+currentDate+'\n'+thisDate);
    
      // new compare the date using the number of milliseconds between 1/1/1970 (GMT) and the current Date object
      // 2007-03-26 O.Niekrenz Mantis 4931: bugfix, changed '<' to '<=' comparison, now it is really a 'greater than'
      // instead of a 'greater or equal than' comparison
      if( thisDate.getTime() <= currentDate.getTime() ){ //alert('isDateGreaterThanCurrent:\n\nYour date \n"'+thisDate+'"\nis less than today\n"'+currentDate+'"');
        return false;
      } else{
        return true;
      }
    
      // never reached
      return false;
    }
    
    /* END @CR3611 M. Grabe 2007/01/24 - date gt today - new additional check here */


/*
 * perform check for ISO conforming date, format is "yyyy-mm-dd"
 * it is allowed to also input the formats "yyyymmdd" and "yymmdd", in the
 * latter case the year is expanded to "20yy"
 * 2007-03-12 O.Niekrenz
 */
function isDateISO( field ) {
  var value = document.getElementsByName(field)[0].value;

  // check allowed formats
  if (!value.match(/\d\d\d\d-\d\d-\d\d/) && !value.match(/\d\d\d\d\d\d\d\d/)
    && !value.match(/\d\d\d\d\d\d/)) return false;

  // remove control characters and adjust century if needed
  value = value.replace(/-/g, "");
  if (value.length == 6) {
    value = "20" + value;
  }

  var year = parseInt(value.substr(0, 4));
  if(year<1900 || year>2100) return false;
  var month = parseInt(value.substr(4, 2), 10);
  if(month<1 || month>12) return false;
  var day = parseInt(value.substr(6, 2), 10);
  if(day<1 || day>31) return false;
  return true;
}

/*
 * perform check for ISO conforming date that lies in the future
 * see isDateISO() and isDateGTT()
 * 2007-03-12 O.Niekrenz
 */
function isDateISOGTT( field ){ //alert(field);

  // get the value of the form text element
  var v = document.getElementsByName(field)[0].value;
  if( v == null ){ //alert('isDateGTT: Invalid input!');
        return false;
  } //alert(v);

  // first check given date being valid
  if( !isDateISO(field) ){ //alert('isDateGreaterThanCurrent: Invalid date format: YYYY-MM-DD');
    return false;
  }

  // remove control characters and adjust century if needed
  v = v.replace(/-/g, "");
  if (v.length == 6) {
    v = "20" + v;
  }

  // set up given date
  var thisDate = new Date(
    parseInt(v.substr(0, 4)),
    parseInt(v.substr(4, 2), 10)-1,
    parseInt(v.substr(6, 2), 10)
  ); //alert('this date: '+thisDate);

  // get the current date
  var currentDate = new Date();

  // forget about any minutes, seconds and so to be able to compare numerically
  currentDate = new Date(
    currentDate.getFullYear(),
    currentDate.getMonth(),
    currentDate.getDate()
  ); //alert('Compare:\n'+currentDate+'\n'+thisDate);

  // new compare the date using the number of milliseconds between 1/1/1970 (GMT) and the current Date object
  // 2007-03-26 O.Niekrenz Mantis 4931: bugfix, changed '<' to '<=' comparison, now it is really a 'greater than'
  // instead of a 'greater or equal than' comparison
  if( thisDate.getTime() <= currentDate.getTime() ){ //alert('isDateGreaterThanCurrent:\n\nYour date \n"'+thisDate+'"\nis less than today\n"'+currentDate+'"');
    return false;
  } else{
    return true;
  }

  // never reached
  return false;
}



function isEmail(field) {
  return validateTest(field, /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/);
}

function isPlz(field) {
  //return validate(field, /\d\d\d\d\d/);
  // wg. der Miniapp Bewerbungsservice Lieferanten muessen weniger bzw. mehr
  // als 5 Ziffern erlaubt sein
  return validate(field,/[\d]{4,6}/);
}

/*
	Prueft ob es sich um 8-stellige Zahl handelt
*/
function isNumeric8Digits(field) {
	return validate(field,/[\d]{8}/);
}

function isPlzGerman(field) {
  return validate(field, /\d\d\d\d\d/);
}

// PLZ-Pruefung auch gueltig fuer polnische PLZs (z.B. 12-345)
function isPlzPolish(field) {
	return validate(field, /\d\d[\-]{0,1}\d\d\d/);
}

function isNumber(field) {
  return validate(field, /[0-9]+/);
}

// pwielowinski 2007-02-14
function isOrganisationNoSE(field) {
  var value = document.getElementsByName(field)[0].value;
  value = value.replace(/ /g, "");
  value = value.replace(/-/g, "");
  var regExp = /\d+/;
  var erg = regExp.exec(value);

    if(erg != null && erg.length) {
    if(erg[0] != value) return false;
    } else {
    if(erg != value) return false;
  }
  return true;    
}

// 13.03.2007 - pdelijewski: Finnish social security ID
function isSocialSecID(field) {
  var value = document.getElementsByName(field)[0].value;
  var regExp = /(\d{6})[\-\+A](\d{3})[0123456789ABCDEFHJKLMNPRSTUVWXY]/;

  var erg = regExp.exec(value);

    if(erg != null && erg.length) {
      if(erg[0] != value) return false;
    } else {
      if(erg != value) return false;
    }

  var day = parseInt(value.substring(0, 2));
  var month = parseInt(value.substring(2, 4));

  if ((day >= 1 && day <= 31) && (month >= 1 && month <= 12)) {
    var checksumString = "0123456789ABCDEFHJKLMNPRSTUVWXY";
    var number = parseInt(value.substring(0,6) + value.substring(7,10));

    if (checksumString.charAt(number % 31) != value.charAt(10)) {
      return false;
    }
  } else {
    return false;
  }

  return true;
}

// 2007-03-07 O.Niekrenz: swedish custome number
function isCustomerNoSE(field) {
  return validate(field, /[\d]{10}/);
}

/* BEGIN M. Grabe 2007/01/12 - personal number - new additional check here */

    function isInt(str){
      if(str==null){
        return false;
      }
      var i = parseInt(str);
      if( isNaN(i) ){
        return false;
      } else{
        return true;
      }
    }
    function isPersnrSE( field ){

      // get the value of the form text element
      var v = document.getElementsByName(field)[0].value;
      if( v == null ){ alert('isPersnrSE: Invalid input!');
        return false;
      }

      // first, rigid validation: must be 10 digits long
      v = v.replace(/^ +/,"");
      v = v.replace(/ +$/,"");
      v = v.replace(/[-]+/,"");
      v = v.replace(/[ ]+/,"");
      if( v.length != 10 ){
        return false;
      }
      //alert("'"+v+"'");

      // get checksum being the 10.th digit
      var checksum = v.substring( v.length-1, v.length ); //alert("checksum: "+checksum);

      // compute the weights
      var arr = [
        v.substring( 0, 1 )*2,
        v.substring( 1, 2 )*1,
        v.substring( 2, 3 )*2,
        v.substring( 3, 4 )*1,
        v.substring( 4, 5 )*2,
        v.substring( 5, 6 )*1,
        v.substring( 6, 7 )*2,
        v.substring( 7, 8 )*1,
        v.substring( 8, 9 )*2
      ];

      //for( i = 0; i < arr.length; i++ ){
      //  alert("arr "+i+": "+arr[i]);
      //}

      // prepare to check sum
      var sum = 0;
      for( i = 0; i < arr.length; i++ ){
        if( arr[i] > 9 ){
          var s = new String(arr[i]);
          var i1 = parseInt(s.substring(0,1));
          var i2 = parseInt(s.substring(1,2));
          sum += i1+i2;
        } else{
          sum += arr[i];
        }
      }
      //alert("sum: "+sum);

      // any non-digits therein?
      if( !isInt(sum) ){
        return false;
      }
      
      // compute the checksum and test it against the given one
      // x1canders 2007-08-23 get the modulo of 10 and this number is the checksum
      var tocheck = sum % 10;
      // hescholz 2007-08-23 checking if 10 minus tocheck number equals checksum
      // additional mod 10 calculation to "convert" result "10" to "0"
      if ((10 - tocheck) % 10 == checksum) { //alert("ok");
        return true;
      } else { //alert("not ok");
        return false;
      }

      // never reached
      return false;
    }
    
/* END M. Grabe 2007/01/12 - personal number */

function isFloat(field) {
  return validate(field, /[0-9]*[\.,]?[0-9]+/);
}


function isHnr(field) {
  return validate(field, /[0-9]{1,4}[a-zA-Z]?/);
}


function isFon(field) {
  return validate(field, /\+?[0-9\- \/]+/);
}


function isName(field) {
  return isText(field);
}

function isGpn(field) {
  return validate(field, /[0-9]{1,10}/ );
}

//
// Ist es Geld
//
function isCurrency(field) {
  return validate(field, /[0-9]+([\.,]{1}[0-9]{2}){0,1}/ );
}

//
//
// pwielowinski 26-01-2007 
// added Swedish characters : \u00C5\u00E5 
function isText(field) {
  
  
  
  return validate(field, /[\n\r -;=?-~¡-ſǄ-ǌȀ-ȗȘ-țȪ-ȳ]+/);
}


function isTextNum(field) {
  
  
  return isText(field);
}

// pwielowinski 26-01-2007 
// added Swedish characters : \u00C5\u00E5 
function isAscii(field) {
  
  
  return isText(field);
} 

// pwielowinski 26-01-2007 
// city name should be entered as a regular text
function isCity(field) {
  return isText(field);
}

// pwielowinski 26-01-2007 
// street name is extended to accept numbers in addition to regular text
function isStreet(field) {
  
  
  return isText(field);
}

// pwielowinski 30-01-2007
function isZipSE(field) {
  return validate(field, /\d\d\d[ ]?\d\d/);
}

function isPixel(field) {
  return isNumber(field);
}



var js_Auml = '\u00C4';
var js_Ouml = '\u00D6';
var js_Uuml = '\u00DC';

var js_auml = '\u00E4';
var js_ouml = '\u00F6';
var js_uuml = '\u00FC';
var js_szlig = '\u00DF';

var js_format_date       = 'TT.MM.JJJJ';
var js_format_dateMMYYYY = 'MM.JJJJ';
var js_format_dateyyyy   = 'JJJJ';
var js_format_time       = 'SS:MM';


  js_format_date       = 'YYYY-MM-DD';
  js_format_dateMMYYYY = 'MM.YYYY';
  js_format_dateyyyy   = 'YYYY';
  js_format_time       = 'HH:MM';


var js_format_email      = 'name@domain.topdomain';
var js_format_number     = '0-9';
var js_format_gpn 			 = '1234567890';
var js_format_float	     = '0-9.0-9';
var js_format_plz        = '[0-9]';
var js_format_plzgerman  = '[0-9]';
var js_format_plzpolish  = '[0-9],[-]';
var js_format_text       = resourceBundleValidate.getString("format");

var js_format_textnum    = resourceBundleValidate.getString("formatTextNum");
var js_format_hnr        = '[0-9][a-z,A-Z]';
var js_format_fon        = '[0-9]/[0-9]';
var js_format_currency   = '[0-9],[0-9]';
var js_format_numeric8digits = '[0-9]{8}';

var js_format_street     = '[a-z, A-Z, 0-9]';
var js_format_zipse      = '[0-9]{5}';
var js_format_name       = resourceBundleValidate.getString("formatName");
var js_format_city       = resourceBundleValidate.getString("formatCity");
var js_format_ascii      = resourceBundleValidate.getString("formatAscii");





var js_format_persnrse = resourceBundleValidate.getString("formatPersnrSE"); //'811218-9876'; // 'JJMMDD[-][0-9]{4}';



var js_format_dategtt = resourceBundleValidate.getString("formatDateGTT"); 



var js_format_customernose = '1234567890';

var js_format_organisationnose = '123456-7890';


var js_format_dateisogtt = resourceBundleValidate.getString("formatDateISOGTT");
var js_format_dateiso = resourceBundleValidate.getString("formatDateISO");


function alertInvalidFormat(field, message, format) {
  setFocus(field);
  
  
  if (message.indexOf("&euro;") >= 0) {
    message = message.replace(/&euro;/g, "\u20ac");
  }
  
  var outtext = resourceBundleValidate.getString("invalidFormat");
      outtext = outtext.replace("{0}", message);
  if(format) {
                outtext = outtext+resourceBundleValidate.getString("invalidFormat2");
                outtext = outtext.replace("{1}", format);
             }
  alert(outtext);
  return false;
}


function alertMandatoryField(field, message) {
  setFocus(field);
  
  
  if (message.indexOf("&euro;") >= 0) {
    message = message.replace(/&euro;/g, "\u20ac");
  }
  
  var outtext = resourceBundleValidate.getString("mandatoryField");
  alert(outtext.replace("{0}", message));
  return false;
}


function setFocus(field) {
  var fieldObj = document.getElementsByName(field)[0];      // Get object to focus on
  fieldObj.focus();                                         // Focus works always
  // Select works only for text, password and textarea
  if (fieldObj.type == 'text' || fieldObj.type == 'password' || fieldObj.type == 'textarea') {
    fieldObj.select();
  }
}

function trim(value) {
  return value.replace(/^ */g, '').replace(/ *$/g, '');
}


function validate(field, regExp) {
  var value = document.getElementsByName(field)[0].value;
  
  var erg = regExp.exec(value);
  if(erg != null && erg.length) {
	if(erg[0] != value) return false;
  } else {
	if(erg != value) return false;
  }
  return true;
}


function validateTest(field, regExp) {
  var value = document.getElementsByName(field)[0].value;
  return regExp.test(value);
}





//ptemich 2008.04.09, new validation function,
//function is used to validated selectors inside the C05 module
//selector is valid only when something is selected and selected option is not the "please select" one
function isNoneValueSelected(field) {  
  var NONE_VALUE = "n_o_n_e";
  var fieldsList = document.getElementsByName(field);
  if (fieldsList != null) {
    var fieldElement = fieldsList[0];
    if (fieldElement) {
      var elementSelection = fieldElement.selectedIndex;      
      if (elementSelection != -1 && fieldElement.options[elementSelection].value != NONE_VALUE) {
        return true;
      }
    }
  }
  return false;
}