/**********************MENSAJES (OJO - CAMBIAR AL LENGUAJE CORRESPONDIENTE *************************************/
//var MsgTopeBloqueErr = "La cantidad de millas a comprar no puede ser mayor de ";
//var MsgCompraMas = "Si deseas comprar más Millas, favor realizar otra transacción. Puedes hacer tantas transacciones como quieras."
//var MsgBloqueErr = "La cantidad de millas a comprar debe ser m&uacute;ltiplo de ";

/*** Mensajes Transferencia de Millas ***/
//var MsgTopeTransfErr = "La cantidad de millas a transferir no puede ser mayor de ";
//var MsgBloqueTransfErr = "La cantidad de millas a transferir debe ser m&uacute;ltiplo de ";

/*************************************************************************************************************************/
 /** Esta funcion abre una nueva ventana para los links alternos de la pagina */
function newwin(page,Popwidth,Popheight,Popresize,Popscroll)
{
OpenWin = this.open(page, "CtrlWindow", "width="+Popwidth+",height="+Popheight+",top=0,left=0,toolbar=no,location=no,menubar=no,scrollbars="+Popscroll+",resizable="+Popresize);
OpenWin.focus();
}

/** esta funcion imprime el contenido de la pagina parent */
function myprint() {
window.parent.focus();
window.print();
}

/** valida que el caracter que recibe de parametro sea numero entero */
function valida_entero(e){
	//-Jose Handal- 21/09/2008
    /**vcharcode =  (document.all) ? e.keyCode : e.which;*/
	var vcharcode; 
	    vcharcode=document.all?parseInt(e.keyCode): parseInt(e.which);
	/** entre 48 y 57 son numero **/
	if (vcharcode==8 || vcharcode==0){
		return true;
	}
    if (vcharcode < 48 || vcharcode > 57){
        StopPropagation(e);
		e.returnValue = false;
		e.cancel = true;
		return false;
    }
    return true;
}

//Cancela evento. -Jose Handal- 21/09/2008
function StopPropagation(e){
	if(window.addEventListener){ //Firefox
		e.stopPropagation();                
	}else{//IE
		window.event.cancelBubble = true;
	}
}

/** esta funcion aproxima la cantidad que recibe de parametro segun el multiplo del bloque que recibe de parametro **/
function aproxima_bloque(cantidad,bloque,topeBloque){
	cantidad = parseInt(cantidad);
	bloque = parseInt(bloque);
	topeBloque = parseInt(topeBloque);

	if((cantidad <= bloque) && (bloque <= topeBloque))
		return bloque;

	if((cantidad > topeBloque) || (cantidad + bloque - (cantidad % bloque) > topeBloque))
		return topeBloque - topeBloque % bloque;

	if((cantidad % bloque) != 0)
		return cantidad + bloque - (cantidad % bloque);

	return cantidad
}

function gotopage(form){
	window.alert(form);
	var formulario = getElementbyId(form);
	window.alert("Intentando hacer submit al form " + formulario.name);
	formulario.submit();
}

function valida_length_keypress(control, maxlength){
    if (document.getElementById(control).value.length >= maxlength) {
        return false;
    }
    return true;
}

function valida_length_trunc(control, maxlength){
    document.getElementById(control).value = document.getElementById(control).value.substr(0, maxlength);
}

//Permite mostrar mensaje en el label en caso de validaciones.
function printLbl(idLbl,msg)
{
	document.getElementById(idLbl).style.cssText="white-space:nowrap";
	if(msg!=""){
		//Coloca la cadena en el mensaje y muestra el label.		
		document.getElementById(idLbl).innerHTML = "<strong class='txterrorform'>"+msg+"</strong>";
		//document.getElementById(idLbl).style.display="";				
	}
	else{
		//Mensaje vacio y esconde el label
		document.getElementById(idLbl).innerHTML = "";
        document.getElementById(idLbl).style.display="none";
	}           
}

//Retorna la cadena sin los espacios vacios.
function sTrim(str)
{
    if(!str || typeof str != 'string')
        return null;
		return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
 
//Valida que el valor del campo no este vacio.
function IsEmpty(controlId){
	if (document.getElementById(controlId).value==""){
        return true;
    }
	else if (sTrim(document.getElementById(controlId).value)==""){
        return true;
    }
	else{
		return false;
	}
}
//No permite letras en un textbox
function IsNumber(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	if (tecla==8) return true;
	patron = /\d/; // Solo acepta nÃºmeros
	te = String.fromCharCode(tecla);
	return patron.test(te);
}


function IsDate(dateStr) {
		//yyyy-MM-dd
		var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
			return false;
		}
		month = matchArray[3]; // p@rse date into variables
		day = matchArray[5];
		year = matchArray[1];
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				return false;
			}
		}
		return true; // date is valid
	}

