
/* ******************************************************************************/
/* onload */
/* ******************************************************************************/
Event.observe(window, "load", function() {
	// hack para los bg en IE6+
	if(document.uniqueID && !window.XMLHttpRequest ) document.execCommand("BackgroundImageCache",false,true);
	
	// twitter
	getTwitters('twitters', { 
		id: 'cinking', 
		count: 1, 
		enableLinks: true, 
		ignoreReplies: true, 
		clearContents: true,
		template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
	});
	
});

/* ******************************************************************************/
/* Validación form
/* ******************************************************************************/
/*
	Comprueba si el valor de el es un número de lon cifras
*/
function isANumber(el, lon)
{
var undefined;

	if((lon==undefined)&&(!isNaN(el.getValue())) ) return true;
	else if((el.getValue().length==lon)&&(!isNaN(el.getValue())) ) return true;
	else return false;
}

/*
	Comprueba si el valor de el es un mail válido
*/
function isAMail(el)
{
	var mail = el.getValue();
	
	if(mail.indexOf('@')<0) { return false; }
	if(mail.substring(mail.indexOf('@')+1,mail.length).indexOf('.')<0) { return false; }
	if(mail.charAt(mail.length-1)=='.') { return false; }
	return true;
}

/*
	Comprueba si w es un carácter entre A-Z o a-z
*/
function isAWord(w)
{
	if((65<=w)&&(w<=90)) return true;
	if((97<=w)&&(w<=122)) return true;
	return false;
}

// variable para controlar que no se abran todas las ventanas justo en el medio
var centeredWindows = 0;

/* ******************************************************************************/
/* Para abrir ventanas
/* ******************************************************************************/
function abre(a)
{
	if($(a.href)!=null) return false;
	
	var ventana = new UI.Window({
		id: a.href, 
		theme: "alphacube", 
		shadowTheme: "mac_shadow",
		shadow: true
	});
	ventana.setSize(600, 400);
	ventana.setAjaxContent(a.href+'?ajax=1', {
		encoding: 'ISO-8859-1'
	});
	ventana.setHeader(a.title);
	ventana.show(); 
	ventana.center();
	
	// si hay más de una ventana en el medio, desplazamos
	centeredWindows++;
	if(centeredWindows>1)
	{
		var pos = ventana.getPosition();
		ventana.setPosition(pos.top+(centeredWindows*15), pos.left+(centeredWindows*15));
	}
	ventana.focus();
	
	// cada vez q se cierre una ventana, actualizamos el contador
	ventana.observe('move:ended', function(e) {
		
		if(!e.memo.window.moved) centeredWindows--;
		e.memo.window.moved=true;
	});
	ventana.observe('destroyed', function(e) {
		if(!e.memo.window.moved) centeredWindows--;
	});

	return false;
}

function visualitza_pestanya(np) {
	for (i=1; i<=4; i++) {
		if (i==np) {
			document.getElementById('pestanya_'+np).style.display='block';
			document.getElementById('pestanya_li'+np).className = 'current';
		} else {
			document.getElementById('pestanya_'+i).style.display='none';
			document.getElementById('pestanya_li'+i).className = '';
		}
	}
}

function visualitza_gover(np) {
	for (i=1; i<=3; i++) {
		if (i==np) {
			document.getElementById('gover_'+np).style.display='block';
			document.getElementById('pestanya_li'+np).className = 'current';
		} else {
			document.getElementById('gover_'+i).style.display='none';
			document.getElementById('pestanya_li'+i).className = '';
		}
	}
}