// Esta función cargará las paginas
function llamarasincrono(url, id_contenedor){
var pagina_requerida = false
if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
pagina_requerida = new XMLHttpRequest()
} else if (window.ActiveXObject){ // pero si es IE
try {
pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){ // en caso que sea una versión antigua
try{
pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pagina_requerida.onreadystatechange=function(){ // función de respuesta
cargarpagina(pagina_requerida, id_contenedor)
}
pagina_requerida.open('GET', url, true) // asignamos los métodos open y send
pagina_requerida.send(null)
}
// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText
}
///////////////////////funcion para pasar el CP
setCp = function (tex,td,clase,tipo){
	var t1 = document.getElementById(tex);
	var td1 = document.getElementById(td);
	//alert(t1.value);
	if(t1.value.length==5){
		//alert(t1.value);
	llamarasincrono('getAsenta.php?cp='+t1.value+'&class='+clase+'&type='+tipo, td);
	}else{
		//llamarasincrono('about:blank', 'combDiv');
	}
}
//////------END---------------------------------
// --- START --- Función que elimina los caracteres alfabéticos de un capo de texto --------------------
function justNumbers(fieldName){
	var allowedKeys = new Array("0","1","2","3","4","5","6","7","8","9");
	var contentArray = new Array();
	var finalArray = new Array();
	var fieldContent = fieldName.value;
	var cont = 0;
	var filteredContent = "";
	
	// Creación de un arreglo con los caracteres del campo de texto
	for(i=0; i<=fieldContent.length; i++){
		contentArray[i] = fieldContent.substring(i,i+1);
	}
	
	for(j=0; j<=contentArray.length; j++){
		for(x=0; x<=allowedKeys.length; x++){
			if(contentArray[j] == allowedKeys[x]){
				finalArray[cont] = contentArray[j];
				cont++;
			}
		}
	}

	for(z=0; z<=finalArray.length-2; z++){
		filteredContent += finalArray[z];
	}
	fieldName.value = filteredContent;
}
// --- END ----------------------------------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
///////funcion que pide la CLave de Chiapas---------------------------------------------------------------
confirmClave = function (table1,table2,texto){
	var t1 = document.getElementById(table1);
	var t2 = document.getElementById(table2);
	var clav = document.getElementById(texto);
	if (clav.value == "amchiapas_2006"){
		t1.style.display = "none";
		t2.style.display = "inline";
	}else{
		alert('Clave Invalida intentelo nuevamente o comuniquese con su coordinador para que le de una clave correcta...')	
	}
}
// --- END -----------------------------------------------------------------------------------------------
// - Recibe dos parámetros txtField = "nombre del campo" y apply = "número de implementación"
function setMySQLDate(txtField,apply){
	var d = "dia"+apply;
	var m = "mes"+apply;
	var a = "anyo"+apply;
	
	var txt = document.getElementById(txtField);
	var dia = document.getElementById(d).value;
	var mes = document.getElementById(m).value;
	var anyo = document.getElementById(a).value;
	
	txt.value = anyo+"-"+mes+"-"+dia;
}
// --- END ------------------------------------------------------------------------------------------
// --- START --- Función que mustra y/u oculta los forms[0]s según sea el caso seleccionado -------
function showFormCase(valueToEvaluate){
var formCase2 = document.getElementById('form_case2'); //ID 102
var formCase3N4 = document.getElementById('form_case3AND4'); //ID 103
var hdnField = document.getElementById('caseSelected');
var totalEdosCedula = document.forms[0].edocedula.length;
	if(valueToEvaluate != ""){
		if(valueToEvaluate == "101"){
			formCase2.style.display = 'none';
			formCase3N4.style.display = 'none';
			hdnField.value = 1;
			document.forms[0].edocedula.style.display = 'none';
			for(i =0;i<totalEdosCedula;i++){
				if(document.forms[0].edocedula[1].value!=95){
					var cedula = document.createElement("option");
					cedula.value = 95;
					cedula.innerText = "Cedula Profesional";
					document.forms[0].edocedula.insertBefore(cedula, opciones_2);
					document.forms[0].edocedula[1].selected = true;
				}	
			}
		
		}
		else if(valueToEvaluate == "102"){
			formCase2.style.display = '';
			formCase3N4.style.display = 'none';
			document.forms[0].edocedula.style.display = 'none';
			for(i =0;i<totalEdosCedula;i++){
				if(document.forms[0].edocedula[1].value!=95){
					var cedula = document.createElement("option");
					cedula.value = 95;
					cedula.innerText = "Cedula Profesional";
					document.forms[0].edocedula.insertBefore(cedula, opciones_2);
					document.forms[0].edocedula[1].selected = true;
				}	
			}
			hdnField.value = 2;
		}
		else if(valueToEvaluate == "103"){
			formCase2.style.display = 'none';
			formCase3N4.style.display = '';
			document.forms[0].edocedula.style.display = 'none';
			for(i =0;i<totalEdosCedula;i++){
				if(document.forms[0].edocedula[1].value!=95){
					var cedula = document.createElement("option");
					cedula.value = 95;
					cedula.innerText = "Cedula Profesional";
					document.forms[0].edocedula.insertBefore(cedula, opciones_2);	
					document.forms[0].edocedula[1].selected = true;
				}	
			}
			hdnField.value = 3;
		}
		else if(valueToEvaluate == "104"){
			formCase2.style.display = 'none';
			formCase3N4.style.display = '';
			document.forms[0].edocedula.style.display = 'inline';
			for(i =0;i<totalEdosCedula;i++){
				if(document.forms[0].edocedula[i].value==95){
					document.forms[0].edocedula.remove(i);
					document.forms[0].edocedula[0].selected = true;
					crear = true;
					break;	
				}
			}
			hdnField.value = 4;
		}
		else if(valueToEvaluate == "105"){
			formCase2.style.display = 'none';
			formCase3N4.style.display = 'none';
			document.forms[0].edocedula.style.display = 'inline';
			hdnField.value = 5;
			for(i =0;i<totalEdosCedula;i++){
				if(document.forms[0].edocedula[1].value!=95){
					var cedula = document.createElement("option");
					cedula.value = 95;
					cedula.innerText = "Cedula Profesional";
					document.forms[0].edocedula.insertBefore(cedula, opciones_2);	
					document.forms[0].edocedula[1].selected = true;
				}	
			}
		}
	}
	else{
			formCase2.style.display = 'none';
			formCase3N4.style.display = 'none';
			hdnField.value = 0;
	}
	//alert("Caso seleccionado: \""+hdnField.value+"\"");
	var crear = false;
}
// --- END ------------------------------------------------------------------------------------------
////// Funcion que cambia las sedes Segun el Estado
function AsignaSede(combo_estado,combo_sede){	
	var campo = combo_estado.value;
	var oSelect = combo_sede;
	var separa = campo.split("|")
	var estado = separa[0];
	var valor = separa[1].split(":");
	var texto = separa[2].split(":");
	var vm = valor.length-1;
	var vt = 50;
	for(i=0;i<=vt;i++){ oSelect.remove(1);	}
	for(i=0;i<=vm;i++){
		var oOption = document.createElement("OPTION");
		oOption.text=texto[i]+" ("+valor[i]+")";
		oOption.value=estado+"|"+valor[i];
		oSelect.add(oOption);
		//alert(valor[i]);
		/*if(valor[i]==304){
			oOption.selected = true;	
		}*/
	}
//combo_sede.focus();
}
// --- END ------------------------------------------------------------------------------------------
/////////////////////////////////////////////
function Cuota(vvalor){
			valor = vvalor.split("|");
	if (document.forms[0].opcion.value =="1"){
		document.forms[0].cuotavals.value = vvalor; //valor cuota completa
		document.forms[0].cuota_tipo.value = valor[1]; //tipo cuota
		document.forms[0].ref_cuota.value = valor[2];	 //numero sesiones q paga
		document.forms[0].nsp_cuota.value = valor[3];	 //numero sesiones q paga
		document.forms[0].cuota_rete_coord.value = valor[9];	 //numero sesiones q paga
		document.forms[0].cantidad.value = valor[0];
		//document.formulario.cantidad.focus();
		document.forms[0].chidden.value = valor[0]; //valor cuota oculta
		// Empieza el calculo de comisión retenida para coordinadores		
		if (document.forms[0].cantidad_coord_valor.value == "0"){
			document.forms[0].cantidad_coord.value = document.forms[0].cuota_rete_coord.value;
		}
		if (document.forms[0].cantidad_coord_valor.value == "1"){
			document.forms[0].cantidad_coord.value = document.forms[0].cantidad.value;
		}
		// Aquí termina el calculo de comisión retenida para coordinadores
		//alert(document.formulario.cantidad_coord.value);
		//document.formulario.cantidad_coord.value = valor[0]*.5; //valor cuota oculta
	}
	//Empieza el calculo para promesa de pago
	if (document.forms[0].opcion.value =="2"){
		//document.formulario.cuotavals.value = vvalor; //valor cuota completa
		document.forms[0].cuota_tipo.value = valor[1]; //tipo cuota
		document.forms[0].ref_cuota.value = valor[2];	 //numero sesiones q paga
		document.forms[0].nsp_cuota.value = valor[3];	 //numero sesiones q paga
		//document.formulario.cuota_rete_coord.value = valor[9];	 //numero sesiones q paga
		document.forms[0].cantidad.value = valor[0];
		//document.formulario.cantidad.focus();
		document.forms[0].chidden.value = valor[0]; //valor cuota oculta
	}
	//Termina el calculo para promesa de pago
	if (document.forms[0].opcion.value =="2"){
		document.forms[0].cantidad.value = 0;
		document.forms[0].cantidad_coord.value = document.forms[0].cantidad.value;
		
	}
	//alert(document.formulario.cantidad_coord.value);
	//alert(document.formulario.cantidad.value);
	//alert(document.formulario.cuota_tipo.value);
}
//////////////////////////////////////////////////////////////////
