// JavaScript Document

// ######################################################################
// funcion para desplegar u ocultar objetos al momento de hacerle click
// ######################################################################
	function display(obj) {
		obj = document.getElementById(obj);
		if (obj.style.display == "none") {
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	}

// #########################################################################
// funcion para seleccionar todas las casillas de un conjuntos de checkboxes
// #########################################################################

checked=false;
function checkedAll(aa) {
	var aa= document.getElementById(aa);
	 if (checked == false)
          {
           checked = true
          }
        else
          {
          checked = false
          }
	for (var i =0; i < aa.elements.length; i++) 
	{
	 aa.elements[i].checked = checked;
	}
      }
	  
// #########################################################################
// funcion para saltar con la opcion seleccionada del select
// #########################################################################	  
	
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// #########################################################################
// funcion para validar formularios
// #########################################################################	  

function ValidarForm(f) {
		if (f.nombre.value == '') {
			alert('Por favor, Ingrese el Título.');
			f.nombre.focus();
			return false;
		}
		
		if (f.descripcion.value == '') {
			alert('Por favor, Ingrese el Contenido');
			f.descripcion.focus();
			return false;
		}
		

	}
	
// #########################################################################	 	
/************************   AJAX del suggest *************************************/
// #########################################################################	 
function createRequestObject() { 

   var req; 

   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      // There is an error creating the object, 
      // just as an old browser is being used. 
      alert('Problem creating the XMLHttpRequest object'); 
   } 

   return req; 

} 

// Make the XMLHttpRequest object 
   var http = createRequestObject();
  //busqueda de productos 
function sendRequest(q) { 

       //alert(q);
	   // Open PHP script for requests  
       http.open('get', 'suggest.php?q='+q);  
       http.onreadystatechange = handleResponse;  
       http.send(null); 

}  


//busqueda de usuarios
function sendRequest1(q) { 

       //alert(q);
	   // Open PHP script for requests  
       http.open('get', 'suggest1.php?q='+q);  
       http.onreadystatechange = handleResponse;  
       http.send(null); 

} 

// handles the response returned FROM the PHP script. Anything echoed or printed
// in that script is stored in a variable as part of the http object which we can work with later.

function handleResponse() { 

   if(http.readyState == 4 && http.status == 200){ 

      // Text returned FROM the PHP script 
      var response = http.responseText; 

      if(response) { 
         // UPDATE ajaxTest content 
         document.getElementById("searchResults").innerHTML = response; 
      	display('searchResults');
	  } 

   } 

} 	





//////////////////////////////////////////////////////////////////////////////////////////
// funcion para abrir pop up
//////////////////////////////////////////////////////////////////////////////////////////

function openWindow(url) {
  window.open( url, 'remote', 'resizable,dependent,width=640,height=480,left=50,top=150, scrollbars=yes')
}




//funciones nuevas
//funcion para agregar el nombre del cliente al campo de texto
function Mostrar(id,nombre) {
document.getElementById("searchResults").style.display = 'none';
document.f.cliente.value = nombre;
document.f.id.value = id;
}





//busqueda proyectos
function sendRequest2(q) { 

       //alert(q);
	   // Open PHP script for requests  
       http.open('get',q);  
       http.onreadystatechange = handleResponse2;  
       http.send(null); 

} 

// handles the response returned FROM the PHP script. Anything echoed or printed
// in that script is stored in a variable as part of the http object which we can work with later.
	

//funcion para ocultar y mostrar capas 
//valor contiene la capa a mostrar y todas_capas contiene las capas a ocultar
    function GoSomewhere(valor,todas_capas)
         {
		   //alert(todas_capas);
          var capas = todas_capas.split(",");
		  var tamano = capas.length-1;
		   //alert(capas[0]);
		   
		 for (i=0; i <= tamano; i++)
			{
			///alert(capas[i] + valor);
				if(valor == capas[i])
					{
					 //alert("entro");
					 document.getElementById(valor).style.display = 'block';
					}
				else
				{
					document.getElementById(capas[i]).style.display = 'none';
				}
		    }
			
		  //location.href=pagina+valor
            //window.location.href = "http://www.google.com";
     	 }

