$(document).ready(function ()
{	
	$('#nav li').hover(
		function () {
			$('ul', this).slideDown(200);
		}, 
		function () {
			$('ul', this).slideUp(200);			
		}
	);

	g('q').onblur = function(){ sintexto(this); }
	g('q').onfocus = function() { contexto(this); }
	if (g('esp')) g('esp').onclick = function() { traducir('es'); }
	if (g('eng')) g('eng').onclick = function() { traducir('en'); }
	if (g('fra')) g('fra').onclick = function() { traducir('fr'); }
	if (g('mar')) g('mar').onclick = function() { traducir('ar'); }
	if (g('rom')) g('rom').onclick = function() { traducir('ro'); }
	
	document.oncontextmenu = function() { return false; }
	document.ondragstart = function() { return false; }
	document.onmousedown = md;
	
	jQuery(function($) {
		if ($("a[rel^='lightbox']").slimbox) {
			$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
				return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
			});
		}
	});
	
	if (top !== self && document.referrer.match(/translate\.google\.com\/\w{1,8}/)) top.location.replace(self.location.href);

});

function g(name)
{
	return $("#"+name)[0]; 
}

function leernoticia(obj)
{
	window.location=obj.title;
	return true;
}

function redireccionar(url)
{
	url = (typeof url == 'undefined') ? this.location : url;
	this.location=url;
	return true;
}

function sintexto(caja)
{
	if(caja.value=='')caja.value='Buscar...';
	return true;
}

function contexto(caja)
{
	if(caja.value=='Buscar...')caja.value='';
	return true;
}

function encod(tipo, form)
{
	if (form.q.value=='Buscar...') {
		return false;
	} else {
		alert(tipo);
		if (tipo=='base64') {
			form.q.value=encode64(form.q.value);
			return true;
		}
	}
}

//textarea onkeydown="return maximo(this, event, 200)"></textarea>
function maximo(obj, e, ma)
{
	tecla = (document.all) ? e.keyCode : e.which;
	if (obj.value.length==ma && tecla!=8) return false;
}

String.prototype.toProperCase = function()
{
     return this.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}

function destruir(obj)
{
   document.getElementById(obj).parentNode.removeChild(document.getElementById(obj));
   return true;
}

function prelogin(tipo)
{
	if (document.getElementById('hugu_crd_pln').value=="" || document.getElementById('hugu_usr').value=="") {
		return false;
	}
	
	if (tipo==1) {
		document.getElementById('hugu_crd').value = SHA256(SHA256(document.getElementById('hugu_crd_pln').value));
	} else if (tipo==2) {
		document.getElementById('hugu_crd').value = document.getElementById('hugu_crd_pln').value;
	}
	destruir('hugu_crd_pln');
	return true;
}

function in_array(needle, haystack, strict)
{ 
    var found = false, key, strict = !!strict; 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    } 
    return found;
}

function mostrar_servicios(letra)
{
	$('#dat li').each(function() { 
	  $(this).attr('style', 'display:');
	})
	if (letra!=="todos") {
		$('#dat li').each(function() {
			if (this.id!==letra) {
				$(this).attr('style', 'display:none');
			}
		})
	}	
	return true;
}

function traducir(destino)
{
	this.location='http://translate.google.com/translate?prev=hp&hl=es&js=y&u='+this.location+'&sl=es&tl='+destino;
	return true;
}

function checkEmail(email)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	} else {
		return true;
	}
}

function check()
{
	if (g("mensaje")) {
		if (palabras_malsonantes(g("mensaje"))) return false;
	}
	if (g("asunto")) {
		if (palabras_malsonantes(g("asunto"))) return false;
	}	
	if (g("correo").value=="" || g("asunto").value=="" || g("mensaje").value=="") {
		var alertm = "";
		alertm += "\nHOSPITAL UNIVERSITARIO DE GUADALAJARA\n\nHa dejado algún/os campos obligatorios sin completar.\nRellene todos los campos del formulario.\n\n";
		alert(alertm);
		return false;
	} else {
		if (!checkEmail(g("correo").value)) {
			var alertm = "";
			alertm += "\nHOSPITAL UNIVERSITARIO DE GUADALAJARA\n\nIntroduzca una dirección de correo correcta\n\n";
			alert(alertm);
			g("correo").focus();
			return false;
		}
	}
	return true;
}

function palabras_malsonantes(obj)
{
	var palabras = new Array("cabron","cabrón","gilipollas","puta","me cago","caguen","hijoputa","polla","cojones","coño","joder","jodio","por culo","chupa pollas","lame culos","chupapollas","lameculos","cagonto","mierda","cabrones");
	if (obj.value)
	{
		for (i = 0; i < palabras.length; i++) {
			var pos = obj.value.toLowerCase().search(palabras[i]);
			var next = obj.value.charAt(pos+palabras[i].length);
			if (pos>=0 && (next==" " || next=="")) {
				alert("\nHOSPITAL UNIVERSITARIO DE GUADALAJARA\n\nPor favor, no utilize palabras malsonantes como '"+palabras[i].substr(0,palabras[i].length-1)+"*' en el texto.\n\n");
				return true;
			}
		}
	}
	return false;
}

function md(e) 
{ 
  try { if (event.button==2||event.button==3) return false; }  
  catch (e) { if (e.which == 3) return false; } 
}

function abrir(url, w, h)
{
	ventana = window.open(url,"ventana","location=0,status=1,scrollbars=0,width="+w+",height="+h);
}