var language = 'de';
var languageID = 1;

function setLanguage(lan, lanID)
{
  language = lan;
  languageID = lanID;
}

function check_plz(plz)
{
  if(!is_string(plz) || (plz.length < 5)) return false;

  return check_is_value(plz);
}

function check_state_plz(plz, state, hard_plz)
{
  if(!is_string(state)) state = '';
  if(!is_bool(hard_plz)) hard_plz = true;

  switch(state)
  {
    case 'de':
      return ((plz.length >= (hard_plz ? 5 : 1)) && check_is_value(plz));
    case 'at':
      return ((plz.length >= (hard_plz ? 4 : 1)) && check_is_value(plz));
    case 'pl':
      var to_check = ((hard_plz) ?
                       /^[0-9]{2,2}(-)?[0-9]{3,4}$/
                       :
                       /^[0-9]([0-9](-)?[0-9]{0,4})?$/
                     );

      return to_check.test(plz);
  }

  return ((plz.length > 0) && check_is_value(plz));
}

function check_is_value_at_area(value, natural, a, b)
{
  if(!is_bool(natural)) natural = true;

  if(natural && !check_is_natural_value(value)) return false;
  if(!natural && !is_float_input(value, false)) return false;

  var c = (is_string(value) ? 1 * value : 1 * value);

  if((is_number(a) && (c < a)) ||
     (is_number(b) && (c > b))
    ) return false;

  return true;
}

function check_is_value(value)
{
  var i = 0, end = value.length, cur_value;

  for(; i < end; i++)
  {
    cur_value = value.charAt(i);

    if(!(cur_value >= '0' && cur_value <= '9')) return false;
  }

  return true;
}

function check_is_natural_value(value)
{
  switch(typeof value)
  {
    case 'number':
      {
        return (value - Math.floor(value) === 0);
      }

      break;
    case 'string':
      {
        var natural_is = /^(\-|\+|)[0-9]+$/;

        return natural_is.test(value);
      }

      break;
  }

  return false;

}

function is_float_input(value, check_sign, greater)
{
  if(typeof value == "undefined") return false;

  if(!is_bool(check_sign)) check_sign = false;
  if(!is_bool(greater)) greater = true;

  switch(typeof value)
  {
    case 'number':
      {
        if(!check_sign) return true;

        return (greater ? (value >= 0) : (value < 0));
      }

      break;
    case 'string':
      {
        var pattern = '^[+-]?[0-9]+([.][0-9]+)?$';

        if(check_sign) pattern = ((greater) ? '^[+]?[0-9]+([.][0-9]+)?$' : '^[-][0-9]+([.][0-9]+)?$');

        // \.  -> [.]

        var test_reg = new RegExp(pattern);

        return test_reg.test(value);
      }

      break;
  }

  return false;
}


function check_is_unix_dirs(value, delimiter)
{
  var unix_dir_is = null;

  unix_dir_is = ((delimiter.length == 0) ?
                 new RegExp("^(\/[a-zA-Z0-9]+)+$") :
                 new RegExp("^(\/[a-zA-Z0-9]+)+(" + delimiter + "(\/[a-zA-Z0-9]+)+)*$"));

  return unix_dir_is.test(value);
}

function set_date_with_time(to_set_date, to_set_time)
{
  if((to_set_date == null) || (typeof to_set_date != "object") ||
     (to_set_time == null) || (typeof to_set_time != "object"))
  {
    return null;
  }

  to_set_date.setHours(to_set_time.getHours());
  to_set_date.setMinutes(to_set_time.getMinutes());
  to_set_date.setSeconds(to_set_time.getSeconds());

  return to_set_date;
}

function get_common_time(to_check_time, is_lang_de)
{
  if(!check_common_time(to_check_time, is_lang_de)) return null;

  var time_format;

  switch(to_check_time.length)
  {
    case 5: time_format = /^(\d\d):(\d\d)$/;
            // (HH:MM)
            break;
    case 8: time_format = /^(\d\d):(\d\d):(\d\d)$/;
            // (HH:MM:SS)
            break;
    default: return null;
  }

  if(!time_format.exec(to_check_time)) return null;

  var hh, mm, ss = 0;

  hh = 1 * RegExp.$1;
  mm = 1 * RegExp.$2;

  if(to_check_time.length == 8) ss = 1 * RegExp.$3;

  var rc = new Date();

  rc.setHours(hh);
  rc.setMinutes(mm);
  rc.setSeconds(ss);

  return rc;
}


function check_common_time(to_check_time)
{
  if((to_check_time == null) || (typeof to_check_time != "string") || (to_check_time.length < 5))
  {
    return false;
  }

  var time_format;

  switch(to_check_time.length)
  {
    case 5: time_format = /^(\d\d):(\d\d)$/;
            // (HH:MM)
            break;
    case 8: time_format = /^(\d\d):(\d\d):(\d\d)$/;
            // (HH:MM:SS)
            break;
    default: return false;
  }

  if(!time_format.exec(to_check_time)) return false;

  var hh, mm, ss = 0;

  hh = 1 * RegExp.$1;
  mm = 1 * RegExp.$2;

  if(to_check_time.length == 8) ss = 1 * RegExp.$3;

  return ((hh >= 0 && hh <= 23) &&
          (mm >= 0 && mm <= 59) &&
          (ss >= 0 && ss <= 59));
}

function check_common_date(to_check_date, is_lang_de)
{
  if((to_check_date == null) || (typeof to_check_date != "string") || (to_check_date.length != 10))
  {
    return false;
  }

  var date_format;

  if(is_lang_de)
  {
    date_format = /^(\d\d)\.(\d\d)\.(\d\d\d\d)$/;
    // DD.MM.YYYY
  }
  else
  {
    date_format = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
    // YYYY-MM-DD
  }

  if(!date_format.exec(to_check_date)) return false;

  var year, month, day;
  var test_date, base = 0;

  day = 1 * ((is_lang_de) ? RegExp.$1 : RegExp.$3);
  month = 1 * RegExp.$2;
  year = 1 * ((is_lang_de) ? RegExp.$3 : RegExp.$1);

  test_date = new Date(year, month - 1, day);

  if(test_date.getYear() < 1900) base = 1900;

  return ((test_date.getDate() == day) &&
          (test_date.getMonth() == (month - 1)) &&
          ((test_date.getYear() + base) == year));
}

function get_common_date(to_check_date, is_lang_de)
{
  if(!check_common_date(to_check_date, is_lang_de)) return null;

  var date_format;

  if(is_lang_de)
  {
    date_format = /^(\d\d)\.(\d\d)\.(\d\d\d\d)$/;
    // DD.MM.YYYY
  }
  else
  {
    date_format = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
    // YYYY-MM-DD
  }

  if(!date_format.exec(to_check_date)) return null;

  var year, month, day;
  var test_date, base = 0;

  day = 1 * ((is_lang_de) ? RegExp.$1 : RegExp.$3);
  month = 1 * RegExp.$2;
  year = 1 * ((is_lang_de) ? RegExp.$3 : RegExp.$1);

  return new Date(year, month - 1, day);
}


function check_date(what_date)
{
  if(what_date.length < 10)
  {
    alert('Das Datumsformat sollte DD-MM-YYYY sein!');

    return false;
  }

  if(!check_is_value(what_date.substr(0, 2)))
  {
    alert('Das Datumsformat sollte DD-MM-YYYY sein!');

    return false;
  }

  if(!check_is_value(what_date.substr(3, 2)))
  {
    alert('Das Datumsformat sollte DD-MM-YYYY sein!');

    return false;
  }

  if(!check_is_value(what_date.substr(6, 4)))
  {
    alert('Das Datumsformat sollte DD-MM-YYYY sein!');

    return false;
  }

  var day = what_date.substr(0, 2);
  var month = what_date.substr(3, 2);
  var year = what_date.substr(6, 4);
  var base = 0;

  //alert(day + "," + month + "," + year);

  /*if(isNaN(day) || isNaN(month) || isNaN(year))
    return false;*/

  var test_date = new Date(year, month - 1, day);

/*  test_date = new Date(2000, 1, 1);
  test_date.setYear(2001);
  test_date.setMonth(month - 1)
  test_date.setDate(31);*/

  //alert(test_date);

  if(test_date.getDate() != day)
    alert('Error at Day');

  if(test_date.getMonth() != (month - 1))
    alert('Error at Month');

  //alert(test_date.getMonth());

  if(test_date.getYear() < 1900) base = 1900;

  if((test_date.getYear() + base) != year)
  {
    alert('Error at Year');

    //alert(year);

    //alert(test_date.getYear());
  }

  return (test_date.getDate() == day && test_date.getMonth() == (month - 1) && (test_date.getYear() + base) == year);
}

function get_js_date(what_date)
{
  if(!check_date(what_date)) return null;

  var day = what_date.substr(0, 2);
  var month = what_date.substr(3, 2);
  var year = what_date.substr(6, 4);

  var test_date = new Date(year, month - 1, day);

  return test_date;
}

function get_last_num(where, del)
{
  if(!is_string(where) || strlen(where)===0 ||
     !is_string(del) || strlen(del)===0
    ) return -1;

  var pos = where.lastIndexOf(del);

  return (pos===-1 ? -1 : 1*where.substr(pos+1));
}

function standard_open(what, named)
{
  var n = window.open(what,
                      named,
                      'width=700,height=600,menubar=no,scrollbars=yes,scrollable=yes,resizable=yes,screenX=150,screenY=20');
}

function load_left_right_frame(in_left, in_right)
{
  if(parent.left_frame)
  {
    if(in_left !== '') parent.left_frame.location.href = in_left;

    if(in_right !== '') parent.right_frame.location.href = in_right;
  }
  else
  {
    alert('ERROR: Sie scheinen einen Proxy zu verwenden, welcher nicht transparent ist\n.' +
          'Bitte versuchen sie es ohne / mit anderen Proxy.');
  }
}

function is_email_adress(email_adress)
{
  if(!is_string(email_adress) || strlen(email_adress)<=4) return false;

  email_adress = email_adress.replace(/ß/, 'ss');

  return (email_adress.search(/^[_\.0-9a-z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,4}$/) != -1); // 26.12.2006,
                                                                                                    // ignore between A a at domains
}

function is_checked_radio(radio_object, from, to)
{
  for(; from <= to; from++)
  {
    if((radio_object[from]) && (radio_object[from].checked)) return true;
  }

  return false;
}

function is_checked_checkup(checkup_object)
{
  if(!is_object(checkup_object)) return false;

  //for(var i in checkup_object)
  for(var i = 0; i< checkup_object.length; i++)
  {
    //alert(i + ', ' + checkup_object[i].checked);

    if(checkup_object[i].checked) return true;
  }

  return false;
}

function get_checked_checkup(checkup_object, field_ID)
{
  // id - field with struc            field_name[nr]

  if(!is_object(checkup_object) || !is_string(field_ID) || is_empty(field_ID)) return new Array();

  var rc = new Array();

  var tmp_field;
  var tmp_pos;

  //for(var i in checkup_object)
  for(var i = 0; i< checkup_object.length; i++)
  {
    if(checkup_object[i].checked !== true) continue;

    tmp_field = checkup_object[i][field_ID];

    tmp_pos = tmp_field.indexOf('[');

    if((tmp_pos === -1) || (tmp_field.length - (tmp_pos+2)) <= 0) continue;

    tmp_pos = 1*tmp_field.substr(tmp_pos+1, tmp_field.length - (tmp_pos+2));

    rc[tmp_pos] = checkup_object[i].value;
  }

  return rc;
}

function set_check_checkup(field_name, sel_index, new_value, doc)
{
  // sel_index = {[i,value1], [j,value2], ...}

  if(!is_string(field_name) || is_empty(field_name) || !is_bool(new_value) || !is_array(sel_index)) return false;

  if(!is_object(doc)) doc = document;

  var tmp = null;

  for(var i in sel_index)
  {
    tmp = doc.getElementById(field_name + '[' + i + ']');

    if(!tmp) continue;

    tmp.checked = new_value;
  }

  return true;
}


function clear_select_list(select_list)
{
  if(select_list.length) select_list.length = 0;
}

function default_select_list(select_list)
{
  if(!is_object(select_list)) return false;

  for(var i = 0; i < select_list.length; i++)
    if(select_list.options[i].defaultSelected === true) select_list.options[i].selected = true;

  return true;
}

function show_tags(obj, max_obj)
{
  if(!is_object(obj)) return false;

  max_obj = (!is_number(max_obj) ? 10 : max_obj);

  for(var j in obj)
  {
    alert(j + ': ' + obj[j]);

    --max_obj;

    if(!max_obj) return true;
  }

  return true;
}

function setBrowserConfiguration(fld)
{
  if(typeof fld == "undefined") return false;

  var is_first = true;
  var to_check = ["document.all", "document.getElementById", "document.designMode"];
  var i, elem;

  fld.value = "";

  for(i in to_check)
  {
    if(is_first) is_first = false;
    else fld.value += "|";

    elem = eval(to_check[i]);

    fld.value += to_check[i] + "=" + ((elem) ? "1" : "0");
  }

  return true;
}

function get_path(path)
{
  if(!is_string(path) || strlen(path)===0) return '';

  var pos = path.lastIndexOf('/');

  if(pos===-1) return '';

  return path.substr(0, pos+1);
}

function hex2bin(str)
{
  if(typeof str != "string" || str.length < 3 || str.length % 2 == 1 || str.substring(0, 2) != "0x") return str;

  var rc = '';
  var end = (str.length / 2) - 1;
  var pos = 0;

  for(var i = 0; i < end; i++)
  {
    pos = 2 * (i+1);

    rc += String.fromCharCode(parseInt(str.substring(pos, pos+2), 16));
  }

  return rc;
}

function isset(mixed_var)
{
  return (typeof mixed_var !== 'undefined');
}

function is_bool(mixed_var)
{
  return (typeof mixed_var === 'boolean');
}

function is_string(mixed_var)
{
  return (typeof mixed_var === 'string');
}

function is_number(mixed_var)
{
  return (typeof mixed_var === 'number');
}

function is_object(mixed_var)
{
  return (typeof mixed_var === 'object');
}

function is_array(mixed_var)
{
  try {
    return (typeof mixed_var === 'object' && typeof mixed_var.length === 'number');
  } catch(err_IS_ERROR) {
    return false;
  }
}

function is_int(mixed_var)
{
  return is_number(mixed_var) &&
         (mixed_var - Math.floor(mixed_var) === 0);
}

function is_float(mixed_var)
{
  return is_number(mixed_var);
}

function count(mixed_var)
{
  if(!is_array(mixed_var)) return false;

  var i = 0;

  for(var key in mixed_var) ++i;

  return i;
}

function array()
{
  return [];
}

function str_replace(from, to, what)
{
  if(!is_string(what) || strlen(what)===0) return '';

  if(is_string(from)) from = [from];
  if(is_string(to)) to = [to];

  if(!is_array(from) || !is_array(to)) return '';

  var pos = 0;

  for(i in from)
  {
    if(strlen(from[i])===0) continue;

    if(!array_key_exists(i, to) || !is_string(to[i])) return '';

    pos = -1;

    while((what.length !== 0) && (pos = what.indexOf(from[i], pos+1)) !== -1)
    {
      what = (pos>0 ? what.substr(0, pos) : '') + to[i] + what.substr(pos + from[i].length);

      pos += to[i].length;
    }
  }

  return what;
}

function is_null(mixed_var)
{
  return (mixed_var === null);
}

function is_empty(mixed_var)
{
  return (typeof mixed_var === 'string' &&
          mixed_var.length === 0
         );
}

function strlen(mixed_var)
{
  if(!is_string(mixed_var)) return -1;

  return mixed_var.length;
}

function str_repeat(what, c_what)
{
  if(!is_string(what) || strlen(what)===0 || !is_number(c_what) || c_what <= 0) return '';

  var rc = '';

  while(c_what-- > 0) rc += what;

  return rc;
}

function lr_trim(mixed_var)
{
  if(!is_string(mixed_var) || is_empty(mixed_var)) return mixed_var;

  var from = 0, to = mixed_var.length - 1;
  
  var tab = String.fromCharCode(09);

  while(from <= to && (mixed_var.substr(from, 1) === ' ' ||
  										 mixed_var.substr(from, 1) === tab
  							      )) ++from;

  if(from > to) return '';

  while((mixed_var.substr(to, 1) === ' ' ||
  			 mixed_var.substr(to, 1) === tab
        )) --to;

  return mixed_var.substr(from, to - from + 1);
}

function array_key_exists(key, where)
{
  if(!isset(key) || !is_array(where)) return false;

  return isset(where[key]);
}

function array_keys(where, is_num)
{
  if(!is_array(where)) return new Array();

  if(!is_bool(is_num)) is_num = false;

  var keys = new Array();

  for(var i in where) keys[keys.length] = (is_num ? 1*i : i);

  return keys;
}

function array_merge(tab1, tab2, with_index, num_index)
{
  if(!is_array(tab1) || !is_array(tab2)) return [];

  if(!is_bool(with_index)) with_index = false;
  if(!is_bool(num_index)) num_index = false;

  var rc = [];
  var i;

  for(i in tab1)
  {
    if(with_index) rc[(num_index ? 1*i : i)] = tab1[i];
    else rc[rc.length] = tab1[i];
  }

  for(i in tab2)
  {
    if(with_index) rc[(num_index ? 1*i : i)] = tab2[i];
    else rc[rc.length] = tab2[i];
  }

  return rc;
}

function in_array(value, where)
{
  if(!isset(value) || !is_array(where)) return false;

  for(var i in where)
    if(where[i] === value) return true;

  return false;
}

function superclass_get()
{
  if(!is_string(location.search) || strlen(location.search)===0) return [];

  var rc = [];
  var param = '' + location.search;
  var i;
  var buf;

  if(param.substr(0, 1) === '?') param = param.substr(1);

  if(param.indexOf('&') === -1) param = [param];
  else param = param.split('&');

  for(i in param)
  {
    if(param[i].indexOf('=') === -1) continue;

    buf = param[i].split('=', 2);

    rc[buf[0]] = buf[1];
  }

  return rc;
}

function std_fast_jump(jump_to, site, win)
{
  if(!is_string(jump_to) || strlen(jump_to)===0 || !is_number(site)) return false;

  if(!is_object(win)) win = window;

  //alert(win.location.protocol + '//' + win.location.host);
  //alert(win.location.protocol + '//' + win.location.host /*+ '/'*/ + (jump_to.substring(0,1) === '/' ? '' : '/') + jump_to);
  //return true;

  if(jump_to.substring(0, 4).toUpperCase() !== 'HTTP')
  {
    // now we think, that you need the server, if you had no host!
    jump_to = win.location.protocol + '//' + win.location.host /*+ '/'*/ + (jump_to.substring(0,1) === '/' ? '' : '/') + jump_to;
  }

  win.location.href = jump_to + (jump_to.substring(jump_to.length-1) === '=' ? '' : '=') + site;

  return true;
}

function load_style(url)
{
  if(!is_string(url) || strlen(url) === 0) return false;

  var a = document.createElement('link');
  
  a.setAttribute('rel','stylesheet');
  a.setAttribute('type','text/css');
  a.setAttribute('href',url);

  document.getElementsByTagName('head')[0].appendChild(a);
  
  return true;
}

function unload_style(url)
{
  if(!is_string(url) || strlen(url) === 0) return false;
  
  var head = document.getElementsByTagName('head')[0];
  var a = head.firstChild;

	while(a != null)
	{
	  //alert(a.nodeType);
	  if(a.nodeType === 1 && a.getAttribute('rel') === 'stylesheet' && 
	  	a.getAttribute('href') === url)
	  {
		//alert('yes');
	    head.removeChild(a);
	    
	    return true;
	  }
		
	  a = a.nextSibling;
	}
	
	
	return true;
}

if(!(window.navigator.userAgent.indexOf("MSIE") > 0))
{
  HTMLElement.prototype.__defineGetter__("innerText",
              function () { return(this.textContent); });

  HTMLElement.prototype.__defineSetter__("innerText",
              function (txt) { this.textContent = txt; });
}

