var LightWindow = {
  open: function(pagina) {
	myLightWindow.activateWindow({
		href: pagina,
		width: 900, 
		height: 700, 
		iframeEmbed: true}
	);
  }
};
function showHideElem(id) {
  if (!document.getElementById) return false;
  var elem = document.getElementById(id);
  if (showHideRow.style.display != "none") {
	  showHideRow.style.display = "none"; // ocultar fila
  } else {
	  showHideRow.style.display = ""; // mostrar fila
  }
  
  return false;
}

// sets the display attribute to html element
function setDisplay(id, val)
{
	var element = document.getElementById(id);
	if(element!= null)
	{
		element.style.display=val;
	}
}

// sets the class attribute to html element
function setClass(id, val)
{
	var element = document.getElementById(id);
	if(element!= null)
	{
		element.className=val;
	}
}


function ResizeText(textArea, length){

	if (textArea.length > length) {
		
		textArea = textArea.substr(0,length) + "...";
	}
	
	return textArea;
	
}

function ResizeElemCategory(id) {
	
	categorias = id;
	pixelC = 22;
	dato =categorias *  pixelC;
	return dato;
}

function ResizeElemDivTable(id){
	tarifas = id;
   	pixel = 62;
   	dato =  tarifas *  pixel;
 
	return dato;

}
function PositionFooter(id){
	if(id==0)
	{
		id=1;
	}
	multiplicador = id;
   	pixel = 295;
   	dato =  multiplicador *  pixel + 35;
	return dato;

}
/**
 * Metodo que muestra o esconde el numero de input text que contiene las edades
 * de los pasajeros dependiendo del numero de pasajaros selecionados.
 * 
 * @return devuelve el estado de visibility de los input conforme el numero de
 *         pasajeros elegidos.
 */
function selectAges() {

	var n = document.getElementById("passengers").value;
	var elem2 = document.getElementById("passengerAges2");
	var elem3 = document.getElementById("passengerAges3");
	var elem4 = document.getElementById("passengerAges4");
	elem2.style.visibility = 'hidden';
	elem3.style.visibility = 'hidden';
	elem4.style.visibility = 'hidden';

	if (n > 1) {
		elem2.style.visibility = 'visible';
	}
	if (n > 2) {
		elem3.style.visibility = 'visible';
	}
	if (n > 3) {
		elem4.style.visibility = 'visible';
	}
}
/**
 * Metodo para el el texto que indica al utilizador que para reservar mas de un
 * camarote tiene que realizar una reserva por camarote.
 * 
 * @return cambia el estado del div que contiene el texto entre block o none.
 */
function showNumberCabin() {
	
	var selector = document.getElementById("selectNumberCabin");
	var elem = document.getElementById("numberCabins");
	
	if( parseInt(selector.value) > 1)
	{
		elem.style.display = "block";
	}else
	{
		elem.style.display = "none";
	}
	checkC2C('c2cStep1');
}

function showMessage(cabinNumber)
{
	if(cabinNumber != 1)
	{
		document.getElementById('numberCabinText').style.display='block';
	}
	else
	{
		document.getElementById('numberCabinText').style.display='none';
	}
}
function sendDataFormSearchResult(navy, cruise, category, date, hasFlight, hasDiscount, ncrcamarote, nuevo)
{
	
	$('navyHidden').value=navy;
	$('cruiseHidden').value=cruise;
	$('dateHidden').value=date;
	$('categoryHidden').value=category;
	$('hasFlightHidden').value=hasFlight;
	$('hasDiscountHidden').value=hasDiscount;
	$('ncrcamaroteHidden').value=ncrcamarote;
	$('nuevoC').value=nuevo;
	
	$('initPreBookingForm').submit();
	
	return false;
}


var elementAnim;


function expandCabinType(cabinTypeCategoriesId, cabinTypePricesId, matrizId, contGeneralId, contOfertaId, expandLinkId, contractLinkId)
{
	// shows all categories for this cabin type
	setDisplay(cabinTypeCategoriesId , '' );
	
	
	// shows all prices for this cabin type
	var i=0;
	while( document.getElementById(cabinTypePricesId + "_" + i) != null)
	{
		setDisplay(cabinTypePricesId + "_" + i , '' );
		i++;
	}
	
	var heightToAdd = i * 20;
	
	var contGeneralHeight = parseInt( document.getElementById(contGeneralId).style.height.replace('px', '') ) + heightToAdd;
	var contOfertaHeight = parseInt( document.getElementById(contOfertaId).style.height.replace('px', '') ) + heightToAdd;
	var matrizHeight = parseInt( document.getElementById(matrizId).style.height.replace('px', '') ) + heightToAdd;
	
	document.getElementById(contGeneralId).style.height= contGeneralHeight + 'px';
	document.getElementById(contOfertaId).style.height= contOfertaHeight + 'px';
	document.getElementById(matrizId).style.height= matrizHeight + 'px';
	
	setDisplay(expandLinkId , 'none');
	setDisplay(contractLinkId , '');
	
}

function contractCabinType(cabinTypeCategoriesId, cabinTypePricesId, matrizId, contGeneralId, contOfertaId, expandLinkId, contractLinkId)
{
	// hide all categories for this cabin type
	setDisplay(cabinTypeCategoriesId , 'none' );
	
	
	// hide all prices for this cabin type
	var i=0;
	while( document.getElementById(cabinTypePricesId + "_" + i) != null)
	{
		setDisplay(cabinTypePricesId + "_" + i , 'none' );
		i++;
	}
	
	var heightToRest = i * 20;
	
	var contGeneralHeight = parseInt( document.getElementById(contGeneralId).style.height.replace('px', '') ) - heightToRest;
	var contOfertaHeight = parseInt( document.getElementById(contOfertaId).style.height.replace('px', '') ) - heightToRest;
	var matrizHeight = parseInt( document.getElementById(matrizId).style.height.replace('px', '') ) - heightToRest;
	
	document.getElementById(contGeneralId).style.height= contGeneralHeight + 'px';
	document.getElementById(contOfertaId).style.height= contOfertaHeight + 'px';
	document.getElementById(matrizId).style.height= matrizHeight + 'px';
	
	setDisplay(contractLinkId , 'none');
	setDisplay(expandLinkId , '');
	
}


function shadeRowAndColumHeader (rowTdId, columnTdId, rowClassName, columnClassName) 
{
	setClass(rowTdId, rowClassName );
	setClass(columnTdId, columnClassName );
	
}

// obtains an object for AJAX request
function obtainXmlHttpRequest()
{
	var request=null;
	
	if (window.ActiveXObject) {
		request= new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		request= new XMLHttpRequest();
	}
	return request;
}

// displays a tab as current
function displayTabAsCurrent(tab)
{
	var ulTabs=document.getElementById('menu-cruceros');
	if (ulTabs != null)
	{
		var liListTabs = ulTabs.getElementsByTagName('li');
		
		for(var i=0; i<liListTabs.length; i++)
		{
			setClass(liListTabs[i].id, '');
		}
		
		setClass(tab +'-li', 'current');
	}
	
	
}

// obtains jsonTabs file
function obtainJsonTabs(navyId, shipCod, tab, divId, divPricesId)
{
	navyIdGlobal = navyId;
	shipCodGlobal = shipCod;
	tabGlobal = tab;
	divIdGlobal = divId;
	divIdPriceGlobal=divPricesId;
	
	
	// obtains json
	if(shipJsonObject == null)
	{
		if(xmlHttpRequest!=null&&xmlHttpRequest.readyState!=0&&xmlHttpRequest.readyState!=4)
		{
			xmlHttpRequest.abort();
		}
		
		xmlHttpRequest=obtainXmlHttpRequest();
		
		xmlHttpRequest.onreadystatechange=stateCheckerLoadTabs;
		// open socket connection
		xmlHttpRequest.open('GET','/js/cruises/tabs.json',true);
		xmlHttpRequest.send(null);
		
	}else
	{
		setDisplay(divPricesId, 'none');
		displayTabAsCurrent(tab);
		eval('showTab'+ tab +'( divId, shipJsonObject, navyIdGlobal );');
	}
	
	
}

// obtains jsonTabs response and parse it.
function stateCheckerLoadTabs()
{
	if(xmlHttpRequest.readyState==4)
	{
       	if(xmlHttpRequest.status==200)
		{
       		// recogemos el json como string.
			var tabsJson = xmlHttpRequest.responseText;
			// parseamos el json.
			var jsonTabsParsed = eval('(' + tabsJson + ')');
			
			shipJsonObject =getShipJsonObject(navyIdGlobal, shipCodGlobal, jsonTabsParsed );
			setDisplay(divIdPriceGlobal, 'none');
			displayTabAsCurrent(tabGlobal);
			
			eval('showTab'+ tabGlobal +'( divIdGlobal, shipJsonObject , navyIdGlobal );');
			
		}
	    else
		{
       		
	    }
    }	
}

// obtain a ship object by navy id and ship code from jsonTabs
function getShipJsonObject(navyId, shipCod, jsonTabs)
{
	for(var i=0; i < jsonTabs.navies.length; i++)
	{
		var navy = jsonTabs.navies[i];
		if(navy.id==navyId)
		{
			for(var j=0; j<navy.ships.length; j++)
			{
				ship=navy.ships[j];
				if(ship.cod==shipCod)
				{
					return ship;
				}
			}
		}
	}
	
	return null;
	
}

// shows Camarotes Tab
function showTabcamarotes(divId, shipJsonObject, navyId)
{
	if(shipJsonObject != null)
	{
			var tabContentDiv = document.getElementById(divId);
			tabContentDiv.innerHTML ='';
			
			/*
			 * Create table
			 */ 
			var tableCamarotes = document.createElement('table');
			tableCamarotes.className = 'crc-tabla-camarotes';
			var tbodyCamarotes = document.createElement('tbody');
			tableCamarotes.appendChild(tbodyCamarotes);
			
			tabContentDiv.appendChild(tableCamarotes);
			
			/*
			 * Create ship description row
			 */
			var trShipDesc = document.createElement('tr');
			var tdShipDesc = document.createElement('td');
			tdShipDesc.className = 'crc-barcos-descripcion';
			tdShipDesc.colSpan='3';
		
			
			var txtShip1 = document.createTextNode('El barco ');
			tdShipDesc.appendChild(txtShip1);
			
			var spanSeo = document.createElement('span');
//			spanSeo.setAttribute('class', 'precios-seo-c');
			spanSeo.className='precios-seo-c';
			var txtShip2 = document.createTextNode(shipJsonObject.name);
			spanSeo.appendChild(txtShip2);
			tdShipDesc.appendChild(spanSeo);
			
			var txtShip3 = document.createTextNode(' ofrece los siguientes tipos y categorías de camarotes.');
			tdShipDesc.appendChild(txtShip3);
			trShipDesc.appendChild(tdShipDesc);
			tbodyCamarotes.appendChild(trShipDesc);
			
			
			var trSpace = document.createElement('tr');
			trSpace.className = 'crc-espacio-camarotes';
			tbodyCamarotes.appendChild(trSpace);
			
		
			/*
			 * Create one row for each category
			 */
			for(var i=0; i<shipJsonObject.categories.length; i++)
			{
				var catJson = shipJsonObject.categories[i];
				var trCat = document.createElement('tr');
				
				var tdPhoto = document.createElement('td');
				tdPhoto.className = 'crc-foto-pestana';
				/*
				 * Category photo
				 */
				if(catJson.photo != null)
				{
					var imgCat = document.createElement('img');
					imgCat.style.width='115px';
					imgCat.style.height='80px';
					imgCat.setAttribute('src', '/images/cruises/' + catJson.photo);
					tdPhoto.appendChild(imgCat);
					
				
				}
				trCat.appendChild(tdPhoto);
				
				/*
				 * Category content
				 */
				var tdCatTxt =document.createElement('td');
				tdCatTxt.className = 'crc-categoria-texto';
				tdCatTxt.vAlign='top';
				
				
				var p =  document.createElement('p');
//				p.setAttribute('class', 'negro-normal');
				p.className='negro-normal';
				p.setAttribute('valign', 'top');
				
				var maxCapacityText ='';
				var titleBold = document.createElement("b");
				if(catJson.cap!=null)
				{
					maxCapacityText=' Capacidad máxima: ' + catJson.cap + ' pasajeros.';
				}
				var txt1= document.createTextNode('Categoría ' + catJson.cod + ' - ' + catJson.name +'.' + maxCapacityText );
				titleBold.appendChild(txt1);
				p.appendChild(titleBold);
				p.appendChild(document.createElement('br'));
				
				if (catJson.covs.length>0)
				{
					var txt2 = document.createTextNode('Situado en las cubiertas:' );
					var boldTxt = document.createElement("b");
					
					var coverts='';
					for(var j=0; j<catJson.covs.length; j++)
					{
						coverts+=' ' +catJson.covs[j].name + ',';
					}
					coverts=coverts.substring(0,coverts.length-1) + '.';
					boldTxt.appendChild(document.createTextNode(coverts));
					
					p.appendChild(txt2);
					p.appendChild(boldTxt);
					p.appendChild(document.createElement('br'));
				}
				
				tdCatTxt.appendChild(p);
				if (catJson.desc != null)
				{
				var pDesc = document.createElement('p');
				pDesc.innerHTML =catJson.desc;
				tdCatTxt.appendChild(pDesc);
				}
				trCat.appendChild(tdCatTxt);
				/*
				 * Category photo layout
				 */
				if(catJson.phoLay != null)
				{
					var tdPhotoLay = document.createElement('td');
					tdPhotoLay.className = 'crc-foto-planta';
	
					var imgCatLay = document.createElement('img');
					imgCatLay.className = 'crc-foto-planta-camarote';
					imgCatLay.src='/images/cruises/' + catJson.phoLay;
//					imgCatLay.setAttribute('src', '/images/cruises/' + catJson.phoLay);
					tdPhotoLay.appendChild(imgCatLay);
					
					trCat.appendChild(tdPhotoLay);
				}
				
				tbodyCamarotes.appendChild(trCat);
			}
	}
}

// shows 'Detalles del barco' tab
function showTabficha(divId, shipJsonObject, navyId)
{
	if(shipJsonObject != null)
	{
		var tabContentDiv = document.getElementById(divId);
		tabContentDiv.innerHTML ='';
		
		/*
		 * div ship Name
		 */
		var divName = document.createElement('div');
		divName.className="divShipNameStyle";
//		divName.setAttribute('style', 'padding-right: 10px; padding-left: 10px;');
		
		var pName=document.createElement('p');
//		pName.setAttribute('class', 'precios-seo-c');
		pName.className='precios-seo-c';
//		pName.setAttribute('style', 'padding-top: 5px;');
		pName.appendChild(document.createTextNode(shipJsonObject.name));
		
		divName.appendChild(pName);
		tabContentDiv.appendChild(divName);
		
		
		/*
		 * div image and technical sheet
		 */
		var divImageSheet = document.createElement('div');
		divImageSheet.id="ficha-imagen";
//		divImageSheet.setAttribute('id', 'ficha-imagen');
		
		if(shipJsonObject.photo != null)
		{
			var shipImg = document.createElement('img');
			shipImg.style.width='161px';
			shipImg.style.height='106px';
			shipImg.src='/images/cruises/' + shipJsonObject.photo;
//			shipImg.setAttribute('src', '/images/cruises/' + shipJsonObject.photo);
			divImageSheet.appendChild(shipImg);
		}
		
		
		tabContentDiv.appendChild(divImageSheet);
		
		
		/*
		 * div ship description, and div technical list
		 */
		if(shipJsonObject.desc != null)
		{
			var descArray = shipJsonObject.desc.split('$&');
			var shipDesc = descArray[0];
			
			var dataArray = new Array();
			if(descArray.length >1)
			{
				var shipTech = descArray[1];
				dataArray = shipTech.split('#');
			}
			
			var divDesc= document.createElement('div');
			divDesc.id="ficha-descripcion";
//			divDesc.setAttribute('id', 'ficha-descripcion');
			
			var pDesc = document.createElement('p');
			pDesc.className="pDescShipTechStyle";
//			pDesc.setAttribute('style', 'padding-top: 5px;');
			
// pDesc.appendChild(document.createTextNode(shipDesc));
			pDesc.innerHTML = shipDesc;  
			
			divDesc.appendChild(pDesc);
			tabContentDiv.appendChild(divDesc);
			
			var divTechList = document.createElement('div');
			divTechList.id="lista-tecnica";
//			divTechList.setAttribute('id','lista-tecnica');
			
			var ulTech1 = document.createElement('ul');
//			ulTech1.setAttribute('class', 'lista-tecnica');
			ulTech1.className='lista-tecnica';
			var innerDiv = document.createElement('div');
			innerDiv.className="verdana7azul";
//			innerDiv.setAttribute('class', 'verdana7azul');
			
			var ulTech2 = document.createElement('ul');
			ulTech2.className="ulTech2Style";
//			ulTech2.setAttribute('style', 'margin-top: 20px; margin-left: 40px;');
			
			var li;
			for(var i=0; i<dataArray.length; i++)
			{
				li=document.createElement('li');
				
				var boldPoint = document.createElement('b');
				boldPoint.appendChild(document.createTextNode('• '));
				li.appendChild(boldPoint);
				
				li.appendChild(document.createTextNode(dataArray[i] + '.'));
				ulTech2.appendChild(li);
			}
			
			innerDiv.appendChild(ulTech2);
			ulTech1.appendChild(innerDiv);
			divTechList.appendChild(ulTech1);
			tabContentDiv.appendChild(divTechList);
			
		}
		
		tabContentDiv.appendChild(document.createElement('br'));
			
	}
}

/**
 *  shows Galeria de fotos tab.
 * @param divId
 * @param shipJsonObject
 * @param navyId
 * @return
 */
function showTabfotos(divId, shipJsonObject, navyId)
{
	var NUM_PHOTOS_BY_ROW = 10;
	
	if(shipJsonObject != null)
	{
		var tabContentDiv = document.getElementById(divId);
		tabContentDiv.innerHTML ='';
		
		
		var table = document.createElement('table');
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		tabContentDiv.appendChild(table);
		
		/*
		 * FOR EACH PHOTO SHOWS IT IN A TD OF TABLE. CHANGE TO NEXT TR EACH
		 * NUM_PHOTOS_BY_ROW PHOTOS
		 */
		var tr = document.createElement('tr');
		for(var i=0; i<shipJsonObject.photos.length; i++)
		{
			var photo = shipJsonObject.photos[i];
			
			var td = document.createElement('td');
//			td.setAttribute('width', '98');
//			td.setAttribute('width', '70');
//			td.setAttribute('style', 'padding: 8px 5px;');
			td.className="tdRowPhotoStyle";
			td.style.width="98px";
			td.style.height="75px";
			td.style.border="1px";
			var a = document.createElement('a');
			
			if(photo.desc != null)
			{
				a.setAttribute('title', photo.desc);
			}
			
			var imgSrc =  '/images/cruises/' + photo.id;
			a.rel="shadowbox[galeria];options={counterType:'skip',continuous:true,animSequence:'sync'}"
//			a.setAttribute('rel', "shadowbox[galeria];options={counterType:'skip',continuous:true,animSequence:'sync'}");
//			a.href=imgSrc.replace('.', '_grande.');
			a.href=imgSrc;
//			a.setAttribute('href', imgSrc.replace('.', '_grande.'));
			
			var img = document.createElement('img');
			img.style.width="92px";
			img.style.height="70px";
			img.style.border="1";
			img.src=imgSrc;
//			img.setAttribute('width', '98');
//			img.setAttribute('height', '70');
//			img.setAttribute('border', '1');
//			img.setAttribute('src', imgSrc);
			
			a.appendChild(img);
			td.appendChild(a);
			tr.appendChild(td);
			
			// change to next row table.
			if( ((i+1) % NUM_PHOTOS_BY_ROW) == 0)
			{
				tbody.appendChild(tr);
				tr = document.createElement('tr');
			}
		}
		
		tbody.appendChild(tr);
		Shadowbox.init();
		Shadowbox.setup();
	}
}	
/**
 *  shows 'cubiertas' tab. 
 * @param divId
 * @param shipJsonObject
 * @param navyId
 * @return
 */
function showTabcubiertas(divId, shipJsonObject, navyId)
{
	
	if(shipJsonObject != null)
	{
		var tabContentDiv = document.getElementById(divId);
		tabContentDiv.innerHTML ='';
		
		var table = document.createElement('table');
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		tabContentDiv.appendChild(table);
		
		/*
		 * ship name
		 */
		var trShipName = document.createElement('tr');
		var tdShipName = document.createElement('td');
		tdShipName.className="shipNameStyle";
//		tdShipName.setAttribute('style', 'padding-left: 10px;');
		
		var spanShipName = document.createElement('span');
//		spanShipName.setAttribute('class', 'precios-seo-c');
		spanShipName.className='precios-seo-c';
		spanShipName.appendChild(document.createTextNode(shipJsonObject.name + ':'));
		tdShipName.appendChild(spanShipName);
		trShipName.appendChild(tdShipName);
		tbody.appendChild(trShipName);
		
		/*
		 * ship description
		 */
		if(shipJsonObject.desc != null)
		{
			var descArray = shipJsonObject.desc.split('$&');
			var shipDesc = descArray[0];
			
			var trShipDesc = document.createElement('tr');
			var tdShipDesc = document.createElement('td');
//			tdShipDesc.setAttribute('style', 'padding-left: 10px; padding-top: 10px;');
			tdShipDesc.className="shipDescStyle";
			var divDesc = document.createElement('div');
//			divDesc.setAttribute('id', 'descripcion-cubierta');
			divDesc.id="descripcion-cubierta";
			
			//divDesc.appendChild(document.createTextNode(shipDesc));
			divDesc.innerHTML=shipDesc;
			tdShipDesc.appendChild(divDesc);
			trShipDesc.appendChild(tdShipDesc);
			tbody.appendChild(trShipDesc);
			
		}
		
		/*
		 * ship coverts photo
		 */
		if(shipJsonObject.phoCovs != null)
		{
			var trCovsPhoto = document.createElement('tr');
			var tdCovsPhoto = document.createElement('td');
			
			tdCovsPhoto.setAttribute('align', 'center');
			tdCovsPhoto.className="tdCovsPhotoStyle";
			var imgCovs = document.createElement('img');
			/*
			 * imgCovs.style.width='680px'; imgCovs.style.height='170px';
			 */
//			imgCovs.setAttribute('src', '/images/cruises/' + shipJsonObject.phoCovs);
			imgCovs.src="/images/cruises/" +  shipJsonObject.phoCovs;
			tdCovsPhoto.appendChild(imgCovs);
			trCovsPhoto.appendChild(tdCovsPhoto);
			tbody.appendChild(trCovsPhoto);
		}
		/*
		 * coverts links table
		 */
		var tableLinks =document.createElement('table');
		tableLinks.className="tableLinksStyle";
		tableLinks.align="center";
//		tableLinks.setAttribute('align', 'center');
		var tbodyLinks =document.createElement('tbody');
		tableLinks.appendChild(tbodyLinks);
		tabContentDiv.appendChild(tableLinks);
		
		
		var trLinks = document.createElement('tr');
		
		for(var i=0; i<shipJsonObject.coverts.length; i++)
		{
			var covert = shipJsonObject.coverts[i];
			if(covert.name != null)
			{
				var td = document.createElement('td');
				var a = document.createElement('a');
//				a.setAttribute('class', 'texto-enlaces');
				a.className='texto-enlaces';
				a.href="javascript:showCabinDetails(" + navyId + ", '"+ shipJsonObject.cod + "','" + covert.id + "',0,'displayDeckDetail');";
//				a.setAttribute('href', "javascript:showCabinDetails(" + navyId + ", '"+ shipJsonObject.cod + "','" + covert.id + "',0,'displayDeckDetail');");
//				a.setAttribute('style', 'padding-right: 5px;');
				a.className="aCoverNameStyle";
				a.appendChild(document.createTextNode(covert.name));
				td.appendChild(a);
				trLinks.appendChild(td);
			}
		}
		
		tbodyLinks.appendChild(trLinks);
	}
}


function activarCapa()
{

}
function startScroll(dir, id, le){
	x=le;
	if (dir == "left") {
		elementAnim = dojo.anim(id, { left: le }, 2000);
	}
	else if (dir == "right") {
		elementAnim = dojo.anim(id, { left: 270 }, 1000);
	}
	else if (dir == "up") {
		elementAnim = dojo.anim(id, { top: -400 }, 2000);
	}
	else {
		elementAnim = dojo.anim(id, { top: 0 }, 1500);
	}
}

function stopScroll() {
	elementAnim.stop(); 
}


function afoto(cual,titulo){
	var ventana;
	var cont=0;

	if(cont==1){ventana.close();ventana=null}
	ventana=window.open('','ventana','resizable=yes,scrollbars=no')
	ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.cont=0"><img src="' + cual + '">');
	ventana.resizeTo(this.width+12,this.height+28);
	ventana.setTimeout("self.focus()",100)
	ventana.document.close();
	cont++;
}

function MM_openBrWindow(theURL,winName,features) { // v2.0

	  window.open(theURL,winName,features);
}

function Mes(mesId){
	var Meses = new Array('','Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
	var mes = 0;
	
	if(mesId.substr(0,1)=="0") 
	{
		mes= mesId.substr(1,1);
	}
	if(mesId.substr(0,1)=="1") 
	{
		mes=mesId.substr(0,2);
	}
	
	var linea =  Meses[mes] + mesId.substr(2,5);
	return  linea;
}
function showAirport(airport)
{
	if(airport == 'MAD')
	{
		document.getElementById('availableClass').style.visibility = "visible";
	}
	else
	{
		document.getElementById('availableClass').style.visibility = "hidden";
	}
}
/* lanza el click to call */
/* lanza el click to call */
function lounchClickToCall(servTemplate)
{
	
	webVoicePop('Template=' + servTemplate);
	
}

function isOutOfTimeC2C()
{
	var outOfTime;
	
	var now = new Date();
	var actualHour = now.getHours();
	
	var day = now.getDay();
	if( (day >=1) && (day <=5) && ((10 <= actualHour && actualHour <= 14) || (16 <= actualHour && actualHour <= 20)) )
	{
		outOfTime=false;
	}else
	{
		outOfTime=true;
	}
	
	return outOfTime;
}

function checkC2C(divC2C)
{
	if(!isOutOfTimeC2C())
	{
		setDisplay(divC2C, 'block');
	}
}
// Search and get the json of price and reservation tab.
function loadTabPriceJson(navy, cruise, tab, divId, divIdPrices)
{
	
	document.getElementById(divId).innerHTML='';
	
	navyIdGlobal = navy;
	cruiseGlobal = cruise;
	tabGlobal = tab;
	divIdGlobal = divId;
	divIdPriceGlobal = divIdPrices;
	// obtains json
	if(priceTabJson == null)
	{
		if(xmlHttpRequest!=null&&xmlHttpRequest.readyState!=0&&xmlHttpRequest.readyState!=4)
		{
			xmlHttpRequest.abort();
		}
		
		xmlHttpRequest=obtainXmlHttpRequest();
		
		xmlHttpRequest.onreadystatechange=stateCheckerPriceTab;
		// open socket connection
		xmlHttpRequest.open('GET','/js/cruises/' + navy + '.json',true);
		xmlHttpRequest.send(null);
		
	}else
	{
		setDisplay(divIdPrices, 'block');
		// Si viene desde la pestaña.
		displayTabAsCurrent(tab);
		eval('showTab'+ tab +'(divIdPricesGlobal, priceTabJson);');
	}
	
}
function stateCheckerPriceTab()
{
	if(xmlHttpRequest.readyState==4)
	{
       	if(xmlHttpRequest.status==200)
		{
       		// recogemos el json como string.
			var priceTabJson = xmlHttpRequest.responseText;
			// parseamos el json.
			var priceTabJsonParsed = eval('(' + priceTabJson + ')');
			priceTabJson = obtainInfoPriceTab(cruiseGlobal, priceTabJsonParsed );
			setDisplay(divIdPriceGlobal, 'block');
			displayTabAsCurrent(tabGlobal);
			eval('showTab'+ tabGlobal +'(divIdPriceGlobal, priceTabJson);');
		}
	    else
		{
       		// Do nothing.
	    }
    }	
}
function obtainInfoPriceTab(cruiseGlobal, priceTabJsonParsed)
{
	if (priceTabJsonParsed != null)
	{
		for(var i=0; i < priceTabJsonParsed.cruises.length; i++)
		{
			var cruise = priceTabJsonParsed.cruises[i];
			if(cruise.crCode==cruiseGlobal)
			{
				return cruise;
			}
		}
	}
	return null;
}
/**
 * Method to print the informacion os the cruise into the jsp.
 * 
 * @param divId,
 *            the div where goes the cruise information.
 * @param priceTabJson
 *            the jspn parsed.
 * @return the div.
 */
function showTabprecios(divId, priceTabJson)
{
	if(priceTabJson != null)
	{
			var extraInfoDiv = document.getElementById('content-menu-info');
			extraInfoDiv.innerHTML ='';
			// Create table
			extraInfoDiv.appendChild(createCruiseData(priceTabJson, true));
		}
}
/**
 * Method to adding the information of the cruise.
 * 
 * @param tableExtraInfo,
 *            the table with information of the cruise.
 * @param isTab,
 *            specifies from where are called.
 * @return a table with the information of the cruise.
 */
function createCruiseData(priceTabJson, isTab)
{
	var tableExtraInfo = document.createElement('table');
	tableExtraInfo.setAttribute('width', '99%');
	tableExtraInfo.setAttribute('border', '0');
	var tbodyPriceExtraInfo = document.createElement('tbody');	
	if (!(isTab))
	{
		tbodyPriceExtraInfo.appendChild(createCruiseName(priceTabJson.crName));
	}
	/* Cruise description. */
	tbodyPriceExtraInfo.appendChild(createItineraryDescription(priceTabJson.crDesc));
	/* Tabla de itinerario. */
	tbodyPriceExtraInfo.appendChild(createStepsTable(priceTabJson, isTab));
	/* El Crucero Incluye. */
	tbodyPriceExtraInfo.appendChild(createCruiseIncludes(priceTabJson.crIncl));
	/* El Crucero No Incluye. */
	tbodyPriceExtraInfo.appendChild(createCruiseNIncludes(priceTabJson.crNInc));
	/* Notas importantes. */
	tbodyPriceExtraInfo.appendChild(createImportantNote(priceTabJson.crNote));
	tableExtraInfo.appendChild(tbodyPriceExtraInfo);

	return tableExtraInfo;
}
/**
 * Method to adding the name of the cruise.
 * 
 * @param cruiseName,
 *            the name of the cruise.
 * @return a row table with the name of the cruise.
 */
function createCruiseName(cruiseName)
{
	var cruiseNameTitleTr = document.createElement('tr');
	var cruiseNameTitleTd = document.createElement('td');
	cruiseNameTitleTd.setAttribute('colspan','2');
	cruiseNameTitleTd.setAttribute('style','padding-right:10px; padding-left:10px; padding-bottom:15px; padding-top:10px');
	var cruiseNameTitle = document.createElement('h3');
	cruiseNameTitle.setAttribute('id', 'descripcion');
	cruiseNameTitle.setAttribute('class', 'destacado-azul-rumbo');
	cruiseNameTitle.className='destacado-azul-rumbo';
	var cruiseNameTitleText = document.createTextNode('NOMBRE DEL ITINERARIO ');
	cruiseNameTitle.appendChild(cruiseNameTitleText);
	cruiseNameTitleTd.appendChild(cruiseNameTitle);
	var cruiseNameP = document.createElement('p');
	cruiseNameP.setAttribute('class', 'negro-normal');
	cruiseNameP.className='negro-normal';
	cruiseNameP.setAttribute('style', 'text-align:justify; padding-right:10px; margin-top: 3px');
	var cruiseNameText = document.createTextNode(cruiseName);
	cruiseNameP.appendChild(cruiseNameText);
	
	cruiseNameTitleTd.appendChild(cruiseNameP);
	cruiseNameTitleTr.appendChild(cruiseNameTitleTd);
	
	return cruiseNameTitleTr;
}

/**
 * Method to adding the description of the cruise.
 * 
 * @param cruiseIncludes,
 *            the description of the cruise.
 * @return a row table with the description of the cruise.
 */
function createItineraryDescription(cruiseDescription)
{
	var cruiseDescTitleTr = document.createElement('tr');
	var cruiseDescTitleTd = document.createElement('td');
	cruiseDescTitleTd.setAttribute('colspan','2');
	cruiseDescTitleTd.className="DescTitleTd";
	var cruiseDescTitle = document.createElement('h3');
	cruiseDescTitle.setAttribute('id', 'descripcion');
	cruiseDescTitle.className='destacado-azul-rumbo';
	var cruiseDescTitleText = document.createTextNode('DESCRIPCIÓN DEL RECORRIDO');
	cruiseDescTitle.appendChild(cruiseDescTitleText);
	cruiseDescTitleTd.appendChild(cruiseDescTitle);
	var cruiseDescP = document.createElement('p');
	cruiseDescP.className='negro-normal';
	cruiseDescP.innerHTML=cruiseDescription;
	cruiseDescTitleTd.appendChild(cruiseDescP);
	cruiseDescTitleTr.appendChild(cruiseDescTitleTd);
	
	return cruiseDescTitleTr;
}

/**
 * Method to adding the table with the itinerary steps.
 * 
 * @param cruiseIncludes,
 *            the table with the itinerary steps.
 * @return a row table with the table with the itinerary steps.
 */
function createStepsTable(priceTabJson, isTab)
{
	var cruiseStepTableTr = document.createElement('tr');
	if(!(isTab))
	{
		var cruiseFotoMapTd = document.createElement('td');
		cruiseFotoMapTd.setAttribute('style', 'padding-right:10px; padding-left:10px; padding-bottom:15px; padding-top:10px');
		// div for the map.
		var fotoMapDiv = document.createElement('div');
		fotoMapDiv.setAttribute('class', 'fMap');
		fotoMapDiv.className = 'fMap';
		
		var fotoMapImg = document.createElement('img');
		fotoMapImg.setAttribute('src', '/images/cruises/itineraries/maps/' + priceTabJson.crFMap);
		
		fotoMapDiv.appendChild(fotoMapImg);
		
		cruiseFotoMapTd.appendChild(fotoMapDiv);
		
		cruiseStepTableTr.appendChild(cruiseFotoMapTd);
	}
	
	var cruiseStepTableTd = document.createElement('td');
	cruiseStepTableTd.setAttribute('style', 'padding-right:10px; padding-left:10px; padding-bottom:15px; padding-top:10px');
	
	/*
	 * Building the steps table.
	 */
	var stepTable = document.createElement('table');
	stepTable.setAttribute('width','430px');
	stepTable.setAttribute('cellspacing','0');
	stepTable.setAttribute('cellpadding','0'); 
	stepTable.setAttribute('class', 'tabla');
	stepTable.className='tabla';
	stepTable.setAttribute('valign', 'middle');
	
	var stepTableTBody = document.createElement('tbody');
	
	var stepTableTr = document.createElement('tr');
	var stepTableTdDay = document.createElement('td');
	stepTableTdDay.setAttribute('height','20px');
	stepTableTdDay.setAttribute('class','titular-promos-hoteles');
	stepTableTdDay.className='titular-promos-hoteles';
	stepTableTdDay.setAttribute('style','padding-left:10px');
	var tdDayText = document.createTextNode('Día');
	stepTableTdDay.appendChild(tdDayText);
	var stepTableTdPort = document.createElement('td');
	stepTableTdPort.setAttribute('height','20px');
	stepTableTdPort.setAttribute('class','titular-promos-hoteles');
	stepTableTdPort.className='titular-promos-hoteles';
	stepTableTdPort.setAttribute('style','padding-left:10px');
	var tdPortText = document.createTextNode('Puerto');
	stepTableTdPort.appendChild(tdPortText);
	var stepTableTdArrival = document.createElement('td');
	stepTableTdArrival.setAttribute('height','20px');
	stepTableTdArrival.setAttribute('class','titular-promos-hoteles');
	stepTableTdArrival.className='titular-promos-hoteles';
	stepTableTdArrival.setAttribute('style','padding-left:10px');
	var tdArrivalText = document.createTextNode('Llegada');
	stepTableTdArrival.appendChild(tdArrivalText);
	var stepTableTdDeparture = document.createElement('td');
	stepTableTdDeparture.setAttribute('height','20px');
	stepTableTdDeparture.setAttribute('class','titular-promos-hoteles');
	stepTableTdDeparture.className='titular-promos-hoteles';
	stepTableTdDeparture.setAttribute('style','padding-left:10px');
	var tdDepartureText = document.createTextNode('Salida');
	stepTableTdDeparture.appendChild(tdDepartureText);
	stepTableTr.appendChild(stepTableTdDay);
	stepTableTr.appendChild(stepTableTdPort);
	stepTableTr.appendChild(stepTableTdArrival);
	stepTableTr.appendChild(stepTableTdDeparture);
	
	stepTableTBody.appendChild(stepTableTr);
	
	for (var i = 0; i < priceTabJson.crsteps.steps.length; i++)
	{
		var rowStep = document.createElement('tr');
		
		var tdStepDay = document.createElement('td');
		tdStepDay.setAttribute('height','20px');
		tdStepDay.setAttribute('nowrap','nowrap');
		tdStepDay.setAttribute('class','destacado-azul-rumbo');
		tdStepDay.className='destacado-azul-rumbo';
		tdStepDay.setAttribute('style','padding-left:10px');
		var tdStepDayText = document.createTextNode("Día " + priceTabJson.crsteps.steps[i].dDep);
		tdStepDay.appendChild(tdStepDayText);
		
		var tdStepPort = document.createElement('td');
		tdStepPort.setAttribute('height','20px');
		tdStepPort.setAttribute('nowrap','nowrap');
		tdStepPort.setAttribute('style','padding-left:10px');
		var tdStepPortText = document.createTextNode(priceTabJson.crsteps.steps[i].port);
		tdStepPort.appendChild(tdStepPortText);
		
		var tdStepArrival = document.createElement('td');
		tdStepArrival.setAttribute('height','20px');
		tdStepArrival.setAttribute('nowrap','nowrap');
		tdStepArrival.setAttribute('style','padding-left:10px');
		var tdStepArrivalTextSpan = document.createElement('span');
		var tdStepArrivalText = document.createTextNode(priceTabJson.crsteps.steps[i].hDep);
		tdStepArrivalTextSpan.appendChild(tdStepArrivalText);
		tdStepArrival.appendChild(tdStepArrivalTextSpan);
		
		var tdStepDeparture = document.createElement('td');
		tdStepDeparture.setAttribute('height','20px');
		tdStepDeparture.setAttribute('nowrap','nowrap');
		tdStepDeparture.setAttribute('style','padding-left:10px');
		var tdStepDepartureTextSpan = document.createElement('span');
		var tdStepDepartureText = document.createTextNode(priceTabJson.crsteps.steps[i].hArr);
		tdStepDepartureTextSpan.appendChild(tdStepDepartureText);
		tdStepDeparture.appendChild(tdStepDepartureTextSpan);
		
		rowStep.appendChild(tdStepDay);
		rowStep.appendChild(tdStepPort);
		rowStep.appendChild(tdStepArrival);
		rowStep.appendChild(tdStepDeparture);
		
		stepTableTBody.appendChild(rowStep);
	}
	
	stepTable.appendChild(stepTableTBody);
	
	cruiseStepTableTd.appendChild(stepTable);
	cruiseStepTableTr.appendChild(cruiseStepTableTd);
	
	return cruiseStepTableTr;
}


/**
 * Method to adding what the cruise includes.
 * 
 * @param cruiseIncludes,
 *            what the cruise includes.
 * @return a row table with the information of that cruise includes.
 */
function createCruiseIncludes(cruiseIncludes)
{
	var cruiseIncludesTitleTr = document.createElement('tr');
	var cruiseIncludesTitleTd = document.createElement('td');
	cruiseIncludesTitleTd.setAttribute('colspan','2');
	cruiseIncludesTitleTd.className="IncludesTitleTd";
	var cruiseIncludesTitle = document.createElement('h3');
	cruiseIncludesTitle.setAttribute('id', 'descripcion');
	cruiseIncludesTitle.className='destacado-azul-rumbo';
	var cruiseIncludesTitleText = document.createTextNode('EL CRUCERO INCLUYE');
	cruiseIncludesTitle.appendChild(cruiseIncludesTitleText);
	cruiseIncludesTitleTd.appendChild(cruiseIncludesTitle);
	var cruiseIncludesP = document.createElement('p');
	cruiseIncludesP.className='negro-normal';
	cruiseIncludesP.innerHTML=cruiseIncludes;
	cruiseIncludesTitleTd.appendChild(cruiseIncludesP);
	cruiseIncludesTitleTr.appendChild(cruiseIncludesTitleTd);
	
	return cruiseIncludesTitleTr;
}

/**
 * Method to adding what the cruise not includes.
 * 
 * @param cruiseIncludes,
 *            what the cruise not includes.
 * @return a row table with the information of that cruise not includes.
 */
function createCruiseNIncludes(cruiseNIncludes)
{
	var cruiseNIncludesTitleTr = document.createElement('tr');
	var cruiseNIncludesTitleTd = document.createElement('td');
	cruiseNIncludesTitleTd.setAttribute('colspan','2');
	cruiseNIncludesTitleTd.className="NIncludesTitleTdStyle";
	var cruiseNIncludesTitle = document.createElement('h3');
	cruiseNIncludesTitle.setAttribute('id', 'descripcion');
	cruiseNIncludesTitle.className='destacado-azul-rumbo';
	var cruiseNIncludesTitleText = document.createTextNode('EL CRUCERO NO INCLUYE');
	cruiseNIncludesTitle.appendChild(cruiseNIncludesTitleText);
	cruiseNIncludesTitleTd.appendChild(cruiseNIncludesTitle);
	var cruiseNIncludesP = document.createElement('p');
	cruiseNIncludesP.className='negro-normal';
	cruiseNIncludesP.innerHTML=cruiseNIncludes;
	cruiseNIncludesTitleTd.appendChild(cruiseNIncludesP);
	cruiseNIncludesTitleTr.appendChild(cruiseNIncludesTitleTd);
	
	return cruiseNIncludesTitleTr;
}

/**
 * Method to adding the important notes.
 * 
 * @param importantNote,
 *            the important notes.
 * @return a row table with the important notes.
 */
function createImportantNote(importantNote)
{
	var cruiseNoteTitleTr = document.createElement('tr');
	var cruiseNoteTitleTd = document.createElement('td');
	cruiseNoteTitleTd.setAttribute('colspan','2');
	cruiseNoteTitleTd.className="NoteTitleTdStyle";
	var cruiseNoteTitle = document.createElement('h3');
	cruiseNoteTitle.setAttribute('id', 'descripcion');
	cruiseNoteTitle.id="descripcion";
	cruiseNoteTitle.className='destacado-azul-rumbo';
	var cruiseNoteTitleText = document.createTextNode('NOTAS IMPORTANTES');
	cruiseNoteTitle.appendChild(cruiseNoteTitleText);
	cruiseNoteTitleTd.appendChild(cruiseNoteTitle);
	var cruiseNoteP = document.createElement('p');
	cruiseNoteP.className='negro-normal';	
	cruiseNoteP.innerHTML=importantNote;
	cruiseNoteTitleTd.appendChild(cruiseNoteP);
	cruiseNoteTitleTr.appendChild(cruiseNoteTitleTd);
	
	return cruiseNoteTitleTr;
}

/**
 * Method to get the information of the cruise to show it in teh result page
 * (result.jsp)
 * 
 * @param navy
 *            Navy code.
 * @param cruise
 *            the cruise code.
 * @param divId
 *            the div element that gona show the information
 * @return the json with the itineraries by navy.
 */
function printItineraryData(navy, cruise, divId)
{
	navyIdGlobal = navy;
	cruiseGlobal = cruise;
	divIdGlobal = divId;
	if(cruiseJson == null)
	{
		if(xmlHttpRequest != null && xmlHttpRequest.readyState != 0 && xmlHttpRequest.readyState != 4)
		{
			xmlHttpRequest.abort();
		}
		xmlHttpRequest = obtainXmlHttpRequest();
		xmlHttpRequest.onreadystatechange=stateCheckerCruiseInfo;
		// open socket connection
		xmlHttpRequest.open('GET','/js/cruises/' + navy + '.json',true);
		xmlHttpRequest.send(null);
		
	}else
	{
		showCruiseInfo(divId, cruiseJson);
	}
}
/**
 * Method to parser the response.
 * 
 * @return the json parsed.
 */
function stateCheckerCruiseInfo()
{
	if(xmlHttpRequest.readyState==4)
	{
       	if(xmlHttpRequest.status==200)
		{
       		// recogemos el json como string.
			var cruiseJson = xmlHttpRequest.responseText;
			// parseamos el json.
			var cruiseJsonParsed = eval('(' + cruiseJson + ')');
			cruiseJsonObject = obtainInfoPriceTab(cruiseGlobal, cruiseJsonParsed);
			showCruiseInfo(divIdGlobal, cruiseJsonObject);
		}
	    else
		{
       		// Do nothing.
	    }
    }	
}
/**
 * Method to print the informacion os the cruise into the jsp.
 * 
 * @param divId,
 *            the div where goes the cruise information.
 * @param priceTabJson
 *            the json parsed.
 * @return the div.
 */
function showCruiseInfo(divId, cruiseInfoJson)
{
	if(cruiseInfoJson != null)
	{
			var cruiseInfoDiv = document.getElementById(divId);
			cruiseInfoDiv.innerHTML ='';
			// Adding the table.
			cruiseInfoDiv.appendChild(createCruiseData(cruiseInfoJson, false));
		}
}
/**
 * Method to asign the filter recommended.
 * 
 */
function resetFilter()
{
	var duration = document.getElementById('selDuracion');
	if ('' == duration.value)
	{
	document.getElementById('radRecommended').checked = 1;
	}
	else
	{
	document.getElementById('radPrice').checked = 1;
	}
}

