// *************************
// *************************
// * llibreria de funcions *
// *************************
// *************************
		
		
// ****************************************************
// * funcio que detecta navegador                     *
// * mira si el nom de navegador que li passam        *
// * com a parametre esta dins el nom de l'aplicacio  *
// ****************************************************
		
function navegador(nom){

	nom=nom.toUpperCase();
	
	exist=true;
			
	if ( navigator.appName.toUpperCase().indexOf(nom)==-1 ){
		exist=false;}
		
	return exist;					
	
}

netsca=navegador("netscape")
explor=navegador("explorer")

// *****************************************************************************
// * funcion que mou o situa un objecte                                        *
// * si moure="S" mou sino situa	                                           *
// * li passam el nom de l'objecte, la posicio x i la y, i si ha de moure o no *
// *****************************************************************************
		
function moure(tag,x,y,moure){
		
	if (navegador("netscape")){
				
		// NETSCAPE -->
		
		if (moure=="S"){
			document.layers[tag].top=parseInt(document.layers[tag].top,10)+y;
			document.layers[tag].left=parseInt(document.layers[tag].left,10)+x;
			}
		else{
			document.layers[tag].top=y;
			document.layers[tag].left=x;						
			}
	}
		
	else{
	
		// EXPLORER -->
				
		if (moure=="S"){
			document.all[tag].style.top=parseInt(document.all[tag].style.top,10)+y;
			document.all[tag].style.left=parseInt(document.all[tag].style.left,10)+x;
			}
		else{
			document.all[tag].style.top=y;
			document.all[tag].style.left=x;						
			}
	}
					
}
		
		
// ********************************************************************************
// * funcio que activa la captura de teclat                                       *
// * li passam com a parametre el nom de la funcio que ha de controlar les tecles *
// ********************************************************************************
		
var fun_cont;
		
function cap_teclado(nom_funcio){
	document.onkeydown=mira_tecla;
	if (navegador("netscape")){
		document.captureEvents(Event.KEYDOWN);}
	fun_cont=nom_funcio;
}
		
		
// ******************************************	
// funcio que captura una determinada tecla *
// el parametre e es obligatori             *
// ******************************************
		
function mira_tecla(e){
			
	n_tecla=0;
	c_tecla="";

	if (navegador("netscape")){
		n_tecla=e.which;}
	else{
		n_tecla=event.keyCode;}
				
	c_tecla=String.fromCharCode(n_tecla);
			
	eval(fun_cont+"(n_tecla,c_tecla);");
		
}

// *********************************************************
// * funcio per fer el rollover                            *
// * li passam el nom de la imatge que volem tractar       *
// * i llavors el nom fitxer de la imatge que ha de quedar *
// *********************************************************
		
function canvi_ima(nom,imatge){
	eval("document."+nom+".src=imatge");
}
	
//obrir oferta
function obrir_oferta(idi){
	ancho=screen.width;				//ample pantalla
	alto=screen.height;				//alt pantalla
	f_amp=350;						//ample finestra
	f_alt=275;						//alt finestra
	v_top=(alto-f_alt)/2;	
	v_left=(ancho-f_amp)/2;
	window.open("oferta_"+idi+".htm","oferta","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 test_mail(camp){
	if (camp==''){
		return false;
	}else{
		camp.toLowerCase();
		if ((camp.indexOf("@")==-1) || (camp.indexOf(" ")!=-1) || (camp.indexOf(".")==-1)){
			return false;
		}else{
			if (camp.length<6){
				return false;
			}
		}
		return true;
	}
}

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 comprova_tarja_credit(card_number){

	cc_array=card_number.split("");
	cc_array.reverse();
	digit_string="";
	
	for (counter=0;counter<cc_array.length;counter++){
		if (counter % 2 != 0){
			cc_array[counter]*=2;
		}
		digit_string+=cc_array[counter];
	}
	digit_sum=0;
	
	for (counter=0;counter<digit_string.length;counter++){
		current_digit=parseInt(digit_string.charAt(counter));
		digit_sum+=current_digit
	}
	
	if (digit_sum % 10 == 0){
		return true;
	}else{
		return false;
	}
	
}
//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);
}