/* ----------------------------------------------------
     Functions written by
     Pletschette André (www.pletschette.com/andre)
   ----------------------------------------------------*/


/* ----------------------------------------------------
   ----  Variables      -------------------------------
   ----------------------------------------------------*/
var made_changes = false;


/* ----------------------------------------------------
   ----  Functions      -------------------------------
   ----------------------------------------------------*/

/* ----------------------------------------------------
    Checks if you made any changes to form fields
*/
function test_exit() {

        if (made_changes) {
                return confirm("\nIf you click yes, your changes won't be saved!\n\n"+
                                "Click cancel if you want to save them.\n\n");
        } else {
                return true;
        }
}

/* ----------------------------------------------------
    Function that does nothing else than loading
    the page URL into the current frame
*/
function loadURL(URL) {
        //alert("I'me alive2");
        if (test_exit()) {
                if (URL == "") {
                        //alert("Ungültige Adresse!");
                } else {
                        //alert("Gültige Adresse!");
                        location.href = URL;
                        location.replace(URL);
                }
        }
}

/* ----------------------------------------------------
    Sets all the variables which are given as
    arguments to value
*/
function setFields(value) {
        // see page 52 in the book of Stefan Koch
        // for functions with variable arguments
        for (var i = 1; i < setFields.arguments.length; i++) {
                for (var j=0; j < (document.forms[0].elements.length); j++) {
                        //alert(i+': '+j+': '+document.forms[0].elements[j].name+' - '+document.forms[0].elements.length);
                        if (document.forms[0].elements[j].name == setFields.arguments[i]) {
                                document.forms[0].elements[j].value = setFields.arguments[0];
                        }

                }
        }
}

/* ----------------------------------------------------
    Set Focus to the first cell in a form
*/
function setFocus() {
        if (document.forms[0].elements[0])  {
                var first = "";
                //alert("OK; JavaScript");
                for (var i=1; i < (document.forms[0].elements.length); i++) {

                        if ((!(document.forms[0].elements[i].type == "hidden")) && (!(document.forms[0].elements[i].type == "submit")) && (first == "")) {
                                //alert("Selecting: "+i);
                                document.forms[0].elements[i].focus();
                                document.forms[0].elements[i].blur();
                                if ((document.forms[0].elements[i].type == "text") || (document.forms[0].elements[i].type == "password")) {
                                        document.forms[0].elements[i].select();
                                }
                                first = i;
                        }
                }
        }
}
