// javascript for investment24
// Extra Fenster oeffnen
function fenster (url,name,wi,hi) {
    ext_window = window.open(url, name,"width="+wi+",height="+hi+",screenX=100,screenY=100,top=100,left=100,scrollbars=yes,menubar=yes,resizable=yes,innerHeight=1,innerWidth=1");
    ext_window.focus();
}
// Extra Fenster schliessen
function schliessen () {
    self.close();
}
// used for email security
function send(email,subject) {
    location.href = "mailto:"+email+"?subject="+subject;
}
// marks formelement
function on_focus (form,name) {
    document.forms[form].elements[name].focus(); // select () früher aber es gab bei ddl´s probleme
}
// show a hidden field
function show_field (id) {
    document.getElementById(id).style.visibility = 'visible';
}
// shows an div container
function show_block (id) {
    document.getElementById(id).style.display = 'inline' ;
}
// hides a visible field
function hide_field (id) {
    document.getElementById(id).style.visibility = 'hidden';
}
// hides an div container
function hide_block (id) {
    document.getElementById(id).style.display = 'none' ;
}
function set_attribute (id,attrib,value) {
    document.getElementById(id).style[attrib] = value;
}
// preselect the item in the ddl or optionfield
function set_item (typ,elem,value,form) {
    if (!form) { form = 0; }
//alert(typ+'-'+elem+'-'+value+'-'+form);
    if (typ == "ddl") {
        for (Cnt=0; Cnt < document.forms[form].elements[elem].length; Cnt++) {
            if (document.forms[form].elements[elem].options[Cnt].value == value) {
                document.forms[form].elements[elem].options[Cnt].selected = true;
            }
        }
    }
    if (typ == "opt") {
        for (Cnt=0; Cnt < document.forms[form].elements[elem].length; Cnt++) {
            if (document.forms[form].elements[elem][Cnt].value == value) {
                document.forms[form].elements[elem][Cnt].checked = true;
            }
        }
    }
    if (typ == "box") {
        if (value == document.forms[form].elements[elem].value) {
            document.forms[form].elements[elem].checked = true;
        } else {
            document.forms[form].elements[elem].checked = false;
        }
    }
    if (typ == "text") {
        document.forms[form].elements[elem].value = value;
    }
}
// handle the periphere option like the new bereich
function set_periphere (form,masterid,value) {
//alert(form+'-'+masterid+'-'+value);
    for (Cnt=0; Cnt < document.forms[form].elements[masterid].length; Cnt++) {
        id = masterid+document.forms[form].elements[masterid].options[Cnt].value;
        if (document.getElementById(id)) {
            shade(id);
            hide_block (id);
        }
    }
    show_block (masterid+value);
    deshade(masterid+value);
}
// marks all checkboxes in a list
function mark_all (check,field,quantity,form) {
    if (!form) { form = 0; }
//alert(check+'-'+field+'-'+quantity+'-'+form);
    quantity = quantity-1;
    if (document.forms[form].elements[check].checked) {
        for (cnt=1; cnt <= quantity; cnt++) {
            document.forms[form].elements[field+'['+cnt+']'].checked = true;
        }
    } else {
        for (cnt=1; cnt <= quantity; cnt++) {
            document.forms[form].elements[field+'['+cnt+']'].checked = false;
        }
    }
}
// make usable disable the grey
function deshade(block) {
    if (block == "co_ppayment") {
        document.contact.must_co_pfreefield1.disabled = false;
        document.contact.co_pfreefield2.disabled = false;
        document.contact.co_pfreefield3.disabled = false;
        document.contact.must_co_padress1.disabled = false;
        document.contact.co_padress2.disabled = false;
        document.contact.must_co_pzip.disabled = false;
        document.contact.must_co_pcity.disabled = false;
        document.contact.must_co_pcountry.disabled = false;
        set_attribute ("lng_co_pfreefield1","color","#000000");
        set_attribute ("lng_co_pfreefield2","color","#000000");
        set_attribute ("lng_co_padress1","color","#000000");
        set_attribute ("lng_co_padress2","color","#000000");
        set_attribute ("lng_co_pzip","color","#000000");
        set_attribute ("lng_co_pcity","color","#000000");
        set_attribute ("lng_co_pcountry","color","#000000");
    }
}
// make unusable disable the fields and the letters grey
function shade(block) {
    if (block == "co_ppayment") {
        document.contact.must_co_pfreefield1.disabled = true;
        document.contact.co_pfreefield2.disabled = true;
        document.contact.co_pfreefield3.disabled = true;
        document.contact.must_co_padress1.disabled = true;
        document.contact.co_padress2.disabled = true;
        document.contact.must_co_pzip.disabled = true;
        document.contact.must_co_pcity.disabled = true;
        document.contact.must_co_pcountry.disabled = true;
        set_attribute ("lng_co_pfreefield1","color","#A0A0A0");
        set_attribute ("lng_co_pfreefield2","color","#A0A0A0");
        set_attribute ("lng_co_padress1","color","#A0A0A0");
        set_attribute ("lng_co_padress2","color","#A0A0A0");
        set_attribute ("lng_co_pzip","color","#A0A0A0");
        set_attribute ("lng_co_pcity","color","#A0A0A0");
        set_attribute ("lng_co_pcountry","color","#A0A0A0");
    }
}
// window size
function window_size () {
    var y;
    if (self.innerHeight) {
        // all except Explorer
        y = self.innerHeight - 120;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        // Explorer 6 Strict Mode
        y = document.documentElement.clientHeight - 140;
    } else if (document.body) {
        // other Explorers
        y = document.body.clientHeight - 145;
    }
    if (!y) {
        y = 500;
    }
    //document.getElementById('content').style.height = y+'px';
//alert(y);
}
// dropdown mainnavigation
var timer;
var lock = 0;
function show_menu(id){
    if (id != 0) {
        window.clearTimeout(timer);
        lock = 0;
        close_menu ();
        document.getElementById('controlblock').style.zIndex = '100';
        show_field (id);
        lock = 1;
    }
}
function out_menu(){
    lock = 0;
    timer = window.setTimeout("close_menu()",150);
}
function close_menu(){
    if (lock == 0) {
        for (i = 1; i <= 6; i++) {
            document.getElementById('controlblock').style.zIndex = '0';
            hide_field ('navelements_'+i);
        }
    }
}
// send forms with enter
var VALUE_FOR_RETURN_KEY = 13;
var VALUE_FOR_ENTER_KEY_MACOS = 3;
var ua = navigator.userAgent;
var bW3C=false;bFirefox=false,bOpera=false,bMSIE=false,bMozilla=false,bNetscape=false,bSafari=false,bMozilla121=false;
if ( ua.indexOf("Firefox") > -1 ) bFirefox = true;
if ( ua.indexOf("Opera") > -1 ) bOpera = true;
if ( ua.indexOf("MSIE") > -1 ) bMSIE = true;
if ( ua.indexOf("Gecko") > -1 && ua.indexOf("Mozilla") > -1 && ua.indexOf("Netscape") == -1 && ua.indexOf("Firefox") == -1 ) bMozilla = true;
if ( ua.indexOf("Gecko") > -1 && ua.indexOf("Mozilla") > -1 && ua.indexOf("Netscape") > -1 ) bNetscape = true;
if ( ua.indexOf("Safari") > -1 ) bSafari = true;
var bW3C = bFirefox || bMozilla || bNetscape || bOpera || bSafari;
if ( bMozilla && ua.indexOf("rv:1.2.1") > -1) bMozilla121 = true;
handleKeyDown(executeDefaultFunctionOnEnter);
function handleKeyDown(keyDownFunction) {
    if ( bW3C ) {
        document.captureEvents (Event.KEYPRESS);
        document.onkeypress = keyDownFunction;
    } else if ( bMSIE ) {
        document.onkeyup = keyDownFunction;
    }
}
function executeDefaultFunctionOnEnter(event) {
    if ( bMSIE ) {
        var event = window.event;
        if ( event.keyCode == VALUE_FOR_RETURN_KEY ) execute();
    } else if ( !bSafari && bW3C ) {
        if ( event.which == VALUE_FOR_RETURN_KEY) execute();
    } else if ( bSafari ) {
        if ( event.which == VALUE_FOR_RETURN_KEY || event.which == VALUE_FOR_ENTER_KEY_MACOS ) execute();
    }
}
var submid = true;
var formname = "login";
function set_submitform(val) {
    formname = val;
    submid = true;
}
function unset_submit () {
    submid = false;
}
function execute() {
    if (submid) { // && !bMSIE
        submid = false;
        document.forms[formname].submit();
    }
}
// get mousepostion and set tooltip
if (bW3C) {
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (bMSIE) {
    document.onmousemove = captureMousePosition;
}
xmousepos = 0;
ymousepos = 0;
setfieldid = 0;
function captureMousePosition(e) {
    if (bW3C) {
        xmousepos = e.pageX;
        ymousepos = e.pageY;
    } else if (bMSIE) {
        xmousepos = window.event.x;
        ymousepos = window.event.y;
    }
    if (setfieldid != 0) { set_field (setfieldid); }
}
function set_field (id) {
    x = xmousepos + 15;
    y = ymousepos - 2;
    document.getElementById(id).style.left = x+'px';
    document.getElementById(id).style.top = y+'px';
    show_field (id);
    setfieldid = id;
}
function unset_field (id) {
    setfieldid = 0;
    hide_field (id);
}