﻿String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function validate_email(field)
{
    if (field.value == null || dotpos.value == null)
        return false;
        
    var apos = field.value.indexOf("@");
    var dotpos = field.value.lastIndexOf(".");
        
    return !(apos<1||dotpos-apos<2);
}

function validate_is_not_empty(field) 
{
    if (field.value == null)
        return false;
        
    return (field.value.trim().length > 0);
}

function validate_form(thisform)
{
    var author = document.getElementById('author_name');
    var body = document.getElementById('body');
    
    var status = true;
    
    if(!validate_is_not_empty(author) ) {
        author.focus();
        document.getElementById('validation_author').style.visibility = 'visible';
        status = false;
    }
    else
        document.getElementById('validation_author').style.visibility = 'hidden';
    
    if(!validate_is_not_empty(body) ) {
        body.focus();
        document.getElementById('validation_body').style.visibility = 'visible';
        status = false;
    }
    else
        document.getElementById('validation_body').style.visibility = 'hidden';
    
    return status;
}
