	function compartir(tipo){
		var title = encodeURIComponent(window.document.title);
		var href = encodeURIComponent(window.document.location.href);

		switch(tipo){
			case 'delicious' : url = 'http://del.icio.us/post?url='+href+'&title='+title; break;
			case 'digg' : url = 'http://digg.com/submit?phase=2&url='+href+'&title='+title;	break;
			case 'facebook' : url = 'http://www.facebook.com/share.php?u='+href; break;
			case 'igoogle' : url = 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+href+'&title='+title; break;
			case 'mylive' : url = 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=es-es&url='+href+'&title='+title; break;
			case 'myspace' : url = 'http://www.myspace.com/Modules/PostTo/Pages/?u='+href; break;
			case 'twitter' : url = 'http://twitthis.com/twit?url='+href+'&title='+title; break;
			case 'yahoo' : url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+href+'&t='+title+'&ei=UTF-8'; break;
			default : return false;
		}

		window.open(url);
	}

	function url_actual(){

		var a = location.protocol+'//'+location.hostname;
		return a;

	}
	
	function mostrar_texto(texto,capa){
		document.getElementById(capa).innerHTML = texto;
	}
	
	function bookmarksite(title,url){
		if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}
		else if(document.all)// ie
		window.external.AddFavorite(url, title);
	}

	function trim(cadena){
		cadena= cadena.replace(/^\s+/, '');
		for (var i = cadena.length; i > 0; i--) {
			if (/\S/.test(cadena.charAt(i))) {
				cadena= cadena.substring(0, i);
				break;
			}
		}
		return cadena;
	}

	function cerrar_ventana(){

		try{
			window.parent.hidePopWin(true);
		}catch(err){
			window.close();
		}

	}

	function confirmacion(){
		if (confirm('¿Realmente desea proceder?, esta acción es irreversible.')){
			return true;
		}else{
			return false;
		}
	}
	
	function mostrar_ocultar_capa(capa){
		document.getElementById(capa).style.display = (document.getElementById(capa).style.display == '' )?'none':'';
		createCookie(capa,document.getElementById(capa).style.display);
	}

	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	function imprimir() {
		if (window.print){
			window.print()
		}else{
			alert("Disculpe, su navegador no soporta esta opción.");
		}
	}

	function confirmar(theform){
		var elem=false;
		for(var i=0; i < theform.elements.length; i++){
			if ((theform.elements[i].type == "checkbox" || theform.elements[i].type == "radio") && theform.elements[i].disabled == false && theform.elements[i].checked == true){
				elem=true;
				break;
			}
		}
		if(!elem){
			alert('Por favor seleccione al menos un elemento para continuar.');
			return false;
		}
	}

	function alerta(mensaje){
		try{
			showPopWin(mensaje, 260, 80, null, true);
		}catch(err){
			alert(mensaje);
		}
	}

	function setear_campo(campo){
		document.getElementById(campo).className = 'requerido';
		document.getElementById(campo).value = '';
		document.getElementById('span-'+campo).innerHTML = '';
	}

	function validar_ajax(theform){
		var error = false;
		for (var i = 0; i < theform.length; i++){
			if(theform.elements[i].type == "text" || theform.elements[i].type == "textarea" || theform.elements[i].type == "select-one"){
				var class_campos = theform.elements[i].className;
				if((trim(theform.elements[i].value) == "" && theform.elements[i].disabled == false && class_campos == "requerido") || (class_campos == "input_alerta" || class_campos == "input_error")){
					if(class_campos != "input_alerta"){
						theform.elements[i].className = "input_error";
						if(document.getElementById('span-'+theform.elements[i].id)){
							document.getElementById('span-'+theform.elements[i].id).innerHTML = ('<img src="'+url_actual()+'/img/error.png" alt="" class="validacion" title="El Campo no es opcional">');
						}
					}
					error = true;
				}else{
					if(class_campos != "input_alerta"){
						theform.elements[i].className = "";
						if(document.getElementById('span-'+theform.elements[i].id)){
							document.getElementById('span-'+theform.elements[i].id).innerHTML = ('<img src="'+url_actual()+'/img/ok.png" alt="" class="validacion">');
						}
					}
				}
			}
		}
		if(error){
			alerta('Existen errores en el formulario.');
			return false;
		}
	}

	/*/////////////////////*/

	function nucleo_ajax(){
		var xmlhttp = false;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
	  		}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}

	function consulta_ajax(cadena,capa_destino,valores,metodo){
		var base_php = url_actual() + '/ajax.php?'; //COLOCAR URL COMPLETA!!!
		var ajax = nucleo_ajax();
		ajax.open (metodo, base_php + cadena, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4){
				switch(ajax.responseText){
					case "err":
						if(document.getElementById(capa_destino).className != "input_error"){
							document.getElementById(capa_destino).className = "input_error";
							document.getElementById('span-'+capa_destino).innerHTML = ('<img src="'+url_actual()+'/img/error.png" alt="" class="validacion" title="El Campo no es opcional">');
						}
					break;
					case "ok":
						if(document.getElementById(capa_destino).className != ""){
							document.getElementById(capa_destino).className = "";
							document.getElementById('span-'+capa_destino).innerHTML = ('<img src="'+url_actual()+'/img/ok.png" alt="" class="validacion">');
						}
					break;
					case "fallo":
						if(document.getElementById(capa_destino).className != "input_alerta"){
							document.getElementById(capa_destino).className = "input_alerta";
							document.getElementById('span-'+capa_destino).innerHTML = ('<img src="'+url_actual()+'/img/alerta.png" alt="" class="validacion" title="Existen errores en este Campo">');
						}
					break;
					case "ok_pass":
						if(document.getElementById('clave_usuario').className != ""){
							document.getElementById('clave_usuario').className = "";
							document.getElementById('span-clave_usuario').innerHTML = ('<img src="'+url_actual()+'/img/ok.png" alt="" class="validacion">');
						}
						if(document.getElementById('clave_usuario_confirm').className != ""){
							document.getElementById('clave_usuario_confirm').className = "";
							document.getElementById('span-clave_usuario_confirm').innerHTML = ('<img src="'+url_actual()+'/img/ok.png" alt="" class="validacion">');
						}
					break;
					case "fallo_pass":
						if(document.getElementById('clave_usuario').className != "input_alerta"){
							document.getElementById('clave_usuario').className = "input_alerta";
							document.getElementById('span-clave_usuario').innerHTML = ('<img src="'+url_actual()+'/img/alerta.png" alt="" class="validacion" title="Las Contraseñas deben coincidir">');
						}
						if(document.getElementById('clave_usuario_confirm').className != "input_alerta"){
							document.getElementById('clave_usuario_confirm').className = "input_alerta";
							document.getElementById('span-clave_usuario_confirm').innerHTML = ('<img src="'+url_actual()+'/img/alerta.png" alt="" class="validacion" title="Las Contraseñas deben coincidir">');
						}
					break;
					default:
						document.getElementById(capa_destino).innerHTML = ajax.responseText;
					break;
				}
			}
		}
		
		switch(metodo.toUpperCase()){
			case "GET":
				ajax.send(null);
			break;
			case "POST":
				ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				ajax.send(valores);
			break;
		}

		//delete(ajax);

	}

	function conmutar(modo,capa){

		var deshabilitado;
		if(modo == "block"){
			deshabilitado = false
			color_gris = "#000000";
		}else{
			deshabilitado = true;
			color_gris = "#a1a1a1";
		}

		capa_matriz = document.getElementById(capa);

		for (i=0; elemento = capa_matriz.getElementsByTagName('textarea')[i]; i++){
			elemento.disabled = deshabilitado;
		}
		for (i=0; elemento = capa_matriz.getElementsByTagName('select')[i]; i++){
			elemento.disabled = deshabilitado;
		}
		for (i=0; elemento = capa_matriz.getElementsByTagName('label')[i]; i++){
			elemento.style.color = color_gris;
		}

		for (i=0; elemento = capa_matriz.getElementsByTagName('input')[i]; i++){
			try{
				elemento.checked = !deshabilitado;
				if(elemento.name == 'permiso[]'){
					elemento.disabled = deshabilitado;
				}else if(elemento.name == 'acceso[]'){
					capa_matriz.getElementsByTagName('label')[i].style.color = "#000000";
				}else{
					elemento.disabled = deshabilitado;
				}
			}catch(err){
				return false;
			}
		}

		document.getElementById(capa).style.display = modo;

	}

	function roll_over(img_name, img_src){
		document.getElementById(img_name).src = img_src;
	}

	function abrirVentana(mypage,myname,w,h,scroll,sizeable){

		try{
			//initPopUp = null;
			//initPopUp(parseInt(w), parseInt(h));
			showPopWin(mypage, parseInt(w), parseInt(h), null);
		}catch(err){
			var win = null;
			LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
			settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+sizeable
			win = window.open(mypage,myname,settings)
			win.focus();
		}

	}

	function conmutar_visible(div1,div2){
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "block";
		document.getElementById('titulo_msg').focus();
	}
	
	window.onload = function (){

		var detener = false;
		var raiz = document.forms;
		for(var j = 0; j < raiz.length; j++){
			var theform = raiz[j];
			for(var i = 0; i < theform.length; i++){
				if((theform.elements[i].type == "text" || theform.elements[i].type == "password" || theform.elements[i].type == "textarea") && (theform.elements[i].disabled == false && theform.elements[i].readOnly == false)){
					theform.elements[i].focus();			
					detener = true;
					break;
				}
			}
			if(detener){
				break;
			}
		}
		if(readCookie('confirmacion') == 1){
			alerta('Datos procesados exitosamente.');
			eraseCookie('confirmacion');
		}
		var url = location.href;
		var ancla = (url.substring(url.lastIndexOf("#")));
		if(url.indexOf("#") > -1 && ancla.length > 1){
			window.location.hash = ancla;
		}

	}
