// Farmeworks
// Programador: Marcelo Tobal
// Todos los derechos reservados.

var clearclick=false;
function cleartextonclick(obj)
{
	if(!clearclick)
	{
		obj.value="";
		clearclick=true;
	}
}
function escribir_blur_buscador(obj)
{
	
	{
		if(obj.value=="")
		{
			obj.value="Buscar ...";
			clearclick=false;
		}
	}
}

//SUGEST Buscador
function OnBlurSugest()
{
	setTimeout("cerrarsuggest('sugest')",500)//Esto nos permite pulsar en el link de sugerencia
}
function suggest(capa1,capa2,texto)
{
	if(texto.length>1 && texto.length<30)
	{
		document.getElementById(capa1).style.display='block';
		llamarasincrono('inc/suggest.php?texto='+texto, capa2);
	}
}
function cerrarsuggest(capa)
{
	document.getElementById(capa).style.display='none';
}

//MICROVENTANA
function microVENTANA(url,ancho,alto,div)
{
	document.getElementById(div).style.display='block';
	document.getElementById(div).style.width=ancho+'px';
	document.getElementById(div).style.height=alto+'px';
	document.getElementById(div).style.marginLeft='-'+(ancho/2)+'px';
	document.getElementById(div).style.marginTop='-'+(alto/2)+'px';	
	//width: 500px;height: 300px;position: absolute;top: 50%;left: 50%;margin-top: -150px;margin-left: -250px;
	llamarasincrono(url,div+'_Cont');		
}
function microVENTANA_CERRAR(div)
{
	document.getElementById(div).style.display='none';	
}

//AJAX
//GET
function llamarasincrono(url, id_contenedor){
	
	//if(id_contenedor=="UM_NOTICIA")
	
	if(id_contenedor=="epigrafeFoto")
	{
			document.getElementById(id_contenedor).innerHTML='<img src=img/cargando.gif align="absmiddle"> Cargando...';	
	}
	
	if(id_contenedor=="mostrarHoroscopo" )
		document.getElementById(id_contenedor).innerHTML='<img src=img/cargando.gif align="absmiddle"> Cargando...';
	if(id_contenedor=="Divisas_panel")
		document.getElementById(id_contenedor).innerHTML='<img src=img/cargando.gif align="absmiddle"> Cargando...';
	
	if(id_contenedor!="UM_NOTICIA" && id_contenedor!="epigrafeFoto" && id_contenedor!="mostrarHoroscopo" && id_contenedor!="checkEmail" && id_contenedor!="TemperaturaRio3" && id_contenedor!="Divisas_panel")
		document.getElementById(id_contenedor).innerHTML='<center>Espere por favor ...</center>';	
	
	
	var pagina_requerida = false
	if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
	pagina_requerida = new XMLHttpRequest()
	} else if (window.ActiveXObject){ // pero si es IE
	try {
		pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){ // en caso que sea una versión antigua
	try{
	pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
	}
	}
	else
	return false
	pagina_requerida.onreadystatechange=function(){ // función de respuesta
	cargarpagina(pagina_requerida, id_contenedor)
	}
	pagina_requerida.open('GET', url, true) // asignamos los métodos open y send
	pagina_requerida.send(null)
}
// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText	
}

//POST Formulario
//envio de formulario
function llamaraform(url, id_contenedor, formid){

	     var Formulario = document.getElementById(formid);

         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
		 }
var pagina_requerida = false
if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
pagina_requerida = new XMLHttpRequest()
} else if (window.ActiveXObject){ // pero si es IE
try {
pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){ // en caso que sea una versión antigua
try{
pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pagina_requerida.onreadystatechange=function(){ // función de respuesta
cargarpagina(pagina_requerida, id_contenedor)
}
pagina_requerida.open('POST', url, true) // asignamos los métodos open y send

pagina_requerida.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
pagina_requerida.send(cadenaFormulario);
}



//Funcion vacia
function link()
{
}


//ULTIMO MOMENTO
var UMselect=1;
var UMtotal=0;
function iraUM(not)
{
	document.getElementById('UM-'+UMselect).src="img/um_notD.png";
	UMselect=not;
	document.getElementById('UM-'+UMselect).src="img/um_not.png";
	llamarasincrono('ajax/um.php?not='+UMselect, 'UM_NOTICIA')
}
function avanzarUM(total)
{
	document.getElementById('UM-'+UMselect).src="img/um_notD.png";
	
	UMselect++;
	if((UMselect)>total)
	{
		UMselect=1;
	}
	document.getElementById('UM-'+UMselect).src="img/um_not.png";
	llamarasincrono('ajax/um.php?not='+UMselect, 'UM_NOTICIA')

}
function atrasUM(total)
{
	document.getElementById('UM-'+UMselect).src="img/um_notD.png";
	
	UMselect--;
	if((UMselect)<1)
	{
		UMselect=total;
	}
	document.getElementById('UM-'+UMselect).src="img/um_not.png";
	llamarasincrono('ajax/um.php?not='+UMselect, 'UM_NOTICIA')
}

//enviar encuesta
function enviarencuesta()
{
	var voto=document.getElementsByName('voto').item(checkselected(document.getElementsByName('voto'))).value;
	var vot=document.getElementById('vot').value;
	var encuesta=document.getElementById('encuesta').value;
	llamarasincrono('encuestaajax.php?encuesta='+encuesta+'&voto='+voto+'&vot='+vot, 'contenedorencuesta');
	//alert('encuestaajax.php?encuesta='+encuesta+'&voto='+voto+'&vot='+vot);
}

//chequear que radio esta selecionado
function checkselected(radio) {
for (i=0; i<radio.length; i++) {
    if (radio[i].checked) { return i; }
}
return false
}  

//POPUP
function Ventana(URL,Nombre,Flags) { 
  window.open(URL,Nombre,Flags);
}

function climaLoad()
{
	llamarasincrono('ajax/clima.php','TemperaturaRio3');
}
function divisasLoad()
{
	llamarasincrono('ajax/divisas.php','Divisas_panel');
}




//funcion cambiar estilos de botones
function cambiaEstilo(div,etiqueta,classe,obj)
{
	var li=document.getElementById(div).getElementsByTagName(etiqueta);
	for(i=0; i<li.length;i++)
	{
		if(li.item(i).className==classe)
			li.item(i).className="";
	}
	obj.className='selecionado';
}