var TIEMPO_SEGUNDOS = 1000;
var TIEMPO_MINUTOS = 60 * 1000;
var TIEMPO_HORAS = 60 * 60 * 1000;
var TIEMPO_DIAS = 24 * 60 * 60 * 1000;
var TIEMPO_SEMANAS = 7 * 24 * 60 * 60 * 1000;
var TIEMPO_MESES = 30 * 24 * 60 * 60 * 1000;

// Funciones.

function ValidarfrmNewsletters(){

	b_lc_bdv = document.formNewsletters.lc_bdv.checked;
	b_lc_sem = document.formNewsletters.lc_sem.checked;
	b_lc_esp = document.formNewsletters.lc_esp.checked;

	if (document.formNewsletters.nom.value == "") {alert ("Introduļu un nom de contacte")
			document.formNewsletters.nom.focus();
			return false;}
	else if (document.formNewsletters.email.value == ""){alert("Introduļu un E-mail");
         	document.formNewsletters.email.focus();
         	document.formNewsletters.email.select();
         	return false;}
	else if (!checkEmail(document.formNewsletters.email.value)){alert("Introduļu un E-mail vąlid");
         	document.formNewsletters.email.focus();
         	document.formNewsletters.email.select();
         	return false;}
	else if (b_lc_bdv != true && b_lc_sem != true && b_lc_esp != true) {alert ("Heu triar almenys un dels butlletins")
         	document.formNewsletters.lc_bdv.focus();
         	return false;}
	else if (document.formNewsletters.privat.checked != true) {alert ("Heu d'acceptar la cląusula de privacitat")
			document.formNewsletters.privat.focus();
         	return false;}
	else {return true;}

}



function overTD(td,color){
	td.style.cursor='hand';
	td.bgColor = color;
	td.children.tags('A')[0].style.color = 'FFFFFF';
}

function outTD(td){
	td.style.cursor='default';
	td.bgColor='F0F0F0';
	td.children.tags('A')[0].style.color = '000000';
}

function clickTD(td){
	td.children.tags('A')[0].click();
}

function Item(){
  this.length = Item.arguments.length 
  for (var i = 0; i < this.length; i++)
    this[i] = Item.arguments[i]
}

function Fecha() {
  var ndia  = new Item('Diumenge', 'Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte')
  var nmes  = new Item('de gener', 'de febrer', 'de marē', "d'abril", 'de maig', 'de juny', 
                          'de juliol', "d'agost", 'de setembre', "d'octubre", 'de novembre', 'de desembre')
  var ahora
  var fecha = new Date()
  var mes   = fecha.getMonth()
  var dia   = fecha.getDay()
  var aux   = "" + fecha

  ahora = ndia[dia] + ", " + aux.substring(7, 10) + "  " + nmes[mes] + " de " + fecha.getFullYear()
  return ahora
}

function sendnew(cual) 
{
	var url;
	url = "http://www.vilanovadigital.com/espais/sendnew.asp?idnew=" + cual;
	window.open(url,'Question','status=no,titlebar=no,width=570,height=460,top=150,left=150');
}

function printnew(cual) 
{
	var url;
	url = "http://www.vilanovadigital.com/espais/printnew.asp?idnew=" + cual;
	window.open(url,'printnew','toolbar=yes,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no,width=640,height=520');
}


function suscribir() 
{
	if (document.frmSusButlletins.nom.value == "") {
		alert ("Introduļu un nom");
		document.frmSusButlletins.nom.focus();
	}
	else if (document.frmSusButlletins.email.value == "") {
		alert("Introduļu el vostre E-mail");
       	document.frmSusButlletins.email.focus();
	}
	else if (!checkEmail(document.frmSusButlletins.email.value)) {
		alert("Introduļu un E-mail vąlid");
        document.frmSusButlletins.email.focus();
        document.frmSusButlletins.email.select();
	}
	else {
		var url;
		url = "http://www.vilanovadigital.com/membres/suscribir.asp?nom=" + escape(document.frmSusButlletins.nom.value) ;
		url += "&email=" + escape(document.frmSusButlletins.email.value) ;
		url += "&lista=" + escape(document.frmSusButlletins.lista.value) ;
		window.open(url,'suscribir','status=no,titlebar=no,width=560,height=500');
	}
}

function suscribir2() 
{
	if (document.frmSusButlletins.nom.value == "") {
		alert ("Introduļu un nom");
		document.frmSusButlletins.nom.focus();
	}
	else if (document.frmSusButlletins.email.value == "") {
		alert("Introduļu el vostre E-mail");
       	document.frmSusButlletins.email.focus();
	}
	else if (!checkEmail(document.frmSusButlletins.email.value)) {
		alert("Introduļu un E-mail vąlid");
        document.frmSusButlletins.email.focus();
        document.frmSusButlletins.email.select();
	}
	else if (document.frmSusButlletins.privat.checked != true) {
		alert ("Heu d'acceptar la cląusula de privacitat")
		document.frmSusButlletins.privat.focus();
	}
	else {
		var url;
		url = "http://www.vilanovadigital.com/membres/suscribir.asp?nom=" + escape(document.frmSusButlletins.nom.value) ;
		url += "&email=" + escape(document.frmSusButlletins.email.value) ;
		url += "&lista=" + escape(document.frmSusButlletins.lista.value) ;
		window.open(url,'suscribir','status=no,titlebar=no,width=560,height=500');
	}
}


function fshowquestion(cual) 
{
	var url;
	url = "http://www.vilanovadigital.com/serveis/enquestes/question.asp?idpregunta=" + cual;
	window.location = url;
}

function votarquestion(pregunta,tipopregunta){

	var alguno_activado=0;
	var respuesta="";

		if (tipopregunta=="RB") {
		  for(var i=0; i<document.encuesta.length; i++) {
			if (document.encuesta.elements[i].checked==true) {
				alguno_activado=1;
				respuesta = document.encuesta.elements[i].value;
			}
		  }
		}
		else if (tipopregunta=="CB"){
		  for(var i=0; i<document.encuesta.length; i++) {
			if (document.encuesta.elements[i].checked==true) {
				alguno_activado=1;
				respuesta += ((respuesta!="") ? "," : "") + document.encuesta.elements[i].value;
			}
		  }
		}

  	// alert(alguno_activado)
	if (alguno_activado==0) {
		alert("Seleccioneu alguna de les respostes")
		return;
	}

	url = "http://www.vilanovadigital.com/serveis/enquestes/replyquestions.asp?source=email&Tipo=" + tipopregunta + "&IdPregunta=" + pregunta + "&" + pregunta + "=" + respuesta;
	window.location = url;

}

function getCookie( nombre )
// Devuelve un string con el contenido asignado a la cookie cuyo nombre se pasa como parįmetro. Si la cookie no existe, devuelve null.
{
  var coincid = ( new RegExp( nombre + "=([^\\;\\,\\s]*)\\;?" ) ).exec( document.cookie );

  return ( coincid != null ) ? unescape( coincid[ 1 ] ) : null;
}

////	      function setCookie( nombre, "", 0, factor )
function setCookie( nombre, valor, plazoExp, factor )
////    function setCookie( nombre, "", 0, TIEMPO_SEGUNDOS )
// Asigna valor a la cookie cuyo nombre se pasa como primer parįmetro. El plazo de expiración (tercer parįmetro) es opcional. El factor de tiempo por defecto es TIEMPO_DIAS.
// Para borrar una cookie, emplear setCookie( nombre, "", 0, TIEMPO_SEGUNDOS )
{
  var nuevaCookie = nombre + "=" + escape( valor );

  if ( plazoExp != null && ( !isNaN( parseInt( plazoExp ) ) || !isNaN( parseFloat( plazoExp ) ) ) )
  {
    var fechaExp = new Date();

    fechaExp.setTime( fechaExp.getTime() + ( plazoExp * ( ( factor == null ) ? TIEMPO_DIAS : factor ) ) );
    nuevaCookie += "; expires=" + fechaExp.toGMTString();
  }
  document.cookie = nuevaCookie;
}

	
//// Comprobar si es un email valido
function checkEmail(valor){

		if ( (valor.indexOf('@') < 0) ||
			 (valor.indexOf('.') < 0) ||
			 (valor.indexOf('@') > valor.lastIndexOf('.'))||
			 (valor.length < 5) ||
			 (valor.indexOf(' ') >= 0) ||
			 (valor.indexOf('\'') >= 0) ||
			 (valor.indexOf('#') >= 0)
		    ){
				return false;
			}else{
				return true;
			}
	}

function som() 
{
	window.open('http://www.vilanovadigital.com/som.asp','popup','resizable=no,scrollbars=no,status=no,width=220,height=500,top=100,left=100');
}

function Sugerencias() 
{
	window.open('http://www.vilanovadigital.com/Membres/Feedback.asp','popup','resizable=no,scrollbars=no,status=no,width=560,height=450,top=100,left=100');
}

function Registrat() 
{
	window.open('http://www.vilanovadigital.com/Membres/Membre1.htm','popup','resizable=no,scrollbars=no,status=no,width=560,height=500,top=100,left=100');
}

function Recomana() 
{
	window.open('http://www.vilanovadigital.com/Membres/Recomendar.asp','popup','resizable=no,scrollbars=no,status=no,width=560,height=500,top=100,left=100');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

