var max = 19;
var min = 10;
tamano_original=13;
function upSize() {
	size = parseInt(document.getElementById("cuerpo").style.fontSize);
	if(size=='' || isNaN(size)) size=tamano_original;
	if (size < max) {
		size=size+3;
	}
	document.getElementById("cuerpo").style.fontSize = size + "px";
}
function downSize() {
	size = parseInt(document.getElementById("cuerpo").style.fontSize);
	if(size=='' || isNaN(size)) size=tamano_original;
	if (size > min) {
		size=size-3;
	}
	document.getElementById("cuerpo").style.fontSize = size + "px";
}
function checkmail(str){var at="@";var dot=".";	var lat=str.indexOf(at);var lstr=str.length;var ldot=str.indexOf(dot);var ok ="1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";if (str.indexOf(at)==-1){return false;}for(k=0; k < str.length ;k++){if(ok.indexOf(str.charAt(k))<0){return false;}}if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}if (str.indexOf(at,(lat+1))!=-1){return false;}if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}if (str.indexOf(dot,(lat+2))==-1){return false;}if (str.indexOf(" ")!=-1){return false;}return true;}


function initSendToAFriend(contenedor, formulario){
	var handleSubmit = function() {this.submit();};
	var handleCancel = function() {this.cancel();};
	var callbackSucces = function(o) {formulario.nombre.value="";formulario.mail.value="";formulario.mail_amigo.value="";alert("La noticia fue enviada correctamente");};
	var handleFailure = function(o) {alert('Se produjo un error, intentelo mas tarde');};
	contenedor.sendFriend= new YAHOO.widget.Dialog("comentarioSndFrnd",{ width : "30em",fixedcenter : true,visible : false, constraintoviewport : true, modal:true, buttons : [ { text:"Enviar", handler:handleSubmit, isDefault:true },{ text:"Cancelar", handler:handleCancel } ]});
	contenedor.sendFriend.validate = function() {
		var data = this.getData();
		if(data.nombre == "") {
			alert('Debe indicar su nombre');
			return false;
		}
		if(data.mail == "") {
			alert('Debe indicar su email');
			return false;
		}
		if (!checkmail(data.mail)){
			alert('La direccion indicada como su mail no es valida');
			return false;
		}
		if(data.mail_amigo == "") {
			alert('Debe indicar el email de la persona a la que desea enviar la noticia');
			return false;
		}
		if (!checkmail(data.mail_amigo)){
			alert('La direccion indicada de la persona a la que desea enviar la noticia no es valida');
			return false;
		}
		return true;
	};
	contenedor.sendFriend.callback = { success: callbackSucces,failure: handleFailure };
	contenedor.sendFriend.render();
	YAHOO.util.Event.addListener(["sndFrndBttn1","sndFrndBttn2","sndFrndBttn3","sndFrndBttn4"], "click", mostrarSendFriend,contenedor.sendFriend );
}

function mostrarSendFriend(evento,dialogo){dialogo.show();}

function initComentDialog(contenedor) {
	var handleSubmit = function() {this.submit();};
	var handleCancel = function() {this.cancel();};
	var handleSuccess = function(o) {
		var r = o.responseText;
		if (r!= 'valido'){
			alert('El codigo ingresado no coincide');
			mostrar_dialog({comentario_id:null});
			return -1;
		}
		alert('Su comentario fue ingresado con exito');
		var cadena = document.getElementById("cantidad_mensajes").innerHTML;
		var primero=cadena.indexOf("<B>");
		var ultimo=cadena.indexOf("</B>");
		numero=parseInt(cadena.substring(primero+3,ultimo));
		siguiente=numero+1;
		cadena=cadena.replace(numero,siguiente);
		document.getElementById("cantidad_mensajes").innerHTML=cadena;
		mostrar_comentarios({articulo_id:contenedor.contenido_id,pagina:1});
	};
	var handleFailure = function(o) {alert('Se produjo un error, intentelo nuevamente');};
	contenedor.dialog1 = new YAHOO.widget.Dialog("comentarioFrmCont",{ width : "auto",fixedcenter : true,visible : false, constraintoviewport : true, modal:true, buttons : [ { text:"Enviar", handler:handleSubmit, isDefault:true },{ text:"Cancelar", handler:handleCancel } ]});
	contenedor.dialog1.validate = function() {var data = this.getData();if (data.nombre == "") {alert("Por favor ingrese su nombre o seudonimo.");return false;}if (data.comentario == "") {alert("Por favor ingrese su comentario.");return false;}if (data.captchacode == "") {alert("Por favor copie el codigo de seguridad que aparece en el formulario.");return false;}return true;};
	contenedor.dialog1.callback = { success: handleSuccess,failure: handleFailure };
	contenedor.dialog1.render();
	YAHOO.util.Event.addListener(["comentar_top1","comentar_top2","comentar_top3","comentar_bottom1","comentar_bottom2","comentar_bottom3"], "click", mostrar_dialog_wrap, {comentario_id:0}, contenedor.dialog1);
}
function mostrar_dialog_wrap(evento, requestObj){
	mostrar_dialog(requestObj);
}
function mostrar_dialog(requestObj){
	var imgDest = document.getElementById('imgCaptcha');
	var imgSrc = 'captcha.asp?rnd='+parseInt(Math.random()*1000);
	imgDest.setAttribute("src", imgSrc);
	//alert(imgSrc);
	if (requestObj.comentario_id!=null){document.form_comentario.comentario_id.value=requestObj.comentario_id;}YAHOO.container.dialog1.show();
}


//Listar Comentarios
function mostrar_comentarios(requestObj){
	var content = document.getElementById("contenedor_comentarios");
	content.innerHTML = "";
	var callback={cache:false, success : function(o){ content.innerHTML = o.responseText; },failure : function(o) {content.innerHTML = "no se pudo conectar al servicio!";}};
	var conn = YAHOO.util.Connect;
	conn.asyncRequest("GET", "/vertext/includes/listar_comentarios.asp?id="+requestObj.articulo_id+"&pagina="+requestObj.pagina, callback);
}

