/*--------------------------------------------------------------------------------------
	JS Document (Javascript)

	project:	LONGCHAMP
	created:	2008-04-15 (yyy-mm-dd)
	modified:	2008-04-15 (yyy-mm-dd)
	author:		Yves Van Goethem
	email:		yvangoethem@digitas.com
	website:	http://www.digitas.fr

	Summary :	
-------------------------------------------------------------------------------------- */


/*	=Comparator
-------------------------------------------------------------------------------------- */

var Comparator = function() {
	var d = document;
	var list = $('listArticles');
	var choices = [];
	var choicesElm = [];
	var url = window.location.protocol+'//'+window.location.host+window.location.pathname;

	var crawlArticles = function() {
		for (var i = 0; i < list.getElementsByTagName('*').length; i++) {
			if (list.getElementsByTagName('*')[i].id.split('compareChoice')[1]) {
				choicesElm.push(list.getElementsByTagName('*')[i]);
				choices.push(null);
				list.getElementsByTagName('*')[i].onclick = function() {
					checkArticles(this, this.id);
				};
			}

            /****************************/
           	if (list.getElementsByTagName('*')[i].id.split('deleteChoice')[1]) {

				list.getElementsByTagName('*')[i].onclick = function() {
					//checkArticles(this, this.id);
                   // console.log(url+'?action=del&id='+this.value);
                    document.location.href = url+'&action=del&id='+this.value;
                    
				};
			}
           
           
            
		}
	};
	
	var checkArticles = function(elm, id) {
		var pos = elm.id.split('compareChoice')[1];
		var _checkFunction = function(x) {
			for (var i = 0; i < choicesElm.length; i++) {
				if (!choicesElm[i].checked)
					choicesElm[i].disabled = x;
			}
		};
		var _checkBtn = function(x) {
			__linkOn = function() {
				document.getElementById('popinComparateur').onclick = function() {
					var elmt = document.getElementById('popinComparateur');

                    var super1 = choices.compact().first();
                    var super2 = choices.compact().last();
                    
					Modalbox.show('/FRONT/LONGCHAMP/include/whishlist_comparateur.php?super1='+super1+'&super2='+super2+'&lan_s_id='+$('lan_s_id').value+'&coe_i_id='+$('coe_i_id').value, {title: ' ', width: 760, closeString: 'fermer', currentClass: elmt.className, afterLoad: function(){
						// une fois le fichier externe load�
						getPageReadyOnLoad();
						initScrollbars('wishlistComparatorContent','scrollPanier','verticalHandle','verticalTrack');
						initColors("wc");
					}});
				};
			};
			__linkOff = function() {
				document.getElementById('popinComparateur').onclick = function() {
					return;
				};
			};
			var btn = $('comparatorBtn');
			if (x == true) {
				btn.src = btn.src.replace(/_off.gif$/,'_green.gif');
				__linkOn();
			}
			else if (x == false) {
				btn.src = btn.src.replace(/_green.gif$/,'_off.gif');
				__linkOff();
			}
		};
		if (choices.compact().length >= 2 && elm.checked) {
			elm.checked = false;
			return false;
		}
		else if (elm.checked) {
			choices[pos] = elm.value;
			if (choices.compact().length >= 2) {
				_checkFunction(true);
				_checkBtn(true);
			}
		}
		else if (!elm.checked) {
			choices[pos] = null;
			if (choices.compact().length < 2) {
				_checkFunction(false);
				_checkBtn(false);
			}
		}
	};
	
	return {
		crawl : crawlArticles
	}
};



Event.observe(window,"load",function() {
// window.onload = function() {
	var azx = new Comparator();
	azx.crawl();
// };
});



