Number.prototype.decimal = function (num) { 
    pot = Math.pow(10,num); 
    return parseInt(this * pot) / pot; 
} 

function formatNumber(num,prefix){
	prefix = prefix || '';
	num += '';
	var splitStr = num.split('.');
	var splitLeft = splitStr[0];
	var splitRight = splitStr.length > 1 ? ',' + splitStr[1] : '';
	var regx = /(\d+)(\d{3})/;
	while (regx.test(splitLeft)) {
	splitLeft = splitLeft.replace(regx, '$1' + '.' + '$2');
	}
	return prefix + splitLeft + splitRight;
}

function adaptaNumero(valor){
		valor=valor.replace('.','');
		valor=valor.replace(',','.');
		valor=parseInt(valor);
		return valor;
}

function calcularValores(valor,c,id){
		valor=adaptaNumero(valor);			
		if (isNaN(valor)) { 
			valor=0;
      	}
		peso=eval(valor/c).decimal(3);	
		if (id!=1){
			document.getElementById(1).value=formatNumber(peso,'');
		}
		if (id!=2){
			document.getElementById(2).value=formatNumber(eval(peso*document.getElementById(2).name).decimal(3),''); 
		}
		if (id!=3){
			document.getElementById(3).value=formatNumber(eval(peso*document.getElementById(3).name).decimal(3),'');
		}	
		
		if (id!=4){
			document.getElementById(4).value=formatNumber(eval(peso*document.getElementById(4).name).decimal(3),'');
		}	
		
		if (id!=5){
			document.getElementById(5).value=formatNumber(eval(peso*document.getElementById(5).name).decimal(3),'');
		}	
		
		if (id!=6){
			document.getElementById(6).value=formatNumber(eval(peso*document.getElementById(6).name).decimal(3),'');
		}	
		
		if (id!=7){
			document.getElementById(7).value=formatNumber(eval(peso*document.getElementById(7).name).decimal(3),'');
		}	
		
		if (id!=9){
			document.getElementById(9).value=formatNumber(eval(peso*document.getElementById(9).name).decimal(3),'');
		}	
		
		if (id!=10){
			document.getElementById(10).value=formatNumber(eval(peso*document.getElementById(10).name).decimal(3),'');
		}	

		if (id!=11){
			document.getElementById(11).value=formatNumber(eval(peso*document.getElementById(11).name).decimal(3),'');
		}	

		if (id!=12){
			document.getElementById(12).value=formatNumber(eval(peso*document.getElementById(12).name).decimal(3),'');
		}
		
		if (id!=13){
			document.getElementById(13).value=formatNumber(eval(peso*document.getElementById(13).name).decimal(3),'');
		}
		
		if (id!=14){
			document.getElementById(14).value=formatNumber(eval(peso*document.getElementById(14).name).decimal(3),'');
		}
	}
	
function obtenerFechaYHora(){
	var IE = (navigator.userAgent.indexOf("Opera")==-1 && navigator.userAgent.indexOf("MSIE")!=-1 ? true : false);
	var d=new Date();
	var dia=new Array(7);
	var mes=new Array(12);
	var year;
	dia[0]="Domingo";
	dia[1]="Lunes";
	dia[2]="Martes";
	dia[3]="Miércoles";
	dia[4]="Jueves";
	dia[5]="Viernes";
	dia[6]="Sábado";
	mes[0]="enero";
	mes[1]="febrero";
	mes[2]="marzo";
	mes[3]="abril";
	mes[4]="mayo";
	mes[5]="junio";
	mes[6]="julio";
	mes[7]="agosto";
	mes[8]="septiembre";
	mes[9]="octubre";
	mes[10]="noviembre";							
	mes[11]="diciembre";
	
	if (IE)
	{
		year=d.getYear();
	}
	else
	{
		year=d.getYear()+1900;
	}
	//document.write("Fecha: ");
	document.write(dia[d.getDay()]+" "+ d.getDate() +" de "+mes[d.getMonth()]+" de "+year);

}

	function EvaluateText(cadena, obj, e){
		opc = false;
		tecla = (document.all) ? e.keyCode : e.which;
		if (cadena == "%d")
		if (tecla > 47 && tecla < 58 || tecla == 8)
		opc = true;
		if (cadena == "%f"){
		if (tecla > 47 && tecla < 58 || tecla == 8)
		opc = true;
		if (obj.value.search("[.*]") == -1 && obj.value.length != 0)
		if (tecla == 46)
		opc = true;
		}
		return opc;
	}

// Reloj ***********************************************************************************************
function JSClock() {          
	var time = new Date()          
	var hour = time.getHours()          
	var minute = time.getMinutes()          
	var second = time.getSeconds()          
	var temp = ((hour > 12) ? hour - 12 : hour)          
	temp += ((minute < 10) ? ":0" : ":") + minute          
	temp += ((second < 10) ? ":0" : ":") + second          
	temp += (hour >= 12) ? "&nbsp;P.M." : "&nbsp;A.M."          
	document.getElementById("relojito").innerHTML = temp
	//document.write(temp)
	id = setTimeout("JSClock()",1000)
}

