
function validate() 
{
    var error;
    var email_regex = /^([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
    
    // swfu is the SWFUpload javascript object and must be defined
    if (test_for_file && swfu.getFile(0) == null)
    {
        error = 'You must upload a file! Please try again.';      
    }
    else if (jQuery("#publish_title")[0].value.length == 0)
    {
        error = 'You must specify a title! Please try again.';             
    }
    else if (jQuery("#publish_email").length && (jQuery("#publish_email")[0].value.length == 0 || !(jQuery("#publish_email")[0].value.match(email_regex))))
    {
        error = 'You must specify a valid email address! Please try again.' ;            
    }
    else if (jQuery(".checkbox").length && !jQuery(".checkbox")[0].checked)
    {
        error = 'You must accept the terms and conditions! Please try again.';
    }    
    else if (jQuery("#recaptcha_response_field").length && jQuery("#recaptcha_response_field")[0].length == 0)
    {
        error = 'You didn\'t fill in the CAPTCHA! Please try again.';            
    }
    
    if (error)
    {
        jQuery(".error").html(error);  
        location.href="#error";
    } 
    else 
    {
      jQuery(".error").html('');
    }
    
    return error == null;    
}
