// JavaScript Document
// Parametro de Navegacion
Navegacion = 0;
var browser = "";
var browsername = navigator.appName;
function new_vod (url,streamtitle,customfeatures) 
{
	windowFeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=624,height=212,titlebar=no';


	var browser = "";
	var browsername = navigator.appName;
	var browserversion = parseInt(navigator.appVersion);
	var browserplatform = navigator.userAgent;
	if (browsername == "Netscape") 
	{
		browser = "ns" + browserversion;
	}
	else
	{
		if (browsername == "Microsoft Internet Explorer") 
		{
			if (browserversion >= 4) 
			{
				browser = "ie" + browserversion;
			}
			else
			{
				browser = "ie3";
			}
		}
	}

	if ((customfeatures) && customfeatures != '') 
	{
		windowFeatures = customfeatures;
	}

	if (url.indexOf(".rm",(url.length-10)) != -1) 
	{
		if (browser != 'ie3') 
		{
			hasplugin = 'false';
			if ( (browserplatform.indexOf('Mac') !=-1) && ( browsername != "Netscape") )  
			{
				numPlugins = 0;
				for (i = 0; i < numPlugins; i++) 
				{
					plugin = navigator.embeds[i];
					if (plugin.name.substring(0,10)=="RealPlayer") 
					{
						hasplugin = 'true';
					}
				}
			}
			else
			{
				numPlugins = navigator.plugins.length;
				for (i = 0; i < numPlugins; i++) 
				{
					plugin = navigator.plugins[i];
					if (plugin.name.substring(0,10)=="RealPlayer") 
					{
						hasplugin = 'true';
					}
				}
			}
			if (browser.substring(0,2) == 'ie') 
			{
				hasplugin = 'true';
			}
			if (hasplugin == 'true') 
			{
				videoWin = window.open (url , 'video', windowFeatures);
				if (streamtitle != '') 
				{
					videoWin.streamtitle=streamtitle;
				}
				videoWin.document.close();		
			}
			else
			{
				stream = url.substring(0,(url.length-5));
				location.href=stream + '.ram';
			}
		}
		else
		{
			videoWin = window.open (url , 'video', windowFeatures);
			if (document.images) 
			{
				if (streamtitle != '') 
				{
					videoWin.streamtitle=streamtitle;
				}
			}
			videoWin.document.close();			
		}		
	}
	else
	{
		videoWin = window.open (url , 'video', windowFeatures);
		if (document.images) 
		{
			if (streamtitle != '') 
			{
				videoWin.streamtitle=streamtitle;
			}
		}
		videoWin.document.close();
	}
}

var browserversion = parseInt(navigator.appVersion);
if (browsername == "Netscape") 
{
	browser = "ns" + browserversion;
}
else
{
	if (browsername == "Microsoft Internet Explorer") 
	{
		if (browserversion >= 4) 
		{
			browser = "ie" + browserversion;
		}
		else 
		{
			browser = "ie3";
		}
	}
}
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);

// this handles the homepage picture of the day
function popNav(url,name,features) 
{
	if ((browser == "ns3","ns4") || (browser == "ie4")) 
	{
		popBox = window.open(url,name,features);
		popBox.focus();
	}
	else
	{
		if (browser == "ie3") 
		{
			popBox = window.open(url,name,features);
		}  
	}
}

function med_vod(vidlocation){

	openWindow(vidlocation,'770x196','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=770,height=196');
}

// this is for opening pop-up windows
function openWindow (earl,name,widgets) 
{
	host = location.hostname;
	if (host.indexOf('customnews') != -1) 
	{
		var url = 'http://customnews.cnn.com' + earl;
	}
	else
	{
		var url = earl;
	}
	popupWin = window.open (url,name,widgets);
	//popupWin.opener.top.name="opener";
	popupWin.focus();
	
}

function closeWindow () 
{
	parent.close ();
}

function goTW()
{
	var URL = document.pathfinder.site.options[document.pathfinder.site.selectedIndex].value;
	window.location.href = URL;
}
function new_vod1(vidlocation){

	openWindow(vidlocation,'500x465','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=465');
	popupWin.opener.top.name="closed";
}

function new_vod2(vidlocation){

	openWindow(vidlocation,'500x448','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=448');
	popupWin.opener.top.name="closed";
}

function new_vod3(vidlocation){

	openWindow(vidlocation,'770x465','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=465');
	popupWin.opener.top.name="closed";
}

function new_vod4(vidlocation){

	openWindow(vidlocation,'563x223','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=563,height=126');
	popupWin.opener.top.name="closed";
}

function new_vod5(vidlocation){

	openWindow(vidlocation,'374x160','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=197, top=200, width=384,height=140');
	popupWin.opener.top.name="closed";
}

function new_vod6(vidlocation){

	openWindow(vidlocation,'497x305','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=10, top=10, width=520,height=500');
	popupWin.opener.top.name="closed";
}
function localizacion(vidlocation){

	openWindow(vidlocation,'449x249','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=197, top=200, width=449,height=249');
	popupWin.opener.top.name="closed";
}

function new_vod7(vidlocation){

	openWindow(vidlocation,'563x223','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=592,height=247');
	popupWin.opener.top.name="closed";
}

function new_vod8(vidlocation){

	openWindow(vidlocation,'449x249','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=449,height=249');
	popupWin.opener.top.name="closed";
}

function new_vod9(vidlocation){

	openWindow(vidlocation,'563x223','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=50');
	popupWin.opener.top.name="closed";
}

function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) 
		{
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
   		}
	}
return params;
}

function ShowMsgEmpty(fieldname) 
	{
  		 //alert("No puede dejar el campo <<"+fieldname+">> vacío."); 
		 alert(fieldname); 
	}

	
  	// Funcion que retornal si el campo es nulo
	function isEmpty(e) 
	{
        if ((e.value == null) || (e.value == ""))
    		return true;
	}
  	// Funcion que valida un campo de texto
  	function textOk(text,msg) {
		if (isEmpty(text)){
			ShowMsgEmpty(msg);
			text.focus();
			text.select();
			return false;
		}
	return true;	
	}
	function mailOk(text, msg)
     {	 	
      var str = text.value; 	
      result =  ((str.indexOf('@') != -1) && (str.indexOf('@') != 0) && (str.indexOf('@') != str.length -1) && (str.indexOf('.') != -1) && (str.indexOf('.') != 0) && (str.indexOf('.') != str.length -1))  
      if (!result)
       alert(msg);
	  text.focus();
	  text.select();
      return result
    }
		
	
    function textYes(text,msg) {
 	if ((text.value==1) && (msg.value!=null)){
			alert("Si selecciona la opcion yes tiene que marcar un hotel."); 
			text.focus();
			text.select();
			return false;
		}
	return true;	
	}

//Validar los dartos de Newsletter
//Form Fields validation
function ValidaNForm(NF)
{	
		if(!mailOk(NF.email,"Email"))
			return false;
		if(!textOk(NF.fname,"First Name"))
			return false;
		if(!textOk(NF.lname,"Last Name"))
			return false;
		if(!textOk(NF.address,"Address"))
			return false;
		if(!textOk(NF.city,"City"))
			return false;
		if(!textOk(NF.zip,"Zip/Post Code"))
			return false;
		if (isEmpty(NF.country)|| NF.country.value==0){
			ShowMsgEmpty("Country");
			NF.country.focus();
			return false;
		}
		if (isEmpty(NF.idioma)|| NF.idioma.value==0){
			ShowMsgEmpty("Prefered Languages");
			NF.idioma.focus();
			return false;
		}
		if(!isChecked(NF,'You must check at least one interest')){
			alert("You must check at least one interest");
			NF.elements['interest[0]'].focus();
			return false;
		}
		if ((NF.FirstSelectDay.options[NF.FirstSelectDay.selectedIndex].value!=0) && 
			(NF.FirstSelectMonth.options[NF.FirstSelectMonth.selectedIndex].value!=0) && 
			(NF.FirstSelectYear.options[NF.FirstSelectYear.selectedIndex].value!=0))
				NF.birth.value = NF.FirstSelectYear.options[NF.FirstSelectYear.selectedIndex].value + '-' +
								NF.FirstSelectMonth.options[NF.FirstSelectMonth.selectedIndex].value + '-' +
								NF.FirstSelectDay.options[NF.FirstSelectDay.selectedIndex].value;	
}
// Validar los contactos del travel professional
function ValidaContactForm(TPF)
{
		// Validar los campos nombre
		if(!textOk(TPF.email,"Email"))
			return false;
		// Validar email
		if(!mailOk(TPF.email,"Email"))
			return false;
		// Validar los campos email no nulo
		if(!textOk(TPF.Asunto,"Comment"))
			return false;
}


function ValidaTPForm(TPF)
{
		// Validar los campos nombre
		if(!textOk(TPF.aname,"Name"))
			return false;
		// Validar los campos email no nulo
		if(!textOk(TPF.email,"Email"))
			return false;
		// Validar email
		if(!mailOk(TPF.email,"Email"))
			return false;		
		// Validar los campos travelname
		if(!textOk(TPF.travelname,"Company name"))
			return false;
		// Validar los campos Company identifier
		if (isEmpty(TPF.tagencia) || TPF.tagencia.value==0){
			ShowMsgEmpty("Company identifier");
			TPF.tagencia.focus();
			return false;
		}
		// Validar los campos IATA
		if(TPF.tagencia.value!=5)
		{
			if(!textOk(TPF.IATA,"IATA"))
				return false;		
		}
		// Validar los campos address
		if(!textOk(TPF.address,"Address"))
			return false;
		// Validar los campos city
		if(!textOk(TPF.city,"City"))
			return false;
		// Validar los campos zip
		if(!textOk(TPF.zip,"Zip"))
			return false;
		// Validar los campos country
		if (isEmpty(TPF.country)|| TPF.country.value==0){
			ShowMsgEmpty("Country");
			TPF.country.focus();
			return false;
		}
		// Validar los campos phone
		if(!textOk(TPF.phone,"Phone"))
			return false;
		// Validar los campos de factura
		if(!textOk(TPF.user,"User Name"))
			return false;
		// Validar los campos pass
		if(!textOk(TPF.pass,"Password"))
			return false;
		// Validar los campos pass
		if(TPF.pass.value!=TPF.confirmpass.value)
		{
			alert('Los campos Clave y Confirmar clave deben ser iguales');
			TPF.pass.focus();
			return false;
		}
}
// Funcion que validad Olvido su palabra clave en el Tavel Professional
function ValidaForgotForm(TPF)
{
		// Validar los campos email
		if(!textOk(TPF.email,"Email"))
			return false;
		// Validar los campos de factura
		if(!textOk(TPF.user,"User Name"))
			return false;
		// Validar los campos de factura
		if(!textOk(TPF.pass,"Password"))
			return false;
		// Validar los campos de factura
		if(!textOk(TPF.confirmpass,"Confirm Password"))
			return false;
		// Validar los campos pass
		if(TPF.pass.value!=TPF.confirmpass.value)
		{
			alert('Los campos Clave y Confirmar clave deben ser iguales');
			TPF.pass.focus();
			return false;
		}
}

//****************************************************

function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) 
		{
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
   		}
	}
return params;
}

// Funcion para onmaouse over de las imagenes
function Rollover(theImage, theSrc)
{
var objStr,obj;
	if(document.images)
	{
		if (typeof(theImage) == 'string') 
		{
			objStr = 'document.' + theImage;
			obj = eval(objStr);
			obj.src = theSrc;
		} 
		else if ((typeof(theImage) == 'object') && theImage && theImage.src) 
		{
			theImage.src = theSrc;
		}
	}
}

// Funcion que muestra la noticia
function ShowNew(New, Path)
{
	var url = Path + "news/new_popup.php?new=" + New + "&longtext=true";
	openWindow(url,'563x223','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=498,height=350');
	popupWin.opener.top.name="closed";
}

// Validacion de correo electronico
function valid_email(form_name, field_name)
{
  var form = eval('document.'+form_name);
  var str = form.elements[field_name].value; 
  result =  ((str.indexOf('@') != -1) && (str.indexOf('@') != 0) && (str.indexOf('@') != str.length -1) && (str.indexOf('.') != -1) && (str.indexOf('.') != 0) && (str.indexOf('.') != str.length -1))  
  if (!result)
  {
   alert('La dirección de correo electrónico no es valida');
   form.elements[field_name].focus();
   form.elements[field_name].select();
  }

  return result;
}

// Validacion de formularios
function valid_all(Form)
{
 result = true;
 error = false;
 for (var i = 1; ((i < fields.length) && (!error)); i++)
  {
   if (((Form.elements[fields[i]].value == '') || (Form.elements[fields[i]].value == 0)) && !Form.elements[fields[i]].disabled)
     {alert('You must fill the field "'+display[i]+'".');
      error = true;
      result = false;
      Form.elements[fields[i]].focus();}
  }    

 return result;
}

function ShowAgree(lang)
{
	if(lang=='es')
	{
		msg = "--------------- Términos para descargar fotos --------------\n\n";
		msg += "Los derechos de producción de este material son propiedad de Sol Meliá Cuba, cualquier venta, \n";
		msg += "distribución y exibición del mismo es destinado al uso exclusivo para la promoción de sus \n";
		msg += "hoteles. Cualquier otra utilización necesita previa autorización de Sol Melia Cuba.\n\n";
		msg += "Aceptar los términos y proceder con la descarga\n";
	}
	else
	{
		msg = "--------------- Terms for download the photos --------------\n\n";
		msg += "Duplication rights of this material are the property of Sol Meliá Cuba. Any sales, distribution\n";
		msg += "or exhibit here of may have the sole aim of promoting its hotels. Any other uses require previous\n";
		msg += "authorization by Sol Meliá Cuba.\n\n";
		msg += "Accept the terms and continue with the download\n";
	}
	return confirm(msg);
}

function numChecked(frm)
{
	j=0;
	for(i=0;i< frm.length;i++)
	{
		e=frm.elements[i];
		if (e.type=='checkbox' && e.name != 'allbox' && e.checked)
		j++;		
	}
	return j;
}

function Subm(act,first,dosub)
{
	num = ((first) ? slct1st(frm) : numChecked(frm));
	if (!num)
	{	
		alert("You must select at least one Additional Service");
		return false;
	}	
}

// ******* Funciones para la reserva con fastbooking *******/

var FBRESA = "http://www.fastbookings.biz/DIRECTORY/";

function hhotelPTC(val, lg, codeprice, codetrack, cluster)
{
	hhotelResa(val, lg, codeprice, "", "", codetrack, cluster, "")
}
function hhotelPTC1(val, lg, codeprice, codetrack, cluster)
{
	hhotelResa1(val, lg, codeprice, "", "", codetrack, cluster, "")
}
function hhotelPromo(val, lg, theme)
{
	hhotelResa(val, lg, "DYNPROMO", "", "", "", "", theme)
}
function hhotelNegociated(cname, lg, codeprice, codetrack, cluster)
{
	hhotelResa(cname, lg, codeprice, "", "", codetrack, cluster, "", "negociated=1");
}
function hhotelSearchGroup(cluster, lg, price, nights, title)
{
	hhotelSearch(cluster, lg, price, nights, title, "");
}
function hhotelSearchPartner(cluster, lg, price, codetrack, title)
{
	if (codetrack != "") args = "&from="+codetrack;
	else	args = "";
    hhotelSearch(cluster, lg, price, "", title, "", args);

}
function hhotelSearchPriceDate(cluster, price, nights, title,firstdate)
{
	// firstdate : format "YYMMDD"
	var args="";
	if (firstdate != "") args = "FirstDate="+firstdate;
	hhotelSearch(cluster, "", price, nights, title, "", args);
}

function hhotelDispoprice(theForm)
{
	theForm.action = FBRESA + "dispoprice.phtml";
	window.open('','dispoprice', 'toolbar=no,width=700,height=600,menubar=no,scrollbars=yes,resizable=yes');
	document.idForm.submit();
}
function hhotelSearchPromo(cluster, lg, theme)
{
	hhotelSearch(cluster, lg, "", "", "", theme);
}

function hhotelcancel(cname,lg)
{
  var waction = FBRESA+"cancel.phtml?state=77&Hotelnames="+cname;
  if (lg != "") waction += "&langue="+lg;
  window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

function hhotelResa1(val, lg, codeprice, firstroom, firstdate, codetrack, cluster, theme)
{
	var waction = FBRESA+"preresa.phtml?Hotelnames="+val;
	if (lg != "") waction += "&langue="+lg;
	if (firstroom != "") {
		waction += "&FirstRoomName="+firstroom;
		if (codeprice == "")
			codeprice = "DIRECT";
		}
	if (firstdate != "") {
		waction += "&FirstDate="+firstdate;
		if (codeprice == "")
			codeprice = "DIRECT";
		}
	waction += "&FSTBKNGCode="+codeprice;
	if (codetrack != "") waction += "&FSTBKNGTrackLink="+codetrack;
	if (cluster != "") waction += "&clustername="+cluster;
	if (theme != "") waction += "&theme="+theme;	
	window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");	
	//window.location = waction;
}

function hhotelResa(val, lg, codeprice, firstroom, firstdate, codetrack, cluster, theme)
{
	var waction = FBRESA+"preresa.phtml?Hotelnames="+val;
	if (lg != "") waction += "&langue="+lg;
	if (firstroom != "") {
		waction += "&FirstRoomName="+firstroom;
		if (codeprice == "")
			codeprice = "DIRECT";
		}
	if (firstdate != "") {
		waction += "&FirstDate="+firstdate;
		if (codeprice == "")
			codeprice = "DIRECT";
		}
	waction += "&FSTBKNGCode="+codeprice;
	if (codetrack != "") waction += "&FSTBKNGTrackLink="+codetrack;
	if (cluster != "") waction += "&clustername="+cluster;
	if (theme != "") waction += "&theme="+theme;	
	window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");	
	//window.location = waction;
}

function hhotelSearch(cluster, lg, price, nights, title, theme)
{
	var waction = FBRESA+"crs.phtml?clusterName="+cluster;
	if (lg != "") waction += "&langue="+lg;
	if (price != "") waction += "&FSTBKNGCode="+price;
	if (nights != "") waction += "&nights="+nights;
	if (title != "") waction += "&title="+escape(title);
	if (theme != "") waction += "&theme="+theme;
	window.open(waction,"search","toolbar=no,width=700,height=550,menubar=yes,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}
function change_div()
{ 		
	if(document.getElementById('contenu') && document.getElementById('loading')) 
	{
		var contenu_div = document.getElementById('contenu');
		var loading_div = document.getElementById('loading');
		contenu_div.style.display='block';
		loading_div.style.display='none';   
	}
}

//Nuevas
//enable desable array of checkboxes
function ChgStateCheckBoxes(form,boxname,boxNum, state)
{
	for(i=0;i< boxNum;i++){
		form.elements['boxname['+i+']'].disabled = state;
		}
}

function isChecked(frm,msg)
{
	var checked = false;
	for(i=0;i< frm.length;i++)
	{
		e=frm.elements[i];
		if (e.type=='checkbox' && e.checked){
			checked = true;
			break;
		}
	}
	if (!checked) alert (msg);
	return checked;
}

function markChkBox(form,chkName,index)
{
	var checkbox = form.elements[chkName+'['+index+']'].checked = true;
	checkbox.checked = true;
}

function setRadioOption(chkObj,code)
{
	eval("var radios = document.all.offert_" + code)
	if (chkObj.checked == true){
		if (radios.length > 0)
			radios[0].checked = true
			else radios.checked = true
	} else {
			if (radios.length > 0){
				for (var i=0; i < radios.length;i++)
					radios[i].checked = false;
				} else radios.checked = false;	
			}
}

<!-- helper script that uses the calendar -->
var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

//** Validacion del CRS Home
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function ShowAgesInfo(type, value)
{
	if(type==1 && value==1)
	{
		document.getElementById("age1").style.display = "block";
		document.getElementById("age_content").style.display = "block";
		document.getElementById("age2").style.display = "none";
	}
	else if(type==1 && value==2)
	{
		document.getElementById("age1").style.display = "block";
		document.getElementById("age_content").style.display = "block";
		document.getElementById("age2").style.display = "block";
	}
	else if(type==1 && value==0)
	{
		document.getElementById("age1").style.display = "none";
		document.getElementById("age_content").style.display = "none";
		document.getElementById("age2").style.display = "none";
	}
	if(type==2 && value==1)
	{
		document.getElementById("iage1").style.display = "block";
		document.getElementById("age_content1").style.display = "block";
		document.getElementById("iage2").style.display = "none";
	}
	else if(type==2 && value==2)
	{
		document.getElementById("iage1").style.display = "block";
		document.getElementById("age_content1").style.display = "block";
		document.getElementById("iage2").style.display = "block";
	}
	else if(type==2 && value==0)
	{
		document.getElementById("iage1").style.display = "none";
		document.getElementById("age_content1").style.display = "none";
		document.getElementById("iage2").style.display = "none";
	}
}

