current_overID = "";
last_overID = "";
SITIO_RUTA="http://www.extra.ec/";

var calificacion=0;
var WEB_ROOT="";
var ID = 0;

function item (img_name,width,height)
{
	img_prefix = img_name;
	this.slide_img = new Image (width,height);
	this.slide_img.src = SITIO_RUTA+"/imagenes/2010/noticias/" + img_prefix + ".jpg";
}
function new_item (img_name,width,height){
	item [img_name] = new item (img_name,width,height);
}
function mouseover (itemID)
{
	
	current_overID = itemID;
	if (current_overID != last_overID) {
		  document.jrcmap.src = item [current_overID].slide_img.src;
	
	}
}
function mouseover2 (itemID)
{
	current_overID = itemID;
	if (current_overID != last_overID) {
		  document.asi.src = item [current_overID].slide_img.src;
	}
}
new_item ("0",66,14);
new_item ("1",66,14);
new_item ("2",66,14);
new_item ("3",66,14);
new_item ("4",66,14);
new_item ("5",66,14);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'':(v=='hide')?'none':v; }
	obj.display=v; }
}
	
function activarCSS(title) { 
	
	var links = document.getElementsByTagName("link"); 	
	for (var i=0; i<links.length; i++) { 
		if (links[i].getAttribute("title") == "pequena" || links[i].getAttribute("title") == "normal" || links[i].getAttribute("title") == "grande") { 
			links[i].disabled = true; 
		}
	}
	for (var i=0; i<links.length; i++) { 
		if (links[i].getAttribute("title") == title) { 
			links[i].disabled = false; 
		} 
	} 
} 
/****************/
// COMENTARIOS
function registrarComentario()
{

	var comentario=document.getElementById("txtcomentario").value;
	var noticia=document.getElementById("noticia").value;
	var nombre=document.getElementById("txtnombrecomentario").value;


	if(comentario!="" && nombre!=""){		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		//document.getElementById("mensaje").className="mensaje";
		document.getElementById("mensaje").innerHTML="Por favor espere..._";
		var url=SITIO_RUTA+"/comportamientos/includes/_comentarios.asp";		
		
		url=url+"?comentario="+comentario;
		url=url+"&noticia="+noticia;
		url=url+"&nombre="+nombre;
		xmlHttp.onreadystatechange=stateChangedComentarios;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
			
	}else{
		document.getElementById("mensaje").className="mensaje-error";
		document.getElementById("mensaje").innerHTML="Debe ingresar todos los campos.";
	}
}
function stateChangedComentarios() 
{ 		

	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
	{	
		
		if(xmlHttp.status == 200){		

			xml = xmlHttp.responseXML;			
			//xml = xmlHttp.responseTEXT;			
			ManejarRespuestasComentarios()
		}					
	}else{		
	}	
}
function ManejarRespuestasComentarios(){	
	document.getElementById("mensaje").innerHTML=xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue;
	setTimeout(borrarMensaje,3000);
	document.getElementById("mensaje").className=xml.getElementsByTagName("class")[0].childNodes[0].nodeValue;
	if(xml.getElementsByTagName("estado")[0].childNodes[0].nodeValue=="OK")
	{
		document.getElementById("formcomentario").reset();
	}
}
function borrarMensaje()
{
	if(document.getElementById("mensaje") != null)
   {
	   document.getElementById("mensaje").innerHTML="";
   }
}
/****************/
// CALIFICACION

/***********************************************************/
function setearCalificacion(valor)
{	
	calificacion=valor;
	for(var i=1; i<=5; i++)
	{
		$("#opcionEstrella"+i).removeClass("inactivo");
		$("#opcionEstrella"+i).removeClass("activo");		
		if(i<=valor){
			$("#opcionEstrella"+i).addClass("activo"); 
		}
	}
}
function CalificarEstrellas()
{
	var articuloid=document.getElementById("hdaid").value;
	xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}		
		var url=WEB_ROOT+"/webservices/noticia.aspx";				
		url=url+"?opcion=Calificar";		
		url=url+"&calificacion="+calificacion;	
		url=url+"&articuloid="+articuloid;		
		xmlHttp.onreadystatechange=stateChangedCalificar;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function stateChangedCalificar() 
{ 		
	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
	{		
		if(xmlHttp.status == 200){		
			xml = xmlHttp.responseText;						
			//alert(xml);
			ManejarRespuestasCalificar()
		}					
	}else{		
	}	
}
function ManejarRespuestasCalificar(){
	if(xml=="OK"){
		alert("Gracias por calificar este artículo.");
	}else{
		alert("Gracias por calificar este artículo.asasas");
	}
}



/****************/
// RECOMENDAR
function registrarRecomendar()
{


	var nombre=document.getElementById("txtnombre").value;
	var email=document.getElementById("txtemail").value;
	var nombreamigo=document.getElementById("txtnombreamigo").value;
	var emailamigo=document.getElementById("txtemailamigo").value;
	var comentario=document.getElementById("txtcomentariosrecomendar").value;
	var noticia=document.getElementById("noticiaenlace").value;
	
	if(nombre !="" && nombreamigo !="" && validate(email) && validate(emailamigo)){		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		//document.getElementById("mensaje").className="mensaje";
		document.getElementById("mensaje-recomendar").innerHTML="Por favor espere....";
		var url=SITIO_RUTA+"/comportamientos/includes/_recomendar.asp";		
		
		url=url+"?nombre="+nombre;
		url=url+"&email="+email;
		url=url+"&nombreamigo="+nombreamigo;
		url=url+"&emailamigo="+emailamigo;
		url=url+"&link="+noticia;
		url=url+"&comentario="+comentario;
		//alert(url);
		xmlHttp.onreadystatechange=stateChangedRecomendar;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{
		//document.getElementById("mensaje-recomendar").className="mensaje-error";
		document.getElementById("mensaje-recomendar").innerHTML="Debe ingresar todos los campos.";
		if (!validate(email) || !validate(emailamigo)){
			document.getElementById("mensaje-recomendar").innerHTML="Debe ingresar direcciones de correo v&aacute;lidas.";
		}
	}
}
function stateChangedRecomendar() 
{ 		

	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
	{	
		
		if(xmlHttp.status == 200){		

			xml = xmlHttp.responseXML;			
			//xml = xmlHttp.responseTEXT;			
			ManejarRespuestasRecomendar()
		}					
	}else{		
	}	
}
function ManejarRespuestasRecomendar(){	
	document.getElementById("mensaje-recomendar").innerHTML=xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue;
	setTimeout(borrarMensajeRecomendar,3000);
	document.getElementById("mensaje-recomendar").className=xml.getElementsByTagName("class")[0].childNodes[0].nodeValue;
	if(xml.getElementsByTagName("estado")[0].childNodes[0].nodeValue=="OK")
	{
		document.getElementById("formrecomendar").reset();
	}
}
function borrarMensajeRecomendar()
{
	if(document.getElementById("mensaje-recomendar") != null)
   {
	   document.getElementById("mensaje-recomendar").innerHTML="";
   }
}
/***/
function registrarContacto()
{
	var nombre=document.getElementById("txtnombre").value;
	var email=document.getElementById("txtemail").value;
	var comentario=document.getElementById("txtcomentario").value;
	var articuloid=document.getElementById("hdaid").value;

	if(nombre!="" && validarEmail(email) && comentario!=""){		
		xmlHttp=null;
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		$("#mensajeContacto").slideDown("slow");
		document.getElementById("mensajeContacto").className="mensaje";
		document.getElementById("mensajeContacto").innerHTML="Por favor espere.....";
		var url=WEB_ROOT+"/webservices/noticia.aspx";		
		
		url=url+"?opcion=Comentario";		
		url=url+"&nombre="+nombre;		
		url=url+"&email="+email;
		url=url+"&comentario="+comentario;
		url=url+"&articuloid="+articuloid;
		xmlHttp.onreadystatechange=stateChangedComentariosNoticias;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		//alert(url);
			
	}else{
		document.getElementById("mensajeContacto").className="mensaje-error";
		alert(nombre+','+email+','+comentario);
		if(nombre=="" || email=="" || comentario==""){	
			document.getElementById("mensajeContacto").innerHTML="Debe ingresar todos los campos.";
		}else{
			if(!validarEmail(email)){	
				document.getElementById("mensajeContacto").innerHTML="Debe ingresar un email v&aacute;lido.";
			}
		}
	}
}
function stateChangedComentariosNoticias() 
{ 	
	
	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
	{		
		//alert(xmlHttp.status );
		//alert(xmlHttp.responseText);
		if(xmlHttp.status == 200 || xmlHttp.status == 0){	
				
			xml = xmlHttp.responseText;	
			//alert(xml);
			ManejarRespuestas()
		}					
	}else{		
	}	
}
function ManejarRespuestas(){	
	if(xml=="OK"){
		document.getElementById("formComentario").reset();
		document.getElementById("mensajeContacto").innerHTML="Gracias por participar, su comentario ser&aacute; revisado y publicado lo m&aacute;s pronto nos sea posible.";
		setTimeout("ComentarNoticia()",2000);		
	}else{
		document.getElementById("mensajeContacto").innerHTML="Gracias por participar, su comentario ser&aacute; revisado y publicado lo m&aacute;s pronto nos sea posible.";
	}	
}

function MaxComentario(contenido, max) {
   ;
    if (document.getElementById(contenido) != null) {
        var textbox = document.getElementById(contenido);
        if (textbox.value.length > max) {
            textbox.value = textbox.value.substring(0, max);            
            textbox.scrollTop = textbox.scrollTop + textbox.scrollHeight;
        }
    }
}
function ComentarNoticia()
{
	document.getElementById("mensajeContacto").innerHTML="";
	if ($(".comentarNoticia").is(":hidden")) {
        $(".comentarNoticia").slideDown("slow");
      } else {
        $(".comentarNoticia").hide();
      }
}

function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      //alert('Invalid Email Address');
      return false;
   }else{
	   return true;
   }
}
function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){	
		return (true)
	} else {
		return (false);
	}
}
function OcultarMensajeComentario(){
	$("#mensajeContacto").fadeOut("slow");
}


/***********************************************************/

function EnviarCorreo(){
	var articuloid=document.getElementById("hdaid").value;
	var CorreoNombreRemitente=document.getElementById("CorreoNombreRemitente").value;
	var CorreoEmailRemitente=document.getElementById("CorreoEmailRemitente").value;
	var CorreoNombreDestinatario=document.getElementById("CorreoNombreDestinatario").value;
	var CorreoEmailDestinatario=document.getElementById("CorreoEmailDestinatario").value;
	var CorreoMensaje=document.getElementById("CorreoMensaje").value;
	var hdaurl=document.getElementById("hdaurl").value;
	var hdatitulo=document.getElementById("hdatitulo").value;
	
	if(CorreoNombreRemitente!="" && validarEmail(CorreoEmailRemitente) && CorreoNombreDestinatario!="" && validarEmail(CorreoEmailDestinatario)){	
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}		
		document.getElementById("CorreoMensajeError").innerHTML="Por favor espere......";
		var url=WEB_ROOT+"/webservices/noticia.aspx";				
		url=url+"?opcion=EnviarCorreo";		
		url=url+"&CorreoNombreRemitente="+CorreoNombreRemitente;	
		url=url+"&CorreoEmailRemitente="+CorreoEmailRemitente;	
		url=url+"&CorreoNombreDestinatario="+CorreoNombreDestinatario;	
		url=url+"&CorreoEmailDestinatario="+CorreoEmailDestinatario;	
		url=url+"&CorreoMensaje="+CorreoMensaje;			
		url=url+"&url="+hdaurl;	
		url=url+"&titulo="+hdatitulo;	
		url=url+"&articuloid="+articuloid;
		
		xmlHttp.onreadystatechange=stateChangedEnviarCorreo;
		xmlHttp.open("GET",url,true);
		//alert(url);
		xmlHttp.send(null);
	}else{
		if(CorreoNombreRemitente=="" || CorreoEmailRemitente=="" || CorreoNombreDestinatario=="" || CorreoEmailDestinatario==""){	
			document.getElementById("CorreoMensajeError").innerHTML="Debe ingresar los campos obligatorios.";
		}else{
			if( !validarEmail(CorreoEmailRemitente)  ||  !validarEmail(CorreoEmailDestinatario) ){	
				document.getElementById("CorreoMensajeError").innerHTML="Debe ingresar un email v&aacute;lido.";
			}
		}
	}
}

function stateChangedEnviarCorreo() 
{ 		
	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
	{		
		if(xmlHttp.status == 200){		
			xml = xmlHttp.responseText;						
			//alert(xml);
			ManejarRespuestasCorreo()
		}					
	}else{		
	}	
}
function ManejarRespuestasCorreo(){
	if(xml=="OK"){
		document.getElementById("CorreoMensajeError").innerHTML="Gracias por recomendar este ar&iacute;culo.";
		document.getElementById("formEnviarCorreo").reset();
	}else{
		alert(xml);
	}
}
	
