/*
cantones.js
2007
Daniel Ardila

Peticiones de los cantones de una provincia
--------------------------------------------------------- 
Basado en http://www.captain.at/howto-ajax-form-post-get.php
dardila@undermedia.com.ec
http://www.undermedia.com.ec/
--------------------------------------------------------- */

   var http_request = false;
   function makeRequest(url) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('No se pudo crear la instancia XMLHTTP');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
			
            result = http_request.responseText;
			
			var update = new Array();			
			if(result.indexOf('|') != -1) {
				update = result.split('|');
				changeTextPro(update[0], update[1]);
			}       
         } else {
            alert('Hubo un problema en ejecutar la petición.');
         }
      }
   }

function sndPro(provincia) {

	var idProvincia=provincia.split(","); //ramiro
	provincia = idProvincia[2]; // ramiro
	
	var thetd = document.getElementById('districto'); // the td de cantones
	var proid = parseInt(provincia);
	
	if(provincia == 0){
		thetd.innerHTML = '';
		return false;
	}
	
	thetd.innerHTML = '<div class="loading"><strong>Cargando...</strong><img src="img/working.gif" /></div>';
	
    makeRequest('comboDinamicoAjax.php?idCiu='+proid);
}

function changeTextPro( div2show, text) {
    // Detect Browser
	id = parseInt(div2show);
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById('districto');
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all['districto'].innerHTML = text;
    }
}




