// JavaScript Document
function addEvent( elemento, evento, funcion, captura ) {
   if ( elemento.attachEvent ) {
      elemento.attachEvent( 'on' + evento, funcion );
      return true;
   } else {
      if ( elemento.addEventListener ) {
         elemento.addEventListener( evento, funcion, captura );
         return true;
      } else {
         return false;
	  }
   }
}

function crearXMLHttpRequest() {
   var xmlHttp=null;
   if ( window.ActiveXObject ) {
      xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
   } else {
      if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
   }
   return xmlHttp;
}

//*************************************************************************
/*
function inicializarEventos() {
   var ob;
   for( f=1; f<=12; f++ ) {
      ob = document.getElementById( 'enlace' + f );
      addEvent( ob, 'click', presionEnlace, false );
   }
}

function presionEnlace( e ) {
   if ( window.event ) {
      window.event.returnValue = false;
      var url = window.event.srcElement.getAttribute( 'href' );
      cargarHoroscopo( url );     
   } else {
      if ( e ) {
         e.preventDefault();
         var url = e.target.getAttribute( 'href' );
         cargarHoroscopo( url );
	  }
   }
}

function cargarHoroscopo( url ) {
   if ( url == '' ) {
      return;
   }
   conexion1=crearXMLHttpRequest();
   conexion1.onreadystatechange = procesarEventos;
   conexion1.open("GET", url, true);
   conexion1.send(null);
}

function procesarEventos() {
   var detalles = document.getElementById("detalles");
   if ( conexion1.readyState == 4 ) {
      detalles.innerHTML = conexion1.responseText;
   } else {
      detalles.innerHTML = 'Cargando...';
   }
}*/

function procesarDepartamentos() {
   var departmentos = document.getElementById( "departamentos" );
   if ( coneccion.readyState == 4 ) {
      departmentos.innerHTML = coneccion.responseText;
   } else {
      departmentos.innerHTML = 'Cargando...';
   }
}

function procesarProvincias() {
   var provincias = document.getElementById( "provincias" );
   if ( coneccion.readyState == 4 ) {
	  //alert(coneccion.responseText);
      provincias.innerHTML = coneccion.responseText;
   } else {
      provincias.innerHTML = 'Cargando...';
   }
}

function procesarDistritos() {
   var distritos = document.getElementById( "distritos" );
   if ( coneccion.readyState == 4 ) {
	  //distritos.innerHTML = 'ABC';
      distritos.innerHTML = coneccion.responseText;
   } else {
      distritos.innerHTML = 'Cargando...';
   }
}

function cargarDepartamentos( pais ) {
   if ( pais == 0 ) {
      return;
   }
   var url = 'ajax/select_departamentos.php?pID=' + pais;
   coneccion = crearXMLHttpRequest();
   coneccion.onreadystatechange = procesarDepartamentos;
   coneccion.open( "GET", url, true );
   coneccion.send( null );
	
}

function cargarProvincias( departamento ) {
   //alert('abc');
   if ( departamento == 0 ) {
      return;
   }
   var url = 'ajax/select_provincias.php?dID=' + departamento;
   coneccion = crearXMLHttpRequest();
   coneccion.onreadystatechange = procesarProvincias;
   coneccion.open( "GET", url, true );
   coneccion.send( null );
	
}

/*function cargarDistritos( provincia ) {
   alert('Provincia: ' + provincia);
}*/

function cargarDistritos( provincia ) {
   //alert('Provincia: ' + provincia);
   //return;
   if ( provincia == 0 ) {
      return;
   }
   var url = 'ajax/select_distritos.php?pID=' + provincia;
   coneccion = crearXMLHttpRequest();
   coneccion.onreadystatechange = procesarDistritos;
   coneccion.open( "GET", url, true );
   coneccion.send( null );
}

/* MENUS */
function cargarDestino( tipo, valor ) {
   if ( tipo == '' ) {
      return;
   }
   var url = 'ajax/menu_destino.php?tipo=' + tipo + '&valor=' + valor;
   coneccion = crearXMLHttpRequest();
   coneccion.onreadystatechange = procesarMenuDestino;
   coneccion.open( "GET", url, true );
   coneccion.send( null );
}

function procesarMenuDestino() {
   var enlace = document.getElementById( "enlace" );
   if ( coneccion.readyState == 4 ) {
      enlace.innerHTML = coneccion.responseText;
   } else {
      enlace.innerHTML = 'Cargando...';
   }
}
/* FIN MENUS */

/* ENVIAR COMENTARIOS CONTENIDO */
function CargarDatosComentarioContenido() {
  var parametros = '';
  var cliente = document.getElementById('cliente').value;
  var comentario = document.getElementById('comentario').value;
  parametros = 'cliente=' + encodeURIComponent(cliente) + '&comentario=' + encodeURIComponent(comentario);
  return parametros;
}

function EnviarComentarioContenido() {
   var url = 'ajax/enviar_comentario_contenido.php';
   coneccion = crearXMLHttpRequest();
   coneccion.onreadystatechange = procesarEnvioComentarioContenido;
   coneccion.open( "POST", url, true );
   coneccion.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
   coneccion.send( CargarDatosComentarioContenido() );
}

function procesarEnvioComentarioContenido() {
   var comentarios = document.getElementById( "comentarios" );
   if ( coneccion.readyState == 4 ) {
      comentarios.innerHTML = coneccion.responseText;
   } else {
      comentarios.innerHTML = 'Cargando...';
   }
}
/* FIN ENVIAR COMENTARIOS CONTENIDO */

//addEvent( window, 'load', inicializarEventos, false );
var coneccion;
//var conProvincia;
