function time() {
    return Math.round(new Date().getTime()/1000);
}

function miss(text, auto){
	$("#miss").html(text).fadeIn("fast");
	if(auto==undefined || auto==true) setTimeout("miss_fora();",3000);
}
function miss_fora(){
	$("#miss").fadeOut(1500);
}

///////////////////// COMPROVAR CAPMS /////////////////////////////////////
function comprovar_form(ob){
	var ok=false;

	if(ob.camps.length>0){
		ok=true;
		if(ob.color==undefined) ob.color="#FFCC33";
		
		for(var i=0;i<ob.camps.length;i++){
		//repasso tots els camps

			if($("#"+ob.camps[i]).val().length<1){
			//no hi ha dades
				ok=false;
				$("#"+ob.camps[i]).css("background-color",ob.color);
			}else{
			//hi ha dades
				$("#"+ob.camps[i]).css("background-color","");
			}
		}
	}else{
		alert("# Falten camps!");
	}

	return ok;
}

///////////////////////// MOVIMENT DE CAIXA ///////////////////////////////
function caixa_mov(op){
	var err="";
	if(op!=undefined){
		if(op.id!=undefined){
///// es pot procedir ////////////

			if(op.max==undefined) op.max=5000;
			op.max=op.max*(-1);
			if(op.translacio==undefined) op.translacio=100;
			op.translacio=op.translacio*(-1);
			if(op.orientacio==undefined) op.orientacio="x";
			if(op.temps==undefined) op.temps=1000;

			this.reg=op;
///// Acava procediment //////////
		}else{
			err+="\n   - Falta id"
		}
	}else{
		err+=("\n   - Falta declaració");
	}
	if(err.length>0) alert("Errors al crear la caixa:"+err);
}

caixa_mov.prototype.reg={buit:true};

caixa_mov.prototype.seg=function(){
	if(this.reg.buit==true){
		alert("No hi ha registre actiu.");
	}else{
		if(this.reg.orientacio=="x"){

			var a=$("#"+this.reg.id+" #_caixa").position().left;
			//a=a-$("#"+this.reg.id+" #_cos").position().left;

			if(a>this.reg.max && ((a+this.reg.translacio)<this.reg.max)){
			//he d'abançar però no massa
				var b=this.reg.max;
			}else if(a>this.reg.max && ((a+this.reg.translacio)>=this.reg.max)){
			//es pot abançar segons config
				var b=a+this.reg.translacio;
			}

			if(b!=undefined) $("#"+this.reg.id+" #_caixa").animate({left:b},this.reg.temps);
		}

		if(this.reg.orientacio=="y"){
			var a=$("#"+this.reg.id+" #_caixa").position().top;
			//a=a-$("#"+this.reg.id+" #_cos").position().top;

			if(a>this.reg.max && ((a+this.reg.translacio)<this.reg.max)){
			//he d'abançar però no massa
				var b=this.reg.max;
			}else if(a>this.reg.max && ((a+this.reg.translacio)>=this.reg.max)){
			//es pot abançar segons config
				var b=a+this.reg.translacio;
			}

			if(b!=undefined) $("#"+this.reg.id+" #_caixa").animate({top:b},this.reg.temps);
		}
	}
}

caixa_mov.prototype.ant=function(){
	if(this.reg.buit==true){
		alert("No hi ha registre actiu.");
	}else{
		if(this.reg.orientacio=="x"){
			var a=$("#"+this.reg.id+" #_caixa").position().left;
			//a=a-$("#"+this.reg.id+" #_cos").position().left;
			if(a<0 && ((a-this.reg.translacio)>=0)){
			//he d'abançar però no massa
				var b=0;
			}else if(a<0 && ((a-this.reg.translacio)<=0)){
			//es pot abançar segons config
				var b=a-this.reg.translacio;
			}
			if(b!=undefined) $("#"+this.reg.id+" #_caixa").animate({left:b},this.reg.temps);
		}

		if(this.reg.orientacio=="y"){
			var a=$("#"+this.reg.id+" #_caixa").position().top;
			//a=a-$("#"+this.reg.id+" #_cos").position().top;

			if(a<0 && ((a-this.reg.translacio)>=0)){
			//he d'abançar però no massa
				var b=0;
			}else if(a<0 && ((a-this.reg.translacio)<=0)){
			//es pot abançar segons config
				var b=a-this.reg.translacio;
			}
			if(b!=undefined) $("#"+this.reg.id+" #_caixa").animate({top:b},this.reg.temps);
		}
	}
}




//// COMANDAMENTS IMATGES /////////////////
function comandaments_img(){
	var a="_";
}

comandaments_img.prototype.carregar=function (nom, ruta){
	if (nom=="com"){   // no podem posar de nom 'com' pq es un nom reservat
		alert("'com' és un nom d'imatge reservat.\nNo pot registrar l'imatge amb aquest nom.");
	}else{  //registrem la imatge
		img[nom]= new Image();
		img[nom].src=ruta;
	}
}

comandaments_img.prototype.posa=function(imag, desti){
		$("#"+desti).prepend("<img src=\""+img[imag].src+"\" />");
}

comandaments_img.prototype.codi=function(imag){
	return "<img src=\""+img[imag].src+"\" />";
}

img=new Array();
img['com']=new comandaments_img();
/////////////////////////////////////////////////////////

function precarrega(){
	img.com.carregar("fApats","../plats/fons.jpg");
	img.com.carregar("fEspais","../espais/fons.jpg");
	img.com.carregar("fNecessitem","../necessitem/fons.jpg");
	img.com.carregar("fExpe","../experiencies/fons.jpg");
	img.com.carregar("fContact","../contactar/fons.jpg");
	img.com.carregar("fCredits","../credits/fons.jpg");
	img.com.carregar("fMouMesY1","../imatges/mou_mes_y1.gif");
	img.com.carregar("fMouMenysY1","../imatges/mou_menys_y1.gif");
}

setTimeout("precarrega();",1500);