// JavaScript Document
function download(ruta)
{
	x=500;
	y=500;
	t=(screen.availHeight-y)/2;
	l=(screen.availWidth-x)/2;
	win=window.open(ruta,'download_win','status=yes,scrollbars=yes,resizable=yes,left='+l+',top='+t+',width='+x+',height='+y);
}
 
	
function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
 
  
  return newObject;
}

startList = function() {
	

}

window.onload=startList;
var last_content=false;
var prelast_content=false;
var last_id_item=false;
var id_area=false;


var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];var xmlDoc;for (var i = 0; i < prefixes.length; i++) {try {xmlDoc = new ActiveXObject(prefixes[i] + ".XMLDOM");	}catch (ex) 	{};}
function canvia_adreca(id)
{
	
	xmlDoc.async = false;
	xmlDoc.load(apps_url+"?action=ART_xml_modifica_adreca_entrega&id_adreca_entrega="+id);
	xmlObj = xmlDoc.documentElement;
	if(xmlObj.childNodes(0).getAttribute("value"))
	{
		//alert(xmlObj.childNodes(0).getAttribute("value"));
	}
}	
function ves_pagina(num,id)
{
	ajaxpage(apps_url+"?id="+id+"&no_index=true&next="+num,"content");
}

function preview(ruta)
{

	x=100;
	y=100;
	t=(screen.availHeight-y)/2;
	l=(screen.availWidth-x)/2;
	win=window.open(http_url+'preview.php?src='+ruta,'preview','status=yes,scrollbars=no,left='+l+',top='+t+',width='+x+',height='+y);
}
function tornar()
{
if(prelast_content){ajaxpage(prelast_content,'content');}else{history.back(0)}
}
function modifica_quantitat(id,valor)
{
	ajaxpage(apps_url+'?action=ART_modify_cart&id='+id+'&no_index=true&quantitat='+valor,'content');									ajaxpage(apps_url+'?action=ART_go_to_cart&plantilla=carro_simple.html&no_index=true','cistella');
}
function aplica_codi_promo(valor)
{
	ajaxpage(apps_url+'?action=ART_aplica_promo&no_index=true&codi='+valor,'content');										ajaxpage(apps_url+'?action=ART_go_to_cart&plantilla=carro_simple.html&no_index=true','cistella');
}
function modifica_quantitat_pres(id,id_detall,valor)
{
	ajaxpage(apps_url+'?action=CLI_pressupostos_modifica_pres&id='+id+'&id_detall='+id_detall+'&no_index=true&quantitat='+valor,'detalls_pres_'+id);
}

function add_to_carro(id_sub,id_item,promo,tipus,id_proveidor,bot_id_item)
{
	

	if(promo=="Y"  && tipus=="G")
	{
		if(confirm(veure_promocions_associades))
		{
			ajaxpage(apps_url+'?action=ART_promocions&id_subarticle='+id_sub+'&no_index=true','content');
			return false;
		}
	}
	if(bot_id_item==3155 && id_item!=3155)
	{
			ajaxpage(apps_url+'?id='+bot_id_item+'&no_index=true','content');
			return false;
	}
	else
	{
	ajaxpage(apps_url+'?action=ART_add_to_cart&id_subarticle='+id_sub+'&id_item='+id_item+'&plantilla=carro_simple.html&no_index=true&quantitat='+document.getElementById('qty_'+id_sub+'').value,'cistella');
	desplega_tooltip(id_sub);
	}
}
var last_id_color=false;
function colors(id) 
{
	if(last_id_color)
	{
		document.getElementById("color_quadre_"+last_id_color).style.display="none";
	}
	dist=distancies("color_"+id)
	obj=document.getElementById("color_quadre_"+id);
	obj.style.display="block";
	obj.style.top=dist["y"]+15+"px";
	obj.style.left=dist["x"]+"px";
	last_id=id;
}

function handleMouseMove() {
  var evento = elEvento || window.event;
  window.status = "Mouse: X="+evento.clientX;+",Y="+evento.clientY;
  return false;
}
function retorna_color(id,obj)
{
	document.getElementById("color_"+id).src=obj.src;
	document.getElementById("color_quadre_"+id).style.display="none";
}
function amaga(id)
{	
	obj=document.getElementById("color_quadre_"+id);
	Px=parseInt(obj.style.left.replace("px",""))+1;
	Py=parseInt(obj.style.top.replace("px",""))+2;
	amplada=obj.offsetWidth;
	altura=obj.offsetHeight;
	Mx=window.event.clientX;
	My=window.event.clientY;
//	alert(My+" "+Py+" "+altura);
	if((Mx>=(Px+amplada)
	 || Mx<=Px)
	 || (My>=(Py+altura)
	 || My<=Py))obj.style.display="none";

	//document.getElementById("color_quadre_"+id).style.display="none";
}
var last_id_item=false;
function carrega_enllac(id_item,id_enllac)
{
	try
	{
	document.getElementById('div_contenidor_'+id_item).style.display="block";
	document.getElementById("div_contenidor_fill_"+id_item).style.display="block";
	document.getElementById('img_'+id_item).style.display="block";
	document.getElementById('img_'+id_item).src=http_url+"/templates/PUBLIC/imgs/x_plegat.gif";
	ajaxpage(apps_url+'?id_plantilla=producte_no_ruta.html&no_index=true&id='+id_enllac,'sub_div_'+id_item);
	last_id_item=id_item;
		document.getElementById("amagar_"+id_item).style.display="none";
			
	}
	catch(e)
	{
		alert(e.name + " -- " + e.message)
	}
}
function ensenya_enllac(id_item)
{
	
	document.getElementById("amagar_"+id_item).style.display="block";
	/*document.getElementById('img_'+id_item).src=http_url+"/templates/PUBLIC/imgs/x_desplegat.gif";*/
	document.getElementById('img_'+id_item).style.display="none";
	document.getElementById("div_contenidor_fill_"+id_item).style.display="none";

}
function cercar(desc)
{
	valor=document.getElementById("buscar").value
	if(valor==desc)valor="";
	url="?action=cercar&no_index=true&tipus[0]=id_subarticle&desc="+valor;
	if(document.getElementById("mySelectBox").value>0)
	{
		url+="&botiga[id_caracteristica][3]="+document.getElementById("mySelectBox").value
	}
	
	return url;
	
}

function validar(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
   	patron = /\d/;  // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
} 

//patron = /\d/; // Solo acepta nmeros
//patron = /\w/; // Acepta nmeros y letras
//patron = /\D/; // No acepta nmeros
//patron =/[A-Za-z\s]/; // igual que el ejemplo, pero acepta tambin las letras  y 
 
function desplega_tooltip(bot) 
	{
	$('.e1').tooltip ('<span style="float:left;padding-right:5px;"><img src="'+http_url+'/templates/PUBLIC/imgs/carrito3.png" /></span><p style="float:left">'+sa_agregat+'</p>', { click: true, width: 240, style: 'coda', sticky: 1 }); 
    $('#ca_'+bot).bind('click', function() {
	 setTimeout(function() {$('#ca_'+bot).tooltip_hide(); }, 2000);
         });   
	
	}
function desmarca_alb(id)
{
	$('#alb_res_'+id).css({display:"none"});
	$('#alb_res_'+id).animate({
    opacity: 0}, '500', function() {
	});

	 $('#alb_'+id).css({display:""});
	 $('#alb_'+id).animate({
    opacity: 100}, '500', function() {});
	 
	totals_alb("resta",id)
}
function totals_alb(que,id)
{
	total_alb_ini=total_alb;
	if(que=="resta")
	{
		total_alb=(Math.round((total_alb-res_arr[id])*100)/100).toFixed(2);;
	}
	if(que=="suma")
	{
		total_alb=(Math.round(((total_alb*1) + (res_arr[id]*1))*100)/100).toFixed(2); ;
	}
	$('#total_alb').html(total_alb);
	if(total_alb_ini==0 && total_alb>0)
	{
		$('#resultat_compra').css({display: ""})
	}
	if(total_alb_ini>0 && total_alb==0)
	{
		$('#resultat_compra').css({display: "none"})
	}
}
var res_arr= new Array();
var total_alb=0;
function anima_alb(id,ruta,descripcio,preu,qty)
{
	
	$('#alb_'+id).animate({	
    opacity: 0}, '500', function() {	
	$("#alb_"+id).css({display:"none"});
	if(res_arr[id])	
	{
		
		$("#alb_res_"+id).css({display:""});
		$('#alb_res_'+id).animate({
   	 opacity: 100}, '500', function(){});
		$("#det_alb_"+id).attr('checked', true);	
	}
	else
	{
	res_arr[id]=preu;
    res='<tr  id="alb_res_'+id+'"><td><a rel="sexylightbox" href="{_HTTP_URL}foto.php?watermark=true&width=800&src='+ruta+'"><img src="'+http_url+'foto.php?watermark=true&src='+ruta+'&width=40&adjust=true&def=true" /></a></td><td>'+descripcio+'</td><td align="right">'+preu+'&euro;</td><td  align="center">'+qty+'</td><td  align="center"><input type="checkbox" checked name="id_detall['+id+']" id="det_alb_'+id+'" onclick="desmarca_alb('+id+')" value="'+id+'"</td></tr> ';
$("#resultat").html($("#resultat").html()+res);
SexyLightbox.refresh();
	}
	totals_alb("suma",id)
	
	
  });
}

        
         