
var sprachen = new Array(2);
// und jetzt erzeugen wir einen Array mit zwei Dimensionen
for (var i = 0; i < sprachen . length; i++) {
    sprachen[i] = new Array(2);
}
sprachen[0][0] = "Externer Link";
sprachen[0][1] = "- neues Fenster";
sprachen[1][0] = "Interner Link";
sprachen[1][1] = "- neues Fenster";

//alert ('was');
function titelUndTargetAendern()
{
    // Pruefen, ob der Browser das neue DOM kennt; wenn nicht, hier stoppen
    // (title kann nicht angepasst werden, also duerfen wir kein neues Fenster aufmachen fuer WCAG1/BITV-Konformitaet)
    if (!document . getElementsByTagName) {return;}
    // Array mit allen Links auf der Seite fuellen
    var links = document . getElementsByTagName("a");
    // Schleife, um jeden einzelnen Link anzusprechen

//    alert (links . length);
    for (i = 0; i < links . length; i++) {

//    alert ('drin A');
  //  if (i>3){
    //return true;
    //}
        // Variable fuer einzelnen Link
        var einzelLink = links[i];
        // title des einzelnen Links holen
        titelAlt = einzelLink . getAttribute("title");
        // Wenn ein title vorhanden ist
        if (titelAlt) {
            // und hier gehen wir die verschiedenen Sprachen durch
            for (j = 0; j < sprachen . length; j++) {

  //          alert ('drin: '+sprachen[0][0]);
//            return true;
                // Pruefen, ob der Indentifier fuer eine Sprache im title vorkommt
                if (titelAlt . indexOf(sprachen[j][0]) != -1) {
                    // title aufsplitten, um den Text hinter dem Indentifier zu kriegen
                    titelZusatz = titelAlt . substring((titelAlt . indexOf(sprachen[j][0])) + sprachen[j][0] . length, titelAlt . length);
                    // schreibe das neue title-Attribut
                    einzelLink . setAttribute("title", sprachen[j][0] + " " + sprachen[j][1] + titelZusatz);
                    // Und jetzt sagen wir, dass der Link in einem neuen Fenster aufgehen soll (ein anderer Name kann verwendet
                    // werden, um alle Links im gleichen Fenster aufgehen zu lassen, aber es ist ein zusaetzliches .focus fuer das
                    // Fenster erforderlich)
                    einzelLink . target = "_blank";
                    // da wir soweit sind, kann die Schleife unterbrochen werden
                    break;
                }
            }
        }
    }


}




function janein (url)
{
    zeigen = confirm("Wollen Sie diesen Datensatz tatsaechlich und endgueltig loeschen?");
    if (zeigen == true) {
        location = url;
    } else {
        return true;
    }

}

function popup(str)
{
    tipWin = window . open(str, 'tipWin', 'width=600,height=500,resizeable=yes,scrollbars=yes,left=100,top=100');
    window . open(str, 'tipWin', 'width=400,height=400');
    tipWin . opener = self;
}

//DW
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- In '+nm+' muss eine E-Mail-Adresse rein.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- In '+nm+' muss eine Zahl zwischen '+min+' und '+max+' rein.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' ist ein Pflichtfeld.\n'; }
  } if (errors) alert('Folgende Fehler sind aufgetreten:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// unterschiedliche Array, welche zum Check heran gezogen werden ( und aus Formular-XML-Files gefuellt werden )
var check_element = new Array();
var check_mail = new Array();
var check_int = new Array();
var check_min = new Array();
var check_min_len = new Array();
var check_max = new Array();
var check_max_len = new Array();
var check_dates = new Array();
var check_times = new Array();
// dieses Array wird im PHP weiter gefuellt - damit die Auswahl der Kategorien ueberprueft werden kann...
var selection_kats = new Array();




check_element[0] = "firstname";
check_min[0] = "firstname";
check_min_len[0] = "3";

check_element[1] = "lastname";
check_min[1] = "lastname";
check_min_len[1] = "3";

check_element[2] = "username";
check_min[2] = "username";
check_min_len[2] = "6";

check_element[3] = "email";
check_element[4] = "email2";

check_mail[0] = "email";
check_mail[1] = "email2";

check_element[5] = "password";
check_min[5] = "password";
check_min_len[5] = "6";

check_element[6] = "password2";
check_min[6] = "password2";
check_min_len[6] = "6";

check_element[7] = "agb";



function validateRegForm ()
{
    last_field = false;
    /**
     * * Test auf gueltige E-Mail
     */

    var count_mail = check_mail . length;
    for (var n = 0; n < count_mail; n++) {
        if (document . getElementById(check_mail[n]) . value) {
            var b_email = check_email(document . getElementById(check_mail[n]) . value);
            if (b_email != true) {
                exit_check (document . getElementById(check_mail[n]), "E-Mail-Adresse fehlerhaft!");
                return false;
            }
        }
    }
    /**
     * * Test auf numerische Werte
     */
    var count_int = check_int . length;
    for (var n = 0; n < count_int; n++) {
        if (document . getElementById(check_int[n]) . value) {
            var b_numval = check_num_val(document . getElementById(check_int[n]) . value);
            if (b_numval == false) {
                exit_check (document . getElementById(check_int[n]), "Bitte geben Sie hier nur Zahlen ein!", true);
                return false;
            }
        }
    }

    /**
     * * Test auf Datum Eingaben
     */
    var count_date = check_dates . length;

    for (var n = 0; n < count_date; n++) {
        if (document . getElementById(check_dates[n]) . value) {
            var b_dateval = check_date(document . getElementById(check_dates[n]));
            if (b_dateval == false) {
                // exit_check (document . getElementById(check_dates[n]), "Ungueltiges Datum!", true);
                return false;
            }
        }
    }
    /**
     * * im ersten Block wird
     * erst mal geguckt, ob die Pflichtfelder gefuellt sind
     */
    var count_ele = check_element . length;
    var count_min = check_min . length;
    var count_max = check_max . length;

    for (var k = 0; k < count_ele; k++) {
        if (document . getElementById(check_element[k]) . type == "select-one") {
            if (document . getElementById(check_element[k]) . options[document . getElementById(check_element[k]) . selectedIndex] . value == 'NULL') {
                exit_check (document . getElementById(check_element[k]), "Fehlende Auswahl!");
                return false;
            }
            if (document . getElementById(check_element[k]) . value == "") {
            }
        } else if (document . getElementById(check_element[k]) . type == "checkbox") {
            if (document . getElementById(check_element[k]) . checked == false) {
            if (check_element[k]=='agb') {
                exit_check (document . getElementById(check_element[k]), "Bitte bestaetigen Sie die Nutzungsbedingungen!");
            } else {
                exit_check (document . getElementById(check_element[k]), "Bitte Checkbox anklicken!");
                }
                return false;
            }
        } else {
            if (document . getElementById(check_element[k]) . value == "") {
                exit_check (document . getElementById(check_element[k]), "Fehlende Eingabe!");
                return false;
            }
            /**
             * * Test auf minimale Laenge
             */
            for (var n = 0; n < count_min; n++) {
                if (document . getElementById(check_element[k]) . name == check_min[n]) {
                    if (document . getElementById(check_element[k]) . value . length < check_min_len[n]) {
                        exit_check (document . getElementById(check_element[k]), "Eingabe zu kurz.\n\nBitte beachten Sie eine Mindestlaenge von " + check_min_len[n] + " Zeichen!");
                        return false;
                    }
                }
            }
            /**
             * * Test auf maximal Laenge - aktuell nur beim Textareas eingestellt, da Eingabefelder eine max. Begrenzung haben
             */
            for (var n = 0; n < count_max; n++) {
                if (document . getElementById(check_element[k]) . name == check_max[n]) {
                    if (document . getElementById(check_element[k]) . value . length > check_max_len[n]) {
                        exit_check (document . getElementById(check_element[k]), "Eingabe zu lang.\n\nBitte beachten Sie eine maximale Laenge von " + check_max_len[n] + " Zeichen!");
                        return false;
                    }
                }
            }
        }
    }
    // zum Schluss werden noch ganz spezielle Kombinationen abgeprueft, die fuer jedes Formular ziemlich individuell sind
    var b_spezial_kond = check_spezial_konditions();
    if (b_spezial_kond == false) {
        return false;
    }

}

function check_date(feld)
{
    if (feld . value == '') {
        return true;
    }

    var vormals = feld . value;
    // alle Sonderzeichen werden zum Pumkt umgewandelt
    // muss doppelt ausgeuehrt werden, da pro Durchgang nur ein Zeichen ersetzt werden
    vormals = vormals . replace(',', '.');
    vormals = vormals . replace(',', '.');
    vormals = vormals . replace(' ', '.');
    vormals = vormals . replace(' ', '.');
    vormals = vormals . replace('+', '.');
    vormals = vormals . replace('+', '.');
    vormals = vormals . replace('/', '.');
    vormals = vormals . replace('/', '.');
    vormals = vormals . replace('-', '.');
    vormals = vormals . replace('-', '.');
    vormals = vormals . replace('_', '.');
    vormals = vormals . replace('_', '.');
    vormals = vormals . replace('*', '.');
    vormals = vormals . replace('*', '.');
    vormals = vormals . replace(':', '.');
    vormals = vormals . replace(':', '.');
    vormals = vormals . replace(';', '.');
    // falls kein Punkt vorhanden ist, werden die Eingaben biei 6 oder 8 Zeichen gesplittet
    if (vormals . indexOf(".") == -1) {
        if (vormals . length == 6 || vormals . length == 8) {
            var tt = vormals . substr(0, 2);
            var mm = vormals . substr(2, 2);
            var yy = vormals . substr(4);
        } else {
            // falls keine 6 oder 8 Zeichen gefunden, sind, kann auch nicht sinnvoll ersetzt werden
            exit_check (document . getElementById(feld . name), "Fehlerhafte Eingabe des Datums");
            return false;
        }
    } else {
        // falls Punkte vorhanden, werden hier die vorderen Zeichen aufgefuellt mit  NULLEN
        var punkt1 = vormals . indexOf(".");

        var tt = vormals . substr(0, punkt1);
        var mmyy = vormals . substr(1 + punkt1);

        var punkt2 = mmyy . indexOf(".");

        var mm = mmyy . substr(0, punkt2);
        var yy = mmyy . substr(1 + punkt2);

        if (tt . length == 1) {
            tt = '0' + tt;
        }
        if (mm . length == 1) {
            mm = '0' + mm;
        }
        if (yy . length == 1) {
            yy = '0' + yy;
        }
        if (yy . length == 2) {
            if (yy < 10) {
                yy = '20' + yy;
            } else {
                yy = '19' + yy;
            }
        }
    }

    if (yy . length == 2) {
        if (yy < 10) {
            yy = '20' + yy;
        } else {
            yy = '19' + yy;
        }
    }

    var b_date = check_valid_date(yy, mm, tt);
    if (b_date == false) {
        exit_check (feld, "ungueltiges Datum");
        return false;
    }
    // neues Datum wird nun wieder ins Feld gesetzt
    document . getElementById(feld . name) . value = tt + "." + mm + "." + yy;
    // hier sollten noch bestimmte Daten raus fallen, zb. Geburtstage
    if (feld . name == 'pk_userdata_gebdatum' || feld . name == 'pk_cinemaxx_data_gebdatum') {
        var r_alter = true;
    } else {
        var r_alter = false;
    }
    // flag entscheidet darueber, ob Datum in Zukunft oder Vergangenheit liegen soll
    // keine ueberpruefung fuer das Datum der Memo-Eingabe
    if (feld . name == 'admin_fza_register_history_memo_datum') {
        return true;
    }

    var b_date_past = check_datum_vergangen(feld, r_alter);
    if (b_date_past == false) {
        // exit_check (feld, "Datum liegt in der Vergangenheit");
        return false;
    }
} // end func replaceTrennzeichenToPunkt
// Test, ob Parameter eine gueltige E-Mail ist
function check_email(val)
{
    var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
    var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
    var regex = "^" + usr + "\@" + domain + "$";
    var myrxp = new RegExp(regex);
    var check = (myrxp . test(val));

    if (check != true) {
        return false;
    }
    return true;
}
// Test, ob Parameter eine gueltige E-Mail ist
function check_valid_date(y, m, t)
{
    // test auf gueltiges Datum
    var int_mm = m -1;
    var check_date = new Date(y, int_mm, t);
    // Datum wird anhand von Jahr, Monat und Tag berechnet (Monat faengt bei 0 an zu zaehlen, deswegen vorher eins abziehen ;-) )
    // danach ermitteln von Jahr, Monat und Tag, wenn alle Angaben mit der Eingabe uebereinstimmen, dann ist das Datum gueltig
    // (wird zum 32 als Tag eingegeben, rechnet JS automatisch ein Tag im Feb aus - das waere dann falsch)
    var tag = check_date . getDate();
    var monat = check_date . getMonth();
    var jahr = check_date . getFullYear();
    if (tag != t || monat != int_mm || jahr != y) {
        return false;
    }
    return true;
}

// Test, ob Parameter ein numerischer Wert ist
function check_num_val(val)
{
    var myvalue = val;
    // var num = myvalue . match(/[^0-9,\.]/gi);
    var num = myvalue . match(/[^0-9,\.]/gi);

    if (num != null) {
        return false;
    }
    return true;
}

// einheitlicher Ausstieg aus Felder-Check
function exit_check(feld, text, del_val)
{
    if (!feld) {
        alert ("kein Feld: " + feld + "\n\ntext: " + text);
        return true;
    }

    last_field = feld . name;
    // alert ("Feldname: "+feld.name);
    feld . style . backgroundColor = '#FF0000';
//    alert("Bitte beachten Sie: \n\n" + text);
    alert(text);
    if (del_val == true) {
        feld . value = '';
    }

    if (feld . type != 'text' && feld . type != 'textarea' && feld . type != 'select-one' && feld . type != 'checkbox' && feld . type != 'password') {
        alert ("kein Fokus-Typ gefunden... \n\nZeile 1077\n\n;-)\n\n" + feld . type + "\n\n" + feld . name);
    }

    var focus_error = feld . focus();
    feld . style . backgroundColor = '';
    if (focus_error) {
        alert ('Fehler beim Fokus-Setzen des Feldes. ' + feld);
    }
    if (feld . type == 'text' || feld . type == 'textarea' || feld . type == 'password') {
        feld . select();
    }

}

// hier werden dann speziele Kombinationen, die notwendig sind, abgeprueft
function check_spezial_konditions()
{
            if (document . getElementById('email') . value != document . getElementById('email2') . value) {
            document . getElementById('email2').value='';
                exit_check (document . getElementById('email2'), "E-Maileingaben stimmen nicht ueberein");
                return false;
            }
            if (document . getElementById('password') . value !=  document . getElementById('password2') . value) {
            document . getElementById('password').value='';
            document . getElementById('password2').value='';
                exit_check (document . getElementById('password'), "Passworteingaben stimmen nicht ueberein");
                return false;
            }

}

