function ventanita3 (URL){
      ventana = window.open(URL,"Recomendar","width=480,height=420,top=70,left=500, scrollbars=NO, menubar=NO,toolbar=NO");
	  ventana.focus();
}


// JavaScript Document
var newsfont = 12; 
function changeFont(id) { 
	if (document.getElementById) { 
			document.getElementById(id).style.fontSize = newsfont+"px"; 
		} else { 
			if (document.layers) { 
				document.layers[id].fontSize = newsfont+"px"; 
			} else { 
				if (document.all) { 
					eval("document.all." + id + ".style.fontSize = \"" + newsfont + "px \""); 
				} 
			} 
		} 
		 
		// esto arregla scroll al utilizar layers 
	//    updateHeight();  
	
} 
// aqui se produce el error 
function larger() { 
    if (newsfont < 20) { 
        newsfont= newsfont +1; 
        changeFont('center-in'); 
    } 
} 

function smaller() { 
    if (newsfont > 10) { 
    newsfont= newsfont -1; 
    changeFont('center-in'); 
    } 
}

/*CARRITO*/

function oNumero(numero)

{

//Propiedades

this.valor = numero || 0

this.dec = -1;

//Métodos

this.formato = numFormat;
this.ponValor = ponValor;

//Definición de los métodos

function ponValor(cad)

{

if (cad =='-' || cad=='+') return

if (cad.length ==0) return

if (cad.indexOf('.') >=0)

    this.valor = parseFloat(cad);

else

    this.valor = parseInt(cad);

}

function numFormat(dec, miles){

	var num = this.valor, signo=3, expr;

	var cad = ""+this.valor;

	var ceros = "", pos, pdec, i;

	

	for (i=0; i < dec; i++)

		ceros += '0';

		pos = cad.indexOf('.')

		if (pos < 0)

			cad = cad+"."+ceros;

		else{

			pdec = cad.length - pos -1;

			if (pdec <= dec)

				{

				for (i=0; i< (dec-pdec); i++)

					cad += '0';

				}

			else

				{

				num = num*Math.pow(10, dec);

				num = Math.round(num);

				num = num/Math.pow(10, dec);

				cad = new String(num);

				}

		 }

		pos = cad.indexOf('.')

		if (pos < 0) pos = cad.lentgh

		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+')

			   signo = 4;

		if (miles && pos > signo)

			do{

				expr = /([+-]?\d)(\d{3}[\.\,]\d*)/

				cad.match(expr)

				cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)

				}

		while (cad.indexOf(',') > signo)

			if (dec<0) cad = cad.replace(/\./,'')

				return cad;

		}
		
		

}//Fin del objeto oNumero:


function actualizar(param){
			var precio_unidad;
			var precio_unidad_iva;
			var cantidad;						
			var total_sin_iva;
			var iva_total;
			var stock;

			cantidad = eval("document.getElementById('cantidad_"+param+"').value");
			precio_unidad = eval("document.getElementById('hid_precio_" +param+"').value");
			precio_unidad_iva = eval("document.getElementById('hid_iva_"+param+"').value");
			stock = eval("document.getElementById('stock_"+param+"').value");			
			
			cantidad = cantidad.replace(".","");		
			aux = eval("document.getElementById('cantidad_"+param+"').value='"+cantidad+"';");
			
			//Primero compruebo que lo que se introduce es número
			if (isNaN(cantidad)){
				alert('El valor introduït ha de ser numèric');
				aux= eval("document.getElementById('cantidad_"+param+"').value='1'");
				cantidad = 1;
				aux= eval("document.getElementById('cantidad_"+param+"').focus()");
				aux= eval("document.getElementById('cantidad_"+param+"').select()");							
				//return false;
			}
			
			if (parseInt(stock) < parseInt(cantidad)){
				alert('No disposem de tal estoc, únicament tenim '+stock+' unitats');
				aux= eval("document.getElementById('cantidad_"+param+"').value='1'");
				cantidad = 1;
				aux= eval("document.getElementById('cantidad_"+param+"').focus()");
				aux= eval("document.getElementById('cantidad_"+param+"').select()");							
				//return false;
			}
			
			//actualizo el item
			var numero = new oNumero(cantidad*precio_unidad);	
			aux = eval("document.getElementById('d_base_total_"+param+"').innerHTML='"+ numero.formato(2,false).replace(".",",") +"'");
			
			numero = new oNumero(cantidad*precio_unidad_iva);
			aux = eval("document.getElementById('d_iva_total_"+param+"').innerHTML='"+ numero.formato(2,false).replace(".",",") +"'");
			
			numero = new oNumero((cantidad*precio_unidad) + (cantidad*precio_unidad_iva));
			aux = eval("document.getElementById('d_total_"+param+"').innerHTML='"+ numero.formato(2,false).replace(".",",") +"'");
			
			
			/*Actualizo la cantidad en la temporal*/ //LA RUTA HABRÄ QUE CAMBIARLA
			if (cantidad != ""){
				document.getElementById('frame_carrito').src='http://www.tresiquatre.com/includes/carrito_modificar_cantidad.asp?ca_id='+param+'&cantidad='+cantidad;
			}
			
			return saca_totales();
					
}

function no_vacio(param){
	 cantidad = eval("document.getElementById('cantidad_"+param+"').value");
	 if (cantidad == ""){
		alert('El valor introduït ha de ser numèric');
		aux= eval("document.getElementById('cantidad_"+param+"').value='1'");
		aux= eval("document.getElementById('cantidad_"+param+"').focus()");
		aux= eval("document.getElementById('cantidad_"+param+"').select()");
	 }
}

function saca_totales(){
 	var supertotal_bases = 0;
	var supertotal_ivas = 0;
	var supertotal_total = 0;

	for (j = 0; j < document.forms.form_compra.elements.length; j++){
			if (document.forms.form_compra.elements[j].name.substring(0,9)=='cantidad_'){
				aux = document.forms.form_compra.elements[j].name.substring(9);
				
				cantidad = eval("document.getElementById('cantidad_"+aux+"').value");
				precio_unidad = eval("document.getElementById('hid_precio_" +aux+"').value");
				precio_unidad_iva = eval("document.getElementById('hid_iva_"+aux+"').value");

				supertotal_bases = supertotal_bases + (cantidad * precio_unidad);
				supertotal_ivas = supertotal_ivas + (cantidad * precio_unidad_iva);
				//total = base_total + iva_total;
			}

	}

	supertotal_total = supertotal_bases + supertotal_ivas;

	var numero = new oNumero(supertotal_bases);
	aux = eval("document.getElementById('d_supertotal_bases').innerHTML='"+ numero.formato(2,true).replace(".",",") +" €'");
	
	
	var numero = new oNumero(supertotal_ivas);
	aux = eval("document.getElementById('d_supertotal_ivas').innerHTML='"+ numero.formato(2,true).replace(".",",") +" €'");

	
	var numero = new oNumero(supertotal_total);
	aux = eval("document.getElementById('d_supertotal_total').innerHTML='"+ numero.formato(2,true).replace(".",",") +" €'");

	return true;

 }
 
 
 function eliminar_item(param){
	if (confirm("Aquesta acció eliminarà el producte de la cistella ")){
		eval("document.getElementById('tr_"+param+"').style.display='none';");
		eval("document.getElementById('tr_"+param+"').style.visibility='hidden';");	
		eval("ob = document.getElementById('cantidad_"+param+"');");
		padre = ob.parentNode;
		padre.removeChild(ob);
		return saca_totales();
	}else{
		return false;	
	}	
 }
 
 
 function copiar_datos(){
		document.getElementById('us_nombre_entrega').value = document.getElementById('us_nombre').value;
		document.getElementById('us_direccion_entrega').value = document.getElementById('us_direccion').value;
		document.getElementById('us_poblacion_entrega').value = document.getElementById('us_poblacion').value;
		document.getElementById('us_provincia_entrega').value = document.getElementById('us_provincia').value;
		document.getElementById('us_codigo_postal_entrega').value = document.getElementById('us_codigo_postal').value;
		actualiza_mensajeria();
 }
 
 
 
 
 function comprobar_datos_personales(param){
	 //Param:0->tengo en cuenta las restricciones en el campo mail y password, 1->No Lo hago
	  
		 
     var str;
	 document.getElementById('er_nombre').style.visibility='hidden';
	 //document.getElementById('er_cif').style.visibility='hidden';
	 document.getElementById('er_direccion').style.visibility='hidden';
	 document.getElementById('er_poblacion').style.visibility='hidden';
	 document.getElementById('er_provincia').style.visibility='hidden';
	 document.getElementById('er_codigo_postal').style.visibility='hidden';
	 
	 document.getElementById('er_nombre_entrega').style.visibility='hidden';
	 document.getElementById('er_direccion_entrega').style.visibility='hidden';
	 document.getElementById('er_poblacion_entrega').style.visibility='hidden';
	 document.getElementById('er_provincia_entrega').style.visibility='hidden';
	 document.getElementById('er_codigo_postal_entrega').style.visibility='hidden';
     document.getElementById('er_telefono').style.visibility='hidden';
	 
	 if (param == 0){
		 document.getElementById('er_email').style.visibility='hidden';
		 document.getElementById('er_password').style.visibility='hidden';
		 document.getElementById('er_password2').style.visibility='hidden'; 
	 }
	 	
	 str = document.getElementById('us_nombre').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_nombre').style.visibility='visible';
		 document.getElementById('us_nombre').focus();
		 return false;
	 }
	 
	 
	 
	 str = document.getElementById('us_direccion').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_direccion').style.visibility='visible';
		 document.getElementById('us_direccion').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_poblacion').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_poblacion').style.visibility='visible';
		 document.getElementById('us_poblacion').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_telefono').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_telefono').style.visibility='visible';
		 document.getElementById('us_telefono').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_codigo_postal').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_codigo_postal').style.visibility='visible';
		 document.getElementById('us_codigo_postal').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_provincia').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str=="" || str=="0"){
		 document.getElementById('er_provincia').style.visibility='visible';
		 document.getElementById('us_provincia').focus();
		 return false;
	 }
	 
	 
	 
	 
	 str = document.getElementById('us_nombre_entrega').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_nombre_entrega').style.visibility='visible';
		 document.getElementById('us_nombre_entrega').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_direccion_entrega').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_direccion_entrega').style.visibility='visible';
		 document.getElementById('us_direccion_entrega').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_poblacion_entrega').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_poblacion_entrega').style.visibility='visible';
		 document.getElementById('us_poblacion_entrega').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_codigo_postal_entrega').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_codigo_postal_entrega').style.visibility='visible';
		 document.getElementById('us_codigo_postal_entrega').focus();
		 return false;
	 }
	 
	 str = document.getElementById('us_provincia_entrega').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str=="" || str=="0"){
		 document.getElementById('er_provincia_entrega').style.visibility='visible';
		 document.getElementById('us_provincia_entrega').focus();
		 return false;
	 }
	 
	 
	 
	 if (str=="10000"){
		alert("Per a enviaments fora del estat espanyol ha de posar-se en contacte amb nosaltres en la següent adreça de correu electrònic: compres@tresiquatre.com");
		return false; 
	 }
	 
	 
	 
	 str = document.getElementById('us_cif').value;
	 str = str.replace(/^\s*|\s*$/g,"");
	 if (str==""){
		 document.getElementById('er_cif').style.visibility='visible';
		 document.getElementById('us_cif').focus();
		 if (confirm('No ha introduït el seu NIF/CIF, no se li emetrà factura. Continuar? ')){
			 
		 }else{
			 return false;
		 }
	 }
	 
	 /*
	  entra = 0;
	  for (var i = 0; i<document.f_datos_personales.us_mensajeria.length; i++){
			if (document.f_datos_personales.us_mensajeria[i].checked ){
				entra = 1;
			}
	  }
	  
	  if (entra==0){
		 document.getElementById('er_mensajeria').style.visibility='visible';
		 return false;
	  }
	  */
	  
	 
	 if (param == 0){
		 str = document.getElementById('us_email').value;
		 str = str.replace(/^\s*|\s*$/g,"");
		 if (str==""){
			 document.getElementById('er_email').innerHTML=' Camp obligatori';
			 document.getElementById('er_email').style.visibility='visible';
			 document.getElementById('us_email').focus();
			 return false;
		 }

		 if(str.search(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ig)){
			document.getElementById('er_email').innerHTML=' Email incorrecte';
			document.getElementById('er_email').style.visibility='visible';
			document.getElementById('us_email').focus();
			return false;  
		 } 
		 
		 str = document.getElementById('us_password').value;
		 str = str.replace(/^\s*|\s*$/g,"");
		 if (str==""){
			 document.getElementById('er_password').innerHTML=' Camp obligatori';
			 document.getElementById('er_password').style.visibility='visible';
			 document.getElementById('us_password').focus();
			 return false;
		 }
		 
		 str = document.getElementById('us_password2').value;
		 str = str.replace(/^\s*|\s*$/g,"");
		 if (str==""){
			 document.getElementById('er_password2').innerHTML=' Camp obligatori';
			 document.getElementById('er_password2').style.visibility='visible';
			 document.getElementById('us_password2').focus();
			 return false;
		 }
		 
		 if (document.getElementById('us_password').value != document.getElementById('us_password2').value){
			 document.getElementById('er_password').innerHTML=' les contrasenyes no coincideixen.';
			 document.getElementById('er_password').style.visibility='visible';
			 document.getElementById('us_password2').focus();
			 return false;
		 }
 
	 }
	
	//Vector para la comprobacion de las provincias con el código postal. La posición es el id
	v = new Array(360);
	v[298] = "01";
	v[299] = "02";
	v[300] = "03";
	v[301] = "04";
	v[302] = "05";
	v[303] = "06";
	v[304] = "07";
	v[305] = "08";
	v[306] = "09";
	v[307] = "10";
	v[308] = "11";
	v[309] = "12";
	v[310] = "13";
	v[311] = "14";
	v[312] = "15";
	v[313] = "16";
	v[314] = "17";
	v[315] = "18";
	v[316] = "19";
	v[317] = "20";
	v[318] = "21";
	v[319] = "22";
	v[320] = "23";
	v[321] = "24";
	v[322] = "25";
	v[323] = "26";
	v[324] = "27";
	v[325] = "28";
	v[326] = "29";
	v[327] = "30";
	v[328] = "31";
	v[329] = "32";
	v[330] = "33";
	v[331] = "34";
	v[332] = "35";
	v[333] = "36";
	v[334] = "37";
	v[335] = "38";
	v[336] = "39";
	v[337] = "40";
	v[338] = "41";
	v[339] = "42";
	v[340] = "43";
	v[341] = "44";
	v[342] = "45";
	v[343] = "46";
	v[344] = "47";
	v[345] = "48";
	v[346] = "49";
	v[347] = "50";
	v[348] = "51";
	v[349] = "52";
	
	
	if (v[document.getElementById('us_provincia').value] != document.getElementById('us_codigo_postal').value.substring(0,2)){
		alert('En la adreça fiscal el codi postal no coincideix amb la província ');
		return false;
	}
	
	if (v[document.getElementById('us_provincia_entrega').value] != document.getElementById('us_codigo_postal_entrega').value.substring(0,2)){
		alert('En la adreça de lliurament el codi postal no coincideix amb la província ');
		return false;
	}
	
	return true;
 }

 
 
 function cierra(){
	parent.$('#dialog').jqmHide();	
	parent.$('#dialog').html("");
 }

