/* Funciones javascript */

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function addbookmark() {
	if ( navigator.appName != 'Microsoft Internet Explorer' ) {
		window.sidebar.addPanel('MicroSkiManager.com','http://www.microskimanager.com','');
	} else {
		window.external.AddFavorite('http://www.microskimanager.com','MicroSkiManager.com');
	}
}

function calcula_incentivo(tipo_inc) {
	if (tipo_inc == 1) {
		var a_pagar = parseInt(document.getElementById('inc_1').value);
		var a_dias = parseInt(document.getElementById('dias_1').value);
		var total = a_pagar * a_dias;

		document.getElementById('valor_inc_1').value = total + ' msm';	
	} else {
		var total = parseInt(document.getElementById('inc_2').value);
		document.getElementById('valor_inc_2').value = total + ' msm';			
	}
}

function calcula_credito1(cred) {
	if (cred == 1) {
		var dinero = parseInt(document.getElementById('dinero1').value);
		var plazo = parseInt(document.getElementById('plazo1').value);			
	} else {
		var dinero = parseInt(document.getElementById('dinero2').value);
		var plazo = parseInt(document.getElementById('plazo2').value);			
	}

	var interes = 0;
	switch (plazo) {
		case 2 : interes = 5; break;
		case 5 : interes = 10; break;
		case 10 : interes = 20; break;
	}

	var total = (dinero * (interes + 100)) / 100;
	var semanal = total / plazo;

	if (cred == 1) {
		document.getElementById('semanal1').value = semanal + ' msm / sem';
		document.getElementById('total1').value = total + ' msm';
	} else {
		document.getElementById('semanal2').value = semanal + ' msm / sem';
		document.getElementById('total2').value = total + ' msm';		
	}
}

function calcula_prep(aforo_act) {
	var total = 0;
	var total_horas = 0;
	var nuevacap = parseInt(document.getElementById('nuevacap').value);
	var prec_asiento = 50;

	if (isNaN(nuevacap)) { 
		nuevacap = 0;
		document.getElementById('nuevacap').value = 0;
	}
	var capacidad_restante = 2000 - aforo_act;

	if (nuevacap > capacidad_restante) { 
		nuevacap = capacidad_restante;
		document.getElementById('nuevacap').value = capacidad_restante;
	}

	if (aforo_act >= 1500) {
		prec_asiento = 100;
	} else if (aforo_act >= 1000) {
		prec_asiento = 80;
	} else if (aforo_act >= 500) {
		prec_asiento = 60;
	}

	total = total + (prec_asiento * nuevacap);
	total_horas = Math.ceil(total / 500);

	if (document.getElementById('calefaccion')) {
		if (document.getElementById('calefaccion').checked) total = total + 5000; 	
	}

	if (document.getElementById('cubierta')) {
		if (document.getElementById('cubierta').checked) total = total + 7000; 		
	}

	if (document.getElementById('accesos')) {
		if (document.getElementById('accesos').checked) total = total + 10000; 		
	}

	if (document.getElementById('accesos1')) {
		if (document.getElementById('accesos1').checked) total = total + 20000; 		
	}

	if (document.getElementById('iluminacion')) {
		if (document.getElementById('iluminacion').checked) total = total + 5000; 		
	}

	if (document.getElementById('iluminacion1')) {
		if (document.getElementById('iluminacion1').checked) total = total + 15000; 		
	}	

	document.getElementById('presupuesto').value = total + ' msm';
	document.getElementById('tiempo_est').value = total_horas + ' horas';
}



function masomenos(capa,valor) {
	var inicio = document.getElementById(capa).value;
	if (inicio >= 1 && inicio < 5 && valor == 'mas') {
		document.getElementById(capa).value = parseInt(inicio) + 1;
	} 
	if (inicio > 1 && inicio <= 5 && valor == 'menos') {
		document.getElementById(capa).value = inicio - 1;
	}
}

function mostrar(capa) { 
	if (capa != 'elim_club') {
		document.getElementById(capa).style.display = 'block';
	} else if (capa == 'elim_club') {
		var check_el = document.getElementById('eliminar');
		if (check_el.checked) document.getElementById(capa).style.display = 'block';
	}
}

function ocultar(capa) { 
	document.getElementById(capa).style.display = 'none';
}