function buscarNoticias()
{
  
   xGetElementById('listticker').innerHTML ="<br/><div align='center'><table width='60px' align='center' border='0' cellspacing='0' cellpadding='0'><tr>   <td></td><td></td><td><img src='img/loadCC.gif' width='24' height='24' /></td></tr></table></div><div align='center'><span style='color:#999999;  font-family: Arial, Helvetica, sans-serif; font-size: 12px;' >Cargando.. </span></div><br/>";
   
   AjaxRequest.post
    ({
		'parameters':
        { 
            'accion':"buscarTodasNoticias",'tipo':1 
        },
        'onSuccess':armarNoticias,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 	
}

function buscarNoticiasPag()
{
  
   xGetElementById('listticker').innerHTML ="<br/><div align='center'><table width='60px' align='center' border='0' cellspacing='0' cellpadding='0'><tr>   <td></td><td></td><td><img src='img/loadCC.gif' width='24' height='24' /></td></tr></table></div><div align='center'><span style='color:#999999;  font-family: Arial, Helvetica, sans-serif; font-size: 12px;' >Cargando.. </span></div><br/>";
   
   AjaxRequest.post
    ({
		'parameters':
        { 
            'accion':"buscarTodasNoticias",'tipo':2 
        },
        'onSuccess':armarNoticias,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 	
}

function armarNoticias(req)
{
	var respuesta = req.responseText;  
	var resultado = eval("(" + respuesta + ")"); 
	var menu  = xGetElementById('listticker');
	mD.limpiaTexto(menu);
	if(resultado)
	{
		for(var i=0;i<resultado.length;i++)
		{  
			var codNoticia = resultado[i]['co_noticia'];
			var lista = mD.agregaNodoElemento('li', 'noticia'+i, 'noticia'+i,{});
			mD.agregaHijo(menu,lista);
			/*var img = mD.agregaNodoElemento('img', 'imagen'+i, 'imagen'+i,{"width":"70","height":"70","title":resultado[i]['tx_titulo'],"src":"img/noticia/"+resultado[i]['tx_url_imagen']});
			img.width=70;
			img.height=70;
			mD.agregaHijo(lista,img);*/
			
			var elemento = mD.agregaNodoElemento('a', 'elemento'+i, 'elemento'+i,{"class":"news-title","title":resultado[i]['tx_titulo'],"style":"cursor:pointer","onclick":"mostrarDetalleNoticia("+codNoticia+")"});
			mD.agregaHijo(lista,elemento);
		    mD.agregaNodoTexto(elemento,resultado[i]['tx_titulo']);
			var texto = mD.agregaNodoElemento('span', 'texto'+i, 'texto'+i,{"class":"news-text","style":"cursor:pointer","onclick":"mostrarDetalleNoticia("+codNoticia+")"});
			mD.anexaEvento(lista,'click',mostrarDetalleNoticia,[codNoticia])
			//texto.onclick="mostrarDetalleNoticia("+codNoticia+")";
			//lista.style.cursor="pointer";
			mD.agregaHijo(lista,texto);
			var cadena = resultado[i]['tx_texto'];
			var cadenaTexto = cadena.substr(0,200);
			var cuerpoNoticia = cadenaTexto+" .....";
		    mD.agregaNodoTexto(texto,cuerpoNoticia);
			var fechaPublicacion = fechaCorta(resultado[i]['fe_publicacion']);
		    mD.agregaNodoTexto(texto,"\n Fecha de Publicación: "+fechaPublicacion);
			//mD.anexaEvento (elemento, 'click',llamarPagAfiliado, [resultado[i]['co_categoria']]);
		}
	}
	else
	{
		var lista = mD.agregaNodoElemento('li', 'noticia', 'noticia',{});
		mD.agregaHijo(menu,lista);
		var elemento = mD.agregaNodoElemento('a', 'elemento', 'elemento',{"class":"news-title"});
		mD.agregaHijo(lista,elemento);
		mD.agregaNodoTexto(elemento,"Bienvenidos a la Página Web de la Cámara de Comercio, Industria y Producción de Cumaná");
	}
}

function mostrarDetalleNoticia(codNoticia)
{
	var url = 'include/detalle_noticia.php';
	var divv = xGetElementById('contentPag');
	xDisplay('contentPag','block');
	xDisplay('noticiaCam','none');
	xDisplay('notiUniversal','none');
	xDisplay('indicadores','none');
	AjaxRequest.post({
			'parameters': {},
			'onSuccess': function(req){
				mD.limpiaTexto(divv);
				divv.innerHTML = req.responseText;
				buscarDetalleNoticia(codNoticia);
			},
			'url': url,
			'onError': function(req){
				alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText);
			}
		});
}

function buscarDetalleNoticia(codNoticia)
{
	AjaxRequest.post
    ({
		'parameters':
        { 
            "accion":"buscarNoticiasEspecif", "codNoticia":codNoticia
        },
        'onSuccess':armarDetalleNoticias,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 
}

function armarDetalleNoticias(req)
{
    var respuesta = req.responseText;
    var resultado = eval("(" + respuesta + ")");
	var tablaNoticia = xGetElementById('detalleNoticia');
	mD.limpiaTexto(tablaNoticia);
	var titulo = xGetElementById('tituloNoticia');
	mD.limpiaTexto(titulo);
    mD.agregaNodoTexto(titulo,resultado[0]['tx_titulo']);

	var fila = mD.insertarFila(tablaNoticia, -1, {});
    var celda = mD.insertarCelda(fila, -1, {'colspan':'2'});
if(resultado[0]['tx_url_imagen'] != '' || resultado[0]['tx_url_imagen'] !=null){
var img = mD.agregaNodoElemento('img', 'imagen' + 0, 'imagen' + 0, {"width":"250","height":"250","title": resultado[0]['tx_titulo'],"src":"img/noticia/"+resultado[0]['tx_url_imagen']});
	img.width=250;
	img.height=250;
	mD.agregaHijo(celda, img);}
	//var fila = mD.insertarFila(tablaNoticia, -1, {});
	//var celda = mD.insertarCelda(fila, -1, {'colspan':'2'}, "\n"+resultado[0]['tx_titulo']);
	var fila = mD.insertarFila(tablaNoticia, -1, {});
	var celda = mD.insertarCelda(fila, -1, {'colspan':'2'},"\nFecha de Publicación: "+fechaCorta(resultado[0]['fe_publicacion']));
	var fila = mD.insertarFila(tablaNoticia, -1, {});
	var celda = mD.insertarCelda(fila, -1, {"align":"justify",'colspan':'2'},"\n"+resultado[0]['tx_texto']);

	//var titulo = xGetElementById("tituloPag");
	//mD.agregaNodoTexto(titulo, 'Camara Comercio Cumaná: '+resultado[0]['tx_titulo']);

	
	var facebook = xGetElementById("iconFacebook");
	mD.agregaAtributo(facebook, {"href": "http://www.facebook.com/sharer.php?u=www.camaradecumana.com/detalleNoticia.php?noticia="+resultado[0]['co_noticia']+"&t=Cámara Comercio Cumaná: "+resultado[0]['tx_titulo']+""});
	mD.agregaAtributo(facebook, {"target":"blank"});
	
	
	var twitter = xGetElementById("iconTwitter");
	mD.agregaAtributo(twitter, {"href": "http://twitter.com/home?status=Noticias - http://www.camaradecumana.com/detalleNoticia.php?noticia="+resultado[0]['co_noticia']+""});
	mD.agregaAtributo(twitter, {"target":"blank"});
	
	xGetElementById("inputCompartir").value='http://www.camaradecumana.com/detalleNoticia.php?noticia='+resultado[0]['co_noticia'];

	/*var img = mD.agregaNodoElemento('img', 'imagen' + 0, 'imagen' + 0, {"width":"250","height":"250","title": resultado[0]['tx_titulo'],"src":"img/noticia/"+resultado[0]['tx_url_imagen']});
	mD.agregaHijo(celda, img);*/
}


function seleccionarTodo(id)
{
	xGetElementById('id').select();
}

//------------------------------------------------------------------------------------------------
//Descripciï¿½n: Ubica una determinada categorï¿½a
//Entrada: N/A
//Salida: Vector con los datos correspondiente a las categorï¿½as de los afiliados
//------------------------------------------------------------------------------------------------
function buscarNoticiasEspecifica(titulo)
{ 
    AjaxRequest.post
    ({
		'parameters':
        { 
            'accion':"buscarNoticiaTitulo", 'titulo':titulo
        },
        'onSuccess':mostrarNoticias,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 
}


//------------------------------------------------------------------------------------------------
//Descripciï¿½n: Funciï¿½n que permite mostrar todas las categorï¿½as creadas
//Entrada: Vector con los datos correspondientes a las categorï¿½as de los afiliados 
//Salida: Tabla con los resultados de todas las categorï¿½as existentes de los afiliados
//------------------------------------------------------------------------------------------------
function mostrarNoticias(req)
{
    var respuesta = req.responseText;
    var resultado = eval("(" + respuesta + ")");
   	var tabla = xGetElementById('cuerpomostrarNoticia');  
	mD.limpiaTexto(tabla);
	if (resultado)
	{   
   		var n=resultado.length;
	    /*for (var i=0; i<n; i++)	
	    {	
			var fila = mD.insertarFila(tabla, -1, {'style':'cursor:pointer','onclick':"capturarTitulo(\""+resultado[i]['tx_titulo']+"\",\""+resultado[i]['tx_texto']+"\",\""+resultado[i]['co_noticia']+"\");"});
			mD.insertarCelda(fila, -1, {'width':'670px'}, resultado[i]['fe_publicacion']);
			mD.insertarCelda(fila, -1, {'width':'230px'}, resultado[i]['tx_titulo']);
	    }  */
 for (var i=0; i<n; i++)	
	    {	
			var fila = mD.insertarFila(tabla, -1, {'style':'cursor:pointer','onclick':"buscarDetalleNoticiaInt(\""+resultado[i]['co_noticia']+"\");"});
			mD.insertarCelda(fila, -1, {'width':'670px'}, resultado[i]['fe_publicacion']);
			mD.insertarCelda(fila, -1, {'width':'230px'}, resultado[i]['tx_titulo']);
	    }  
        xDisplay('registrosNoticiasM','block');
        xGetElementById('registrosNoticias').value = n;
	}
	else
    {
		var fila = mD.insertarFila(tabla, -1, {});
		mD.insertarCelda(fila, -1, {'class':'tablaContenido','colspan':'2','align': 'center'}, 'Noticia no registrada');
    }
}



function buscarDetalleNoticiaInt(codNoticia)
{
	AjaxRequest.post
    ({
		'parameters':
        { 
            "accion":"buscarNoticiasEspecif", "codNoticia":codNoticia
        },
        'onSuccess':armarNoticiasInt,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 
}


//------------------------------------------------------------------------------------------------
//Descripciï¿½n: Permite obtener el valor de una categorï¿½
//Entrada: Recibe el nombre de la categorï¿½a, el tipo al cual pertenece (principal o no) y el cï¿½digo correspondiente
//Salida: 1 para el caso de que la categorï¿½a corresponda a un activo principal y 0 en caso contrario
//------------------------------------------------------------------------------------------------
function armarNoticiasInt(req)
{
 var respuesta = req.responseText;
    var resultado = eval("(" + respuesta + ")");
	
    	

xGetElementById('txtTitulo').value = resultado[0]['tx_titulo'];
	xGetElementById('hdnCodNot').value =resultado[0]['co_noticia']
	xGetElementById('txtDescripcion').value = resultado[0]['tx_texto']
}

//------------------------------------------------------------------------------------------------
//Descripciï¿½n: Funciï¿½n que permite cambiar los datos de una categorï¿½a
//Entrada:N/A
//Salida: Vector con los datos asociados a la categorï¿½a a modificar
//------------------------------------------------------------------------------------------------
function modificarNoticia()
{
    var noticia= xGetElementById('txtTitulo').value;
    var coNoticia = xGetElementById('hdnCodNot').value;
    var descripcion = xGetElementById('txtDescripcion').value;
    AjaxRequest.post
    ({
		'parameters':
        { 
            'accion':"modificarNoticia", 'noticia':noticia, 'descripcion':descripcion,'coNoticia':coNoticia 
        },
        'onSuccess':mostrarModificacionNoticia,
        'url':'trans/mConsultasNoticia.php',
        'onError':function(req)
        {
        	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
        }
    }); 
}

//------------------------------------------------------------------------------------------------
//Descripciï¿½n: Funciï¿½n que permite mostrar lo exitoso o no de la modificaciï¿½n realizada a una categorï¿½a
//Entrada: Respuesta del servidor en relaciï¿½n con los datos asociados a la categorï¿½a a modificar
//Salida: Mensaje de notificaciï¿½n de que la operaciï¿½n se haya realizado con ï¿½xito o error en la modificaciï¿½n de la categorï¿½a 
//------------------------------------------------------------------------------------------------
function mostrarModificacionNoticia(req)
{
	var respuesta = req.responseText;           
	var resultado = eval("(" + respuesta + ")");
    if(resultado)
    {
        alert("La operación de modificación fue realizada con éxito");
		xGetElementById('hdnCodNot').value="";
		xGetElementById('txtTitulo').value="";
		xGetElementById('txtDescripcion').value="";
		    }
    else
    {
        alert("Error al modificar la noticia");
    }
}

