//Crea el objeto AJAX
function crearObjeto(){
  var xmlhttp=false;
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
  try {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
  xmlhttp = false;
  }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}
//Funciones de la aplicacion

function cargarListaImagenes()
{
	//definer los controles
	//comentario = new Array('');

		divResultado = document.getElementById("resultado");
		idNoticia=document.guardarImagen.idNoticia.value;
		codImagen=document.guardarImagen.codImagen.value;
		dir=document.guardarImagen.dir.value;
		comentario = document.guardarImagen.comentario.value;
		accion = document.guardarImagen.btonguardarImagen.value;
		
		xmlhttp = crearObjeto();
		xmlhttp.open("POST","listaImagen.jsp",true);
		xmlhttp.onreadystatechange = function()
		{
			if(xmlhttp.readyState == 4)	
			{
				divResultado.innerHTML = xmlhttp.responseText;		
				document.guardarImagen.comentario.value = "";

				if(xmlhttp.Status == 500)
				{
					divResultado.innerHTML = xmlhttp.responseText;
				}
			}
		}
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send("idNoticia="+idNoticia+"&codImagen="+codImagen+"&dir="+dir+"&comentario="+comentario+"&accion="+accion);
}

function validarImagen()
{
	if(document.guardarImagen.comentario.value == '' || document.guardarImagen.comentario.value == null)
	{
		if(confirm("El Campo del comentario esta vacio \nDesea Guardar de todas maneras..."))
		{	
			cargarListaImagenes();
		}
	}else{
		cargarListaImagenes();
	}
}

function cargarLista(idNoticia)
{
	//definer los controles
	divResultado = document.getElementById("resultado");

	xmlhttp = crearObjeto();
	xmlhttp.open("POST","listaImagen.jsp",true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)	
		{
			divResultado.innerHTML = xmlhttp.responseText;		
			if(xmlhttp.Status == 500)
			{
				divResultado.innerHTML = xmlhttp.responseText;
			}
		}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("idNoticia="+idNoticia);
}
function cargarImagen(idFotografia,idNoticia)
{
	//definer los controles
	divResultado = document.getElementById("mostrarImagen");


	xmlhttp = crearObjeto();
	xmlhttp.open("POST","../noticias/fotografia.jsp",true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)	
		{
			divResultado.innerHTML = xmlhttp.responseText;		
			if(xmlhttp.Status == 500)
			{
				divResultado.innerHTML = xmlhttp.responseText;
			}
		}
		else
		{
			divResultado.innerHTML = "<br><img src='/img/cargando.gif'><br>Cargando...<br>";
		}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("idNoticia="+idNoticia+"&idFotografia="+idFotografia);
}


/* Para abrir el popup de la vista previa en editar noticias  */
function vistaPrevia(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left = 150,top = 40');");
}


/////////////////////////////////////////////////////////////////////////////
////////////        PARA GUARDAR DETALLE
/////////////////////////////////////////////////////////////////////////////
function toggle_div(d1,d2)
{
	var div1 = document.getElementById(d1);
	var div2 = document.getElementById(d2);

	if(div1.style.display == "block") {
    	div1.style.display = "none";
		div2.style.display = "block";
  	}
	else {
		div1.style.display = "block";
		div2.style.display = "none";
	}
}

function cargarNuevaCiudad()
{
	//definer los controles
	divResultado = document.getElementById("ciudad");
	idDept=document.SaveNoticia.idDept.value;
	newciudad=document.SaveNoticia.newciudad.value;

	xmlhttp = crearObjeto();
	xmlhttp.open("POST","../noticias/ciudad.jsp",true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)	
		{
			divResultado.innerHTML = xmlhttp.responseText;		

			if(xmlhttp.Status == 500)
			{
				divResultado.innerHTML = xmlhttp.responseText;
			}
		}
		else
		{
			divResultado.innerHTML = "<br><img src='/img/cargando.gif'><br>Cargando...<br>";
		}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("idDept="+idDept+"&newciudad="+newciudad);
	toggle_div("newCiudadON","ciudad")
}

function cargarNuevaFuente()
{
	//definer los controles
	divResultado = document.getElementById("fuente");
	newfuente=document.SaveNoticia.newfuente.value;

	xmlhttp = crearObjeto();
	xmlhttp.open("POST","../noticias/fuente.jsp",true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)	
		{
			divResultado.innerHTML = xmlhttp.responseText;		
			
			if(xmlhttp.Status == 500)
			{
				divResultado.innerHTML = xmlhttp.responseText;
			}
		}
		else
		{
			divResultado.innerHTML = "<br><img src='/img/cargando.gif'><br>Cargando...<br>";
		}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("newfuente="+newfuente);
	toggle_div("newFuenteON","fuente")
}

function cargarNuevaClasificacion()
{
	//definer los controles
	divResultado = document.getElementById("clasificacion");
	newclasificacion=document.SaveNoticia.newclasificacion.value;

	xmlhttp = crearObjeto();
	xmlhttp.open("POST","../noticias/clasificacion.jsp",true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)	
		{
			divResultado.innerHTML = xmlhttp.responseText;		
			
			if(xmlhttp.Status == 500)
			{
				divResultado.innerHTML = xmlhttp.responseText;
			}
		}
		else
		{
			divResultado.innerHTML = "<br><img src='/img/cargando.gif'><br>Cargando...<br>";
		}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("newclasificacion="+newclasificacion);
	toggle_div("newClasificacionON","clasificacion")
}
	function mOut(src,cor) {
		if (!src.contains(event.toElement))
		{
		 src.style.cursor = 'default';
		 src.bgColor = cor;
		}
	}
	function mOvr(src,cor) {
	 if (!src.contains(event.fromElement)) {
		 src.style.cursor = 'default';
		 src.bgColor = cor;
		}
	}

