
function IsInt(textObj) {
var newValue = textObj.value
var newLength = newValue.length
var aChar

	if (newLength < 1) return false; 
	for(var i = 0; i < newLength; i++) {
		aChar = newValue.substring(i, i+1);
		if (aChar < '0' || aChar > '9') {
			return false;
		}
	}
	return true;
}

function ltrim(str) {
var s = "";

	for (var i = 0; str.charAt(i) == " " && i < str.length; i++) ;
	s = str.substring(i, str.length);
	return s;
}	

function rtrim(str) {
var s = "";
 
	for (var i = str.length - 1; str.charAt(i) == " " && i > 0; i--) ;
	s = str.substring(0, i + 1);
	return s;
}

function trim(str) {
return rtrim(ltrim(str));
}


function cargarHidden(combo, var_hid)
{
//carga variable hidden
var i;
	var_hid.value='';
	for(i=0;i<combo.length;i++)
	{
		var_hid.value=var_hid.value + combo[i].value + "-";
	}
}


function cargarCombo(combo1,combo2)
{
//carga el combo de la derecha y descarga el de la izq
 var i;
	for(i=0;i<combo1.length;i++){
		if(combo1.options[i].selected==true){
		  combo2.options[combo2.length]=new     Option(combo1.options[combo1.selectedIndex].text,combo1.options[combo1.selectedIndex].value);
		  combo1.options[combo1.selectedIndex]=null;  
		  i--;			
 		}
	}	
	return false;
} 

function verDescripcion(textObj,mensaje) {
//chequea que el contenido de un campo text no sea vacio
var s = ""
	s = textObj.value;
	s = trim(s)
	if (s.length >  0) {
		textObj.value = s;
		return true;
	} else {
		alert(mensaje + " no puede estar en blanco.");
		textObj.focus();
		textObj.select();
		return false;
	}		
}

function verHidden(textObj,mensaje) {
//chequea que el contenido de un campo text no sea vacio
var s = ""
	s = textObj.value;
	s = trim(s)
	if (s.length >  0) {
		textObj.value = s;
		return true;
	} else {
		alert(mensaje + " no puede estar en blanco.");
		//textObj.focus();
		//textObj.select();
		return false;
	}		
}

function verCombo(combo,mensaje){
//chequea que un select no este vacio
	if(combo.selectedIndex==-1){
		alert('Seleccione ' + mensaje);
		combo.focus();
		return false;
	}
    return true;	
}

function verComboVacio(combo,mensaje){
//chequea que un select tenga seleccionado algo
	if(combo.value==''){
		alert('Seleccione ' + mensaje);
		combo.focus();
		return false;
	}
    return true;	
}

function verComboMultiline(combo,mensaje) {
//chequea que un select multi-line no este vacio
	if(combo.length==0){
		alert('Seleccione ' + mensaje);
		combo.focus();
		return false;
	}
    return true;	
}

function verEntero(textObj, mensaje) {
//chequea que el contenido de un campo text sea un entero > 0 
//sino devuelve el mensaje
var s;
	if (isNaN(textObj.value) || (textObj.value<=0) ) {
		//alert(textObj.value);
		alert (mensaje + " debe contener sólo números.");
		textObj.focus();
		textObj.select();
		return false;
	} else {
		s=textObj.value;
		if(s.length==0)
			{textObj.value='0';}
		return true;
	}
}

function verEnteroOptativo(textObj, mensaje) {
//chequea que el contenido de un campo text sea un entero > 0 si la longitud es mayor a cero (si
// tiene algo ingresado)
var s;
	if (textObj.value.length>0){
		if (isNaN(textObj.value) || (textObj.value<=0) ) {
			//alert(textObj.value);
			alert (mensaje + " debe ser un número mayor a cero.");
			textObj.focus();
			textObj.select();
			return false;
		}
	}
	return true;
}

function checkEntero(textObj, mensaje) {
//chequea que el contenido de un campo text sea un numerico >= 0 
//sino lo pone en cero
var s;
	if (isNaN(textObj.value) || (textObj.value<0) ) {
		//alert(textObj.value);
		alert (mensaje + " debe ser un número mayor o igual a cero.");
		textObj.focus();
		textObj.select();
		return false;
	}
	else {
		s=textObj.value;
		if(s.length==0)
			{textObj.value='0';}
		return true;
	}
}


function compararDosValores(valor1,valor2,mensaje){
	if(valor1.value!='' && valor2.value!=''){
 	   if((Math.max(valor1.value,valor2.value)==valor1.value && valor1.value!=valor2.value) ){
			alert(mensaje);
			valor1.focus();
			return false;
	   }
	}
	return true;
}

function verDosValores(elem,elem2,mensaje){
//chequea que si un campo esta lleno el otro tambien lo este
	if( (elem.value!='' && elem2.value=='') || (elem2.value!='' && elem.value=='')){
		alert(mensaje);
		elem2.focus();	
		return false;
	}
	return true;
}

function compararClaves(clave,confirma){
	if(confirma.value!=clave.value){
		alert('La contraseña y su confirmación no son iguales');
		return false;
	}
	 return true;	
}


function checkLength(usuario,mini,maxi,mensaje){
var cadena;
	cadena=usuario.value;
	if(cadena.length<mini || cadena.length>maxi){
		alert(mensaje + ' debe tener entre ' + mini + ' y ' + maxi + ' caracteres');
		return false;
	}	
	return true;
}


function checkCUIT(cuit){
var cadena;
	cadena=cuit.value;
	if(!esCuit(cadena) && cadena!='0'){
	//cadena.length != 11 || !verEntero(cuit)) {
		alert('CUIT invalido');
		cuit.focus();
		return false;
	}	
	return true;
}


function volver(){
	history.back();
	return false;
}

function volverVarias(paginas){
	history.go(paginas);
	return false;
}

function imprimir(){
	window.print();
	return false;
}

function check_radio(radio, mensaje){
var i,chequeado,paso;
	chequeado=false;
	paso=false;
	if(radio.length>0){
		for(i=0;i<radio.length;i++){
			paso=true;
			if(radio[i].checked==true)
				chequeado=true;
		}
	}
	else{
		if(radio.checked==true)
				chequeado=true;
	}
	if(chequeado==false){
		alert('Debe seleccionar '+ mensaje);
	}
	return chequeado;
}

function checkRadioValor(radio, mensaje){
var i,chequeado,paso,valor;
	valor='';
	chequeado=false;
	paso=false;
	if(radio.length>0){
		for(i=0;i<radio.length;i++){
			paso=true;
			if(radio[i].checked==true){
				chequeado=true;
				valor=radio[i].value;
			}
		}
	}
	else{
		if(radio.checked==true){
			chequeado=true;
			valor=radio.value;
		}
	}
	if(chequeado==false){
		alert('Debe seleccionar '+ mensaje);
	}
	return valor;
}


function check_mail(obj) 
{
 var expRe = /^[^@]+@[^@]+\.[^@]+$/;               //Crea patrón de expresión regular.
    if (expRe.exec(obj.value)) {
  return true;
 }
 else 
 {
  return false;
 } 
} 

function esCuit(nro) {
var suma;
var resto;
var verif;
var pos = nro.split('');

if (! /^\d{11}$/.test(nro)) return false;

while (true) {
suma = (pos[0] * 5 + pos[1] * 4 + pos[2] * 3 +
pos[3] * 2 + pos[4] * 7 + pos[5] * 6 +
pos[6] * 5 + pos[7] * 4 + pos[8] * 3 + pos[9] * 2);
resto = suma % 11;

if (resto == 0) {
verif = 0;
break;
} 
else if (resto == 1 && (pos[1] == 0 || pos[6] == 7)) {
pos[1] = 4;
continue;
}
else {
verif = 11 - resto;
break;
}
}
return pos[10] == verif;
}
