/***************************************************
	catalogue.js
----------------------------------------------------
	Author  : 			Tommy Rochette [www.troisiemeoeil.ca] 
	Contact : 			tom@troisiemeoeil.ca
	Licence :			2006-2007 troisièmeOeil, ALL RIGHT RESERVED
	Created :			May 151th  2007
	Last modification:	May 15th  2007
-----------------------------------------------------
	Description : 
	Javascript control for catalogue pages
	
	!!!!Warning!!!!
	The change made in this file will be seen in all
	boutiqueflorin.com's catalogue pages.
----------------------------------------------------
	History of file
----------------------------------------------------
	2007-05-15 --> File created
***************************************************/ 

/***************************************************
	OnDomReady --> Called by mootools
***************************************************/

var Catalogue = {
	init: function () {
		var selectItems = document.getElementsByTagName("select");
	
		for( var i =0 ; i< selectItems.length; i++) {
			if(i==0) {
				selectItems[i].onchange = Catalogue.changeOrder;
			} else {
				selectItems[i].onchange = Catalogue.changeOrder1;
			}
		}

		if($('printFiche')) $('printFiche').onclick = function () {
			var path = window.location.href;
			path = path.substring(path.indexOf("no_produit="), path.length);
			popupWindow("impression_produits.php?"+path, "print_produits", 560, 360);
		}
		
		if($('zoomproduit')) {
			$('zoomproduit').rel = $('zoomproduit').href;
			$('zoomproduit').href = "javascript://";
			$('zoomproduit').onclick = function() {
				popupWindow(this.rel, "zoom_produit", 600, 560);
			}
		}
		
		if($('lien_pubtele'))  $('lien_pubtele').onclick = function () {
			popupWindow("pubtele/pubtele.php", "pubtele", 340, 310);
		}
	},
	
	changeOrder: function() {
		var fieldValue=document.getElementsByTagName("select")[0].value;
		if(fieldValue!=""){
			if(window.location.href.indexOf("ordre")!=-1){
				 var sUrl   = window.location.href;
					 sUrl   = sUrl.replace(/ordre=1/ ,"ordre="+fieldValue);
					 sUrl   = sUrl.replace(/ordre=2/ ,"ordre="+fieldValue);
					 sUrl   = sUrl.replace(/ordre=3/ ,"ordre="+fieldValue);			
				 window.location.href=sUrl;	 	 
			}else{
				 window.location.href=window.location.href+"&ordre="+fieldValue;
			}
		
		}
	},
	
	changeOrder1: function() {
		var fieldValue=document.getElementsByTagName("select")[1].value;
		if(fieldValue!=""){
			if(window.location.href.indexOf("ordre")!=-1){
				 var sUrl   = window.location.href;
					 sUrl   = sUrl.replace(/ordre=1/ ,"ordre="+fieldValue);
					 sUrl   = sUrl.replace(/ordre=2/ ,"ordre="+fieldValue);
					 sUrl   = sUrl.replace(/ordre=3/ ,"ordre="+fieldValue);			
				 window.location.href=sUrl;	 	 
			}else{
				 window.location.href=window.location.href+"&ordre="+fieldValue;
			}
		}
	}
}


function popupWindow(url, nom, largeur, hauteur) {
	var vOptions="menubar=no,scrollbars=no,statusbar=no";
	var haut=(screen.height-hauteur)/2;
	var gauche=(screen.width-largeur)/2;
	portfolio=window.open(url,nom,"top="+haut+",left="+gauche+",width="+largeur+",height="+hauteur+","+vOptions);
}


window.addEvent('load', Catalogue.init);