//***************************************************************
// General Purpose Functions for ZPortal                        
//                                                              
// Modification History                                         
//                                                              
// 11/10/01 RCH Created - autotab stuff (stolen from VDXWeb 2.2.7)
// 31/10/01 RCH added enterSubmit()
// 16/11/01 RCH added confirm_msg()
// 21/11/01 RCH change in text prompt for AllowSubmit
// 15/01/04 RCH enterSubmit and autoTab now actually submit the form since processForm doesn't
//                                                              
//***************************************************************

// functions for performing tabbing between form elements

function autoTab(input, e)
{
    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
    var keyCode = (isNN) ? e.which : e.keyCode;

    if (keyCode == 13)
    {
        var next = getNext(input);
        if (next != -1)
        {
            if (isNN)
                eval('input.form[next].focus()');
            else
                e.keyCode = 9;
        }
        else
        {
            // At the end of the form
            if (processForm(input.form))
            {
                input.form.submit();
            }
        }
    }
    return false;
}

function getNext(input) 
{
    var index = -1, i = 0;
    for (i=0; i < input.form.length; i++)
    {
        if(input.form[i] == input)
        {
            // skip hidden elements
            if (input.form[(i+1)].type != "hidden")
            return (++i < input.form.length) ? i : -1;
        }
    }
    return -1;
}


function enterSubmit(input, e)
{

    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
    var keyCode = (isNN) ? e.which : e.keyCode;
    if (keyCode == 13)
    {
        if (processForm(input.form))
        {
            input.form.submit();
        }
        return false;
    }
    return true;
}

function hideEnterKey(e)
{

    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
    var keyCode = (isNN) ? e.which : e.keyCode;

    if (keyCode == 13)
        return false;
    return true;
}


//  functions that control stopping forms being submitted multiple times.

function AllowSubmit(action_form)
{
	if (action_form.form_submitted)
	{
		if (get_text(action_form.name, "form_submitted") == 'true')
		{
			return confirm_msg("Cette page a déjà été soumise. Soumettre encore?");
		}
		else
			return true;
	}

	return true;
}


function SetSubmit(action_form,value)
{
	if (action_form.form_submitted)
		set_text(action_form.name,"form_submitted", value);
}

function confirm_msg(text)
{
    if(text == null || text == "")
    {
        return true;
    }
    return confirm(text);
}
