﻿function setVisibility(elmName, visible) {
	var elm = document.getElementById(elmName);
	if (elm != null)
		elm.style.display = visible ? '' : 'none';
}
function txtTrim(sender) {
	str = sender.value;
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);
	sender.value = str;
}
function checkMaxLength(sender, e, max) {
	if (sender.value.length >= max) {
		sender.value = sender.value.substr(0, max);
	}
}
function validateCombo(sender, arguments) {
	arguments.IsValid = (arguments.Value != "_") && (arguments.Value != "");


}
function validateFecha(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = new Date(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var now = new Date().setHours(0, 0, 0, 0);
	arguments.IsValid = (arguments.Value == '__/__/____') || ((new Date('01/01/1900') <= fecha) && (fecha <= now));
}
function validateFechaPas(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = new Date(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var now = new Date().setHours(0, 0, 0, 0);
	arguments.IsValid = (arguments.Value == '__/__/____') || (fecha <= now);
}
function validateFechaFut(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = Date.parse(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var now = new Date(); now.setHours(0, 0, 0, 0);
	var max = new Date(); max.setHours(0, 0, 0, 0);
	max.setFullYear(max.getFullYear() + 100);
	arguments.IsValid = false || (arguments.Value == '__/__/____') || (!isNaN(fecha) && fecha >= now && fecha <= max);
}

function validateFechaMayor18(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = Date.parse(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var max = new Date();
	max.setHours(0, 0, 0, 0);
	max.setFullYear(max.getFullYear() - 18);
	var min = new Date('01/01/1950');

	arguments.IsValid = (arguments.Value == '__/__/____') || ((min <= fecha) && (fecha <= max));
}

function validateFechaMayor18DDMMYYY(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = new Date(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var max = new Date();
	max.setHours(0, 0, 0, 0);
	max.setFullYear(max.getFullYear() - 18);
	var min = new Date('01/01/1950');

	var mm = 0;
	var dd = 0;
	var yyyy = 0;
	try {
		var arrfecha = arguments.Value.split('/');
		dd = parseFloat(arrfecha[0]);
		mm = parseFloat(arrfecha[1]);
		yyyy = parseFloat(arrfecha[2]);
	}
	catch (e) {
	}

	arguments.IsValid = (arguments.Value == '__/__/____') || (((min <= fecha) && (fecha <= max))) && validarFechaDDMMYYYY(dd, mm, yyyy);
}

function validateDDMMYYYY(sender, arguments) {
	var fecha = arguments.Value.split('/');
	var mm = parseFloat(fecha[1]);
	var dd = parseFloat(fecha[0]);
	var yyyy = parseFloat(fecha[2]);
	arguments.IsValid = validarFechaDDMMYYYY(dd, mm, yyyy);
}

function validarFechaDDMMYYYY(dd, mm, yyyy) {
	if (yyyy >= 1753 && yyyy <= 9999) {
		if (mm >= 1 && mm <= 12) {
			if (dd >= 1 && dd <= obtenerUltimoDiaMes(dd, mm, yyyy)) {
				return true;
			}
			else {
				return false;
			}
		}
		else
			return false;
	}
	else {
		return false;
	}
	return false;
}

function obtenerUltimoDiaMes(dd, mm, yyyy) {
	if (mm == 2) {
		if (yyyy % 4 == 0) return 29; else return 28;
	}
	else {
		if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12)
			return 31;

		if (mm == 4 || mm == 6 || mm == 9 || mm == 11)
			return 30;
	}
	return 31;
}

function validateFechaSimple(sender, arguments) {
	var fecha = arguments.Value.split('/');
	fecha = new Date(fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	var base = new Date();
	base.setFullYear(base.getFullYear() + 1000);
	base.setHours(0, 0, 0, 0);
	arguments.IsValid = (arguments.Value == '__/__/____') || ((new Date('01/01/1900') <= fecha) && (fecha <= base));
}
function validateFechaVacia(sender, arguments) {
	arguments.IsValid = (arguments.Value != '__/__/____' && arguments.Value.length != 0);
}
function displayGridFooter(gridName, btnName, display) {
	var grid = document.getElementById(gridName);
	if (grid == null) return;
	var trs = grid.getElementsByTagName('tr');
	var footer = trs[trs.length - 1];
	footer.style.display = display ? '' : 'none';
	var btn = document.getElementById(btnName);
	btn.style.display = !display ? '' : 'none';
}
String.prototype.endsWith = function (str) {
	var lastIndex = this.lastIndexOf(str);
	return (lastIndex != -1) && (lastIndex + str.length == this.length);
}
function validateFileImg(sender, arguments) {
	arguments.IsValid = validateFile(arguments.Value, 'jpg,jpeg,gif,bmp,png');
}
function validateFileDoc(sender, arguments) {
	arguments.IsValid = validateFile(arguments.Value, 'doc,docx,pdf,rtf,odt');
}
function validateFile(fileName, extensions) {
	fileName = fileName.toLowerCase();
	extensions = extensions.toLowerCase();
	var ext = extensions.split(',');
	var i = 0;
	while (i < ext.length)
		if (fileName.endsWith('.' + ext[i++])) return true;
	return false;
}
function show(elmName) { document.getElementById(elmName).style.display = ''; }
function hide(elmName) { document.getElementById(elmName).style.display = 'none'; }


function VerPopUp_OfertaLaboral2(OfertaID) {

	var oSeleccion = new Object();
	{
		var hora = new Date();
		Resultado = window.open('VerPopUp_HistorialPostulaciones.aspx?OfertaID=' + OfertaID + '&TipoMantenimiento=0', 'Ratting', 'width=800,height=170,left=150,top=200,toolbar=1,status=1,');

		window.IdAsocioar = 0;
		if (Resultado) {
			return true;
		}
		else
		{ return false; }


	}

}
function VerPopUp_ModificarOfertaLaboral(OfertaID) {
	var oSeleccion = new Object();
	{


		window.location = 'PopUpMntoOferta.aspx?OfertaID=' + OfertaID + '&TipoMantenimiento=1';

	}
}
function VerPopUp_EliminarOfertaLaboral(OfertaID) {

	var oSeleccion = new Object();
	{
		var hora = new Date();
		oSeleccion = OfertaID;

		if (confirm("desea eliminar la oferta laboral con número: " + OfertaID) == true) {
			window.rpta = "1"
			alert(window.rpta);

		}
		else {

			window.rpta = "0";
			return false;
		}
	}

}
function ReloadObjeto() { __doPostBack('TextBox1', '') }


function desaparecer(objeto) {
	try {
		$(objeto).animate({ opacity: 0.0, marginTop: '10%' }, 500).hide("slow");
	}
	catch (e) { }
}

function aparecer(objeto) {
	try {
		$(objeto).animate({ opacity: 0.0, marginTop: "-" + '10%' }, 10).show();
		$(objeto).animate({ opacity: 1.0, marginTop: "0" }, 1000);
	}
	catch (e) { }
}

function desaparecerIni(objeto) {
	try {
		$(objeto).hide();
	}
	catch (e) { }
}

function Validar(Cadena) {
	var Fecha = new String(Cadena);
	var RealFecha = new Date();
	var Ano = new String(Fecha.substring(Fecha.lastIndexOf("/") + 1, Fecha.length));
	Ano = Ano.replace("_", "");
	var Mes = new String(Fecha.substring(Fecha.indexOf("/") + 1, Fecha.lastIndexOf("/")));
	var Dia = new String(Fecha.substring(0, Fecha.indexOf("/")));
	if (isNaN(Ano) || Ano.length < 4 || parseFloat(Ano) < 1900) return false;
	if (isNaN(Mes) || parseFloat(Mes) < 1 || parseFloat(Mes) > 12) return false;
	if (isNaN(Dia) || parseInt(Dia, 10) < 1 || parseInt(Dia, 10) > 31) return false;
	if (Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11 || Mes == 2) {
		if (Mes == 2 && Dia > 28 || Dia > 30) {
			return false;
		}
	}
	return true;
}

function validateFechaSimpleDos(sender, arguments) {
	var fecha1 = arguments.Value;
	var fecha2 = Validar(fecha1);

	var fecha = arguments.Value.split('/');
	fecha = new Date(fecha = fecha[1] + '/' + fecha[0] + '/' + fecha[2]); // convertir a MM/dd/yyyy
	arguments.IsValid = false;
	arguments.IsValid = (arguments.Value == '__/__/____') || (!isNaN(fecha) && (new Date('01/01/1900') <= fecha) && (fecha2 == true));
}

function textboxMultilineMaxNumber(txt, maxLen) {
	if (txt.value.length > maxLen) {
		txt.value = txt.value.substring(0, maxLen);
	}
}


function ScrollToElement(theElement) {
	var selectedPosX = 0;
	var selectedPosY = 0;
	while (theElement != null) {
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
	window.scrollTo(selectedPosX, selectedPosY);
}

function Override_ClientValidate() {
	Page_ClientValidate = function (validationGroup) {
		Page_InvalidControlToBeFocused = null;
		if (typeof (Page_Validators) == "undefined") {
			return true;
		}
		var i;
		for (i = 0; i < Page_Validators.length; i++) {
			ValidatorValidate(Page_Validators[i], validationGroup, null);
		}
		ValidatorUpdateIsValid();
		ValidationSummaryOnSubmit(validationGroup);
		Page_BlockSubmit = !Page_IsValid;

		if (Page_BlockSubmit)
			for (i = 0; i < Page_ValidationSummaries.length; i++)
				if (Page_ValidationSummaries[i].validationGroup == validationGroup)
					ScrollToElement(Page_ValidationSummaries[i]);

		return Page_IsValid;
	};
}

function trim(cadena) {
	while (cadena.substr(0, 1) == " ")
		cadena = cadena.substr(1);
	while (cadena.substr(cadena.length - 1, 1) == " ")
		cadena = cadena.substr(0, cadena.length - 1);
	while (cadena.search(/  /) != -1)
		cadena = cadena.replace("  ", " ");
	return (cadena);
}

function getValue(id) {
	if (document.getElementById(id) == null)
		return '';
	return document.getElementById(id).value;
}

function openVentana(url, w, h, name) {
	var leftScreen = (screen.width - w) / 2;
	var topScreen = (screen.height - h) / 2;
	var opciones = "directories=no,menubar=no,scrollbars=no,status=yes,resizable=no,width=" + w + ",height=" + h + ",left=" + leftScreen + ",top=" + topScreen;
	ventana = window.open(url, name, opciones);
	ventana.focus();
}

function setValue(id, value) {
	if (document.getElementById(id) == null)
		return;
	document.getElementById(id).value = value;
}

/*****************************************************************************/
function validarEmail(value) {
	var reEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return (reEmail.test(value));
}

//*********************************************************************//
function lettersOnly(myfield, e, dec) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla <= 13) return true;
	patron = /[A-Za-zñÑwáéíóúÁÉÍÓÚ\s]/;
	te = String.fromCharCode(tecla);
	return patron.test(te);
}
//*********************************************************************//
function numbersOnly(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key == null) || (key == 0) || (key == 8) ||
                (key == 9) || (key == 13) || (key == 27))
		return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;

	// decimal point jump
	else if (dec && (keychar == ".")) {
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}

function validateFilePdf(sender, arguments) {
	arguments.IsValid = validateFile(arguments.Value, 'pdf');
}




function setValueHtml(id, value) {
	if (document.getElementById(id) == null)
		return;
	document.getElementById(id).innerHTML = value;
}

function TeclaEnter(e) {
	var keyPressed;
	if (document.all) {
		//Browser used: Internet Explorer 6
		keyPressed = e.keyCode;
	}
	else {
		keyPressed = e.which; //Browser used: Firefox
	}
	return keyPressed;
}

//*********************************************************************//
function reorder(box, down) {
	var si = box.selectedIndex;

	if (si == -1) {
		box.selectedIndex = 0;
	}
	else {
		sText = box.options[si].text;
		sValue = box.options[si].value;

		if ((box.options[si].value > "") && (si > 0) && (down == 0)) {
			box.options[si].text = box.options[si - 1].text;
			box.options[si].value = box.options[si - 1].value;
			box.options[si - 1].text = sText;
			box.options[si - 1].value = sValue;
			box.selectedIndex--;
		}
		else if ((si < box.length - 1) && (box.options[si + 1].value > "") && (down == 1)) {
			box.options[si].text = box.options[si + 1].text;
			box.options[si].value = box.options[si + 1].value;
			box.options[si + 1].text = sText;
			box.options[si + 1].value = sValue;
			box.selectedIndex++;
		}
		else if (si == 0) {
			for (var i = 0; i < (box.length - 1); i++) {
				box.options[i].text = box.options[i + 1].text;
				box.options[i].value = box.options[i + 1].value;
			}

			box.options[box.length - 1].text = sText;
			box.options[box.length - 1].value = sValue;

			box.selectedIndex = box.length - 1;
		}
		else if (si == (box.length - 1)) {
			for (var j = (box.length - 1); j > 0; j--) {
				box.options[j].text = box.options[j - 1].text;
				box.options[j].value = box.options[j - 1].value;
			}

			box.options[0].text = sText;
			box.options[0].value = sValue;

			box.selectedIndex = 0;
		}
	}
}

/*****************************************************************************/
function resizeControl(elm, minusheight) {
	var h = document.body.clientHeight - minusheight;
	try { $(elm).style.height = h + 'px'; } catch (e) { }
}

if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function (obj) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == obj) {
				return i;
			}
		}
		return -1;
	}
}
jQuery(document).ready(function () {
	jQuery('textarea[maxlength]').keydown(function (event) {

		if (([8, 13, 16, 17, 18, 27, 35, 36, 37, 38, 39, 40, 46].indexOf(event.keyCode) == -1) && (jQuery(this).val().length >= jQuery(this).attr('maxlength'))) {
			jQuery(this).blur();
			event.returnValue = false;
		}
	});
	jQuery('textarea[maxlength]').blur(function () {
		jQuery(this).val(jQuery(this).val().substr(0, jQuery(this).attr('maxlength')));
	});
});

