
// JavaScript Document

// ****************************************
// ******* funciones del calendario *******
// ****************************************
nombreMes = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
calen = new Array();
function creaCalendario(cod,m,a,id,f,fb,nombreDestino) {
	calen[id] = new calendario(cod,m,a,id,f,fb,nombreDestino);
	llenarCalendarios(id);
}
	
function calendario(cod,m,a,id,f,fb,nomDest) {
	this.codigo = cod;
	this.mes = m;
	this.ano = a;
	this.id = id;
	this.fechas = f;
	this.fechasBaratas = fb;
	this.mes_inicial = m;
	this.ano_inicial = a;
	this.nombreDestino = nomDest;
	eliminar_anterior(id);
	
}
function eliminar_anterior(id) {
	ba = document.getElementById("anterior_"+id);
	borra_hijos(ba);
	ba.appendChild(document.createTextNode(String.fromCharCode(171)+' Anterior'));
	ba.style.color = "#CCCCCC";
}
function borra_hijos(parent) {
	if(parent) {
		while (parent.firstChild) {
			parent.removeChild(parent.firstChild);
		}
	}
}
function mostrar_anterior(id) {
	ba = document.getElementById("anterior_"+id);
	borra_hijos(ba);
	obj_link = document.createElement('a');
	obj_link.href = "javascript:mesAnterior("+id+");";
	obj_link.className ="link7";
	obj_link.appendChild(document.createTextNode('Anterior'));
	ba.appendChild(document.createTextNode(String.fromCharCode(171)+' '));
	ba.appendChild(obj_link);
	ba.style.color = "#76787B";
}
function llenarCalendarios(id) {
	obj = calen[id];
	aa = obj.ano;		
	mesTemp = obj.mes;
	
	for(cal=1;cal<=3;cal++) {
		mm = mesTemp+cal-2;
		if(mm>11) {
			mm = 0;
			mesTemp = 0;
			aa++;
		}
		comienzo = new Date(aa,mm,1);
		com = comienzo.getDay()+1;
		final = new Date(aa,mm+1,0);
		fin = final.getDate();
		
		titulo = document.getElementById('titulo_cal_'+id+'_'+cal);
		titulo.childNodes[0].replaceData(0,100,nombreMes[mm]+" "+aa);
	
		dia = 1;
		flag = false;
		ds = 1;
		for(div=1;div<=42;div++) {
			obj_div = document.getElementById('cal_'+id+'_'+cal+'_'+div);
			if(div>=com && flag==false) {
				flag = true;
			}
			while (obj_div.firstChild) {
			  obj_div.removeChild(obj_div.firstChild);
			}
			if(dia<=fin && flag==true) {
				if(controla_fechas(obj,dia,mm,aa)) {
					obj_link = document.createElement('a');
					
					obj_link.href = "resumen-de-sus-vacaciones-a-"+obj.nombreDestino+"/viaje-"+obj.codigo+"-"+dia+"-"+(mm+1)+"-"+aa+".html";			
					if(controla_fechas_baratas(obj,dia,mm,aa)) {
						obj_link.className ="calendario_fecha_barata";
					} else {
						obj_link.className ="calendario_fecha";
					}
					obj_link.appendChild(document.createTextNode(dia));
					obj_div.appendChild(obj_link);
				} else {
					obj_div.appendChild(document.createTextNode(dia));
				}
				if( ds==1 || ds==7 ) {
					obj_div.style.color = "#AAAAAA";
				}
				dia++;
			}
			ds = (ds==7)? ds=1 : ds+1;
		}
	}
}
// controlo si este dia esta entre las fechas posibles de partida
function controla_fechas(obj,d,m,a) {
	retorno = false;
	for( i=0; i<obj.fechas.length ; i++ ) {
		dia_pos = obj.fechas[i].substr(0,2);
		mes_pos = obj.fechas[i].substr(3,2);
		ano_pos = obj.fechas[i].substr(6,4);
		if(dia_pos==d && mes_pos==m+1 && ano_pos==a) {
			retorno = true;
		}
	}		
	return retorno;
}
// controlo si este dia esta entre las fechas posibles de partida y es mas
// barata
function controla_fechas_baratas(obj,d,m,a) {
	retorno = false;
	for( i=0; i<obj.fechasBaratas.length ; i++ ) {
		dia_pos = obj.fechasBaratas[i].substr(0,2);
		mes_pos = obj.fechasBaratas[i].substr(3,2);
		ano_pos = obj.fechasBaratas[i].substr(6,4);
		if(dia_pos==d && mes_pos==m+1 && ano_pos==a) {
			retorno = true;
		}
	}
	return retorno;
}

function mesSiguiente(id) {
	obj = calen[id];
	obj.mes++;
	ba = document.getElementById("anterior_"+obj.id);
	if(obj.mes>12) {
		obj.ano++;
		obj.mes=1;
	}
	if(obj.ano_inicial!=obj.ano || obj.mes_inicial!=obj.mes) {
		mostrar_anterior(id);
	}
	llenarCalendarios(id);
}	
	
function mesAnterior(id) {
	obj = calen[id];
	ba = document.getElementById("anterior_"+obj.id);
	obj.mes--;
	if(obj.mes<1) {
		obj.ano--;
		obj.mes=12;
	}
	if(obj.ano_inicial==obj.ano && obj.mes_inicial==obj.mes) {
		eliminar_anterior(obj.id);
	}
	llenarCalendarios(id);
}

/** ******************************** */
/* FUNCIONES DE MODULOS COLAPSABLE */
/** ******************************** */	
agrandaModulo = new Array();
function elegir_fechas(id,y_px,texto) {
	if(y_px==undefined) {
		y_px = 17;
	}
	if(texto==undefined) {
		texto = "elegir fecha de salida &raquo;";
	}
	modulo = document.getElementById("colapsable_"+id);
	lk = document.getElementById("c_link_"+id);
	agrandaModulo[id] = new Tween(modulo.style, 'height', Tween.elasticEaseOut, y_px, 236, 1, 'px');
	agrandaModulo[id].start();
	lk.innerHTML = '<a href="javascript:cerrar_fechas('+id+','+y_px+',\''+texto+'\');" class="link8"><strong>cerrar x</strong></a>';
}
function cerrar_fechas(id,y_px,texto) {
	modulo = document.getElementById("colapsable_"+id);
	lk = document.getElementById("c_link_"+id);
	agrandaModulo[id] = new Tween(modulo.style, 'height', Tween.regularEaseOut, 236, y_px, 0.4, 'px');
	agrandaModulo[id].start();
	lk.innerHTML = '<a href="javascript:elegir_fechas('+id+','+y_px+',\''+texto+'\');" class="link8"><strong>'+texto+'</strong></a>';
}
/** ****************************** */
/* FUNCIONES DE GALERIA DE FOTOS */
/** ****************************** */
foto = 1;
function foto_siguiente() {
	foto = (foto>=fotos_cantidad) ? 1 : foto+1;
	muestra_foto();
}
function foto_anterior() {
	foto = (foto<=1) ? fotos_cantidad : foto-1;
	muestra_foto();

}
function muestra_foto() {
	obj = document.getElementById('foto_galeria');
	obj.src = "imagen.php?imagen="+fotos_galeria[foto];
	txt = document.getElementById('contador_fotos');
	txt.childNodes[0].replaceData(0,100,"Foto "+foto+" de "+fotos_cantidad+": ");
								  
	epi = document.getElementById('epigrafe');
	epi.childNodes[0].replaceData(0,100,epigrafe[foto]);
}
/** ****************************** */
/* FUNCIONES DE POP UP */
/** ****************************** */
var int;
function popup(event,div,p) {
	obj = document.getElementById("popup"+p);
	obj.style.visibility = "visible";
	div.style.backgroundColor = "#F9F9F9";
	
}
function popup_mueve(event,p) {
	obj = document.getElementById("popup"+p);
	obj.style.left = (event.clientX+17)+"px";
	alturaPopup = obj.offsetHeight;
	obj.style.top = (event.clientY-alturaPopup-5)+"px";
}
function no_popup(div,p) {
	obj1 = document.getElementById("popup"+p);
	obj1.style.visibility = "hidden";
	div.style.backgroundColor = "#FFFFFF";
}
/** ********************************** */
/* FUNCIONES DE POP UP HOTEL */
/** ********************************** */
var int;
function popup_hotel(event,p) {
	obj = document.getElementById("popup"+p);
	obj.style.visibility = "visible";
}
function popup_mueve_hotel(event,p) {
	obj = document.getElementById("popup"+p);
	obj.style.left = (event.clientX+17)+"px";
	alturaPopup = obj.offsetHeight;
	obj.style.top = (event.clientY-alturaPopup-5)+"px";
}
function no_popup_hotel(p) {
	obj1 = document.getElementById("popup"+p);
	obj1.style.visibility = "hidden";
	div.style.backgroundColor = "#FFFFFF";
}
/** ******************************************* */
/* FUNCIONES DE DESCRIPCION EN 2 COLUMNAS */
/** ******************************************* */
function descripcion2columas(c1,c2,txt) {
	columna_1 = document.getElementById(c1);
	columna_2 = document.getElementById(c2);
	// calculo la mitad del texto
	mitad = parseInt(txt.length/2);
	texto = txt.split(" ");
	// recorro todo en string txt
	chr = 0;
	c = columna_1;
	flagMitad = false;
	for(i=0;i<texto.length;i++) {
		chr += texto[i].length + 1;
		if(chr>=mitad && flagMitad == false) {
			alturaActual = c.offsetHeight;
			flagMitad = true;
		}
		if(flagMitad == true && c.offsetHeight>alturaActual) {
			c.style.height = alturaActual+"px";
			c.style.overflow = "hidden";
			c = columna_2;
			i--;
		}
		c.appendChild(document.createTextNode(texto[i]+" "));
	}
}
/** ****************************** */
/* FUNCIONES DE GOOGLE MAPS */
/** ****************************** */
function inicia_mapa(html,lat,lon,pin) {
	// inicia google maps en el div id="map_canvas"
	var map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GSmallMapControl());
	// map.addControl(new GMapTypeControl());
	if(pin=="SI") {
		zoom=15;
	} else {
		zoom=11;	
	}
	map.setCenter(new GLatLng(lat,lon), zoom);
	map.setMapType(G_NORMAL_MAP);
	
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "img/maps/shadow50.png";
	baseIcon.iconSize = new GSize(32, 39);
	baseIcon.shadowSize = new GSize(42, 44);
	baseIcon.iconAnchor = new GPoint(16, 38);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	if(pin=='SI') {
		// Agrego la marca de ubicacion del hotel
		  var point = new GLatLng(lat,lon);
		// texto html del marcador
		
		  var atiIcon = new GIcon(baseIcon);
		  atiIcon.image = "img/maps/marca.png";
		
		  // Set up our GMarkerOptions object
		  markerOptions = { icon:atiIcon };
		  var marker = new GMarker(point, markerOptions);
		
		  map.openInfoWindowHtml(point,  html);
		  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		  });
		  map.addOverlay(marker);
	}
}
/** ************************************************** */
/* FUNCIONES DE GOOGLE MAPS PARA HOTEL SUGERENCIAS */
/** ************************************************** */
function inicia_mapa2(lat,lon,zoom,pin) {
	// inicia google maps en el div id="map_canvas"
	var map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(lat,lon), zoom);
	map.setMapType(G_NORMAL_MAP);
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "img/maps/shadow50.png";
	baseIcon.iconSize = new GSize(32, 39);
	baseIcon.shadowSize = new GSize(42, 44);
	baseIcon.iconAnchor = new GPoint(16, 38);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
	// activo evento por doble click
	var atiIcon = new GIcon(baseIcon);
	atiIcon.image = "img/maps/marca.png";
	// Set up our GMarkerOptions object
	markerOptions = { icon:atiIcon, draggable:true };

	// pongo el pin el la latitud longitud que corresponda
	var point = new GLatLng(lat,lon);
    var marker = new GMarker(point, markerOptions);
    map.addOverlay(marker);
  	
	gc = new GClientGeocoder();
	this.ubicarPais = function () {
		pais = document.getElementById("pais");
		gc.getLatLng(pais.value,ubicarMapa);		
	}

	function ubicarMapa(punto) {
		map.setCenter(punto, 4);
		marker.setLatLng(punto);
		reubicarMarker(marker.getLatLng());
	}
	GEvent.addListener(map, "dblclick", function(overlay,latlng) {
			marker.setLatLng(latlng);
			map.panTo(marker.getLatLng());  
	});
	GEvent.addListener(map, "zoomend", function(oldLevel,newLevel) {
		  if(oldLevel<newLevel) {
			marker.setLatLng(map.getCenter());
			reubicarMarker(marker.getLatLng());
		  } else {
			map.panTo(marker.getLatLng());  
		  }
	});
    GEvent.addListener(marker, "dragend", function(overlay,  latlng) {
		  map.panTo(marker.getLatLng());												   
          reubicarMarker(marker.getLatLng());

	});
	function reubicarMarker(latLon) {
		inputLat = document.getElementById("latitud");
		inputLng = document.getElementById("longitud");
		// lleno los campos ocultos latitud y longitud
		inputLat.value = latLon.lat();
		inputLng.value = latLon.lng();
	}

}
/** **************************************** */
/* FUNCIONES DE ITINERARIO COLAPSABLE */
/** **************************************** */
function mostrar_itinerario() {
	modulo = document.getElementById("itinerario");
	lk = document.getElementById("i_link");
	agrandaModulo = new Tween(modulo.style, 'height', Tween.elasticEaseOut, 17, modulo.scrollHeight+10, 1, 'px');
	agrandaModulo.start();
	lk.innerHTML = '<a href="javascript:cerrar_itinerario();" class="link8"><strong>cerrar x</strong></a>';
}
function cerrar_itinerario() {
	modulo = document.getElementById("itinerario");
	lk = document.getElementById("i_link");
	agrandaModulo = new Tween(modulo.style, 'height', Tween.regularEaseOut, modulo.scrollHeight+10, 16, 0.4, 'px');
	agrandaModulo.start();
	lk.innerHTML = '<a href="javascript:mostrar_itinerario();" class="link8"><strong>ver itinerario &raquo;</strong></a>';
}
/** **************************************** */
/* AJAX REGIMEN DE ALIMENTACION */
/** **************************************** */
String.prototype.toProperCase = function(){
     return this.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}

function cambia_hab_reg(codigo,dia,mes,ano,hotel,categoria,regimen) {
	actualiza_datos("calculando","");
	hr = document.getElementById('hab_reg');
	
	// busco los radio buttons y los desactivo antes de llamar a AJAX
	i=0;
	while(r = document.getElementById('radio_'+i)) {
		r.disabled = true;
		i++;
	}
	new Ajax.Updater('hab_reg', 'regimen.php?codigo='+codigo+'&dia='+dia+'&mes='+mes+'&ano='+ano+'&hotel='+hotel+'&categoria='+categoria+"&regimen="+regimen, { method: 'get', evalScripts: true, asynchronous: false });
	/*
	 * cat_hab = document.getElementById("cat_habitacion");
	 * borra_hijos(cat_hab);
	 * cat_hab.appendChild(document.createTextNode(categoria.toProperCase()));
	 */
}
/** **************************************** */
/* AJAX DETALLES DE HABITACIONES */
/** **************************************** */
function cambia_habitaciones(obj,codigo) {
	actualiza_datos("calculando","");
	new Ajax.Updater('detalles_habitaciones', 'detalle_habitaciones.php?habitaciones='+obj.value+"&codigo="+codigo,
	{ method: 'get', evalScripts: true, asynchronous: false });
	new Ajax.Updater('hab_reg', 'regimen2.php', { method: 'get', evalScripts: true, asynchronous: false });
}
function cambia_adulto(obj,habitacion,codigo) {
	actualiza_datos("calculando","");
	new Ajax.Updater('detalles_habitaciones', 'cambia_adulto.php?adultos='+obj.value+'&habitacion='+habitacion+"&codigo="+codigo,
	{ method: 'get', evalScripts: true, asynchronous: false });
	new Ajax.Updater('hab_reg', 'regimen2.php', { method: 'get', evalScripts: true, asynchronous: false });
}
function cambia_paxs(codigo) {
	new Ajax.Updater('detalles_habitaciones', 'cambia_paxs.php?codigo='+codigo,
	{ method: 'get', evalScripts: true, asynchronous: false });
}
function cambia_menor(obj,habitacion,codigo) {
	actualiza_datos("calculando","");
	new Ajax.Updater('detalles_habitaciones', 'cambia_menor.php?menores='+obj.value+'&habitacion='+habitacion+"&codigo="+codigo,
	{ method: 'get', evalScripts: true, asynchronous: false });
	new Ajax.Updater('hab_reg', 'regimen2.php', { method: 'get', evalScripts: true, asynchronous: false });
}
function cambia_edad(obj,habitacion,menor,codigo) {
	actualiza_datos("calculando","");
	new Ajax.Updater('detalles_habitaciones', 'cambia_edad.php?edad='+obj.value+'&habitacion='+habitacion+'&menor='+menor+"&codigo="+codigo, { method: 'get', evalScripts: true, asynchronous: false });
	new Ajax.Updater('hab_reg', 'regimen2.php', { method: 'get', evalScripts: true, asynchronous: false });
}
function actualiza_datos(moneda,precio) {
	p = document.getElementById("precio");
	m = document.getElementById("moneda");
	borra_hijos(p);
	borra_hijos(m);
	p.appendChild(document.createTextNode(precio));
	m.appendChild(document.createTextNode(moneda));										  
}
function actualiza_detalles(codigo) {
	new Ajax.Updater('detalles_habitaciones', 'actualiza_detalles.php?codigo='+codigo,
	{ method: 'get', evalScripts: true, asynchronous: false });
	new Ajax.Updater('hab_reg', 'regimen2.php', { method: 'get', evalScripts: true, asynchronous: false });
}

/** **************************************** */
/* SCROLL AUTOMATICO */
/** **************************************** */
function miScroll() {
	setTimeout(scroll_retrasado,500);
}
function scroll_retrasado() {
	scr = new Tween(new Object(), 'y', Tween.regularEaseInOut, 0, 650, 2);
	scr.start();
	scr.onMotionChanged = function(event) {
		window.scrollTo(0,event.target._pos);
	}	
}
/** **************************************** */
/* FUNCIONES DE FECHA FORMULARIO */
/** **************************************** */
function script_fecha(etiqueta){
	fecha_oculta = document.getElementById(etiqueta);
	mes = document.getElementById(etiqueta+"_mes");
	dia = document.getElementById(etiqueta+"_dia");
	ano = document.getElementById(etiqueta+"_ano");
	fecha_oculta.value = ano.value+"-"+((mes.value<10)? "0"+mes.value : mes.value)+"-"+((dia.value<10)? "0"+dia.value : dia.value);
	// alert(fecha_oculta.value);
}
/** **************************************** */
/* MENU DESPLEGABLE FUNCIONES */
/** **************************************** */
function muestra_desplegable(id) {
	desp = document.getElementById("desp_"+id);
	desp2 = document.getElementById("desp2_"+id);
	desp.style.visibility = "visible";
	desp2.style.visibility = "visible";

}
function oculta_desplegable(id) {
	desp = document.getElementById("desp_"+id);
	desp2 = document.getElementById("desp2_"+id);
	desp.style.visibility = "hidden";
	desp2.style.visibility = "hidden";	
}
function m_destino_over(id) {
	dest = 	document.getElementById("menu_destino_"+id);
	dest.className = "menuPrincipal_destinos_over";
}
function m_destino_out(id) {
	dest = 	document.getElementById("menu_destino_"+id);
	dest.className = "menuPrincipal_destinos";
}
/** **************************************** */
/* AJAX PLAN DE PAGO */
/** **************************************** */
function controla_numeros(evt) {
  var keyPressed = (evt.which) ? evt.which : event.keyCode
  if(keyPressed<32 || (keyPressed>47 && keyPressed<58 )) {
	return true;  
  } else {
	return false;
  }
}
function cambia_tarjeta(primerpago,reserva) {
    btn = document.getElementById('btn_pagar');
	btn.href = "javascript:alert('Elija importe a pagar, medio de pago y seleccione un plan de pago');";
	
	// recupera el objeto monto
	mon = document.getElementById('monto');
	
	// recupero tarjeta
	for(i=1;i<10;i++) {
		if(tarj = document.getElementById("tarjeta"+i)) {
			if(tarj.checked) {
				tar = tarj.value;
			}
		}
	}
	
	d_mediopago = document.getElementById("d_mediopago");
	
	if(tar=="MASTER" || tar=="CITI MASTER") cod_tar=15;
	  if(tar=="VISA" || tar=="CITI VISA") cod_tar=1; 
	  if(tar=="DINERS" || tar=="CITI DINERS")cod_tar=8; 
	  if(tar=="AMEX") cod_tar=6;
	  if(tar=="PAGOMISCUENTAS") cod_tar=41;
	  if(tar=="Pago Facil") cod_tar=999;
	 
// cod_tar = tar;
	
	tipo = document.getElementById('tipo_tarjeta');
	tipo.value = tar;
	
	d_mediopago.value = cod_tar;
	
	d_monto = document.getElementById("d_monto");
	importe = format_number(mon.value,2);
	d_monto.value = importe*100;
	
	borra_hijos(document.getElementById('plan'));
	if(mon.value>0) {
		new Ajax.Updater('plan', 'plan_de_pago.php?tarjeta='+tar+'&monto='+mon.value+'&primerpago='+primerpago+'&reserva='+reserva,
		{ method: 'get', evalScripts: true, asynchronous: false });
	}
}
monto_max = 0;
function monto_maximo(monto) {
	monto_max = monto;
}
function plan_seleccionado(tarjeta,primerpago,reserva,cuotas,monto,nroOperacion) {
	d_monto = document.getElementById("d_monto");
	d_opera = document.getElementById("d_nrooperacion");
	if(nroOperacion!="") {
		d_opera.value = nroOperacion;
	}

	for(i=1;i<19;i++) {
		if(document.getElementById("radio"+i)) {
	    	plan2 = document.getElementById("radio"+i);
			if(plan2.checked) {
				plan_valor = plan2.value.split(",");
				pl = plan_valor[0];
				d_monto.value = plan_valor[1];
			}
		}
	}

	d_cuotas = document.getElementById("d_cuotas");
	d_cuotas.value = pl;
	btn = document.getElementById('btn_pagar');
	monto2 = document.getElementById('monto');

	if(tarjeta=="PAGO FACIL") {
		if( monto2.value <= monto_max || monto_max == -1) {
			btn.href = "javascript:pagofacil("+mon.value+","+primerpago+","+reserva+");";
		} else {
			btn.href = "javascript:alert('El Importe no puede ser mayor que su Saldo Total a Pagar.');";		
		}
	} else {
		if( monto2.value <= monto_max || monto_max == -1) {
			if(tarjeta.indexOf('CITI')!=-1) {
				btn.href = "javascript:mostrarCartelChequeoCiti();";
			} else {		
				// subo el recibo pendiente por ajax
				btn.href = "javascript:generarRecibo('"+tarjeta+"','"+reserva+"','"+cuotas+"','"+monto+"');" +
						"document.form_pagar.submit();";
			}
		} else {
			btn.href = "javascript:alert('El Importe no puede ser mayor que su Saldo Total a Pagar.');";		
		}
	}
}
function generarRecibo(tarjeta,reserva,cuotas,monto) {
	new Ajax.Request("generarRecibo.php?tarjeta="+tarjeta+"&reserva="+reserva+"&cuotas="+cuotas+"&monto="+monto, { method: 'get', evalScripts: true, asynchronous: false });	
}
function enviarCiti() {
	new Ajax.Updater('plan', 'mail_cobranzas.php', { method: 'get', evalScripts: true, asynchronous: false });
	document.form_pagar.submit();
}
function mostrarCartelChequeoCiti() {
		citi = document.getElementById('chequeo_citi');
		tipo = document.getElementById('tipo_tarjeta');
		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 (tipo.value) {
			case 'CITI DINERS':
				numero4.style.visibility = 'hidden';
				numero2.size = '6';
				numero2.maxLength = '6';
				logo.className = 'chequeo_logo_diners';
				break;
			case 'CITI MASTER':
				numero4.style.visibility = 'visible';
				numero2.size = '4';
				numero2.maxLength = '4';
				logo.className = 'chequeo_logo_mastercard';
				break;
			case 'CITI VISA':
				numero4.style.visibility = 'visible';
				numero2.size = '4';
				numero2.maxLength = '4';
				logo.className = 'chequeo_logo_visa';
				break;				
		}
		
		citi.style.visibility = "visible";
}
function ocultarCartelChequeoCiti() {
	numero4 = document.getElementById('numero_tarjeta4');	
		citi = document.getElementById('chequeo_citi');
		citi.style.visibility = "hidden";
		numero4.style.visibility = 'hidden';
}
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;
	monto2 = document.getElementById("d_monto").value/100;
	cuotas2 = document.getElementById("d_cuotas").value;
	
	tipoTarjeta = document.getElementById('tipo_tarjeta');
	new Ajax.Request('chequearTarjeta.php?tarjeta='+numero+'&tipo='+tipoTarjeta.value+'&nrooperacion='+nro.value+'&importe='+monto2+'&cuotas='+cuotas2,				
		{
		onSuccess: function(response) {
			text = response.responseText.split(",");
			if(text[0]=="OK") {
				numero = text[1].split(" ");
				if(numero[0]>=2000000) {
					generarRecibo(tipoTarjeta.value,numero[0],cuotas2,monto2);
				} 
				document.form_pagar.submit();
			} else {
				alert(response.responseText);
			}
			}
		}
	);
}
function pagofacil(importe3,primerpago3,reserva3) {
	window.open("pagofacil.php?importe="+importe3+"&primerpago="+primerpago3+"&reserva="+reserva3,null,"height=760,width=760,status=yes,toolbar=no,menubar=no,location=no");
	generarRecibo("PAGO FACIL",reserva3,1,importe3);
	document.location.href="misreservas.php";
}
function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}
/** **************************************** */
/* POPUPS DOCUMENTACION */
/** **************************************** */
function abre_ventana(URL) {
	 window.open(URL,"ventana1","width=650,height=650,scrollbars=YES");
}
/** **************************************** */
/* NUEVO NAVEGADOR OVER, OUT, CLICK */
/** **************************************** */
function overNavegador(obj) {
	obj.style.backgroundColor = '#F8F8F8';	
}
function outNavegador(obj) {
	obj.style.backgroundColor = 'transparent';	
}
function clickNavegador(url) {
	window.location.href = url;	
}

/** **************************************** */
/* POPUP MENSAJE BLOG */
/** **************************************** */
function mensajeCerrar() {
	men = document.getElementById('mensaje');
	men2 = document.getElementById('mensaje2');	
		ter = document.getElementById('terminado');
	men.style.visibility = "hidden";
	men2.style.visibility = "hidden";
	ter.style.visibility = "hidden";
}
function mensajeAbrir() {
	men = document.getElementById('mensaje');
	men2 = document.getElementById('mensaje2');
	ter = document.getElementById('terminado');
	men.style.visibility = "visible";
	men2.style.visibility = "visible";
	ter.style.visibility = "hidden";
}
function mensajeEnviar() {
	men3 = document.getElementById('mensaje3');
	mensaje = document.getElementById('campo_mensaje');
	de = document.getElementById('campo_de');
	para = document.getElementById('campo_para');
	url = document.getElementById('campo_url');
	asunto = document.getElementById('campo_asunto');
	ter = document.getElementById('terminado');
	
	new Ajax.Request('enviar_a_un_amigo.php?de='+de.value+'&para='+para.value+'&mensaje='+mensaje.value+"&url="+url.value+"&asunto="+asunto.value,				
					{
						onSuccess: function(response) {
							
							ter.style.visibility = "visible";
						}
					}
	 );
}
/** **************************************** */
/* CLASE DE MANEJO DE AVISO DE DIARIO */
/** **************************************** */
function Aviso() {
	this.f = document.getElementById('imagen');
	this.div = document.getElementById('aviso');
	this.interface = document.getElementById('interface');
	this.centroX = 375;
	this.centroY = 275;
	this.velocidad = 5;
	
	este = this;

	this.interfaceOver = function() {
		this.interface.style.opacity = "1";
		this.interface.style.filter = "alpha(opacity=100)";	
	}
	this.interfaceOut = function() {
		this.interface.style.opacity = "0.75";
		this.interface.style.filter = "alpha(opacity=75)";	
	}
	this.actualizarImagen = function(imagen,zoom) {
		this.imagen = imagen;
		this.zoom = zoom;	
		this.f.src = "resample_porcentaje.php?imagen="+imagen+"&porcentaje="+zoom;
	}
	this.ubicarImagen = function() {
		this.div.style.marginLeft = this.centroX-(this.f.width/2)+"px";
		this.left = this.centroX-(this.f.width/2);
		this.right = this.centroX+(this.f.width/2);
		this.div.style.marginTop = this.centroY-(this.f.height/2)+"px";
		this.top = this.centroY-(this.f.height/2);
		this.bottom = this.centroY+(this.f.height/2);
		this.div.style.width = this.f.width+"px";
		this.div.style.height = this.f.height+"px";
		this.div.style.cursor = "auto";
	}
	this.zoomIn = function(ev) {
		if(this.zoom<100) {
			if(ev.x !=undefined) {
				evX = ev.x;	
				evY = ev.y-40;
			} else {
				evX = ev.layerX;	
				evY = ev.layerY;
			}	
			this.centroX -= (evX-this.centroX);
			this.centroY -= (evY-this.centroY);
			this.actualizarImagen(this.imagen,this.zoom*2);
			this.div.style.cursor = "wait";	
			this.velocidad = this.velocidad * 2;
		}
	}
	this.zoomInBoton = function() {
		if(this.zoom<100) {
			this.actualizarImagen(this.imagen,this.zoom*2);
			this.div.style.cursor = "wait";	
			this.velocidad = this.velocidad * 2;
		}
	}
	this.zoomOut = function() {
		this.centroX = 375;
		this.centroY = 275;
		this.actualizarImagen(this.imagen,25);
		this.div.style.cursor = "wait";		
		this.velocidad = 5;
	}
	this.izquierdaDown = function(boton) {
		this.mouseUp();
		this.int = setInterval(this.moverIzquierda,50);
	}
	this.moverIzquierda = function() {
		if(este.left<50) {
			este.centroX += este.velocidad;	
			este.ubicarImagen();
		}
	}
	this.derechaDown = function(boton) {
		this.mouseUp();
		this.int = setInterval(this.moverDerecha,50);
		
	}
	this.moverDerecha = function() {
		if(este.right>700) {
			este.centroX -= este.velocidad;	
			este.ubicarImagen();
		}
	}
	this.arribaDown = function(boton) {
		this.mouseUp();	
		this.int = setInterval(this.moverArriba,50);
			
	}
	this.moverArriba = function() {
		if(este.top<50) {
			este.centroY += este.velocidad;	
			este.ubicarImagen();
		}
	}
	this.abajoDown = function(boton) {
		this.mouseUp();	
		this.int = setInterval(this.moverAbajo,50);
			
	}
	this.moverAbajo = function() {
		if(este.bottom>500) {
			este.centroY -= este.velocidad;	
			este.ubicarImagen();
		}
	}
	this.finMov = function() {
		window.onmouseup = null;
		clearInterval(this.int);
	}
	this.mouseUp = function() {
    	clearInterval(este.int);
		window.onmouseup = document.onmouseup = function() {
			este.finMov();
		};
	}
}

// SUBIDA DE FOTOS CON AJAX Y PHP
function cargarFoto(numeroDeFoto,ancho,alto,completo) {
	foto = document.getElementById("muestraFoto"+numeroDeFoto);
	foto.src = "";
	foto.alt = "Cargando...";
	accionOriginal = document.formulario.action;
	document.formulario.action = "subefoto.php?foto="+numeroDeFoto+"&ancho="+ancho+"&alto="+alto+"&completo="+completo;
	document.formulario.target = "respuesta";
	document.formulario.submit();
	// repongo la accion original
	document.formulario.action = accionOriginal;
	document.formulario.target = "";
}
function agregarFoto() {
	agregar = document.getElementById('agregarFotos');
	div = agregar.appendChild(document.createElement('div'));
	div.id = "agregarFoto"+proximaFoto;
	new Ajax.Updater("agregarFoto"+proximaFoto, 'agregar_foto.php?foto='+proximaFoto, { method: 'get', evalScripts: true});
	proximaFoto++;
}
/**
 * Funciones de drag and drop de ventana
 */

function dragVentana(ev,id) {
	ven = document.getElementById(id);
	xInicial = ven.offsetLeft-ev.clientX;
	yInicial = ven.offsetTop-ev.clientY;
	ven.style.cursor = "move";
	document.onmousemove = function(ev2) {
		var navegador = navigator.appName
		if (navegador == "Microsoft Internet Explorer") {
			ven.style.left = xInicial+window.event.clientX+"px";
			ven.style.top = yInicial+window.event.clientY+"px";
		} else {
			ven.style.left = xInicial+ev2.clientX+"px";
			ven.style.top = yInicial+ev2.clientY+"px";
		}
		
	
	}
	document.onmouseup = function() {
		document.onmousemove = function() {};
		ven.style.cursor = "auto";
	}
}
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]);
	}
}
/** ********************************* */
/* 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="link8">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="link8">ver mapa &raquo;</a>';
	agrandaSucursal[idSucursal] = new Tween(sucursal.style, 'height', Tween.regularEaseOut, 484, 90, 0.3, 'px');
	agrandaSucursal[idSucursal].start();
	
}
/** ************** */
/* ABRIR VENTANA */
/** ************** */

function abrirItinerario(id) {
	javascript:window.open('itinerario.php?c='+id , 'Itinerario' , 'width=640,height=600,scrollbars=YES');
}



