// Variables

/*Values Contenidos*/

var textAutor = "#textAutor";
var textEmail = "#textEmail";
var textComentario = "#textComentario";

var autor = "#autor";
var email = "#email";
var comentario = "#comentario";
var formulario = ".comentarios";

//CARGA DEL DOCUMENTO
$(document).ready(function (){
	/*Llamada form contenidos*/
	$(formulario).submit(function (){
		if(presionaBotonSubmitContenidos())
		{	
			return true;
		}
		else{
			return false;	
			}
	});	
		
});	

//FUNCIONES

function presionaBotonSubmitContenidos(){
	
	if(compTodosContenidos())
	{
		return true;
	}
	else
	{
		return false;
	}
}

function compTodosContenidos(){
	var ok = true;	
	if(!compAutor())
		ok = false;	
	if(!compEmail())
		ok = false;	
	if(!compComentario())
		ok = false;	
		
	return ok;
}

/*VALIDACIONES*/
function compAutor(){
	if($(autor).attr("value") == null){
		pintarTextoError(textAutor);
		return false;
	}
	else{
		pintarTextoNormal(textAutor);
		return true;
		}
}

function compEmail(){	
	var email2 = ($(email).val());
	var AtPos = email2.indexOf("@")
	var StopPos = email2.lastIndexOf(".")
	var ok = true

	if (email2 == "") {
	ok = false;
	}

	if (AtPos == -1 || StopPos == -1) {
	ok = false;
	}

	if (StopPos < AtPos) {
	ok = false;
	}

	if (StopPos - AtPos == 1) {
	ok = false;
	}
	
	if(ok){
		pintarTextoNormal(textEmail);
	}
	else{
		pintarTextoError(textEmail);
	}
		
return ok;
		
}

function compComentario(){
	if($(comentario).attr("value") == null){
		pintarTextoError(textComentario);
		return false;
	}
	else{
		pintarTextoNormal(textComentario);
		return true;
		}
}




/****Acciones Báscias****/

function limpiarTextoError(){
$(textoError).empty();	
}

function ponerError(string){
$(textoError).append(string+" <br> ");
}

function ocultarCapaError(){
$(capaError).hide();
}

function mostrarCapaError(){
$(capaError).show();
}

function pintarTextoError(text){ 
$(text).css('color', '#FF0000');
}

function pintarTextoNormal(text){
$(text).css('color', '#666666');
}

