// JavaScript Document
function validarEmail(valor)
{
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	{
		//alert("La dirección de email " + valor    + " es correcta.") 
		return (true);
	}
  	else
  	{
		alert("La dirección de email es incorrecta.");
   		return (false);
  	}
}

function validar2(form, e)
{
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	// 13: Enter
	if(keynum == 13){
	
		if(!validarEmail(form.mail.value)){
			form.mail.focus();
		}
		else
			go(form, "registre_news.php");
	}
}

function validar(form)
{

	if(!validarEmail(form.mail.value)){
		form.mail.focus();
	}
	else
		go(form, "registre_news.php");
}

function go_galeria(form, url, contador) 
{
	form.posicio.value = contador;
//alert(form.posicio.value);
	form.action = url;
	form.submit();
}

function canviarFoto(model, foto, direc)
{  //el Mozilla no agafa elements per id si no hi ha l'etiqueta id a l'element corresponent,
   //en canvi l'Internet Explorer si que agafa el nom en comptes de l'id
	parent.document.getElementById("titolPrincipal").src = model;
	parent.document.getElementById("fotoPrincipal").src = foto;
	parent.document.getElementById("link").href = "javascript:obrirFinestra('" + direc + "','Dispromedia', '775', '500', '100', '150')";
}
function canviarFoto2(foto)
{
	parent.document.getElementById("fotoPrincipal").src = foto;
}
//-->
function obrirFinestra( url, nomFinestra, amplada, altura, top, left )
{
	var wf = "";	
	wf = wf + "width=" + amplada;
	wf = wf + ",height=" + altura;
	wf = wf + ",resizable=no";
	wf = wf + ",title="+ nomFinestra;
	wf = wf + ",scrollbars=yes";
	wf = wf + ",menubar=no";
	wf = wf + ",toolbar=no";
	wf = wf + ",directories=no";
	wf = wf + ",location=no";
	wf = wf + ",status=no";
	wf = wf + ",top=" + ((screen.availHeight-amplada)/2);
	wf = wf + ",left=" + ((screen.availHeight-altura)/2);	

    window.open(url,nomFinestra,wf);
}
function obrirFinestra2( url, nomFinestra, amplada, altura, top, left )
{ 
	var wf = "";	
	wf = wf + "width=" + amplada;
	wf = wf + ",height=" + altura;
	wf = wf + ",resizable=no";
	wf = wf + ",title="+ nomFinestra;
	wf = wf + ",scrollbars=no";
	wf = wf + ",menubar=no";
	wf = wf + ",toolbar=no";
	wf = wf + ",directories=no";
	wf = wf + ",location=no";
	wf = wf + ",status=no";
	wf = wf + ",top=" + ((screen.availHeight-amplada)/2);
	wf = wf + ",left=" + ((screen.availHeight-altura)/2);	

	window.open(url,nomFinestra,wf);
 	if (navigator.userAgent.indexOf('Safari') != -1)
 	{
		window.document.contacto.politica.disabled = false;
 	}
 	else if (navigator.userAgent.indexOf('MSIE') != -1)
 	{
	    // funciona de totes dues maneres
		//parent.document.getElementById("politica").disabled = false;
		window.document.contacto.politica.disabled = false;
	}
 	else if (navigator.userAgent.indexOf('Mozilla') != -1)
 	{
		window.document.contacto.politica.disabled = false;
	}
 	else if (navigator.userAgent.indexOf('Netscape') != -1)
 	{
		window.document.contacto.politica.disabled = false;
 	}
	else 
	{
		window.document.contacto.politica.disabled = false;
	}
}
function obrirFinestra3( url, nomFinestra, amplada, altura, top, left )
{
	var wf = "";	
	wf = wf + "width=" + amplada;
	wf = wf + ",height=" + altura;
	wf = wf + ",resizable=no";
	wf = wf + ",title="+ nomFinestra;
	wf = wf + ",scrollbars=no";
	wf = wf + ",menubar=no";
	wf = wf + ",toolbar=no";
	wf = wf + ",directories=no";
	wf = wf + ",location=no";
	wf = wf + ",status=no";
	wf = wf + ",top=" + ((screen.availHeight-amplada)/2);
	wf = wf + ",left=" + ((screen.availHeight-altura)/2);	

    window.open(url,nomFinestra,wf);
}
function testejar()
{
 	if (navigator.userAgent.indexOf('Safari') != -1)
 	{
		window.document.contacto.politica.disabled = false;
 	}
 	else if (navigator.userAgent.indexOf('MSIE') != -1)
 	{
	    // funciona de totes dues maneres, com en el Mozilla també
		if (parent.document.getElementById("politica").checked)
		{
			parent.document.getElementById("enviar").disabled = false;
		}
		else
		{
			parent.document.getElementById("enviar").disabled = true;
		}	
	}
 	else if (navigator.userAgent.indexOf('Mozilla') != -1)
 	{
		if (window.document.getElementById("politica").checked)
		{
			window.document.getElementById("enviar").disabled = false;
		}
		else
		{
			window.document.getElementById("enviar").disabled = true;
		}	
		//window.document.contacto.politica.disabled = false;
	}
 	else if (navigator.userAgent.indexOf('Netscape') != -1)
 	{
		window.document.contacto.politica.disabled = false;
 	}
	else 
	{
		window.document.contacto.politica.disabled = false;
	}
}
   function verificarFormBuscador_ref(form) 
   {
	   if (form.referencia.value != "" && !Number(form.referencia.value))
	   {
		  alert("Por favor introduzca una referencia válida en el campo correspondiente.");
          form.referencia.focus();
		  return false;
	   }      
       else
	   {
	   	   go(form, "consulta_buscador_ref.php");
	   }      
	}
   function focus_otros(form) 
   {
		  form.otros.focus();
   }
   function verificarForm(form, url) 
   {
	   valor = form.remitente.value;
       correo = "valor.lastIndexOf('@')!=valor.indexOf('@') || valor.indexOf('@')<2 || valor.lastIndexOf('.')<valor.length-4 || valor.lastIndexOf('.')>valor.length-3";

	   if (form.nombre.value == "" || form.nombre.value.length<3 )
	   {
		  alert("Por favor introduzca un nombre.");
		  form.nombre.focus();
		  return false;
	   }      
	   else if (form.remitente.value == "" || eval(correo))
	   {
		  alert("Por favor introduzca un correo electrónico válido para poder responder sus cuestiones.");
		  form.remitente.focus();
		  return false;
	   }
	   else if (form.telf.value == "" || form.telf.value.length<9 )
	   {
		  alert("Por favor introduzca un teléfono de contacto válido.");
		  form.telf.focus();
		  return false;
	   }
	   else if (form.asunto.value == "" || form.asunto.value.length<3 )
	   {
		  alert("Por favor introduzca el tema de contacto en el campo asunto.");
		  form.asunto.focus();
		  return false;
	   }      
	   else if (form.mensaje.value == ""  || form.mensaje.value.length<5 )
	   {
		  alert("Por favor introduzca en el campo mensaje la razón de contacto con nuestra empresa.");
		  form.mensaje.focus();
		  return false;
	   }      
       else
	   {
	   	  go(form, url);
	   }      
   }
function go(form,url) 
{
	form.action = url;
	form.submit();
}
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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function obrirFoto(titol,foto,alcada,amplada,esquerra,superior) { 
  myWin= open("", "", "width="+amplada+",height="+alcada+",left="+esquerra+",top="+superior);

  // open document for further output
  myWin.document.open();
  
  // create document
  myWin.document.write("<html><head><title>" + titol + "</title>");
  myWin.document.write("<style type='text/css'><!-- .fondogaleria { background-image: url(" + foto + ");	background-repeat: no-repeat;}</style>");
  myWin.document.write("<style type='text/css'><!-- a:link, a:visited, a:hover { color: #000000; text-decoration: none; font-weight: bold;} </style>");
  myWin.document.write("<style type='text/css'><!-- a:hover { text-decoration: underline;} </style>");
  myWin.document.write("</head>");
  myWin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'> ");
  myWin.document.write("<table width=" + amplada + " height=" + alcada + " border='0' align='center' class='fondogaleria'>");
  myWin.document.write("<tr> <td height=" + (alcada - 37) + ">&nbsp;</td>");
  myWin.document.write("</tr><tr><td align='left'></td></tr>");
  myWin.document.write("</table>");
  myWin.document.write("</body></html>");

  // close the document - (not the window!)
  myWin.document.close();  
}
function seguent(element)
{
	if (element == 2)
	{
		if (document.forms[0].elements[element].value.length == 2 && document.forms[0].elements[element].value != 34)
			document.forms[0].elements[element + 1].focus();
	}
	else if (document.forms[0].elements[element].value.length == 3)
			document.forms[0].elements[element + 1].focus();
}
function go2(form,url) 
{	
	form.action = url + "?idFamilia=" + form.families.options[form.families.selectedIndex].value;
	form.submit();
}
function go_catala2(form,url) 
{	
	form.action = url + "?idFamilia=" + form.families.options[form.families.selectedIndex].value + "&lang=ca";
	form.submit();
}