
function getEventSrc(e) {
 // get a reference to the IE/windows event object
 if (!e) e = window.event;

 // DOM-compliant name of event source property
 if (e.target)
   return e. target;
 // IE/windows name of event source property
 else if (e.srcElement)
   return e.srcElement;
}

//
// Process the XForm submission
//
function submitForm(form, modelid, submissionid) {
    var saction = '__submission_action+'+modelid+'+'+submissionid
    var smethod = '__submission_method+'+modelid+'+'+submissionid
    // This is basically a hack, because, for some reason, early mozilla
    // versions seem to supress the value of the submitted button when
    // the onclick event is raised
    form.__submit__.value = modelid+'+'+submissionid
    for (var i=0; i < form.elements.length; i++) {
        if (form.elements[i].name == saction) {
            form.action = form.elements[i].value;
        }
        else if (form.elements[i].name == smethod) {
            if (form.elements[i].value == 'form-data-post') {
                form.method = 'POST';
                form.enctype = 'multipart/form-data';
            }
            else if (form.elements[i].value == 'urlencoded-post') {
                form.method = 'POST';
                form.enctype = 'application/x-www-form-urlencoded';     
            }
            else {
                form.method = 'GET';
            }
        }
    }
    form.submit();
    return true;
};


function submitButtonHandler(submitter) {
    var sparts = submitter.name.split('+');
    var sname = sparts[0];
    var modelid = sparts[1];
    var submissionid = sparts[2];

    return submitForm(submitter.form, modelid, submissionid);
}

function keypressEventHandler(form, event) {
    target = getEventSrc(event);
    var sparts = target.name.split('+');
    var modelid = sparts[0];
    var submissionid = '';
    if (event.keyCode == 13) {
        for (var i=0; i < form.elements.length; i++) {
            var eparts = form.elements[i].name.split('+');
            if (eparts[0] == '__submission_action' && eparts[1] == modelid) {
                if (submissionid != '') {
                   return false;
                }
                else {
                   submissionid = eparts[2];
                }
            }
        }
        submitForm(form, modelid, submissionid);
        return false;
    }
    return true;
}
