// JavaScript Document
function popup(url,windowname,width,height,features) { 
width=(width)?width:screen.width/2; 
height=(height)?height:screen.height/2; 
var screenX = (screen.width/2 - width/2); 
var screenY = (screen.height/2 - height/2); 
var features= "width=" + width + ",height=" + height +",scrollbars=yes,status=no"; 
features += ",screenX=" + screenX + ",left=" + screenX; 
features += ",screenY=" + screenY + ",top=" + screenY; 

var mywin=window.open(url, windowname, features); 
if (mywin) 
mywin.focus(); 
return mywin; 
} 


function enfocat(objecte,condicio){
	if(condicio){
	objecte.style.borderColor = '#5EEB61';
	objecte.parentNode.style.color = 'black';
	}
	else {
	objecte.style.borderColor = '#ccc';
	objecte.parentNode.style.color = '#888';
	}
}


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 fotosEstrella(vincle,referencia){
// existeix a la cookie aquesta foto?
if (readCookie('fotosPreferides')){	
var esFavorita;
	if (readCookie('fotosPreferides').indexOf(',' + referencia) != -1) { 
	esFavorita = true;
	}
	else {
	esFavorita = false;
	}	
}

//reescribim la cookie en funció de l'acció
var nouValorCookie;

	if (esFavorita){ // esborrar
	nouValorCookie = readCookie('fotosPreferides').replace(','+referencia+'','');
	createCookie('fotosPreferides',nouValorCookie,7)
	vincle.className = 'notriada'
	}
	else { //afegir
	nouValorCookie = readCookie('fotosPreferides') + ',' + referencia;
	createCookie('fotosPreferides',nouValorCookie,7)
	vincle.className = 'triada'
	}

//quantes fotos tenim? 
var fotografies =  new Array();
fotografies = readCookie('fotosPreferides').split(',');
var nombre = fotografies.length - 1;

//modifiquem el número entre parèntesi
d = document.getElementById('quantitatPreferides')
d.innerHTML = '(' + nombre + ')';
}

function treureDePreferides(referencia,objecte){
//modifiquem la cookie
var nouValorCookie = readCookie('fotosPreferides').replace(','+referencia+'','');
createCookie('fotosPreferides',nouValorCookie,7)

//amaguem la foto eliminada
a = objecte.parentNode.parentNode;
a.style.display = 'none';
}

function checkscript(idioma){
// valors obligatoris
nom = document.forms['frm_contacte'].elements['nom_i_cognoms'];
email = document.forms['frm_contacte'].elements['email'];
telefon = document.forms['frm_contacte'].elements['telefon'];

switch(idioma) {
case "ca":
alerta_nom = "Si us plau, facilita'ns el teu nom i cognoms \nper tal que poguem atendre la teva consulta";
alerta_telefon = "Si us plau, facilita'ns el teu telèfon \nper tal que poguem atendre la teva consulta";
alerta_email = "Si us plau, facilita'ns el teu correu electrònic \nper tal que poguem atendre la teva consulta";
break;

case "es":
alerta_nom = "";
alerta_email = "";
alerta_nom = "";
break;

case "en":
alerta_nom = "";
alerta_email = "";
alerta_telefon = "";
break;
}

	if (nom.value == '')	{
		alert(alerta_nom);
		nom.focus();
		return false;
	}
	else if (email.value == '')	{
		alert(alerta_email);
		email.focus();
		return false;
	}
	else if (telefon.value == '')	{
		alert(alerta_telefon);
		telefon.focus();
		return false;
	}
return true;
}


