function $_(id){
	var obj = document.getElementById(id);
	return(obj);
}
function limpia_cuadros_login(texto_inicial,id){
	if($_(id).value==""){
		$_(id).value = texto_inicial;	
	}
	else if($_(id).value==texto_inicial){
		$_(id).value = "";	
	}
}
function teclaintro(e){
    var evento = e || window.event;

    var caracter = evento.charCode || evento.keyCode;
    var letra = String.fromCharCode(caracter);
    var codigo = letra.charCodeAt(0);
	
	if(codigo==13){ //Tecla Intro
		document.login.submit();
	}
}
function despliega(ano){
	var lista = $_('lista_'+ano);
	var enlace = $_('enlace_'+ano);
	if(enlace.className=="selected"){
		enlace.className = "";
		lista.style.display="none";
	}
	else{
		enlace.className = "selected";
		lista.style.display="block";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
////                      Funcion para situar un objeto sobre otro                                 ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var ret = new Array(curleft,curtop);
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
////               Funcion para situar una capa sobre otra con desplazamiento x e y                ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function situa_capa(kual,donde,dondex,dondey){
	var obj = $_(kual);
	var obj_donde = $_(donde);
	
	var xy = findPos(obj_donde);
	
	if (dondex!=-1){
		obj.style.left = (xy[0]*1+dondex*1) + 'px';
//		alert(xy[0]);
	}
	if (dondey!=-1){
		obj.style.top = (xy[1]*1+dondey*1) + 'px';
//		alert(xy[1]);
	}
}

function mostrar(id){
	var capa = $_(id);
	if(capa.style.display=="block"){
		capa.style.display="none";
	}
	else{
		capa.style.display="block";
	}
}
function metecontenido(id,contenido){

	var inst = tinyMCE.getInstanceById(id);
	inst.execCommand('mceInsertContent',false,contenido);

}
function checkbox(id){
	var img = $_(id);
	var hidden = $_(id+"_hidden");
	if(hidden.value==0){
		img.src="imagenes/checkbox_on.png";
		hidden.value = 1;
	}
	else{
		img.src="imagenes/checkbox_off.png";
		hidden.value = 0;
	}
}
function limpia_buscador(modo){
	var caja = $_("busqueda");
	if(modo==1){
		caja.value = "";	
	}
	else if(caja.value==""){
		caja.value = $_("restaura_texto").value;
	}
}


jQuery.extend(jQuery.validator.messages, {
	required: "Debes rellenar este campo"
});

$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a > img").parent().hover(function(){
		var self = $(this);
		self.css("backgroundColor","#ffffff");
	});
});
