function BotonDerecho(e){
	var msg = "TELCEL - Copyright"+String.fromCharCode(169)+" 2008";
	if ((navigator.appName == 'Netscape' && e.which == 3) || (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)){
		alert(msg);
	}
	return false;
}

//document.onmousedown = BotonDerecho;
//document.oncontextmenu = BotonDerecho;

function setClassName(objId, className2) {
	document.getElementById(objId).className = className2;
}

function CambiaColor(ncolor, id){
	if(ncolor == "" || ncolor == "none"){
		document.getElementById(id).style.background = 'none';
	} else {
		document.getElementById(id).style.background = "#"+ncolor;
	}
	return false;
}

function CambiaColor2(ncolor, id){
	if(ncolor == "" || ncolor == "none"){
		document.getElementById(id).style.background = 'none';
	} else {
		document.getElementById(id).style.background = "#"+ncolor;
	}
	return false;
}

function Ventana(URL, target, x, y) {
	if (x || y) {
		LeftPos = (screen.width) ? (screen.width - x) / 2 : 0;
		TopPos = (screen.height) ? (screen.height - y) / 2 : 0;
	} else {
		LeftPos = (screen.width) ? (screen.width - x) / 2 : 0;
		TopPos = (screen.height) ? (screen.height - y) / 2 : 0;
	}
	//window.onerror=BIMpopERROR; 
	BIM=window.open(URL , target, "height=" + y + ",width=" + x + ",toolbar=no,location=no,status=no,directories=no,scrollbars=yes,resizable=no,left=" + LeftPos + ",top=" + TopPos); 
	//var BIM=window.showModalDialog(URL,target,"dialogHeight: "+y+"px; dialogWidth: "+x+"px; dialogTop: px; dialogLeft: px; center: Yes; resizable: No; status: No;");
	BIM.focus();
	//TerremotoXY(BIM,5);
	return false;
}

function VentanaApp(URL) {
	var x = 800;
	var y = 550;
	if (x || y) {
		LeftPos = (screen.width) ? (screen.width - x) / 2 : 0;
		TopPos = (screen.height) ? (screen.height - y) / 2 : 0;
	} else {
		LeftPos = (screen.width) ? (screen.width - x) / 2 : 0;
		TopPos = (screen.height) ? (screen.height - y) / 2 : 0;
	}
	window.onerror=BIMpopERROR;
	BIM=window.open(URL , "win1", "height=" + y + ",width=" + x + ",toolbar=no,location=no,status=no,directories=no,scrollbars=yes,resizable=no,left=" + LeftPos + ",top=" + TopPos); 
	BIM.focus();
	return false;
}

function BIMpopERROR() {
	if (!BIM) if (confirm("Probablemente tienes un programa que bloquea los POPUPs. Por favor intentalo de nuevo dando clic y presionando la tecla CTRL")); 
}

function ValidaDelete(url, obj){
	if(confirm("Esta seguro que desea borrar este elemento?")){
		window.location = url; // sin AJAX
		//v = cargar(url, '', false); // con AJAX
		tab = document.getElementById('tabla');
		while (obj.tagName != 'TR') { obj = obj.parentNode; }
		for (i=1; ele=tab.getElementsByTagName('tr')[i]; i++) { 
			if(ele==obj) { 
				var num=i;
			}
		}
		tab.deleteRow(num); // sin AJAX
		//$("#"+obj.id).slideUp("slow", function(){ tab.deleteRow(num); }); // con AJAX
		return false;
	}
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function FixPNG(){
	if ((version >= 5.5) && (document.body.filters)){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src='" + img.src + "', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
	}
}

addLoadEvent(FixPNG);

// Para que una caja de texto solo admita números enteros o flotantes
// <input name="txtQty" TYPE="text" size="6" onkeypress="onlyDigits(event,'noDec');">  noDec = no decimales
// <input name="txtPrice" TYPE="text" size="6" onkeypress="onlyDigits(event,'decOK');">  devOK = acepta decimales

var isIE = document.all?true:false;
var isNS = document.layers?true:false;
function onlyDigits(e,decReq) {
	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 58) ? true:false;
	var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
	window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
	e.which = (!isNum && !dotOK && isNS) ? 0:key;
	return (isNum || dotOK);
}

function noWriting(e){ return window.event ? (window.event.keyCode = 0) : (e.which = 0); } ;

function Disponibilidad(username){
	//username = trim(username);
	if(username != ""){
		//if(!isUsername(username)){ alert("Nombre de usuario incorrecto"); return false; }
		document.getElementById("btnDisponibilidad");
		var ele = document.getElementById("disponibilidad");
		ele.disabled = true;
		setClassName("disponibilidad", "poner");
		ele.innerHTML = "Verificando...";
		var url = "../cpanel/validacionesAjax.php?username=" + username;
		var resultado = procesar(url);
		if( resultado == "0" ){
			// Si regresa CERO indica que el nombre de usuario esta disponible
			ele.innerText = "Disponible";
			setClassName("disponibilidad", "disponible");
		} else {
			// Si regresa UNO indica que el nombre de usuario no esta disponible
			ele.innerText = "No disponible";
			setClassName("disponibilidad", "noDisponible");
		}
		document.getElementById("btnDisponibilidad").disabled = false;
	}
}

function isUsername(username) {
	var expr = new RegExp("(^[a-zA-Z])[a-zA-z0-9_]{4,50}$", "gi");
	return expr.test(username);
	/********************
	flags	Significado 
	 g 		  Explorar la cadena completa 
	 i 		  No distinguir mayúsuculas de minúsuculas 
	 m 		  Permite usar varios ^y $ en el patrón 
	 s 		  Incluye el salto de línea en el comodín punto .  
	 x 		  Ignora los espacios en el patrón 
	 ********************/
}

function Seleccionar(f, valor){
	for (i=0; i<f.elements.length; i++) {
		objeto = f.elements[i];
		if(objeto.type == "checkbox" && objeto.name == "eliminar[]"){
			objeto.checked = valor;
		}
	}
}

function Letra(c){
	document.getElementById("letra").value = c;
	document.form1.submit();
	return false;
}

function VariosEliminados(f){
	f.method = "post";
	f.submit();
	return false;
}

function getVarsForm(f){
	// No envia archivos, solo datos
	var parametros = "";
	for (var i=0; i<f.elements.length; i++) {
		objeto = f.elements[i];
		if(objeto.type == "radio" || objeto.type == "checkbox"){
			if(objeto.checked === true){
				parametros += objeto.name+"="+objeto.value+"&";
			}
		} else {
			parametros += objeto.name+"="+objeto.value+"&";
		}
	}
	return parametros;
}

function recargarPagina(url1){
	var contenedor = "contenedorPadre";
	var div = document.createElement("div");
	div.id = "___divMSG___";
	div.className = "divMSG";
	div.innerHTML = '<table align="center"><tr><td><img src="images/loading.gif"></td><td><p>Recargando p&aacute;gina. Espere por favor.</p></td></tr></table>';
	document.getElementById(contenedor).appendChild(div);
	div.style.left = (window.screen.width-300)/2 + "px";
	div.style.top = (window.screen.height-40)/2 + "px";
	$("div#"+div.id).fadeIn("slow", function(){
		var html = $.ajax({
			url: url1,
			async: true,
			success: function(htmlcode){
				$("div#"+div.id).fadeOut('slow', function(){
					document.getElementById(contenedor).removeChild(div);
				});
				$("#contenedor").html(htmlcode);
			}
			});
	});
}

function EliminarVarios(){
	if(confirm("Esta seguro que desea borrar estos elementos?")){
		var param = "";
		$("input[id=eliminar][checked]").each(function(i){
			param += "&"+this.name+"="+this.value;
			obj = this;
			tab = document.getElementById('tabla');
			while (obj.tagName != 'TR') { obj = obj.parentNode; }
			for (i=1; ele=tab.getElementsByTagName('tr')[i]; i++) { 
				if(ele==obj) { 
					var num=i;
				}
			}
			//tab.deleteRow(num); // sin AJAX
			$("#"+obj.id).slideUp("slow"); // con AJAX
		});
		url = "candidatos_gestion.php?accion=eliminar"+param;
		v = cargar(url, "", false, "POST", param)
		alert(v);
		setTimeout(function() { recargarPagina("candidatos_gestion.php"); }, 1000);
	}
}

function desvanecer(id){
	$(".disponible").fadeOut('2000');	
}

function cuentaRegresiva(){
	setTimeout("desvanecer()", 5000);
}
