// generic

function overCell(quinID, col, bgcol) {
  	obj = document.getElementById(quinID);
  	//obj.style.fontWeight = "bold";
	obj.style.color = col;
	obj.style.backgroundColor=bgcol;		
}

function toggleMenu(currMenu) {
	if (document.getElementById) {
		thisMenu = document.getElementById(currMenu).style		
		if (thisMenu.display == "") {
			thisMenu.display = "none"
		}
		else {
			thisMenu.display = ""
		}
		return false
	}
	else {
		return true
	}
}

function canviarTots (_array) {
	n=_array.length;
	for (i=0;i<n;i++) {		
		toggleMenu(_array[i]);
	}
}

function amagarTots (_array) {
	n=_array.length;
	for (i=0;i<n;i++) {				
		if (document.getElementById) {
			thisMenu = document.getElementById(_array[i]).style;
			thisMenu.display = "none"
		}
	}
}


function finestracentre (url, nom, ample, alta) {
	ampl = screen.availWidth/2;
	alt = screen.availHeight/2;
	_left=ampl-ample/2;
	_top=alt-alta/2;			
	finestra = window.open(url, nom, "toolbar=no,location=no,scrollbars=yes,resizable=no,width="+ample+",height="+alta+",top=" + _top + ",left=" + _left);			
	finestra.focus(); 
}

String.prototype.trim = function() {
		return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
}

// noticies 

function esborrar_noticia (id,txt) {
	if (confirm('Esborrar notícia: ' + txt + '?')) {
		this.location = "transac/transac_noticies.php?action=Esborrar&id="+id;
	} 
}

function esborrar_linia (id,txt,transac) {
	if (confirm('Esborrar : ' + txt + '?')) {
		this.location = "transac/"+ transac +"?action=Esborrar&id="+id;
	} 
}

function enviar_news (id,txt) {
	if (confirm('Enviar : ' + txt + '?')) {
		this.location = "cms.php?sec=enviarnewsletter&id="+id;
	} 
}

function popup_upload(seccio,tipus,camp,ample,alt) {
	finestracentre ('upload_file.php?seccio='+seccio+'&tipus='+tipus+"&camp="+camp+"&ample="+ample+"&alt="+alt, 'uploadimg', 500, 250)
}

function submitIt(camp,str) {		
	// str es obligatori
	val = camp.value;
	val = val.trim() 
	if (val=="") {
		alert(str + " es un camp obligatori");
		return false;
	}
}

function validEmail(email) {

			invalidChars = " /:,;"


			if (email == "") {

				return false

			}

			for (i=0; i<invalidChars.length; i++) {

				badChar = invalidChars.charAt(i)

				if (email.indexOf(badChar,0) > -1) {

					return false

				}

			}

			atPos = email.indexOf("@",1)

			if (atPos == -1) {

				return false

			}

			if (email.indexOf("@",atPos+1) > -1) {

				return false

			}

			periodPos = email.indexOf(".",atPos)

			if (periodPos == -1) {

				return false

			}

			if (periodPos+3 > email.length)	{

				return false

			}

			return true

}

function submitItMultiple(form,array_camps,array_strs) {
	// aqui form es un string
	for (var i=0;i<array_camps.length;i++) {
		camp = eval(form+"."+array_camps[i]);
		val = camp.value;
		val = val.trim();
		if (camp.id=='email' && !validEmail(val)) {
				alert('Formato de email incorrecto');
				return false;
		} else if (val=="") {
			alert(array_strs[i] + " es un campo obligatorio");
			return false;
		}
	}
}

function mapa_contact(id,mapaimg) {
	if (document.getElementById) {
		thisID = document.getElementById(id).style				
		thisID.backgroundImage = "url(../img/"+mapaimg+")";				
		return false
	} else {
		return true
	}
}


