//------------- variables globals del retard
	var inicio=5;
	var tmp;


function menorE(obj) 
{

	if (document.frmSolicitaTP.neix.value=="")
	{
	return false
	}
		
	var fechaActual = new Date();
		
 	if (obj=="1")
 		{
  		var fecha2000 = new Date(document.frmSolicitaTP.neix.value);
		}

	if (obj=="2")
		{
  		var fecha2000 = new Date(document.frmSolicitaTP.tneix.value);
		}

  		var tiempoRestante =  fechaActual.getTime()-fecha2000.getTime();
  		var dias = Math.floor(tiempoRestante / (1000 * 60 * 60 * 24*365));
		
		
		if (obj=="1")
		{
			
			if (dias<4)
			{
			posaError("neix","No tienes la edad suficiente para asociarte!")
			//alert ("No tienes la edad legal!")
			document.frmSolicitaTP.neix.value=""
			document.getElementById ("neix").style.background="transparent"
			return false
			}
			
			
			if (dias<18)
			{
			document.getElementById ("tutor").style.display="block"
			document.getElementById ("tutor").style.opacity="1"
			document.getElementById ("tutor").style.filter ="alpha(opacity=100)"
			
			document.frmSolicitaTP.tnom.disabled=false;
			document.frmSolicitaTP.tcognom1.disabled=false;
			document.frmSolicitaTP.tcognom2.disabled=false;
			document.frmSolicitaTP.tadreca.disabled=false;
			document.frmSolicitaTP.tpoblacion.disabled=false;
			document.frmSolicitaTP.tprovincia.disabled=false;
			document.frmSolicitaTP.tCP.disabled=false;
			document.frmSolicitaTP.tDNI.disabled=false;
			document.frmSolicitaTP.ttelefon.disabled=false;
			document.frmSolicitaTP.temail.disabled=false;
			document.frmSolicitaTP.menor.value="SI"
			}  		
  			else
  			{
			document.getElementById ("tutor").style.display="none"
			document.getElementById ("tutor").style.opacity=".3"
			document.getElementById ("tutor").style.filter ="alpha(opacity=30)"

			document.frmSolicitaTP.tnom.disabled=true;
			document.frmSolicitaTP.tcognom1.disabled=true;
			document.frmSolicitaTP.tcognom2.disabled=true;
			document.frmSolicitaTP.tadreca.disabled=true;
			document.frmSolicitaTP.tpoblacion.disabled=true;
			document.frmSolicitaTP.tprovincia.disabled=true;
			document.frmSolicitaTP.tCP.disabled=true;
			document.frmSolicitaTP.tDNI.disabled=true;
			document.frmSolicitaTP.ttelefon.disabled=true;
			document.frmSolicitaTP.temail.disabled=true;
			document.frmSolicitaTP.menor.value="NO"
  			}
  		}


		if (obj=="2")
		{
		if (dias<18) 
			{
			//alert ("el tutor no puede ser menor de edad!")
			posaError("tneix","El tutor no puede ser menor de edad!")
			//alert ("No tienes la edad legal!")
			document.frmSolicitaTP.tneix.value=""
			document.getElementById ("tneix").style.background="transparent"
			return false

			return false
			}
		}


}





//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------

// -------------------- la madre del cordero! aqui processem les dades del form
function procesaF()
{

	if (document.frmSolicitaTP.nom.value=="") {
		posaError('nom','no está completado!')
		return false
		} 

	if (document.frmSolicitaTP.cognom1.value=="") {
		posaError('cognom1','no está completado!')
		return false
		} 
	
	if (document.frmSolicitaTP.cognom2.value=="") {
		posaError('cognom2','no está completado!')
		return false
		} 
	

	if (document.frmSolicitaTP.adreca.value=="") {
		posaError('adreca','no está completado!')
		return false
		} 

	if (document.frmSolicitaTP.poblacion.value=="") {
		posaError('poblacion','no está completado!')
		return false
		} 

	if (document.frmSolicitaTP.provincia.value=="") {
		posaError('provincia','no está completado!')
		return false
		} 

	if (document.frmSolicitaTP.CP.value=="") {
		posaError('CP','no está completado!')
		return false
		} 

	/*if (document.frmSolicitaTP.DNI.value=="") {
		posaError('DNI','no está completado!')
		return false
		} 
	*/


	/*if (document.frmSolicitaTP.telefon.value=="") {
		posaError('telefon',0)
		return false
		} 
	*/


	if (document.frmSolicitaTP.neix.value=="") {
		posaError('neix','no está completado!')
		return false
		} 


	//------------------- comproba len CP

	if ((document.getElementById ("CP").value.length)<5) 
		{
		posaError("CP","debe tener 5 digitos!")
		document.frmSolicitaTP.CP.value="";return false;
		}


	//----------------- comproba len DNI
	if (document.frmSolicitaTP.menor.value=="NO")
	{
		if ((document.getElementById ("DNI").value.length)<6) 
		{
		posaError("DNI","debe tener al menos 6 digitos,ceros incluidos a la izquierda si los tiene!")
		document.frmSolicitaTP.DNI.value="";return false;
		}
		else
		{
		//---Res
		}
	}


	//------------------------------ i ara fel lo propi si es menor		
	if (document.frmSolicitaTP.menor.value=="SI") 
	{

		if (document.frmSolicitaTP.tnom.value=="") {
			posaError('tnom','no está completado!')
			return false
			} 
	
		if (document.frmSolicitaTP.tcognom1.value=="") {
			posaError('tcognom1','no está completado!')
			return false
			} 
	
		if (document.frmSolicitaTP.tcognom2.value=="") {
			posaError('tcognom2','no está completado!')
			return false
			} 
	

		if (document.frmSolicitaTP.tadreca.value=="") {
			posaError('tadreca','no está completado!')
			return false
			} 

		if (document.frmSolicitaTP.tpoblacion.value=="") {
			posaError('tpoblacion','no está completado!')
			return false
			} 

		if (document.frmSolicitaTP.tprovincia.value=="") {
			posaError('tprovincia','no está completado!')
			return false
			} 

		if (document.frmSolicitaTP.tCP.value=="") {
			posaError('tCP','no está completado!')
			return false
			} 

		if (document.frmSolicitaTP.tDNI.value=="") {
			posaError('tDNI','no está completado!')
			return false
			} 


		/*if (document.frmSolicitaTP.ttelefon.value=="") {
			posaError('ttelefon',385)
			return false
			} 
		*/



		if (document.frmSolicitaTP.tneix.value=="") {
			posaError('tneix','no está completado!')
			return false
			} 

		//----------------------- comprobem LEN DNI i CP
		
		if ((document.getElementById ("tCP").value.length)<5) 
			{
			posaError("tCP","debe tener 5 digitos!")
			document.frmSolicitaTP.tCP.value="";return false;
			}


		//----------------- comproba len DNI
		if ((document.getElementById ("tDNI").value.length)<6) 
			{
			posaError("tDNI","debe tener al menos 6 digitos, ceros incluidos a la izquierda si los tiene")
			document.frmSolicitaTP.tDNI.value="";return false;
			}

		//---------------- finalment posem lletras DNI dels camps individuals	
		document.frmSolicitaTP.tDNI.value=document.frmSolicitaTP.tDNI.value + document.frmSolicitaTP.tlDNI.value 
		if (document.frmSolicitaTP.txTra.value=="")
		{/*res*/}
		else
		{document.frmSolicitaTP.tDNI.value=document.frmSolicitaTP.txTra.value + document.frmSolicitaTP.tDNI.value}

	}
	
	
	//---------------- finalment posem lletras DNI dels camps individuals	
	document.frmSolicitaTP.DNI.value=document.frmSolicitaTP.DNI.value + document.frmSolicitaTP.lDNI.value 
	if (document.frmSolicitaTP.xTra.value=="")
	{/*res*/}
	else
	{document.frmSolicitaTP.DNI.value=document.frmSolicitaTP.xTra.value + document.frmSolicitaTP.DNI.value}
	//----------------- FII! enviem formulari!  						                                  			
		
	
	document.frmSolicitaTP.submit ()
	//alert ("tot OK! " + document.frmSolicitaTP.DNI.value + " " +document.frmSolicitaTP.tDNI.value);
}	

//---------------------------------------------------------------------------------------------------------------------------
//--------Agafat-----------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
function treuError(obj) {
	
	document.getElementById (obj).style.background="transparent"		

return false;
}


//----------------------------------------------------------------------------

function posaError(obj,tS)
{
	inicio=5;
	dias=tS;
	
	if (document.all)
	{
	document.getElementById ("contingut").style.filter ="alpha(opacity=18)"
	document.getElementById ("menu").style.filter ="alpha(opacity=18)"
	document.getElementById ("errorss").style.filter ="alpha(opacity=100)"
	}
	else
	{document.getElementById ("contingut").style.opacity= 0.18;
	document.getElementById ("errorss").style.opacity= 1;
	}

//---------- averigua valors width hieght utils de la finestra
//function alertSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
  	}
  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
  	}
  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
  	}
  	//window.alert( 'Width = ' + myWidth );
  	//window.alert( 'Height = ' + myHeight + ' ' +myHeight/2 );
	//}
//************************************************************
		
	st2=String(100+(myHeight /2))+"px;"

	//alert (st2 + " " + myHeight);
	
	st2=document.getElementById ("pagina").offsetHeight;
	//alert (st2)

	//-------------hem de deshabilitar TOTS els controls del form!!!
	document.frmSolicitaTP.nom.disabled =true;
	document.frmSolicitaTP.cognom1.disabled =true;
	document.frmSolicitaTP.cognom2.disabled =true;
	document.frmSolicitaTP.adreca.disabled =true;
	document.frmSolicitaTP.poblacion.disabled =true;
	document.frmSolicitaTP.provincia.disabled =true;
	document.frmSolicitaTP.CP.disabled =true;
	document.frmSolicitaTP.neix.disabled =true;
	document.frmSolicitaTP.DNI.disabled =true;
	document.frmSolicitaTP.telefon.disabled =true;
	document.frmSolicitaTP.enviaF.disabled =true;
	document.frmSolicitaTP.capCombo.disabled =true;


	//---------- ah! i els del tutor clar! ... si es menor
	if (document.frmSolicitaTP.menor.value=="SI") 
	{
		document.frmSolicitaTP.tnom.disabled =true;
		document.frmSolicitaTP.tcognom1.disabled =true;
		document.frmSolicitaTP.tcognom2.disabled =true;
		document.frmSolicitaTP.tadreca.disabled =true;
		document.frmSolicitaTP.tpoblacion.disabled =true;
		document.frmSolicitaTP.tprovincia.disabled =true;
		document.frmSolicitaTP.tCP.disabled =true;
		document.frmSolicitaTP.tneix.disabled =true;
		document.frmSolicitaTP.tDNI.disabled =true;
		document.frmSolicitaTP.ttelefon.disabled =true;
		document.frmSolicitaTP.capCombo.disabled =true;
	}
	//*------------ tots deshabilitats	
	
	
	document.getElementById ("errorss").style.visibility ="visible";
	document.getElementById ("errorss").style.top=((myHeight/2)-110) +'px';
	


	if (obj == "nom") {tS = "nombre"}
	if (obj == "cognom1") {tS = "Primer apellido"}
	if (obj == "cognom2") {tS = "Segundo apellido"}
	if (obj == "adreca") {tS = "Dirección"}
	if (obj == "CP") {tS = "Código postal"}
	if (obj == "neix") {tS = "Fecha nacimiento"}
	if (obj == "poblacion") {tS = "Población"}
	if (obj == "provincia") {tS = "Provincia"}
	if (obj == "DNI") {tS = "DNI"}


	if (obj == "tnom") {tS = "Nombre del tutor"}
	if (obj == "tcognom1") {tS = "Primer apellido del tutor"}
	if (obj == "tcognom2") {tS = "Segundo apellido del tutor"}
	if (obj == "tadreca") {tS = "Dirección del tutor"}
	if (obj == "tCP") {tS = "Código postal del tutor"}
	if (obj == "tneix") {tS = "Fecha nacimiento del tutor"}
	if (obj == "tpoblacion") {tS = "Población del tutor"}
	if (obj == "tprovincia") {tS = "Provincia del tutor"}
	if (obj == "tDNI") {tS = "DNI del tutor"}

	
	document.getElementById ("errorrss").innerHTML =tS;	
	document.getElementById ("merror").innerHTML =dias;	
	

	tmp=setInterval("contar('"+obj+"')",1000)
 	}


//--------------------------------------------------------------------------------------------------------------------------

	function contar(obj) {
  		inicio--;
  		document.getElementById('espe').innerHTML ="espera "+ inicio +" segundos ...";
  		if (inicio<=0) {
    		clearInterval(tmp);
				if (document.all)
					{
					document.getElementById ("contingut").style.filter ="alpha(opacity=100)"
					document.getElementById ("menu").style.filter ="alpha(opacity=100)"
					document.getElementById ("errorss").style.filter ="alpha(opacity=100)"
					}
				else
					{
					document.getElementById ("contingut").style.opacity= 1;
					document.getElementById ("errorss").style.opacity= 1;
					}

				document.getElementById ("errorss").style.visibility ="hidden"

				//-------------hem de tornar a habilitar TOTS els controls del form!!!
				document.frmSolicitaTP.nom.disabled =false;
				document.frmSolicitaTP.cognom1.disabled =false;
				document.frmSolicitaTP.cognom2.disabled =false;
				document.frmSolicitaTP.adreca.disabled =false;
				document.frmSolicitaTP.poblacion.disabled =false;
				document.frmSolicitaTP.provincia.disabled =false;
				document.frmSolicitaTP.CP.disabled =false;
				document.frmSolicitaTP.neix.disabled =false;
				document.frmSolicitaTP.DNI.disabled =false;
				document.frmSolicitaTP.telefon.disabled =false;
				document.frmSolicitaTP.enviaF.disabled =false;
				document.frmSolicitaTP.capCombo.disabled =false;
				
					//---------- ah! i els del tutor clar! ... si es menor
				if (document.frmSolicitaTP.menor.value=="SI") 
					{
					document.frmSolicitaTP.tnom.disabled =false;
					document.frmSolicitaTP.tcognom1.disabled =false;
					document.frmSolicitaTP.tcognom2.disabled =false;
					document.frmSolicitaTP.tadreca.disabled =false;
					document.frmSolicitaTP.tpoblacion.disabled =false;
					document.frmSolicitaTP.tprovincia.disabled =false;
					document.frmSolicitaTP.tCP.disabled =false;
					document.frmSolicitaTP.tneix.disabled =false;
					document.frmSolicitaTP.tDNI.disabled =false;
					document.frmSolicitaTP.ttelefon.disabled =false;
					document.frmSolicitaTP.capCombo.disabled =false;
					}

				//*------------ tots habilitats	

				document.getElementById (obj).focus();
				document.getElementById (obj).style.background="#ffff00"
		  		document.getElementById('espe').innerHTML = "espera 5 segundos ...";

		}

	}

//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------










//----------------------------------------------------------------------------------

function posaXtra(obj) 
{
	if (obj=='1')
	{
		if (document.frmSolicitaTP.xTra.value=="")
		{document.frmSolicitaTP.xTra.value="X";document.frmSolicitaTP.xTra.blur();return}

		if (document.frmSolicitaTP.xTra.value=="X")
		{document.frmSolicitaTP.xTra.value="";document.frmSolicitaTP.xTra.blur();return}
	}

//---------------------- i ara per el tutor

	if (obj=='2')
	{
		if (document.frmSolicitaTP.txTra.value=="")
		{document.frmSolicitaTP.txTra.value="X";document.frmSolicitaTP.txTra.blur();return}

		if (document.frmSolicitaTP.txTra.value=="X")
		{document.frmSolicitaTP.txTra.value="";document.frmSolicitaTP.txTra.blur();return}
	}


}



//-----------------------------------------------------------------------------------Posem Dni
function posaDNI()
{

	strDNI="TRWAGMYFPDXBNJZSQVHLCKET" 

 
 
	if ( (document.getElementById ("DNI").value.length)<6 )
		{
		document.frmSolicitaTP.lDNI.value=""
		document.frmSolicitaTP.xTra.value=""
		return false;
		}
		else
		{
		posicio = document.frmSolicitaTP.DNI.value % 23 
		lletra = strDNI.substring(posicio,posicio+1) 
		document.frmSolicitaTP.lDNI.value=lletra
		}
}			

//-------------------------- ara al tutor
function posatDNI()
{

	strDNI="TRWAGMYFPDXBNJZSQVHLCKET" 

 
 
	if ( (document.getElementById ("tDNI").value.length)<6 )
		{
		document.frmSolicitaTP.tlDNI.value=""
		document.frmSolicitaTP.txTra.value=""
		return false;
		}
		else
		{
		posicio = document.frmSolicitaTP.tDNI.value % 23 
		lletra = strDNI.substring(posicio,posicio+1) 
		document.frmSolicitaTP.tlDNI.value=lletra
		}
}			

//................................................. comproba que nomes siguin nums
//................ aquest si que va amb tots els browsers	

function esNumero(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;
	
	return true;
}

//------------------------------------------------------- mateixa adreca afilat que tutor

function posaMateix()
{

	if (document.frmSolicitaTP.mateix.value=="")
	{
	document.getElementById ("mateix").style.backgroundImage = "url(grafics/OK.gif)";
	document.frmSolicitaTP.tadreca.value=document.frmSolicitaTP.adreca.value
	document.frmSolicitaTP.tpoblacion.value=document.frmSolicitaTP.poblacion.value
	document.frmSolicitaTP.tprovincia.value=document.frmSolicitaTP.provincia.value
	document.frmSolicitaTP.tCP.value=document.frmSolicitaTP.CP.value
	document.frmSolicitaTP.ttelefon.value=document.frmSolicitaTP.telefon.value
	document.frmSolicitaTP.mateix.value="OK"
	return true
	}

	if (document.frmSolicitaTP.mateix.value=="OK")
	{
	document.getElementById ("mateix").style.backgroundImage = "url(grafics/OK2.gif)";
	document.frmSolicitaTP.tadreca.value=""
	document.frmSolicitaTP.tpoblacion.value=""
	document.frmSolicitaTP.tprovincia.value=""
	document.frmSolicitaTP.tCP.value=""
	document.frmSolicitaTP.ttelefon.value=""
	document.frmSolicitaTP.mateix.value=""
	return true
	}



}


//---------------------------------------------------------
 function treuDivError() 
 {
 inicio=-1;
 }





























