// 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) 
{
  return ((e.value == null) ||
	  (e.value.replace(/^\s*(\S*)\s*$/, "$1") == ""));
}

// 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)
{
  // Regular expression for an email address
//   reMailAddress = /^\w+[-+.\w]*@\w+(\.\w)+$/;
//   complies = reMailAddress.test(text.value);
//   if (! complies ) {
//     alert(msg);
//     text.focus();
//     text.select();
//   }
//   return complies;

  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 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 ValidaNForm(NF, IntCount)
{	
  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.language)|| NF.language.value==0){
    ShowMsgEmpty("Prefered Languages");
    NF.language.focus();
    return false;
  }
  if(!IntCount){
    alert("You must check at least one interest");
    //NF.language.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((i == 1 || i == 4) || (i == 5 || i == 8) ){ //Add by Luiso & Onelio's Company 
      if (((Form.elements[fields[i]].value == '') || (Form.elements[fields[i]].value == 0)) && !Form.elements[fields[i]].disabled)
	{alert('El campo "'+display[i]+'" no puede estar vacio.');
	error = true;
	result = false;
	Form.elements[fields[i]].focus();}
    }
    }    

  return result;
}

function valid_all_modified(Form)  //Add by Luiso & Onelio's Company
{
  result = true;
  error = false;
  for (var i = 0; ((i < fields.length) && (!error)); i++){
    if (((Form.elements[fields[i]].value == '') || (Form.elements[fields[i]].value == 0)) && !Form.elements[fields[i]].disabled){
        alert('El campo "'+display[i]+'" no puede estar vacio.');
        error = true;
        result = false;
        Form.elements[fields[i]].focus();
    }
  }    

  return result;
}
