var comentario_enviando = false;9
var comentario_url = "";
var videos_data = Array();
var Asunto = "";

function msgComentarios(Mensaje) {
	document.getElementById('div_msg').innerHTML = Mensaje;
}

// Carga de Videos - tíldes
function verVideo(index)
{
	//var v_datos = String(datos).split(String.fromCharCode(166));
	var v_datos = videos_data[index];
	document.getElementById('ref_id').value = v_datos[0];
	//document.getElementById('div_video_fecha').innerHTML = v_datos[1];
	document.getElementById('div_video_titulo').innerHTML = v_datos[2];
	if (document.all) {
		document.getElementById('div_video_embed').innerHTML = v_datos[8];
	} else {
		document.getElementById('div_video_embed').innerHTML = v_datos[4];
	}
	document.getElementById('div_video_texto').innerHTML = v_datos[5];
	
	// link tampoco siempre esta
	try {
		$('video_link').href = RUTA+"video/"+v_datos[0]+"_"+v_datos[9]+"/";
	} catch (e) {}
	
	// no siempre esta
	try {
		document.getElementById('div_video_dias').innerHTML = v_datos[7];
	} catch (e) {}
	
	// opiniones
	if (v_datos[6] == 0) {
		document.getElementById('div_video_comentarios').innerHTML = "sin&nbsp;comentarios";
	} else
	if (v_datos[6] == 1) {
		document.getElementById('div_video_comentarios').innerHTML = v_datos[6]+"&nbsp;comentario";
	} else {
		 document.getElementById('div_video_comentarios').innerHTML = v_datos[6]+"&nbsp;comentarios";
	}
	
	// dias
	try {
		if (v_datos[7] == 0) {
			document.getElementById('div_video_dias').innerHTML = "Hoy";
		} else
		if (v_datos[7] == 1) {
			document.getElementById('div_video_dias').innerHTML = "Ayer";
		} else {
			 document.getElementById('div_video_dias').innerHTML = v_datos[7]+"&nbsp;d&iacute;as";
		}
	} catch (e) {}
	
	document.getElementById('div_comentarios').innerHTML = "";
	verComentarios(v_datos[0],2);
	addVideoHit(v_datos[0]);
	window.location.href = "#encabezado";
}

// Carga de Comentarios 
function verComentarios(id_ref,id_seccion)
{
	if (id_ref) {
		new Ajax.Updater('div_comentarios', RUTA+'comentarios/'+id_ref+'/'+id_seccion, {onComplete:fixTables});
	}
}

function addVideoHit(id_ref)
{
	var AJAX = new sack(RUTA+"_php/ajax/video_hit.php");
	AJAX.setVar("id", id_ref);
	AJAX.runAJAX();
}

function fixTables()
{
	if (($('tbl_1').offsetHeight + 28) < ($('td_1').offsetHeight + 75)) {
		$('tbl_1').style.height = ($('td_1').offsetHeight)+47;
	} else {
		$('td_1').style.height = $('tbl_1').offsetHeight-47;
	}
}

function enviarComentario() 
{
	var NombreObj = document.getElementById("Nombre");
	var EmailObj = document.getElementById("Email");
	var SitioObj = document.getElementById("Sitio");
	var MensajeObj = document.getElementById("Mensaje");
	
	if (NombreObj.value == "") {
		msgComentarios("Debe completar el Nombre");
		NombreObj.focus();
	} else 
	if (EmailObj.value == "") {
		msgComentarios("Debe completar el Email");
		EmailObj.focus();
	} else
	if (!isEmail(EmailObj)) {
		msgComentarios("Email inv&aacute;lido");
		EmailObj.focus();
	}else
	if (MensajeObj.value == "") {
		msgComentarios("Debe completar el Mensaje");
		MensajeObj.focus();
	} else {
		comentario_send(NombreObj.value, EmailObj.value, SitioObj.value, MensajeObj.value);
	}
}



function comentario_send(A,B,C,D) 
{
	if (!comentario_enviando) {
		var AJAX = new sack(RUTA+"_php/ajax/comentario.php");
		var seccion = document.getElementById('seccion_id').value;
		var id_ref = document.getElementById('ref_id').value;
		AJAX.setVar("Nombre", A);
		AJAX.setVar("Email", B);
		AJAX.setVar("Sitio", C);
		AJAX.setVar("Mensaje", D);
		AJAX.setVar("Seccion", seccion);
		AJAX.setVar("id_ref", id_ref);
		AJAX.onCompletion = function() {
			var v_result = AJAX.response.split("|");
			var result = v_result[0];
			if (result) {
				verComentarios(id_ref,seccion);
				//msgComentarios("Tu opini&oacute;n queda a la espera para ser publicada.");
			} else {
				msgComentarios("En este momento el sistema de envio de mails est&aacute; ca&iacute;do. Lo sentimos.");
			}
			comentario_enviando = false;
		}
		msgComentarios("Enviando...");
		comentario_enviando = true;
		AJAX.runAJAX();
	} else {
		msgComentarios("Enviando, aguarde por favor...");
	}
}

function openPopup(pagina,name,specs){
		var url = RUTA+pagina;
		window.open(url,name,specs);
}