//alert("simulador");
var forma = document.frmCalcula;

function Inicializa()
{	
	var VerLen
	
	
	VerLen= CompruebaLen()		
	
	if (VerLen == false)
	{
		
		alert("Necesita cambiar su configuración regional para que opere adecuadamente el simulador \nrequiere la configuración español México para que los separadores de miles aparezcan\ncon comas (,) y no con puntos (.)");
		forma.Produc.disabled = true;	
		forma.ValViv.disabled = true;	
		forma.BtnCalcula.disabled = true;	
		return 0;
	}	
	HabObj("Inicio", false);
	forma.TiCrSi.disabled = false;	
	forma.Produc.disabled = false;	
	forma.TipCal.disabled = false;	
	forma.CFTiFi.disabled = false;
	forma.HonNot.value = "2.0";
	forma.BtnCalcula.disabled = true;		
	forma.TiCrSi.value = 0;	
	forma.TipCal.value = 0;	
	forma.CFTiFi.value = 0;	
	forma.TiCrSi.focus();		
}	

function CalculaGN(Produc, PorGan)
{
	var ValViv = DN(forma.ValViv.value)
		
	if (Produc == "INF")
	{
		// Si es por importe habilitamos el campo del importe...
		if (PorGan=="X")
		{	forma.ImpGan.disabled = false;	}
		else
		{
			if (PorGan == "0" || ValViv == "0")
			{	forma.ImpGan.value = formatonum(0,2)	}
			else
			{	forma.ImpGan.value = formatonum(((ValViv * PorGan)/100),2)	}
			forma.ImpGan.disabled = true;						
		}
	}
	
	if (Produc == "FOV")
	{
		// Si es por importe habilitamos el campo del importe...
		if (PorGan == "X")
		{	forma.CFImNo.disabled = false;	}
		else
		{
			if (PorGan == "0" || ValViv == "0")
			{	forma.CFImNo.value = formatonum(0,2)	}
			else
			{	forma.CFImNo.value = formatonum(((ValViv * PorGan)/100),2)		}
			forma.CFImNo.disabled = true;
		}
	}	
	
	
	if (Produc == "SHF")
	{
		if (PorGan == "V")
		{	PorGan = forma.NotSad.value	}		
	
		// Si es por importe habilitamos el campo del importe...
		if (PorGan=="X")
		{	forma.GanSHF.disabled = false;	}
		else
		{
			if (PorGan == "0" || ValViv == "0")
			{	forma.GanSHF.value = formatonum(0,2)	}
			else
			{	forma.GanSHF.value = formatonum(((ValViv * PorGan)/100),2)	}
			forma.GanSHF.disabled = true;						
		}
	}	
}

function CompruebaLen()
{
	var NumPru
	
	NumPru = formatonum(1000000,2);
	/*alert(NumPru);
	alert(BuscaPunto(NumPru));*/
	if (BuscaPunto(NumPru) == 2)	
	{	return  false	}
	else
	{	return  true	}
	
	//alert(Remplaza(NumPru,");	(
	//alert(NumPru.replace(',','');
}

/*function ValidaPlaMon(TipCre)
{
	if (TipCre == "INF")
	{
		//alert(forma.Produc.value);
		if (forma.TipCre.value == "2" && forma.PlaCre.value == "300" && forma.Produc.value != "CP" )
		{	forma.PlaCre.value = 240;	}
	}
	if (TipCre == "FOV")
	{
		if (forma.CFMoCr.value == "2" && forma.CFPlCr.value == "300")
		{	forma.CFPlCr.value = 240;	}
	}
}*/


function HabObj(SecObj, Estado)
{
	if (Estado == true)
	{	Estado = false	}
	else
	{	Estado = true	}
	
	if (SecObj=="Inicio")
	{	
		forma.Produc.disabled = Estado;
		forma.ValViv.disabled = Estado;
		forma.PorCre.disabled = Estado;
		forma.MonCre.disabled = Estado;
	}
	
	if (SecObj=="Recoti")
	{	
		forma.Produc.disabled = Estado;
		forma.ValViv.disabled = Estado;
		forma.PorCre.disabled = Estado;
		forma.MonCre.disabled = Estado;
		forma.MonEng.disabled = Estado;
		forma.NumSes.disabled = Estado;
		forma.Ingres.disabled = Estado;
		forma.IngPro.disabled = Estado;
		forma.ApoAdi.disabled = Estado;
		forma.NSSCof.disabled = Estado;
		forma.TipCal.disabled = Estado;
		forma.TipCre.disabled = Estado;
		forma.PlaCre.disabled = Estado;
		forma.HonNot.disabled = Estado;
		forma.ImpDer.disabled = Estado;
		forma.IngShf.disabled = Estado;
		forma.chkEst.disabled = Estado;
		forma.chkAva.disabled = Estado;
		forma.ImpGan.disabled = Estado
		
		forma.TipCre.disabled = Estado;
		forma.CFTiFi.disabled = Estado;
		forma.CFIngr.disabled = Estado;
		forma.CFSaBa.disabled = Estado;
		forma.CFBuAc.disabled = Estado;
		
		forma.AjAcCF.disabled = Estado;
		forma.AjAcSV.disabled = Estado;
		forma.AjCoCF.disabled = Estado;
		forma.AjCoSV.disabled = Estado;
		
		forma.CFApAd.disabled = Estado;
		forma.CFMoCr.disabled = Estado;
		forma.CFPlCr.disabled = Estado;
		forma.CFGaEs.disabled = Estado;
		forma.CFImNo.disabled = Estado;
		forma.chkCFEst.disabled = Estado;
		forma.chkCFAva.disabled = Estado;
		forma.TipCre.disabled = Estado;
		forma.TiCrSi.disabled = Estado;
		
		forma.CofCon.disabled = Estado;
		forma.CFCURP.disabled = Estado;
		forma.CURPCoa.disabled = Estado;
		forma.NSSCon.disabled = Estado;
		forma.IngCon.disabled = Estado;
		
		forma.NombSC.disabled = Estado;
		forma.CrInSC.disabled = Estado;
		forma.SuViSC.disabled = Estado;
		forma.DeInSC.disabled = Estado;
		
		forma.FovCon.disabled = Estado;
		forma.CFCOIn.disabled = Estado;
		forma.CFCPSB.disabled = Estado;
		forma.BurCoa.disabled = Estado;		

		
		forma.NotSad.disabled = Estado;
		forma.GanSHF.disabled = Estado;		
		
		forma.OriViv.disabled = Estado;
		forma.chkSub.disabled = Estado;
		
		forma.IngAcrSub.disabled = Estado;
		forma.SubCon.disabled = Estado;
		forma.IngConSub.disabled = Estado;
		forma.ApoAdiSub.disabled = Estado;
	}
	
	if (SecObj=="Calcul")
	{	
		forma.Produc.disabled = Estado;
		forma.ValViv.disabled = Estado;
		forma.TipCal.disabled = Estado;
		forma.PorCre.disabled = Estado;
		forma.MonCre.disabled = Estado;
		forma.MonEng.disabled = Estado;	
		forma.NumSes.disabled = Estado;
		forma.Ingres.disabled = Estado;
		forma.IngPro.disabled = Estado;
		forma.ApoAdi.disabled = Estado;
		forma.NSSCof.disabled = Estado;
		forma.TipCre.disabled = Estado;
		forma.PlaCre.disabled = Estado;
		forma.HonNot.disabled = Estado;
		forma.IngShf.disabled = Estado;
		forma.chkEst.disabled = Estado;
		forma.chkAva.disabled = Estado;
		forma.ImpDer.disabled = Estado;
		
		forma.CofCon.disabled = Estado;
		forma.CFCURP.disabled = Estado;
		forma.CURPCoa.disabled = Estado;
		forma.NSSCon.disabled = Estado;
		forma.IngCon.disabled = Estado;
		
		forma.CFTiFi.disabled = Estado;
		forma.CFIngr.disabled = Estado;
		forma.CFSaBa.disabled = Estado;
		forma.CFBuAc.disabled = Estado;		
		forma.AjAcCF.disabled = Estado;
		forma.AjAcSV.disabled = Estado;
		forma.AjCoCF.disabled = Estado;
		forma.AjCoSV.disabled = Estado;
		forma.CFApAd.disabled = Estado;
		forma.CFMoCr.disabled = Estado;
		forma.CFPlCr.disabled = Estado;
		forma.CFGaEs.disabled = Estado;
		forma.CFImNo.disabled = Estado;
		forma.chkCFEst.disabled = Estado;
		forma.chkCFAva.disabled = Estado;
		forma.TipCre.disabled = Estado;
		forma.TiCrSi.disabled = Estado;		
		
		forma.NombSC.disabled = Estado;
		forma.CrInSC.disabled = Estado;
		forma.SuViSC.disabled = Estado;
		forma.DeInSC.disabled = Estado;		
		
		forma.FovCon.disabled = Estado;
		forma.CFCOIn.disabled = Estado;
		forma.CFCPSB.disabled = Estado;
		forma.BurCoa.disabled = Estado;		
		
		forma.OriViv.disabled = Estado;
		forma.chkSub.disabled = Estado;
		
		forma.IngAcrSub.disabled = Estado;
		forma.SubCon.disabled = Estado;
		forma.IngConSub.disabled = Estado;
		forma.ApoAdiSub.disabled = Estado;
		
		if (forma.HonNot.value == "X")
		{	forma.ImpGan.disabled = Estado	}	
		DIV_DatCof.style.display = "none"
		DIV_DatFov.style.display = "none"

		/*DIV_DetUDI.style.display = "none"
		DIV_DetPES.style.display = "none"
		DIV_CotUdi.style.display = "none"
		DIV_CotPes.style.display = "none"
		
		
		DIV_DetCof.style.display = "none"*/		
		if (forma.BtnPla.value = "Ocultar plazos")
		{	
			TD_LeyCom.innerHTML = ""
			forma.BtnPla.value = "Otros plazos"
			HabObj("PlaCof",true)	
		}
		
		forma.NotSad.disabled = Estado;
		forma.GanSHF.disabled = Estado;
	}
	
	/*if (SecObj=="PlaCof")
	{				
		forma.PlaCot.value = ""		
		forma.Plazo1.value = ""
		forma.Plazo2.value = ""
		forma.CrCMP1.value = ""
		forma.CrCMP2.value = ""
		forma.CrInP1.value = ""
		forma.CrInP2.value = ""
		forma.SuViP1.value = ""
		forma.SuViP2.value = ""
		forma.GaOrP1.value = ""
		forma.GaOrP2.value = ""
		forma.EngaP1.value = ""
		forma.EngaP2.value = ""
		forma.VaViP1.value = ""
		forma.VaViP2.value = ""
		forma.MeCmP1.value = ""
		forma.MeCmP2.value = ""
		forma.GaCmP1.value = ""
		forma.GaCmP2.value = ""
		forma.GaInP1.value = ""
		forma.GaInP2.value = ""
		forma.GaEsP1.value = ""
		forma.GaEsP2.value = ""	
		forma.ApAdP1.value = ""	
		forma.ApAdP2.value = ""	
		
		forma.ImDeP1.value = ""	
		forma.ImDeP2.value = ""		
		
		

		forma.DMINP1.value = "";
		forma.DMINP2.value = "";
		forma.ToGOP1.value = "";
		forma.ToGOP2.value = "";
		
		forma.ToGOP1.style.borderTop="";
		forma.ToGOP2.style.borderTop="";
		forma.VaViP1.style.borderTop="";
		forma.VaViP2.style.borderTop="";

	}*/
}


function TipCalSHF(Calculo)
{
	forma.BtnCalcula.disabled = false;
	

	
	if (DN(forma.ValViv.value) >= 1000000 && forma.TiCrSi.value == "S")
	{	
		forma.TipCal.value = "V";
		Calculo = "V"
	}
	
	if (forma.Produc.value == "GMAC")
	{	
		forma.TipCal.value = "V";
		Calculo = "V"
	}
	
	if (Calculo == "V")
	{		
		DIV_CALVIV1.style.display = ""	
		DIV_CALVIV2.style.display = ""			
		DIV_CALVIV3.style.display = ""			
		DIV_INGSHF.style.display = "none"	
		forma.PorCre.value = PorMaxCre();
		forma.PorCreRea.value = forma.PorCre.value
		ValidaViv(forma);
		
	}
	if (Calculo == "I")
	{
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_INGSHF.style.display = ""	
	}	
}



	
function SelPro(TipPro)
{
	/*alert(aRanVal[0]);
	return 0;*/
	var LeyDes;	

	//alert(TipPro);	
	
	var oTR_GanSAD = document.getElementById("TR_GanSAD")
	// Seleccionado producto habilitamos 
	HabObj("Inicio", true);
	//forma.BtnCalcula.disabled = false;
	forma.TipCal.value = 0;
	LBL_LeyCof.innerHTML = '';	


	if (TipPro == "UDIPES" || TipPro == "GMAC"  || TipPro == "DEG")
	{

		// Desplegamos datos de crédito tradicional
		DIV_CRETRA.style.display = ""
		oTR_GanSAD.style.display = ""	
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_INGSHF.style.display = "none"
		
		// Ocultamo cofi
		//DIV_NSS.style.display = "none"	
		DIV_COF.style.display = "none"				
		DIV_DatCof.style.display = "none"
		DIV_FOVIST.style.display = "none"
		
		
		if ( DN(forma.PorCre.value) > PorMaxCre())
		{			
			ValidaCre(forma);
		}
		forma.PorCre.value = PorMaxCre()				
		forma.PorCreRea.value = eval(forma.PorCre.value) / 100
		//alert(TipPro);
		//return 0;
		
		/*if (TipPro == "GMAC")
		{*/
//			TipCalSHF('V')
			ValidaViv(forma);
			//ValidaCre(forma);
	//	}
		//alert(forma.Usuari.value);
		
		var Obj1 = eval(forma.name + ".TipCal");				

		with(Obj1.options)	
		{			
			
			innerHTML = "";
			add( new Option( "VALOR DE VIVIENDA", "V"));	
			if (forma.Usuari.value == "HICAME" || forma.Usuari.value == "PROMOTOR")
			{	
				if (TipPro == "UDIPES")
				{					
					add( new Option( "INGRESOS", "I"));						
				}
			}			
			Obj1.selectedIndex = 0;
			TipCalSHF("V");
			
		}
		
	}	
			
	
	if (TipPro == "INFCOF" || TipPro == "INFCIA" || TipPro == "INFGCO" || TipPro == "INFCSU")
	{	

		forma.BtnCalcula.disabled = true;
		//DIV_DatCof.style.display = ""
		DIV_COF.style.display = ""
		DIV_FOVIST.style.display = "none"
		//DIV_NSS.style.display = "none"			
		DIV_CRETRA.style.display = "none"
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_INGSHF.style.display = "none"
		TR_AjAcCF.style.display = "none"
		TR_AjAcSV.style.display = "none"
		TR_AjCoCF.style.display = "none"		
		TR_AjCoSV.style.display = "none"				
		DIV_IngPro.style.display = "none"
		ValidaViv(forma);		
		
		
		// Si es Cofinavit con subsidios
		if (TipPro == "INFCSU")	
		{	
			// Si no existen parametros de subsidios
			if (forma.ParSub.value == "")	{	ObtenDato('ParSub')		}
			if (DN(forma.Ingres.value) > 0)	{	ValidaIngSub()	}
			// Ocultamos combo de conyugal y inhabilitamos controles			
			TR_CofCon.style.display = "none"				
			forma.CofCon.value = "N"
			ActivaCofCon(forma.CofCon.value)
		}
		else 	{	TR_CofCon.style.display = ""	}

		oTR_GanSAD.style.display = "none"
		
/*		var CboMon = eval(forma.name + ".TipCre");
		with(CboMon.options)
		{	
			innerHTML = "";						
			add( new Option("UDIS", 1));
			add( new Option("PESOS", 2));
		}*/
		
		
		if (TipPro == "INFCIA")
		{		
			DIV_IngPro.style.display = ""	
			TR_CofCon.style.display = "none"
			forma.CofCon.value = "N";
			ActivaCofCon('N')
		}
		//DeshabilitaSub()
	}
	
	
	
	if (TipPro == "APOINF" || TipPro == "INFGAI")
	{
		DIV_DatCof.style.display = "none"
		TR_AjAcCF.style.display = "none"
		TR_AjAcSV.style.display = "none"
		TR_AjCoCF.style.display = "none"
		TR_AjCoSV.style.display = "none"		
		//DIV_NSS.style.display = ""
		DIV_COF.style.display = "none"							
		DIV_FOVIST.style.display = "none"
		DIV_CRETRA.style.display = ""
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_INGSHF.style.display = "none"
		/*if (TipPro == "A")
		{	forma.PorCre.value = 95.00	}
		if (TipPro == "AP")
		{	forma.PorCre.value = 90.00	}*/
		forma.PorCre.value =PorMaxCre()
		
		oTR_GanSAD.style.display = ""
		ValidaViv(forma);		
		//DeshabilitaSub()
		
		var Obj1 = eval(forma.name + ".TipCal");

		with(Obj1.options)	
		{			
			
			innerHTML = "";
			add( new Option( "VALOR DE VIVIENDA", "V"));	
			if (TipPro == "APOINF")
			{	
				if(forma.Usuari.value == "HICAME" || forma.Usuari.value == "PROMOTOR" );
				{						
					add( new Option( "INGRESOS", "I"));		
				}
			}
			Obj1.selectedIndex = 0;
			TipCalSHF("V");
		}
		//alert(TipPro);
	}
	
	if (TipPro == "FOVALI" || TipPro == "FOVRES" || TipPro == "FOALSU")
	{						
		DIV_DatCof.style.display = "none"		
		DIV_COF.style.display = "none"							
		DIV_FOVIST.style.display = "none"
		DIV_FOVIST.style.display = ""
		DIV_CRETRA.style.display = "none"
		TR_GanSAD.style.display = "none"
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_INGSHF.style.display = "none"
		forma.BtnCalcula.disabled = false;
		oTR_GanSAD.style.display = "none"
//		DeshabilitaSub()
		if (forma.Usuari.value =="HCMINF")
		{	TR_AjAcCF.style.display = ""	}
		
		// Si es Alia2 con subsidios
		if (TipPro == "FOALSU")	
		{	
			// Ocultamos combo de conyugal y inhabilitamos controles
			TR_FovCon.style.display = "none"	
			forma.FovCon.value = "N"
			ActivaFovCon(forma.FovCon.value)
		}	
		else 	{	TR_FovCon.style.display = ""	}
		

		
		forma.CFTiFi.value = TipPro;
		TipFinFov(TipPro);
		ValidaViv(forma);
//		alert(TipPro);
		if (TipPro == "FOVALI")
		{			
			document.getElementById("Img_TipFinFOV").src="Images/ALIA2PLUS.JPG"
			//LeyDes = '<b><i>alia2<img src="Images/alia2.jpg" width=120px height=50px></i></B><br>- El valor máximo de la vivienda es de 676 VSM del D.F.<br>  ';
//			LeyDes = '<b><i>ALIA2+</i></B><br>- El valor máximo de la vivienda es de 676 VSM del D.F.<br>  ';
			LeyDes = '<b><i>ALIA2+</i></B><br>';
			//LeyDes += '&nbsp;&nbsp;&nbsp;equivalente a $1,039,233.72 pesos<BR>'						
			LeyDes += '- Los recursos a recibir se integran por el saldo de la Subcuenta<br>&nbsp;&nbsp;&nbsp;más el crédito FOVISSSTE más el crédito de Casa Mexicana'
		}
		if (TipPro == "FOVRES")
		{
			document.getElementById("Img_TipFinFOV").src="Images/respalda2.jpg"
			LeyDes = '<b><i>respalda2</i></B><br>'
			LeyDes += '- No hay limite en el valor de la vivienda<BR>'
			LeyDes += '- Los recursos a recibir se integran por el saldo de la Subcuenta<br>&nbsp;&nbsp;&nbsp;más el crédito de Casa Mexicana'
		}
		if (TipPro == "FOALSU")
		{			
			document.getElementById("Img_TipFinFOV").src="Images/alia2.jpg"
			LeyDes = '<b><i>alia2</i></B><br>- El valor máximo de la vivienda es de 158 VSM del D.F.<br>  ';
			LeyDes += '- Los recursos a recibir se integran por el saldo de la Subcuenta<br>&nbsp;&nbsp;&nbsp;más el crédito FOVISSSTE más el Subsidio a la vivienda<br>&nbsp;&nbsp;&nbsp;más el crédito de Casa Mexicana'
			
			// Si no existen parametros de subsidios
			if (forma.ParSub.value == "")	{	ObtenDato('ParSub')		}
			
			ValidaViv(forma);	
			if (DN(forma.CFIngr.value) > 0)	{	ValidaIngSub()	}
			//ValidaIngSub()
		}

		
		LBL_LeyCof.innerHTML  = LeyDes;
	}	
	
	
	if (TipPro == "SUBSID")
	{	
		forma.chkSub.checked = true;	
		ValidaViv(forma);	
		TR_OriViv.style.display = ""
		DIV_SUB.style.display = ""
		TR_SubCon.style.display = ""
		oTR_GanSAD.style.display = "none"	
		DIV_FOVIST.style.display = "none"
		DIV_COF.style.display = "none"
/*		DIV_CRETRA.style.display = "none"*/
		HabilitaSubSid("SI")
		// Si se selecciona subsidios por primera vez se cargan parámetros
		if (forma.ParSub.value == "")
		{
			ObtenDato('ParSub')
		}


	}
	else
	{	
		TR_OriViv.style.display = "none"
		DIV_SUB.style.display = "none"
		TR_SubCon.style.display = "none"
		//HabilitaSubSid("NO")
	}

}



function VerOpcSHF()
{		
	// Si es cotización UDIS y esta habilitada
	if (forma.CotUdi.value == "S")
	{	TR_TRAUDI.style.display = ""	}
	// Si es cotización PESOS y esta habilitada
	if (forma.CotPes.value == "S")
	{	TR_TRAPES.style.display = ""	}
	
	DIV_DatSHF.style.display = "none"			
	DIV_BotSHF.style.display = "none"
}

function LimpiaForma(forma)
{

	forma.TI_U25.value = ""
	forma.TI_U20.value = ""
	forma.TI_U15.value = ""
	forma.TI_U10.value = ""
	forma.TI_U05.value = ""

	forma.PM_U25.value = ""
	forma.PM_U20.value = ""
	forma.PM_U15.value = ""
	forma.PM_U10.value = ""
	forma.PM_U05.value = ""

	forma.FP_U25.value = ""
	forma.FP_U20.value = ""
	forma.FP_U15.value = ""
	forma.FP_U10.value = ""
	forma.FP_U05.value = ""

	forma.IR_U25.value = ""
	forma.IR_U20.value = ""
	forma.IR_U15.value = ""
	forma.IR_U10.value = ""
	forma.IR_U05.value = ""
	
	forma.TI_P20.value = ""
	forma.TI_P15.value = ""
	forma.TI_P10.value = ""
	forma.TI_P05.value = ""

	forma.PM_P20.value = ""
	forma.PM_P15.value = ""
	forma.PM_P10.value = ""
	forma.PM_P05.value = ""

	forma.FP_P20.value = ""
	forma.FP_P15.value = ""
	forma.FP_P10.value = ""
	forma.FP_P05.value = ""

	forma.IR_P20.value = ""
	forma.IR_P15.value = ""
	forma.IR_P10.value = ""
	forma.IR_P05.value = ""
}

function ltrim(argvalue) {
   while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
	  argvalue = argvalue.substring(1, argvalue.length);
	  }
  return argvalue;
  }

function rtrim(argvalue) {  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;    argvalue = argvalue.substring(0, argvalue.length - 1);  }
  return argvalue;}

function trim(argvalue) { var tmpstr = ltrim(argvalue);  return rtrim(tmpstr);}

function ValidaCre(forma)
{
	// Asignamos al objeto la forma y objeto...			
	var nomfor = forma.name + '.';	
	
	var objViv = eval(nomfor + "ValViv");	
	var objCre = eval(nomfor + "MonCre");
	var objPro = eval(nomfor + "Produc");
	var objEng = eval(nomfor + "MonEng");
	
	
	var objPor = eval(nomfor + "PorCre");
	
	var ValUdi = forma.ValUdi.value
	//var CreTop = 500000 * ValUdi
	var CreTop = ValMaxCre()
	var CreMin = ValMinCre()
	var CreMax = 0;
	var MtCrAj = 0;
	
	if (DN(objCre.value) != 0 && DN(objViv.value) == 0)
	{	
		alert("Favor de ingresar un valor de vivienda")	
		objCre.value = "0.00"
		return 0;
	}

		// Valor máximo para credito tradicional
		CreMax = DN(objViv.value) * (eval(PorMaxCre()) / 100)
		
		/*alert(CreTop);
				alert(CreMax);
						alert(DN(objCre.value)	);*/
		
		// Validamos que no exceda el % maximo de crédito
		if (DN(objCre.value) > CreMax)
		{			
			// Si el monto de crédito máximo no super el crédito tope
			if (CreMax < CreTop)
			{	MtCrAj = CreMax	}
			else
			{	MtCrAj = CreTop	}						
			//alert("cre ajus" + MtCrAj)
			
			objCre.value = formatonum(MtCrAj,2)
			objPor.value = formatonum((MtCrAj / DN(objViv.value) * 100),2)
			forma.PorCreRea.value = MtCrAj / DN(objViv.value)
			objEng.value = formatonum((DN(objViv.value) - MtCrAj),2)			
		}
		else
		{				
			// Si excede el tope de crédito
			if (DN(objCre.value) != 0)
			{
				if (DN(objCre.value) > CreTop)
				{
	
					objCre.value = formatonum(CreTop,2)
					objPor.value = formatonum((CreTop / DN(objViv.value) * 100),2)
					forma.PorCreRea.value = CreTop / DN(objViv.value)
					objEng.value = formatonum((DN(objViv.value) - CreTop),2)
					
				}
				else
				{				
					// Si es menor al monto minímo de crédito
					if (DN(objCre.value) < CreMin)
					{	
						// Ajustamos al minímo de crédito
						objCre.value = formatonum(CreMin,2)
						objPor.value = formatonum((CreMin / DN(objViv.value) * 100),2)
						forma.PorCreRea.value = CreMin / DN(objViv.value)
						objEng.value = formatonum((DN(objViv.value) - CreMin),2)
						
					}
					else
					{
						// Verificamos si tiene el minimo de crédito capturado
						// Ajustamos el porcentaje al monto de crédito
						objPor.value = formatonum((DN(objCre.value) / DN(objViv.value) * 100),2)
						forma.PorCreRea.value = DN(objCre.value) / DN(objViv.value)				
						objEng.value = formatonum((DN(objViv.value) - DN(objCre.value)),2)
					}
				}						
			}
		}						

}


function ValidaViv(forma)
{	
	// Asignamos al objeto la forma y objeto...			
	var nomfor = forma.name + '.';	
	var ValViv = 0; 
	var PorCre = 0; 	
	var ValTop = 0;
	var VaMaVi = ValMaxViv();
	var VaMiVi = ValMinViv();	
	var Produc = forma.Produc.value;
	
	//LimpiaForma(forma);
	// Obtenemos valor de la vivienda
	ValViv = parseFloat(QC(forma.ValViv.value));		

	if (ValViv == "0.00")
	{
		forma.MonCre.value = "0.00"
		return 0;
	}
	
	/*if (Produc  == "C" || Produc  == "I" || Produc  == "CP")
	{
		// Valor tope de vivienda
		ValTop = 538064.80
		// Topamos el valor de vivienda
		if (ValViv > parseFloat(ValTop))
		{
			alert("El valor de vivienda máximo para cofinanciamiento es " + formatonum(ValTop,2));
			forma.ValViv.value = formatonum(ValTop,2);
		}		
		
		if (ValViv < 400000 && forma.UsuLog.value == "URBI")
		{
			alert("Valor de vivienda mínimo de 400,000.00");	
			forma.ValViv.value = "400,000.00"
			ValViv = 400000
		}						
	}			
	
	if (Produc == "UDIPES")
	{	*/	
		if (ValViv != "0.00")
		{
			//PorCre = parseFloat(forma.PorCre.value);	
			//alert(forma.PorCre.value);
			PorCre = parseFloat(forma.PorCreRea.value);	
				
			// Verificamos si el valor de vivienda es mayor al parámetrizado
			if (ValViv > VaMaVi)
			{	
				alert("Valor de vivienda máximo de " + formatonum(VaMaVi,2));	
				forma.ValViv.value = formatonum(VaMaVi,2)
				ValViv = VaMaVi			
			}
			
			// Verificamos si el valor de vivienda es menor al parámetrizado
			if (ValViv < VaMiVi)
			{	
				alert("Valor de vivienda minímo de " + formatonum(VaMiVi,2));	
				forma.ValViv.value = formatonum(VaMiVi,2)
				ValViv = VaMiVi			
			}
			
			/*if (ValViv < 400000 && forma.UsuLog.value == "URBI")
			{
				alert("Valor de vivienda mínimo de 400,000.00");	
				forma.ValViv.value = "400,000.00"
				ValViv = 400000
			}
			
			if (forma.UsuLog.value == "HILHCM")
			{
				if (ValViv < 300000)
				{
					alert("Valor de vivienda mínimo de 300,000.00");	
					forma.ValViv.value = "300,000.00"
					ValViv = 300000
				}
				
				if (ValViv > 1500000)
				{
					alert("Valor de vivienda máximo de 1,500,000.00");	
					forma.ValViv.value = "1,500,000.00"
					ValViv = 1500000
				}
	
			}
			*/

			/*
			if (ValViv <= 225000)
			{
				TR_ChkSub.style.display = ""
				HabilitaSubSid();
			}
			else
			{
				DeshabilitaSub()
			}
			*/
			
			//alert(PorCre);			
			
			// Validamos que si el valor de vivienda es de
			// 1,000,000 en adelate deshabilitamos el 
			// calculo por monto
			
			/*if (ValViv >= 1000000  && forma.TiCrSi.value == "UDIPES")
			{	
				forma.TipCal.value = "V";
				TipCalSHF('V');
			}
			*/
			forma.MonCre.value = formatonum((ValViv * PorCre),2)			
			forma.PorCre.value = formatonum((DN(forma.MonCre.value) / ValViv * 100),2)
			/*alert(DN(forma.MonCre.value))
			alert(DN(forma.MonCre.value) / ValViv)*/
			forma.PorCreRea.value = DN(forma.MonCre.value) / ValViv
			forma.MonEng.value = formatonum(ValViv - parseFloat(QC(forma.MonCre.value)),2)				
										
			ValidaCre(forma)
		}
	

	/*if (Produc == "GMAC")
	{	
		
		
		
		// Verificamos si el valor de vivienda es mayor al parámetrizado
		if (ValViv > VaMaVi)
		{	
			alert("Valor de vivienda máximo de " + formatonum(VaMaVi,2));	
			forma.ValViv.value = formatonum(VaMaVi,2)
			ValViv = VaMaVi			
		}
		
		// Verificamos si el valor de vivienda es menor al parámetrizado
		if (ValViv < VaMiVi)
		{	
			alert("Valor de vivienda minímo de " + formatonum(VaMiVi,2));	
			forma.ValViv.value = formatonum(VaMiVi,2)
			ValViv = VaMiVi			
		}
			
		PorCre = parseFloat(forma.PorCreRea.value);	
		forma.MonCre.value = formatonum((ValViv * PorCre),2)			
		forma.PorCre.value = formatonum((DN(forma.MonCre.value) / ValViv * 100),2)

		forma.PorCreRea.value = DN(forma.MonCre.value) / ValViv
		forma.MonEng.value = formatonum(ValViv - parseFloat(QC(forma.MonCre.value)),2)				
		TipCalSHF('V');							
		ValidaCre(forma)
	}
	
	if (Produc == "A" || Produc  == "AP")
	{		
		// Valor tope de vivienda
		ValTop = 1890913.44 
		
		//if (ValViv < 400000 && forma.UsuLog.value == "URBI")

		
		// Topamos el valor de vivienda
		if (ValViv > parseFloat(ValTop))
		{
			alert("El valor de vivienda máximo a financiar para Apoyo Infonavit es " + formatonum(ValTop,2));
			forma.ValViv.value = formatonum(ValTop,2);
		}				
		PorCre = parseFloat(forma.PorCre.value);	
		forma.MonCre.value = formatonum(ValViv * (PorCre /100),2)
		forma.MonEng.value = formatonum(ValViv - parseFloat(QC(forma.MonCre.value)),2)	
		ValidaCre(forma)
	}
	
	if (Produc == "FA")
	{		
		// Valor tope de vivienda
		ValTop = 1039233.72 		
		
		// Topamos el valor de vivienda
		if (ValViv > parseFloat(ValTop))
		{
			alert("El valor de vivienda máximo a financiar para el programa aliados es " + formatonum(ValTop,2));
			forma.ValViv.value = formatonum(ValTop,2);
		}						
	}
	*/
}	

function DeshabilitaSub()
{
	
	TR_ChkSub.style.display = "none"
	forma.chkSub.checked = false;
	HabilitaSubSid();
	TBL_COTUDI.width = "550"
	TBL_COTPES.width = "550"
}

function js_VI(forma, Campo, Decimales)
{	
	
	// Declaramos variables
	var Mensaje;
	// Asignamos al objeto la forma y objeto...			
	var nomfor = forma.name + '.';
	var obj=eval(nomfor + Campo.name);			
						
	// Obtenemos el mensaje correspondiente al campo de captura
	if (obj.value == "") 
	{obj.value = 0;}	
																				
	// Quitamos comas		
	obj.value = QC(obj.value);								
	
	//alert(js_ValidaNumero(forma,Campo,"campo numérico"));															
	if (js_ValidaNumero(forma,Campo,"campo numérico")==false)
	{				
		obj.focus();		
	}			
	// Agregamos/restituimos comas														
	obj.value = formatonum(obj.value,Decimales);
}

function js_VP(forma, Campo, Decimales)
{									
	
	// Declaramos variables
	var Mensaje;
	// Asignamos al objeto la forma y objeto...			
	var nomfor = forma.name + '.';
	var obj=eval(nomfor + Campo.name);		
	
	var LimPor = 0;
	
	/*// Si es crédito tradicional...
	if (forma.Produc.value == "UDIPES")
	{	LimPor = 90	}
	else
	{	LimPor = 95	}*/
	// Establecemos porcentaje máximo
	LimPor = PorMaxCre();
	
	// Obtenemos el mensaje correspondiente al campo de captura
	if (obj.value == "") 
	{obj.value = 0;}																				
	// Quitamos comas										
	obj.value = QC(obj.value);							
	
	//alert(LimPor);
									
	if (js_ValidaNumero(forma,Campo,"campo numérico")==false)
	{
		obj.value = LimPor;
	}

	else
	{	
		// Validamos que el valor no sea mayor a 100
		if (parseFloat(obj.value) > LimPor)
		{
		   alert("El porcentaje no puede ser mayor a " + formatonum(LimPor,2));
	  	   obj.value = LimPor;
		   obj.focus();
		}  
	}			

	// Agregamos/restituimos comas												
	obj.value = formatonum(obj.value,Decimales);		
	//alert((obj.value/100));
	forma.PorCreRea.value = DN((obj.value/100));
}



function js_ValidaNumero(forma, obj,Mensaje, ValIni)
{	
	
	// Asignamos al objeto la forma y objeto...			
	var nomfor = forma.name + '.';
	var obj=eval(nomfor + obj.name);	
	
	
	// Quitamos comas									
	obj.value = QC(obj.value);
	
	if (ValIni==undefined)
	{	ValIni = 0}						

	if (trim(obj.value)==""){
	   alert("Proporciona " + Mensaje);
	   obj.value=ValIni;
	   obj.focus();
	   return 0;
	}	
	else if (isNaN(obj.value))
	{	
	   alert("Formato no válido para " + Mensaje);	   
	   obj.value=ValIni;
	   obj.focus();
	   return false;
	}	
	else if (parseInt(obj.value)<0)
	{	
	   alert("El " + Mensaje + " debe ser mayor o igual a cero");
	   obj.focus();
	   obj.value=ValIni;
	   return 0;
	}  		
}

function ResaltaCampo(objeto)
{								
	var obj=eval("TD_" + objeto);															
	obj.style.color = "BLUE"
}
	
function RestauraCampo(objeto)
{								
	var obj=eval("TD_" + objeto);										
	obj.style.color = "BLACK"	
}							

function ResaltaBoton(boton)
{	boton.style.background = "NAVY"	}

function RestauraBoton(boton)
{	boton.style.background = "#828FB6" }

function SimulaCre(forma, DirVir, ValUdi, Usuario)
{
	var Produc = forma.Produc.value;
	var oTR_TRAUDI = document.getElementById("TR_TRAUDI");
	var oTR_TRAPES = document.getElementById("TR_TRAPES");

	if (Produc == "0")
	{	
		forma.BtnCalcula.disabled = false;
		return 0	
	}
	
	if (forma.ValViv.value == "0.00")
	{	
		alert("Ingrese el valor de vivienda a cotizar");
		forma.ValViv.focus();
		//forma.BtnCalcula.disabled = false;
		return 0	
	}
	
	if (forma.BtnCalcula.value == "Calcular")
	{	
		// Si es cofinanciamiento primero calculamos el crédito a otorgar
		if (Produc == "INFCOF" || Produc == "INFCIA" || Produc == "INFGCO" || Produc == "INFCSU")
		{
			if (forma.Produc.value != "INFCIA") 
				ObtenCof(DirVir, ValUdi);
			else
				ObtenCof(DirVir, ValUdi, true);
		}	
		
		if (Produc == "SUBSID")
		{
			// Revalidamos los ingresos para ver si aplica el producto
			if (ValidaIngSub() == "1")
			{	PagoMenFon(forma, DirVir, ValUdi)	}			
		}
		
		//if (Produc == "UDIPES" || Produc == "A" || Produc == "GMAC" || Produc == "AP")
		if (Produc == "UDIPES" || Produc == "GMAC" || Produc == "APOINF" || Produc == "INFGAI" || Produc == "DEG")
		{

			
			if (forma.TipCal.value == "V")
			{	
				//Tasas(forma, DirVir, ValUdi);					
				PagoMenFon(forma, DirVir, ValUdi);				
			}
			else
			{	
				SHF_PorIng(forma, DirVir, ValUdi);	
			}
		}			
		
		if (Produc == "FOVALI" || Produc == "FOVRES" || Produc == "FOALSU")
		{						
			ObtenCofFov(forma, DirVir, ValUdi);			
		}			
		
		
		forma.BtnCalcula.value = "Recotizar"
		HabObj("Recoti", false);
	}
	else
	{		
		forma.BtnCalcula.value = "Calcular"		
		DIV_BotSHF.style.display = "none"
		
/*		DIV_CotUdi.style.display = "none"
		DIV_CotPes.style.display = "none"*/
		
		oTR_TRAUDI.style.display = "none"
		oTR_TRAPES.style.display = "none"
		
		
		DIV_DatSHF.style.display = "none"
		HabObj("Calcul", true);
		forma.ValViv.focus();
	}

//			alert("despues proceso:" + TR_ToGaCI.display);	
}

function PagoMenFon(forma,DirVir, ValUdi)
{


	if (forma.BtnCalcula.value != "Calcular")
	{					
		forma.BtnCalcula.value = "Calcular"		
		DIV_BotSHF.style.display = "none"
		/*DIV_CotUdi.style.display = "none"
		DIV_CotPes.style.display = "none"*/
		DIV_DatSHF.style.display = "none"
		HabObj("Calcul", true);
		forma.ValViv.focus();
		return 0;
	}
	
	var xmldom, strURL;
	var nomfor = forma.name + '.';
	
	var objViv = eval(nomfor + "ValViv");	
	var objCre = eval(nomfor + "MonCre");
	var objPro = eval(nomfor + "Produc");		
	
	var oTR_TRAUDI = document.getElementById("TR_TRAUDI");
	var oTR_TRAPES = document.getElementById("TR_TRAPES");
	
	/*var oTD_PL_P25 = document.getElementById("TD_PL_P25");
	var oTD_CR_P25 = document.getElementById("TD_CR_P25");
	var oTD_TI_P25 = document.getElementById("TD_TI_P25");
	var oTD_PM_P25 = document.getElementById("TD_PM_P25");
	var oTD_IR_P25 = document.getElementById("TD_IR_P25");
	var oTD_DE_P25 = document.getElementById("TD_DE_P25");	*/
	var Cad_ParExt = "";
	var Usu_Simula = forma.Usuari.value;
	var TipCre = forma.TiCrSi.value;
	var Produc = forma.Produc.value;
	var PorCre = forma.PorCre.value;
	
	var ValViv, MtoCre; 
	var FonDif = "";		
	
	if (Produc == "SUBSID")
	{
		var Ingres = 0;
		
		if (forma.SubCon.value == "N")
		{	Ingres = DN(forma.IngAcrSub.value)	}
		else
		{	Ingres = DN(forma.IngAcrSub.value) +  DN(forma.IngConSub.value)	}
		
		Cad_ParExt = forma.OriViv.value + "|" + Ingres + "|" + DN(forma.ApoAdiSub.value) + '|' 
		//alert(Cad_ParExt);ApoAdiSub
	}

	// Validamos el porcentaje de enganche
	if (Produc == "UDIPES")
	{
		if	(eval(PorCre) > 85)
			{	lblUdiAju.innerHTML = "Crédito ajustado a 85% de valor de vivienda"	}	
		else
			{	lblUdiAju.innerHTML = ""	}
		
	}
	
	// Obtenemos valor de vivienda y monto de crédito
	ValViv = QC(objViv.value)
	MtoCre = QC(objCre.value)
	
	// Ocultamos monedas y plazos
	oTR_TRAUDI.style.display = "none"
	oTR_TRAPES.style.display = "none"
	
	DetMonPLa("DE_U05","none")
	DetMonPLa("DE_U10","none")		  
	DetMonPLa("DE_U15","none")
	DetMonPLa("DE_U20","none")
	DetMonPLa("DE_U25","none")		
	DetMonPLa("DE_P05","none")
	DetMonPLa("DE_P10","none")
	DetMonPLa("DE_P15","none")
	DetMonPLa("DE_P20","none")
	DetMonPLa("DE_P25","none")
	
	TBL_COTUDI.width = 216
	TBL_COTPES.width = 216
	forma.CotUdi.value = "N"
	forma.CotPes.value = "N"	
	
		
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/PagMenPro_XML.asp";
	   strURL += "?Usuari=" + Usu_Simula + "&TipCre=" + TipCre + "&Produc=" + Produc
   	   strURL += "&ValViv=" + ValViv + "&MtoCre=" + MtoCre
	   strURL += "&ParExt=" + Cad_ParExt
	   xmldom.async = false;			   	   
	   
	   forma.CadXML.value = strURL;
	   

	   
/*	   	if (Usu_Simula == "HUNION")
	{
		alert(strURL)		
	}*/

//alert(strURL);
/*	//return 0;
alert((xmldom.load(strURL) ));*/
	 
	/*DIV_CotUdi.style.display = "none"
	DIV_CotPes.style.display = "none"*/
	DIV_MoCrPe.style.display = "none"
	DIV_MoCrUd.style.display = "none"
	DIV_InRePe.style.display = ""
	DIV_InReUd.style.display = ""
	
	/*DIV_CotUdi.style.display = "none"
	DIV_CotPes.style.display = "none"*/
	
/*
	oTD_PL_P25.style.display = "none"
	oTD_CR_P25.style.display = "none"
	oTD_TI_P25.style.display = "none"
	oTD_PM_P25.style.display = "none"
	oTD_IR_P25.style.display = "none"
	oTD_DE_P25.style.display = "none"	  
	
*/

	if (Produc == "SUBSID")
	{		
		
		DIV_MoCrUd.style.display = ""
		DIV_MoCrPe.style.display = ""

//		TD_CR_U25.style.display = ""
	}
	else
	{
		DIV_MoCrPe.style.display = "none"
		DIV_MoCrUd.style.display = "none"		
	}
	

	if (Produc == "GMAC" || Produc == "INFGAI" )	{	FonDif = "*"	}	else {	FonDif =""	}	
	
	if( xmldom.load(strURL) )
	{

		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);		
		//alert(root.childNodes.length);
		if (root.childNodes.length==0)
		{
			return 0;
		}      				
		
		// Ciclo por el total de campos			    
		for( ii = 0; ii < root.childNodes.length; ii++ )
		{	
			
			for( i = 0; i < element.childNodes.length; i++ )
			{	
				element = root.childNodes(ii)			
				// Nombre del campo
				strNombre = element.childNodes(i).nodeName
				strValor = element.childNodes(i).text;
				
				
				
				if (i==2)	
				{	strValor  = strValor + " " + FonDif	}				
			
				if(strNombre.substring(0,2) == "FO")
				{
				
					if (oTR_TRAUDI.style.display == "none" && strNombre.substring(3,4) == "U")
					{	
						oTR_TRAUDI.style.display = ""	
						forma.CotUdi.value = "S"
					}
					
					if (oTR_TRAPES.style.display == "none" && strNombre.substring(3,4) == "P")
					{	
						oTR_TRAPES.style.display = ""	
						forma.CotPes.value = "S"
					}
//					alert(oTR_TRAUDI.style.display);
					
					DetMonPLa(strNombre,"")
					
					if (strNombre.substring(3,4) == "U")
					{	TBL_COTUDI.width = eval(TBL_COTUDI.width) + 56	}
					else
					{	TBL_COTPES.width = eval(TBL_COTPES.width) + 56	}

					
				//	alert(strNombre.substring(3,6));					
					
				}
/*				alert(strNombre.substring(0,2));*/
				//return 0;
//				if (strNombre.subtring(0,2) == "FO_P25")
				
			
				/*
				if (strNombre == "FO_P25")
				{					
					oTD_PL_P25.style.display = ""
					oTD_CR_P25.style.display = ""
					oTD_TI_P25.style.display = ""
					oTD_PM_P25.style.display = ""
					oTD_IR_P25.style.display = ""
					oTD_DE_P25.style.display = ""
				}
				
				*/
				// Instanciamos al objeto de la forma con el nombre del nodo						
				obj = eval(nomfor + strNombre );
				obj.value = strValor;
			}
			//alert(TBL_COTUDI.width);
		}
	}
	
	/*	
	if (forma.Usuari.value == "URBI" || forma.Usuari.value == "HILHCM")
	{
		DetMonPLa("DE_U05","none")
		DetMonPLa("DE_U10","none")		  
		DetMonPLa("DE_U15","none")
		DetMonPLa("DE_U20","none")
		DetMonPLa("DE_P05","none")
		DetMonPLa("DE_P10","none")
		DetMonPLa("DE_P15","none")
		DetMonPLa("DE_P20","none")
		
		TBL_COTUDI.width = "280"
		TR_TRAPES.style.display = "none"		
	
	}
	*/
	
/*	DIV_CotUdi.style.display = ""
	DIV_CotPes.style.display = ""*/

	DIV_InRePe.style.display = ""
	DIV_InReUd.style.display = ""

	
	if (forma.BtnCalcula.value == "Calcular")
	{					
		forma.BtnCalcula.value = "Recotizar"
		HabObj("Recoti", false);
	}		
}

function DetMonPLa(PreMonPla, Estatus)
{
	var PlaMon = PreMonPla.substring(3,6);
	//	alert(PlaMon);

	var oTD_PL = document.getElementById("TD_PL_" + PlaMon);
	var oTD_CR = document.getElementById("TD_CR_" + PlaMon);
	var oTD_TI = document.getElementById("TD_TI_" + PlaMon);
	var oTD_PM = document.getElementById("TD_PM_" + PlaMon);
	var oTD_IR = document.getElementById("TD_IR_" + PlaMon);
	var oTD_DE = document.getElementById("TD_DE_" + PlaMon);	
	
	oTD_PL.style.display = Estatus
	oTD_CR.style.display = Estatus
	oTD_TI.style.display = Estatus
	oTD_PM.style.display = Estatus
	oTD_IR.style.display = Estatus
	oTD_DE.style.display = Estatus	  
	
	
	
	//var oTR_FoCoIn = document.getElementById("TR_FoCoIn");	
}

function Tasas(forma,DirVir, ValUdi)
{

	var xmldom, strURL;
	var ValViv, MtoCre; 
	var FacSeg = 0.0085;
	var CreUdi = 0;
	var VivUdi = 0;
	var SegUdi = 0
	var SegPes = 0
	var ComAdm = 65
	var ComCob = 0 
	var MtoCob = 0
	var OtrCos = 0
	var FapPes = 0
	var FapUdi = 0
	
	
	var TSwa_05 = 0.0131
	var TSwa_10 = 0.0246
	var TSwa_15 = 0.0347
	var TSwa_20 = 0.0435
	var TSwa_25 = 0.0500
	
	//var forma = document.frmProspecto;
	
	var nomfor = forma.name + '.';
	var objViv = eval(nomfor + "ValViv");	
	var objCre = eval(nomfor + "MonCre");
	var objPro = eval(nomfor + "Produc");				
	var objFap;
	var objInr;
	var objPup;
	var objDem;
	
	// Desplegamos valor fijo de monto de crédito
	forma.CR_U25.value = objCre.value
	forma.CR_U20.value = objCre.value
	forma.CR_U15.value = objCre.value
	forma.CR_U10.value = objCre.value
	forma.CR_U05.value = objCre.value
	
	forma.CR_P20.value = objCre.value
	forma.CR_P15.value = objCre.value
	forma.CR_P10.value = objCre.value
	forma.CR_P05.value = objCre.value		
	
	// Obtenemos valor de vivienda y monto de crédito
	ValViv = QC(objViv.value)
	MtoCre = QC(objCre.value) 	
	// Monto del seguro en pesos
	SegPes = MtoCre * parseFloat(FacSeg/12)
	
	// Calculamos el crédito en UDIS
	CreUdi  = QC(ValorUdis(MtoCre, ValUdi,'',''));
	VivUdi  = QC(ValorUdis(ValViv, ValUdi,'',''));
	SegUdi = CreUdi * parseFloat(FacSeg/12)	
	// Redondeamos a 2 decimales
	SegUdi = formatonum(SegUdi,2)			
	
	
	FapPes = FacPagIng(ValViv,"P")
	FapUdi = FacPagIng(VivUdi,"U")
	
		
	// Desplegamos mensaje en barra
	//window.status = "Obteneniendo tasas.."					    
					  					
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/TasasCal_XML.asp";
	   strURL += "?ValViv=" + ValViv + "&MtoCre=" + MtoCre + "&TipPro=" + objPro.value;
	   strURL += "&CreUdi=" + CreUdi;
	   xmldom.async = false;		

	 /* alert(strURL);			  
	  alert(xmldom.load(strURL));*/
	  //	  return 0;
	  
	
	if( xmldom.load(strURL) )
	{

		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);
		
		if (root.childNodes.length==0)
		{
			return 0;
		}      				
		
		// Ciclo por el total de campos			    
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
			//alert(strNombre + ':' + strValor);
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			if (strNombre.substring(0,2) == "PM")			
			{					
				// Desglose de mensualidad
					objDem = eval(nomfor + "DM_" + strNombre.substring(3,6));
					
				// Llenamos objetos de factor de pago e ingreso requerido..
				if (strNombre.substring(0,4) == "PM_U")
				{										
					// Pago mensual en UDIS
					//strValor = ValorUdis(strValor, ValUdi,'','');				
					//alert(strValor);
					// Componentes del pago mensual					
					//alert(strValor + "|" + ComAdm + "|" + SegUdi + "|");
					//alert(DN(strNombre.substring(4,6)) * 12);
					//alert(strValor);
					//alert(CreUdi);
					objDem.value =  strValor + "|" + ComAdm + "|" + SegUdi + "|";
					
					
					// Calculamos monto a consdirerar para cobertura				
					MtoCob = (DN(strValor) + DN(SegUdi) + ComAdm)				
					
					// Calculamos la cobetura...				
					if (strNombre == "PM_U25")
					{	ComCob  = MtoCob * TSwa_25  }
					if (strNombre == "PM_U20")
					{	ComCob  = MtoCob * TSwa_20  }
					if (strNombre == "PM_U15")
					{	ComCob  = MtoCob * TSwa_15  }
					if (strNombre == "PM_U10")
					{	ComCob  = MtoCob * TSwa_10	}
					if (strNombre == "PM_U05")				
					{	ComCob  = MtoCob * TSwa_05	}	
					
					// Redondeamos a 2 decimales					
					ComCob = formatonum(ComCob,2)																	
					
					// Calculamos el pago mensual final en UDIS
					//strValor = formatonum((DN(strValor) + SegUdi + DN(ComAdm) + DN(ComCob)),2)					
					strValor =  formatonum(DN(strValor) + DN(SegUdi) + DN(ComAdm) + DN(ComCob),2)
					
					// Desglose completo de pago mensual
					objDem.value =  objDem.value + ComCob + "|" + DN(strValor) + "|" + DN(CreUdi) + "|" 
					
					
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));					
					objFap.value= formatonum((DN(strValor) / parseFloat(CreUdi)*1000),2)	
					
					
					// Calculamos el pago mensual final en pesos
					objPup = eval(nomfor + "PP_" + strNombre.substring(3,6));
					objPup.value= formatonum((DN(strValor) * parseFloat(ValUdi)),2)
					objInr = eval(nomfor + "IR_" + strNombre.substring(3,6));									
					objInr.value= formatonum((DN(objPup.value) * FapUdi),2)																			
									
				}
				else
				{										
					// Desglose completo de pago mensual
					objDem.value =  strValor + "|0.01|" + SegPes				
					
					
					// Calculamos el pago mensual final en Pesos
					strValor = formatonum(DN(strValor) + 0.01 + SegPes,2)			
					
						
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));
					objFap.value= formatonum((DN(strValor) / parseFloat(MtoCre)*1000),2)
					objInr = eval(nomfor + "IR_" + strNombre.substring(3,6));										
					objInr.value= formatonum((DN(strValor) * FapPes),2)													
				}
			}
			// Asignamos valor a objeto..						
			obj.value = strValor;
	
		}																				
	}	
	// Convertimos a UDIS
	
	//ValorUdis(ValViv, ValUdi,forma, 'VaViUd')
	//ValorUdis(MtoCre, ValUdi,forma, 'MoCrUd')
	/*ValorUdis((parseFloat(ValViv) - parseFloat(MtoCre)),ValUdi,forma, 'MoEnUd')*/
	
	/*DIV_CotUdi.style.display = ""
	DIV_CotPes.style.display = ""*/
	DIV_MoCrPe.style.display = "none"
	DIV_MoCrUd.style.display = "none"
	DIV_InRePe.style.display = ""
	DIV_InReUd.style.display = ""
	
}

function ValorUdis(Monto, Udi,forma, Campo)
{
	
	
	if (forma.name != undefined)
	{
		var nomfor = forma.name + '.';		
		var obj=eval(nomfor + Campo);			
		// Asignamos valor en udis al objeto
		obj.value = formatonum((parseFloat(Monto) / parseFloat(Udi)),2)
	}
	else
	{
		/*alert(QC(Monto));
		alert(Udi);
		alert(formatonum((parseFloat(QC(Monto)) / parseFloat(Udi)),2));*/
		
		return formatonum((parseFloat(QC(Monto)) / parseFloat(Udi)),2)
		
	}
	
}		

function DatosInf(NSS, forma, DirVir)
{
	// Limpiamos objetos ...
	forma.Nombre.value = ""
	forma.SucViv.value = ""
	forma.DeCrIn.value = ""		
	
	if (NSS.length != 0)
	{
		if (NSS.length != 11)
		{	
			alert("Numero de seguro social es de 11 digitos, favor de verificarlo")	
			return 0;
		}
	}
	else
	{	return 0;	}	
	if(isNaN(NSS)) return;
	
	//alert(NSS.length);
	lbl_BusInf.innerHTML  = '<img src="Images/pg.gif" title="Buscando datos"/>&nbsp;&nbsp;Obteniendo datos de INFONAVIT';
	//alert("ConectaInf('" + NSS + "', '" + DirVir + "'):
	//alert("ConectaInf(\"" + NSS + "\", \"" + DirVir + "\")");
	setTimeout("ConectaInf(\"" + NSS + "\", \"" + DirVir + "\")",500)
}

function DatosFOV(CURP, forma, DirVir)
{
	// Limpiamos objetos ...
/*	forma.Nombre.value = ""
	forma.SucViv.value = ""
	forma.DeCrIn.value = ""		
	*/
	if (CURP.length != 0)
	{
		if (CURP.length != 18)
		{	
			alert("La CURP es de 18 caracteres, favor de verificarlo")	
			return 0;
		}
	}
	else
	{	return 0;	}	
	
	// Desplegamos datos para la conexión..
	lbl_BusInf.innerHTML  = '<img src="Images/pg.gif" title="Buscando datos"/>&nbsp;&nbsp;Obteniendo datos de FOVISSSTE';
	// Obtenemos datos de la conexión..
//	alert("Obtnemos datos de la curp del fovi");
	setTimeout("ConectaFov(\"" + CURP + "\", \"" + DirVir + "\")",500)
}
// Desplegamos mensaje en barra
//window.status = "Obteneniendo tasas.."					    

function ConectaInf(NSS, DirVir)
{	
	var forma = document.frmCalcula;
	
	var xmldom, strURL;		
	var nomfor = forma.name + '.';
	var CreCof = "";
	var bIngAdi = false;
	var vProduc = forma.Produc.value;	
	
	var NssAcr = "";
	var NssCon = "";
	
	// Obtenemos el NSS del acreditado principal
	NssAcr = forma.NSSCof.value
	// Obtenemos el NSS del conyuge
	if ((vProduc == "INFCOF" || vProduc == "INFGCO") && forma.CofCon.value == "S")
	{	
		NssCon = forma.NSSCon.value					
	}
	
	//alert(vProduc);
	
	switch(vProduc) {
		case "INFCIA":
			bIngAdi = true;
		case "APOINF": 
			CreCof = "N";
			break;
		default:
			CreCof = "S";
	}
	
	
	DIV_AHOINF.style.display = "none"		
	
	
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/DatInf_XML.asp";	   
	   strURL += "?NuSeSo=" + NssAcr + "&Cofina=" + CreCof + "&NSSCon=" + NssCon
	   if (bIngAdi) strURL += "&IngAdi=S";
	   xmldom.async = false;		
	   
	//  alert(strURL);
	   //return 0;
	  
	 if( xmldom.load(strURL) )
	{

		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);				
		
		if (root.childNodes.length==0)
		{	return 0;	}
		
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
			//alert(strNombre + ':' + strValor);
			
			if (strNombre == "E")
			{	
				alert(strValor + ", \n no se puede continuar con la simulación");
				lbl_BusInf.innerHTML  = "";	
				return 0;
			}
			if (strNombre == "VI")
			{	
			 
				alert(strValor + " \nPuede optar por la opción del producto Apoyo Infonavit, por lo no se puede continuar con la simulación solicitada");				
				lbl_BusInf.innerHTML  = "";	
				return 0;
			}
			
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			obj.value = strValor;			
		}				

		if ((CreCof == "S" || bIngAdi == true) && parseInt(DN(forma.AhoInf.value)) != "0")
		{
			DIV_AHOINF.style.display = ""		
			
			
			//alert("Para hacer valido su crédito por parte de INFONAVIT debe cubrir la cantidad de "  + forma.AhoInf.value);
			LBL_AhoInf.innerHTML  = "Para hacer valido su crédito por parte de INFONAVIT debe " + "<br>" + 
									"cubrir la cantidad de $"  + forma.AhoInf.value + " ya que no cuenta con la " + "<br>" + 
									"puntuación mínima requerida, el resultado de la cotización " + "<br>" + 
									"se hace considerando que el trabajador realize la aplicación del " + "<br>" + 
									"importe indicado ante el INFONAVIT "
			
		}			
		
		
		// Habilitamos objeto de calculo
		forma.BtnCalcula.disabled = false;
		if (bIngAdi) {
			var DesMenINF=0;
			var vDeMeIn=QC(forma.DeMeIN.value);
			
			//var vTope=(50.57)*(30.4) // Salario Mínimo Diario DF * Dias del Mes
			var vTope= DN(forma.SaMiMe.value)	
			
			
			//var vTopeDiario=(50.57)*3.9;
			var vTopeDiario=(DN(DN(forma.SaMiMe.value)/30.4))*3.9;
			//window.status = NSS
			
			
			if (!isNaN(vDeMeIn)) DesMenINF = parseFloat(vDeMeIn);
			//alert("bIngAdi: " + bIngAdi + "\nvDeMeIn: "+vDeMeIn+"\nvTope: "+vTope);
			/*
			if (NSS == "42967500747")
			{
				alert(DesMenINF);	alert(vTope);
			}
			*/
			/*
			alert(DesMenINF);
			alert(vTope);*/
			if (DesMenINF>vTope) {
				if (NSS != "09038221272")	{
				var sNom=forma.Nombre.value;
				var sMsg="MENSAJE DEL SISTEMA\n\n"
				sMsg+="_______________________________________________________\n";
				sMsg+="No califica para COFINANCIAMIENTO CON INGRESOS ADICIONALES\n";
				sMsg+="_______________________________________________________\n\n";
				sMsg+="Motivo:\n";
				sMsg+=sNom.toUpperCase()+" con número de seguro social '"+NSS+"'\n";
				sMsg+="percibe un salario diario integrado superior a los " + formatonum(vTopeDiario,2) +".\n\n";
				forma.BtnCalcula.disabled = true;
				alert(sMsg);
				}
			}
		} 
	} else {
		var sMsg="MENSAJE DEL SISTEMA\n\n"
		sMsg+="______________________________________________\n";
		sMsg+="NO SE PUEDE REALIZAR UNA SIMULACIÓN DEL CRÉDITO\n";
		sMsg+="______________________________________________\n\n";
		sMsg+="Motivo:\n";
		sMsg+="El número de seguro social '"+NSS+"'\n";
		sMsg+="no se encuentra registrado ante el INFONAVIT.\n\n";
		alert(sMsg);
	}	
	lbl_BusInf.innerHTML  = "";
}

function ConectaFov(NSS, DirVir)
{	
	var forma = document.frmCalcula;
	
	var xmldom, strURL;		
	var nomfor = forma.name + '.';
	var vProduc = forma.Produc.value;	
	
	var CURP_Acr = "";
	var CURP_Con = "";
	var Pro_WS = "";
	var ValErr = ""
	var CadCon = "";
	
	// Habilitamos objeto de calculo
	forma.BtnCalcula.disabled = true;
	
	// Obtenemos la CURP del acreditado principal
	CURP_Acr = forma.CFCURP.value
	
	// Si la longitud no es de 18 de caracteres
	if (CURP_Acr.length != "18")	{	return 0	}

	// Si es cofi conyugal	
	if (forma.FovCon.value == "S")
	{
		// Obtenemos la CURP del coacreditado
		CURP_Coa = forma.CURPCoa.value
		CadCon = "&Conyug=S&CURP_Coa=" + CURP_Coa
	}
	
	// Obtenemos clave de producto valida para el Web Service 
	if (vProduc == "FOVALI"){	Pro_WS = "ALIA2"	}
	if (vProduc == "FOVRES"){	Pro_WS = "RESPA"	}	

	//alert(vProduc);	
	
	DIV_AHOINF.style.display = "none"		
	
	
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/DatFov_XML.asp";	   
	   strURL += "?CURP_Acr=" + CURP_Acr + "&ProFov=" + Pro_WS
	   strURL += CadCon
	   xmldom.async = false;		
	   
//  alert(strURL);
	  // return 0;
	  
	 if( xmldom.load(strURL) )
	{

		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);				
		
		if (root.childNodes.length==0)
		{	return 0;	}
		
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
	//		alert(strNombre + ':' + strValor);
	
			// Verificamos si existio algun error
/*			if (strValor == "0")
			{	ValErr = strValor	}			*/
		
			// Si se regresa un mensaje de error
			if (strNombre == "MensajeError" && strValor != "")
			{	
				alert(strValor + ", \n no se puede continuar con la simulación");				
				lbl_BusInf.innerHTML  = "";	
				return 0;
			}			
		
			// Si es el monto de crédito FOVISSSTE del acreditado
			if (strNombre == "CapacidadTablas")
			{	forma.CrFoAc.value = formatonum(strValor,2)		}
			
			// Si es el monto de la subcuenta de vivienda del acreditado
			if (strNombre == "SoloSaldoSar")
			{	forma.SuViAc.value = formatonum(strValor,2)		}
			
			// Si es el monto de crédito FOVISSSTE del acreditado
			if (strNombre == "CapacidadTablasC")
			{	forma.CrFoCo.value = formatonum(strValor,2)		}
			
			// Si es el monto de la subcuenta de vivienda del acreditado
			if (strNombre == "SoloSaldoSarC")
			{	forma.SuViCo.value = formatonum(strValor,2)		}			
		
		}						
	}	
	//alert(forma.DFCrFo.value)
//	alert(forma.DFSuVi.value)
	lbl_BusInf.innerHTML  = "";
	forma.BtnCalcula.disabled = false;
		
	// Si es un crédito Respaldado el monto de crédito fovissste es cero
	if (Pro_WS == "RESPA")
	{	
		forma.CrFoAc.value = 0.00
		forma.CrFoCo.value = 0.00
	}
}


function DN(Monto)
{
	return parseFloat(QC(Monto))
}

function FacPagIng(Viv, Mon)
{
	var VecMen = 0;
	var Param = "";
	var Valor = ""
	var	ValTop = 0, FacPon = 0
	
	if (Mon == "U")
	{
		// Validamos primer rango de vivienda hasta 115,000 udis factor de 4 a 1 ingreso sobre pago
		Param = "115000.00|4.00|"
		Valor = Param.split("|");		// Armamos arreglo			
		ValTop = Valor[0], FacPon = Valor[1]		// Obtenemos elementos			
		// Si la vivienda es menor igual al valor tope, asingamos factor
		if (DN(Viv) <= DN(ValTop))
		{	return FacPon	} 
		else
		{	
			// Validamos segundo rango de vivienda hasta 300,000 udis factor de 3.33 a 1 ingreso sobre pago
			Param = "300000.00|3.33|"
			Valor = Param.split("|");		// Armamos arreglo			
			ValTop = Valor[0], FacPon = Valor[1]		// Obtenemos elementos			
			
			// Si la vivienda es menor igual al valor tope, asingamos factor	
			if (DN(Viv) <= DN(ValTop))
			{	return FacPon	}		
			else
			{	return 3.03		} // Factor para viviendas arriba de 300,000 udis
		}
		
	}
	else
	{
		return 3.03
	}
	
}
	
function CosAva()
{	
	var ValViv = DN(forma.ValViv.value);
	
	// Calculamos valor del avaluo en base a la vivienda
	if (ValViv < 280000)
	{	return (800 * 1.15)	}
	else
	{	return (((ValViv * 2.5) /1000)+100) * 1.15	}	
	
}
	
function ComApe(MtoCre, ComApe)
{		
/*	var Produc = forma.Produc.value;		
	var ComTra = DN(forma.CoApTr.value) / 100;
	var ComOtr = DN(forma.CoApNt.value) / 100;	
	*/

	return (MtoCre * (ComApe/100))
	// Calculamos la comisión de apertura
	// Si es apoyo infonavit
/*	if (Produc == "A")
	{	return (MtoCre * ComOtr)	}
	else
	{	return (MtoCre * ComTra)	}	*/	
}

function CalculaCof()
{
	var CreIni = 0;
	var ValViv = DN(forma.ValViv.value);
	var CreInf = DN(forma.DeCrIn.value);
	var CosTot = 0;
	var CreTot = DN(forma.CreTot.value);
	var GasInf = 0;
	var ApoAdi = 0;	
	var ApoObl = 0;	
	var CosTot = 0;
	var CreHCM = 0;
	
	// Calculamos el crédito inicial en base al valor
	// de vivienda y crédito infonavit..
	CreIni  = ValViv - CreInf - (ValViv * 0.1)
	// Calculamos los gastos de infonavit
	GasInf = DN(formatonum((CreTot * 0.05),2))
	// Calculamos el costo total
	CosTot = ValViv + GasInf 	
	// Calculamos aportación obligatoria
	ApoObl = (CosTot -(CreIni + CreTot))
	// Si la aportación es menor a cero la igualamos a cero
	if (ApoObl < 0)	{	ApoObl = 0	}
	
	//forma.CO_ApoIni.ApoObl.value = formatonum(ApoObl,2);
	
	// Calculamos el crédito de casa mexicana
	CreHCM  = CosTot - CreTot - ApoAdi - ApoObl 	
	
	//alert(forma.MonCre.value);
	
	forma.MonCre.value = formatonum(CreHCM,2);
	//alert(forma.MonCre.value);
	
	
	
	/*
	alert(ValViv);
	alert(CreInf);
	//alert(forma.MonCre.value);
	alert(CreIni);
	alert(GasInf);
	alert(CosTot);
	alert(CreIni + CreTot);
	alert(CosTot -(CreIni + CreTot));*/
	//alert(CreHCM);	
}

function ResaltaBoton(boton)
{	boton.style.background = "NAVY"	}

function RestauraBoton(boton)
{	boton.style.background = "#828FB6" }

//function TotalCar(NSS)
function TotalCar(TipCof, Dato)
{
	// Si es cofinanciamiento INFONAVIT
	if (TipCof == "I")
	{
		if (Dato.length != "11" && Dato.length != "0")
		{
			alert("Ha capturado un número de " + Dato.length + " digitos, para realizar la búsqueda se requieren los 11 números del seguro social");
			return 0;
		}
	}

	// Si es cofinanciamiento FOVISSSTE
	if (TipCof == "F")
	{
		if (Dato.length != "18" && Dato.length != "0")
		{
			alert("Ha capturado una CURP de " + Dato.length + " caracteres, para realizar la búsqueda se requieren los 18 caracteres que conforman la CURP");
			return 0;
		}
	}		
}

function TotCarNSS(NSS, forma, DirVir)
{	
	// Verificamos que tenga 11 caracteres..
	if (NSS.length == "11")
	{
		var bSolINF=false;
		if (document.all) {
			if (event.ctrlKey && event.keyCode==86) {
				//alert("Ctrl + V");
				bSolINF=true;
			} else {
				bSolINF=true;
				var lEvtKeyCod = event.keyCode;
				if (lEvtKeyCod<48 || lEvtKeyCod>57) { 
					if (lEvtKeyCod<96 || lEvtKeyCod>106) bSolINF=false;
				}
				//if (!bSolINF) alert(String.fromCharCode(lEvtKeyCod) + " : " + lEvtKeyCod);
			}
		} else
			bSolINF=true;
			
		if (bSolINF) DatosInf(NSS, forma, DirVir);
	}
	else
	{
		// Deshabilitamos botón para hacer calculo		
		forma.BtnCalcula.disabled = true;
	}
}

function TotCarCURP(CURP, forma, DirVir)
{	
	// Verificamos que tenga 11 caracteres..
	if (CURP.length == "18")
	{/*s
		var bSolFOV=false;
		if (document.all) 
		{
			if (event.ctrlKey && event.keyCode==86) 
			{	bSolFOV=true;	}
		} 
		else
		{	bSolFOV=true;		}*/
		bSolFOV=true;	
		//alert(CURP);
		if (bSolFOV) DatosFOV(CURP, forma, DirVir);
		// Habilitamos botón para hacer calculo		
		forma.BtnCalcula.disabled = false;
	}
	else
	{
		// Deshabilitamos botón para hacer calculo		
		forma.BtnCalcula.disabled = true;
	}
}

function ActivaCofCon(CofCon)
{

	var oTR_NSSCon = document.getElementById("TR_NSSCon");
	var oTR_IngCon = document.getElementById("TR_IngCon");	
	var oTR_DeNoCo = document.getElementById("TR_DeNoCo");	
	var oTR_DeNSCo = document.getElementById("TR_DeNSCo");	
	var oTR_DeSuCo = document.getElementById("TR_DeSuCo");	
	
	// Si es cofi conyugal	
	if (CofCon == "S")
	{
		oTR_NSSCon.style.display = ""
		oTR_IngCon.style.display = ""
		oTR_DeNoCo.style.display = ""
		oTR_DeNSCo.style.display = ""
		oTR_DeSuCo.style.display = ""
	}
	else
	{
		oTR_NSSCon.style.display = "none"
		oTR_IngCon.style.display = "none"
		oTR_DeNoCo.style.display = "none"
		oTR_DeNSCo.style.display = "none"
		oTR_DeSuCo.style.display = "none"		
		forma.NSSCof.value = "";
		forma.NSSCon.value = "";
		forma.BtnCalcula.disabled = true;
	}
	
}

function ActivaSubCon(FovCon)
{	
	var oTR_IngConSub = document.getElementById("TR_IngConSub");
	
	
	// Si es cofi conyugal	
	if (FovCon == "S")
	{	
		oTR_IngConSub.style.display = ""
	}
	else
	{
		oTR_IngConSub.style.display = "none"
	}

}


function ActivaFovCon(FovCon)
{	
	var oTR_CFCOIn = document.getElementById("TR_CFCOIn");	
	var oTR_CFCOSB = document.getElementById("TR_CFCOSB");	
	var oTR_CURCOA = document.getElementById("TR_CURCOA");	
	var oTR_CFBuCo = document.getElementById("TR_CFBuCo");		

	var oTR_CURPCo = document.getElementById("TR_CURPCo");	
	
	var oTR_DFInCo = document.getElementById("TR_DFInCo");	
	var oTR_DFSBCo = document.getElementById("TR_DFSBCo");	
	var oTR_DeMFCo = document.getElementById("TR_FoDeMFCo");	

	
	var oTD_DeCFCF = document.getElementById("TD_DeCFCF");
	var oTD_DeCFSu = document.getElementById("TD_DeCFSu");
	var oTD_DeCFBu = document.getElementById("TD_DeCFBu");
	
	var oTR_AjCoCF = document.getElementById("TR_AjCoCF");
	var oTR_AjCoSV = document.getElementById("TR_AjCoSV");		
	
	var TiCrFo = forma.Produc.value;
	
	// Si es cofi conyugal	
	if (FovCon == "S")
	{
		oTR_CFCOIn.style.display = ""
		oTR_CFCOSB.style.display = ""
		//oTR_CFCOSv.style.display = ""		
		oTR_DFInCo.style.display = ""		
		oTR_CURCOA.style.display = ""
		oTR_CFBuCo.style.display = ""
		oTR_DeMFCo.style.display = ""
		oTR_CURPCo.style.display = ""
		oTR_DFSBCo.style.display = ""
		if (TiCrFo == "FOVALI")	//	Solo si es aliado pedimos salario base del conyuge
		{	
			oTR_CFCOSB.style.display = ""
			oTR_DFSBCo.style.display = ""
		}else	{	
			oTR_CFCOSB.style.display = "none"	
			oTR_DFSBCo.style.display = "none"		
		}		
			
		oTD_DeCFCF.innerHTML = "Crédito con FOVISSSTE Conyugal:"				
		oTD_DeCFSu.innerHTML  = "Saldo de la subcuenta Conyugal:"
		oTD_DeCFBu.innerHTML  = "Buró de crédito Conyugal:"
	}
	else
	{		
		oTR_CFCOIn.style.display = "none"
		oTR_CFCOSB.style.display = "none"
		oTR_CURCOA.style.display = "none"
		oTR_CFBuCo.style.display = "none"		
		oTR_DeMFCo.style.display = "none"
		oTR_CURPCo.style.display = "none"
		//oTR_CFCOSv.style.display = "none"
		oTR_DFInCo.style.display = "none"			
		oTR_DFSBCo.style.display = "none"	
		
		oTR_AjCoCF.style.display = "none"
		oTR_AjCoSV.style.display = "none"
		forma.AjCoCF.value = "0.00"
		forma.AjCoSV.value = "0.00"
			
		oTD_DeCFCF.innerHTML  = "Crédito con FOVISSSTE:"		
		oTD_DeCFSu.innerHTML  = "Saldo de la subcuenta:"
		oTD_DeCFBu.innerHTML  = "Buró de crédito:"
		//forma.BtnCalcula.disabled = true;
	}	
}

function CamposInf(Campo, Valor)
{	
	// Copiamos nombre al detalle	
	if (Campo.name == "NombSC")
	{	forma.Nombre.value = Valor	}
	// Copiamos NSS al detalle
	if (Campo.name == "NSSCof")
	{	forma.DeNuSS.value = Valor	}
	// Copiamos importe de crédito infonavit al detalle
	if (Campo.name == "CrInSC")
	{	forma.DeCrIn.value = Valor	}
	// Copiamos importe de la subcuenta de vivienda al detalle
	if (Campo.name == "SuViSC")
	{	
		forma.SucViv.value = Valor	
		forma.DeSuVi.value = Valor	
	}
	// Copiamos descuento mensual de infonavit
	if (Campo.name == "DeInSC")
	{	forma.DeMeIN.value = Valor	}
	
	forma.BtnCalcula.disabled = false;
}

function ObtenCof(DirVir, ValUdi, bIngAdi)
{
	if (bIngAdi==undefined) bIngAdi = false;
	var xmldom, strURL;		
	var nomfor = forma.name + '.';
	var CreCof = "";
	var ValUdi = forma.ValUdi.value
	
	var Ingres = DN(forma.Ingres.value)
	var IngPro = DN(forma.IngPro.value)
	var IngCon = DN(forma.IngCon.value)		
	
	var oTD_CofTit = document.getElementById("TD_CofTit");
	var oTD_CreInf = document.getElementById("TD_CreInf");
	var oTD_SubViv = document.getElementById("TD_SubViv");

	
	// Incrementamos a ingresos las propinas
	if (bIngAdi == true)
	{	Ingres = Ingres + IngPro	}
	
	var oTR_LeySCInf = document.getElementById("TR_LeySCInf");
	
	var oTR_GaOrIn = document.getElementById("TR_GaOrIn");
	var oTR_GaCoIn = document.getElementById("TR_GaCoIn");
	var oTR_GaCMCo = document.getElementById("TR_GaCMCo");
	var oTR_GaInCo = document.getElementById("TR_GaInCo");
	var oTR_GaEsCo = document.getElementById("TR_GaEsCo");
	
	var oTR_EsCoNo = document.getElementById("TR_EsCoNo");
	
	var oTR_MtSuIn = document.getElementById("TR_MtSuIn");
	var oTR_GaFiSu = document.getElementById("TR_GaFiSu");
	
	var oTR_ToGaCI = document.getElementById("TR_ToGaCI");
	
	//alert(oTR_LeySCInf.style.display);
	
	// Limpiamos cuadros de 11 VSM si es simulador sin conexion	
	if (oTR_LeySCInf.style.display == "")
	{		
		forma.CofAGA.value = "N"
		forma.CofAGC.value = "N"
		// Ocultamos leyenda de ingresos ya que no contamos con el dato		
		lblIngAcr.innerHTML = ""
	}
	
	// Incrementamos a ingresos las propinas
	if (forma.CofCon.value == "S")
	{			
		// Los ingresos son la suma del principal y el conyuge		
		Ingres = Ingres + IngCon	
		// Modificamos leyendas		
		oTD_CofTit.innerHTML  = "COFINANCIAMIENTO CONYUGAL"	
		oTD_CreInf.innerHTML  = "Crédito con INFONAVIT Conyugal:"	
		oTD_SubViv.innerHTML  = "Saldo de la subcuenta Conyugal:"
		forma.NuSSCon.value = forma.NSSCon.value
		forma.SueCon.value = forma.IngCon.value
	}
	else
	{		 
		oTD_CofTit.innerHTML  = "COFINANCIAMIENTO SHF" 
		if (forma.Produc.value == "INFCSU")	{	oTD_CofTit.innerHTML  = "COFINANCIAMIENTO SHF CON SUBSIDIO" 	}
		oTD_CreInf.innerHTML  = "Crédito con INFONAVIT:"	
		oTD_SubViv.innerHTML  = "Saldo de la subcuenta:"
	}
	
	
	var ValViv = DN(forma.ValViv.value)
	var PlaCre = forma.PlaCre.value
	var Moneda = forma.TipCre.value
	var HonNot = forma.HonNot.value
//	var ImpGan = forma.ImpGan.value
	var ImpGan = DN(forma.ImpGan.value)	
	var IncEst = forma.chkEst.checked;
	var IncAva = forma.chkAva.checked;		
	var Usuari = forma.Usuari.value;
	var ApoAdi = DN(forma.ApoAdi.value);
	var ImpDer = DN(forma.ImpDer.value);
	
	var oTR_Ley11S = document.getElementById("TR_Ley11S");
	var oTR_DeInIn = document.getElementById("TR_DeInIn");	
	var oTR_AjDeAc = document.getElementById("TR_AjDeAc");	
	var oTR_TiAcCo = document.getElementById("TR_TiAcCo");	
	var oTR_SuViRC = document.getElementById("TR_SuViRC");	
	var oTR_CrInRC = document.getElementById("TR_CrInRC");		
	var oTR_DeMeIC = document.getElementById("TR_DeMeIC");
	
	
	
	// Igualamos valores
	forma.DeNuSS.value  = forma.NSSCof.value
	forma.DIAjAc.value  = ""
	forma.DMICAC.value  = ""
	oTR_AjDeAc.style.display = "none"
	oTR_TiAcCo.style.display = "none"
	oTR_SuViRC.style.display = "none"
	// Desplegamos campos de cofinanciamiento normales	
	oTR_GaOrIn.style.display = ""
	oTR_GaCoIn.style.display = ""
	oTR_GaCMCo.style.display = ""
	oTR_GaInCo.style.display = ""
	oTR_GaEsCo.style.display = ""
	oTR_ToGaCI.style.display = ""
	oTR_EsCoNo.style.display = ""
	// Ocultamos campos de cofinanciamiento con subsidios
	oTR_MtSuIn.style.display = "none"
	oTR_GaFiSu.style.display = "none"
	
	// Si es cofinanciamiento infonavit con subsidios
	if (forma.Produc.value == "INFCSU")	
	{	
		// Ocultamos campos de cofinanciamiento normales
		oTR_GaOrIn.style.display = "none"
		oTR_GaCoIn.style.display = "none"
		oTR_GaCMCo.style.display = "none"
		oTR_GaInCo.style.display = "none"
		oTR_GaEsCo.style.display = "none"
		oTR_ToGaCI.style.display = "none"
		oTR_EsCoNo.style.display = "none"
		// Desplegamos campos de cofinanciamientos con subsidios
		oTR_MtSuIn.style.display = ""
		oTR_GaFiSu.style.display = ""
	}

	
	oTR_DeMeIC.style.display  = (forma.CofCon.value=="S") ? "" : "none";
		
	
	// Si es ingresos adicionales...
	if (bIngAdi == true)
	{
		forma.DeInNe.value  = forma.Ingres.value + " + " + forma.IngPro.value + " de propinas"
		oTR_Ley11S.style.display = "none"
		oTR_DeInIn.style.display = "none"
		HabCof_11VSM("none")
	}
	else
	{		
		forma.DeInNe.value  = forma.Ingres.value
	
		
//		oTR_Ley11S.style.display  = (forma.CofCon.value=="S") ? "" : "none";
		oTR_Ley11S.style.display = ""


		// Si es diferente de N la bandera de COFINAVIT AG es un acreditado con ingresos mayores a 11 VSM
		if (forma.CofAGA.value != "N")
		{			
		//	alert("CREDITO MAYOR A 11 VSM")
			lblIngAcr.innerHTML = "Ingresos registrados en INFONAVIT mayores a 11 VSM"
			HabCof_11VSM("")
			//oTR_Ley11S.style.display = ""
			// Obtenemos valores de la cadena
		//	alert(forma.CofAGA.value);
			var ValOpe5 = DN(ValViv) * 0.05
			var aCofAGA = forma.CofAGA.value.split("|")
			var SubVivA = DN(aCofAGA[0]);			
			
			// Dibujamos valores en campos
			forma.SuCaIn.value = formatonum(aCofAGA[0],2)	// Subcuenta de vivienda calculada por infonavit
			forma.CiPoVi.value = formatonum(ValOpe5,2)		// 5 % sobre el valor de la vivienda
			forma.ToSuCo.value = formatonum(aCofAGA[2],2)	// Dibujamos el monto total de subcuenta
			forma.MoCrIn.value = formatonum(aCofAGA[3],2)	// Monto de crédito Infonavit calculado por infonavit
			
			oTD_CreInf.innerHTML  = "Crédito con INFONAVIT (C):"	
			oTD_SubViv.innerHTML  = "Saldo de la subcuenta (Z):"
			forma.SiCoSu.value = "(Z) "  
			forma.SiSuCo.value = "";		
			forma.SiCoCr.value = "(C) "
			forma.SiCrIn.value = "";
			
			// Si el valor de vivienda al 5% es menor a la subcuenta de vivienda
			// Determinamos subcuenta de vivienda a considerar y remanente contra el total
			if (ValOpe5 < aCofAGA[0])
			{	//alert("si modifica");	
				forma.SucViv.value = formatonum(ValOpe5,2)
				forma.DeSuVi.value = formatonum(ValOpe5,2)
				forma.SuViRe.value = formatonum(ValOpe5,2)
				forma.ReSuCo.value = formatonum((DN(aCofAGA[2]) - DN(ValOpe5)),2)	
			}
			else
			{	//alert("no modifica");	
			
				forma.SucViv.value = formatonum(aCofAGA[0],2)
				forma.DeSuVi.value = formatonum(aCofAGA[0],2)
				forma.SuViRe.value = formatonum(aCofAGA[0],2)
				forma.ReSuCo.value = formatonum((DN(aCofAGA[2]) - DN(aCofAGA[0])),2)	
			}
			
			// Calculamos 2.8 veces la subcuenta de vivienda
			forma.NuVeSu.value = formatonum((DN(forma.DeSuVi.value) * 2.8),2)	
			
			// Si 2.8 veces la subcuenta de vivienda es menor al crédito infonavit
			// Actualizamos el monto de crédito infonavit a considerar en los calculos
			if (DN(forma.NuVeSu.value) < DN(aCofAGA[3]))
			{	//alert("si modifica");	
				forma.CreTot.value = forma.NuVeSu.value
				forma.DeCrIn.value = forma.NuVeSu.value
				forma.CrInRe.value = forma.NuVeSu.value
				// Recalculamos el pago mensual aproximado del infonavit
				var FacCalInf = DN(aCofAGA[4]) / DN(aCofAGA[3])	//	Obtenemos factor para prorratear el total del pago
				forma.DeMeIN.value = formatonum((DN(forma.NuVeSu.value) * DN(FacCalInf)),2)
				forma.DIAjAc.value = "(&)"
				oTR_AjDeAc.style.display = ""
/*								alert(FacCalInf)
				alert(forma.NuVeSu.value)*/
				// Calculamos el pago mensual aproximado
			}
			else
			{	//alert("no modifica");				
				forma.CreTot.value = formatonum(aCofAGA[3],2)	
				forma.DeCrIn.value = formatonum(aCofAGA[3],2)	
				forma.CrInRe.value = formatonum(aCofAGA[3],2)	
				forma.DeMeIN.value = formatonum(aCofAGA[4],2)	
			}

			oTR_DeInIn.style.display = ""
			
			// Si es cofinanciamiento conyugal
			if (forma.CofCon.value == "S")
			{	
				var aCofAGC = forma.CofAGC.value.split("|")
				// Dibujamos valores en campos
				forma.SuCICo.value = formatonum(aCofAGC[0],2)	// Subcuenta de vivienda calculada por infonavit
				forma.CiPoVC.value = formatonum(ValOpe5,2)		// 5 % sobre el valor de la vivienda
				forma.ToSuCC.value = formatonum(aCofAGC[2],2)	// Dibujamos el monto total de subcuenta
				forma.MoCrCo.value = formatonum(aCofAGC[3],2)	// Monto de crédito Infonavit calculado por infonavit
				
				oTR_TiAcCo.style.display = "";
				oTR_SuViRC.style.display = "";
				oTR_CrInRC.style.display = "";
				oTD_CreInf.innerHTML  = "Crédito con INFONAVIT Conyugal (C):"	
				oTD_SubViv.innerHTML  = "Saldo de la subcuenta Conyugal (Z):"
				forma.SiCoSu.value = "+ "
				forma.SiSuCo.value = "(Z)  ";
				forma.SiCoCr.value = "+ "
				forma.SiCrIn.value = "(C) ";
				
				/*alert(forma.DeSuVi.value);
				alert(aCofAGC[0]);
				alert(ValOpe5);*/
				
				// Si el valor de vivienda al 5% es menor a la subcuenta de vivienda del conyuge
				// Determinamos subcuenta de vivienda a considerar y remanente contra el total
				if (ValOpe5 < aCofAGC[0])
				{	//alert("si modifica");	
					/*alert(forma.DeSuVi.value);
					alert(ValOpe5);*/
					

					forma.SuViRC.value = formatonum(ValOpe5,2)
					forma.ReSvCo.value = formatonum((DN(aCofAGC[2]) - DN(ValOpe5)),2)	 
				}
				else
				{	//alert("no modifica");	
					/*alert(forma.DeSuVi.value);
					alert(aCofAGC[0]);*/

					
					forma.SuViRC.value = formatonum(aCofAGC[0],2)
					forma.ReSvCo.value = formatonum((DN(aCofAGC[2]) - DN(aCofAGC[0])),2)	
				}
				
				
				forma.SucViv.value = formatonum((DN(forma.SucViv.value) + DN(forma.SuViRC.value)),2)
				forma.DeSuVi.value = formatonum((DN(forma.DeSuVi.value) + DN(forma.SuViRC.value)),2)
				
/*				
				forma.SucViv.value = formatonum((DN(forma.SucViv.value) + DN(aCofAGA[0])),2)
				forma.DeSuVi.value = formatonum((DN(forma.SucViv.value) + DN(aCofAGA[0])),2)		*/
				
				// Calculamos 2.8 veces la subcuenta de vivienda
				forma.NVSuCo.value = formatonum((DN(forma.SuViRC.value) * 2.8),2)	
				oTR_DeMeIC.style.display = "none";
				
				// Si 2.8 veces la subcuenta de vivienda es menor al crédito infonavit
				// Actualizamos el monto de crédito infonavit a considerar en los calculos
				if (DN(forma.NVSuCo.value) < DN(aCofAGC[3]))
				{//	alert("si modifica cre cof");	
					forma.CreTot.value = formatonum((DN(forma.CreTot.value) + DN(forma.NVSuCo.value)),2)
					forma.DeCrIn.value = formatonum((DN(forma.DeCrIn.value) + DN(forma.NVSuCo.value)),2)
					forma.CrInRC.value = formatonum(DN(forma.NVSuCo.value),2)
					
					// Recalculamos el pago mensual aproximado del infonavit
					var FaCaInCo = DN(aCofAGC[4]) / DN(aCofAGC[3])	//	Obtenemos factor para prorratear el total del pago
					forma.DMICAC.value = formatonum((DN(forma.NVSuCo.value) * DN(FaCaInCo)),2)
					forma.DIAjCo.value = "(&)"
					/*oTR_AjDeAc.style.display = ""
	//								alert(FacCalInf)
					alert(forma.NuVeSu.value)*/
					// Calculamos el pago mensual aproximado
				}
				else
				{	
					//alert("no modifica cre cof");	
					forma.CreTot.value = formatonum((DN(forma.CreTot.value) + DN(aCofAGC[3])),2)	
					forma.DeCrIn.value = formatonum((DN(forma.DeCrIn.value) + DN(aCofAGC[3])),2)	
					forma.CrInRC.value = formatonum(aCofAGC[3],2)	
					forma.DeMeIC.value = formatonum(aCofAGC[4],2)	
					forma.DMICAC.value = formatonum(aCofAGC[4],2)
					forma.DIAjCo.value = ""
				}
				
			}
			else
			{
				forma.SuCICo.value = "";
				forma.CiPoVC.value = "";
				forma.ToSuCC.value = "";
				forma.ReSvCo.value = "";
				forma.MoCrCo.value = "";
				forma.NVSuCo.value = "";
				forma.SiCrIn.value = "";
			}
			
			
			
			// Dependiendo del valor de vivienda
		/*	alert(ValViv);
			alert(aCofAGA[0]);
			alert(ValOpe5);
			alert(forma.DeSuVi.value);
			alert(forma.DeCrIn.value);*/
			
			// Si el 5% del valor de la vivienda es menor a la subcuenta determinada
			// por Infonavit se tiene que recalcular 
			// Subcuenta de vivienda disponible, Monto restante de subcuenta y crédito Cofinavit
		
			

			
		}
		else
		{	
			//alert("");
			lblIngAcr.innerHTML = "Ingresos registrados en INFONAVIT menores a 11 VSM"			
			HabCof_11VSM("none")
			oTR_DeInIn.style.display = "none"
			//oTR_Ley11S.style.display = "none"
		}				
	}
	
	forma.DeVaVi.value  = forma.ValViv.value
	forma.DePlCr.value  = (DN(forma.PlaCre.value) / 12) + " años"
	forma.DeTiPr.value  = forma.TipCre.options(forma.TipCre.selectedIndex).text;
	forma.SumCre.value  = forma.ValViv.value
	forma.DeApAd.value = forma.ApoAdi.value;
	forma.DeImDe.value = forma.ImpDer.value;
	var CreInf = DN(forma.DeCrIn.value)
	var SubViv = DN(forma.SucViv.value)
	
	if (HonNot != "X")
	{
		forma.DePoNo.value  = "("  + HonNot + " %)"
	}
	else
	{
		forma.DePoNo.value  = "("  + formatonum(((DN(ImpGan) / ValViv)*100),2)  + " %)"
	}
	
	
	// Verificamos el producto para saber si es GMAC
	if (forma.Produc.value == "INFGCO")
	{	
		oTD_CofTit.innerHTML  = "COFINANCIAMIENTO PLUS"
		//Usuari = "GMAC"	
	}
					  
	// Desplegamos mensaje en barra
	//window.status = "Obteneniendo tasas.."
					  					
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/DatosCof_XML.asp";
	   strURL += "?Ingres=" + Ingres + "&ValViv=" + ValViv;
	   strURL += "&PlaCre=" + PlaCre + "&Moneda=" + Moneda;
	   strURL += "&HonNot=" + HonNot + "&CreInf=" + CreInf;
	   strURL += "&SucViv=" + SubViv + "&ValUdi=" + ValUdi;
	   strURL += "&IncEst=" + IncEst + "&IncAva=" + IncAva;
	   strURL += "&ImpGan=" + ImpGan + "&UsuSim=" + Usuari;
	   strURL += "&ApoAdi=" + ApoAdi + "&ImpDer=" + ImpDer;	   
	   if (bIngAdi==true) 
   	   {	strURL += "&IngAdi=true";	} 
	   else 
	   {	strURL += "&IngAdi=false";	} 
	   strURL += "&Usuari=" + forma.Usuari.value + "&TipCre=" + forma.TiCrSi.value;
  	   strURL += "&Produc=" + forma.Produc.value;	
	   
	   
	   forma.CadXML.value = strURL;
	   
	  // alert(strURL)
/*   alert(xmldom.load(strURL))*/
	   //return 0;
	   
	   xmldom.async = false;
	   
	  /*
	 if (forma.Usuari.value == "URBI")
	 {	alert(strURL);		 
	 alert(xmldom.load(strURL))
	 
		strURL = "http://192.168.1.1/SimulaCre/DatosCof_XML.asp?Ingres=18000&ValViv=500000&plaCre=300&Moneda=1&HonNot=2.0&CreInf=87627.69&SucViv=21443.17&ValUdi=3.842702&IncEst=true&IncAva=true&ImpGan=0.0&UsuSim=URBI&ApoAdi=0&ImpDer=0"
		alert(strURL);		 
	 alert(xmldom.load(strURL))
	 }
	  alert(strURL);		
	       alert(xmldom.load(strURL));
		  */	

	 //	return 0; 
	   
	 if( xmldom.load(strURL) )
	{
		DIV_DatCof.style.display = ""		
		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);				
		
		if (root.childNodes.length==0)
		{	return 0;	}
		
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
			//alert(strNombre + ':' + strValor);			
			 
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			obj.value = strValor;			
		}
		
		// Verificamos si el campo de leyenda se encuentra vacio
		if (forma.LeySim.value != "")
		{
			DIV_DatCof.style.display = "none"	
			alert(forma.LeySim.value)			
			return 0;
		}
		
		// Si es promotor SADASI
		if (forma.Usuari.value == "SADASI")
		{	// 		
			forma.DeInEn.value = forma.DeApCl.value; 
			forma.DeInPm.value = forma.DePaMe.value;
			forma.DeInTo.value = formatonum((DN(forma.DeApCl.value) + DN(forma.DePaMe.value)),2);
		}					
		
		// Calculamos el factor de pago..					
		forma.Cof_FacPag.value = formatonum((DN(forma.DePaMe.value) / DN(forma.DeCrCM.value)) *1000,2)
		forma.Cof_TasInt.value = forma.TC_Tas.value + " %"
		
		// Habilitamos objeto de calculo
		forma.BtnCalcula.disabled = false;
		var oTD_CofTit = document.getElementById("TD_CofTit");
		//var oTR_DeMeIN = document.getElementById("TR_DeMeIN");
		var oTR_MsgCre = document.getElementById("TR_MsgCre");
		//oTD_CofTit.innerHTML      = "COFINANCIAMIENTO"
		oTD_CofTit.innerHTML     += (bIngAdi==true) ? " CON INGRESOS ADICIONALES" : "";
		//oTR_DeMeIN.style.display  = (bIngAdi==true) ? "" : "none";
		//oTR_DeMeIN.style.display  = "";
		oTR_MsgCre.innerHTML      = "&nbsp;";				
		
		//alert(forma.CofCon.value);
	
		
		// Ocultamos leyenda de ingresos ya que no contamos con el dato		
		if (oTR_LeySCInf.style.display == "")
		{	lblIngAcr.innerHTML = ""		}
		
		// Si es crédito en UDIS y la vivienda excede las 500,000 udis deplegamos mensaje
/*		if (Moneda == 1 && (DN(forma.ValViv.value) / forma.ValUdi.value) > 350000)
		{
			TR_LEY_SINCOBINF.style.display = ""
			TR_LEY_SINCOBINF.style.display = ""
		}
		else
		{
			TR_LEY_SINCOBINF.style.display = "none"	
		}*/

		
		if (bIngAdi) {
			// Verificamos que su capacidad de pago (máxima) + el descuento mensual del infonavit
			// no sea superior al 40% de sus ingresos "comprobable"
			var vUDI   = parseFloat(ValUdi);
			var DesMenINF=0;
			var vDeMeIn=QC(forma.DeMeIN.value);
			if (!isNaN(vDeMeIn)) DesMenINF = parseFloat(vDeMeIn);
			var vMenSHF = (!isNaN(QC(forma.DePaMe.value))) ? parseFloat(QC(forma.DePaMe.value)) : 0;
			var vCapMaxPag=vMenSHF+DesMenINF;
			//alert("forma.DePaMe.value: "+forma.DePaMe.value+"\nDesMenINF: "+DesMenINF+"\nvCapMaxPag: "+vCapMaxPag + "\nvMenSHF: " +vMenSHF + "\nIngres*0.4: "+(Ingres*0.4) );
			if (vCapMaxPag>(Ingres*0.4)) {
				var sNom=forma.Nombre.value;
				var sMsg="";
				sMsg ='<span style=" font-weight:bold;font-size:12px;color:red;">No califica para COFINANCIAMIENTO CON INGRESOS ADICIONALES</span><br>';
				sMsg+='La suma de la mensualidad SHF + el descuento INFONAVIT,<br>es superior al 40% de sus ingresos comprobables.<br>';
				oTR_MsgCre.innerHTML      = sMsg;
				sMsg="MENSAJE DEL SISTEMA\n\n";
				sMsg+="_______________________________________________________\n";
				sMsg+="No califica para COFINANCIAMIENTO CON INGRESOS ADICIONALES\n";
				sMsg+="_______________________________________________________\n\n";
				sMsg+="Motivo:\n";
				//sMsg+=sNom.toUpperCase()+" con número de seguro social '"+forma.NSSCof.value+"'\n";
				sMsg+="La suma de la mensualidad SHF + el descuento INFONAVIT, \n"
				sMsg+="es superior al 40% de sus ingresos comprobables.\n\n";
				alert(sMsg);
				return;
			}
		}

	}	
	
}

function DesLeyTip(Seccion)
{	
	if (Seccion == "SubViv")
	{	Lbl_TipSubViv.innerHTML = "De clic para ver más detalles del calculo de la Subcuenta de Vivienda"	}
	if (Seccion == "RemSuv")
	{	Lbl_TipRemSuv.innerHTML = 'De clic para ver más detalles del calculo del Remanente de la Subcuenta de Vivienda'	}
	if (Seccion == "CreInf")
	{	Lbl_TipCreInf.innerHTML = 'De clic para ver más detalles del calculo del Crédito INFONAVIT'	}
}

function OcuLeyTip(Seccion)
{	
	if (Seccion == "SubViv")
	{	Lbl_TipSubViv.innerHTML = ""	}
	if (Seccion == "RemSuv")
	{	Lbl_TipRemSuv.innerHTML = ""	}
	if (Seccion == "CreInf")
	{	Lbl_TipCreInf.innerHTML = ""	}
}

function HabCof_11VSM(Valor)
{
	// "Instanciamos" objetos para desplegar/ocultar
	var oTR_ReSuCo = document.getElementById("TR_ReSuCo");
	var oTR_LeVaSu = document.getElementById("TR_LeVaSu");
	var oTR_ToSuCo = document.getElementById("TR_ToSuCo");
	var oTR_SeAc11 = document.getElementById("TR_SeAc11");	
	var oTR_Separ1 = document.getElementById("TR_Separ1");	
	var oTR_SuCaIn = document.getElementById("TR_SuCaIn");
	var oTR_CiPoVi = document.getElementById("TR_CiPoVi");
	var oTR_SuViRe = document.getElementById("TR_SuViRe");
	var oTR_MoCrIn = document.getElementById("TR_MoCrIn");
	var oTR_NuVeSu = document.getElementById("TR_NuVeSu");
	var oTR_CrInRe = document.getElementById("TR_CrInRe");
	var oTR_Separ2 = document.getElementById("TR_Separ2");
	var oTR_LeCrIn = document.getElementById("TR_LeCrIn");
											 
//		var oTR_SuDiCo = document.getElementById("TR_SuDiCo");
	// Pasamos valor que determina si se oculta o muestra
	oTR_ReSuCo.style.display = Valor
	oTR_LeVaSu.style.display = Valor
	oTR_ToSuCo.style.display = Valor
	oTR_SeAc11.style.display = Valor
	oTR_Separ1.style.display = Valor
	oTR_SuCaIn.style.display = Valor
	oTR_CiPoVi.style.display = Valor
	oTR_SuViRe.style.display = Valor
	oTR_MoCrIn.style.display = Valor
	oTR_NuVeSu.style.display = Valor
	oTR_CrInRe.style.display = Valor
	oTR_Separ2.style.display = Valor
	oTR_LeCrIn.style.display = Valor
//	oTR_SuDiCo.style.display = Valor
}

function TipFinFov(TipFin)
{
	var oTR_SaBaCF = document.getElementById("TR_CFSaBa");
	var oTR_CFBuAc = document.getElementById("TR_CFBuAc");
	var oTR_SalBas = document.getElementById("TR_DeCFSB");
	var oTR_CURPAc = document.getElementById("TR_CURPAc");
	var oTR_CURPCo = document.getElementById("TR_CURPCo");	
	var oTR_CreFov = document.getElementById("TR_DeCFCF");
	var oTR_CFCOSB = document.getElementById("TR_CFCOSB");
	var oTR_DFSBCo = document.getElementById("TR_DFSBCo");
	
	var oTR_FoDeBu = document.getElementById("TR_FoDeBu");
	var oTR_FoDeMF = document.getElementById("TR_FoDeMF");
	var oTR_FoDeMFCo = document.getElementById("TR_FoDeMFCo");	
	var oTR_FoDeTE = document.getElementById("TR_FoDeTE");
	var oTR_LePaFo = document.getElementById("TR_LePaFo");	
	var oTR_LyDIFo = document.getElementById("TR_LyDIFo");		

	// Ocultamos o desplegamo secciones

	oTR_SaBaCF.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_CFBuAc.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_SalBas.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_CURPAc.style.display  = (TipFin=="FOVALI" || TipFin=="FOVRES" || TipFin=="FOALSU") ? "" : "none";	
	oTR_CreFov.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";	
	oTR_DFSBCo.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	
	oTR_FoDeBu.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_FoDeMF.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_FoDeMFCo.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_FoDeTE.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_LePaFo.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";
	oTR_LyDIFo.style.display  = (TipFin=="FOVALI" || TipFin=="FOALSU") ? "" : "none";

	if (TipFin == "FOVALI" || TipFin=="FOALSU" || TipFin=="FOVRES")
	{			
/*		forma.CFSaBa.disabled = false;	
		forma.CFSaBa.title = "Salario base para calcular el crédito FOVISSSTE"*/
		//alert(forma.FovCon.value);
		if (forma.FovCon.value == "N")
		{	
			//oTR_CFCOSB.style.display = "none";
			oTR_DFSBCo.style.display = "none";
			oTR_CURPCo.style.display = "none";			
			oTR_FoDeMFCo.style.display = "none";
		}
		else
		{	
			oTR_CFCOSB.style.display = "";	
			oTR_DFSBCo.style.display = "";	
			oTR_CURPCo.style.display = "";
			oTR_FoDeMFCo.style.display = "";			
			//alert("visible");
		}
	}
	else
	{	
		oTR_CFCOSB.style.display = "none";	
		oTR_DFSBCo.style.display = "none";	
		oTR_CURPCo.style.display = "none";
		oTR_FoDeMFCo.style.display = "none";		
		/*forma.CFSaBa.disabled = true;
		forma.CFSaBa.title = "No hay financiamiento por parte del FOVISSSTE"*/
	}	
}

function ObtenCofFov(forma, DirVir, ValUdi)
{	
	
	var xmldom, strURL;		
	var nomfor = forma.name + '.';
	var CreCof = "";
	var CalCAT = 0;
	
	var ValUdi = DN(forma.ValUdi.value)
	var Ingres = DN(forma.CFIngr.value)
	var IngBas = DN(forma.CFSaBa.value)			
	var ValViv = DN(forma.ValViv.value)
	var PlaCre = forma.CFPlCr.value
	var Moneda = forma.CFMoCr.value
	var HonNot = forma.CFGaEs.value
	var ImpGan = DN(forma.CFImNo.value);

	//  var SubViv = DN(forma.CFSuVi.value) 	// Se inhibe la subcuenta por captura
	
	
	/* * * * * * * * * * * * * * * * * * * INICIA CAMBIOS POR EL WS DE FOVISSSSTE */
	// Se considera la subcuenta recuperada del WS
	var SubViv = DN(forma.SuViAc.value)
	var CrFoAc = DN(forma.CrFoAc.value)
	
	// Si se obtienen los valores de la captura manual
	if (TR_AjAcCF.style.display == "")
	{
		CrFoAc = DN(forma.AjAcCF.value)
		SubViv = DN(forma.AjAcSV.value)
	}	
	
	var CrFoCo = 0
	var SuViCo = 0	

	/* * * * * * * * * * * * * * * * * * * FIN CAMBIOS POR EL WS DE FOVISSSSTE */	

	
	
	var IncEst = forma.chkCFEst.checked;
	var IncAva = forma.chkCFAva.checked;
	var Usuari = forma.Usuari.value;
	var ApoAdi = DN(forma.CFApAd.value)	
	var TipFin = forma.CFTiFi.value;	
	var CrFoAj = 0
	
	var FovCon = forma.FovCon.value;
	var IngCon = 0;
	var SaBaCo = 0;
	var BuroCo = 0;	
	var SuViCo = 0;
	var BuCrAc = 0;
	var ToBuCr = 0
	

	// Obtenemos deudas de buro del acreditado, inicializamos total de deudas de buro
	BuCrAc = DN(forma.CFBuAc.value);
	ToBuCr = BuCrAc
	
	var oTR_MtSuFo = document.getElementById("TR_MtSuFo");
	oTR_MtSuFo.style.display = "none"		

	if (forma.Produc.value == "FOALSU")	{	oTR_MtSuFo.style.display = ""	}
	
	var oTD_CofFov = document.getElementById("TD_CofFov");	
	
	oTD_CofFov.innerHTML  = "CR&Eacute;DITO DE COFINANCIAMIENTO FOVISSSTE" 
	if (forma.Produc.value == "FOALSU")	{	oTD_CofFov.innerHTML  = "CR&Eacute;DITO DE COFINANCIAMIENTO FOVISSSTE CON SUBSIDIO" 	}	
	
	// Replicamos detalle

	forma.DFSuCo.value = forma.CFIngr.value
	forma.DFSaBa.value = forma.CFSaBa.value
	forma.DFCuAc.value = forma.CFCURP.value
	forma.DFCuCo.value = forma.CURPCoa.value
//	forma.DFSuVi.value = forma.CFSuVi.value
	forma.DFVaVi.value = forma.ValViv.value
	forma.DFPlCr.value = (DN(forma.CFPlCr.value) / 12) + " años"
	forma.DFTiPr.value = forma.CFMoCr.options(forma.CFMoCr.selectedIndex).text;
	forma.DFSuma.value = forma.ValViv.value
	forma.DFApAd.value = forma.CFApAd.value;					
	
	if (forma.FovCon.value == "S")
	{
		IngCon = DN(forma.CFCOIn.value);
		SaBaCo = DN(forma.CFCPSB.value);
		BuroCo = DN(forma.BurCoa.value)
		
		// Incrementamos monto total de deudas de buri
		ToBuCr = ToBuCr + BuroCo
//				alert(DN(forma.BurCoa.value));
		//SaBaCo = 0
//		alert(BuroCo);
	//	return 0;
		
		//SuViCo = DN(forma.CFCoSV.value);
		CrFoCo = DN(forma.CrFoCo.value)
		SuViCo = DN(forma.SuViCo.value)		
		// Si se obtienen los valores de la captura manual
		//alert(TR_AjCoCF.style.display);
		//alert(CrFoCo);
		if (TR_AjCoCF.style.display == "")
		{
			CrFoCo = DN(forma.AjCoCF.value)
			SuViCo = DN(forma.AjCoSV.value)
		}	
		//alert(CrFoCo);
		forma.DFInCo.value = forma.CFCOIn.value
		//forma.DFSBCo.value = forma.CFCPSB.value
		forma.DFSBCo.value = formatonum(DN(SaBaCo),2)
		//forma.DFSuVi.value = formatonum(DN(forma.CFSuVi.value) + SuViCo,2)
	}
	
	if (HonNot != "X")
	{	forma.DFPoNo.value  = "("  + HonNot + " %)"	}
	else
	{	forma.DFPoNo.value  = "("  + formatonum(((DN(ImpGan) / ValViv)*100),2)  + " %)"	}

		
	// Pintamos subcuenta de vivienda...
	forma.DFSuVi.value = formatonum(DN(SubViv) + SuViCo,2)
					  
	// Desplegamos mensaje en barra
	//window.status = "Obteneniendo tasas.."
					  					
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/DatosCofFov_XML.asp";	   
	   strURL += "?Ingres=" + Ingres + "&ValViv=" + ValViv;
	   strURL += "&PlaCre=" + PlaCre + "&Moneda=" + Moneda;
	   strURL += "&HonNot=" + HonNot + "&IngBas=" + IngBas;
	   strURL += "&SucViv=" + SubViv + "&ValUdi=" + ValUdi;
	   strURL += "&IncEst=" + IncEst + "&IncAva=" + IncAva;
	   strURL += "&ImpGan=" + ImpGan + "&UsuSim=" + Usuari;
	   strURL += "&ApoAdi=" + ApoAdi + "&TipFin=" + TipFin;	   
	   strURL += "&FovCon=" + FovCon + "&IngCon=" + IngCon;
	   strURL += "&SaBaCo=" + SaBaCo + "&SuViCo=" + SuViCo;	
   	   strURL += "&CrFoAj=" + CrFoAj
	   strURL += "&Usuari=" + forma.Usuari.value + "&TipCre=" + forma.TiCrSi.value;
  	   strURL += "&Produc=" + forma.Produc.value;	
	   strURL += "&CrFoAc=" + CrFoAc + "&CrFoCo=" + CrFoCo;	
	   strURL += "&CFBuAc=" + ToBuCr 
	   xmldom.async = false;  	   
	   
	   //alert(strURL);
	//   return 0;
	   
	 //DatosCofFov_XML.asp?Ingres=15000&ValViv=500000&PlaCre=240&Moneda=2&HonNot=0.0&IngBas=10000&SucViv=500000&ValUdi=0&IncEst=false&IncAva=true&ImpGan=0.0&UsuSim=HCM&ApoAdi=0&TipFin=FA&FovCon=N&IngCon=0&SaBaCo=0&SuViCo=0&CrFoAj=0
/*	   forma.CadXML.value = strURL
	   alert(strURL);		*/
//	 alert(xmldom.load(strURL));
	 /**/
//	 return 0;
	 
	  
	 if( xmldom.load(strURL) )
	{
		DIV_DatFov.style.display = ""		
		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);				
		
		if (root.childNodes.length==0)
		{	return 0;	}
		
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
		//	alert(strNombre + ':' + strValor);
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			obj.value = strValor;			
		}
		
		// Verificamos si el campo de leyenda se encuentra vacio
		if (forma.LeySim.value != "")
		{
			DIV_DatFov.style.display = "none"	
			alert(forma.LeySim.value)			
			return 0;
		}

		// Calculamos y desplegamos el CAT	
		//CalCAT = ObtenCAT (DN(forma.DFCrCM.value), DN(forma.TC_Tas.value), DN((PlaCre)),DN(forma.DFPaMe.value))	
		//forma.Fov_CAT.value = CalCAT + " %";
		
		// Calculamos el factor de pago..					
		forma.DFFaPa.value = formatonum((DN(forma.DFPaMe.value) / DN(forma.DFCrCM.value)) *1000,2)
		forma.DFTaIn.value = forma.TC_Tas.value + " %"		
		
		// Calculamos y asignamos valores del pago mensual y desplegamos del buro
		forma.FOV_BurCre.value = formatonum(ToBuCr,2)
//		forma.FOV_PagFov.value = formatonum((DN(IngBas)*.30),2)
		forma.FOV_PagFov.value = formatonum(((DN(IngBas)*.10)),2)
		forma.FOV_PaFoCo.value = formatonum(((DN(SaBaCo)*.10)),2)
		
		// Hacemos la sumatoria de egresos y calculamos el % de endeudamiento
		var fTotAde = 0
		
		// 
		//alert("Adeudos")
		//alert("mensualidad:" + forma.DFPaMe.value + ",total buro:" + ToBuCr + ", pago fov acr:" + forma.FOV_PagFov.value + ", pago fov coa:" + forma.FOV_PaFoCo.value);
		fTotAde = DN(forma.DFPaMe.value) + DN(ToBuCr) + DN(forma.FOV_PagFov.value) + DN(forma.FOV_PaFoCo.value)
		//alert(fTotAde);
		
		//forma.FOV_PoDeIn.value = formatonum((DN(fTotAde) / DN(Ingres)*100),2)
		forma.FOV_TotEgr.value = formatonum(fTotAde,2)
		TD_LePoDF.innerHTML = "     (#) Total de egresos representa el (" + formatonum((DN(fTotAde) / DN(Ingres + IngCon)*100),2) + "%) del ingreso"		
		//alert(formatonum((DN(fTotAde) / DN(Ingres)*100),2));
	}		
}



function ObtenDatoNom(sNomObj) 
{
	try 
	{
		var oObj = document.getElementsByName(sNomObj);
		var vObj = QC(oObj[0].value);
		return vObj;
	}
	catch (e)
	{
		return 0;
	}
}

function OtrosPla(DirVir, ValUdi)
{
	var nomfor = forma.name + '.';
	var xmldom, strURL;
	
	var Obj;
		
	if (forma.BtnPla.value == "Otros plazos")
	{
		forma.BtnPla.value = "Ocultar plazos"			
		forma.BtnPla.title= "Ocultar comparativo"
		TD_LeyCom.innerHTML = "Comparativo"		
	}
	else
	{
		forma.BtnPla.value = "Otros plazos"
		forma.BtnPla.title= "Ver cotización en 2 diferentes plazos al elegido"
		TD_LeyCom.innerHTML = ""
		HabObj("PlaCof",true)
		return 0;		
	}
	
		
	
	var Ingres = DN(forma.Ingres.value)
	var ValViv = DN(forma.ValViv.value)
	var PlaCre = forma.PlaCre.value
	var Moneda = forma.TipCre.value
	var HonNot = forma.HonNot.value
	var CreInf = DN(forma.DeCrIn.value)
	var SubViv = DN(forma.SucViv.value)
	var IncEst = forma.chkEst.checked;
	var IncAva = forma.chkAva.checked;
	var ImpGan = forma.ImpGan.value
	var Usuari = forma.Usuari.value;
	var ApoAdi = DN(forma.ApoAdi.value);
	var ImpDer = DN(forma.ImpDer.value);
	
		// Igualamos campos
	forma.CrInP1.value = forma.DeCrIn.value;
	forma.CrInP2.value = forma.DeCrIn.value;
	forma.SuViP1.value = forma.SucViv.value;
	forma.SuViP2.value = forma.SucViv.value;
	forma.GaInP1.value = forma.GasInf.value;
	forma.GaInP2.value = forma.GasInf.value;	
	forma.VaViP1.value = forma.ValViv.value
	forma.VaViP2.value = forma.ValViv.value
	forma.GaEsP1.value = forma.GasEsc.value;
	forma.GaEsP2.value = forma.GasEsc.value;				

	forma.DMINP1.value = forma.DeMeIN.value;				
	forma.DMINP2.value = forma.DeMeIN.value;				
	forma.ToGOP1.value = forma.ToGaOr.value;				
	forma.ToGOP2.value = forma.ToGaOr.value;		
	
	forma.DeApAd.value = forma.ApoAdi.value;
	forma.ApAdP1.value = forma.ApoAdi.value;
	forma.ApAdP2.value = forma.ApoAdi.value;
	
	forma.ImDeP1.value = forma.ImpDer.value
	forma.ImDeP2.value = forma.ImpDer.value	
	
	
	
		
	forma.ToGOP1.style.borderTop="1px solid black";
	forma.ToGOP2.style.borderTop="1px solid black";
	forma.VaViP1.style.borderTop="1px solid black";
	forma.VaViP2.style.borderTop="1px solid black";		
	// Dependiendo del plazo elegido y moneda
	// obtenemos los nuevos plazos a mostrar
	
	
	// Dependiendo de la moneda
	if (Moneda == 1)	// Para udis
	{	
		if (PlaCre >= 120 && PlaCre <= 240)
		{	
			PlaCr1 = parseInt(PlaCre) - parseInt(60);
			PlaCr2 = parseInt(PlaCre) + parseInt(60);
		}
		else
		{
			if (PlaCre == 60)
			{	
				PlaCr1 = parseInt(120);
				PlaCr2 = parseInt(180);
			}
			else
			{
				PlaCr1 = parseInt(240);
				PlaCr2 = parseInt(180);
			}
		}
	
	}
	else		
	{
		if (PlaCre >= 120 && PlaCre <= 180)
		{	
			PlaCr1 = parseInt(PlaCre) - parseInt(60);
			PlaCr2 = parseInt(PlaCre) + parseInt(60);
		}
		else
		{
			if (PlaCre == 60)
			{	
				PlaCr1 = parseInt(120);
				PlaCr2 = parseInt(180);
			}
			else
			{
				PlaCr1 = parseInt(180);
				PlaCr2 = parseInt(120);
			}
		}	
	}
	
	forma.PlaCot.value = parseInt(PlaCre) / 12 + " años"
	//forma.Plazo1.value = parseInt(PlaCr1) / 12 + " años"
	//forma.Plazo2.value = parseInt(PlaCr2) / 12 + " años"
	
	//forma.DePoNo.value  = "("  + HonNot + " %)"
	
		
	// Desplegamos mensaje en barra
	//window.status = "Obteneniendo tasas.."
					  					
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/DatosCofPla_XML.asp";	   
	   strURL += "?Ingres=" + Ingres + "&ValViv=" + ValViv;
	   strURL += "&PlaCre=" + PlaCre + "&Moneda=" + Moneda;
	   strURL += "&HonNot=" + HonNot + "&CreInf=" + CreInf;
	   strURL += "&SucViv=" + SubViv + "&ValUdi=" + ValUdi;
	   strURL += "&PlaCr1=" + PlaCr1 + "&PlaCr2=" + PlaCr2;
	   strURL += "&IncEst=" + IncEst + "&IncAva=" + IncAva;
	   strURL += "&ImpGan=" + ImpGan + "&UsuSim=" + Usuari;
	   strURL += "&ApoAdi=" + ApoAdi + "&ImpDer=" + ImpDer;	   
	   if (forma.Produc.value=="I") strURL += "&IngAdi=S";
	   xmldom.async = false;		
	   
	   
	  /*
	  alert(strURL);		
	  alert(xmldom.load(strURL));
	  return 0;*/
	  
	 if( xmldom.load(strURL) )
	{		
		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);				
		
		if (root.childNodes.length==0)
		{	return 0;	}
		
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
			//alert(strNombre + ':' + strValor);
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			obj.value = strValor;			
		}					
		
		// Habilitamos objeto de calculo
		forma.BtnCalcula.disabled = false;
	}	

}


function SHF_PorIng(forma,DirVir, ValUdi)
{

	var xmldom, strURL;
	var ValViv, MtoCre; 
	var FacSeg = 0.0085;
	var CreUdi = 0;
	var VivUdi = 0;
	var SegUdi = 0
	var SegPes = 0
	var ComAdm = 65
	var ComCob = 0 
	var MtoCob = 0
	var OtrCos = 0
	var FapPes = 0
	var FapUdi = 0
	
	var Ingres = 0;
	ValUdi = forma.ValUdi.value
	
	var TSwa_05 = 0.0131
	var TSwa_10 = 0.0246
	var TSwa_15 = 0.0347
	var TSwa_20 = 0.0435
	var TSwa_25 = 0.0500
	
	var oTD_PL_P25 = document.getElementById("TD_PL_P25");
	var oTD_CR_P25 = document.getElementById("TD_CR_P25");
	var oTD_TI_P25 = document.getElementById("TD_TI_P25");
	var oTD_PM_P25 = document.getElementById("TD_PM_P25");
	var oTD_IR_P25 = document.getElementById("TD_IR_P25");
	var oTD_DE_P25 = document.getElementById("TD_DE_P25");	
	
		oTD_PL_P25.style.display = "none"
	oTD_CR_P25.style.display = "none"
	oTD_TI_P25.style.display = "none"
	oTD_PM_P25.style.display = "none"
	oTD_IR_P25.style.display = "none"
	oTD_DE_P25.style.display = "none"	 
	
	//var forma = document.frmProspecto;
	
	var nomfor = forma.name + '.';
	var objViv = eval(nomfor + "ValViv");	
	var objCre = eval(nomfor + "MonCre");
	var objPro = eval(nomfor + "Produc");				
	var objFap;
	var objInr;
	var objPup;
	var objDem;
	var objCru;
	
	var DifIng = 0;
	
	Ingres = DN(forma.IngShf.value)
	
	// Obtenemos valor de vivienda y monto de crédito
	ValViv = QC(objViv.value)		
	
	// Calculamos el crédito en UDIS
	CreUdi  = QC(ValorUdis(MtoCre, ValUdi,'',''));
	VivUdi  = QC(ValorUdis(ValViv, ValUdi,'',''));	
	// Redondeamos a 2 decimales
	SegUdi = formatonum(SegUdi,2)			
	
	
	FapPes = FacPagIng(ValViv,"P")
	FapUdi = FacPagIng(VivUdi,"U")
	
					  
	// Desplegamos mensaje en barra
	//window.status = "Obteneniendo tasas.."					    
					  					
	xmldom = new ActiveXObject("microsoft.xmldom");
	with( document.location )
	   strURL = protocol + "//" + hostname + DirVir + "/CalIngres_XML.asp";
	   strURL += "?ValViv=" + ValViv + "&TipPro=" + objPro.value;
	   strURL += "&Ingres=" + Ingres  + "&ValUdi=" + forma.ValUdi.value 
	   xmldom.async = false;			   	   

	/*
 alert(strURL);			  
	 	  alert(xmldom.load(strURL));*/
	
	  //  return 0;
	  
	
	if( xmldom.load(strURL) )
	{

		var root = xmldom.documentElement;
		var element, strValor, strNombre;
		var obj;	    	    
		var plaMes;
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);
		
		if (root.childNodes.length==0)
		{
			return 0;
		}      				
		
		// Ciclo por el total de campos			    
		for( i = 0; i < element.childNodes.length; i++ )
		{	
			// Nombre del campo
			strNombre = element.childNodes(i).nodeName
			strValor = element.childNodes(i).text;
			//alert(strNombre + ':' + strValor);
			plaMes = eval(eval(strNombre.substring(4,6)) * 12)
			
			// Instanciamos al objeto de la forma con el nombre del nodo						
			obj = eval(nomfor + strNombre );
			// Asignamos valor del nodo al objeto 
			if (strNombre.substring(0,2) == "CR")			
			{					
				// Desglose de mensualidad
				objDem = eval(nomfor + "DM_" + strNombre.substring(3,6));
					
				// Llenamos objetos de factor de pago e ingreso requerido..
				if (strNombre.substring(0,4) == "CR_U")
				{						
					// Asignamos valor a objeto..
					obj.value = formatonum((DN(strValor)),2);										
								
					// Valor del crédito en pesos
					CreUdi  = DN(strValor)										
					
					//alert((eval(strNombre.substring(4,6)))*60)
					
					
					//alert(plaMes);
					//alert(eval(eval(plaYea) * eval(12)));
					//alert(eval(strNombre.substring(4,6)) * 60);
					//alert(CreUdi);
					
					// Valor del crédito lo convertimos a udis
					CreUdi  = formatonum((CreUdi /  ValUdi),2)
					CreUdi = DN(CreUdi);					
					
					objCru = eval(nomfor + "CU_" + strNombre.substring(3,6));					
					objCru.value= CreUdi
					
					// Calculamos seguro 				
					SegUdi = CreUdi * parseFloat(FacSeg/12)											
					
					// Asignamos valor a objeto..
					//obj.value = formatonum((DN(strValor) * ValUdi),2);
					
					// Incrementamos contador 
					i = i + 1
					
					// Nombre del campo
					strNombre = element.childNodes(i).nodeName
					strValor = element.childNodes(i).text;
					
					// Instanciamos al objeto de la forma con el nombre del nodo						
					obj = eval(nomfor + strNombre );
						
					// Pago mensual en UDIS
					//strValor = ValorUdis(strValor, ValUdi,'','');				
					// Componentes del pago mensual					
					objDem.value =  DN(strValor) + "|" + ComAdm + "|" + SegUdi + "|";
					
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));					
					objFap.value= formatonum((DN(strValor) / CreUdi*1000),2)																				
					
					// Calculamos monto a consdirerar para cobertura				
					MtoCob = (DN(strValor) + DN(SegUdi) + ComAdm)				
					
					// Calculamos la cobetura...				
					if (strNombre == "PM_U25")
					{	ComCob  = MtoCob * TSwa_25  }
					if (strNombre == "PM_U20")
					{	ComCob  = MtoCob * TSwa_20  }
					if (strNombre == "PM_U15")
					{	ComCob  = MtoCob * TSwa_15  }
					if (strNombre == "PM_U10")
					{	ComCob  = MtoCob * TSwa_10	}
					if (strNombre == "PM_U05")				
					{	ComCob  = MtoCob * TSwa_05	}	
					
					// Redondeamos a 2 decimales					
					ComCob = formatonum(ComCob,2)															
					
					// Calculamos el pago mensual final en UDIS
					//strValor = formatonum((DN(strValor) + SegUdi + DN(ComAdm) + DN(ComCob)),2)					
					strValor =  formatonum(DN(strValor) + DN(SegUdi) + DN(ComAdm) + DN(ComCob),2)
					
					// Desglose completo de pago mensual					
					//objDem.value =  objDem.value + ComCob + "|" + DN(strValor) + "|" + DN(CreUdi) + "|" 
					objDem.value =  objDem.value + ComCob + "|" + DN(strValor) + "|2.50|50|800|" 
					
					//alert(objDem.value);
					
					
					
					// Calculamos el pago mensual final en pesos
					objPup = eval(nomfor + "PP_" + strNombre.substring(3,6));
					objPup.value= formatonum((DN(strValor) * parseFloat(ValUdi)),2)
					objInr = eval(nomfor + "IR_" + strNombre.substring(3,6));									
					objInr.value= formatonum((DN(objPup.value) * FapUdi),2)		
					
					// Obtenemos el diferencial entre el ingreso requerido y el calculado
					DifIng = DN(objInr.value) - DN(forma.IngShf.value)
					
					if (DifIng > -1 && DifIng < 1)
					{						
						objInr.value = forma.IngShf.value 
					}
					
																						
									
				}
				else
				{
					// Monto de crédito
					MtoCre = DN(strValor)									
					
					// Monto del seguro en pesos
					SegPes = DN(strValor) * parseFloat(FacSeg/12)		
					
					// Asignamos valor a objeto..
					obj.value = strValor;			
					
					// Incrementamos contador 
					i = i + 1
					
					// Nombre del campo
					strNombre = element.childNodes(i).nodeName
					strValor = element.childNodes(i).text;											
					
					// Instanciamos al objeto de la forma con el nombre del nodo						
					obj = eval(nomfor + strNombre );
					
					// Actualizamos factor de pago
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));
					objFap.value= formatonum((DN(strValor) / parseFloat(MtoCre)*1000),2)
					
					// Desglose completo de pago mensual
					objDem.value =  DN(strValor) + "|0.01|" + SegPes + "|0|" 
					
					// Calculamos el pago mensual final en Pesos
					strValor = formatonum(DN(strValor) + 0.01 + SegPes,2)
					
					objDem.value =  objDem.value + DN(strValor) + "|2.50|50|800|"
					
					objInr = eval(nomfor + "IR_" + strNombre.substring(3,6));										
					objInr.value= formatonum((DN(strValor) * FapPes),2)					
					
					// Obtenemos el diferencial entre el ingreso requerido y el calculado
					DifIng = DN(objInr.value) - DN(forma.IngShf.value)
					
					if (DifIng > -1 && DifIng < 1)
					{						
						objInr.value = forma.IngShf.value 
					}
					
					
				}
			}
			// Asignamos valor a objeto..
			obj.value = strValor;
			
			if (strNombre.substring(0,2) == "PM")
			{	// Llenamos objetos de factor de pago e ingreso requerido..
				if (strNombre.substring(0,4) == "PM_U")
				{
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));					
					objFap.value= formatonum((parseFloat(QC(strValor)) / parseFloat(CreUdi)*1000),2)
				}
				else
				{
					objFap = eval(nomfor + "FP_" + strNombre.substring(3,6));
					objFap.value= formatonum((DN(strValor) / parseFloat(MtoCre)*1000),2)					
				}												
			}
			
			if (strNombre.substring(0,2) == "TI")
			{	// Llenamos objetos de factor de pago e ingreso requerido..
				if (strNombre.substring(0,4) == "TI_U")
				{
					objDem.value =  plaMes + "|" + DN(strValor) + "|" + DN(CreUdi) + "|" + objDem.value
				}		
				else
				{
					//alert(plaMes + "|" + DN(strValor) + "|" + DN(MtoCre) + "|" + objDem.value);
					objDem.value =  plaMes + "|" + DN(strValor) + "|" + DN(MtoCre) + "|" + objDem.value	
				}															
			}
		}																				
	}				
	
	/*DIV_CotUdi.style.display = ""
	DIV_CotPes.style.display = ""*/
	TR_TRAPES.style.display = ""
	TR_TRAUDI.style.display = ""
	DIV_MoCrPe.style.display = ""
	DIV_MoCrUd.style.display = ""
	DIV_InRePe.style.display = "none"	
	DIV_InReUd.style.display = "none"	
}

function VerDet(Det, lMndCre, lAnios)
{	
	
	var CadVal
	var ArrVal
	var objDep;
	var objPam;
	var objPap;
	var objCre;
	var objPpr;
	var objFon;
	var IngReq;	
	var MonCre;
	var CreCom = 0;
	var CosEst, CosBur;
	var MtoCre;
	var ObjSub;
	var ArrSub;
	var oTR_TRAUDI = document.getElementById("TR_TRAUDI");	
	var oTR_INFCSU = document.getElementById("TR_Ley_INFCSU");	
	var oTR_TRAPES = document.getElementById("TR_TRAPES");
	var oTR_CreTra = document.getElementById("TR_CRE_TRA_SHF");
	var oTR_SubSid = document.getElementById("TR_CRE_SUB_SHF");
	var oTR_SHF_IngCom = document.getElementById("TR_SHF_IngCom");
	
	var objTas;
	var objFac;
	var oTD_ComApe = document.getElementById("TD_ComApe");
	
	var CalCAT = 0;	
	
	// Ocultamos por default los ingresos requeridos
	oTR_SHF_IngCom.style.display = "none"	


	if (lMndCre == 1)
	{	MonCre = "SMF"	}
	else
	{	MonCre = "PESOS"	}	
	
	//	alert(DN(forma.ValViv.value) / forma.ValUdi.value);		
	// Si es crédito en UDIS y la vivienda excede las 500,000 udis deplegamos mensaje
	/*	if (lMndCre == 1 && (DN(forma.ValViv.value) / forma.ValUdi.value) > 350000)
	{
		TR_LEY_SINCOBSHF.style.display = ""	
	}	
	else
	{
		TR_LEY_SINCOBSHF.style.display = "none"	
	}*/
	
	
	//TR_LEY_SINCOB
		
	
	if (forma.De_Cre.value != "")
	{	
		var objBot =  eval(forma.name + "." + forma.De_Cre.value);
		//alert(objBot.name);
		RestauraBoton(objBot)		
	
	}
	ResaltaBoton(Det)
	forma.De_Cre.value = Det.name;

	//alert(Det.name);
	
	/*DIV_CotUdi.style.display = "none"	
	DIV_CotPes.style.display = "none"*/
	
	oTR_TRAUDI.style.display = "none"
	oTR_TRAPES.style.display = "none"
	oTR_SubSid.style.display = "none"	
	oTR_CreTra.style.display = "";
	DIV_BotSHF.style.display = ""
	DIV_DatSHF.style.display = ""		
	
	//alert(forma.name + ".DM_" + Det.name.substring(4,7));	
	objDem = eval(forma.name + ".DM_" + Det.name.substring(4,7));		
	//	alert(objDem.value);
	
	if (lMndCre == 1)
	{	objPam = eval(forma.name + ".PP_" + Det.name.substring(4,7));	}
	else
	{	objPam = eval(forma.name + ".PM_" + Det.name.substring(4,7));	}
	
	objPap = eval(forma.name + ".PP_" + Det.name.substring(4,7));
	
		
	
	if (forma.TipCal.value == "V")
	{	MtoCre = DN(forma.MonCre.value);	}
	else
	{			
		objCre = eval(forma.name + ".CR_" + Det.name.substring(4,7));			
		MtoCre = DN(objCre.value);
	}
	

	IngReq = eval(forma.name + ".IR_" + Det.name.substring(4,7));
	objTas = eval(forma.name + ".TI_" + Det.name.substring(4,7));
	objFac = eval(forma.name + ".FP_" + Det.name.substring(4,7));
	objPpr = eval(forma.name + ".PR_" + Det.name.substring(4,7));
	objFon = eval(forma.name + ".FO_" + Det.name.substring(4,7));
	

	// Obtenemos valores del detalle de la mensualidad
	CadVal = objDem.value;							
	

	
	ArrVal = CadVal.split("|");		// Armamos arreglo				


	
	// Desplegamos la comisión de apertura
	oTD_ComApe.innerHTML  = "Comisión de apertura (" + ArrVal[8] + "%) :"
	
	// Establecemos el costo del buro y del estudio
	CosBur = formatonum(ArrVal[9],2)
	CosEst = formatonum(ArrVal[10],2)
	
	// Si el producto es crédito tradicional
	if (forma.Produc.value == "UDIPES")
	{	TD_LeySHF.innerHTML = "CREDITO TRADICIONAL" }
	else
	{	TD_LeySHF.innerHTML = forma.Produc.options(forma.Produc.selectedIndex).text.toUpperCase()	}
	/*if (forma.Produc.value != "C")
	{	*/

	if (forma.Produc.value == "SUBSID")
	{
		
	
/*		TR_CRE_TRA_SHF.style.display = "none"
		TR_CRE_SUB_SHF.style.display = ""*/
		oTR_SubSid.style.display = ""	
		oTR_CreTra.style.display = "none";
		ObjSub = eval(forma.name + ".CS_" + Det.name.substring(4,7));
		TD_LeySHF.innerHTML  = "PROGRAMA DE SUBSIDIO A LA VIVIENDA";						
		
		ArrSub = ObjSub.value.split("|")
		//alert(ObjSub.value);
		//alert(ArrSub[0]);
		

		forma.SHF_SUCred.value = formatonum	(ArrSub[0],2)
		forma.SHF_SUVaVi.value = formatonum	(ArrSub[1],2)
		forma.SHF_SUPoGo.value = "(" + ArrSub[2] + " %)" 
		forma.SHF_SUGaOr.value = formatonum	(ArrSub[3],2)
		
		forma.SHF_SUSuSf.value = formatonum	(ArrSub[8],2)
		forma.SHF_SUApAd.value = formatonum	(ArrSub[12],2)
		forma.SHF_PreGPI.value =  "(" + ArrSub[9] + " %)"
		forma.SHF_SUGPI.value = formatonum	(ArrSub[10],2)
		forma.SHF_SUPoEn.value = "(" + ArrSub[7] + " %)"
		forma.SHF_SUEnga.value = formatonum	(ArrSub[6],2)		
		

		forma.Det_InSubAc.value = forma.IngAcrSub.value
		forma.Det_InSubCo.value = forma.IngConSub.value
		
		//forma.Sub_IngCon.value = "Ingresos conyugales "
		
		/*alert(oTR_INFCSU.style.display);
		alert(forma.SubCon.value);*/
		// Desplegamos ingresos a comprobar para subsidios
		if (forma.SubCon.value == "S")
		{	oTR_INFCSU.style.display = ""	}
		else
		{	oTR_INFCSU.style.display = "none"	}
		
		oTR_SHF_IngCom.style.display = ""	


		//alert(ArrSub[6]);
		//alert(ArrSub[3]);
		
		if ((ArrSub[6] - ArrSub[3]) > 0)
		{	
			//lbl_NotEng.innerHTML = '&nbsp;&nbsp;*';	
			//TD_LeyGaO_Sub.style.display = ""
		}
		else
		{	
			lbl_NotEng.innerHTML = '';	
			TD_LeyGaO_Sub.style.display = "none"
		}

		forma.SHF_SUPaMe.value = objPam.value;
		forma.SHF_SUSuFr.value = formatonum	(ArrSub[8],2)
		forma.SHF_SUSuto.value = formatonum	(ArrSub[11],2)
		if (forma.OriViv.value == "N")
		{	forma.SHF_SUOrVi.value = "NUEVA"	}
		else if (forma.OriViv.value == "U")
		{	forma.SHF_SUOrVi.value = "USADA"	}
		
	}
	
		// Si la moneda es UDIS
		if (forma.Produc.value == "UDIPES" && lMndCre == 1 && forma.TipCal.value == "V")
		{	
			// Porcentaje de enganche es mayor a 85
			if	(eval(forma.PorCre.value) > 85)
			{	
				//	Ajustamos el monto de crédito al 85% del valor de la vivienda
				MtoCre = DN(forma.ValViv.value) * .85	
			}
		}
		
		
		forma.SHF_DePlCr.value = lAnios + " años "  //(" + (lAnios * 12) + " meses)";
		forma.SHF_ValViv.value = forma.ValViv.value;
		forma.SHF_CreHCM.value = formatonum	(MtoCre,2);
		CreCom = MtoCre		
		forma.SHF_PagMen.value = objPam.value;
		forma.SHF_Ingres.value = IngReq.value;
		forma.SHF_PagPro.value = objPpr.value;
		forma.SHF_Moneda.value = MonCre;				
		forma.SHF_TasInt.value = objTas.value + " %";		
		
		forma.SHF_FacPag.value = formatonum	((DN(objPam.value) / MtoCre) * 1000,2);		
		
		forma.SHF_EngCre.value = formatonum(DN(forma.ValViv.value) -  MtoCre,2);
		forma.SHF_SumCre.value  = forma.ValViv.value;
	/*		
	}
	else
	{	

		forma.CO_TipPro.value = forma.Produc.options(forma.Produc.selectedIndex).text;		
		forma.CO_Plazo.value = lAnios + " años (" + (lAnios * 12) + " meses)";
		forma.CO_ValViv.value = forma.ValViv.value;
		forma.CO_MtoCre.value = forma.MonCre.value;	
		CreCom = DN(MonCre.value)
		forma.CO_CreInf.value = forma.DeCrIn.value;	
		forma.CO_SubCta.value = forma.SucViv.value;	
		forma.CO_ApoIni.value = forma.AhoInf.value;	
		forma.CO_ApoAdi.value = "0.00";			
		DIV_DetCof.style.display = ""	
	}*/

	// Desglozamos valores del pago...
	forma.PagNet.value = ArrVal[0]
	forma.ComAdm.value = ArrVal[1]
	forma.SegVid.value = ArrVal[2]
	forma.ComCob.value = ArrVal[3]	
	
	// Calculamos y desplegamos costo del avaluo
	forma.SHF_GasAva.value = formatonum(CosAva(),2);	

	// Si hay gastos notariales por calcular..
	if (forma.NotSad.value != "X")
	{	forma.PoGaNo.value = "(" + forma.NotSad.value + " %):"	}	
	else
	{	forma.PoGaNo.value = "(" + formatonum(((DN(forma.GanSHF.value) / DN(forma.ValViv.value))*100),2) + " %):"	}
	
	forma.DeGaNo.value = formatonum(DN(forma.GanSHF.value),2);
	// Calculamos comisión de apertura
	forma.SHF_GasCoa.value = formatonum(ComApe(CreCom, ArrVal[8]),2);	
	forma.SHF_GasEng.value = forma.SHF_EngCre.value		
	forma.SHF_GasMen.value = objPam.value;		
	// Sumamos gastos de estudio y buro
	forma.SHF_GasEst.value = formatonum((DN(CosEst) + DN(CosBur)),2);
						
	// Sumamos los gastos aproximados
	forma.SHF_GasApr.value = DN(CosEst) + DN(CosBur) + DN(forma.SHF_GasAva.value) + DN(forma.SHF_GasCoa.value) + DN(forma.DeGaNo.value)
	forma.SHF_GasApr.value = formatonum(forma.SHF_GasApr.value,2)

		// Sumamos los gastos totales
	forma.SHF_GasTot.value = DN(forma.SHF_GasApr.value) + DN(forma.SHF_GasEng.value) + DN(forma.SHF_GasMen.value)
	
	forma.SHF_GasTot.value = formatonum(forma.SHF_GasTot.value,2)		
//			alert("9");	
	// Le descontamo al crédito los gastos inciales
	MtoCre = MtoCre - DN(forma.SHF_GasEst.value) - DN(forma.SHF_GasAva.value) - DN(forma.SHF_GasCoa.value)	

	// Calculamos y desplegamos el CAT	
	CalCAT = ObtenCAT (MtoCre, DN(objTas.value), DN((lAnios) * 12),DN(objPam.value))	
	forma.SHF_CAT.value = CalCAT + " %";
	
	
	//alert(Det.name.substring(4,5));
	var sTasa="TI_";
	var lTasa=0;
	switch(lMndCre) {
		case 1: sTasa+="U"; break;
		case 2: sTasa+="P"; break;
	}
	if (lAnios==5)
		sTasa+="05";
	else
		sTasa+=lAnios;
	
	lTasa = DN(forma.SHF_TasInt.value)
	
	var sParPag=(lAnios*12).toString()+"|";		
	
	sParPag+=lTasa.toString()+"|";
	

	// Armamos cadena para desgloze de la tabla de amortización
	sParPag+=ArrVal[2] + "|";
	sParPag+=ArrVal[3] + "|";
	sParPag+=ArrVal[4] + "|";
	sParPag+=ArrVal[5] + "|";
	sParPag+=ArrVal[6] + "|";
	sParPag+=ArrVal[7] + "|";
	//alert(sParPag);
	document.getElementById("Moneda").value=lMndCre;
	document.getElementById("ParPag").value=sParPag;
	

	document.getElementById("ParPag").value=CadVal ;


}

function ObtenCAT(MtoCre, TasMen, PlaMes, PagMen)
{
	var xmldom, strURL;
	
	// Realizamos el calculo del CAT
	xmldom = new ActiveXObject("microsoft.xmldom");
	
	with( document.location )
	   strURL = protocol + "//" + hostname + forma.RutApl.value + "/GeneraCAT_XML.asp";
	   strURL += "?MtoCre=" + MtoCre + "&TasMen=" + TasMen;
	   strURL += "&PlaMes=" + PlaMes + "&PagMen=" + PagMen 
	   xmldom.async = false;		

	
	  //alert(strURL);			  
	  //alert(xmldom.load(strURL));
	  
	  //  return 0;
	  
	
	
	if( xmldom.load(strURL) )
	{
	
		var root = xmldom.documentElement;
		var element, strValor
		
		
		// Inicializa variables
		root = xmldom.documentElement; 
		element = root.childNodes(0);
		
		strValor = element.childNodes(0).text;
		
		//alert(strValor);
		return formatonum(strValor,2)
	
	}
}
 
 
function ValidaPlazosMon(forma, Moneda)
{
	var ComPla = eval(forma.name + ".PlaCre");	
	var ValAct = ComPla.value;	
	
	with(ComPla.options)
	{	
		innerHTML = "";
		
		add( new Option("5 AÑOS", 60) );	
		add( new Option("10 AÑOS", 120));
		add( new Option("15 AÑOS", 180));
		add( new Option("20 AÑOS", 240));
		
		// Si la moneda es Udis
		if (Moneda == 1)
		{	
			add( new Option("25 AÑOS", 300));	
			ComPla.value = ValAct
		}		
		else
		{
			if (ValAct != 300)
			{	ComPla.value = ValAct	}
			else
			{	ComPla.value = 240	}
		}
	
	}
}

//function PlazosMonGMAC(forma)
//{
//	var ComPla = eval(forma.name + ".PlaCre");	
//	var ValAct = ComPla.value;	
//	
//	with(ComPla.options)
//	{	
//		innerHTML = "";
//		
//		
//		add( new Option("25 AÑOS", 300));
//		add( new Option("20 AÑOS", 240));
//		add( new Option("15 AÑOS", 180));
//
//
///*		if (ValAct != 300)
//		{	ComPla.value = ValAct	}
//		else
//		{	ComPla.value = 240	}		*/			
//	}
//}

function HabilitaSubSid(Habilitado)
{

	var oTBL_COTUDI = document.getElementById("TBL_COTUDI");
	var oTBL_COTPES = document.getElementById("TBL_COTPES");
	//	alert(forma.TiCrSi.value);

	if (Habilitado == "SI")
	{
		//forma.TiCrSi.options(forma.TiCrSi.selectedIndex).text = "Casa Ayuda"		
		DIV_CALVIV1.style.display = "none"
		DIV_CALVIV2.style.display = "none"
		DIV_CALVIV3.style.display = "none"
		DIV_CRETRA.style.display = "none"
		DIV_INGSHF.style.display = "none"
		TR_GanSAD.style.display = "none"		
		DIV_SUB.style.display = ""
		TR_OriViv.style.display = ""
		TR_SubCon.style.display = ""
	/*	forma.Usuari.value = "HCMSUB"
		DetMonPLa("DE_U05","none")
		DetMonPLa("DE_U10","none")		  
		DetMonPLa("DE_U15","none")
		DetMonPLa("DE_P05","none")
		DetMonPLa("DE_P10","none")
		DetMonPLa("DE_P15","none")	*/
		forma.BtnCalcula.disabled = false;
		
	/*	TBL_COTUDI.width = "350"
		TBL_COTPES.width = "270"		*/
	}
	else
	{
		if (forma.TiCrSi.options(forma.TiCrSi.selectedIndex).text == "Casa Ayuda")
		{	forma.TiCrSi.options(forma.TiCrSi.selectedIndex).text = "Casa Mexicana"	}		
		DIV_CALVIV1.style.display = ""
		DIV_CALVIV2.style.display = ""		
		DIV_CALVIV3.style.display = ""
		DIV_INGSHF.style.display = ""
		//TR_GanSAD.style.display = "none"		
		TR_OriViv.style.display = "none"		
		TR_SubCon.style.display = "none"
		DIV_SUB.style.display = "none"
/*		if (forma.UsuTem.value != "HCMSUB")
		{	forma.Usuari.value = forma.UsuTem.value		}
		else
		{	forma.Usuari.value = "HCM"	}
		DetMonPLa("DE_U05","")
		DetMonPLa("DE_U10","")		  
		DetMonPLa("DE_U15","")
		DetMonPLa("DE_U20","")
		DetMonPLa("DE_U25","")		
		DetMonPLa("DE_P05","")
		DetMonPLa("DE_P10","")
		DetMonPLa("DE_P15","")
		DetMonPLa("DE_P20","")

		TBL_COTUDI.width = "550"
		TBL_COTPES.width = "550"*/
	}	
}	