//=====================================================================
// Event Listener
// by Scott Andrew - http://scottandrew.com
// edited by Mark Wubben, <useCapture> is now set to false
//=====================================================================
function addEvent(obj, evType, fn){
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, false); 
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	} else {
		return false;
	}
}

//funcion para marcar los links externos, solo marca los que tienen el atributo rel="external" (esta es la que uso)
/*function external_links() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
		anchor.className = "external";
		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external2") {
		anchor.target = "_blank";
		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "license") {
		anchor.target = "_blank";
		}
	}
}
//addEvent(window, "load", external_links); //=window.onload=external_links
Event.observe(window, 'load', external_links, false);*/
		
function abrir(pagina) {
	window.open(pagina,"imagen","width=400,height=400,scrollbars=no, resizable=no, top=280,left=200");
}

//funcion para validar campos de formulario
function validar(cadena,targetId){	
	var validaciones = cadena.split('.');
	error = false;
	for (i=0;i<validaciones.length;i++){
		if (document.getElementById(validaciones[i]).value=="") { error = true; };
	}	
	if (error==true){
		document.getElementById(targetId).innerHTML='<p class="error">Rellena los campos obligatorios (*)</p>';
		return false;
		}
	else return true;
}

//funcion para ocultar/mostrar 
function muestra(targetId) {
	target = document.getElementById(targetId);
	if ((!target.style.display) || (!target.style) || (target.style.display == "none")) target.style.display = "block";
	else target.style.display = "none";
	return false;
}

//funciones relacionadas con xcode
	function negrita(campo)
     {
	   document.getElementById(campo).value=document.getElementById(campo).value+'[b][/b]';
       document.getElementById(campo).focus();		
     }

     function cursiva(campo)
     {
       document.getElementById(campo).value=document.getElementById(campo).value+'[i][/i]';
       document.getElementById(campo).focus();		
     }

     function subrayado(campo)
     {
       document.getElementById(campo).value=document.getElementById(campo).value+'[u][/u]';
       document.getElementById(campo).focus();		
     }
     
	   function imagen(campo)
     {
      document.getElementById(campo).value=document.getElementById(campo).value+'[img src=url_de_la_imagen]';
       document.getElementById(campo).focus();		
     }

     function url(campo)
     {
       mensaje_actual=document.getElementById(campo).value;
		
       var url = prompt("Introduzca la URL de la web: ", "http://");

       if((url==null)||(url=="")) return;

       var titulo = prompt("Nombre para el enlace (Pulse ESC si desea que sea la URL)", "Titulo de la pagina");

       if((titulo==null)||(titulo==''))
           var url_codigo = '[url href="'+url+'" rel="external"]'+url+'[/url]';
       else
           var url_codigo = '[url href="'+url+'" rel="external"]'+titulo+'[/url]';

       mensaje = mensaje_actual+url_codigo;
       
       document.getElementById(campo).value=mensaje;
       document.getElementById(campo).focus();		
     }
 
       function cita(campo)
     {
       tag="\n[cita][/cita]";
       document.getElementById(campo).value=document.getElementById(campo).value+tag;
       document.getElementById(campo).focus();		
     }
	
		function smiley(campo,cara)
     {
        switch(cara){
			case ":P": emoticon=" :P "; break;
			case ":S": emoticon=" :S "; break;
			case ":)": emoticon=" :) "; break;
			case ";)": emoticon=" ;) "; break;
			case ":(": emoticon=" :( "; break;
			case ":D": emoticon=" :D "; break;
		};
		 
		 document.getElementById(campo).value=document.getElementById(campo).value+emoticon;
		 document.getElementById(campo).focus();
     }

