var errorDiv = "";
var termsDiv = "";
var errorTime = "";
var thanksDiv = "";
var thanksTime= "";
var containerComment="";
var containerUserInfo="";
vsmlang = 'es';
function errorComments(txt,id){
	if (errorDiv != "")closeErrorDiv();
	errorDiv = document.getElementById("errorComments"+id);
	errorDiv.style["display"] = "";
	txt = "<img src='/1/img/icn16/warning.gif'>" + txt
	errorDiv.firstChild.innerHTML = txt;
	window.clearInterval(errorTime);
	errorTime = setInterval("closeErrorDiv()",7000);;
	return false;
}
function termsComments(id){
	if (termsDiv!="") closeTermsDiv();
	termsDiv = document.getElementById("termsComments"+id);
	termsDiv.innerHTML = '<div><div class=headline>NORMAS DE USO</div><table cellspacing="2" cellpadding="0"><tr><td valign=top>-</td><td>Los presentes comentarios reflejan exclusivamente la opinión  del lector, mas no necesariamente la de minutouno.com<br></td></tr><tr><td valign=top>-</td><td>No se permitirán opiniones que afecten la honorabilidad o reputación de terceros, como así tampoco aquellas que de algún modo puedan ser contrarias a la legislación vigente en la República Argentina.<br></td></tr><tr><td valign=top>-</td><td> El lector autoriza expresamente a minutouno.com a que edite sus comentarios, o bien los suprima y/o modifique total o parcialmente a fin de adecuarlos a los preceptos enunciados precedentemente.<br></td></tr></table><div align=center style="padding:10px 0px 15px 0px"><a href="javascript:closeTermsDiv();">cerrar</a></div></div><div class=close><a href="javascript:closeTermsDiv();"><img src="/1/img/icn16/close.gif" border=0></a></div>';
	termsDiv.style["display"] = "";
}

function enableBlogComment(id){
	var cm = document.getElementById(id)
	cm.style.display = '';
}
function closeTermsDiv(){termsDiv.style.display='none'}
function closeErrorDiv(){errorDiv.style.display='none'}
function closeThanksDiv(){thanksDiv.style.display='none'}
function closeFormsDiv(id){document.getElementById(id).style.display ='none';}
function clearCssFrmError(tag,id){
	var comments = document.getElementById("frmComments"+id);
	var inputs = comments.getElementsByTagName(tag);
	for(var i=0;i<inputs.length;i++){
		if (inputs[i].className == "vsmformerror") inputs[i].className = "inputs";
	}
}
if (getCookie('comentado')>0){
	id = getCookie('comentado');
	var h1 = document.getElementsByTagName("H1");
	for(var i=0;i<h1.length;i++){
		if (h1[i].className == "headline" ) {
			headline = h1[i];
			break;
		}
	}	
	thanksDiv = document.createElement("DIV");
	thanksDiv.className = "thanks";
	thanksDiv.innerHTML =	"<div class=close style='position:absolute;top;-1px;left:540px;'><a href=\"javascript:closeThanksDiv();\"><img src=\"/1/img/icn16/close.gif\" border=0></a></div>";
	thanksDiv.innerHTML += "<b>Muchas gracias<b><br>";
	thanksDiv.innerHTML += "Tu comentario fue enviado correctamente y será publicado a la brevedad. " +txtCommentsModerate;
	thanksDiv.innerHTML += "<br><u>COMENTARIO SOBRE LOS COMENTARIOS</u><br>";
	thanksDiv.innerHTML += "Reiteramos las condiciones bajo las cuales se aceptarán comentarios y opiniones, participación que agradecemos y consideramos la esencia de la democratización de Internet. minutouno.com en especial ha hecho de esta opción un elemento vital de nuestra existencia como portal de noticias. <br>";
	thanksDiv.innerHTML += "Sin embargo, teniendo en cuenta la experiencia de los últimos meses, nos vemos en la necesidad de aclarar lo que creíamos obvio: minutouno.com busca ser una tribuna de debate, de controversia, de pluralismo (que hemos demostrado a rajatabla). De ninguna manera es este portal una barricada desde la cual se pueden disparar insultos, agresiones, ofensas, acusaciones sin fundamente ni grosería de ningún tipo.<br>";
	thanksDiv.innerHTML += "Que nadie entienda esto como censura, sino simplemente como una reiteración de las condiciones bajo las cuales nació la profunda convicción  de respetar todas las opiniones e ideas.<br>";
	thanksDiv.innerHTML += "Por todo esto, de aquí en adelante, cualquier comentario que incluya groserías, insultos o acusaciones sin fundamento será eliminado.<br>";
	thanksDiv.innerHTML +="De ustedes depende que la tribuna de minutouno.com  crezca en nivel y participación.<br>"

	window.clearInterval(thanksTime);
	thanksTime = setInterval("closeThanksDiv()",60000);;
	headline.style.position = "relative";
	headline.appendChild(thanksDiv);
	document.cookie= "comentado=0";
}

function wraperAlert(obj,lang,id){
	clearCssFrmError("INPUT",id);
	clearCssFrmError("TEXTAREA",id);
	window.nativeAlert = window.alert;
	window.alert = function(txt){
		errorComments(txt,id);
	}
	var status = vsmSubmit(obj, lang);
	window.alert = window.nativeAlert;
	if (status)	document.cookie = "comentado="+obj.objId.value;
	return status;
}

function vsmUrlCache(){
	args = arguments;
	url=args[0] ;
	for (var i=1; i < args.length; i++){
		url= url.replace("%"+i,args[i]);
	}
	return url;
}
function userInfor_callbck(txt){
	if (anonymousComment!=1 && txt.substr(4,1)==0) window.location= '/1/vnc/login.vnc?comment';
	else containerUserInfo.innerHTML = txt;
}
function comment_error_callbck(txt){
}
function showExtendedComments(id,tabIndex){
	var comments = document.getElementById("frmComments"+id);
	var hideObjs = comments.getElementsByTagName("DIV");
	if (tabIndex == undefined) tabIndex = id*10;
	for(var i=0;i<hideObjs.length;i++){
		if (hideObjs[i].className == "hide"){
			if (vsmLoggedIn()){
				if (hideObjs[i].id == "hideInputs" +id){
					url = vsmUrlCache(urlInfoUsuario,id,tabIndex,vsmLoggedIn());
					vsmHttpRequest(url, 'userInfor_callbck', 'comment_error_callbck');
					containerUserInfo= hideObjs[i];
					hideObjs[i].innerHTML = "Cargando informarci&oacute;n del usuario";
				}
			}
			hideObjs[i].className ='show'; 
			hideObjs[i].style["display"] = '';
			fadeIn(hideObjs[i].id,0);
		}
	}
}
function comment_callbck(text){
	var response = document.getElementById("answers"+containerComment);
	response.innerHTML = text;
	var anspbtn = document.getElementById("answbtn"+containerComment);
	anspbtn.innerHTML = '';
}
function comment_error_callbck(text){
	var response = document.getElementById("answers"+containerComment);
	response.innerHTML = text;
}

function getComments(idObject,idComment){
	containerComment = idComment;
	url = vsmUrlCache(urlRespComments,idObject,idComment);
	vsmHttpRequest(url, 'comment_callbck', 'comment_error_callbck')
	
}
function responseComment(idComment){
		id = objectid;
		var comments = document.getElementById("frmComments"+id);
		var response = document.getElementById("response"+idComment);
		response.innerHTML = "<div id=frmComments"+idComment+" class=boxed>"+comments.innerHTML+"<div class=close style=\"z-index:3\"><a href=\"javascript:closeFormsDiv('frmComments"+idComment+"');\"><img src='/1/img/icn16/close.gif' border=0></a></div></div></div>";
		response.style.zIndex = 2;
		var divs = response.getElementsByTagName("*");
		tabIndex = idComment*10;
		for (i=0; i<divs.length;i++){
			divs[i].id = divs[i].id.replace(id,idComment);
			if (divs[i].tagName == "LABEL"){
					divs[i].htmlFor = divs[i].htmlFor.replace(id,idComment);
			}
			if (divs[i].tabIndex >0){
				tabIndex++; 
				divs[i].tabIndex = tabIndex;
			}
			if (divs[i].tagName == "A"){
				divs[i].href = divs[i].href.replace(id,idComment);
			}
			if (divs[i].tagName == "INPUT"){
				if (divs[i].name == "commentId") divs[i].value = idComment; 
			}
		
			if (divs[i].className == "headline") 
				divs[i].innerHTML = "Responde este comentario";
		}
		response.getElementsByTagName("TEXTAREA")[0].onclick = "";
		showExtendedComments(idComment,tabIndex);
		response.getElementsByTagName("FORM")[0].onsubmit = function(){return wraperAlert(this,'es',idComment);}

}
function changeScore(id,selected){
	var score = document.getElementById("scoreImg"+id);
	score.src = (selected==1) ? "/1/img/icn16/starSelect.gif":"/1/img/icn16/star.gif";
}
function selectScore(obj){
	var scoreTxt = document.getElementById("scoreText");
	var scoreInput = document.getElementById("scoreInput")
	scoreTxt.innerHTML = "";
	if(obj.id != "scoreImg0"){
		obj.src = "/1/img/icn16/starSelect.gif";
	}
		scoreTxt.innerHTML = obj.alt;
	switch(obj.id){
		case "scoreImg0":
			changeScore(1);
			changeScore(2);
			changeScore(3);
			scoreInput.value = 0;
		break
		case "scoreImg1":
			changeScore(2);
			changeScore(3);
			scoreInput.value = 1;
		break
		case "scoreImg2":
			changeScore(1,1);
			changeScore(3);
			scoreInput.value = 2;			
		break;
		case "scoreImg3":
			changeScore(1,1);
			changeScore(2,1);
			scoreInput.value = 3;			
		break
	}

}
