var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;

var peticion_http;

function cargaContenido(url, metodo, funcion) {
  //alert("entro");
  peticion_http = inicializa_xhr();
  if(peticion_http) {
    //Esto no esta muy bien aqui -> mirar
    swap_paneles(1);
    
    peticion_http.onreadystatechange = funcion;

    peticion_http.open(metodo, url, true);
    peticion_http.send(null);
  }
}

function inicializa_xhr() {
  if(window.XMLHttpRequest) {
    return new XMLHttpRequest();
  } else if(window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
}

function muestraContenido() {
  if(peticion_http.readyState == READY_STATE_COMPLETE) {
    if(peticion_http.status == 200) {
      //alert(peticion_http.responseText);
      //var object = document.getElementById(objectID);
      var object = document.getElementById("panel_telefonos");
      object.innerHTML = peticion_http.responseText;
      swap_paneles(0);
    }
  }
}

function swap_paneles(cargando) {
  el1 = document.getElementById("panel_telefonos");
  el2 = document.getElementById("panel_cargando");
  if (cargando) {
    el1.style.display = 'none';
    el2.style.display = 'block';
  } else {
    el2.style.display = 'none';
    el1.style.display = 'block';
  }
}


function rowOverLoader(obj) {
  if (obj.className != 'seleccionado') {
    obj.className = 'over';
  }
}

function rowOutLoader(obj) {
  if (obj.className != 'seleccionado') {
    obj.className = 'normal';
  }
}

function change_price_plan_selector() {
	el = document.getElementById('price_plan_selector');
	cargaContenido(el.value,'GET',muestraContenido);
}

function mostrar(elemento) {
  el = document.getElementById(elemento);
  el.style.display = 'block';
}

function ocultar(elemento) {
  el = document.getElementById(elemento);
  el.style.display = 'none';
}

function rowOverNav(obj) {
    obj.className = 'nav_over';
}

function rowOutNav(obj) {
    obj.className = 'nav';
}
function change_contract_type_selector() {
    el = document.getElementById('contract_type_selector');
    cargaContenido(el.value,'GET',muestraContenido);
}