function validate_form ( myform )
{
    valid = true;

    name = trim( myform.name.value, "\\s" );
    email = trim( myform.email.value, "\\s" );
    blog_url = trim( myform.blog_url.value, "\\s" );
    blog_name = trim( myform.blog_name.value, "\\s" );
    age = trim( myform.age.value, "\\s" );
    description = trim( myform.name.value, "\\s" );
    politics = myform.politics.checked;

    if ( name == "" )    {
        alert ( "Por favor, introduce tu Nombre" );
        valid = false;
    }
    else if ( email == "" )    {
        alert ( "Por favor, introduce tu Email" );
        valid = false;
    }
    else if ( ! checkemail( email ) )    {
        alert ( "Por favor, introduce un Email válido" );
        valid = false;
    }
    else if ( blog_url == "" )    {
        alert ( "Por favor, introduce la Url de tu blog" );
        valid = false;
    }
    else if ( ! checkURL( blog_url ) )    {
        alert ( "Por favor, introduce una Url válida" );
        valid = false;
    }
    else if ( blog_name == "" )    {
        alert ( "Por favor, introduce el Nombre de tu blog" );
        valid = false;
    }
    else if ( age == "" )    {
        alert ( "Por favor, introduce tu Edad" );
        valid = false;
    }
    else if ( description == "" )    {
        alert ( "Por favor, danos información sobre ti" );
        valid = false;
    } else if ( ! politics ) {
        alert ( "Debe aceptar la política de privacidad");
        valid = false;
    }

    return valid;
}

/*   ---   */

function checkemail(str){
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str)) {
        testresults=true
    } else{
        testresults=false
    }
    return (testresults)
}
/*   ---   */

function checkURL(str) {
    lengthValue = trim(str);
    lengthValue = lengthValue.length;
    res = true;

    if(lengthValue != 0) {
        var j = new RegExp();
        j.compile("^https?://[A-Za-z0-9-]+\.[A-Za-z0-9]+");
        lengthValue = trim(str);
        if (!j.test(lengthValue)) {
            res = false;
        }
    } else {
        res = false;
    }
    return res;
}
/*   ---   */

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
/*   ---   */
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
/*   ---   */
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
/*   ---   */
/*   ---   */
