function acceptNum(evt){ 
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
	var key = nav4 ? evt.which : evt.keyCode; 
	return (key <= 13 || key == 46 || (key >= 48 && key <= 57));
}

function acceptNumComa(evt){ 
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
	var key = nav4 ? evt.which : evt.keyCode; 
	return (key <= 13 || key == 44 || (key >= 48 && key <= 57));
}

function acceptMay(evt){ 
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
	var key = nav4 ? evt.which : evt.keyCode;
	//alert (key);
	if (key <= 13 || (key >= 97 && key <= 122))
	  return evt.keyCode = key-32;
}

function acceptCass(evt){ 
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
	var key = nav4 ? evt.which : evt.keyCode;
	if (document.f1.numcass.value.length < 6)
	{
		// solo acepto numeros
		return (key <= 13 || (key >= 48 && key <= 57));
	}
	else
	{
		// solo acepto letras
  	if (key <= 13 || (key >= 97 && key <= 122))
  	  return evt.keyCode = key-32;
  	else return false;
	}
}

function cambio(d,v,f)
{
  if (d.options[d.selectedIndex].value == v) f.disabled = false;
  else f.disabled = true;
}

function setDisabled(id, disabled)
{
  if ( !document.getElementById
  || !document.getElementsByTagName) return;
  
  var nodesToDisable = {checkbox :'', input :'', span :'', strong : '',
  option :'', select :'', textarea :'', radio :'', text :''};
  
  var node, nodes;
  var div = document.getElementById(id);
  if (!div) return;
  
  nodes = div.getElementsByTagName('*');
  if (!nodes) return;
  
  var i = nodes.length;
  while (i--)
  {
    node = nodes[i];
    if ( node.nodeName
    && node.nodeName.toLowerCase() in nodesToDisable ){
      node.disabled = disabled;
    }
  }
}

function setDisabledT(id, disabled)
{
  if ( !document.getElementById
  || !document.getElementsByTagName) return;
  
  var nodesToDisable = {checkbox :'', input :'', span :'', strong : '',
  option :'', select :'', textarea :''};
  
  var node, nodes;
  var div = document.getElementById(id);
  if (!div) return;
  
  nodes = div.getElementsByTagName('*');
  if (!nodes) return;
  
  var i = nodes.length;
  while (i--)
  {
    node = nodes[i];
    if ( node.nodeName
    && node.nodeName.toLowerCase() in nodesToDisable ){
      if (node.disabled) node.disabled = false
      else node.disabled = true;
    }
  }
}

function enviar()
{
	if (document.f1.apellidos.value == "")
	{
		alert("El camp cognoms és obligatori");
		muestra('t1','content1');
		document.f1.apellidos.focus();
		return false;
	}
	if (document.f1.nombre.value == "")
	{
		alert("El camp nom és obligatori");
		muestra('t1','content1');
		document.f1.nombre.focus();
		return false;
	}
	if (document.f1.fechaacc.value == "")
	{
		alert("El camp data accident és obligatori");
		muestra('t2','content2');
		document.f1.fechaacc.focus();
		return false;
	}
	f_actual = new Date();
	f_acc    = new Date(document.f1.fechaacc.value.substring(6,10),((document.f1.fechaacc.value.substring(3,5)*1)-1),document.f1.fechaacc.value.substring(0,2));
	if (f_acc > f_actual)
	{
		alert("La data del accident no pot ser posterior a la actual");
		muestra('t2','content2');
		document.f1.fechaacc.focus();
		return false;
	}
	if (document.f1.horaacc_h.value == 99 || document.f1.horaacc_m.value == 99)
	{
		alert("El camp hora accident és obligatori");
		muestra('t2','content2');
		document.f1.horaacc_h.focus();
		return false;
	}
	// comprobacion de fechas
	if (document.f1.fechanac.value != "" && !compruebaFechaS(document.f1.fechanac))
	{
		alert("El camp Data naixement no té el format correcte");
		muestra('t1','content1');
		document.f1.fechanac.focus();
		return false;
	}
	if (document.f1.fechaaltaemp.value != "" && !compruebaFechaS(document.f1.fechaaltaemp))
	{
		alert("El camp Data d'alta a l'empresa no té el format correcte");
		muestra('t1','content1');
		document.f1.fechaaltaemp.focus();
		return false;
	}
	if (document.f1.fechaacc.value != "" && !compruebaFechaS(document.f1.fechaacc))
	{
		alert("El camp Data d'accident no té el format correcte");
		muestra('t2','content2');
		document.f1.fechaacc.focus();
		return false;
	}
	if (document.f1.fechabaja.value != "" && !compruebaFechaS(document.f1.fechabaja))
	{
		alert("El camp Data de baixa laboral no té el format correcte");
		muestra('t4','content4');
		document.f1.fechabaja.focus();
		return false;
	}	
	if (document.f1.fechaconocimiento.value != "" && !compruebaFechaS(document.f1.fechaconocimiento))
	{
		alert("El camp Data de coneixement no té el format correcte");
		muestra('t6','content6');
		document.f1.fechaconocimiento.focus();
		return false;
	}	
	return true;
}


function cambia(c)
{
  if (c.value == "1") c.value = "0";
  else c.value = "1";
}

/*
function cambia_idioma(idioma)
{
//  if (idioma == 2) alert("proximament");
//  if (idioma == 3) alert("coming soon");

//	if (document.location.href.match(/\?/))
//		car = "&"
//	else
//		car = "?"
	var url  = "";
	var url1 = "";
	if (parent.document.location.href.match(/\#/))
    url = parent.document.location.href.substring(0,document.location.href.length-1);
  else
    url = parent.document.location.href

  if (url.match(/motor.php\?/))
  {
  	// estamos en una url del tipo motor.php?id_pagina=x
  	// hemos de añadir un parametro solo
		var items = url.split("&")
		if (items[items.length-1].match(/idioma/))
		{
			for (i=0;i<items.length-1;i++) {
				url1 = url1 + items[i] + "&"
			}
			url1 = url1 + "idioma=" + idioma;
			url = url1;
		}
		else
		{
			url = url + "&idioma=" + idioma;
		}
  }
	else if (url.match(/componentes.php/))
	{
	  url = parent.parent.document.location.href;
	  var items = url.split("?")
	  url1 = items[0] & "?ln=" + idioma + "&" + items[1];
	  parent.parent.document.location.href = url1;
	  return;	  
	}
	else
	{
	  // tengo que analizar la url y cambiar el primer elemento
	  // tengo la utl en formato /en/seccion/subseccion
	  var items = url.split("default.aspx");
		for (i=4;i<items.length;i++) {
			url1 = url1 + items[i] + "/"
		}
		if (url1 == "/" || url1 == "") url1 = "home/default.aspx";
	  url = "/" + idioma + "/" + url1.substring(0,url1.length-1);
	}
  parent.document.location.href = url;
}*/

function cambia_idioma(idioma){
	if (idioma=="it"){
		parent.location.href="/it/default.aspx"
	}else if(idioma=="en"){
		parent.location.href="/en/default.aspx"
	}
}
