/*******************************************************************************************************/
function isRequiredRadioButtonInformByName(oField, oId) {
	if (oField.length==null || isNaN(parseFloat(oField.length))) {	
		if (!oField.checked) {	
			document.getElementById(oId).style.display='block';
		}		
		return oField.checked;	
	}
	else {	
		for(var i=0;i<oField.length;i++){
			if (oField[i].checked == true) return true;	
		}		
		document.getElementById(oId).style.display='block';
		return false;
	}
}
/*******************************************************************************************************/
function isRequiredRadioButtonAlert(oField, sFieldName, bAlert) {
	var bRes = false;
	if (oField.length==null || isNaN(parseFloat(oField.length))) {
		bRes = oField.checked;		
		if (!bRes && bAlert!=false) {	
			alert("ATENCIÓ:\nHauries d'omplir l'opció de " + sFieldName + ".");
		}				
	}
	else {
		for (var i=0;i<oField.length;i++) {  
			if (oField[i].checked == true) {
				bRes = true;
			}
		}
		if (!bRes && bAlert!=false) {
			alert("ATENCIÓ:\nHauries d'omplir alguna de les opcions de " + sFieldName + ".");
		}
	}
	return bRes;
}
/*******************************************************************************************************/
function isRequiredFieldEmptyById(oField, className){
	if (document.getElementById(oField).value == ""){
		missatge = "Aquest camp és obligatori";
		document.getElementById(oField).className = className;
		document.getElementById(oField).value = missatge;
		return true;
	}
	return false;
}
/*******************************************************************************************************/
function differentEmails(oField1, oField2, className){
	if ((document.getElementById(oField1).value != "") && (document.getElementById(oField2).value != "")){
		if (document.getElementById(oField1).value != document.getElementById(oField2).value ){ 
			missatge = "Els correus electrònics no coincideixen. Torna-ho a provar";
			document.getElementById(oField2).className = className;
			document.getElementById(oField2).value = missatge;
			return true;
		}
	}
	return false;
}
/*******************************************************************************************************/
function isItemSelected(oField,oId){
	if(document.getElementById(oField).value == "0"){
		document.getElementById(oId).style.display='block';
		return false
	}
	return true;
}
/*******************************************************************************************************/
function isRequiredOptionEmptyById(oField,oId){
	var i=0;
	if (document.getElementById(oField1).selectedIndex<=0){
		document.getElementById(oId).style.display='block';
		return true;
	}
	return false;
}

/*******************************************************************************************************/
/*function isValidLength(oField, sFieldName, iMinLength, iMaxLength){
	if ((oField.value.length < iMinLength) || (oField.value.length > iMaxLength)) {
		alert("ATENCIÓ:\nEl camp "+ sFieldName +" ha de ser un valor entre "+iMinLength+" i "+iMaxLength+" caracters.");
		oField.focus();
		return false;		
	}
	return true;
}
*/
/*******************************************************************************************************/
/*function isValidContent(oField,sFieldName){
	var aSpChars = ["/","\\",":","*","?","\"","<",">","|","&"," ","'","á","à","é","è","í","ì","ó","ò","ú","ù","ä","ë","ï","ö","ü","â","ê","î","ô","û"];
	var iIdx = 0;
	var sField = new String(oField.value);	
	sField = sField.toLowerCase();	
	for (iIdx;iIdx<aSpChars.length;iIdx++){		
		if (sField.indexOf(aSpChars[iIdx]) != -1){ 
			alert("ATENCIÓ:\nEl " + sFieldName + " no pot contenir cap dels següents caràcters:\n" + "/ \\ : * ? \" < > | & \' ,  caràcters accentuats i  inclós l\'espai en blanc ");	
			oField.focus();
			return false;						
		}
	}				
	return true;
}
*/
/**************************************************************************************************************/
/*function isValidContentNumbers(oField,sFieldName) {
	sAlert = "ATENCIÓ:\nEl " + sFieldName + " nomes pot contenir numeros.";
	if (isNaN(oField.value)) {
		alert(sAlert);
		return false;
	}
	return true;
}
*/
/*******************************************************************************************************/
/*function validate_date(date) {
	
	var mesos = new Array(31,29,31,30,31,30,31,31,30,31,30,31)

	var in_date = stripCharString(date," ");
    	in_date = in_date.toUpperCase();
    	var date_is_bad = 0;
    	
        if (!allowInString(in_date,"/0123456789")) {
        	date_is_bad = 1;
        	return false
        }
         
        if (!date_is_bad)  {
            var date_pieces = new Array();
            date_pieces = in_date.split("/");
            if (date_pieces.length == 2) {
                var d = new Date();
                in_date = in_date + "/" + get_full_year(d);
                date_pieces = in_date.split("/");
           }
            
        	if ( date_pieces.length != 3 || date_pieces[0]==null || date_pieces[0].length > 2 || date_pieces[0].length < 1 || 
        	    date_pieces[1]==null || date_pieces[1].length > 2 || date_pieces[1].length < 1 || parseInt(date_pieces[1],10) < 1 || parseInt(date_pieces[1],10) > 12 ||
        	    date_pieces[2]==null || date_pieces[2].length > 4 || date_pieces[2].length < 4 || parseInt(date_pieces[2]) < 1900) {
        	    return false
        	}

        		var mes = parseInt(date_pieces[1],10)
        		if ((parseInt(date_pieces[0],10) < 1 || parseInt(date_pieces[0],10) > mesos[mes-1])){        		
        			return false
        		} if (mes == 2) { 
        			if ( (Math.abs(parseInt(date_pieces[2]) - 2000)%4 != 0) && (parseInt(date_pieces[0]) > 28)) {
        				return false
        			}
        		}

        }
        
    return true;
}
*/
/*******************************************************************************************************/
/*function get_full_year(d) {
    var y = d.getYear();

    if (y > 69  && y < 100) y += 1900;
    if (y < 1000) y += 2000;
    return y;
}
*/
/*******************************************************************************************************/
/*function stripCharString (InString, CharString)  {
	var OutString="";
	
	for (var Count=0; Count < InString.length; Count++)  {
      var TempChar=InString.substring (Count, Count+1);
      var Strip = false;
      for (var Countx = 0; Countx < CharString.length; Countx++) {
        var StripThis = CharString.substring(Countx, Countx+1)
         if (TempChar == StripThis) {
                Strip = true;
            break;
         }
      }
      if (!Strip)
        OutString=OutString+TempChar;
	}
    return (OutString);
}
*/
/*******************************************************************************************************/
/*function allowInString (InString, RefString)
{
	if(InString.length==0) return (false);

	for (var Count=0; Count < InString.length; Count++)  {
		var TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
        	return (false);
   	}
   	
	return true	
}
*/
/*******************************************************************************************************/
/*function mostrar_data()
{
  var data='';

  mes = new Array();
  dia = new Array();
  mes[0]="gener";
  mes[1]="febrer";
  mes[2]="marc,";
  mes[3]="abril";
  mes[4]="maig";
  mes[5]="juny";
  mes[6]="juliol";
  mes[7]="agost";
  mes[8]="setembre";
  mes[9]="octubre";
  mes[10]="novembre";
  mes[11]="desembre";

  dia[0]="Diumenge";
  dia[1]="Dilluns";
  dia[2]="Dimarts";
  dia[3]="Dimecres";
  dia[4]="Dijous";
  dia[5]="Divendres";
  dia[6]="Dissabte";


  today=new Date();

  data=dia[today.getDay()]+', '+today.getDate();
  if (((today.getMonth())==3)||((today.getMonth())==7)||((today.getMonth())==9)) data=data+' d\'';
	else data=data+' de ';
	data=data+mes[today.getMonth()]+' de ';
	data = data+'2002';
	document.write(data);	
}*/
/*******************************************************************************************************/
/*function centerWindow(oWindow,iWidth,iHeight) {
	//% de offset que se aplica en caso que el width y el height no vengan informados
	if (iWidth==null) iWidth=(9*screen.width)/10;
	if (iHeight==null) iHeight=(9*screen.height)/10;
		
	//Factor de correcion aplicado a la formula de centrado dado que con MS IE no funciona sin el +40 y +12. La ventana
	//acaba de centrarse completamente :)
	//Si se desea hacer para NetScape tmb se tendra que aplicar un FC. 
	iWinTop=(screen.height - (iHeight+40))/2;
	iWinLeft=(screen.width - (iWidth+12))/2;
	newWin.moveTo(iWinLeft,iWinTop);

}*/
/*******************************************************************************************************/
function isValidMailById(oField, className){

	var patMail = /^(.+)@(.+)$/; // Define la expresion regular para verificar si el email tiene el formato usuario@dominio
	
	var patUser = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)*$/; // Define la expresion regular para nombres de usuario validos
	
 	var patDomain = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)+$/; // Define la expresion regular para nombres de dominio validos

 	// Verifica que el string que recibe la funcion sea del tipo string@string y separa los substring correspondientes a usuario y dominio
  	var matchArray = document.getElementById(oField).value.match(patMail);
  	if(matchArray == null && document.getElementById(oField).value != ""){
  		mailNoValid(oField, className);
   		return false;
  	}else{
  		if (document.getElementById(oField).value != ""){
			var user = new String(matchArray[1]);
		  	var domain = new String(matchArray[2]);
	
			// Si el nombre de usuario no es valido la funcion devuelve falso
			if(user.match(patUser) == null) {
				mailNoValid(oField, className);
				return false;
			}else{
	 			// Verifica que el string de dominio sea valido.Si es valido verifica que la ultima extension tenga 3 o 4 caracteres de longitud (2 o 3 caracteres mas el punto)
	 			var domainArray = domain.match(patDomain);
			  	if(domainArray == null){
			  		mailNoValid(oField, className);
			   		return false;
			  	}
	  		}
	  	}
  	}
  return true;
}

function mailNoValid (oField, className){
	
	missatge = "Escriu una adreça de correu vàlida"
	document.getElementById(oField).className = className;
	document.getElementById(oField).value = missatge;
	
}
/*******************************************************************************************************/
/*function isValidContent3XL(oField,sFieldName){
	
	sAlert = "ATENCIÓ:\nEl " + sFieldName + " no pot contenir caracters especials."
	
	var patCont = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)*$/; // Define la expresion regular para los passwords validos
	
	var matchArray = oField.value.match(patCont);
  	
  	if(matchArray == null && oField.value != ""){
   		alert(sAlert);
   		return false;
   	}
   	
   	return true;
}
*/

/********************* mirem si l'username i el password són diferents *********************************/
/*function isUserDifFromPwd(oField1,oField2,oText) {
	if (oField1.value == oField2.value) {
		alert("ATENCIÓ:\n" + oText);
		return true;
	}	
	return false;
}*/
/*******************************************************************************************************/
/*function vali_date(date) {
	var mesos = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	var datePattern = /^([1-9]|0[1-9]|[12][0-9]|3[01])\/([1-9]|0[1-9]|1[012])\/([1-9][0-9][0-9][0-9]|[0-9][1-9][0-9][0-9]|[0-9][0-9][1-9][0-9]|[0-9][0-9][0-9][1-9])$/;
	
	if(date.match(datePattern) && date!=null && date.value!="") {
		var birth_date = new Array();
		birth_date = date.split("/");
  		var mes = parseInt(birth_date[1],10);
	    if ((parseInt(birth_date[0],10)<1 || parseInt(birth_date[0],10)>mesos[mes-1])) {
	    	alert("El camp 'Data de Naixement' conté un valor incorrecte. El format correcte és dd/mm/aaaa.");
	    	return false;
	    }
	    if (mes==2) {
	    	if ((Math.abs(parseInt(birth_date[2])-2000)%4 != 0) && (parseInt(birth_date[0])>28)) {
	    		alert("El camp Data naixement conté un valor incorrecte.\nEl format correcte és dd/mm/aaaa.");
	    		return false;
        	}
        }
  	} else {
  		alert("El camp 'Data de Naixement' conté un valor incorrecte. El format correcte és dd/mm/aaaa.");
   		return false;
   	}
	
	// comprovacions de l'edat de l'usuari
	var dateTmp = new Date();
	var sys_date = new Array();
	sys_date[0]=dateTmp.getDate();
	sys_date[1]=dateTmp.getMonth()+1; // els mesos van de 0 a 11
	sys_date[2]=dateTmp.getFullYear();
	
	var yearDif=sys_date[2]-birth_date[2];
	
	if((yearDif>1)&&(yearDif<110)) { // comprovem l'any
		return true;
	} else if((yearDif<1)||(yearDif>110)||(yearDif==0)) {
		alert("La data de naixement no és vàlida.");
		return false;
	} else { // =1 || = 110
		if((sys_date[1]>birth_date[1] && yearDif==1)||(sys_date[1]<birth_date[1] && yearDif==110)) { // comprovem el mes
        	return true;
        } else if(sys_date[1]<birth_date[1]) {
        	alert("La data de naixement no és vàlida.");
        	return false;
        } else {
        	if((sys_date[0]>=birth_date[0] && yearDif==1)||(sys_date[0]<=birth_date[0] && yearDif==110)) { // comprovem el dia
        		return true;
        	} else {
        		alert("La data de naixement no és vàlida.");
        		return false;
        	}
        }
	}
    return true;
}*/
/*******************************************************************************************************/
/*function isEmptyField(oField){
	if (oField.value == ""){
		oField.focus();
		return true;
	}
	return false;
}*/
/*******************************************************************************************************/
/*function isValidNIF(oField,sFieldName) {
  // Validador de NIFs
  var ok = true;
  var nif = oField.value;
  nif = nif.toUpperCase();
  //comprobacion de longitud del nif
  if (nif.length != 9){ 
      alert("ATENCIÓ:\nEl camp " + sFieldName + " ha de tenir 9 dígits.\n(Ompli amb ceros per l'esquerra si és necessari)");
      oField.focus();
      return false;
  }
  //comprobamos si el primer caracter es una letra o un numero.
  //si es letra y es k, l, m o x, sera un nie y se realizara el proceso de comprobacion quitando dicho caracter. Si no, sera incorrecto.
  primerDig = nif.substr(0);
   if (!/^[0123456789]/.test(primerDig)){
    if (!/^[KLMX]/.test(primerDig)){
       alert("ATENCIÓ:\nEl camp " + sFieldName + " és incorrecte");
       oField.focus();
       return false;
    }else{
       nif = nif.substr(1,nif.length-1);
    }
  }
  dni=nif.substr(0,nif.length-1);
  letra=nif.charAt(nif.length-1);
  letraCorrecta = calculoLetraNIF(dni);
  //comprobacion del digito control. primero miramos si es una letra.
  if (/^[0123456789]/.test(letra)){
       alert("ATENCIÓ:\nEl darrer dígit del camp " + sFieldName + " ha de ser una lletra");
       oField.focus();
       return false;
  //luego si se corresponde con la calculada
  }else if (letra!=letraCorrecta) {
       alert("ATENCIÓ:\nLa lletra del " + sFieldName + " és incorrecta");
       oField.focus();
       return false;
  }

  oField.value= dni + letra;
  return true;
}
*/
/*******************************************************************************************************/

/*function calculoLetraNIF(DNI){
  // Función auxiliar utilizada por ValidaNIF
  var baremo;
  var letraNIF, letras = "TRWAGMYFPDXBNJZSQVHLCKET";
  baremo = DNI % 23; // equivale a DNI-23*(DNI/23)
  letraNIF = letras.charAt(baremo);
  return letraNIF;
}*/
/*******************************************************************************************************/

/*function isValidCIF(oField,sFieldName) {
	// Función para validar los CIFs
	var resul = true;
	var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	var temp = 0;
	var elCIF = oField.value;
	var digControl = elCIF.substr(8);
	var v2 = new Array("J","A","B","C","D","E","F","G","H","I");
	var upCIF = elCIF.toUpperCase(); // pasar a mayúsculas
	if (!/^[A-Za-z0-9]{9}$/.test(upCIF)){ // Son 9 dígitos? 
		alert("ATENCIÓ:\nEl camp " + sFieldName + " ha de tenir 9 dígits.\n");
		oField.focus();
		return false;
	}else if (!/^[ABCDEFGHKLMNPQS]/.test(upCIF)) {// Es una letra de las admitidas ?
	        alert("ATENCIÓ:\nLa lletra del " + sFieldName + " és incorrecta");
		oField.focus();
		return false;
	}
	// dígito de control.
	for( i = 2; i <= 6; i += 2 ){
		temp = temp + v1[ parseInt(upCIF.substr(i-1,1)) ];
		temp = temp + parseInt(upCIF.substr(i,1));
	}
	temp = temp + v1[ parseInt(upCIF.substr(7,1)) ];
	temp = (10 - ( temp % 10));
	if (temp == 10 )	  temp = 0;
	else if (!/^[0123456789]/.test(digControl)){
	  temp = v2[temp];
	  if (temp != digControl){
	        alert("ATENCIÓ:\nEl camp " + sFieldName + " és incorrecte");
	  	oField.focus();
	  	return false;
	  }
	}else if (temp != digControl){
          alert("ATENCIÓ:\nEl camp " + sFieldName + " és incorrecte");
	  oField.focus();
	  return false;
	}
	return true;
}
*/
/*******************************************************************************************************/
/*
function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
*/
/*
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
*/
/*
function chkCookies() {
	SetCookie ("CHK_COOKIE", "OK");
	var sCookieValue = GetCookie ("CHK_COOKIE");
	if (sCookieValue==null) {
		alert('Per accedir a aquest servei has de tenir les "cookies" del teu ordinador activades.');
	} else {
		//alert("Cookies " + sCookieValue);
	}
}

chkCookies();
*/
/*

function isEmailValid(checkThisEmail) {
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myAtSymbolAt2 = checkThisEmail.indexOf('@', ((myAtSymbolAt<0) ? 0 : myAtSymbolAt+1));
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;
	if (myAtSymbolAt < 1 )  myEMailIsValid = false;
	if (myAtSymbolAt2 > 0 && (myAtSymbolAt2>myAtSymbolAt)) myEMailIsValid = false;
	if (myLastDotAt < myAtSymbolAt) myEMailIsValid = false;
	if (myLength - myLastDotAt <= 2) myEMailIsValid = false;
	if (mySpaceAt != -1) myEMailIsValid = false;
	return myEMailIsValid;
}
*/

