function do_action(_action)
{
   window.document.formMain.h_action.value = _action;
   window.document.formMain.submit();
}
function do_action2(_action,_plus)
{
   window.document.formMain.h_action.value = _action;
	window.document.formMain.action = window.document.formMain.action + "?" + _plus;
   window.document.formMain.submit();
}
function do_action_n(_action)
{
   window.document.formMain.h_action.value = _action;
   window.document.formMain.target = '_blank';
   window.document.formMain.submit();
   window.document.formMain.target = '';
}
function jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function AssertException(message) { this.message = message; }
AssertException.prototype.toString = function () {
    return 'AssertException: ' + this.message;
}

function assert(cond, err) {
    if (!cond) {
        if ( err == null )
            err = "Assertion failed.";

        alert("Assertion failed: "+ err);
        throw new AssertException(err);
    }
}

function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; }

function uniqueWindowName() {
    var day = new Date();
    var id = day.getTime();
    return "uw" + id;
}

function autoPopup(frm){
    if ( window.opener 
//VR 27.01.2010
		 && frm.target.substring(1,2) == "uw"    //Ist ein unseres PopUp-Fenster schon geöffnet?
    	) {
        // sind wir im Popupfenster?
        return autoPopupAccept(frm);
    }
    else {
        assert(frm.elements.action != null, "form has action element");
        if ( frm.target == null || frm.target == "" )
            frm.target=uniqueWindowName(); // wenn leer, Popupnamen generieren

        frm.elements.action.value = "popup";
//VR 26.06.2009 - Für neue Map wird das Fenster größer gemacht
//VR 26.06.2009        window.open("",frm.target,"toolbars=0,width=620,height=550");
//VR 22.02.2011        window.open("",frm.target,"toolbars=0,width=620,height=620");
        window.open("",frm.target,"toolbars=0,width=820,height=720");

        return true;
    }
}

function autoPopupAccept(frm)
{
    assert(!isEmpty(window.opener), "is a popup");
    assert(!isEmpty(frm.id), "form has id");

    var w = window.opener;
    var frmId = frm.id;
    var f = w.document.getElementById(frmId);
    var tmpAction;
    var tmpFormData={};

    assert(f != null, "parent form exists");

    // copy over all named form elements
    for ( var i=0; i < frm.length; i+=1 ) {
        var nam = frm.elements[i].name;
        if ( nam != null && f.elements[nam] != null ) {
            tmpFormData[nam] = f.elements[nam].value; // save
            f.elements[nam].value = frm.elements[nam].value;
        }
    }

    w.name = uniqueWindowName();
    f.target = w.name;
    if ( f.attributes["realaction"] ) {
        tmpAction=f.action;
        f.attributes["action"].value = f.attributes["realaction"].value; // enable the secondary action
    }
    f.elements.action.value = "applypopup";
    f.submit();
    if ( f.attributes["realaction"] ) {
        f.attributes["action"].value=tmpAction; //restore old action
    }

    // restore old form elements
    for ( var i=0; i < frm.length; i+=1 ) {
        var nam = frm.elements[i].name;
        if ( nam != null && f.elements[nam] != null ) {
            f.elements[nam].value = tmpFormData[nam];
        }
    }
    window.close();
    return false;
}

function submitFormEl(me)
{
    // submits the first form it finds going up the DOM tree
    //
    while (me != null) {
        if ( me.nodeName.toLowerCase() == "form" ) {
            if ( me.onsubmit )
            {
                if ( me.onsubmit() )
                    me.submit();
            }
            else
                me.submit();
            return;
        }
        me = me.parentNode;
    }
    throw("No form found.");
}

function submitForm(frm)
{
    if ( frm.onsubmit )
    {
        if ( frm.onsubmit() )
            frm.submit();
    }
    else
        frm.submit();
}

