/*
	Travel.js
	
	Aplicación: WebHotelPlus
	Autor     : WebHotel
	Desc      : Funcionalidad global
*/

// --------------------------------------------------------
// --- Clase CUser 

function CUser()
{
	this.PK          = 0;  // ID del Usuario
	this.Name        = ""; // Nombre del Usuario
	this.NameB2B     = ""; // Nombre del Usuario B2B
	this.EMail       = ""; // Email del Usuario
	this.Type        = ""; // Tipo de Usuario
	
	this.IsLogged    = _IsLogged;
	this.GetName     = _GetName;

// ------------------------------------
// IsLogged: ¿Usuario Registrado?	
function _IsLogged()
{
	return this.PK != 0;
}

// ------------------------------------
// GetName: 	
function _GetName()
{
	if ( this.Type == "F" )
		return this.Name;
	
	return "";
}


} // End of Class

var m_User = new CUser;


// --------------------------------------------------------
// --- Declaración de Variables
var __SysBanner  = null;
var m_VstPK      = "0";  // Visita Actual
var m_ProvPK     = "0";  // Provincia actual
var m_ProvName     = "España";  // Nombre de Provincia actual
var m_CityPK     = "0";  // Ciudad actual
var m_ChainPK    = "";   // Cadena
var m_HtPK       = "";   // Hotel

var m_nMinHeight = 725;

var m_WndCont    = "IFrmCont";
var m_WndWork    = "IFrmC";
var m_WndPopup   = "IFrmPopup";
// ------------------------------------
// ITopWnd: Interfaz para localizar a Top
function ITopWnd() { return true; }

// ------------------------------------
// OnAppInit: Home
function OnAppInit()
{
	try
	{
//OnHomeFone();
		// --- Ajustar contenidos
		FitContent();
		
		// --- Status Bar
		//window.defaultStatus = "WebHotelPlus.com ... Tu Portal de Reservas";
		
		// --- Comenzar Carrusel de Banners
		__SysBanner = new CSysBanner( "idBanner", "/Images/WHPlus/Banners/" );
//		__SysBanner.AddBanner( "banner_top_hfone.swf", 22000 );
		__SysBanner.AddBanner( "whp.swf",        22000 );
//		__SysBanner.AddBanner( "libretto_875.swf", 22000 );
//		__SysBanner.AddBanner( "cubana.swf", 22000 );
//		__SysBanner.AddBanner( "petit_1813.swf", 22000 );
//		__SysBanner.AddBanner( "zenit_2413.swf", 22000 );
		__SysBanner.Start();
	}
	catch(e) {}
}






// ------------------------------------
// BannerClick : Click en Banner
function BannerClick( nHtPK )
{
	try
	{
		RSV_Init( nHtPK );
	}
	catch(e) {}
}

// ------------------------------------
// FitContent: Ajustar contenido
function FitContent( nForzeHeight )
{
	//var nMinHeight = 525;

	var cbDocHeight  = document.documentElement.clientHeight;
	var cbContTop    = document.getElementById( "idContPage" ).offsetTop;
	var cbFootHeight = document.getElementById( "idFootPage" ).offsetHeight;
	
	var cbContHeight = cbDocHeight - ( cbContTop + cbFootHeight + 20 );

	//if ( arguments.length > 0 )
	//	nMinHeight = ( (nMinHeight<nForzeHeight) ? nForzeHeight : nMinHeight);

	if( cbContHeight < m_nMinHeight )
		cbContHeight = m_nMinHeight;

	document.getElementById( "idContPage" ).style.height = cbContHeight + "px";
}

// ------------------------------------
// SetMinHeight: Ajustar contenido
function SetMinHeight( nHeight )
{
	m_nMinHeight = nHeight;
	FitContent();
}

// ------------------------------------
// RestoreMinHeight: Ajustar contenido
function RestoreMinHeight()
{
	m_nMinHeight = 725;
	FitContent();
}

// ------------------------------------
// HidePopup: Ocultar Popup
function HidePopup()
{
	// --- Ocultar IFrame
	try
	{
		var pDiv = document.getElementById( "idPopup" );
		if( pDiv.style.display != "none" )
		{
			pDiv.style.display = "none";
			WndLoad( m_WndPopup, "about:blank" );
		}
	}
	catch(e){}
}

// --------------------------------------------------------
// --- Comandos Home
// ------------------------------------

// funcion para ver opiniones
function On_Opis( nHtPK )
{
	
	// --- Cargar URL
	var sURL = "http://www.hotelfone.com/show_comments_whp.aspx?hotel_id=" + nHtPK+ "&prov_id=2";
	window.open( sURL,"_self");

}
// ------------------------------------
// Abrir Hotelfone
function Hotelfone()
{
	var sURL = "http://www.hotelfone.com/default.aspx?ProvPK=" + m_ProvPK;
	window.open(sURL, target="_blank")	;
}

// ------------------------------------
// Abrir Roxy-Falso
function hotel( nHtPK )
{
	var sURL = "http://www.webhotelplus.com/whp-hotel/es/default.aspx?Ht_PK=" + nHtPK;
	window.open(sURL, target="_blank")	;
}


// ------------------------------------
// Abrir Roxy-Falso por la pagina de Reserva
function hotelR( nHtPK )
{
	var sURL = "http://www.webhotelplus.com/whp-hotel-Rsv/es/default.aspx?Ht_PK=" + nHtPK;
	window.open(sURL, target="_blank")	;
}

// ------------------------------------
// RecommendTo: Recomendar este sitio
function RecommendTo()
{
	var pWnd = CreatePopupWnd( -1, -1, 500, 230 );
	Pop_Load( "default.aspx?Tpl=Home/Pop_RecommendTo" );
}

// ------------------------------------
// RequestAccOnline: Solicitar Reserva Online
function RequestAccOnline()
{
	var pWnd = CreatePopupWnd( -1, -1, 600, 230 );
	Pop_Load( "default.aspx?Tpl=Home/Pop_RequestAccOnline" );
}

// ------------------------------------
// OnAltaNuevo: Alta Nuevo Hotel
function OnAltaNuevo()
{
}


// ------------------------------------
// OnWHPlus: Sobre WebHotelPlus
function OnWHPlus()
{
	var pWnd = CreatePopupWnd( -1, -1, 640, 400 );
	Pop_Load( "default.aspx?Tpl=Home/FOOT_WHPlus" );
}

// ------------------------------------
// OnCG: Condiciones Generales
function OnCG()
{
	var pWnd = CreatePopupWnd( 10, 10, 780, 500 );
	Pop_Load( "default.aspx?Tpl=Home/FOOT_CG" );
}

// ------------------------------------
// OnPP: Política de Privacidad
function OnPP()
{
	var pWnd = CreatePopupWnd( -1, -1, 640, 400 );
	Pop_Load( "default.aspx?Tpl=Home/FOOT_PP" );
}

// ------------------------------------
// OnCopyR: Copyright
function OnCopyR()
{
	var pWnd = CreatePopupWnd( -1, -1, 640, 400 );
	Pop_Load( "default.aspx?Tpl=Home/FOOT_CopyR" );
}


// --------------------------------------------------------
// --- Comandos de Nivel Superior

// ------------------------------------
// OnHome: Home
function OnHome()
{
	try
	{
		var sURL = "default.aspx";
		
		if( m_ProvPK == "0" )
			sURL = "default.aspx?RmtMethod=Home";
		else
			sURL = "default.aspx?RmtMethod=Home_Prov&ProvPK=" + m_ProvPK;

		WndLoad( m_WndCont, sURL );
		
		// --- Ocultar popup		
		HidePopup();
	}
	catch(e){}
}
// OnHomeHotelfone: HomeFone
function OnHomeFone()
{
	try
	{
		var sURL = "";
		
if( m_ProvPK == '1' )  sURL ="http://www.hotelfone.com/destination.aspx?state=1_ESVIT&radio=9&country=ES";
if( m_ProvPK == '2' )  sURL ="http://www.hotelfone.com/destination.aspx?state=2_ESALB&radio=9&country=ES";
if( m_ProvPK == '3' )  sURL ="http://www.hotelfone.com/destination.aspx?state=3_ESALC&radio=9&country=ES";
if( m_ProvPK == '4' )  sURL ="http://www.hotelfone.com/destination.aspx?state=4_ESLEI&radio=9&country=ES";
if( m_ProvPK == '5' )  sURL ="http://www.hotelfone.com/destination.aspx?state=5_ESAVI&radio=9&country=ES";
if( m_ProvPK == '6' )  sURL ="http://www.hotelfone.com/destination.aspx?state=6_ESBJZ&radio=9&country=ES";
if( m_ProvPK == '8' )  sURL ="http://www.hotelfone.com/destination.aspx?state=8_ESBCN&radio=9&country=ES";
if( m_ProvPK == '9' )  sURL ="http://www.hotelfone.com/destination.aspx?state=9_ESBUR&radio=9&country=ES";
if( m_ProvPK == '10' ) sURL ="http://www.hotelfone.com/destination.aspx?state=10_ESCAC&radio=9&country=ES";
if( m_ProvPK == '11' ) sURL ="http://www.hotelfone.com/destination.aspx?state=11_ESXRY&radio=9&country=ES";
if( m_ProvPK == '12' ) sURL ="http://www.hotelfone.com/destination.aspx?state=12_ESCAS&radio=9&country=ES";
if( m_ProvPK == '13' ) sURL ="http://www.hotelfone.com/destination.aspx?state=13_ESCIU&radio=9&country=ES";
if( m_ProvPK == '14' ) sURL ="http://www.hotelfone.com/destination.aspx?state=14_ESODB&radio=9&country=ES";
if( m_ProvPK == '15' ) sURL ="http://www.hotelfone.com/destination.aspx?state=15_ESSCQ&radio=9&country=ES";
if( m_ProvPK == '16' ) sURL ="http://www.hotelfone.com/destination.aspx?state=16_ESCUE&radio=9&country=ES";
if( m_ProvPK == '17' ) sURL ="http://www.hotelfone.com/destination.aspx?state=17_ESGRO&radio=9&country=ES";
if( m_ProvPK == '18' ) sURL ="http://www.hotelfone.com/destination.aspx?state=18_ESGRX&radio=9&country=ES";
if( m_ProvPK == '19' ) sURL ="http://www.hotelfone.com/destination.aspx?state=19_ESGUI&radio=9&country=ES";
if( m_ProvPK == '20' ) sURL ="http://www.hotelfone.com/destination.aspx?state=20_ESEAS&radio=9&country=ES";
if( m_ProvPK == '21' ) sURL ="http://www.hotelfone.com/destination.aspx?state=21_ESHUE&radio=9&country=ES";
if( m_ProvPK == '22' ) sURL ="http://www.hotelfone.com/destination.aspx?state=22_ESHUS&radio=9&country=ES";
if( m_ProvPK == '23' ) sURL ="http://www.hotelfone.com/destination.aspx?state=23_ESJAE&radio=9&country=ES";
if( m_ProvPK == '24' ) sURL ="http://www.hotelfone.com/destination.aspx?state=24_ESLEO&radio=9&country=ES";
if( m_ProvPK == '25' ) sURL ="http://www.hotelfone.com/destination.aspx?state=25_ESLER&radio=9&country=ES";
if( m_ProvPK == '26' ) sURL ="http://www.hotelfone.com/destination.aspx?state=26_ESRIO&radio=9&country=ES";
if( m_ProvPK == '27' ) sURL ="http://www.hotelfone.com/destination.aspx?state=27_ESLUG&radio=9&country=ES";
if( m_ProvPK == '28' ) sURL ="http://www.hotelfone.com/destination.aspx?state=28_ESMAD&radio=9&country=ES";
if( m_ProvPK == '29' ) sURL ="http://www.hotelfone.com/destination.aspx?state=29_ESAGP&radio=9&country=ES";
if( m_ProvPK == '30' ) sURL ="http://www.hotelfone.com/destination.aspx?state=30_ESMJV&radio=9&country=ES";
if( m_ProvPK == '31' ) sURL ="http://www.hotelfone.com/destination.aspx?state=31_ESNAV&radio=9&country=ES";
if( m_ProvPK == '32' ) sURL ="http://www.hotelfone.com/destination.aspx?state=32_ESORE&radio=9&country=ES";
if( m_ProvPK == '33' ) sURL ="http://www.hotelfone.com/destination.aspx?state=33_ESOVD&radio=9&country=ES";
if( m_ProvPK == '34' ) sURL ="http://www.hotelfone.com/destination.aspx?state=34_ESPAL&radio=9&country=ES";
if( m_ProvPK == '35' ) sURL ="http://www.hotelfone.com/destination.aspx?state=35_ESLAP&radio=9&country=ES";
if( m_ProvPK == '36' ) sURL ="http://www.hotelfone.com/destination.aspx?state=36_ESVGO&radio=9&country=ES";
if( m_ProvPK == '37' ) sURL ="http://www.hotelfone.com/destination.aspx?state=37_ESSAL&radio=9&country=ES";
if( m_ProvPK == '38' ) sURL ="http://www.hotelfone.com/destination.aspx?state=38_ESTCI&radio=9&country=ES";
if( m_ProvPK == '39' ) sURL ="http://www.hotelfone.com/destination.aspx?state=39_ESSDR&radio=9&country=ES";
if( m_ProvPK == '40' ) sURL ="http://www.hotelfone.com/destination.aspx?state=40_ESSEG&radio=9&country=ES";
if( m_ProvPK == '41' ) sURL ="http://www.hotelfone.com/destination.aspx?state=41_ESSVQ&radio=9&country=ES";
if( m_ProvPK == '42' ) sURL ="http://www.hotelfone.com/destination.aspx?state=42_ESSOR&radio=9&country=ES";
if( m_ProvPK == '43' ) sURL ="http://www.hotelfone.com/destination.aspx?state=43_ESTAR&radio=9&country=ES";
if( m_ProvPK == '44' ) sURL ="http://www.hotelfone.com/destination.aspx?state=44_ESTER&radio=9&country=ES";
if( m_ProvPK == '45' ) sURL ="http://www.hotelfone.com/destination.aspx?state=45_ESTOL&radio=9&country=ES";
if( m_ProvPK == '46' ) sURL ="http://www.hotelfone.com/destination.aspx?state=46_ESVLC&radio=9&country=ES";
if( m_ProvPK == '47' ) sURL ="http://www.hotelfone.com/destination.aspx?state=47_ESVLL&radio=9&country=ES";
if( m_ProvPK == '48' ) sURL ="http://www.hotelfone.com/destination.aspx?state=48_ESBIO&radio=9&country=ES";
if( m_ProvPK == '49' ) sURL ="http://www.hotelfone.com/destination.aspx?state=49_ESZAM&radio=9&country=ES";
if( m_ProvPK == '50' ) sURL ="http://www.hotelfone.com/destination.aspx?state=50_ESZAZ&radio=9&country=ES";
if( m_ProvPK == '52' ) sURL ="http://www.hotelfone.com/destination.aspx?state=52_ESMEL&radio=9&country=ES";
if( m_ProvPK == '60' ) sURL ="http://www.hotelfone.com/destination.aspx?state=60_ESPMI&radio=9&country=ES";
if( m_ProvPK == '61' ) sURL ="http://www.hotelfone.com/destination.aspx?state=61_ESMAH&radio=9&country=ES";
if( m_ProvPK == '62' ) sURL ="http://www.hotelfone.com/destination.aspx?state=62_ESIBZ&radio=9&country=ES";
if( m_ProvPK == '70' ) sURL ="http://www.hotelfone.com/destination.aspx?state=70_ESLPA&radio=9&country=ES";
if( m_ProvPK == '71' ) sURL ="http://www.hotelfone.com/destination.aspx?state=71_ESLAN&radio=9&country=ES";
if( m_ProvPK == '72' ) sURL ="http://www.hotelfone.com/destination.aspx?state=72_ESFUE&radio=9&country=ES";
if( m_ProvPK == '74' ) sURL ="http://www.hotelfone.com/destination.aspx?state=74_ESG&radio=9&country=ES";





		window.open( sURL,"_top");

	}
	catch(e){}
}

// ------------------------------------
// OnAboutUs: Acerca de
function OnAboutUs()
{
	try
	{
		WndLoad( m_WndCont, "ZABOUT_Frame.htm" );
		
		// --- Ocultar popup		
		HidePopup();
	}
	catch(e){}
}

// ------------------------------------
// OnUserZone: Zona de Usuario
function OnUserZone()
{
	try
	{
		WndLoad( m_WndCont, "ZUSR_Frame.htm" );
		
		// --- Ocultar popup		
		HidePopup();
	}
	catch(e){}
}

// ------------------------------------
// OnHotelZone: Zona de Hotel
function OnHotelZone()
{
//	try
//	{
//		WndLoad( m_WndCont, "ZHT_Frame.htm" );
//		
		// --- Ocultar popup		
//		HidePopup();
//	}
//	catch(e){}
}


// --------------------------------------------------------
// --- USUARIOS

// ------------------------------------
// USR_IsLogged: ¿Usuario Registrado?	
function USR_IsLogged()
{
	return m_User.IsLogged();
}

// ------------------------------------
// USR_Login: Login de Usuario	
function USR_Login()
{
	var sURL = "";
	
	// --- Comprobar si el Usuario está autentificado
	if ( m_User.IsLogged() )
	{
		USR_MDatos( false );
		return;
	}
	
	// --- Login, AutoRegistro etc.
	sURL = "UsrUI.aspx?RmtMethod=USR_LoginForm&Vst_PK=" + m_VstPK;
	WndLoad( m_WndWork, sURL );
}

// ------------------------------------
// USR_LoginOK: Login Correcto	
function USR_LoginOK()
{
	// --- Ir a Mis Datos
	USR_MDatos();
}

// ------------------------------------
// USR_MDatos: Mis Datos	
function USR_MDatos()
{
	// --- Comprobar si el Usuario está autentificado
	if ( !m_User.IsLogged() )
	{
		USR_Login();
		return;
	}
	
	var sURL = "";
	
	sURL  = "UsrUI.aspx?RmtMethod=USR_EditForm&Usr_PK=" + m_User.PK;
	sURL += "&Usr_Type=" + m_User.Type;
	
	WndLoad( m_WndWork, sURL );
}

// ------------------------------------
// USR_AutoReg: AutoRegistro	
function USR_AutoReg()
{
	var sURL = "UsrUI.aspx?RmtMethod=USR_AutoRegForm0";
	WndLoad( m_WndWork, sURL );
}

// ------------------------------------
// USR_AutoRegForm: Formulario de AutoRegistro	
function USR_AutoRegForm1( sType )
{
	var sURL = "UsrUI.aspx?RmtMethod=USR_AutoRegForm1&Usr_Type=" + sType;
	WndLoad( m_WndWork, sURL );
}


// --------------------------------------------------------
// --- RESERVAS : 


// ------------------------------------
// RSV_Init: Prepara datos para reservar en un Hotel
function RSV_Init( Ht_PK, sFrom  )
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_Init&Ht_PK=" + Ht_PK + "&Vst_PK=" + m_VstPK;
		
		if ( arguments.length > 1 )
			sURL += "&From=" + sFrom
			
		// --- Ocultar popup		
		HidePopup();
		
		// --- Cargar Resultados
		WndLoad( m_WndCont, sURL );
	}
	catch(e){}
}

// ------------------------------------
// RSV_List2User: Listado de Reservas para un usuario dado
function RSV_List2User()
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_List2User&Usr_PK=" + GetTopWnd().m_User.PK;
		WndLoad( m_WndWork, sURL );
	}
	catch(e) {}
}

// ------------------------------------
// RSV_Bono: BONO-RESERVA
function RSV_Bono( Rsv_PK )
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_Bono&Rsv_PK=" + Rsv_PK;
		WndLoad( m_WndWork, sURL );
	}
	catch(e) {}
}

// ------------------------------------
// RSV_CancelList2User: Listado de Reservas	que se pueden Cancelar
function RSV_CancelList2User()
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_CancelList2User&Usr_PK=" + GetTopWnd().m_User.PK;
		WndLoad( m_WndWork, sURL );
	}
	catch(e) {}
}

// ------------------------------------
// RSV_QueryCancel: Confirmar la cancelación
function RSV_QueryCancel( Rsv_PK )
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_QueryCancel&Rsv_PK=" + Rsv_PK;
		WndLoad( m_WndWork, sURL );
	}
	catch(e) {}
}

// ------------------------------------
// RSV_SetCancel: Cancelar
function RSV_SetCancel( Rsv_PK )
{
	try
	{
		var sURL = "RsvUI.aspx?RmtMethod=RSV_SetCancel&Rsv_PK=" + Rsv_PK;
		WndLoad( m_WndWork, sURL );
	}
	catch(e) {}
}

// --------------------------------------------------------
// --- BUSCADOR

// ------------------------------------
// Finder_Send: Listado como Reultados de la búsqueda
function Finder_Send()
{
	try
	{
		Ds_SetFieldValue( "fs_XML", m_Finder.m_XML );
		document.formFinder.submit();
	}
	catch(e){}

}

// --------------------------------------------------------
// --- HOTEL

// ------------------------------------
// Ht_Info: Info del Hotel
function Ht_Info( Ht_PK, sFrom )
{
	try
	{
		// --- Posicionar Ventana Popup
		var nLeft   = document.getElementById( "idContPage" ).offsetLeft
		var nTop    = document.getElementById( "idContPage" ).offsetTop;
		var nWidth  = document.getElementById( "idContPage" ).offsetWidth;
		var nHeight = document.getElementById( "idContPage" ).offsetHeight;
		
		var pDiv = document.getElementById( "idPopup" );
		
		pDiv.style.left    = nLeft   + "px";		
		pDiv.style.top     = nTop    + "px";		
		pDiv.style.height  = nHeight + "px";		
		pDiv.style.width   = nWidth  + "px";		
		
		// --- Cargar URL
		var sURL = "HotelUI.aspx?RmtMethod=Ht_Info&Ht_PK=" + Ht_PK + "&From=" + sFrom + "&Vst_PK=" + m_VstPK;
		WndLoad( m_WndPopup, sURL );
		
		// --- Mostrar IFrame y hacer scroll hacia arriba
		window.scrollTo( 0, 0 );
		pDiv.style.display = "block";
	}
	catch(e){}
}

