﻿/*070821 xlbr: (safari opera) dummies to prevent sharepoint form error*/
if (typeof UpdateFormDigest == 'undefined')
{
var UpdateFormDigest = new Function("a", "b", "");
}
if (typeof _spFormOnSubmitWrapper == 'undefined')
{
var _spFormOnSubmitWrapper = new Function("return false;");
}
//Contiene el color para el borde de los controles que no cumplen con la regla de validación.
var colorError = '#CC0000';

function ChangeText(text, msg, url, interfaceValue, interfaceID, defaultMessage) {

    var resp = true;

    var TextBox = text;
    var mensage;
    document.getElementById(TextBox).value = trim(document.getElementById(TextBox).value)
    mensage = trim(msg);
    if ((document.getElementById(TextBox).value == mensage) || (document.getElementById(TextBox).value == '')) {
        document.getElementById(TextBox).style.color = '#D6D3CE';
        document.getElementById(TextBox).style.borderColor = '#FDD341'
        document.getElementById(TextBox).value = msg;
      
        return false;
    }

    var searchFieldValue = document.getElementById("searchField").value;
    if (defaultMessage != searchFieldValue) {
        var url = url + "?" + interfaceValue + "=" + interfaceID + "&id=-1&requestType=&source=1&question=" + searchFieldValue + "&NormalRequest=Ask";
        CreatePopup(url);
    }

    return true;

}

function ClickText(text){

var TextBox = text;

document.getElementById(TextBox).value ='';
document.getElementById(TextBox).style.borderColor = '';
document.getElementById(TextBox).style.color='#000000';

}

function trim(cadena)

{
            for(i=0; i<cadena.length; )
            {
                        if(cadena.charAt(i)==" ")
                                    cadena=cadena.substring(i+1, cadena.length);
                        else
                                    break;

            }
            for(i=cadena.length-1; i>=0; i=cadena.length-1)
            {
                        if(cadena.charAt(i)==" ")
                                    cadena=cadena.substring(0,i);
                        else
                                  break;
            }
return cadena;
}

/**
 * @autor {sruiz}: Para corregir el bug, 3715.
 * @param {String}, layerID: Es la cortina semi transparente.
 * @param {String}, modalLayer: Es el ventana modal (o conjunto de objetos html) que paracerá sobre la cortina.  
 * @param {Integer}, typeModal: Define que ventana modal se utilizará, 1-StoreFront, 2-LoginPopup.
 * @modify:    
 */
function abrir()
{
    OpenOverlay('fade', 'loginPopup');
}
function findPos(obj){
	var posX = obj.offsetLeft;var posY = obj.offsetTop;
	while(obj.offsetParent){
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{
			posX=posX+obj.offsetParent.offsetLeft;
			posY=posY+obj.offsetParent.offsetTop;
			obj=obj.offsetParent;
		}
	}
	var posArray=[posX,posY]
	return posArray;
}
function repositionModals()
{
	var loginPopupA =  document.getElementById('loginPopupLink'); 
	var loginPopupDIV = document.getElementById('loginPopup'); 
	var loginLinkPos = findPos(loginPopupA);
	loginPopupDIV.style.left = (loginLinkPos[0] - ((195 - loginPopupA.offsetWidth)/2)) + 'px';
	loginPopupDIV.style.top = (loginLinkPos[1] + loginPopupA.offsetHeight) + 'px';
}
// Cross-browser implementation of element.addEventListener()
// Use: listen("event name", elem, func);
function listen(evnt, elem, func) {
    if (elem.addEventListener)  // W3C DOM
        elem.addEventListener(evnt,func,false);
    else if (elem.attachEvent) { // IE DOM
         var r = elem.attachEvent("on"+evnt, func);
	return r;
    }
    else window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
}
function cerrar(params,usertext,passwordtext)
{
	document.getElementById('loginPopup').style.display='none';
	document.getElementById('fade').style.display='none';
	PassActivar();
}
 function disables(radio,textretun,fechreturn,calendar)
{
var _fechreturn = document.getElementById(fechreturn);
var _textretun = document.getElementById(textretun);
var _calendar =document.getElementById(calendar)

if (radio.value != "Radiobutton1")
{
_fechreturn.disabled = "true";
_calendar.disabled = "true";
_fechreturn.style.background ='#D6D3CE';
}
else
{
_fechreturn.disabled = "";
_calendar.disabled = "";
_fechreturn.style.background ='#ffffff';
}
}    
function validarFecha(getdate){
                                          
var fecha  = new Date();
var anio = fecha.getFullYear();
var dia = fecha.getDate();
var mes = fecha.getMonth();
		                                  
var fechahoy = new Date(anio + '/'+ mes +  '/' + dia);
var strinfecha = new Date(getdate);
var fechacal = new Date(getdate);
var fechacalanio = fechacal.getFullYear();
var fechacaldia = fechacal.getDate();
var fechcaalmes  = fechacal.getMonth();

 if ((anio <= fechacalanio))
   {
    if (fechcaalmes >= mes){
     if ((fechcaalmes == mes))
        {
         if (dia < fechacaldia)
           {
         return true;
           }
          else{return false;}
         }
         else{
         return true;
         }
     }
  }
                                          
    if ((anio < fechacalanio))
 {
  return true;
 }
}      
function ValadirRetu(getdate,text)
{
  text = Timer(text)  ;

  var fecha  = new Date(text);
  var anio = fecha.getFullYear();
  var dia = fecha.getDate();
  var mes = fecha.getMonth();
		                                  
   var fechahoy = new Date(text);
   var strinfecha = new Date(getdate);
                                          
   var fechacal = new Date(getdate);
   var fechacalanio = fechacal.getFullYear();
   var fechacaldia = fechacal.getDate();
   var fechcaalmes  = fechacal.getMonth();
                                          
   if (airlinecode == 'CM'){                                       
   if ((anio <= fechacalanio))
  {
     if (fechcaalmes >= mes){
      if ((fechcaalmes == mes))
      {
         if (dia < fechacaldia)
         {
           return true;
         }
         else{return false;}
         }
         else{
         return true;
           }
        }
     }
        }
     else
     {
      if ((anio <= fechacalanio))
        {
           if (fechcaalmes >= mes){
             if ((fechcaalmes == mes))
               {
               if (dia <= fechacaldia)
                {
                 return true;
                  }
               else{return false;}
              }
             else{
              return true;
           }
        }
     }
   }
                                          
 if ((anio < fechacalanio))
 {
 return true;
 }
} 



function trim(cadena)

{
            for(i=0; i<cadena.length; )
            {
                        if(cadena.charAt(i)==" ")
                                    cadena=cadena.substring(i+1, cadena.length);
                        else
                                    break;

            }
            for(i=cadena.length-1; i>=0; i=cadena.length-1)
            {
                        if(cadena.charAt(i)==" ")
                                    cadena=cadena.substring(0,i);
                        else
                                  break;
            }
return cadena;
}

 
function CerrarAll()
{

var citiesPopup = document.getElementById('citiesPopup');
if (citiesPopup == undefined)
{
return false;
}
if (citiesPopup.style.display == 'block')
{
document.getElementById('citiesPopup').style.display='none';
PassActivar();
}

}

function GetOnePassMiles(text)
{ 
var sURL = unescape(window.location.pathname);
try{
var millas = document.getElementById(text);
var myUrl = "http://"+window.location.hostname+"/sites/_layouts/GetOnePasMilesPage.ashx";
      	$.ajax({
  			type: "POST",
  			url: myUrl, 
  			data: "string=g",
  			beforeSend: function() {
  			 
  			},
  			complete: function () {
  			  
  			},
  			success: function(html){
  		    millas.innerHTML = html;
  		}
  		});
  }
  catch(e){
  
  }

  }
  
//function GetDestvalid(textorigen,textdestino,flag,resValueFrom,resValueTo)
//{ 
//var sURL = unescape(window.location.pathname);
//try{
//if((textorigen == undefined) || (textdestino == undefined)){
//return false;
//}
//var origenValid = document.getElementById(textorigen).value;
//var destValido =  document.getElementById(textdestino).value;
//var myUrl = "http://"+window.location.hostname+"/sites/_layouts/GetDestvalido.ashx";
//      	$.ajax({
//  			type: "POST",
//  			url: myUrl,
//  			async:false, 
//  			data: "origenValid=" + origenValid  + "&destValido="+ destValido +"&flag="+ flag +"",
////                      beforeSend: function() {
////  			  alert('Antes de Enviar');  
////  			},
//  			complete: function () {
// 			  
//  			},
//  			success: function(html){
//  		      if (html == 'False'){
//  		          switch(flag)
//                      {
//                            case '0': //Booking Panel
//                                document.getElementById(textorigen).value ='';
//  			                    document.getElementById(textdestino).value ='';
//                            break;
//                            case '1'://Booking Panel
//                                document.getElementById(textdestino).value ='';
//                            break;
//                            case '2'://Flight Information Panel
//                                document.getElementById(textorigen).value =resValueFrom; //;"From"
//                                document.getElementById(textdestino).value =resValueTo; //"To"
//                            break;
//                            case '3'://Flight Information Panel
//                                document.getElementById(textdestino).value =resValueTo; //"To"
//                            break;
//                      }
//  			   }
//  			}
//  		});
//  }
//  catch(e){
//  //alert(e);
//  }

//  }
  
function ShowResultMessage(sIsValidUser, msg){
	if(sIsValidUser == 'true')
	{
		var sURL = unescape(parent.window.location.pathname);
		parent.window.location.href = sURL;
	}
	else
	{
		var oMsg = parent.document.getElementById('msg');
		if(oMsg)
		{
		    oMsg.style.fontSize ='11px';
			oMsg.innerHTML = msg;
		}
	}
}   

function Timer(text){


var texto = text.substring(0,text.indexOf(',')-2);
var textomodificar = text.split(',');
var textomodificado = textomodificar[1];
var textomodicado2 =textomodificar[0];
var tamano = textomodicado2.length;
var tamano2 =textomodicado2.substring(tamano -2,tamano);


switch(trim(texto).toUpperCase() )

{

case "DICIEMBRE":

return "december " + tamano2 + ", " + textomodificado;

break;

case "ENERO":

return "January " + tamano2 + ", " + textomodificado;
break;

case "FEBRERO":

return "February " + tamano2 + ", " + textomodificado;
break;

case "MARZO":

return "March " + tamano2 + ", " + textomodificado;
break;

case "ABRIL":

return "April " + tamano2 + ", " + textomodificado;
break;

case "MAYO":

return "May " + tamano2 + ", " + textomodificado;
break;

case "JUNIO":

return "June " + tamano2 + ", " + textomodificado;
break;

case "JULIO":

return "July " + tamano2 + ", " + textomodificado;
break;

case "AGOSTO":

return "August " + tamano2 + ", " + textomodificado;
break;

case "SEPTIEMBRE":

return "September " + tamano2 + ", " + textomodificado;
break;

case "OCTUBRE":

return "October " + tamano2 + ", " + textomodificado;
break;


case "NOVIEMBRE":

return "November " + tamano2 + ", " + textomodificado;
break;


case "JANEIRO":
return "January " + tamano2 + ", " + textomodificado;
break;

case "FEVEREIRO":

return "February " + tamano2 + ", " + textomodificado;
break;

case "MARÇO":

return "March " + tamano2 + ", " + textomodificado;
break;

case "MAIO":

return "May " + tamano2 + ", " + textomodificado;
break;

case "JUNHO":

return "June " + tamano2 + ", " + textomodificado;
break;

case "JULHO":

return "July  " + tamano2 + ", " + textomodificado;
break;


case "SETEMBRO":

return "September " + tamano2 + ", " + textomodificado;
break;

case "OUTUBRO":

return "October " + tamano2 + ", " + textomodificado;
break;


case "NOVEMBRO":

return "November" + tamano2 + ", " + textomodificado;
break;

case "DEZEMBRO":

return "Dicember " + tamano2 + ", " + textomodificado;

break;

}

return text;

}

function CalenIfrem()
{
$(".yui-calcontainer iframe.fixedsize").css("height","0px");
//comentado por Julio Obispo
//se comenta esto para evitar que se descuadre el booking panel
/*var  oPassenger = document.getElementById('passengers');
    if(oPassenger)
    {
      oPassenger.style.display='none';
    }*/
}

function PassActivar(){
var  oPassenger = document.getElementById('passengers');
    if(oPassenger)
    {
      oPassenger.style.display='block';
    }
}

function ErrorText(params,msgtitulo,msgError)
{
    var textSplit;
    var count;
    var textboxt;
    var flag;
  
	if(Trim(params) != "")
    {
        textSplit = params.split(',');
        count = textSplit.length;
        for(i = 0; i < count; i++)
        {
            textboxt = document.getElementById(textSplit[i]).value;
            if(Trim(textboxt) == "")
            { 
                if(arguments.length==4)
                    document.getElementById(textSplit[i]).style.borderColor = arguments[3];
                else 
                    document.getElementById(textSplit[i]).style.borderColor = '#FDD341';
                    // Se le coloca un fondo a los DropDownList que no estan seleccionados en IE 6 y 7 .
                    if((document.getElementById(textSplit[i]).tagName == "SELECT" && $.browser.msie && (/6.0/.test(navigator.userAgent))) || (document.getElementById(textSplit[i]).tagName == "SELECT" && $.browser.msie && (/7.0/.test(navigator.userAgent)))) 
                    {
                        document.getElementById(textSplit[i]).style.backgroundColor = '#feedb1';                                 
                    } 
                    // Coloca un borde a los TextBox requeridos que no se han llenado, en el browser de Opera.                                       
                    if($.browser.opera)
                    {
                         document.getElementById(textSplit[i]).style.borderColor = '#FDD341';  
                         document.getElementById(textSplit[i]).style.borderStyle= 'solid';
                         document.getElementById(textSplit[i]).style.borderWidth= '1px'; 
                    }          
            } 
            else
            {
                document.getElementById(textSplit[i]).style.borderColor = '';                
            }
        }
        for(i = 0; i < count; i++)
        {             
            textboxt = document.getElementById(textSplit[i]).value;
            if(Trim(textboxt) == "")
            { 
                RenderError(msgtitulo,msgError);
                return false;
            }
        }           
        return true;
	}
	else { return false; }
}

//validate the textbox for Flight Information Panel
//res = abbreviation for Resources
function ErrorFligthInform(params, msgtitulo, msgError, resValueFrom, resValueTo)
{
    var textSplit;
    var count;
    var textboxt;
    var flag;
    var result = false;
    var param0, param1;
    
    
    if(params != "")
    {
        textSplit = params.split(',');
        count = textSplit.length;        
        param0= document.getElementById(textSplit[0]).value; 
        param1= document.getElementById(textSplit[1]).value;

        // ask for From and To Destination
        if  (((param0 == "") || (param0 == resValueFrom)) || ((param1 == "") || (param1 == resValueTo)))
        {               
            for(i = 0; i < count; i++)
            {
                textboxt = document.getElementById(textSplit[i]).value;
        
                if( (textboxt == "") || (textboxt == resValueFrom) || (textboxt == resValueTo))
                {   // if textbox is blank
                    if(arguments.length>=7)
				        document.getElementById(textSplit[i]).style.borderColor = arguments[6];
				    else
                        document.getElementById(textSplit[i]).style.borderColor = '#FDD341';
                } 
                else
                {   // if textbox is not blank
                    document.getElementById(textSplit[i]).style.borderColor = '';
                    result = false;
                }
            }                                
        } 
        else
        {
            if(typeof document.getElementById(textSplit[0]) !=  'undefined') document.getElementById(textSplit[0]).style.borderColor = '';                
            if(typeof document.getElementById(textSplit[1]) !=  'undefined') document.getElementById(textSplit[1]).style.borderColor = '';                
             result = true;
        }
            
     }
     
     if (result == false)
     {  
        RenderError(msgtitulo,msgError);
     }
     
    return result;
}

//modified by Julio Obispo
//05-06-2009
//added paramenter 'separator'
//for customize separator
function RenderError(msgtitulo,msgErrorFull,separator)
{
 //if not sent separator
 //take comma for default separator
 if(separator!=null)
    msgError = msgErrorFull.split(separator);
 else   
    msgError = msgErrorFull.split(',');
 var ulerror = document.getElementById('ulerror')
 var count = msgError.length;
 ulerror.innerHTML = '';
 //Metrica de Error para Omniture
 if (typeof myVar != 'undefined')
  {
     s = s_gi(myVar);
     s.linkTrackVars = "prop19,events,eVar26"; 
     s.linkTrackEvents = "event5";
     s.prop19 = msgErrorFull; 
     s.eVar26 = msgErrorFull;
     s.events = "event5";
     s.tl(this,'o',"Error en Cliente");
  }
 //Fin
 for(i = 0; i < count; i++)
{               
            var li  = document.createElement("li");
            li.innerHTML = msgError[i];
            ulerror.appendChild(li);
         }               
 document.getElementById('error').style.display = 'block';
}

function Errorlogin(params)
{
var textSplit;
var count;
var textboxt;
var flag;
if(params != "")
{
textSplit = params.split(',');

count = textSplit.length;

 for(i = 0; i < count; i++)
  {
        var obj = document.getElementById(textSplit[i]);

        textboxt = obj.value;
        if(textboxt == "")
          { 
           obj.style.borderColor = '#FDD341';  
                        
               if((obj.tagName == "SELECT" && $.browser.msie && ( /6.0/.test(navigator.userAgent))) || (obj.tagName == "SELECT" && $.browser.msie && ( /7.0/.test(navigator.userAgent))) )
               {               
                 obj.style.background = '#feedb1';         
               }               
          } 
         else
          {
           obj.style.borderColor = '';
          }
  }

 }

}

function VerificarMail(params,msgtitulo,msgError,emailStr1,msgmail)
{
    var emailStr = document.getElementById(emailStr1).value;
    if (emailStr == "")
    {
        return ErrorText(params,msgtitulo,msgError)
    }
    /* Verificar si el email tiene el formato user@dominio. */
    var emailPat=/^(.+)@(.+)$/ 

    /* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 

    /* Verifica los caracteres que son válidos en una dirección de email */
    var validChars="\[^\\s" + specialChars + "\]" 

    var quotedUser="(\"[^\"]*\")" 

    /* Verifica si la dirección de email está representada con una dirección IP Válida */ 


    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/


/* Verificar caracteres inválidos */ 

var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
 /*domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
//msgError = msgError + "," + msgtitulo;
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}
var user=matchArray[1]
var domain=matchArray[2]

// Si el user "user" es valido 
if (user.match(userPat)==null) {
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}

/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}
}
return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
domArr[domArr.length-1].length>3) { 
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}

if (len<2) {
if(ErrorText(params,msgtitulo,msgError) == false)
{
msgmail = msgError + "," + msgmail;
}
RenderError(msgtitulo,msgmail)
document.getElementById(emailStr1).style.borderColor = '#FDD341';
return false
}
if(ErrorText(params,msgtitulo,msgError) == false)
{
document.getElementById(emailStr1).style.borderColor = '';
return false;
}
else{
return true;
}
}


function leerCookies(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
} 

function ValidarWCI(params,msgError,msgtxtID,msgtxtlastN)
{
	var mesajeError = "";
	var ParamsText = params.split(',');
	var txtID = Trim(document.getElementById(ParamsText[0]).value);
	var txtlastname = Trim(document.getElementById(ParamsText[1]).value);
	var txtIdPat = new RegExp(/^\d{12,14}|[a-zA-Z]{2}\d{6}|[0-9a-zA-Z]{6}$/);

	var txtIDPat1 = new RegExp(/^\d{12,14}$/);
	var txtIDPat2 = new RegExp(/^[a-zA-Z]{2}\d{6}$/);
	var txtIDPat3 = new RegExp(/^[0-9a-zA-Z]{6}$/);

	var txtlastNPat = new RegExp("^[a-zA-Z]+[ ]*[a-zA-Z ]*$");
	var matchArray ;
	var CheckFildBlank = ErrorText(params,msgError,msgError, colorError);
	if (CheckFildBlank == false)
	{
		mesajeError = msgError ;
	}
	matchArray = txtIdPat.test(txtID);
	matchArray1 = txtIDPat1.test(txtID);
	matchArray2 = txtIDPat2.test(txtID);
	matchArray3 = txtIDPat3.test(txtID);
	if (Trim(txtID) != '')
	{
		if (txtIDPat1.test(txtID) == false && txtIDPat2.test(txtID) == false && txtIDPat3.test(txtID) == false )
		{
			if(Trim(mesajeError) == "" || mesajeError == undefined)
			{
				mesajeError = msgtxtID ;
				if(arguments.length==5)
				    document.getElementById(ParamsText[0]).style.borderColor = colorError
				else 
				    document.getElementById(ParamsText[0]).style.borderColor = '#FDD341'
			}
			else
			{
				mesajeError = mesajeError + "," + msgtxtID;
				if(arguments.length==5)
				    document.getElementById(ParamsText[0]).style.borderColor = colorError
				else
				    document.getElementById(ParamsText[0]).style.borderColor = '#FDD341'
			}
		}
		else
		{
			document.getElementById(ParamsText[0]).style.borderColor = ''
		}
	}
	if (Trim(txtlastname) != '')
	{
		matchArray = txtlastNPat.test(txtlastname);
		if (matchArray == false)
		{
			if(Trim(mesajeError) == "" || mesajeError == undefined)
			{
				mesajeError = msgtxtlastN;
				if(arguments.length>=4)
				    document.getElementById(ParamsText[0]).style.borderColor = colorError
				else
				    document.getElementById(ParamsText[1]).style.borderColor = '#FDD341'
			}
			else
			{
				mesajeError = mesajeError + "," + msgtxtlastN;
				if(arguments.length>=4)
				    document.getElementById(ParamsText[0]).style.borderColor = colorError
				else
				    document.getElementById(ParamsText[1]).style.borderColor = '#FDD341'
			}
		}
		else
		{
			document.getElementById(ParamsText[1]).style.borderColor = ''
		}
	}
	if (Trim(mesajeError) == ""  || mesajeError == undefined )
	{
		return true;
	}
	else
	{
		RenderError(mesajeError,mesajeError);
		return false;
	}
}
var GlbError = 0;
function ValidFechWCI(selDate,ErrorFecha)
{

var fecha = new Date(2009,00,01,23,59,00);
var fechahoy  = new Date()
var DivError = document.getElementById('error').style.display;
var ulerror = document.getElementById('ulerror');
if(selDate > fecha  && selDate < fechahoy)
  {
   if (DivError== 'block')
   {
      ulerror.removeChild(ulerror.lastChild);
      GlbError = 0;
      if(ulerror.childNodes.length == 0)
      {
      document.getElementById('error').style.display = 'none';
      }
   }
else
  {
       document.getElementById('error').style.display = 'none';
  }
     return true;
  }
else
  {
     if (DivError== 'block'){
         if (GlbError == 0){
            var li  = document.createElement("li");
            li.innerHTML = ErrorFecha;
            ulerror.appendChild(li);
            GlbError = 1;
          } 
     }
     else
     { 
     RenderError(ErrorFecha,ErrorFecha);
     GlbError = 1;
 }

return false;

}
}

//valida los campos de texto que son requeridos no estén vacios
function IsValidFormMail(sender, args){
	var txtData = new String(args.Value);
	var ParamsText = txtData.split('|');
	if(VerificarMail(ParamsText[0], ParamsText[1], ParamsText[2], ParamsText[3], ParamsText[4])){
	    var buttonSend = document.getElementById(ParamsText[5]);
        buttonSend.disabled = true;
	    args.IsValid=true;
   }
   else{        
        args.IsValid=false;   
   }
}

function ValidateInputValues(Phone,pager,msgblank,errormsgid, rememberid)
{ 
	var params;
	var phone =  document.getElementById(Phone).value ;
    var Pager =    document.getElementById(pager).value;
    if (Trim(phone) == "" || Trim(Pager) == ""){
		document.getElementById('msg').innerHTML = msgblank;
        params = Phone + "," + pager;
        Errorlogin(params);
        return false;
    }
    var largeExpDate = new Date ();
    largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000)); 
    var timeDeleteCo = new Date(1970,1,1,0,0,0);
	var rememberlogin = document.getElementById(rememberid).checked;
    if(rememberlogin){  
		document.cookie = "userNamePreferences = " + phone + ";expires= "+largeExpDate + ";path = /";
    }
    else{
       document.cookie = "userNamePreferences = " + phone + "; expires = "+timeDeleteCo.toGMTString() + " ;path = /";
    }
	return true;
}
function Trim(str){
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function SetErrorMsg(message){
	var msgbox = document.getElementById('msg');
	if(msgbox){
		msgbox.innerHTML = message;
	}
}
function IsValidInputValues(sender, args){
	var txtData = new String(args.Value);
	var ParamsText = txtData.split('|');
	if(ValidateInputValues(ParamsText[0], ParamsText[1], ParamsText[2], ParamsText[3], ParamsText[4])){
        ShowProgressIcon();
		args.IsValid=true;
   }
   else{        
        args.IsValid=false;
   }
}
function ShowProgressIcon(){
	var img = document.getElementById('WaitingImg');
	if(img){
		img.style.display = '';
	}
}
/* Autor: sruiz
 * Valida si un cambo en el engine de destinos de booking panel
 * coincide con lo que se coloco en la caja de texto, de lo
 * contrarion despliega un error y muestra un bode de color 
 * amarillo a la caja que contiene el dato incorrecto.
 */
function ValidateValue(idTextBox, myObjJSON)
{
    var result =false;
    var text= $('#'+idTextBox).val();
    if(text!=undefined && text.length>0)
    {
        for(var route=0;route<myObjJSON.routes.length;route++)
        {				
			var code = myObjJSON.routes[route].code;
			if(text.indexOf(code)>=0) 
			{ 
			    new Utilities().RenderError("error","ulerror", "",true);
			    return true; 
			}			
        }
    }
    return result;
}
/* Autor: sruiz
 * Verifica si uno de los text box del motor de busqueda
 * contiene un valor válido, y sino le coloca al control 
 * un color de border amarillo "#FDD341".
 * Modificado por sruiz 2009/07/17 border rojo #CC0000.
 */
function IsErrorSetColor(idTextBox,myObjJSON)
{
    var isTrue = ValidateValue(idTextBox,myObjJSON);
    if(arguments.length>2) {
        if(isTrue) { new Utilities().setColorBorder(idTextBox,""); }
        else {new Utilities().setColorBorder(idTextBox,arguments[2]); }
    }
    else {
        if(isTrue) { new Utilities().setColorBorder(idTextBox,""); }
        else {new Utilities().setColorBorder(idTextBox,"#FDD341"); }
    }
    
    return isTrue;
}
/* Modificado: sruiz 2009/junio/17
 * 
 *
 *
 *
 */
function IsValidErrorText(sender, args){
	var txtData = new String(args.Value);
	var ParamsText = txtData.split('|');
	
	var radioOneText = document.getElementById(ParamsText[4]);
	if(radioOneText.checked)
	{	   
	    var requiredFields = ParamsText[0].split(',');
	    ParamsText[0] = ParamsText[0].replace(',' + requiredFields[3], '');
	}
	if(ErrorText(ParamsText[0],ParamsText[1],ParamsText[2],colorError))
	{ 
		var listBox = ParamsText[0].split(',');
		var fromTextBox = IsErrorSetColor(listBox[0], myObject.jsonData,colorError);
		var toTextBox = IsErrorSetColor(listBox[1], myObject.dependant.jsonData,colorError);
		
		if(fromTextBox && toTextBox) { args.IsValid = true; }
		else 
		{ 
		    new Utilities().RenderError('','ulerror','');
		    new Utilities().RenderError('error','ulerror',ParamsText[3]);
		    args.IsValid = false; 
		}
	}
	else { args.IsValid = false; }
	
	return args.IsValid;
}
function IsValidValidarWCI(sender, args){
	var txtData = new String(args.Value);
	var ParamsText = txtData.split('|');
	if(ValidarWCI(ParamsText[0], ParamsText[1], ParamsText[2], ParamsText[3],colorError)){
		args.IsValid = true;
	}
	else{
		args.IsValid = false;
	}
}

function IsValidFligthStatusInputs(sender, args){
	var txtData = new String(args.Value);
	var ParamsText = txtData.split('|');
	if(ErrorFligthInform(ParamsText[0], ParamsText[1], ParamsText[2], ParamsText[3],ParamsText[4],ParamsText[5], colorError)){		
		args.IsValid = true;
	}
	else{
		args.IsValid = false;
	}
}
function addClickFunctionToControl(controlId) {
	var b = document.getElementById(controlId);
	if (b && typeof(b.click) == 'undefined') b.click = function() {
		var result = true; 
		if (b.onclick) result = b.onclick();
		if (typeof(result) == 'undefined' || result) { eval(b.getAttribute('href')); }
	}
}

//Valida que en el textArea Sólo acepte 1024 caracteres.
function ValidarCaracteres(textControl, maxlength) 
{
    if (textControl.value.length > maxlength)
    { 
        textControl.value = textControl.value.substring(0,maxlength);   
    }  
}


function GetMyTripsInfo(sessionID, userName)
{

    var languageSL = $("#drpLanguages option:selected")[0].value;
    var currentURLAddress = document.location.href;
    currentURLAddress = currentURLAddress.replace(/&/g,"¿");
	$.ajax(
			  {
				type: "POST",
				url: window.location.protocol+"//"+window.location.hostname+"/_layouts/GetMyTripsInfoData.ashx", 
				data: "sessionID="+sessionID+"&userName="+userName,
				success: function(html)
				{
					window.location = html.toString();
				}
			  }
	      );
}

//se valida el año y mes introducido
//a partir de ello, se cargan los días
//por mes
function ValidateBirthDayByMonth()
{
   var Months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
   var year = $(".birthDateYear").val();
   var month = $(".birthDateMonth").val();
   var daysDropDown=$(".birthDateDay option").length;
 
   if(year!="" && month!="")
   {
          if(month==Months[0] || month==Months[2] || month==Months[4] || month==Months[6] || month==Months[7] || month==Months[9] || month==Months[11])
          {
            //verificar la cantidad de dias del drop antes de reiniciarlo
                if(daysDropDown!=32)
                {
                   //reiniciar el dropdown
                   ResetDropDown(32);
                }
                
          }
          else if(month==Months[3] || month==Months[5] || month==Months[8] || month==Months[10])
          {
            //verificar la cantidad de dias del drop antes de reiniciarlo
                if(daysDropDown!=31)
                {
                   //reiniciar el dropdown
                   ResetDropDown(31);
                }
          }
          else
          {
            if(IsLeapYear(year))
                {
                //verificar la cantidad de dias del drop antes de reiniciarlo
                if(daysDropDown!=30)
                {
                    ResetDropDown(30);
                }
                }
                else
                {
                  //verificar
                  if(daysDropDown!=29)
                  {
                     ResetDropDown(29);
                  }
                }
          }
   }
}
 
//verifica si un anio es biciesto o no
function IsLeapYear(year)
{
   var yearInt=parseInt(year);
   if((yearInt%4==0) && ((yearInt%100!=0)||(yearInt%400==0)))
   {
     return true;
   }
   else
   {
    return false;
   }
}
 
//modifica la cantidad de dias a mostrar
//segun la cantidad indicada
function ResetDropDown(maxIndex)
{
   var index=$('.birthDateDay option').length;
   var navigatorAgent=navigator.userAgent;
   //si el navegador es Safari, se procedera a agregar los dias de forma distinta
   if(navigatorAgent.toLowerCase().indexOf("webkit") > -1 || navigatorAgent.toLowerCase().indexOf("safari") >-1)
   {
     LoadingDaysSafari(maxIndex);
   }
   else
   {
      //segun el indice indicado por el componente y el mes, se procedera a 
      //agregar dias si hacen falta o a eliminar si hay demas
           if(index <= maxIndex)
           {
                        while(maxIndex!=index)
                        {
                          var pivot=$(".birthDateDay option").length-1;
                          var futureIndex=$(".birthDateDay option").length;
                          $("select.birthDateDay option[value="+pivot.toString()+"]").after("<option value='"+futureIndex.toString()+"'>"+futureIndex.toString()+"</option>");
                          index=$('.birthDateDay option').length;
                        }
                
           }
           else if(index >= maxIndex)
           {
                   while(maxIndex!=index)
                   {
                          var pivot=$(".birthDateDay option").length-1;
                          $("select.birthDateDay option[value='"+pivot.toString()+"']").remove();
                          index=$(".birthDateDay option").length;
                   }
           }
   }
}
//carga de los dias especial para Safari
//debido a su comportamiento con los campos 'select'
function LoadingDaysSafari(maxIndex)
{
        var selectDays=$(".birthDateDay");
        selectDays.each(function(i)
        {
           var $item=$(this);
           var $option=$item.find("option").remove();
        });
        
        $("#spanDays").empty();
        var emptyOption = document.createElement("option");
    emptyOption.text="";
    emptyOption.value="";
        selectDays[0][0]=emptyOption;
        for(var index=1; index<maxIndex; index++)
   {
     var daysOption=document.createElement("option");
        if(index>=1 && index<=9)
        {
           daysOption.text="0"+index.toString();
        }
        else
        {
           daysOption.text=index.toString();
        }
        daysOption.value=index.toString();
        selectDays[0][index]=daysOption;
   }
   $("#spanDays").append(selectDays);   
}
