
function getBounds(element) {
var left = element.offsetLeft;
var top = element.offsetTop;
for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
left += parent.offsetLeft;
top += parent.offsetTop;
}
return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

array_Obj=[];

function fly (obj) { // ?????? "??? ?????"
with (this) {
center_target_left = center_target_top = 0;
finish_fly = null;
//self.alert("iuuiuiui");
fly_div = document.getElementById('flyDiv');
fly_div.style.display = 'none';
fly_div.innerHTML = obj.innerHTML;
bounds_FLY = getBounds(obj);
fly_div.style.width = 56; //bounds_FLY.width + 'px';
fly_div.style.height = 56; //bounds_FLY.height + 'px';
}
}

fly.prototype.target = function (obj_targ) { // ?????? "???? ??????"
var bounds_target = getBounds(obj_targ);
this.center_target_left = bounds_target.left + bounds_target.width/2;
this.center_target_top = bounds_target.top + bounds_target.height/2;
}

fly.prototype.calc_way = function ( num_step, time_fly ) { //???-?? ?????, ????? ????????
this.num_step = num_step;
this.period = Math.ceil( time_fly / num_step );
}

fly.prototype.fly_now = function () { //????? ????
if (!this.step) {
this.step = 1;
this.id = array_Obj.length;
array_Obj[this.id]=this;
}

with (this) {
if ( step > num_step ) {
with (fly_div.style) {
display = 'none';
top = left = 0;
}
if (finish_fly) finish_fly();
step = 0;
delete array_Obj[id];
return;
}
fly_div.style.top = bounds_FLY.top - Math.ceil ( ( bounds_FLY.top - (center_target_top - bounds_FLY.height/2))/num_step * step ); + 'px';
fly_div.style.left = bounds_FLY.left + Math.ceil ( ((center_target_left - bounds_FLY.width/2) - bounds_FLY.left)/num_step * step ) + 'px';

if( step == 1 ) {
fly_div.style.display = '';
fly_div.style.zIndex='1000';
}
step++;
}
timerID = setTimeout( "array_Obj[" + this.id + "].fly_now()", this.period);
}

function DoFly(img){
//self.alert(document.getElementById(img));
var AddCartFly = new fly( document.getElementById(img) );        
        AddCartFly.target( document.getElementById('Recherche') );
        AddCartFly.calc_way(25, 25 );
        AddCartFly.finish_fly = function () {
        //document.getElementById('divinfopanier').innerHTML = 'en cours'    	    
        }
        AddCartFly.fly_now();    
}



function AjoutPanier(f,ID) {
LoadPanier();
FermerDiv('divdetailpanier');
var qte = eval('f.quantite_'+ID+'.value');
if (isNaN(qte)){qte=1;}
if((qte==0)||(qte>99)){qte=1;}
DoFly('fly_img_'+ID);
	  var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		self.alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/boutique/ajax_panier.asp?traitement=ajoutproduit&ID="+ID +"&QTE="+qte, true);
	        xhr_object.onreadystatechange = function() {
	        if(xhr_object.readyState == 4)	        		       
	        	//self.alert(xhr_object.responseText);
			try {
                            eval(xhr_object.responseText);
                        } catch (e) {
                            self.alert("Erreur:\n"+xhr_object.responseText);
                        }
			
	        	}
	        	//self.alert(qte + ' - ' + ID);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "";	
	        xhr_object.send(data);	       
	  	
}

function RefreshPanier(){
		//LoadPanier();
		var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		self.alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/boutique/ajax_panier.asp?traitement=refresh", true);
	        xhr_object.onreadystatechange = function() {
	        if(xhr_object.readyState == 4)	        		       
	        	
			try {
                            eval(xhr_object.responseText);
                        } catch (e) {
                            self.alert("Erreur:\n"+xhr_object.responseText);
                        }
			
	        	}
	        	//self.alert(qte + ' - ' + ID);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "";	
	        xhr_object.send(data);	
}

function DetailPanier() {
		//FermerDiv('divajoutpanier');
	  	var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		self.alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/boutique/ajax_panier.asp?traitement=detailpanier", true);
	        xhr_object.onreadystatechange = function() {
	        
	        if(xhr_object.readyState == 4)	        		       	        	
		//self.alert(xhr_object.responseText);
			try {
                            eval(xhr_object.responseText);
                        } catch (e) {
                            self.alert("Erreur:\n"+xhr_object.responseText);
                        }
			
	        	}
	        	//self.alert(qte + ' - ' + ID);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "";	
	        xhr_object.send(data);	       
	  	
}

function SuppProduit(ID) {
LoadPanier();
//FermerDiv('divdetailpanier');
		var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		self.alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/boutique/ajax_panier.asp?traitement=suppproduit&ID="+ID, true);
	        xhr_object.onreadystatechange = function() {
	        if(xhr_object.readyState == 4)	        		       
	        	
			try {
                            eval(xhr_object.responseText);
                        } catch (e) {
                            self.alert("Erreur:\n"+xhr_object.responseText);
                        }
			
	        	}
	        	//self.alert(qte + ' - ' + ID);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "";	
	        xhr_object.send(data);	       
	  	
}

function SuppProduitPanier(ID) {
SuppProduit(ID);
self.location.href="/boutique/panier.asp?maj=1";      	  	
}

function MajAjoutPanier(f,ID){
	AjoutPanier(f,ID);	
	self.location.href="/boutique/panier.asp?maj=1";
}