function createObsDetallLine() {
	var div = document.createElement('div')
	xAddClass(div,"obsdetallline");
	div.innerHTML = '&nbsp;';
	return div;
}

function createTitleSeccio(title) {
	var div = document.createElement('div')
	xAddClass(div,"obsdetallseccio seccio");
	div.innerHTML = title;
	return div;
}

function createLineObs(label,value) {
	var line = document.createElement('div')
	xAddClass(line,"obsdetallline");
	
	var div = document.createElement('div')
	xAddClass(div,"obsdetalllabel");
	div.innerHTML = label + ':';
	line.appendChild(div);
	
	div = document.createElement('div')
	xAddClass(div,"obsdetallvalida");
	div.innerHTML = '&nbsp;';
	line.appendChild(div);
	
	div = document.createElement('div')
	xAddClass(div,"obsdetallvalue");
	div.innerHTML = value;
	line.appendChild(div);

	return line;
}

function createFoto(nom) {
	var line = document.createElement('div');
	xAddClass(line,"obsdetallline centrat");
	
	var div = document.createElement('div');
	xAddClass(div,"obsdetallfoto");
	line.appendChild(div);
	
	if (nom) {
		var a = document.createElement('a');
		a.href = "javascript:showFotografia(" + nom + ")";
		//a.href = "javascript:alert('not yet');";
		div.appendChild(a);
		
		var img = document.createElement("img");
		img.src = webroot + '/imatges/observacions/' + nom + '_1.jpg';
		img.alt = idiomes['IMATGE_OBS'];
		img.width = 300;
		a.appendChild(img);
	} else {
		div.innerHTML = idiomes['NO_FOTO'];
	}
	return line;
}

function showDetallAlertaEMA(data, estacio, variable) {
	// TODO
	showFinestra('alertaEMA', true, null);
}

function trim(txt)
{
	var str = new String(txt);
	return str.replace(/(^\s*)|(\s*$)/g, "");
}


function resizeFrame(id){
	// Variable para Height del iFrame
	var hFrame;
	//var wFrame;
	if(document.frames){
		// ES IE
		// Miramos el contenido del iframe para IE
		hFrame = document.frames(id + "-frame").document.body.scrollHeight;
		//wFrame = document.frames(id + "-frame").document.body.scrollWidth;
	} else {
		// ES OTRO
		// Miramos el contenido del iframe para GEKO/MOZILLA/...
		hFrame = frames[id + "-frame"].document.body.scrollHeight;
		//wFrame = frames[id + "-frame"].document.body.scrollWidth;
	}
	//alert(hFrame);
	document.getElementById(id + "-frame").height = hFrame;
	document.getElementById("content-" + id).style.height = hFrame + "px";
	document.getElementById(id).style.height = (hFrame + 37) + "px";
	//document.getElementById(id + "-frame").width = wFrame;
	//document.getElementById("content-" + id).style.width = wFrame + "px";
	//document.getElementById(id).style.width = (wFrame + 20) + "px";
}

function showFotografia(url) {
	window.open(webroot + '/imatges/observacions/' + url + '_2.jpg',"_blank");
}

function parseDate(sDate) {
	if (sDate != null) {
		var fechaHora = sDate.split(" ");
		var fecha = fechaHora[0].split("-");
		var hora = fechaHora[1].split(":");
		return new Date(fecha[0], fecha[1]-1, fecha[2], hora[0], hora[1], hora[2], 0);
	} else {
		return null;
	}
}

function formatDate(date) {
	return '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + 
		date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds() + ''; 
}

function searchItem(lista, valor){
	var ind, pos;
	for(ind=0; ind<lista.length; ind++) {
    if (lista[ind] == valor)
    	break;
    }
    pos = (ind < lista.length)? ind : -1;
    return (pos);
}

function parsearDosDigitos(num) {
	if (Math.floor(num/10) > 0) {
		return '' + num  + '';
	} else {
		return '0' + num;
	}
}

function getDateFinal() {
	var dateFinal = document.getElementById('fechaFinal');
	if (dateFinal != null) {
		var sDate = dateFinal.innerHTML;
		var fechaHora = sDate.split(" ");
		var fecha = fechaHora[0].split("/");
		var hora = fechaHora[fechaHora.length - 1].split(":");
		return new Date(fecha[2], fecha[1]-1, fecha[0], hora[0], hora[1], 0, 0);
	}
}

function showFinestra(idFinestra, visible) {
	var finestra=document.getElementById(idFinestra);
	if(visible){
		finestra.style.display="";
	}else{
		finestra.style.display="none";
	}
}

function showHelp(idioma) {
	//alert("Enllaç no configurat");
	window.open("http://www.meteocat.com/mediamb_xemec/servmet/marcs/marc_xemec.html");
}

function makeLink(content, url)
{
	var a = document.createElement('a');
	a.href = url;
	a.appendChild(content);
	return a;
}
