function detect_os(){
	var v_sis="";
	if (navigator.platform.toUpperCase().indexOf("WIN")==-1){
		v_sis="mac";
	}else{
		v_sis="win";
	}
	return v_sis;					
}
var ns4=(document.layers)?true:false;
var ie4=(document.all)?true:false;
var dom=(!document.all && document.getElementById) ? true : false;
var v_plat=detect_os();

function canvi(celda,actiu){
	nom_cel="opcio"+celda;
	if (actiu=="S"){
		color='#EBD816';
	}else{
		color='#25753F';
	}
	if (!ns4){
		if (!dom){
			//explorer
			if (ie4){
				document.all[nom_cel].style.background=color;
			}
		}else{
			//ns6
			document.getElementById(nom_cel).style.background=color;
		}
	}
	return;
}

function val_fecha(v_dat){
		
	var mesos=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	var fecha=v_dat
				
	var dia="";
	var mes="";
	var ano="";
	
	var dia=fecha.substr(0,2);
	var se1=fecha.substr(2,1);
	var mes=fecha.substr(3,2);
	var se2=fecha.substr(5,1);
	var ano=fecha.substr(6,4);
								
	var ok=true;
	
	if((se1!="/") || (se2!="/")){
		ok=false;
	}
			
	if ( isNaN(dia) || isNaN(mes) || isNaN(ano) ) {
		ok=false;
	}
	
	n_dia=dia;
	n_mes=mes-1;
	n_ano=ano;
									
	if ((n_ano%4)==0){
		mesos[1]=29;
	}
	
	if ((n_dia<1) || (n_dia>mesos[n_mes])){
		ok=false;
	}
	
	if ((n_mes+1<1) || (n_mes+1>12)){
		ok=false;
	}
	
	if ( (n_ano==0) || (n_ano=="") ){
		ok=false;
	}
	
	return ok;
	
}

function test_mail(camp){
	camp.toLowerCase();
	sw_pas=true;
	if (camp==""){
		sw_pas=false;
	}else{
		if ((camp.indexOf("@")==-1) || (camp.indexOf(" ")!=-1) || (camp.indexOf(".")==-1)){
			sw_pas=false;
		}else{
			if (camp.length<6){
				sw_pas=false;
			}
		}
	}
	return sw_pas;
}

var v_fin;

//obri popup
function obrir_popup(url,f_amp,f_alt,nom_finestra){
	ancho=screen.width;				//ample pantalla
	alto=screen.height;				//alt pantalla
	v_top=(alto-f_alt)/2;	
	v_left=(ancho-f_amp)/2;
	
	if (typeof(v_fin)!="undefined"){
		v_fin.close();
	
	}
	
	v_fin=window.open(url,nom_finestra,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+f_amp+",height="+f_alt+",top="+v_top+",left="+v_left);
}

function setPointer(theRow, thePointerColor){
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }
	var row_cells_cnt = theRow.cells.length-1;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }
	
	return true;
}

//*********************************************
function punt(nom){
    this.nom=nom;
    this.x=0;
    this.y=0;
    this.getX=getX;
    this.getY=getY;
    this.getOffsetLeft=getOffsetLeft;
    this.getOffsetTop=getOffsetTop;
    if (!is.ie){
        //ns4 i ns6+ i altres
        this.objSp = document.images[this.nom];
        this.x = this.objSp.x;
        this.y = this.objSp.y;
    }else{
        //ie
        this.objSp = eval("document.images['"+this.nom+"']");
        this.x = this.getOffsetLeft(this.objSp);
        this.y = this.getOffsetTop(this.objSp);
    }
}
function getX(){
    return this.x;
}
function getY(){
    return this.y;
}
//*********************
//funcions per explorer
function getOffsetLeft (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null){
        ol += el.offsetLeft;
    }
	return ol;
}
function getOffsetTop (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null){
        ot += el.offsetTop;
    }
    return ot;
}
//*********************
//*********************************************

function verificaForm(oForm,locale){
	
	var locale = locale;
	var arrErrors = new Array();
	
	if (oForm.nom.value==''){
		arrErrors.push({txt:'- '+locale['err_nom'],cmp:'nom'});
	}
	if (oForm.email.value==''){
		
		arrErrors.push({txt:'- '+locale['err_mai'],cmp:'email'});
		
	}else {
	
		var reg_exp = /\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
		if (!reg_exp.test(oForm.email.value)){
			arrErrors.push({txt:'- '+locale['err_mai'],cmp:'email'});
		}
	
	}
	
	if (oForm.curri && oForm.curri.value==''){
		arrErrors.push({txt:'- '+locale['err_cur'],cmp:'curri'});
	}
	
	if (oForm.din && (oForm.din.value=='' || !val_fecha(oForm.din.value))){
		arrErrors.push({txt:'- '+locale['err_din'],cmp:'din'});
	}
	
	if (oForm.dfi && (oForm.dfi.value=='' || !val_fecha(oForm.dfi.value))){
		arrErrors.push({txt:'- '+locale['err_dfi'],cmp:'dfi'});
	}
	
	if (oForm.npe && oForm.npe.value==''){
		arrErrors.push({txt:'- '+locale['err_npe'],cmp:'npe'});
	}
	
	if (oForm.comentari.value==''){
		arrErrors.push({txt:'- '+locale['err_obs'],cmp:'comentari'});
	}
	
	if (arrErrors.length>0){
		
		var arrAux= new Array();
		
		for(i=0;i<arrErrors.length;i++){
			arrAux.push(arrErrors[i].txt);
		}
		
		alert(locale['tit_err']+':\n'+arrAux.join("\n"));
		
		oForm[arrErrors[0].cmp].focus();
		
	}
	
	return !(arrErrors.length>0);

}

function writeEMailLink( nom, dom, text ){
	document.write( '<a hr'+'ef="mai'+'lto:'+nom+'@'+dom+'">'+text+'</a>' );		
}