// FUNCIONES CALENDARIO
var inicio;

function MuestraCalendario(div) {
if (document.getElementById(div).style.display=="inline") { document.getElementById(div).style.display="none"; }
else { document.getElementById(div).style.display="inline"; }
}

function ImprimeCalendario(Anio,Mes,div,campo) {

var meses = new Array(12);
meses[0] = "Ene.";
meses[1] = "Feb.";
meses[2] = "Mar.";
meses[3] = "Abr.";
meses[4] = "May.";
meses[5] = "Jun.";
meses[6] = "Jul.";
meses[7] = "Ago.";
meses[8] = "Sep.";
meses[9] = "Oct.";
meses[10] = "Nov.";
meses[11] = "Dic.";

//si la fecha de inicio de temporada ya paso, no se deben aceptar
//reservaciones con fecha anterior por lo tanto establece al dia de hoy los valores;:
var DiaInicio = new Date(AnioDe,MesDe,DiaDe,0,0,0);
var DiaFinal = new Date(AnioA,MesA+1,2-2,0,0,0);
if (DiaInicio < Hoy) {
	DiaInicio=Hoy;
	AnioDe= Hoy.getYear();
	MesDe=Hoy.getMonth();
	DiaDe=Hoy.getDate();
}

//alert(DiaFinal);

if (Anio == 0) { Anio = AnioDe; Mes = MesDe;}


var dtPriemerDiaMes = new Date(Anio,Mes,1,0,0,0);
var dtUltimoDiaMes = new Date(Anio,Mes+1,2-2,0,0,0);
var intUltimoDiaMes = dtUltimoDiaMes.getDate(); //retorna el numero del ultimo dia del mes.

var casillas = intUltimoDiaMes + dtPriemerDiaMes.getDay();
var lineas = parseInt(casillas /7);
if (lineas <(casillas/7)) { lineas +=1; }

var FgStop =0;
if (DiaFinal > dtUltimoDiaMes) { FgStop=1; }

var ct =1;
var dt =1;

var cal = "<table border='0' width='100%' cellspacing='1' class='CalTabla'>";

if (Mes==11) { ny= Anio+1; nm=0; py=Anio; pm=Mes-1; }
else if (Mes==0) { ny= Anio; nm=Mes+1; py=Anio-1; pm=11; }
else  { ny= Anio; nm=Mes+1; py=Anio; pm=Mes-1;}

cal += "<tr class='CalFondoTitulo'><td>";

if (DiaInicio >= dtPriemerDiaMes) { cal += "<img src='../../i-TravelSoft/paginas/fle_anterior_off.gif' alt='' width='14' height='14' border='0'>";}
else {
	cal += "<a href=\"javascript:void(0)\" onclick=\"ReMes(" + py + "," + pm + ",'" + div + "','" + campo + "')\">";
	cal += "<img src='../../i-TravelSoft/paginas/fle_anterior.gif' alt='" + meses[pm] + " del " + py + "' width='14' height='14' border='0'>";
	cal += "</a>";
}

cal += "</td><td colspan='5' align='center'><strong>" + meses[Mes] + " " + Anio +  "</strong></td><td align='right'>";

if (FgStop==1) {

cal += "<a href=\"javascript:void(0)\" onclick=\"ReMes(" + ny + "," + nm + ",'" + div + "','" + campo + "')\">";
cal += "<img src='../../i-TravelSoft/paginas/fle_sigi.gif' alt='" + meses[nm] + " del " + ny + "' width='14' height='14' border='0'>";
cal += "</a>";

}
else { cal += "<img src='../../i-TravelSoft/paginas/fle_sigi_off.gif' alt='' width='14' height='14' border='0'>"; }
cal += "</td></tr>";


cal += "<tr align='center' class='CalFondoDiasSem'><td>D</td><td>L</td><td>M</td><td>M</td><td>J</td><td>V</td><td>S</td></tr>";


for (I=1;I<=lineas;I++) {
	cal += "<tr align='center' class='CalDias'>";
	
	for (i=1;i<=7;i++) {
		
		cal += "<td>";
		
		if ((ct <=dtPriemerDiaMes.getDay())||(dt>intUltimoDiaMes)) { 
			cal +="&nbsp;";
		}
		
		else if ((Anio <= AnioDe)&&(Mes<=MesDe)&&(dt <= DiaDe) ) {
			cal += dt; //pone el dia sin liga.
			dt+=1;
		}
		
		else if ((FgStop==0) && (dt > DiaA) ) {
			cal += dt; //pone el dia sin liga.
			dt+=1;
		}
				
		else { 
			cal+="<a href='javascript:void(0)' onclick=\"AsignaValorCampo(" + dt + "," + Mes + "," + Anio  + ",'" + campo + "')\" class='cal'>" + dt + "</a>"; //pone el dia con liga
			dt+=1;
		}
		
		cal += "</td>";
		ct +=1;
		
	} //fin for dias
	
	cal += "</tr>";
}

cal += "</table>";

return cal;

}

function AsignaValorCampo(d,m,a,CampoId) {

var Fecha;

d = parseInt(d);
m = parseInt(m+1);
a = parseInt(a);

var d1 = d;
var m1 = m;

if (d1 < 10) { d1 = "0" + d1; }
if (m1 < 10) { m1 = "0" + m1; }

Fecha = d1 + "/" + m1 + "/" + a;
document.getElementById(CampoId).value= Fecha;
inicio =  new Date(a,m-1,d,0,0,0);
AsignaLValorAFinal()

}


function AsignaLValorAFinal() {
	var a = inicio.getYear();
	var m = parseInt(inicio.getMonth()+1);
	var d = inicio.getDate();
	
	if (a < 2000) { a += 1900; }

	var Fecha2 = new Date(a,m-1,(d+Dias+NochesExtras)-1,0,0,0);

	a = parseInt(Fecha2.getYear());
	m = parseInt(Fecha2.getMonth()+1);
	d = Fecha2.getDate();
	

	if (a < 2000) { a += 1900; }

	
	if (d < 10) { d = "0" + d; }
	if (m < 10) { m = "0" + m; }
	
	var Fecha3 = d + "/" + m + "/" + a;
	
	document.getElementById('fecha2').value=Fecha3;
}

function CambioNochesExtras(NochesE) {
	NochesExtras=parseInt(NochesE);
	if (typeof(inicio)=="undefined") { return; }
	AsignaLValorAFinal();
}

function CambioNochesExtras2(NochesE) {
	NochesExtras=parseInt(NochesE);
	if (document.getElementById('fecha').value != "") {
		var f = new Array(3);
		f = document.getElementById('fecha').value.split("/");
		d = parseInt(f[0]);
		m = parseInt(f[1]+1);
		a = parseInt(f[2]);
		
		
		inicio =  new Date(a,m-1,d,0,0,0);
		AsignaLValorAFinal()
		
	}
}

function cambiacomboFecha(NF) {
	if (NF =="") { 	
		document.getElementById('fecha2').value=""; 
		return;
	}
	//NF = "08/08/2008";
	var f = new Array(2);
	f = NF.split("/");
	d = f[0].valueOf();
	m = parseInt(f[1].valueOf()-1);
	a = f[2].valueOf();
	
	inicio =  new Date(a,m,d,0,0,0);
	AsignaLValorAFinal()
}



function ReMes(a,m,div,campo) { 
	document.getElementById(div).innerHTML="";
	document.getElementById(div).innerHTML= ImprimeCalendario(a,m,div,campo);
}

//TERMINA CALENDARIO

function MenorChange(id,Valor,HayMenores) {
	if (HayMenores != 0) { 
		document.getElementById('imen_hab_'+id).length =1;
	}
	
	if (Valor == 3) { 
		if (HayMenores != 0) { 
			document.getElementById('imen_hab_'+id).options[1] = new Option("1 menor",1);
			SetMenor(id,0);
		}
		document.getElementById('adts'+id).src = "../../i-TravelSoft/paginas/ico_h_3.gif";
		
		return;
	}
	if (Valor == 4) { 
		document.getElementById('adts'+id).src = "../../i-TravelSoft/paginas/ico_h_4.gif";
		if (HayMenores != 0) { SetMenor(id,0); }
		return;
	}
	
	if (Valor ==0 || Valor ==1) {
		document.getElementById('adts'+id).src = "../../i-TravelSoft/paginas/px_ffffff.gif";
		if (HayMenores != 0) { 
			document.getElementById('imen_hab_'+id).options.length =1;
			SetMenor(id,0);
		}
		return;
	}
	
	//alert(id);
	
	document.getElementById('adts'+id).src = "../../i-TravelSoft/paginas/ico_h_" + Valor + ".gif";
	
	if (HayMenores != 0) {
		document.getElementById('imen_hab_'+id).options[1] = new Option("1 menor",1);
		document.getElementById('imen_hab_'+id).options[2] = new Option("2 menores",2);
	 	SetMenor(id,0);
	}

};
		
function ValidaNumero(id,valor) {
	if ((document.getElementById('iadts_hab_'+id).value ==3)&&(valor==2))  { 
		alert("La habitación triple sólo acepta un menor como máximo.");
		document.getElementById('imen_hab_'+id).selectedIndex=1;
		document.getElementById('imen_hab_'+id).remove(2);
	}
};

function SetMenor(id,Valor) {
	if (Valor ==2) { document.getElementById('men'+id).src = "../../i-TravelSoft/paginas/ico_2men.gif";}
	if (Valor ==1) { document.getElementById('men'+id).src = "../../i-TravelSoft/paginas/ico_1men.gif";}
	if (Valor ==0) { document.getElementById('men'+id).src = "../../i-TravelSoft/paginas/px_ffffff.gif";}
}


function Numero(e) { 
	key=(document.all) ? e.keyCode : e.which;
	if ((key==33||key==34||key==35||key==36||key==37||key==38||key==39||key==40||key==41||key==42||key==43||key==45||key==46||key==47||key>57))  { return false; }
	return true;
}

function SolicitaCotizacion(forma) {
	var Atributos = "";
	Atributos += "height=350,";
	Atributos += "width=480,";
	Atributos += "top=50,";
	Atributos += "left=50,";
	Atributos += "location=no,";
	Atributos += "resizable=no,";
	Atributos += "scrollbars=yes,";
	Atributos += "menubar=no,";
	Atributos += "status=no,";
	Atributos += "toolbar=no";
	SolCot = window.open("about:blank","SolCot", Atributos);
	
	forma.submit();
	
	SolCot.focus();
}

	
function reseteaForma(forma) {
	document.getElementById("BtnCotiza").style.visibility="visible";
	document.FormaSolCot.reset();
	document.getElementById("Resultado").innerHTML = "";
}


