// JavaScript Document
function borra_hijos(parent) {
	if(parent) {
		while (parent.firstChild) {
			parent.removeChild(parent.firstChild);
		}
	}
}
function pasajeros(cantidad) {
	
	p3 = document.getElementById('pregunta3');
	p2 = document.getElementById('pregunta2');
	borra_hijos(p3);
	borra_hijos(p2);
	
	new Ajax.Updater('pregunta2', 'cuestionario.php?pregunta=2&pasajeros='+cantidad, { method: 'get', evalScripts: true, asynchronous: false });
}
function nombresPasajeros() {
	new Ajax.Updater('pregunta3', 'cuestionario.php?pregunta=3', { method: 'get', evalScripts: true, asynchronous: false });
}

function cartelOver(obj) {
	obj.style.left = "5px";
	obj.style.top = "4px";
}
function cartelOut(obj) {
	obj.style.left = "3px";
	obj.style.top = "1px";
}
function cartelClick(url) {
	document.location.href = url;	
}
function cartelClickEvento(url) {
	document.location.href = "reserva_seleccion.php?idevento="+evento;	
}
// cambia fotos automaticamente
function rotaFotos() {
	this.objFoto = null;
	this.foto = new Array();
	this.fotoActual = 0;
	this.fotoAnterior = null;
	this.cantidadDeFotos = 0;

	
	este = this;

	this.agregarFoto = function(url,descripcion,link,tipo) {
		this.foto[this.cantidadDeFotos] = new Array(url,descripcion,link,tipo);
		this.cantidadDeFotos++;
	}
	this.iniciarRotacion = function() {	
		this.objFoto = document.getElementById("foto");
		this.objFotoLink = document.getElementById("fotoLink");
		this.textoFoto = document.getElementById("textoFoto");
		this.int = setInterval(this.rotar,4000);
	}
	this.rotar = function() {
		este.fotoAnterior = este.fotoActual;
		este.fotoActual++;
		if(este.fotoActual==este.cantidadDeFotos) {
			este.fotoActual = 0;	
		}
		// cambio foto
		este.objFoto.src = este.foto[este.fotoActual][0];
		este.textoFoto.innerHTML = este.foto[este.fotoActual][1];
		// cambio link
		este.objFotoLink.href = este.foto[este.fotoActual][2];
		// cambio indicador 01 02 03 04
		ind = document.getElementById("foto"+(este.fotoActual));
		ind.className = este.claseActiva(este.foto[este.fotoActual][3]);
		ind = document.getElementById("foto"+(este.fotoAnterior));
		ind.className = este.claseNoActiva(este.foto[este.fotoAnterior][3]);
	}
	this.claseActiva = function(tipo) {
		switch(tipo) {
			case "Viaje":
				return "verde foto_nro_activo";
			break;
			case "Evento":
				return "naranja foto_nro_activo";
			break;
			case "Otro":
				return "rojo foto_nro_activo";
			break;
		}
	}
	this.claseNoActiva = function(tipo) {
		switch(tipo) {
			case "Viaje":
				return "fondo_verde foto_nro";
			break;
			case "Evento":
				return "fondo_naranja foto_nro";
			break;
			case "Otro":
				return "fondo_rojo foto_nro";
			break;
		}
	}
	
	
	this.cambiaFoto = function(nro) {
		clearInterval(this.int);
		this.fotoAnterior = this.fotoActual;
		this.fotoActual = nro;
		// cambio foto
		this.objFoto.src = this.foto[this.fotoActual][0];
		this.textoFoto.innerHTML = this.foto[this.fotoActual][1];
		// cambio link
		this.objFotoLink.href = this.foto[este.fotoActual][2];
		// cambio indicador 01 02 03 04
		ind = document.getElementById("foto"+(this.fotoActual));
		ind.className = this.claseActiva(this.foto[this.fotoActual][3]);
		ind = document.getElementById("foto"+(this.fotoAnterior));
		ind.className = this.claseNoActiva(this.foto[this.fotoAnterior][3]);
		this.iniciarRotacion();
	}
}



function fotoOver(obj) {
	obj.style.opacity = "0.85";
	obj.style.filter = "alpha(opacity=85)";
}
function fotoOut(obj) {
	obj.style.opacity = "1";
	obj.style.filter = "alpha(opacity=100)";
}

// *** AJAX PRECIO VIAJE
function precioViaje(idviaje) {
	this.id = idviaje;
	this.actualizar = function(comp,hab) {
		this.bloquear();
		new Ajax.Updater('precio', 'ajax_viaje.php?hab='+hab+'&comp='+comp+'&idviaje='+this.id,{ method: 'get', evalScripts: true, asynchronous: false });
	}
	this.bloquear = function() {
		// busco todos los radio y los bloqueo
		for(c=1;c<4;c++) {
			if(obj = document.getElementById('comp_'+c)) {
				obj.disabled = true;	
			}
		}
		hab = 1;
		while(obj = document.getElementById('hab_'+hab)) {
			obj.disabled = true;
			hab++;	
		}
	}
}
function precioEvento(idevento) {
	this.id = idevento;
	this.actualizar = function(sel) {
		this.bloquear();
		new Ajax.Updater('precio', 'ajax_evento.php?sel='+sel+'&idevento='+this.id,{ method: 'get', evalScripts: true, asynchronous: false });
	}
	this.bloquear = function() {
		// busco todos los radio y los bloqueo
		for(c=1;c<4;c++) {
			if(obj = document.getElementById('desc_'+c)) {
				obj.disabled = true;	
			}
		}
	}
}

// funciones del pago on line
function muestraCuotas(tarjeta) {
	botonIE = document.getElementById('boton');
	importe2 = document.getElementById('importe').value;
	medioDePago = document.getElementById('d_mediopago');
	d_cuota = document.getElementById("d_cuotas");
	d_monto = document.getElementById("d_monto");
	d_cuota.value = 0;
	d_monto.value = 0;
	new Ajax.Updater('cuotas', 'ajax_cuotas.php?tarjeta='+tarjeta+'&importe='+importe2,{ method: 'get', evalScripts: true, asynchronous: false });	
	// actualizo la tarjeta en al form
	switch(tarjeta) {
		case "Mastercard":
		case "Mastercard Citi":
			medioDePago.value = 15;
		break;
		case "Visa":
		case "Visa Citi":
			medioDePago.value = 1;
		break;
		case "Diners Club":
		case "Diners Club Citi":
			medioDePago.value = 8;
		break;
		case "American Express":
			medioDePago.value = 6;
		break;
		case "Pago Facil (Efectivo)":
			medioDePago.value = 999;
		break;
	}
	
}
function cambiaCuota(cuota,monto) {
	d_cuota = document.getElementById("d_cuotas");
	d_monto = document.getElementById("d_monto");
	d_cuota.value = cuota;
	d_monto.value = monto;
}
function enviarFormularioPago(valorMaximo,idreserva) {
	d_cuota = document.getElementById("d_cuotas");
	d_monto = document.getElementById("d_monto");
	d_medio = document.getElementById('d_mediopago');
	importe2 = document.getElementById('importe').value;
	tarj = tarjetaElegida();
	if(d_monto.value>0 && importe2<=valorMaximo && d_cuota.value>0 && d_medio.value>0 && d_medio.value<16) {
		if(tarj.indexOf('Citi')!=-1) {
			mostrarCartelChequeoCiti(tarj);
		} else {
			document.form_pagar.submit();	
		}
	} else if(d_monto.value>0 && d_medio.value==999 && importe2<=valorMaximo) {
			window.open("pagofacil.php?importe="+importe2+"&idreserva="+idreserva,null,"height=760,width=760,status=yes,toolbar=no,menubar=no,location=no");
			window.location.href = "Mi-Cuenta.html";
	} else {
		alert("Debe seleccionar Medio de Pago, Plan de Pago y el importe a pagar no puede superar el saldo total a pagar.");
	}
}
function tarjetaElegida() {
	tar = 1;
	while(t = document.getElementById('tarjeta'+tar)) {
		if(t.checked) {
			return t.value;
		}
		tar++;	
	}
}
function pagoFacil(valor,idreserva) {
	window.open("pagofacil.php?importe="+importe2+"&idreserva="+idreserva,null,"height=760,width=760,status=yes,toolbar=no,menubar=no,location=no");
}
function mostrarCartelChequeoCiti(tarjeta2) {
		citi = document.getElementById('chequeo_citi');
		numero1 = document.getElementById('numero_tarjeta1');
		numero2 = document.getElementById('numero_tarjeta2');
		numero3 = document.getElementById('numero_tarjeta3');
		numero4 = document.getElementById('numero_tarjeta4');	
		logo = document.getElementById('logo_tarjeta');
		
		numero1.value = "";
		numero2.value = "";
		numero3.value = "";
		numero4.value = "";
		switch (tarjeta2) {
			case 'Diners Club Citi':
				numero4.style.visibility = 'hidden';
				numero2.size = '6';
				numero2.maxLength = '6';
				logo.className = 'chequeo_logo_diners';
				break;
			case 'Mastercard Citi':
				numero4.style.visibility = 'visible';
				numero2.size = '4';
				numero2.maxLength = '4';
				logo.className = 'chequeo_logo_mastercard';
				break;
			case 'Visa Citi':
				numero4.style.visibility = 'visible';
				numero2.size = '4';
				numero2.maxLength = '4';
				logo.className = 'chequeo_logo_visa';
				break;				
		}
		
		citi.style.visibility = "visible";
}
function chequearNumeroDeTarjeta() {
	numero1 = document.getElementById('numero_tarjeta1');
	numero2 = document.getElementById('numero_tarjeta2');
	numero3 = document.getElementById('numero_tarjeta3');
	numero4 = document.getElementById('numero_tarjeta4');
	nro = document.getElementById('d_nrooperacion');
	numero = numero1.value+numero2.value+numero3.value+numero4.value;
	monto = document.getElementById("d_monto").value/100;
	cuotas2 = document.getElementById("d_cuotas").value;
	
	tipoTarjeta = tarjetaElegida();
	new Ajax.Request('chequearTarjeta.php?tarjeta='+numero+'&tipo='+tipoTarjeta+'&nrooperacion='+nro.value+'&importe='+monto+'&cuotas='+cuotas2,				
		{
		onSuccess: function(response) {
			if(response.responseText=="OK") {
				document.form_pagar.submit();
			} else {
				alert(response.responseText);
			}
			}
		}
	);
}
function ocultarCartelChequeoCiti() {
	numero4 = document.getElementById('numero_tarjeta4');	
		citi = document.getElementById('chequeo_citi');
		citi.style.visibility = "hidden";
		numero4.style.visibility = 'hidden';
}
function cambiaImporte() {
	// busco que objeto que tarjeta esta seleecionada
	tar = 1;
	while(t = document.getElementById('tarjeta'+tar)) {
		if(t.checked) {
			muestraCuotas(t.value);
			break;
		}
		tar++;	
	}
}
function controlaNumeros(evt) {
  var keyPressed = (evt.which) ? evt.which : event.keyCode
  if(keyPressed<32 || (keyPressed>47 && keyPressed<58 )) {
	return true;  
  } else {
	return false;
  }
}
// pop up para documentacion
function abre_ventana(URL) {
	 window.open(URL,"ventana1","width=650,height=650,scrollbars=YES");
}
/************************************/
/* FUNCIONES DE SUCURSAL COLAPSABLE */
/************************************/
agrandaSucursal = new Array();
function verMapaSucursal(idSucursal) {
	sucursal = document.getElementById("suc"+idSucursal);
	lk = document.getElementById("verMapaSucursal"+idSucursal);
	mapaSuc = document.getElementById("mapaSucursal"+idSucursal);
	lk.innerHTML = '<a href="javascript:cerrarMapaSucursal('+idSucursal+');" class="link_verde">cerrar x</a>';
	agrandaSucursal[idSucursal] = new Tween(sucursal.style, 'height', Tween.elasticEaseOut, 90, 484, 1, 'px');
	agrandaSucursal[idSucursal].start();
	mapaSuc.style.visibility = "visible";
	
}
function cerrarMapaSucursal(idSucursal) {
	sucursal = document.getElementById("suc"+idSucursal);
	lk = document.getElementById("verMapaSucursal"+idSucursal);
	mapaSuc.style.visibility = "hidden";
	lk.innerHTML = '<a href="javascript:verMapaSucursal('+idSucursal+');" class="link_verde">ver mapa &raquo;</a>';
	agrandaSucursal[idSucursal] = new Tween(sucursal.style, 'height', Tween.regularEaseOut, 484, 90, 0.3, 'px');
	agrandaSucursal[idSucursal].start();
	
}
function Mapa(lat,lon,zoom,id) {
	this.map = new GMap2(document.getElementById(id));
	this.map.addControl(new GLargeMapControl());
	this.map.addControl(new GMapTypeControl());
	this.map.setCenter(new GLatLng(lat,lon), zoom);
	this.map.setMapType(G_NORMAL_MAP);
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	this.baseIcon = new GIcon(G_DEFAULT_ICON);
	this.baseIcon.shadow = "img/marcas/shadowAti.png";
	this.baseIcon.iconSize = new GSize(32, 39);
	this.baseIcon.shadowSize = new GSize(42, 44);
	this.baseIcon.iconAnchor = new GPoint(16, 38);
	this.baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
	this.marcador = new Array();
	this.latlng = new Array();
	
	obj = this;
	
	this.agregarMarca = function(nroPin,latitud,longitud) {
		var atiIcon = new GIcon(this.baseIcon);
		if(nroPin=="ati") {
			atiIcon.image = "img/marcas/marcaAti.png";		
		} else {
			atiIcon.image = "img/marcas/marca"+nroPin+".png";	
		}
		
		
		markerOptions = { icon:atiIcon};
		var point = new GLatLng(latitud,longitud);
		this.marcador[nroPin] = new GMarker(point,markerOptions);
    	this.map.addOverlay(this.marcador[nroPin]);
	}
}

