//Expresiones Regulares.
var reAlgo=/\S+/;//Para comprobar si el campo está vacío.
var reNum=/^(\d)*$/;//Para comprobar si un campo es númerico.

// ------------- FUNCIONES PARA COMPROBACIONES ----------------//

function vBorrar(formObj) {
	formObj.txtBase.value=""
	formObj.txtPorc.value="100"		
	formObj.txtResultado.value=""
}
		
function vCheck(formObj) {
	if (!reAlgo.test(formObj.txtBase.value)) {
		alert("<?=CAMPO_VACIO?>");
		formObj.txtBase.focus();
		return;
	}			
	if (!reAlgo.test(formObj.txtPorc.value)) {
		alert("<?=CAMPO_VACIO?>");
		formObj.txtPorc.focus();
		return;
	}
		
formObj.submit();
}




function vCalcula(formObj) {			

			var strbase
			var matriz = new Array(21);
			var bolContinua 
			var i 
			var fltbase 
			var intPorc 
			var res
			
			
			strbase = formObj.txtBase.value
			
			bolContinua = true		
			i = 0;
			fltBase = parseFloat(formObj.txtBase.value);
			intPorc = parseFloat(formObj.txtPorc.value);
			res=0;
			
			if ((formObj.rbTipo[0].checked)||(formObj.rbTipo[1].checked))
			{
				for (var j=0;j<21;j++)	matriz[j]=0;

				while (bolContinua)
				{
					switch (i)
					{
						case 0:
							if (fltBase>300)
							{
								matriz[i]=300;
								i++;
							}
							else
							{
								matriz[i]=fltBase;
								bolContinua=false;
							}
							break;
						case 1:
							if (fltBase>600)
							{
								matriz[i]=600-300;
								i++;
							}
							else
							{
								matriz[i]=fltBase-300;
								bolContinua=false;
							}
							break;
						case 2:
							if (fltBase>3000)
							{
								matriz[i]=3000-600;
								i++;
							}
							else
							{
								matriz[i]=fltBase-600;
								bolContinua=false;
							}
							break;
						case 3:
							if (fltBase>6000)
							{
								matriz[i]=6000-3000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-3000;
								bolContinua=false;
							}
							break;
						case 4:
							if (fltBase>12000)
							{
								matriz[i]=12000-6000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-6000;
								bolContinua=false;
							}
							break;
						case 5:
							if (fltBase>24000)
							{
								matriz[i]=24000-12000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-12000;
								bolContinua=false;
							}
							break;
						case 6:
							if (fltBase>48000)
							{
								matriz[i]=48000-24000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-24000;
								bolContinua=false;
							}
							break;
						case 7:
							if (fltBase>90000)
							{
								matriz[i]=90000-48000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-48000;
								bolContinua=false;
							}
							break;
						case 8:
							if (fltBase>300000)
							{
								matriz[i]=300000-90000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-90000;
								bolContinua=false;
							}
							break;
						case 9:
							if (fltBase>600000)
							{
								matriz[i]=600000-300000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-300000;
								bolContinua=false;
							}
							break;
						case 10:
							if (fltBase>1200000)
							{
								matriz[i]=1200000-600000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-600000;
								bolContinua=false;
							}
							break;
						case 11:
							if (fltBase>1800000)
							{
								matriz[i]=1800000-1200000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-1200000;
								bolContinua=false;
							}
							break;
						case 12:
							if (fltBase>2400000)
							{
								matriz[i]=2400000-1800000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-1800000;
								bolContinua=false;
							}
							break;
						case 13:
							if (fltBase>3000000)
							{
								matriz[i]=3000000-2400000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-2400000;
								bolContinua=false;
							}
							break;
						case 14:
							if (fltBase>3600000)
							{
								matriz[i]=3600000-3000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-3000000;
								bolContinua=false;
							}
							break;
						case 15:
							if (fltBase>4200000)
							{
								matriz[i]=4200000-3600000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-3600000;
								bolContinua=false;
							}
							break;
						case 16:
							if (fltBase>4800000)
							{
								matriz[i]=4800000-4200000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-4200000;
								bolContinua=false;
							}
							break;
						case 17:
							if (fltBase>5400000)
							{
								matriz[i]=5400000-4800000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-4800000;
								bolContinua=false;
							}
							break;
						case 18:
							if (fltBase>6000000)
							{
								matriz[i]=6000000-5400000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-5400000;
								bolContinua=false;
							}
							break;
						case 19:
							matriz[i]=fltBase-6000000;
							bolContinua=false;
							break;

					}
				}
			
				res = res + (((matriz[0]*25/100)*intPorc)/100);
				res += ((matriz[1]*22/100)*intPorc)/100;
				res += ((matriz[2]*16/100)*intPorc)/100;
				res += ((matriz[3]*14/100)*intPorc)/100;
				res += ((matriz[4]*12/100)*intPorc)/100;
				res += ((matriz[5]*11/100)*intPorc)/100;
				res += ((matriz[6]*9/100)*intPorc)/100;
				res += ((matriz[7]*8/100)*intPorc)/100;
				res += ((matriz[8]*8/100)*intPorc)/100;
				res += ((matriz[9]*6/100)*intPorc)/100;
				res += ((matriz[10]*5/100)*intPorc)/100;
				res += ((matriz[11]*4/100)*intPorc)/100;
				res += ((matriz[12]*4/100)*intPorc)/100;
				res += ((matriz[13]*4/100)*intPorc)/100;
				res += ((matriz[14]*3/100)*intPorc)/100;
				res += ((matriz[15]*3/100)*intPorc)/100;
				res += ((matriz[16]*3/100)*intPorc)/100;
				res += ((matriz[17]*3/100)*intPorc)/100;
				res += ((matriz[18]*3/100)*intPorc)/100;
				res += ((matriz[19]*parseFloat(1.5)/100)*intPorc)/100;
			}

			else
			{

				for (var j=0;j<21;j++)
					matriz[j]=0;

				while (bolContinua)
				{
					switch (i)
					{
						case 0:
							if (fltBase>10000)
							{
								matriz[i]=10000;
								i++;
							}
							else
							{
								matriz[i]=fltBase;
								bolContinua=false;
							}
							break;
						case 1:
							if (fltBase>100000)
							{
								matriz[i]=100000-10000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-10000;
								bolContinua=false;
							}
							break;
						case 2:
							if (fltBase>300000)
							{
								matriz[i]=300000-100000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-100000;
								bolContinua=false;
							}
							break;
						case 3:
							if (fltBase>500000)
							{
								matriz[i]=500000-300000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-300000;
								bolContinua=false;
							}
							break;
						case 4:
							if (fltBase>1000000)
							{
								matriz[i]=1000000-500000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-500000;
								bolContinua=false;
							}
							break;
						case 5:
							if (fltBase>2000000)
							{
								matriz[i]=2000000-1000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-1000000;
								bolContinua=false;
							}
							break;
						case 6:
							if (fltBase>5000000)
							{
								matriz[i]=5000000-2000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-2000000;
								bolContinua=false;
							}
							break;
						case 7:
							if (fltBase>10000000)
							{
								matriz[i]=10000000-5000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-5000000;
								bolContinua=false;
							}
							break;
						case 8:
							if (fltBase>50000000)
							{
								matriz[i]=50000000-10000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-10000000;
								bolContinua=false;
							}
							break;
						case 9:
							if (fltBase>75000000)
							{
								matriz[i]=75000000-50000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-50000000;
								bolContinua=false;
							}
							break;
						case 10:
							if (fltBase>100000000)
							{
								matriz[i]=100000000-75000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-75000000;
								bolContinua=false;
							}
							break;
						case 11:
							if (fltBase>200000000)
							{
								matriz[i]=200000000-100000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-100000000;
								bolContinua=false;
							}
							break;
						case 12:
							if (fltBase>300000000)
							{
								matriz[i]=300000000-200000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-200000000;
								bolContinua=false;
							}
							break;
						case 13:
							if (fltBase>400000000)
							{
								matriz[i]=400000000-300000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-300000000;
								bolContinua=false;
							}
							break;
						case 14:
							if (fltBase>500000000)
							{
								matriz[i]=500000000-400000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-400000000;
								bolContinua=false;
							}
							break;
						case 15:
							if (fltBase>600000000)
							{
								matriz[i]=600000000-500000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-500000000;
								bolContinua=false;
							}
							break;
						case 16:
							if (fltBase>700000000)
							{
								matriz[i]=700000000-600000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-600000000;
								bolContinua=false;
							}
							break;
						case 17:
							if (fltBase>800000000)
							{
								matriz[i]=800000000-700000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-700000000;
								bolContinua=false;
							}
							break;
						case 18:
							if (fltBase>900000000)
							{
								matriz[i]=900000000-800000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-800000000;
								bolContinua=false;
							}
							break;
						case 19:
							if (fltBase>1000000000)
							{
								matriz[i]=1000000000-900000000;
								i++;
							}
							else
							{
								matriz[i]=fltBase-900000000;
								bolContinua=false;
							}
							break;
						case 20:
							matriz[i]=fltBase-1000000000;
							bolContinua=false;
							break;

					}
				}
			
				res = res + (((matriz[0]*25/100)*intPorc)/100);
				res += ((matriz[1]*22/100)*intPorc)/100;
				res += ((matriz[2]*16/100)*intPorc)/100;
				res += ((matriz[3]*15/100)*intPorc)/100;
				res += ((matriz[4]*13/100)*intPorc)/100;
				res += ((matriz[5]*11/100)*intPorc)/100;
				res += ((matriz[6]*10/100)*intPorc)/100;
				res += ((matriz[7]*9/100)*intPorc)/100;
				res += ((matriz[8]*8/100)*intPorc)/100;
				res += ((matriz[9]*7/100)*intPorc)/100;
				res += ((matriz[10]*6/100)*intPorc)/100;
				res += ((matriz[11]*5/100)*intPorc)/100;
				res += ((matriz[12]*4/100)*intPorc)/100;
				res += ((matriz[13]*4/100)*intPorc)/100;
				res += ((matriz[14]*4/100)*intPorc)/100;
				res += ((matriz[15]*3/100)*intPorc)/100;
				res += ((matriz[16]*3/100)*intPorc)/100;
				res += ((matriz[17]*3/100)*intPorc)/100;
				res += ((matriz[18]*3/100)*intPorc)/100;
				res += ((matriz[19]*3/100)*intPorc)/100;
				res += ((matriz[20]*parseFloat(1.5)/100)*intPorc)/100;
			}
			formObj.txtResultado.value = res;
			

			
		}
