//
//   Validació (inicial) de camp amb valor numčric
//
function valuevalidation(entered, min, max, alertbox, datatype)
    {
    // Value Validation by Henrik Petersen / NetKontoret
    // Explained at www.echoecho.com/jsforms.htm
    // Please do not remove this line and the two lines above.
    with (entered)
        {
        checkvalue=parseFloat(value);
        if (datatype)
            {smalldatatype=datatype.toLowerCase();
            if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
            }
        if ((parseFloat(min)==min && checkvalue<min) ||
            (parseFloat(max)==max && checkvalue>max) ||
             value!=checkvalue)
            {if (alertbox!="") {alert(alertbox);} return false;}
        else {return true;}
        }
    }
//
//   Validació de camp no buit
//
function emptyvalidation(entered, alertbox)
    {
    // Emptyfield Validation by Henrik Petersen / NetKontoret
    // Explained at www.echoecho.com/jsforms.htm
    // Please do not remove this line and the two lines above.
    with (entered)
        {
        if (value==null || value=="")
            {if (alertbox!="") {alert(alertbox);}
             return false;
            }
        else {return true;}
        }
    }
//
//   Validació (final) de camp amb valor numčric.
//   S'afegeix validació de valor nul i conversió a numčric eliminant altres carącters.
//
function fullvalidation(entered, min, max, alertbox, datatype)
    {
    if (emptyvalidation(entered,"")==false)
        {entered.value=0;}
    if (valuevalidation(entered, min, max, alertbox, datatype)==false)
        {return false;}
    smalldatatype=datatype.toLowerCase();
    with (entered)
        {
        if (smalldatatype.charAt(0)=="i")
            {value=parseInt(value);}
        else
            {value=parseFloat(value);}
        return true;
        }
    }
//
//   Validació del formulari complert
//
function formvalidation(thisform)
    {
    initerrmsg();
    with (thisform)
        {

        //   Camps obligatoris

        if (emptyvalidation (name, msg_name)==false)
            {name.focus();
            return false;
            }
        if (emptyvalidation (family_name, msg_family_name)==false)
            {family_name.focus();
            return false;
            }
        if (emptyvalidation (email, msg_email)==false)
            {email.focus();
             return false;
            }
        if (emptyvalidation (pais, msg_pais)==false)
            {pais.focus();
             return false;
            }

        //   Rank: cal triar-ne un

        if (rank.value=="- Choose One -")
            {alert(msg_rank);
             rank.focus();
             return false;
            }

        }
    return true;
    }
