function inicioDeProceso() {
	$('cargando').show();
	// TODO agregar el bloqueo del navegador
}

function finDeProceso() {
	$('cargando').hide();
	// TODO desbloquear el navegador
}

function procesarRespuesta(input, selected, value, val2) {
	var name = input.id;
	var campoId = $(name + '_id');
	var texto = '';
	if (value == null) {
		value = 0;
	} else {
		var text = selected.getFirst('span');
		var texto = text.innerHTML;
		texto = texto.replace('<span class="autocompleter-queried">', '');
		texto = texto.replace('</span>', '');
	}
	campoId.value = value;
	input.value = texto;
}

function procesarSeleccion(tabla, input, funcion) {
	if (!$chk(funcion))
		return false;
	if ($chk(input.value)) {
		$(input.id + '_id').value = 0;
	}
	var campoId = $(input.id + '_id');
	/*
	 * TODO agregar la forma de agregar en un modalbox de mootools el formulario
	 * para agregar datos y que devuelva el id seleccionado if($chk(campoId)&&
	 * campoId.value == 'agregar'){ var out = agregarValor(campo.value, tabla);
	 * texto = out.texto ; value = out.value; }else{
	 */
	funcion += '();';
	eval(funcion);
	// }
}
function procesarChoice(choice) {
	var text = choice.getFirst('span');
	var span = choice.getElements('span');
	var value = text.innerHTML;
	var id = span[1].innerHTML || 0;
	choice.inputValue = id;
	text.set('html', this.markQueryValue(value));
	this.addChoiceEvents(choice);
}

function agregarValor(palabra, tabla) {
	return {
		texto : 'agregado',
		value : 10
	}
}

function menuSwapBackground(element, on) {
	if (on) {
		element.style.background = "#0033CC";
	} else {
		element.style.background = "#3366FF";
	}
}

function subMenuSwapBackground(element, on) {
	if (on) {
		element.style.background = "#0033CC";
	} else {
		element.style.background = "#3399FF";
	}
}

function gruposByHotelId() {
	sel = document.getElementById('selhoteles');
	hId = sel.options[sel.options.selectedIndex].value;
	if (hId == 0) {
		document.getElementById('grupos').innerHTML = '';
		document.getElementById('tipoDispo').style.visibility = "hidden";
		document.getElementById('dispotime').style.visibility = "hidden";
		document.getElementById('dispo').style.visibility = "hidden";
		document.getElementById('savedispo').style.visibility = "hidden";
		document.getElementById('dispofija').style.visibility = "hidden";
		return;
	}
	var toUrl = urllocal + 'ajax/gruposbyhotelid/hId/' + hId;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {

		},
		onSuccess : function(texto, xmlrespuesta) {
			$('grupos').set('html', texto);
		},
		onFailure : function() {

		}
	}).send();
}

function selectGrupo() {
	sel = document.getElementById('selgrupos');
	if (sel.options) {
		gId = sel.options[sel.options.selectedIndex].value;
	} else {
		gId = sel.value;
	}
	if (gId == 0) {
		document.getElementById('tipoDispo').style.visibility = "hidden";
		document.getElementById('dispotime').style.visibility = "hidden";
		document.getElementById('dispo').style.visibility = "hidden";
		document.getElementById('savedispo').style.visibility = "hidden";
		document.getElementById('dispofija').style.visibility = "hidden";
		document.getElementById('dispofija').style.height = "1px";
		return;
	}
	if (document.getElementById('tvariable').checked) {
		document.getElementById('tipoDispo').style.visibility = "";
		document.getElementById('dispotime').style.visibility = "";
		document.getElementById('dispo').style.visibility = "";
		document.getElementById('savedispo').style.visibility = "";
		document.getElementById('dispofija').style.visibility = "hidden";
		document.getElementById('dispofija').style.height = "1px";
		getDispo();
	} else {
		document.getElementById('tipoDispo').style.visibility = "";
		document.getElementById('dispo').style.visibility = "hidden";
		document.getElementById('dispotime').style.visibility = "hidden";
		document.getElementById('savedispo').style.visibility = "hidden";
		document.getElementById('dispofija').style.visibility = "";
		document.getElementById('dispofija').style.height = "auto";
		getDispoFija();
	}
}
/*
 * function getDispo() { /// por la habitacion o por el grupo desde el que llego
 * 
 * sel = document.getElementById('selgrupos');
 * 
 * if(sel.options){ gId = sel.options[sel.options.selectedIndex].value; }else{
 * gId = sel.value; } md = document.getElementById('mdispo'); ad =
 * document.getElementById('adispo'); m =
 * md.options[md.options.selectedIndex].value; a =
 * ad.options[ad.options.selectedIndex].value; var toUrl =
 * urllocal+'ajax/getdispo/gId/'+gId+'/m/'+m+'/a/'+a; var objAjax = new
 * Request({ method: 'get', url:toUrl, onRequest: function() { }, onSuccess:
 * function(texto, xmlrespuesta){ $('dispo').set('html', texto); }, onFailure:
 * function(){ } }).send(); } /* function saveDispoVariable(hiddens) { d = '';
 * ca = ''; cd = ''; mn = ''; i=1; while(document.getElementById('d'+i)) { d +=
 * document.getElementById('d'+i).value+'='; ca +=
 * document.getElementById('ca'+i).checked+'='; cd +=
 * document.getElementById('cd'+i).checked+'='; mn +=
 * document.getElementById('mn'+i).value+'='; i=i+1; } md =
 * document.getElementById('mdispo'); ad = document.getElementById('adispo'); m =
 * md.value; a = ad.value; // sel = document.getElementById('selgrupos'); // gId =
 * sel.options[sel.options.selectedIndex].value; gId = $('selgrupos').value; //
 * var toUrl =
 * urllocal+'ajax/savedispo/gId/'+gId+'/m/'+m+'/a/'+a+'/d/'+d+'/ca/'+ca+'/cd/'+cd+'/mn/'+mn;
 * var toUrl =
 * urllocal+'disponibilidadvariable/save/gId/'+gId+'/m/'+m+'/a/'+a+'/d/'+d+'/ca/'+ca+'/cd/'+cd+'/mn/'+mn;
 * var objAjax = new Request({ method: 'get', url:toUrl, onRequest: function() { },
 * onSuccess: function(texto, xmlrespuesta){ alert("La Disponibilidad se Guardo
 * Correctamente"); }, onFailure: function(){ console.error('Error al guardar la
 * dispo por favor intentelo nuevamente'); } }).send(); }
 * 
 */
function checkDispo() {
	var hotel = document.getElementById('hotel');
	var hid = hotel.options[hotel.options.selectedIndex].value;
	var chin = document.getElementById('checkin');
	var ci = chin.value;
	var chou = document.getElementById('checkout');
	var co = chou.value;
	var toUrl = urllocal + 'ajax/verifydispo/co/' + co + '/ci/' + ci
			+ '/htlid/' + hid;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			$('dispohabitacion').set('html', texto);
			if (hiddens) {
				var accion = confirm('Desea cargar otra dispo?');
				if (!accion) {
					window.location.href = urllocal
							+ 'tablasoperativas/grupos/hotel/' + hid;
				}
			}
		},
		onFailure : function() {

		}
	}).send();
}

function swapDispo(variable) {
	if (variable) {
		document.getElementById('dispo').style.visibility = "";
		document.getElementById('dispo').style.height = "auto";
		document.getElementById('dispotime').style.visibility = "";
		document.getElementById('savedispo').style.visibility = "";
		document.getElementById('dispofija').style.visibility = "hidden";
		document.getElementById('dispofija').style.height = "1px";
	} else {
		document.getElementById('dispo').style.visibility = "hidden";
		document.getElementById('dispo').style.height = "1px";
		document.getElementById('dispotime').style.visibility = "hidden";
		document.getElementById('savedispo').style.visibility = "hidden";
		document.getElementById('dispofija').style.visibility = "";
		document.getElementById('dispofija').style.height = "auto";
		getDispoFija();
	}

}
/*
 * function saveFija(hiddens) { var hotel =
 * document.getElementById('selhoteles'); var hid= 0; if(hiddens){ hid =
 * hotel.value; }else{ hid = hotel.options[hotel.options.selectedIndex].value; }
 * var sel = document.getElementById('selgrupos'); var gId = 0; if(hiddens){ gId =
 * sel.value; }else{ gId = sel.options[sel.options.selectedIndex].value; } var
 * inicio = document.getElementById('date').value; if(!inicio){
 * alert('Seleccione una fecha de inicio'); return false; } var fin =
 * document.getElementById('date1').value; if(!fin){ alert('Por favor Seleccione
 * una fecha de fin'); return false; } var stock =
 * parseInt(document.getElementById('stock').value); if(!stock){ alert('el stock
 * deve ser superior a 0');return false; } var mn =
 * parseInt(document.getElementById('minimo_noches').value); if(!mn){ alert('el
 * numero de noches deve ser superior a 0');return false; } var cliente =
 * document.getElementById('cliente_id').value; cliente = (!cliente)? 0 :
 * cliente; var toUrl = urllocal+'ajax/savefija'; var formulario =
 * $('formdispofija'); formulario.set('send', { url: toUrl, method: 'post',
 * onRequest: function() { }, onSuccess: function(texto, xmlrespuesta){ alert();
 * 
 * //$('tablaDispos').innerHTML=texto; }, onFailure: function(){ alert('error'); }
 * }); formulario.send(); //Sends the form. }
 * 
 */

function cambiarpreciomv(habitacionId) {
	$('preciomv_' + habitacionId).value = $('costo_' + habitacionId).value;
}

function getDispoFija() {
	var hotel = document.getElementById('selhoteles');
	var hid = hotel.options[hotel.options.selectedIndex].value;
	var sel = document.getElementById('selgrupos');
	var gId = sel.options[sel.options.selectedIndex].value;
	var inicio = document.getElementById('date').value;
	var fin = document.getElementById('date1').value;
	var moneda = document.getElementById('moneda').value;
	var monto = document.getElementById('monto').value;
	var stock = document.getElementById('stock').value;
	var toUrl = urllocal + 'ajax/getfija/hId/' + hid + '/gId/' + gId
			+ '/inicio/' + inicio + '/fin/' + fin + '/moneda/' + moneda
			+ '/monto/' + monto + '/stock/' + stock;

	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			$('dispofija2').set('html', texto);
		},
		onFailure : function() {
		}
	}).send();
}

function searchFiles() {
	var cliente = document.getElementById('clientes');
	var clienteId = cliente.options[cliente.options.selectedIndex].value;
	var numero = document.getElementById('numero').value;
	var nombre = document.getElementById('nombre').value;
	var apellido = document.getElementById('apellido').value;
	var estado = document.getElementById('status');
	var estadoId = estado.options[estado.options.selectedIndex].value;
	var toUrl = urllocal + 'ajax/serchfiles/cId/' + clienteId + '/eId/'
			+ estadoId + '/numero/' + numero + '/nombre/' + nombre
			+ '/apellido/' + apellido;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {

		},
		onSuccess : function(texto, xmlrespuesta) {
			$('files').set('html', texto);
		},
		onFailure : function() {

		}
	}).send();
}

// Ventanas ------------------------------------------------

function verHoteles() {
	var myRef = window
			.open(urllocal + 'ventanas/verhoteles/', 'mywin',
					'left=20,top=20,width=800,height=500,toolbar=1,resizable=0,scrollbars=yes');
}

function verPaquetes() {
	var myRef = window.open(urllocal + 'ventanas/verpaquetes/', 'mywin',
			'left=20,top=20,width=800,height=500,toolbar=1,resizable=0');
}

function verOpcionales() {
	var myRef = window.open(urllocal + 'ventanas/veropcionales/', 'mywin',
			'left=20,top=20,width=800,height=500,toolbar=1,resizable=0');
}

function addHotelV(selectId, habId, ptotal, ctotal) {
	pId = window.opener.document.getElementById('paquete_id').value;
	cantidad = $(selectId).value;
	fin = $('fechaIn').value;
	fout = $('fechaOut').value;
	ditr = "-";// agregar distribucion de personas
	var toUrl = urllocal + 'ajax/inserthabpaq/pId/' + pId + '/ctotal/' + ctotal
			+ '/ptotal/' + ptotal + '/cantidad/' + cantidad + '/hId/' + habId
			+ '/fin/' + fin + '/fout/' + fout + '/distribucion/' + ditr;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onSuccess : function(texto, xmlrespuesta) {
			window.opener.location.reload();
			window.close();
		}
	}).send();
}

function FID() {
	return document.getElementById('fId').value;
}

function addPaquetesV() {
	var sel = document.getElementById('paquetesV');
	var pId = sel.options[sel.options.selectedIndex].value;
	if (pId == 0) {
		alert("Seleccione un paquete");
		return;
	}
	document.getElementById('boton').disabled = "true";
	window.opener.addPaquete(pId);
	window.close();
}

function addHotel(rooms, fechas, fId) {
	var selCli = document.getElementById('selCli');
	var cId = selCli.options[selCli.selectedIndex].value;
	var toUrl = urllocal + 'ajax/addhotel/habitaciones/' + rooms + '/fechas/'
			+ fechas + '/fId/' + fId + '/cId/' + cId + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {

		},
		onSuccess : addHotel2,
		onFailure : function() {
		}
	}).send();
}
function addHotel2(data) {
	var hoteles = document.getElementById('hoteles');
	var div = document.createElement('div');
	div.innerHTML = data;
	hoteles.appendChild(div);
}

var paqs = 0;
function addPaquete(pid) {
	var tourl = urllocal + 'ajax/addpaquete/pId/' + pid;
	var objAjax = new Ajax(tourl, {
		method : 'get',
		onComplete : addPaquete2
	});
	objAjax.request();
}
function addPaquete2(data) {
	paqs = paqs + 1;
	var paquetes = document.getElementById('paquetes');
	var div = document.createElement('div');
	div.id = 'divpaq' + paqs;
	div.innerHTML = data;
	paquetes.appendChild(div);
}

var opcs = 0;
function addOpcional(oid) {
	var toUrl = urllocal + 'ajax/addopcional/oId/' + oid;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {

		},
		onSuccess : addOpcional2(texto),
		onFailure : function() {

		}
	}).send();
}
function addOpcional2(data) {
	opcs = opcs + 1;
	var opcionales = document.getElementById('opcionales');
	var div = document.createElement('div');
	div.id = 'divopc' + opcs;
	div.innerHTML = data;
	opcionales.appendChild(div);
}

// Fin Ventanas ------------------------------------------------

function destSelected() {
	var sel = document.getElementById('destinosV');
	var dId = sel.options[sel.options.selectedIndex].value;

	if (dId == 0) {
		document.getElementById('destOk').style.visibility = "hidden";
	} else {
		document.getElementById('destOk').style.visibility = "";
		getHForSelect(dId);
	}
}

function getHForSelect(dId) {
	var toUrl = urllocal + 'ajax/gethotforselect/destino/' + dId + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onSuccess : function(texto, xmlrespuesta) {
			divHot = document.getElementById('hotSel');
			divHot.set('html', texto);
		}
	}).send();
}

function cantHabSelected() {
	var sel = document.getElementById('chab');
	var dId = sel.options[sel.options.selectedIndex].value;
	if (dId == 0) {
		document.getElementById('cantHabOk').style.visibility = "hidden";
	} else {
		document.getElementById('cantHabOk').style.visibility = "";
		hasta = parseInt(sel.options.selectedIndex) + 1;
		for (i = 1; i < hasta; i++) {
			document.getElementById('hab' + i).style.visibility = "";
			document.getElementById('hab' + i).style.height = "auto";
		}
		for (i = hasta; i < 9; i++) {
			document.getElementById('hab' + i).style.visibility = "hidden";
			document.getElementById('hab' + i).style.height = "1px";
		}
	}
}

function validacpax(hasta) {
	out = "";
	for (i = 1; i < hasta; i++) {
		var sel2 = document.getElementById('ni' + i);
		var hasta2 = parseInt(sel2.options[sel2.options.selectedIndex].value) + 1;
		var sel3 = document.getElementById('ad' + i);
		var cantAd = parseInt(sel3.options[sel3.options.selectedIndex].value);
		if (!(hasta2 - 1) && !cantAd) {
			alert("La habitacion " + i + " no tiene personas cargadas.");
			return false;
		}
		;
		out = out + cantAd + "|";
		for (j = 1; j < hasta2; j++) {
			if (document.getElementById('ihab' + i + 'ni' + j).value == "") {
				alert("Complete todas las edades de los ni�os");
				return false;
			}
			out = out + document.getElementById('ihab' + i + 'ni' + j).value
					+ "_";
		}
		out = out.substring(0, (out.length - 1));
		out = out + "-";
	}
	out = out.substring(0, (out.length - 1));
	return out;
}

function buscarDispoV() {
	var selCli = window.opener.document.getElementById('cliente_id');
	var cId = selCli.options[selCli.selectedIndex].value;
	var dispo = document.getElementById('dispo');
	var fin = document.getElementById('fechaIn').value;
	var fout = document.getElementById('fechaOut').value;
	if (fin == "" || fout == "") {
		alert("Debe completar las fechas");
		dispo.style.visibility = "hidden";
		return;
	}
	;
	var sel = document.getElementById('chab');
	var chab = sel.options[sel.options.selectedIndex].value;
	cpx = validacpax(parseInt(chab) + 1);
	if (!cpx) {
		return;
	}
	var dId = $('destinoS').value;
	var hId = $('habitacioneS').value;
	var toUrl = urllocal + 'ajax/buscardispov/destino/' + dId + '/fin/' + fin
			+ '/fout/' + fout + '/cpax/' + cpx + '/hId/' + hId + '/cId/' + cId
			+ '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {

		},
		onSuccess : function(texto, xmlrespuesta) {

			var dispo = document.getElementById('dispo');
			$('dispo').style.visibility = "";
			$('dispo').style.height = "auto";
			$('dispo').set('html', texto);
		},
		onFailure : function() {

		}
	}).send();

}

function buscarDispoVFile() {
	var selCli = window.opener.document.getElementById('selCli');
	var cId = selCli.options[selCli.selectedIndex].value;
	var dispo = document.getElementById('dispo');
	var fin = document.getElementById('fechaIn').value;
	var fout = document.getElementById('fechaOut').value;
	if (fin == "" || fout == "") {
		alert("Debe completar las fechas");
		dispo.style.visibility = "hidden";
		return;
	}
	;
	var sel = document.getElementById('chab');
	var chab = sel.options[sel.options.selectedIndex].value;
	cpx = validacpax(parseInt(chab) + 1);
	if (!cpx) {
		return;
	}
	var dId = $('destinoS').value;
	var hId = $('hotel_id').value;
	var toUrl = urllocal + 'ajax/buscardispovfile/destino/' + dId + '/fin/'
			+ fin + '/fout/' + fout + '/cpax/' + cpx + '/hId/' + hId + '/cId/'
			+ cId + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
			$('cargando').style.visibility="";
		},
		onSuccess : function(texto, xmlrespuesta) {
			var dispo = document.getElementById('dispo');
			$('dispo').style.visibility = "";
			$('dispo').style.height = "auto";
			$('dispo').set('html', texto);
			$('cargando').style.visibility="hidden";
		},
		onFailure : function() {

		}
	}).send();

}

function buscarDispoV2(data) {
	var dispo = document.getElementById('dispo');
	dispo.style.visibility = "";
	dispo.innerHTML = data;
	dispo.style.height = "auto";
}

function cpax(se, hab) {
	var sel = document.getElementById(se + hab);
	var hasta = parseInt(sel.options.selectedIndex) + 1;
	for (i = 1; i < hasta; i++) {
		document.getElementById('hab' + hab + se + i).style.visibility = "";
		document.getElementById('hab' + hab + se + i).style.height = "auto";
	}
	for (i = hasta; i < 10; i++) {
		document.getElementById('hab' + hab + se + i).style.visibility = "hidden";
		document.getElementById('hab' + hab + se + i).style.height = "1px";
	}
}

function showThisHotel(hts)// hotel to show
{
	hotel = document.getElementById('hotelContainer1');
	cantHots = 1;
	while (hotel != null) {
		cantHots++;
		hotel = document.getElementById('hotelContainer' + cantHots);
	}
	cantHots = cantHots - 1;
	if (cantHots) {
		for (i = 1; i < (cantHots + 1); i++) {
			divcd = document.getElementById('hotelContainer' + i);
			if (i == hts) {
				divcd.style.visibility = "";
				divcd.style.height = "auto";
			} else {
				divcd.style.visibility = "hidden";
				divcd.style.height = "1px";
			}
		}
	}
}
function activar(tabla, id, idlink) {
	var toUrl = urllocal + 'tablasoperativas/cambiarestado/tabla/' + tabla
			+ '/id/' + id + '/ajax/1';
	/* alert(toUrl); */var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			var estado = $(idlink).className;
			estado = (estado != 'publicar activo') ? 'publicar activo'
					: 'publicar';
			$(idlink).className = estado;
		},
		onFailure : function() {
			alert('error')
		}
	}).send();
}
function borrar(tabla, id, nombre) {
	var seguro = confirm('�Seguro desea borrar ' + nombre + '?');
	if (!seguro)
		return;
	var toUrl = urllocal + 'tablasoperativas/borrar/tabla/' + tabla + '/id/'
			+ id + '/ajax/1';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.location.reload();
		},
		onFailure : function() {
		}
	}).send();
}

function agregarOcupacion() {
	var cantidad = $('cantidad').options[$('cantidad').options.selectedIndex].value;
	var toUrl = urllocal + 'ajax/cbocupacion/cantidad/' + cantidad;
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			$('divocupacion').inject(texto);
		},
		onFailure : function() {
		}
	}).send();
}

// -------------------------------------------------------



function searchHabitaciones() {
	var dId = $('destinoS').value;
	var tId = $('categoria').value;
	var fechaIn = $('fechaIn').value;
	var fechaOut = $('fechaOut').value;
	var hoteles = $('hotel_id').value;
	if (!$chk(fechaIn) || !$chk(fechaIn))
		return false;
	var objAjax = new Request( {
		method : 'get',
		url : urllocal + 'ajax/searchhabitaciones/dId/' + dId + '/tId/' + tId
				+ '/fin/' + fechaIn + '/fout/' + fechaOut + '/hoteles/'
				+ hoteles + '/',
		onSuccess : function(texto, xmlrespuesta) {
			$('habFields').innerHTML = texto;
			// ocultarTodos();
	}
	}).send();
}
function searchOpcionales() {
	var dId = $('destinoS').value;
	var fId = window.opener.document.getElementById('fId').value;
	var tId = $('tipoS').value;
	var fecha = $('fechaS').value;
	var opcional = $('opcionaleS').value;
	var objAjax = new Request( {
		method : 'get',
		url : urllocal + 'ajax/searchopcionales/dId/' + dId + '/tId/' + tId+ '/fId/' + fId
				+ '/fecha/' + fecha + '/opcional/' + opcional + '/',
		onSuccess : function(texto, xmlrespuesta) {
			$('opcFields').innerHTML = texto;
			ocultarTodos();
		}
	}).send();
}
function seeOpc(n, id) {
	ocultarTodos();
	$('showfila' + n).style.visibility = "";
	$('showfila' + n).style.height = "auto";
	$('opcId').value = id;
}

function ocultarTodos() {
	tt = parseInt($('totFilas').value) + 1;
	for (i = 1; i < tt; i++) {
		$('showfila' + i).style.visibility = "hidden";
		$('showfila' + i).style.height = "1px";
	}
}

function addOpcionalV() {
	// Valido
	cFilas = parseInt($('totFilas').value) + 1;
	if (cFilas == 1) {
		alert("No hay opcionales para seleccionar");
		return;
	}
	i = 0;
	var listo = false;
	while (!listo && i < cFilas) {
		i++;
		if ($('showfila' + i).style.height == "auto") {
			j = 0;
			while ($('rango' + i + '-' + j) != null) {
				alert("genero el string con los datos del opcId y cuantos de cada rango... se lo paso a una funcion en el opener y ese guarda y escribe en esa pag");
				alert($('rango' + i + '-' + j).value);
				j++
			}
			document.getElementById('boton').disabled = "true";
			// window.close();
		}
	}
	alert("Seleccione un opcional");
	return;
}




function showHab(id) {
	$(id).style.visibility = "";
	$(id).style.height = "auto";
}

function agregarHabitacion(data) {
	var pid = window.opener.document.getElementById('paquete_id').value;
	var cidd = window.opener.document.getElementById('cliente_id');
	var cid = cidd.options[cidd.options.selectedIndex].value;
	arr = data.split("-");
	hotel = arr[0];
	str = hotel + "|";
	for (i = 1; i < arr.length; i++) {
		str += arr[i] + "_" + $("h" + hotel + "-a" + arr[i]).value + "-";
	}
	str = str.substring(0, str.length - 1);
	$('boton').disabled = "true";
	var fin = document.getElementById('fechaIn').value;
	var fout = document.getElementById('fechaOut').value;
	var toUrl = urllocal + 'ajax/inserthabpaq/data/' + str + '/pid/' + pid
			+ '/cid/' + cid + '/fin/' + fin + '/fout/' + fout + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.opener.location.reload();
			window.close();
		}
	}).send();
}

function insertarHabitacionFile() {
	var myRef = window
			.open(
					urllocal + 'ventanas/habitacionesfile/',
					'mywin',
					'scrollbars=1,left=20,top=20,width=900,height=600,toolbar=1,resizable=0,scroll=yes');
}

function agregarHabitacionFile(habitacion,hotel,mkup,costo,venta,tipoDispo) {
	var cantidad = $('sel'+habitacion).value;
	if(cantidad == 0)
	{
		alert('Debe seleccionar la cantidad de habitaciones de este tipo que desea');
		return;
	}
	var fid = window.opener.document.getElementById('fId').value;
	var cidd = window.opener.document.getElementById('selCli');
	var cid = cidd.options[cidd.options.selectedIndex].value;
	$('boton').disabled = "true";
	var fin = document.getElementById('fechaIn').value;
	var fout = document.getElementById('fechaOut').value;
	var toUrl = urllocal + 'ajax/inserthabfile/hotel/' + hotel + '/habitacion/' + habitacion + '/fid/' + fid
			+ '/cid/' + cid + '/fin/' + fin + '/fout/' + fout + '/cantidad/' + cantidad + '/mkup/' + mkup 
			+ '/costo/' + costo + '/venta/' + venta + '/tipodispo/' + tipoDispo + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.opener.location.reload();
			window.close();
		}
	}).send();
}

function agregarHabitacionPaquete(habitacion,hotel,mkup,costo,venta,tipoDispo) {
	var cantidad = $('sel'+habitacion).value;
	if(cantidad == 0)
	{
		alert('Debe seleccionar la cantidad de habitaciones de este tipo que desea');
		return;
	}
	var pid = window.opener.document.getElementById('paquete_id').value;
	var cidd = window.opener.document.getElementById('cliente_id');
	var cid = cidd.options[cidd.options.selectedIndex].value;
	$('boton').disabled = "true";
	var fin = document.getElementById('fechaIn').value;
	var fout = document.getElementById('fechaOut').value;
	var toUrl = urllocal + 'ajax/inserthabpaquete/hotel/' + hotel + '/habitacion/' + habitacion + '/pid/' + pid
			+ '/cid/' + cid + '/fin/' + fin + '/fout/' + fout + '/cantidad/' + cantidad + '/mkup/' + mkup 
			+ '/costo/' + costo + '/venta/' + venta + '/tipodispo/' + tipoDispo + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.opener.location.reload();
			window.close();
		}
	}).send();
}



function insertarOpcionalVFile() {
	// Valido
	cFilas = parseInt($('totFilas').value) + 1;
	if (cFilas == 1) {
		alert("No hay opcionales para seleccionar");
		return;
	}
	i = 0;
	var listo = false;
	var strData = "";
	var fid = window.opener.document.getElementById('fId').value;
	var opid = $('opcId').value;
	strData += "fid=" + fid + "|opid=" + opid + "|";
	while (!listo && i < cFilas) {
		i++;
		if ($('showfila' + i).style.height == "auto") {
			j = 0;
			while ($('rango' + i + '-' + j) != null) {
				strData += j + "-" + $('rango' + i + '-' + j).value + "_";
				j++;
			}
			strData = strData.substring(0, strData.length - 1);
			strData += "|" + $('fechaS').value;
			document.getElementById('boton').disabled = "true";
			var toUrl = urllocal + 'ajax/insertopcfile/data/' + strData + '/';
			var objAjax = new Request( {
				method : 'get',
				url : toUrl,
				onRequest : function() {
				},
				onSuccess : function(texto, xmlrespuesta) {
					window.opener.location.reload();
					window.close();
				}
			}).send();
		}
	}
	alert("Seleccione un opcional");
	return;
}



function searchPaquetes() {
	var dId = $('destinoS').value;
	var tId = $('tipoS').value;
	var fecha = $('fechaS').value;
	var paquete = $('paqueteS').value;
	var objAjax = new Request( {
		method : 'get',
		url : urllocal + 'ajax/searchpaquetes/dId/' + dId + '/tId/' + tId
				+ '/fecha/' + fecha + '/paquete/' + paquete + '/',
		onSuccess : function(texto, xmlrespuesta) {
			$('paqFields').innerHTML = texto;
			ocultarTodos();
		}
	}).send();
}

function insertarPaqueteVFile(n) {
	var strData = "";
	var fid = window.opener.document.getElementById('fId').value;
	var pid = n
	strData += "fid=" + fid + "|pid=" + pid + "|";

	strData += $('fechaS').value;
	var toUrl = urllocal + 'ajax/insertpaqfile/data/' + strData + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.opener.location.reload();
			window.close();
		}
	}).send();
	return;
}

function addPolitica() {
	var pid = $('politica_cancelacion_id').value;
	var id = $('sanc').value;
	var toUrl = urllocal + 'ajax/addpolitica/id/' + id + '/pid/' + pid + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.location.reload();
		}
	}).send();
}

function deletePolitica(id) {
	var toUrl = urllocal + 'ajax/deletepolitica/id/' + id + '/';
	var objAjax = new Request( {
		method : 'get',
		url : toUrl,
		onRequest : function() {
		},
		onSuccess : function(texto, xmlrespuesta) {
			window.location.reload();
		}
	}).send();
}

window.addEvent('domready', function() {

	Element.implement( {
		fancyShow : function() {
			this.fade('in');
		},
		fancyHide : function() {
			this.fade('out');
		},
		show : function() {
			this.setStyle('display', '');
		},
		hide : function() {
			this.setStyle('display', 'none');
		}
	});
});

/*
 * completarCamposDate @element el
 */
function completarCamposDate(el, e) {
	var val = el.value;
	var l = val.length;
	var ul = val.substr(-1);
	if (e.key == 'tab') {
		return val;
	}
	if (!$chk(ul.toInt())) {
		return val.substr(0, (l - 1));
	}
	if (l < 10 && e.key != 'backspace') {
		var nom = (arguments.length > 2) ? arguments[2] : 'aaaa-mm-dd';
		switch (nom) {
		case 'aaaa-mm-dd':
			val += (l == 4 || l == 7) ? '-' : '';
			break;
		case 'dd-mm-aaaa':
			val += (l == 2 || l == 5) ? '-' : '';
			break;
		}
	} else {
		val = val.substr(0, 9);
	}
	return val;
}

function testFecha(e) {
	var campo = ($chk(arguments[2])) ? arguments[2]: this;
	if ($chk(campo.value)) {
		var val = completarCamposDate(campo, e);
		$(campo.id).value = val;
		if (val.length == 10 && $chk(arguments[1]))
			eval(arguments[1] + '()');
		return true;
	}
	return;
}
/*
 * completa el select anidado @sPId = id del padre @urlDestino = url
 * controlador/accion a la que se enviara la peticion
 */
function completarSelectAnidado(sPId) {
	var cPad = $(sPId);
	var d = cPad.get('rel');
	var a = d.split('-');
	var val = cPad.options[cPad.selectedIndex].value;
	var objAjax = new Request( {
		method : 'get',
		url : urllocal + 'ajax/selectanidados/t/' + a[1] + '/pid/'
				+ val.toInt() + '/hid/' + a[0],
		onRequest : inicioDeProceso,
		onSuccess : function(texto, xmlrespuesta) {
			var sp = texto.indexOf('-');
			var id = texto.substr(0, sp);
			texto = texto.substr(sp + 1);
			$(id).empty();
			$(id).innerHTML = texto;
			finDeProceso();
		},
		onFailure : function(err) {
			finDeProceso();
			alert(err);
		}
	}).send();
}
/* cargar botones de opcion*/
function cargarBotonesOpcion()
{
	$$('.borrar').addEvent('click' ,borrar);
}
/*- fin cargar botones de opcion-*/
