function verifica_comentario(frm){
	var texto;
	for(i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type== "text" && frm.elements[i].value=="" || frm.elements[i].type=="textarea" && frm.elements[i].value==""){
			alert("Preencha o campos ");
			frm.elements[i].focus();
			return false;
		}
		if(frm.elements[i].type=="hidden" && frm.elements[i].value==""){
			alert("Erro ao enviar comentário");
			return false;
		}
	}
	texto = ver_espaco(frm.txt_nome.value);
	if(texto.length>0){
		if(ver_html(texto)){
			alert("Não é permitido html");
			return false;
		}
		frm.txt_nome.value= texto;
	}else{
		frm.txt_nome.value= texto;
		alert("Preencha os campos");
		frm.txt_nome.focus();
		return false;
	}
	if (!isValidEmail(frm.txt_email.value,true)) {
      alert("E-mail inválido");
      frm.txt_email.focus();
	  return false;
	}
	texto="";
	texto =ver_espaco(frm.txt_comentario.value);
	if(texto.length>0){
		if(ver_html(texto)){
			alert("Não é permitido html");
			return false;
		}
		frm.txt_comentario.value= texto;
	}else{
		frm.txt_comentario.value= texto;
		alert("Preencha os campos");
		frm.txt_comentario.focus();
		return false;
	}
	//return false;
}
function ver_html(valor){
	exp= /(\<[a-z]{1,}>(.*?)\<\/[a-z]{1,}>|\<[a-z]{1,}(.*?)>|\<\/[a-z]{1,}>|[a-z]{1,}=\"(.*?)\")/gmi;
	if(valor.match(exp)){
		return true;
	}else{
		return false;
	}
}
function ver_espaco(coment){
	var valor="";
	exp= /(<\?(.*?)\?>|<\?php(.*?)\?>|<\?|\?>|<\?php)/gmi;
	coment= coment.replace(exp,"");
	exp=/\n/gm;
	coment= coment.replace(exp,"{[(linha)]}");
	exp= /\s\s/;
	while(coment.match(exp)){
		coment= coment.replace(exp," ");
	}
	exp= /^\s/;
	coment= coment.replace(exp,"");
	exp= /\{\[\(linha\)\]\}/gm;
	coment= coment.replace(exp,"\n");
	return coment;
}
function insertComentario(canal,id){
	var posx= (screen.width-300)/2;
	var posy= (screen.height-380)/2;
	window.open("./scripts/comentario/formulario.php?canal="+canal+"&id="+id,null,"menubar=no,resizable=no,location=no,toolbar=no,width=300,scrollbars=no,height=380,top="+posy+",left="+posx);
}
function getComentario(canal,id){
	var posx= (screen.width-488)/2;
	var posy= (screen.height-320)/2;
	window.open("./scripts/comentario/get_comentario.php?canal="+canal+"&id="+id,null,"menubar=no,resizable=no,location=no,toolbar=no,scrollbars=yes,width=488,height=320,top="+posy+",left="+posx);
}
function isValidEmail(email, required) {
    if (required == undefined) {
        required = true;
    }
    if (email == null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length == 0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (!allValidChars(email)) {
        return false;
    }
    if (email.indexOf("@") < 1) {
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {
        return false;
    } else if (email.indexOf("@") == email.length) {
        return false;
    }
    return true;
}
function allValidChars(email) {
    var parsed = true;
    var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
    for (var i = 0; i < email.length; i++) {
        var letter = email.charAt(i).toLowerCase();
        if (validchars.indexOf(letter) != -1) {
            continue;
        }
        parsed = false;
        break;
    }
    return parsed;
}
function carregar(){
	window.opener.document.location.reload();
}
function limpar(){
	frm= document.frm_comentario;
	for(i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=="text" || frm.elements[i].type=="textarea"){
			frm.elements[i].value="";
		}
		if(frm.elements[i].type=="checkbox"){
			frm.elements[i].checked=0;
		}
	}
}
