// JavaScript Document

/** Funcions per la pagina de coordenades de les estacions Catnet**/
var xmlDoc;
var sLang ="";

function loadCoord(langTmp)
{
//set language
if (langTmp == "" || langTmp == null) {
	 sLang="cat";
} else {
  sLang= langTmp;
}

//load xml file
// code for IE
if (window.ActiveXObject)
{
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load("/web/content/php/geofons/catnet/disp/catnet.xml");
	createtables();
	
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
	xmlDoc=document.implementation.createDocument("","",null);
	xmlDoc.load("/web/content/php/geofons/catnet/disp/catnet.xml");
	xmlDoc.onload=createtables; 
}
else
{
	alert('Your browser cannot handle this script');
}
}


function createtables() {

    createNota(); //nota amb data i fitxer relacionat
    createtableUTM();
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
    createtableGds();
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
    createtableXYZ();
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
    document.getElementById('writeroot').appendChild(document.createElement('BR'));
}

function createNota() {
  switch (sLang) {
  case "cat" :
    sNoteTitle ="Nota";
    sDate= "Data d'última actualització: ";
	  sNote= "Comentaris: ";
	  break;
  case "esl":
    sNoteTitle ="Nota";
    sDate= "Fecha de última actualización: ";
	  sNote= "Comentarios: ";
	  break;
  case "eng":
    sNoteTitle ="Note";
    sDate= "Date of last update: ";
	  sNote= "Comments: ";
	  break;
	default:
	  sNoteTitle ="Nota";
    sDate= "Data d'última actualització: ";
	  sNote= "Comentaris: ";  
  }
  //notaweb i data del fitxer catnet.xml
	var arrayDate = xmlDoc.getElementsByTagName('data'); //1 element
	var arrayNote = xmlDoc.getElementsByTagName('notaweb'); //1 element
	
	
	var styleNota = document.createElement('DIV');
	var sAtri = document.createAttribute("CLASS");
  sAtri.value = "divNote";
  styleNota.setAttributeNode(sAtri);
	
  var styleNotaTitle = document.createElement('DIV');
	var sAtri2 = document.createAttribute("CLASS");
  sAtri2.value = "divNoteTitle";
	styleNotaTitle.setAttributeNode(sAtri2);
  styleNotaTitle.appendChild(document.createTextNode(sNoteTitle));
  styleNota.appendChild(styleNotaTitle);
  
	document.getElementById('writeroot').appendChild(styleNota);
	
  if (arrayDate.length >=0) {
	   if (arrayDate[0].childNodes.length >=0) {
	     styleNota.appendChild(document.createTextNode(sDate + arrayDate[0].childNodes[0].nodeValue));
	     styleNota.appendChild(document.createElement('BR'));
       //document.getElementById('writeroot').appendChild(document.createTextNode(sDate + arrayDate[0].childNodes[0].nodeValue));
	   }
	}
	if (arrayNote.length >=0) {
	   if (arrayNote[0].childNodes.length >=0) {
	     //document.getElementById('writeroot').appendChild(document.createTextNode(sNote + arrayNote[0].childNodes[0].nodeValue));
	     styleNota.appendChild(document.createTextNode(sNote + arrayNote[0].childNodes[0].nodeValue));
	   }
	}
	document.getElementById('writeroot').appendChild(document.createElement('BR'));
	document.getElementById('writeroot').appendChild(document.createElement('BR'));
	document.getElementById('writeroot').appendChild(document.createElement('BR'));
}

function createtableUTM() 
{
	//UTM 31 N
  	
	var sColum= new Array() // array de titols de columna 
  
  //Inicialitzar columnes i titol de la taula, segons idioma
  switch (sLang) {
  case "cat" :
    sTitle = "Coordenades UTM ED50 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["mappr"]="Projecció";
    sColum["E"]="X (m)";
	  sColum["N"]="Y (m)";
	  sColum["OH"]="H (m)";
	  break;
  case "esl":
    sTitle = "Coordenadas UTM ED50 de las estaciones";
    sColum["idXU"]="Código ICC";
	  sColum["idEPN"]="Estación";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["mappr"]="Proyección";
    sColum["E"]="X (m)";
	  sColum["N"]="Y (m)";
	  sColum["OH"]="H (m)";
	  break;
  case "eng":
    sTitle = "UTM ED50 Coordinates of the stations";
    sColum["idXU"]="ICC Code";
	  sColum["idEPN"]="Station";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Ref. Sys.";
    sColum["mappr"]="Projection";
    sColum["E"]="X (m)";
	  sColum["N"]="Y (m)";
	  sColum["OH"]="H (m)";
	  break;
	default:
	  sTitle = "Coordenades UTM ED50 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["mappr"]="Projecció";
    sColum["E"]="X (m)";
	  sColum["N"]="Y (m)";
	  sColum["OH"]="H (m)";
   }

  //titol
	var tableTitle = document.createElement('DIV');
	tableTitle.setAttribute('id', 'contSubsectTitle');
	tableTitle.appendChild(document.createTextNode(sTitle));
  
  document.getElementById('writeroot').appendChild(tableTitle);
	
	//taula amb capçalera + dades
  var tableDades = document.createElement('TABLE');
  var sAtri = document.createAttribute("CLASS");
  sAtri.value = "dataGrid_1";
  tableDades.setAttributeNode(sAtri);
	//tableDades.setAttribute('class', 'dataGrid_1')
  
  var tmp = document.createElement('TBODY');
	tableDades.appendChild(tmp);
  
	// Capçalera. Print Estacio, Codi ICC, Dome num, Ref Sys, projeccio, X, Y, H
	var row = document.createElement('TR');
	
	for (key in sColum) {
	  var container = document.createElement('TD');
	  //container.setAttribute('class','dg_1_header');
	  var sAtri = document.createAttribute("CLASS");
    sAtri.value = "dg_1_header";
    container.setAttributeNode(sAtri);
   	
    container.appendChild(document.createTextNode(sColum[key]));
   	row.appendChild(container);
  }
  tmp.appendChild(row);
	
	
	var t2 = xmlDoc.getElementsByTagName('estacio');
	
  // Files estacions
	// Obtenció Estacio, Codi ICC, Dome num.
  for (i=0;i<t2.length;i++)
	{
		var row = document.createElement('TR');
		for (j=0;j<t2[i].childNodes.length;j++)
		{
		  if (t2[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		//container.setAttribute('class','dg_1_odd') no funciona en IE
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
    		//container.setAttribute('class','dg_1_pair')
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			if(t2[0].childNodes[j].nodeName == 'idEPN' || t2[0].childNodes[j].nodeName == 'DOME' || t2[0].childNodes[j].nodeName == 'idXU')
			{
        if(t2[i].childNodes[j].firstChild.nodeValue != ' null ') {
          var theData = document.createTextNode(t2[i].childNodes[j].firstChild.nodeValue);
        }	else {
          var theData = document.createTextNode('');
			  }
				container.appendChild(theData);
				row.appendChild(container);
			}
		}

	var tMpr = xmlDoc.getElementsByTagName('mpr_crd'); //utm 31n
  	// Obtenció Ref sys, X, Y, H, FUS
		for (j=0;j<tMpr[i].childNodes.length;j++)
		{
			if (tMpr[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		//container.setAttribute('class','dg_1_odd') no funciona en IE
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
    		//container.setAttribute('class','dg_1_pair')
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			if(tMpr[0].childNodes[j].nodeName != 'ajust') // No es vol mostrar ajust
			{
        if(tMpr[i].childNodes[j].firstChild.nodeValue != ' null ') var theData = document.createTextNode(tMpr[i].childNodes[j].firstChild.nodeValue);
			   else var theData = document.createTextNode('');
				container.appendChild(theData); 
				row.appendChild(container);
			}
		}
		tmp.appendChild(row);
	}
		
  document.getElementById('writeroot').appendChild(tableDades);
}


function createtableGds() 
{
	//ETRS89 geodesiques
  	
  var sColum= new Array() // array de titols de columna
  
  //Inicialitzar columnes i titol de la taula, segons idioma
  switch (sLang) {
  case "cat" :
    sTitle = "Coordenades geodèsiques ETRS89 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["glon"]="Longitud";  
  	sColum["glat"]="Latitud";
  	sColum["EH"]="h (m)";  
  	break;
  case "esl":
    sTitle = "Coordenadas geodésicas ETRS89 de las estaciones";
    sColum["idXU"]="Código ICC";
	  sColum["idEPN"]="Estación";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["glon"]="Longitud";
  	sColum["glat"]="Latitud";
  	sColum["EH"]="h (m)";  
	  break;
  case "eng":
    sTitle = "ETRS89 Geodetic coordinates of the stations";
    sColum["idXU"]="ICC Code";
	  sColum["idEPN"]="Station";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Ref. Sys.";
    sColum["glon"]="Longitude";
  	sColum["glat"]="Latitude";
  	sColum["EH"]="h (m)";  
	  break;
	default:
	  sTitle = "Coordenades geodèsiques ETRS89 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["glon"]="Longitud";  
  	sColum["glat"]="Latitud";
  	sColum["EH"]="h (m)";  
  }

 	//titol
	var tableTitle = document.createElement('DIV');
	tableTitle.setAttribute('id', 'contSubsectTitle');
	tableTitle.appendChild(document.createTextNode(sTitle));
  
  document.getElementById('writeroot').appendChild(tableTitle);
	
	//taula amb capçalera + dades
  var tableDades = document.createElement('TABLE');
  var sAtri = document.createAttribute("CLASS");
  sAtri.value = "dataGrid_1";
  tableDades.setAttributeNode(sAtri);
	  
  var tmp = document.createElement('TBODY');
	tableDades.appendChild(tmp);
  
	// Capçalera. Print Estacio, Codi ICC, Dome num, etc.
	var row = document.createElement('TR');
	
	for (key in sColum) {
	  var container = document.createElement('TD');
	  
    var sAtri = document.createAttribute("CLASS");
    sAtri.value = "dg_1_header";
    container.setAttributeNode(sAtri);
   	
    container.appendChild(document.createTextNode(sColum[key]));
   	row.appendChild(container);
  }
  tmp.appendChild(row);
	
	
	var t2 = xmlDoc.getElementsByTagName('estacio');
	
  // Files estacions
	// Obtenció Estacio, Codi ICC, Dome num.
  for (i=0;i<t2.length;i++)
	{
		var row = document.createElement('TR');
		for (j=0;j<t2[i].childNodes.length;j++)
		{
		  if (t2[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		//container.setAttribute('class','dg_1_odd') no funciona en IE
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
     		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			if(t2[0].childNodes[j].nodeName == 'idEPN' || t2[0].childNodes[j].nodeName == 'DOME' || t2[0].childNodes[j].nodeName == 'idXU')
			{
        if(t2[i].childNodes[j].firstChild.nodeValue != ' null ') {
          var theData = document.createTextNode(t2[i].childNodes[j].firstChild.nodeValue);
        }	else {
          var theData = document.createTextNode('');
			  }
				container.appendChild(theData);
				row.appendChild(container);
			}
		}

	var t1 = xmlDoc.getElementsByTagName('ged_crd');//ETRS89 geodesiques
	  var gLon="";
			var mLon="";
			var sLon="";
			var gLat="";
			var mLat="";
			var sLat="";
			var eh ="";
     // Obtenció Ref sys, X, Y, H, FUS
		for (j=0;j<t1[i].childNodes.length;j++)
		{
			if (t1[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
     		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			
			switch (t1[i].childNodes[j].nodeName) {
          case 'refsys':
            container.appendChild(document.createTextNode(t1[i].childNodes[j].firstChild.nodeValue));
            row.appendChild(container);				
            break;
          case 'glon':
            gLon = t1[i].childNodes[j].firstChild.nodeValue;
            break;
          case 'mlon':
            mLon = t1[i].childNodes[j].firstChild.nodeValue;
            break;
          case 'slon':
            sLon = t1[i].childNodes[j].firstChild.nodeValue;
            break;
          case 'glat':
            gLat = t1[i].childNodes[j].firstChild.nodeValue;
            break;
          case 'mlat':
            mLat = t1[i].childNodes[j].firstChild.nodeValue;
            break;
          case 'slat':
            sLat = t1[i].childNodes[j].firstChild.nodeValue;
            break;  
          case 'EH':
            eh = t1[i].childNodes[j].firstChild.nodeValue;
            break;
       }
			}
	   if (gLon != "" && mLon != "" && sLon !="") {
	        var container = document.createElement('TD');
	        if(i%2==0){
    		    var sAtri = document.createAttribute("CLASS");
            sAtri.value = "dg_1_odd";
            container.setAttributeNode(sAtri);
   		     }else{
           		var sAtri = document.createAttribute("CLASS");
              sAtri.value = "dg_1_pair";
              container.setAttributeNode(sAtri);
         		}	
	        var theData = document.createTextNode(gLon + "º " + mLon + "' " + sLon + "''");
          container.appendChild(theData);
          row.appendChild(container);
       }
       if (gLat != "" && mLat != "" && sLat !="") {
          var container = document.createElement('TD');
          if(i%2==0){
        		var sAtri = document.createAttribute("CLASS");
            sAtri.value = "dg_1_odd";
            container.setAttributeNode(sAtri);
       		}else{
         		var sAtri = document.createAttribute("CLASS");
            sAtri.value = "dg_1_pair";
            container.setAttributeNode(sAtri);
       		}	
          var theData = document.createTextNode(gLat + "º " + mLat + "' " + sLat + "''");
          container.appendChild(theData);
          row.appendChild(container);
       }
      
       if (eh != "") {
          var container = document.createElement('TD');
          if(i%2==0){
        		var sAtri = document.createAttribute("CLASS");
            sAtri.value = "dg_1_odd";
            container.setAttributeNode(sAtri);
       		}else{
         		var sAtri = document.createAttribute("CLASS");
            sAtri.value = "dg_1_pair";
            container.setAttributeNode(sAtri);
       		}	
          var theData = document.createTextNode(eh)
          container.appendChild(theData);
          row.appendChild(container);
       }
		tmp.appendChild(row);
	}
		
  document.getElementById('writeroot').appendChild(tableDades);
}


function createtableXYZ() 
{
	//ETRS89 geocentriques
  	  
  var sColum= new Array() // array de titols de columna 
  
  //Inicialitzar columnes i titol de la taula, segons idioma
  switch (sLang) {
  case "cat" :
    sTitle = "Coordenades geocèntriques ETRS89 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["X"]="X (m)";
	  sColum["Y"]="Y (m)";
	  sColum["Z"]="Z (m)";
	  break;
  case "esl":
    sTitle = "Coordenadas geocéntricas ETRS89 de las estaciones";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["X"]="X (m)";
	  sColum["Y"]="Y (m)";
	  sColum["Z"]="Z (m)";
	  break;
  case "eng":
    sTitle = "ETRS89 Geocentric coordinates of the stations";
    sColum["idXU"]="ICC Code";
	  sColum["idEPN"]="Station";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Ref. Sys.";
    sColum["X"]="X (m)";
	  sColum["Y"]="Y (m)";
	  sColum["Z"]="Z (m)";
	  break;
	default:
	  sTitle = "Coordenades geocèntriques ETRS89 de les estacions";
    sColum["idXU"]="Codi ICC";
	  sColum["idEPN"]="Estació";
	  sColum["DOME"]="DOME #";
    sColum["refsys"]="Sist. Ref.";
    sColum["X"]="X (m)";
	  sColum["Y"]="Y (m)";
	  sColum["Z"]="Z (m)";
  }

 	//titol
	var tableTitle = document.createElement('DIV');
	tableTitle.setAttribute('id', 'contSubsectTitle');
	tableTitle.appendChild(document.createTextNode(sTitle));
  
  document.getElementById('writeroot').appendChild(tableTitle);
	
	//taula amb capçalera + dades
  var tableDades = document.createElement('TABLE');
  var sAtri = document.createAttribute("CLASS");
  sAtri.value = "dataGrid_1";
  tableDades.setAttributeNode(sAtri);
  
  var tmp = document.createElement('TBODY'); //per IE
	tableDades.appendChild(tmp);
  
	// Capçalera
	var row = document.createElement('TR');
	
	for (key in sColum) {
	  var container = document.createElement('TD');
	  var sAtri = document.createAttribute("CLASS");
    sAtri.value = "dg_1_header";
    container.setAttributeNode(sAtri);
   	
    container.appendChild(document.createTextNode(sColum[key]));
   	row.appendChild(container);
  }
  tmp.appendChild(row);
	
	
	var t2 = xmlDoc.getElementsByTagName('estacio');
	
  // Files estacions
	// Obtenció Estacio, Codi ICC, Dome num.
  for (i=0;i<t2.length;i++)
	{
		var row = document.createElement('TR');
		for (j=0;j<t2[i].childNodes.length;j++)
		{
		  if (t2[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		//container.setAttribute('class','dg_1_odd') no funciona en IE
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
    		//container.setAttribute('class','dg_1_pair')
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			if(t2[0].childNodes[j].nodeName == 'idEPN' || t2[0].childNodes[j].nodeName == 'DOME' || t2[0].childNodes[j].nodeName == 'idXU')
			{
        if(t2[i].childNodes[j].firstChild.nodeValue != ' null ') {
          var theData = document.createTextNode(t2[i].childNodes[j].firstChild.nodeValue);
        }	else {
          var theData = document.createTextNode('');
			  }
				container.appendChild(theData);
				row.appendChild(container);
			}
		}

    var tXyz = xmlDoc.getElementsByTagName('xyz_crd');
	
  	// Obtencio Ref sys, X, Y, Z
		for (j=0;j<tXyz[i].childNodes.length;j++)
		{
			if (tXyz[i].childNodes[j].nodeType != 1) continue;
			var container = document.createElement('TD');
   		if(i%2==0){
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_odd";
        container.setAttributeNode(sAtri);
   		}else{
    		var sAtri = document.createAttribute("CLASS");
        sAtri.value = "dg_1_pair";
        container.setAttributeNode(sAtri);
   		}	
			if(tXyz[0].childNodes[j].nodeName != 'ajust')
			{
        if(tXyz[i].childNodes[j].firstChild.nodeValue != ' null ') var theData = document.createTextNode(tXyz[i].childNodes[j].firstChild.nodeValue);
			   else var theData = document.createTextNode('');
				container.appendChild(theData); 
				row.appendChild(container);
			}
		}
		tmp.appendChild(row);
	}
		
  document.getElementById('writeroot').appendChild(tableDades);
}
/** Fi de les Funcions per la pagina de coordenades de les estacions Catnet**/

/** Funcions per els reports de catnet de nTripMonitor**/

function daysInFebruary (year){
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
/*function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}*/

function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}


function isValidDate(month,day,year){
	//var daysInMonth = DaysArray(12)
	if ((month==2 && day>daysInFebruary(year)) || day > daysInMonth(month,year)){
		return false;
	}
	return true;
}

   function checkDate1(strLang) {
      //for daily report
      var x = document.getElementById("formCalendar"); //form
	var day = x.dia.options[x.dia.selectedIndex].value; //day in text format
      var day2 = x.dia.options[x.dia.selectedIndex].text; //day in number format
      var month=x.mes.options[x.mes.selectedIndex].value; //month in text format
      var month2=x.mes.options[x.mes.selectedIndex].text; //month in number format
      var year = x.any.options[x.any.selectedIndex].value; //year in text format
      var year2 = x.any.options[x.any.selectedIndex].text;//year in number format
      //check if it's a date < today = ( date<= yesterday)
      var selectedDate= new Date(year, month2 -1,day); //selectedDate (months 0-11 in javascript)
      
      var yesterday = new Date(); //yesterday
      yesterday.setDate(yesterday.getDate() - 1);
      
      if (selectedDate <= yesterday) {
        //check if it's a valid date
        if (isValidDate(month2, day2,year2)) {  
          return true;
        } else { 
            switch(strLang) {
            case 'cat':
              alert("La data no és vàlida");
              break;    
            case 'esl':
              alert("La fecha no es válida");
              break;
            case 'eng':
              alert("Please enter a valid date");
              break;
            default:
              alert("La data no és vàlida");
            }
          
          return false;
        }
        }
      else {
            switch(strLang) {
            case 'cat':
              alert("Si us plau, seleccioni una data anterior a avui.");
              break;    
            case 'esl':
              alert("Por favor, seleccione una fecha anterior a hoy.");
              break;
            case 'eng':
              alert("Please select a date before today.");
              break;
            default:
               alert("Si us plau, seleccioni una data anterior a avui.");
            }
        
        return false;
      }    
  }
  function checkDate2(strLang) {
      //for monthly report
      var x = document.getElementById("formCalendar"); //form
	
      var month=x.mes.options[x.mes.selectedIndex].value; //month in text format
      var month2=x.mes.options[x.mes.selectedIndex].text; //month in number format
      var year = x.any.options[x.any.selectedIndex].value; //year in text format
      
      //check if it's a date < last month's date
      var selectedDate= new Date(year, month2 -1,1); //selectedDate (months 0-11 in javascript)
      
      var lastMonthsDate = new Date(); //today 
      //var daysInMonth = DaysArray(12);
      
      if (lastMonthsDate.getMonth() == 0) {
          //month=0 --> January
          //lastMonthsDate = December
          lastMonthsDate.setDate(31);
          lastMonthsDate.setMonth(11);
          lastMonthsDate.setYear(lastMonthsDate.getFullYear() -1);
      } else {
          month3=lastMonthsDate.getMonth() -1;
          lastMonthsDate.setDate(daysInMonth(month3,year));
          lastMonthsDate.setMonth(month3);
      }
      
      if (selectedDate < lastMonthsDate) {
          return true;
      }
      else {
        switch(strLang) {
            case 'cat':
              alert("Si us plau, seleccioni un mes anterior a l'actual.");
              break;    
            case 'esl':
              alert("Por favor, seleccione un mes anterior al actual.");
              break;
            case 'eng':
              alert("Please select a month before current.");
              break;
            default:
               alert("Si us plau, seleccioni un mes anterior a l'actual.");
            }
        return false;
      }    
  }
   function getXmlFile(strLang) {
      if (checkDate1(strLang)) {
      
      x = document.getElementById("formCalendar");
   day = x.dia.options[x.dia.selectedIndex].value;
      month=x.mes.options[x.mes.selectedIndex].value;
      year = x.any.options[x.any.selectedIndex].value;
      windowURL = "/web/content/php/geofons/catnet/informes/geodesiaICC" + year + month + day + ".xml";
      window.open(windowURL,'xmlGeodesia');
 
      } 
    }
  function getPdfFile(strLang) {
  if (checkDate2(strLang)) {
      x = document.getElementById("formCalendar");
	
      month=x.mes.options[x.mes.selectedIndex].value;
      year = x.any.options[x.any.selectedIndex].value;
      windowURL = "/web/content/php/geofons/catnet/informes/geodesiaICC" + year + month + ".pdf";
      window.open(windowURL,'pdfGeodesia');
      } 
    }
    
function selectYesterday() {
  
    x = document.getElementById("formCalendar");
	
   var yesterday = new Date(); //yesterday
    
    yesterday.setDate(yesterday.getDate() - 1);
        
    x.dia.selectedIndex = yesterday.getDate() -1;
    x.mes.selectedIndex = yesterday.getMonth();
    var strYear = yesterday.getFullYear();
    
    for (i=0;i<x.any.length;i++) {
      if (x.any[i].value == strYear) {
        x.any.selectedIndex = i;  
      }
    }

}

function amapserver(){
	mapserver=window.open("http://galileo.icc.es/website/icc_ressenyes/viewer.htm","mapserver",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=790,height=600');
	mapserver.focus();
}

/** Fi de Funcions per els reports de catnet de nTripMonitor**/

