fechaa = "09/09/2011";  // menos 1 dia del original
fechab = "17/09/2011"; //+ 1 dia del original

function restablecerr()
{
	obj=document.getElementById('frame1');
	obj.src="enviar_cont.html"; 
	obj=document.getElementById('errorpago');
	obj.style.display="none";
}

function anular()
{
	document.getElementById("f1").value="";		
	obj=document.getElementById('errorpago');
	obj.style.display="none";
}
function anular2()
{
	document.getElementById("f2").value="";		
	obj=document.getElementById('errorpago');
	obj.style.display="none";	

}
function restablecer()
{
	obj=document.getElementById('TotalMontoPaqt2');
	obj.style.display="inline";
	innerTexto('TotalMontoPaqt2','0.00');	
	//obj=document.getElementById('sfra');
	//obj.style.display="none";
	obj=document.getElementById('frame1');
	obj.src="envios.html"; 
	obj=document.getElementById('errorpago');
	obj.style.display="none";
		innerTexto('diashabi','');
			document.getElementById('dhos').value=""  ;
}

function frmpagos()
{
	cmonto();
	document.getElementById('frmform').action="https://incatrailreservations.com/hotelviza.com/pagos.php";
	document.getElementById('frmform').target="";
}
function frmenvios()
{
	cmonto();	
	obj=document.getElementById('sfra');
	obj.style.display="inline";
	document.getElementById('frmform').action="http://hotelviza.com/envios.php";
	document.getElementById('frmform').target="destino";	

	

}
function cmonto()
{
obj=document.getElementById('errorpago');
	obj.style.display="none";
obj=document.getElementById('TotalMontoPaqt2');
obj.style.display = "inline";
fical=document.getElementById('f1').value
ffcal=document.getElementById('f2').value
if(fical!="" && ffcal!="")
{
	evaluar(fical,ffcal);	
}

th=document.getElementById('tipohabi').value;
np=document.getElementById('nhabi').value;
cxh=0;
	switch(th)
	{
		case "Habitacion Simple": cxh=22;break;
			case "Habitacion Doble": cxh=33;break;
				case "Habitacion Triple": cxh=43;break;
					case "Suite Matrimonial": cxh=43;break;
					case "Habitacion Matrimonial": cxh=33;break;
					
						case "Single": cxh=22;break;
						case "Double": cxh=33;break;
						case "Triple": cxh=43;break;
						case "Suite - Full bed": cxh=43;break;
						case "Double bed": cxh=33;break;
	}
	mt=cxh*np;
	cd=DiferenciaFechas("frmform");
	if(cd==0){cd=1;}
	tpm=mt*cd; 
	document.getElementById('txtmonto').value=tpm.toFixed(2);
	
	
	//document.getElementById('mimonto').innerText="Monto Total $ "+tpm.toFixed(2);	
	if(fical!="" && ffcal!="")
{

	PCOMPLETOSINO("cbopcompleto")		;
	innerTexto('diashabi',cd);	
	document.getElementById('dhos').value=cd  ;
}
	
		
}
function DiferenciaFechas (formulario) {     
   CadenaFecha1 = document.getElementById('f2').value  ;
   CadenaFecha2 = document.getElementById('f1').value ;  
   var fecha1 = new fecha(CadenaFecha1)      ;
   var fecha2 = new fecha(CadenaFecha2)   ;
   var miFecha1 = new Date(fecha1.anio, fecha1.mes, fecha1.dia )   ;
   var miFecha2 = new Date(fecha2.anio, fecha2.mes, fecha2.dia )   ;
  
   var diferencia = miFecha1.getTime() - miFecha2.getTime()   ;
   var dias = Math.floor(diferencia/(1000 * 60 * 60 * 24))   ; 
   
   return dias;   
}
function fecha( cadena ) {   
   var separador = "/"  ;
   if (cadena.indexOf( separador ) != -1 ) {   
        var posi1 = 0   ;
        var posi2 = cadena.indexOf( separador, posi1 + 1 )   ;
        var posi3 = cadena.indexOf( separador, posi2 + 1 )   ;
        this.dia = cadena.substring( posi1, posi2 )   ;
        this.mes = cadena.substring( posi2 + 1, posi3 );   
        this.anio = cadena.substring( posi3 + 1, cadena.length )   ;
   } else {   
        this.dia = 0   ;
        this.mes = 0   ;
        this.anio = 0   ;   
   }   
}

function innerTexto(idElement, stringInner)
{
	if(document.all)
		document.getElementById(idElement).innerText = stringInner;
	else	
		document.getElementById(idElement).textContent = stringInner;			
}
function PCOMPLETOSINO(x)
	{
		xvalor=document.getElementById(x).value;				
		if (xvalor=="10%")
		{				
				tm=document.getElementById("txtmonto").value;		
				vartxt=(tm*0.1).toFixed(2);				
				innerTexto('TotalMontoPaqt2',vartxt);
		}
		if (xvalor=="COMPLETO")
		{				
				tm=document.getElementById("txtmonto").value;				
				innerTexto('TotalMontoPaqt2',tm);				
		}
		
		
  	}   


/////////////
 
function comparaFecha(fecha, fecha2){
var fechaIni=fecha.split("/");
var fechaFin=fecha2.split("/");

if(parseInt(fechaIni[2],10)>parseInt(fechaFin[2],10)){
return(true);
}else{
if(parseInt(fechaIni[2],10)==parseInt(fechaFin[2],10)){
if(parseInt(fechaIni[1],10)>parseInt(fechaFin[1],10)){
return(true);
}
if(parseInt(fechaIni[1],10)==parseInt(fechaFin[1],10)){
if(parseInt(fechaIni[0],10)>parseInt(fechaFin[0],10)){
return(true);
}else{
return(false);
}
}else{
return(false);
}
}else{
return(false);
}
}

}

function evaluar(fical,ffcal)
{
mivar=0;
		document.getElementById("errorpago").style.display="none";				
		vcmdpagos=document.getElementById("cmdpagos");
		vcmdpagos.disabled=false;
	if(comparaFecha(fical, fechaa)==true && comparaFecha(fical,fechab)==false)
	{		
		vcmdpagos.disabled=true;
		document.getElementById("errorpago").style.display="inline";
		mivar=1;				
	}
	
	if(comparaFecha(ffcal, fechaa)==true && comparaFecha(ffcal,fechab)==false)
	{		
		vcmdpagos.disabled=true;
		document.getElementById("errorpago").style.display="inline";				
		mivar=2;
	}
	
	if(mivar==0 )
	{
		if(comparaFecha(fechaa, fical)==true && comparaFecha(fechab,ffcal)==false)
		{
			
					vcmdpagos.disabled=true;
					document.getElementById("errorpago").style.display="inline";				
		}
		
		
	}
	
	
}
function mostrardiv() {
		
		div = document.getElementById('flotante');
		
		div.style.display = '';
		cerrar2() 
		}
		
		function cerrar() {
		
		div = document.getElementById('flotante');
		
		div.style.display='none';
		
		}
		function mostrardiv2() {
		
		div2 = document.getElementById('flotante2');
		
		div2.style.display = '';
		cerrar() 
		} 
		function cerrar2() {
		
		div2 = document.getElementById('flotante2');
		
		div2.style.display='none';
		
		}
		function Abrir_ventana () {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=508, height=565, top=0, left=540";
window.open("http://hotelviza.com/terminos.php","",opciones);
}
		function Abrir_ventana2 () {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=508, height=565, top=0, left=540";
window.open("http://hotelviza.com/en/terminos.php","",opciones);
}
