/* Implementación AJAX */
var url = "includes/secHerramInicio/result_PaisDelegacion.php?paisID="; // The server-side script

function handleHttpResponse() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    results = http.responseText.split("|");
    
		iArreglo = 0;
		
		totalDeleg = results[0];
		
		document.getElementById("loadingData").innerHTML = '&nbsp;';
		
		iArreglo++;
		
		document.getElementById("titulo_1").innerHTML = results[iArreglo++];
		document.getElementById("nombre_contacto_1").innerHTML = results[iArreglo++];
		document.getElementById("tel_area_1").innerHTML = results[iArreglo++];
		document.getElementById("tels_1").innerHTML = results[iArreglo++];
		document.getElementById("telsfax_1").innerHTML = results[iArreglo++];
		document.getElementById("cels_1").innerHTML = results[iArreglo++];
		document.getElementById("dir01_1").innerHTML = results[iArreglo++]+results[iArreglo++];
		document.getElementById("email01_1").innerHTML = results[iArreglo++];
		document.getElementById("email02_1").innerHTML = results[iArreglo++];
		document.getElementById("url01_1").innerHTML = results[iArreglo++];
		document.getElementById("apart_postal_1").innerHTML = results[iArreglo++];
		
		contenedoResult = '';
		
		if(totalDeleg>1){
			
			for(x=2; x<=totalDeleg; x++)
				contenedoResult = contenedoResult + '<div id="q_' + x + '" class="recuadroBusq">&nbsp;</div><br />';
									
			document.getElementById("cuadro").innerHTML =  contenedoResult;
				
			for(x=2; x<=totalDeleg; x++){
				
				txtResult = '<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">';
				
				txtResult = txtResult + '<tr><td width="15%" align="right">&nbsp;</td><td width="10%" align="right">&nbsp;</td>';
				txtResult = txtResult + '<td width="72%" id="titulo_' + x + '">' + results[iArreglo++] + '</td>';
				txtResult = txtResult + '<td width="3%">&nbsp;</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">Nombre:</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="nombre_contacto_' + x + '" colspan="2">' + results[iArreglo++] + '</td></tr>';
				
				<!-- Telefonos -->
				txtResult = txtResult + '<tr><td colspan="4"><div id="dataComplementa_' + x + '" style="display:none">';
				txtResult = txtResult + '<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">';
				
				txtResult = txtResult + '<tr><td width="15%">&nbsp;</td><td width="10%">&nbsp;</td><td width="75%">&nbsp;</td></tr>';
						
				txtResult = txtResult + '<tr><td align="right" valign="top">Tel&eacute;fonos:</td>';
				txtResult = txtResult + '<td align="center" valign="top" id="tel_area_' + x + '">' + results[iArreglo++] + '</td>';
				txtResult = txtResult + '<td id="tels_' + x + '">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">Tels. fax:</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="telsfax_' + x + '">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">Tel. celular:</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="cels_' + x + '">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '</table></div></td></tr>';
				
				<!-- Direccion -->
				txtResult = txtResult + '<tr><td colspan="4">&nbsp;</td></tr>';
				txtResult = txtResult + '<tr><td align="right" valign="top">Direcci&oacute;n:</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="dir01_' + x + '">' + results[iArreglo++] + results[iArreglo++] + '</td>';
				
				txtResult = txtResult + '<td align="right"><a style="cursor:hand" onclick="javascript:document:getElementById(\'dataComplementa_' + x + '\').style.display=\'\';';
				txtResult = txtResult + 'document:getElementById(\'dataComplementb_' + x + '\').style.display=\'\';';
				txtResult = txtResult + 'document:getElementById(\'imgCompMen_' + x + '\').style.display=\'\';';
				txtResult = txtResult + 'document:getElementById(\'imgCompMas_' + x + '\').style.display=\'none\';">';
				txtResult = txtResult + '<img id="imgCompMas_' + x + '" src="imagenes/masInfoPT.gif" width="14" height="14" /></a></td></tr>';
				
				<!-- emails, web, apart.Postal -->
				txtResult = txtResult + '<tr><td colspan="4"><div id="dataComplementb_' + x + '" style="display:none">';
				txtResult = txtResult + '<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">';
				
				txtResult = txtResult + '<tr><td width="15%">&nbsp;</td><td width="10%">&nbsp;</td><td width="72%">&nbsp;</td><td width="3%">&nbsp;</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">e-mail:</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="email01_' + x + '" colspan="2">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">&nbsp;</td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="email02_' + x + '" colspan="2">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">Sitio web: </td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="url01_' + x + '" colspan="2">' + results[iArreglo++] + '</td></tr>';
				
				txtResult = txtResult + '<tr><td align="right">Apart. Postal: </td><td align="right">&nbsp;</td>';
				txtResult = txtResult + '<td id="apart_postal_' + x + '">' + results[iArreglo++] + '</td>';
				
				txtResult = txtResult + '<td align="right"><a style="cursor:hand" onclick="javascript:document:getElementById(\'dataComplementa_' + x + '\').style.display=\'none\';';
				txtResult = txtResult + 'document:getElementById(\'dataComplementb_' + x + '\').style.display=\'none\';';
				txtResult = txtResult + 'document:getElementById(\'imgCompMen_' + x + '\').style.display=\'none\';';
				txtResult = txtResult + 'document:getElementById(\'imgCompMas_' + x + '\').style.display=\'\';">';
				txtResult = txtResult + '<img id="imgCompMen_' + x + '" src="imagenes/menInfoPT.gif" width="14" height="14" style="display:none" /></a>';
				txtResult = txtResult + '</td></tr>';
				
				
				
				txtResult = txtResult + '</table></div></td></tr>';
				
				txtResult = txtResult + '</table>';
				
				document.getElementById("q_" + x).innerHTML = txtResult;
				
			}
		}else
			// Limpiar
			document.getElementById("cuadro").innerHTML = '&nbsp;';
  }
}

function mostrarDelegacion() {
  var paisValue = document.getElementById("pais").value;
  
	document.getElementById("loadingData").innerHTML = 'Cargando ... <img src="imagenes/loadingData.gif" align="absmiddle" />';
	
	//Llamada a script que procesa y obtiene los resultados según pais escogido
  http.open("GET", url + escape(paisValue), true);
  
	http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
	
  return xmlhttp;
}

var http = getHTTPObject(); // We create the HTTP Object
