

function uniqueArray1( ar ) {
  var j = {};

  ar.forEach( function(v) {
    j[v+ '::' + typeof v] = v;
  });

  return Object.keys(j).map(function(v){
    return j[v];
  });
} 

/* resta de dos fechas */ 
restaFechas = function(f1,f2)
 {
 var aFecha1 = f1.split('/'); 
 var aFecha2 = f2.split('/'); 
 var fFecha1 = Date.UTC(aFecha1[2],aFecha1[1]-1,aFecha1[0]); 
 var fFecha2 = Date.UTC(aFecha2[2],aFecha2[1]-1,aFecha2[0]); 
 var dif = fFecha2 - fFecha1;
 var dias = Math.floor(dif / (1000 * 60 * 60 * 24)); 
 return dias;
 }


function ajax_dimensiones_ronline(capa,PASO,cadena){

	instancia=objetoAjax();
	instancia.open("POST",PASO,true);
	instancia.onreadystatechange=function() {
		if (instancia.readyState==4) {
			document.getElementById(capa).innerHTML = instancia.responseText
		}
	} 
	instancia.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	instancia.send("valor="+cadena)
}

function fun_AllowOnlyAmountInteger(valor){
 
<!-- <input name="numero" id="numero" type="text"  onkeypress="return fun_AllowOnlyAmountAndDot(this.id);">-->
<!--<input name="numero2" id="numero2" type="text"  onkeypress="return fun_AllowOnlyAmountInteger(this.id);">-->
           
			   
               if(event.keyCode > 47 && event.keyCode < 58 ) //|| event.keyCode == 46
               {
                 // var txtbx=document.getElementById(txt);
                  var amount = valor; // document.getElementById(txt).value;
                  var present=0;
                  var count=0;
 //alert(amount);
                  if(amount.indexOf(".",present)||amount.indexOf(".",present+1));
                  {
                 // alert('0');
                  }

                 /*if(amount.length==2)
                 {
                   if(event.keyCode != 46)
                   return false;
                 }*/
                  do
                  {
                  present=amount.indexOf(".",present);
                  if(present!=-1)
                   {
                    count++;
                    present++;
                    }
                  }
                  while(present!=-1);
                  if(present==-1 && amount.length==0 && event.keyCode == 46)
                  {
                       event.keyCode=0; event.preventDefault();
                       //alert("Wrong position of decimal point not  allowed !!");
                       return false;
                  }

                  if(count>=1 && event.keyCode == 46)
                  {

                       event.keyCode=0;event.preventDefault();
                       //alert("Only one decimal point is allowed !!");
                       return false;
                  }
                  if(count==1)
                  {
                   var lastdigits=amount.substring(amount.indexOf(".")+1,amount.length);
                   if(lastdigits.length>=2)
                               {
                                 //alert("Two decimal places only allowed");
                                 event.keyCode=0;event.preventDefault();
                                 return false;
                                 }
                  }
                       return true;
               }
			   
               else
               {
				   // alert(event.keyCode);
                       event.keyCode=0;event.preventDefault();
                       //alert("Only Numbers with dot allowed !!");
                       return false;
               }

           }


    function fun_AllowOnlyAmountAndDot(valor)
           {
               if(event.keyCode > 47 && event.keyCode < 58 || event.keyCode == 46)
               {
                  //var txtbx=document.getElementById(txt);
                  var amount = valor; //document.getElementById(txt).value;
                  var present=0;
                  var count=0;

                  if(amount.indexOf(".",present)||amount.indexOf(".",present+1));
                  {
                 // alert('0');
                  }

                 /*if(amount.length==2)
                 {
                   if(event.keyCode != 46)
                   return false;
                 }*/
                  do
                  {
                  present=amount.indexOf(".",present);
                  if(present!=-1)
                   {
                    count++;
                    present++;
                    }
                  }
                  while(present!=-1);
                  if(present==-1 && amount.length==0 && event.keyCode == 46)
                  {
                       event.keyCode=0;event.preventDefault();
                       //alert("Wrong position of decimal point not  allowed !!");
                       return false;
                  }

                  if(count>=1 && event.keyCode == 46)
                  {

                       event.keyCode=0;event.preventDefault();
                       //alert("Only one decimal point is allowed !!");
                       return false;
                  }
                  if(count==1)
                  {
                   var lastdigits=amount.substring(amount.indexOf(".")+1,amount.length);
                   if(lastdigits.length>=2)
                               {
                                 //alert("Two decimal places only allowed");
                                 event.keyCode=0;event.preventDefault();
                                 return false;
                                 }
                  }
                       return true;
               }
               else
               {
                       event.keyCode=0;event.preventDefault();
                       //alert("Only Numbers with dot allowed !!");
                       return false;
               }

           }

 
 function AddSelectOption(selectObj, text, value, isSelected) 
{
    if (selectObj != null && selectObj.options != null)
    {
        selectObj.options[selectObj.options.length] = 
            new Option(text, value, false, isSelected);
    }
}


function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function genericAjaxECV(capa,PASO,cadena){
 
	genAjaxECV=objetoAjax();
	genAjaxECV.open("POST",PASO,true);
	genAjaxECV.onreadystatechange=function() {
		if (genAjaxECV.readyState==4) 
			{document.getElementById(capa).innerHTML = genAjaxECV.responseText

			}
		} 
		if(document.getElementById(cadena)){
	document.getElementById(cadena).focus();
}
	genAjaxECV.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	genAjaxECV.send("valor="+cadena)
	
}



function genericAjaxECCC(capa,PASO,cadena){
 
	genAjaxECCC=objetoAjax();
	genAjaxECCC.open("POST",PASO,true);
	genAjaxECCC.onreadystatechange=function() {
		if (genAjaxECCC.readyState==4) 
			{document.getElementById(capa).innerHTML = genAjaxECCC.responseText

			}
		} 
		if(document.getElementById(cadena)){
	document.getElementById(cadena).focus();
}
	genAjaxECCC.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	genAjaxECCC.send("valor="+cadena)
	
}


function genericAjaxCS(capa,PASO,cadena){
 
	genAjaxCS=objetoAjax();
	genAjaxCS.open("POST",PASO,true);
	genAjaxCS.onreadystatechange=function() {
		if (genAjaxCS.readyState==4) 
			{document.getElementById(capa).innerHTML = genAjaxCS.responseText

			}
		} 
		if(document.getElementById(cadena)){
	document.getElementById(cadena).focus();
}
	genAjaxCS.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	genAjaxCS.send("valor="+cadena)
	
}

function genericAjaxParent(capa,PASO,cadena){

	genAjaxAx=objetoAjax();
	genAjaxAx.open("POST",PASO,true);
	genAjaxAx.onreadystatechange=function() {
		if (genAjaxAx.readyState==4) 
			{parent.document.getElementById(capa).innerHTML = genAjaxAx.responseText

			}
		} 
	genAjaxAx.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	genAjaxAx.send("valor="+cadena)
}
 
/* calcula el largo de un text area */ 
 function calcLong(input, maximo)
{
var largo
largo = document.getElementById(input).value.length
 
if (largo > maximo)
document.getElementById(input).value = document.getElementById(input).value.substring(0,maximo)
 
}

function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

 function checkDecimals(fieldName, fieldValue,decallowed,mensaje) { 
 if(decallowed==0){
	valor = fieldValue.split('.')
	document.getElementById(fieldName).value=valor[0];
	valor = fieldValue.split(',')
	document.getElementById(fieldName).value=valor[0];
	return true
 }
	//decallowed = 4; // how many decimals are allowed? 
	if (isNaN(fieldValue) || fieldValue == "") { 
		//alert("El número no es válido. Prueba de nuevo."); 
		alert(mensaje)
		 document.getElementById(fieldName).value='';
		fieldName.select(); 
		fieldName.focus(); 
		return false;
	} else { 
		if (fieldValue.indexOf('.') == -1) 
		fieldValue += "."; 
		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length); 
				if (dectext.length > decallowed) { 
					alert ("Por favor, entra un número con " + decallowed + " números decimales."); 
					document.getElementById(fieldName).value=document.getElementById(fieldName).value.substring(0,document.getElementById(fieldName).value.length-1);
					fieldName.select(); 
					fieldName.focus(); 
					return false;
				} else { 
					return true;
					//alert ("Número validado satisfactoriamente."); 
				} 
		} 
	return true;
	}
	
function ajax_links_hbl(capa,PASO,cadena){
	AjaxLinks=objetoAjax();
	AjaxLinks.open("POST",PASO,true);
	AjaxLinks.onreadystatechange=function() {
		if (AjaxLinks.readyState==4) 
			{document.getElementById(capa).innerHTML = AjaxLinks.responseText

			}
		} 
	AjaxLinks.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	AjaxLinks.send("valor="+cadena)
}

function ajax_links_booking(capa,PASO,cadena){
	AjaxLinksB=objetoAjax();
	AjaxLinksB.open("POST",PASO,true);
	AjaxLinksB.onreadystatechange=function() {
		if (AjaxLinksB.readyState==4) 
			{document.getElementById(capa).innerHTML = AjaxLinksB.responseText

			}
		} 
	AjaxLinksB.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	AjaxLinksB.send("valor="+cadena)
}

function genericAjax(capa,PASO,cadena){
 
	genAjaxA=objetoAjax();
	genAjaxA.open("POST",PASO,true);
	genAjaxA.onreadystatechange=function() {
		if (genAjaxA.readyState==4) 
			{document.getElementById(capa).innerHTML = genAjaxA.responseText

			}
		} 
	if(document.getElementById(cadena)){
		document.getElementById(cadena).focus();
	}
	genAjaxA.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	genAjaxA.send("valor="+cadena)
	
}

function LstAjax(capa,PASO){

	AjaxLst=objetoAjax();
	AjaxLst.open("POST",PASO,true);
	AjaxLst.onreadystatechange=function() {
		if (AjaxLst.readyState==4) 
			{document.getElementById(capa).innerHTML = AjaxLst.responseText

			}
		} 
	AjaxLst.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	AjaxLst.send(null)
}

function AjaxCargo(capa,PASO,cadena){

	AjaxCarg=objetoAjax();
	AjaxCarg.open("POST",PASO,true);
	AjaxCarg.onreadystatechange=function() {
		if (AjaxCarg.readyState==4) 
			{document.getElementById(capa).innerHTML = AjaxCarg.responseText

			}
		} 
	AjaxCarg.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	AjaxCarg.send("valor="+cadena)
}

function AjaxContenedor(capa,PASO,cadena){
	AjaxCont=objetoAjax();
	AjaxCont.open("POST",PASO,true);
	AjaxCont.onreadystatechange=function() {
		if (AjaxCont.readyState==4) 
			{document.getElementById(capa).innerHTML = AjaxCont.responseText
			}
		} 
	AjaxCont.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	AjaxCont.send("valor="+cadena)
}

function validaNum(e,campo) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    	
	var mivalor=campo;
	
	if (tecla > 47 && tecla <= 57) 
		
		return true;

		
return false
 }
 
function uc(valor,input) {
	val = valor.toUpperCase();
	document.getElementById(input.id).value=val;

}
 
function valida_importe(e) {

	tecla=(document.all) ? e.keyCode : e.which;

	if((tecla < 48 || tecla > 57) && (tecla != 46))

		return false;

}

function valida_entero(e) {

	tecla=(document.all) ? e.keyCode : e.which;

	if((tecla < 48 || tecla > 57))

		return false;

}

function valida_alfanumerico(e) {

	tecla=(document.all) ? e.keyCode : e.which;

	if((tecla >= 65 && tecla <= 90))

		return true;

	else if ((tecla >= 97 && tecla <= 122))

		return true;

	else if ((tecla >= 48 && tecla <= 57))

		return true;

	else if ((tecla == 32 || tecla == 44 || tecla == 58 || tecla == 46))

		return true;

	else

		return false;

}

function EndsWith(texto,criterio) {

	var liPos = texto.lastIndexOf(criterio);

	if ( liPos < 0 )

		return false;

	if ( criterio.length + liPos == texto.length )

		return true;

	return false;

}

function formato_importe(texto) {

	if (texto) {

		return "$" + number_format(texto,2,".",",");

	} else

		return "$0.00";

}

function number_format( number, decimals, dec_point, thousands_sep ) {

    var n = number, prec = decimals, dec = dec_point, sep = thousands_sep;

    n = !isFinite(+n) ? 0 : +n;

    prec = !isFinite(+prec) ? 0 : Math.abs(prec);

    sep = sep == undefined ? ',' : sep;

 

    var s = n.toFixed(prec),

        abs = Math.abs(n).toFixed(prec),

        _, i;

 

    if (abs > 1000) {

        _ = abs.split(/\D/);

        i = _[0].length % 3 || 3;

 

        _[0] = s.slice(0,i + (n < 0)) +

              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');

 

        s = _.join(dec || '.');

    }

 

    return s;

}

function dame_importe(texto) {

	texto = texto.replace("$", "");

	texto = texto.replace(",", "");

	return texto;

}

function dame_porcentaje(texto) {

	return texto.replace("%", "");

}

function dameFecha(texto) {

	// fecha en yyyy-mm-dd

	var re_dt = /^(\d{1,2})\-(\d{1,2})\-(\d{4})$/;

	// check format

	if (!re_dt.test(texto))

		return null;

	var dt_test = new Date(RegExp.$3, Number(RegExp.$2-1), RegExp.$1);

	return dt_test;

}

function dameTiempo(texto) {

	// Tiempo en HH:MM

	var re_tm = /^(\d{1,2})\:(\d{1,2})$/;

	// check format

	if (!re_tm.test(texto))

		return null;

	var dt_time = new Date();

	dt_time.setTime(0);

	dt_time.setHours(RegExp.$1, RegExp.$2, 0, 0);

	return dt_time;

}

function valores_forma(forma,objeto) {

	var laDatos = [];

	var liIdx;

	

	// Información del campo

	if ( objeto ) {

		var loObjCampo = [];

		loObjCampo["name"] = "campo";

		loObjCampo["value"] = objeto.name;

		laDatos.push( loObjCampo );

	}

	

	// Pasa los datos de la forma a objeto

	if ( forma ) {

		for ( liIdx=0 ; liIdx<forma.elements.length ; liIdx++ ) {

			// Para checkboxes 0 o 1 como valor

			if (forma.elements[liIdx].type == "checkbox")

				forma.elements[liIdx].value = ( forma.elements[liIdx].checked ? "1" : "0" );

			laDatos.push( forma.elements[liIdx] );

		}

	}

	return laDatos;

}

/* valida numeros */
function IsNum( numstr ) {
	// Return immediately if an invalid value was passed in
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;
	var isValid = true;
	var decCount = 0;		// number of decimal points in the string
	// convert to a string for performing string comparisons.
	numstr += "";	
	// Loop through string and test each character. If any
	// character is not a number, return a false result.
 	// Include special cases for negative numbers (first char == '-')
	// and a single decimal point (any one char in string == '.').   
	for (i = 0; i < numstr.length; i++) {
		// track number of decimal points
		if (numstr.charAt(i) == ".")
			decCount++;
    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
				(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
       	isValid = false;
       	break;
		} else if ((numstr.charAt(i) == "-" && i != 0) ||
				(numstr.charAt(i) == "." && numstr.length == 1) ||
			  (numstr.charAt(i) == "." && decCount > 1)) {
       	isValid = false;
       	break;
      }         	         	       
//if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9")) || 
   } // END for   
   
   	return isValid;
}  // end IsNum

function loadin(input,Tspan,msg){
		if(input!=''){
			if (document.getElementById(input).value!='') { 
				if(document.getElementById(Tspan)){
				document.getElementById(Tspan).innerHTML='&nbsp;'+msg+' <img src="../images/loading.gif" align="absbottom" />';
				}
			}
		}else{
			if(document.getElementById(Tspan)){
			document.getElementById(Tspan).innerHTML='&nbsp;'+msg+' <img src="../images/loading.gif" align="absbottom" />';
			}
		}
}

function loadin_t(input,Tspan,msg){
	document.getElementById(Tspan).innerHTML='';
}

function unloadin(Tspan){
	if(document.getElementById(Tspan)){
	document.getElementById(Tspan).innerHTML='';
	}
}

function loadin_(input,Tspan,msg,img){
		if(input!=''){
			if (document.getElementById(input).value!='') { 
				if(document.getElementById(Tspan)){
				document.getElementById(Tspan).innerHTML='&nbsp;'+msg+' <img src="'+img+'" align="absbottom" />';
				}
			}
		}else{
			if(document.getElementById(Tspan)){
			document.getElementById(Tspan).innerHTML='&nbsp;'+msg+' <img src="'+img+'" align="absbottom" />';
			}
		}
}

function loadin_t_(input,Tspan,msg){
	document.getElementById(Tspan).innerHTML='';
}

function unloadin_(Tspan){
	if(document.getElementById(Tspan)){
	document.getElementById(Tspan).innerHTML='';
	}
}

function asign(objeto,valor){
	if(objeto) objeto.value=valor
	//alert(document.getElementById(objeto))
}
// esta no sirve, quitar
function quita_espacios(valor){
	value_no_blank = valor.replace(/\s+/gi,'') 
	return value_no_blank
}
// esta si sirve, DEJAR Y AGREGAR POR TODOS LADOS
function replaceAll(find, replace,str,input) { 
var re = new RegExp(find, 'g'); 
str = str.replace(re, replace); 
document.getElementById(input).value=str
}

	 function keyhandler(obj,e,max) {
    e = e || event;
    max = max || 50;
    console.log(e.keyCode);
    if (e.keyCode === 13) {
        return document.forms[0].submit();
    }
    if (obj.value.length >= max && e.keyCode>46) {
        return false;
    }
	 if (obj.value.indexOf(',')!=-1) {
        return false;
    }
    return true;
}



