//Funciones para centrar la ventana abierta

function centTop(alto){
	alto = alto + 28;
	return ((window.screen.height-alto)/2);
}

function centLeft(ancho){
	return (window.screen.width-ancho)/2;
}

// Convirte valores a true o false

function valBol(val){
	if(val==1){return true}
	else{return false}
}

// Función para validar textos a formatos de base de datos desde un control

// Validar cadenas

function valStr(src, maxLen, minusculas, conSaltos){
	src.value = valStr2(src.value, maxLen, minusculas, conSaltos);
}

function valStr2(texto, maxLen, minusculas, conSaltos){
	if(minusculas != true){
		texto = texto.toUpperCase();
		texto = texto.replace(/Á/gi,"A");
		texto = texto.replace(/É/gi,"E");
		texto = texto.replace(/Í/gi,"I");
		texto = texto.replace(/Ó/gi,"O");
		texto = texto.replace(/Ú/gi,"U");
		texto = texto.replace(/À/gi,"A");
		texto = texto.replace(/È/gi,"E");
		texto = texto.replace(/Ì/gi,"I");
		texto = texto.replace(/Ò/gi,"O");
		texto = texto.replace(/Ù/gi,"U");
	}
	if(conSaltos != true){
		texto = texto.replace(/\r\n|\r|\n/gi," ");
	}
	texto = texto.replace(/\s{2,}/gi," ");
	texto = texto.replace(/^\s|\s$/gi,"");
	if(maxLen){
		texto = texto.substr(0,maxLen);
	}
	return texto;
}

// Función para validar números a formatos de base de datos desde un control

function valNum(src, def){
	src.value = valNum2(src.value, def);
}

function valNum2(num, def){
	num = num / 1;
	if(isNaN(num) == false && num != 0){
		if(num < 0){num = num * (-1)};
		return parseInt(num);
	}
	else{
		if(!def && def!=""){
			return "";
		}
		else{
			return def;
		}
	}
}

// Función para intentar validar direcciones de Correo Electrónico

function isMail(src){
	if(!isMail2(src.value)){
		alert("Debe ingresar un email válido.");
		src.focus();
	}
}

function isMail2(texto){
	var rExp = new RegExp (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	if(texto.length >= 6 && rExp.test(texto)){
		return true;
	}
	return false;
}