function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function calcular_administrativos(monto){
  administrativo = document.getElementById('administrativo');
  if(monto<=1000)
    adm = 6;
  else if(monto<=2000)
    adm = 12;
  else if(monto<=3000)
    adm = 19;  
  else if(monto<=6000)
    adm = 22;
  else
    adm = 28;

  document.getElementById('adm').value = adm;
  administrativo.value = "S/."+adm+".00";
}


function calcular_cuota(){

	if(!IsNumeric(document.getElementById('total').value) || !IsNumeric(document.getElementById('cuotas').value)){
	  if(!IsNumeric(document.getElementById('total').value))  alert("No ha ingresado un monto correcto");
	  if(!IsNumeric(document.getElementById('cuotas').value))  alert("No ha ingresado un plazo de pagos correcto");
	}else{
	  ajax=nuevoAjax();
	  sent="total="+document.getElementById('total').value+"&cuotas="+document.getElementById('cuotas').value;
	  ajax.open("POST", "wp-content/themes/themasterplan_tma_v1.4/tma/calcular_cuota.php",true);
	  ajax.onreadystatechange=function() {
		  if (ajax.readyState==4) {
			  var ajax_res = ajax.responseText;
			  var resultado = ajax_res.split(":::");
			  document.getElementById('cuota_mensual').innerHTML = resultado[0];
			  document.getElementById('cronograma').innerHTML = resultado[1];
			  document.getElementById('cronograma').style.display = 'none';
		  }
	  }
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  ajax.send(sent);
      }
}

function ver_cronograma(){
	document.getElementById('cronograma').style.display = 'block';
} 

function limpiarForm(){
  document.getElementById('frm').reset();
  document.getElementById('cuota_mensual_').value = '';
  document.getElementById('administrativo').value = '';
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   if(sText.length == 0)
      IsNumber = false;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

