jQuery.noConflict(); 
jQuery(document).ready(function(){
	
	// 
	jQuery("#uiCalendar4507482068042614 .active").live("click",function() {
		// Act on the event
		jquery("#DateStart").focus()
	});
	jQuery(".calendarIcon").live("click",function() {
		// Act on the event
		
		jQuery(this).prev().focus()
	});
	
	
	var goUp = false;
	
	dropdownUp = function(){ // MOVE DROPDOWN UP
		if(goUp == true){
			jQuery(".dropdown .content").animate({
				marginTop:"-370px"
			},function(){
				jQuery(".dropdown").css("height","0px")
			})
		}
	}
	
	/* DROPDOWN HEADER */
	var paddingDropdown = jQuery("#citySelect").width() +5
	jQuery(".dropdown").css("marginLeft",paddingDropdown)
	jQuery("#citySelect").hover(function(){ // ON HOVER DROPDOWN APPEAR
		jQuery(".dropdown .content").stop()
		jQuery("#classification_option,#category_option,#category").css('display','none')
		jQuery(".dropdown").css("height","330px")
		goUp = false
		
		jQuery(".dropdown .content").animate({
			marginTop:"0px"
		})
		
	},
	function(){ //ROLLOUT
		goUp = true
		jQuery("#classification_option,#category_option,#category").css('display','block')
		setTimeout("dropdownUp()",1000) // HOVER DROPDOWN?
	})
	
	
	jQuery(".dropdown").hover(function(){ // ON HOVER DROPDOWN APPEAR
		goUp = false
		jQuery("#classification_option,#category_option,#category").css('display','none')
	},
	function(){ // ROLLOUR
		goUp = true
		jQuery("#classification_option,#category_option,#category").css('display','block')
		setTimeout("dropdownUp()",500) // HOVER DROPDOWN?
	})
	
	/* DROPDOWN SLIDERS */
	var firstCity = jQuery(".dropdown .content div:first").attr("class")
	if(firstCity == "quebec"){
		jQuery(".quebec").css("marginLeft","0px")
		jQuery(".ontario").css("marginLeft","-330px")
	}else{
		jQuery(".ontario").css("marginLeft","0px")
		jQuery(".quebec").css("marginLeft","-330px")
	}
	
	
	jQuery("a.flecheRegion").click(function(){ // SLIDER 
		ontarioMargin = jQuery(".ontario").css("marginLeft")
		if(ontarioMargin == "0px"){
			jQuery(".quebec").animate({marginLeft:"0px"})
			
			jQuery(".ontario").animate({
				marginLeft:"330px"
			},function(){
				jQuery(".ontario").css("marginLeft", "-330px")  // MOVE ONTARIO BEFORE QUEBEC
			})
		}else{
			jQuery(".ontario").animate({marginLeft:"0px"})
			
			jQuery(".quebec").animate({
				marginLeft:"330px"
			},function(){
				jQuery(".quebec").css("marginLeft", "-330px") // MOVE QUEBEC BEFORE ONTARIO
			})
		}
		return false;
	})
		
	//jQuery("embed").attr("wmode", "transparent")
	//jQuery("embed").css("zIndex", "1")
	/* PRINT PAGE LINK */
	jQuery("li.print a").click(function(){
		window.print();
		return false;
	})
	
	/* TOOL.phtml CHANGEMENT DE FONT_SIZE */
	jQuery("a.smallText").click(function(){
		jQuery("body").css("fontSize","11px");
		return false;
	})
	jQuery("a.bigText").click(function(){
		jQuery(".tools").css("fontSize","11px");
		jQuery("body").css("fontSize","13px");
		return false;
	})
	
	/* SEND TO A FRIEND MODAL WINDOW */
	jQuery("a.openModal").live("click",function(){
		jQuery(".errorArrow01").css('display','none'); 
		modalToOpen = "#" +jQuery(this).attr("rel")	
		jQuery(".modalWindow").animate({
				opacity:0 					// INTERCHANGE MODAL WINDOWS
			},function(){
				jQuery(".modalWindow").css("display","none")
				jQuery(modalToOpen).css("display","block")
				jQuery(modalToOpen).animate({
					opacity:1				// MODAL WINDOW APPREAR
				})
		})
		return false;
	})
	jQuery(".closeModal").live("click",function(){ closeModal();jQuery(".errorArrow01").css('display','none'); return false;})
	function closeModal(){
		
		jQuery(".modalWindow").animate({
			opacity:0
		},function(){
			jQuery(".modalWindow").css("display","none")
		})
		modalOpen = false;
	}
});

	function onTv(numberDisplay){
		var liSize = $("li.listt").size()
		liSize -=1

		$(".discoverProg li.listt").css("opacity",0)
		// DISPLAY FIRST 3
		if(numberDisplay== 3){
			$(".discoverProg li.listt").eq(0).addClass("firstColt")
			$(".discoverProg li.listt").eq(0).addClass("firstColt")
			$(".discoverProg li.listt").eq(1).addClass("secondColt")
			$(".discoverProg li.listt").eq(2).addClass("thirdColt")
			$(".discoverProg li.listt").eq(0).css("display","block")
			$(".discoverProg li.listt").eq(1).css("display","block")
			$(".discoverProg li.listt").eq(2).css("display","block")
			$(".discoverProg li.listt").eq(0).css("opacity","1")
			$(".discoverProg li.listt").eq(1).css("opacity","1")
			$(".discoverProg li.listt").eq(2).css("opacity","1")
		}else{
			$(".discoverProg li.listt").eq(0).addClass("firstColt")
			$(".discoverProg li.listt").eq(0).css("display","block")
			$(".discoverProg li.listt").eq(0).css("opacity","1")
		}
			

		
		if(liSize > 2){
			var onTvInterval = setInterval("ontvDisplay()",6500)
		}
		// FADE INTERVAL
		ontvDisplay = function(){
			var ramdomLiFadeOut = Math.floor(Math.random()*numberDisplay) 		// RANDOM POSITION AFFICHER
		
			var randomLifadeIn = randomXToY(numberDisplay,liSize)				// RANDOM POSITTION NOUVEAU CONTENT
		
			// FADE DEPENDING OF THEIR POSITION
			if(ramdomLiFadeOut == 0){
				leftDisplay= "firstColt"
			}
			if(ramdomLiFadeOut == 1){
				leftDisplay= "secondColt"
			}
			if(ramdomLiFadeOut == 2){
				leftDisplay= "thirdColt"
			}
		
			$(".discoverProg li."+leftDisplay).animate({opacity: 0}, 700, function() {
				// stuff to do after animation is complete
				
				//INTERCHANGE CONTENT
				var oldContent = $(".discoverProg li."+leftDisplay).html()
				var newContent = $(".discoverProg li.listt").eq(randomLifadeIn).html()
				
				$(".discoverProg li."+leftDisplay).html(newContent)
				$(".discoverProg li.listt").eq(randomLifadeIn).html(oldContent)
			  
			 	$(".discoverProg li."+leftDisplay).animate({opacity: 1}, 700)
			  
			})
			function randomXToY(minVal,maxVal,floatVal){
			  var randVal = minVal+(Math.random()*(maxVal-minVal));
			  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
			}
			
		}
	}
	
	function onTvShow(numberDisplay){
		var liSize = jQuery("li.listt").size()
		liSize -=1
	
		jQuery(".showListingPicks li.listt").css("opacity",0)
		// DISPLAY FIRST 3

			jQuery(".showListingPicks li.listt").eq(0).addClass("firstColt")
			jQuery(".showListingPicks li.listt").eq(0).css("display","block")
			jQuery(".showListingPicks li.listt").eq(0).css("opacity","1")
	
		if(liSize >= 1){
			var onTvInterval = setInterval("ontvDisplay()",6500)
		}
		// FADE INTERVAL
		ontvDisplay = function(){

			var ramdomLiFadeOut = Math.floor(Math.random()*numberDisplay) 		// RANDOM POSITION AFFICHER
		
			var randomLifadeIn = randomXToY(numberDisplay,liSize)				// RANDOM POSITTION NOUVEAU CONTENT
			// FADE DEPENDING OF THEIR POSITION
			if(ramdomLiFadeOut == 0){
				leftDisplay= "firstColt"
			}
			if(ramdomLiFadeOut == 1){
				leftDisplay= "secondColt"
			}
			if(ramdomLiFadeOut == 2){
				leftDisplay= "thirdColt"
			}
		
			jQuery(".showListingPicks li."+leftDisplay).animate({opacity: 0}, 700, function() {
				// stuff to do after animation is complete
				
				//INTERCHANGE CONTENT
				var oldContent = jQuery(".showListingPicks li."+leftDisplay).html()
				var newContent = jQuery(".showListingPicks li.listt").eq(randomLifadeIn).html()
				
				jQuery(".showListingPicks li."+leftDisplay).html(newContent)
				jQuery(".showListingPicks li.listt").eq(randomLifadeIn).html(oldContent)
			  
			 	jQuery(".showListingPicks li."+leftDisplay).animate({opacity: 1}, 700)
			  
			})
			function randomXToY(minVal,maxVal,floatVal){
			  var randVal = minVal+(Math.random()*(maxVal-minVal));
			  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
			}
			
		}
	}
	function psaAlert(){
		var liSize = jQuery(".alert").size()
		liSize -=1
	
		jQuery(".alert").css("opacity",0)

		// DISPLAY FIRST 3

			jQuery(".alert").eq(0).addClass("firstColt")
			jQuery(".alert").eq(0).css("display","block")
			jQuery(".alert").eq(0).css("opacity","1")
	
		if(liSize >= 1){
			var alertInterval = setInterval("alertDisplay()",6500)
		}
		// FADE INTERVAL
		alertDisplay = function(){
					
			var numberDisplay = 0
		
			var randomLifadeIn = randomXToY(numberDisplay,liSize)				// RANDOM POSITTION NOUVEAU CONTENT
			// FADE DEPENDING OF THEIR POSITION
			jQuery(".alert").animate({opacity: 0}, 700, function() {
				// stuff to do after animation is complete
				jQuery(".alert").css("display","none")

			 	 jQuery(".alert").eq(randomLifadeIn).css("display","block")
			 	jQuery(".alert").eq(randomLifadeIn).animate({opacity: 1}, 700)
			  
			})
			function randomXToY(minVal,maxVal,floatVal){
			  var randVal = minVal+(Math.random()*(maxVal-minVal));
			  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
			}
			
		}
	}


function displayScreenClass() {
	var c1 = jml.obj, c2 = jml.xml.node, c3 = jml.events, c4 = jml.browser;
	var scr;
	return {
		$:function(){return this;},
		display : function(o, s) {
			if (!isset(scr)) {
				scr = {};
				scr.ctn = c2.create('DIV', document.body);
				scr.msg = c2.create('DIV', scr.ctn);
			}
			if (!isset(scr.ctn) || !isset(scr.msg)) return;
			c1.set(scr.msg, 'innerHTML', s);
			c1.set(scr.ctn, 'className', 'displayScreenContainer');
			c1.set(scr.msg, 'className', 'displayScreenMessage');
			if (c1.get(scr.ctn, 'display') == 'none') c1.set(scr.ctn, 'display', 'block');
			var n1 = c1.get(o, 'offsetWidth'), n2 = c1.get(o, 'offsetHeight');
			if(n1 < 0) n1 = 0;
			if((n2 - 8) < 0) n2 = 8;
			c1.set(scr.ctn, 'width', n1 + 'px');
			c1.set(scr.ctn, 'height', (n2 - 8) + 'px');
			var n3 = c1.get(scr.ctn, 'offsetWidth'), n4 = c1.get(scr.ctn,'offsetHeight');
			c1.set(scr.ctn, 'left', (c1.get(o, 'offsetLeft') - Math.floor((n3 - n1) / 2)) + 'px');
			c1.set(scr.ctn, 'top', (c1.get(o, 'offsetTop') - Math.floor((n4 - n2) / 2)) + 'px');
			c1.set(scr.msg, 'left', Math.floor((n3 / 2)	- (c1.get(scr.msg, 'offsetWidth') / 2)) + 'px');
			c1.set(scr.msg, 'top', Math.floor((n4 / 2) - (c1.get(scr.msg, 'offsetHeight') / 2)) + 'px');
		},
		remove : function(b) {
			var b = b || false;
			if(!isset(scr.ctn)) return;
			if(b) c2.remove(scr.ctn);
			if(!b) c1.set(scr.ctn, 'display', 'none');
		}
	}.$();
}

function genericPrototype(url, successFunc, method, parameters) {
	
	method = !isset(method) ? 'post' : method;
	successFunc = !isset(successFunc) ? 'emptyFct' : successFunc;
	//window.scrollTo(0, 100); 

	if (isset(parameters)) {
		new Ajax.Request(url, {
			method :method,
			parameters :parameters,
			onSuccess :eval(successFunc),
			onFailure :failureFunc
		});
	} else {
		if(successFunc == "reloadSocialToolsLinkCbk"){
			jQuery.post(url,{
			 param1: "value1", param2: "value2"},
			 function(transport){
				jQuery('.PSAGeneralTools').html(transport);
			});
			
		}else{
			new Ajax.Request(url, {
				method :method,
				onSuccess :eval(successFunc),
				onFailure :failureFunc
			});
		}	
	}
	
}

function failureFunc(response) {
	errorMessageForm(response.error);
}

function emptyFct(response) {
	return;
}

// Home page
function tabClass( tabId , titleId , tabContentId ){
	var c1 = jml.obj ;
	var c2 = jml.xml.node ;
	var c3 = jml.events ;
	var tabId = tabId || null ;
	var titleId = titleId || null ;
	var tabContentId = tabContentId || null ;
	var index ;
	var intl ;
	var tabItem , titleItem , tabContentItem ;
	if( !isset( tabId ) || !isset( titleId ) || !isset( tabContentId ) ) return ;
	function initialize(){
		tabItem = getObj( tabId ) ;
		titleItem = getObj( titleId ) ;
		tabContentItem = getObj( tabContentId ) ;
		if( !isset( tabItem ) || !isset( titleItem ) || !isset( tabContentItem ) ) return ;
		clickItem( null , null , 0 ) ;
		setAction( tabItem ) ;
		intl = setInterval( changeContent , 6000 ) ;
	}
	function changeContent(){
		clickItem( null , null , index == 0 ? 1 : 0 , true ) ;
	}
	function clickItem( e , o , n , b ){
	
		if( isset( o ) && c1.get( o , "alpha" ) != 100 ) return ;
	
		var b = b || false ;
		if( !b ) clearInterval( intl ) ;
		if( index == n ) return ;
		hideExceptIndex( titleItem , n ) ;
		hideExceptIndex( tabContentItem , n ) ;		
		hideFletchExceptIndex( tabItem , n );
		index = n ;
	}
	function setAction( container ){
		for( var i = 0 ; i < c2.length( container ) ; i++ ){
			var x1 = c2.byPosition( i , container ) ;
			c3.add( x1 , "click" , delegate( null , clickItem , x1 , i ) ) ;
		}		
	}
	function hideFletchExceptIndex( container , index ){
		for( var i = 0 ; i < c2.length( container ) ; i++ ){
			var x1 = c2.byPosition( i , container ) ;
			c1.set( x1 , "alpha" , i == index? "30" : "100" ) ;
			c1.set( x1 , "cursor" , i == index? "default" : "pointer" ) ;
		}
	}	
	function hideExceptIndex( container , index ){
		for( var i = 0 ; i < c2.length( container ) ; i++ ){
			var x1 = c2.byPosition( i , container ) ;
			c1.set( x1 , "display" , i == index? "block" : "none" ) ;
		}
	}
	return {
		initialize : initialize
	} ;
}

function toolsClass() {
	var host;
	return {
		$ : function() {
			return host = this;
		},
		SendFriend : function() {
			$('sendfrienderror').update();
			$('savingmsg').style.display = 'block';
			genericPrototype(host.urlSendFriend, 'sendFriendCbk', 'post', Form.serialize($('sendfriendform'), true));
		},
		urlSendFriend : null
	}.$();
}

function sendFriendCbk(transport) {
	if (200 == transport.status) {
		$('savingmsg').style.display = 'none';
		response = transport.responseText.evalJSON();
		if (1 == response.error) {
			//$('modalFriend').update(response.msg);
			jQuery(".closeModal").trigger("click");
		} else {
			jQuery('#sendfrienderror').css('display','block')
			jQuery('#sendfrienderror').html(response.error);
		}
	}
}

function scheduleClass() {
	var host;
	return {
		$ : function() {
			return host = this;
		},
		reloadOnTV : function(direction) {
			page = getObj('ontv_page').value
			genericPrototype(host.urlReloadData + '/page/' + page + '/direction/' + direction, 'onTVReloaderCbk');
		},
		urlReloadData : null
	}.$();
}

function onTVReloaderCbk(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (0 == response.error) {
			getObj('ontv').innerHTML = response.html;
			getObj('ontv_page').value = response.page;
		} 
	}
}

function toggleAnimatedContent( target ){
	var x1 = jml.xml.node.byProximity( target , 1 ) ;
	var s1 = jml.obj.get( x1 , 'className' ) ;
	var s2 = jml.obj.get( target , 'className' ) ;
	jml.obj.set( x1 , 'className' , s1 == null || s1 == '' ? 'open' : '' ) ;
	jml.obj.set( target , 'className' , s2 == null || s2 == '' ? 'active' : '' ) ;
}

function userRegistrationClass() {
	var c1=jml.obj,c2=jml.xml.node,c3=jml.events,c4=jml.server,c5=new displayScreenClass();
	var host;
	var id = 'layermsg';

	return {
		$ : function() {
			host = this;
			return this;
		},
	validateSignUp : function(msg) {
			var cx = new c4.connection();
			self.scrollTo(0, 100)//go back to top of the form
			var id='globalerr_msg';
			c1.set(id, 'innerHTML', msg);
			cx.url = host.urlSignUp
			cx.data = {	firstname:				getObj('fname').value,
						lastname:				getObj('lname').value,
						postalCode:				getObj('postal').value,
						phoneHome:				getObj('homephone').value,
						phoneWork:				getObj('workphone').value,
						cellNumber:				getObj('cellphone').value,
						town:					getObj('city').value,
						province:				getObj('province').value,
						password:				getObj('password').value,
						password_check:			getObj('passwordConfirm').value,
						email:					getObj('email').value,
						emailConfirm:			getObj('emailConfirm').value,
						captcha_code:			getObj('captcha').value,
						captcha_id:				getObj('captcha_id').value,
						optIn:					getObj('accept').checked
					  };
			cx.onLoad = function(data) {
				var dta = decode(data);
				if (dta.result_code == 0) {	//error
					reloadCaptcha('captchabox');
					c1.set(id, 'innerHTML', '<span>'+dta.error_msg+'</span>');
				} else {
					window.location.href=dta.data.redirection; //redirection
				}
				c5.remove();
			}
			cx.onError = function(id, msg) {
				alert(id + ", msg = " + msg);
			};
			cx.connect();
	},
	validateLogin : function(msg) {
		var cx = new c4.connection();
		self.scrollTo(0, 100)//go back to top of the form
		var id='errorLayer';
		c1.set(id, 'innerHTML', msg);
		cx.url = host.urlLogin
		cx.data = {	password:				getObj('password').value,
					email:					getObj('email').value
				  };
		cx.onLoad = function(data) {
			var dta = decode(data);
			if (dta.result_code == 0) {	//error
				c1.set(id, 'innerHTML', '<span>'+dta.error_msg+'</span>');
			} else {
				window.location.href=dta.data.redirection; //redirection
			}
			c5.remove();
		}
		cx.onError = function(id, msg) {
			alert(id + ", msg = " + msg);
		};
		cx.connect();
	},
	updateProfile : function(msg) {
		var cx = new c4.connection();
		self.scrollTo(0, 100)//go back to top of the form
		var id='errorLayer';
		c1.set(id, 'innerHTML', msg);
		cx.url = host.urlUpdateProfile;
		cx.data = {	firstname:getObj('fname').value,
					lastname:getObj('lname').value,
					postalCode:getObj('postal').value,
					phoneHome:getObj('homephone').value,
					phoneWork:getObj('workphone').value,
					cellNumber:getObj('cellphone').value,
					town:getObj('city').value,
					province:getObj('province').value,
					system:getObj('system').value,
					email:getObj('email').value
				  };
		cx.onLoad = function(data) {
			var dta = decode(data);
			if (dta.result_code == 0) {	//error
				c1.set(id, 'innerHTML', '<span>'+dta.error_msg+'</span>');
			} else {
				c1.set(id, 'innerHTML', '<span>'+dta.data.confirmation+'</span>');
			}
			c5.remove();
		}
		cx.onError = function(id, msg) {
			alert(id + ", msg = " + msg);
		};
		cx.connect();
	},
	changeProfilePassword : function(msg) {
		var cx = new c4.connection();
		var id = 'globalerr_msg';
		cx.url = host.urlUpdatePassword;
		cx.data = {	oldpasswordprofil:getObj('pwd1').value,
					newpasswordprofil:getObj('pwd2').value,
					newpasswordconfirmprofil:getObj('pwd3').value
				  };
		cx.onLoad = function(data) {
			var dta = decode(data);
			if (dta.result_code == 0) {	//error
				c1.set(id, 'innerHTML', '<span>'+dta.error_msg+'</span>');
			} else {
				getObj('form').style.display = 'none';
				getObj('sent').style.display = 'block';
			}
			c5.remove();
		}
		cx.onError = function(id, msg) {
			alert(id + ", msg = " + msg);
		};
		cx.connect();	
	},
	validateLostPassword:function($msg){
		if(!isset(host.validateurl)) return;
		var id='errorLayer';
		c1.set(id, 'innerHTML', '');
		var cx=new c4.connection();
		var x2=getObj('email').value;
		cx.url=host.validateurl;
		cx.data = {email:x2};
		cx.onLoad=function(data){
			var dta = decode(data);
			if (dta.result_code == 0) {
				c1.set(id, 'innerHTML', dta.error_msg);
			} else {
				getObj('form').style.display = 'none';
				getObj('sent').style.display = 'block';
			}
			c5.remove();
		};
		cx.onError=function(id,msg){alert(id+", msg = "+ msg);};
		cx.connect();	
	},
	urlSignUp : null,
	urlUpdateProfile : null,
	urlUpdatePassword : null,
	urlLogin : null,
	recipe :null,
	validateurl:null,
	container:null,
	redirection:0,
	clearScreen:function(){c5.remove();}
	}.$();
}

function reloadCaptcha(layer)
{
	if (!isset(layer)) return;
	var c1=jml.obj,c4=jml.server,c5=new displayScreenClass();
	var cx = new c4.connection();
	var id = layer;
	cx.url = '/ajax/ajaxreloadcaptcha';
	cx.onLoad = function(data) {
					var dta = decode(data);
					c1.set(id, 'innerHTML', data);
					c5.remove();
				};
	cx.connect();
}


function initLoginMenuTabSet( menuId , panelId ,  selectedIndex ){
	if( !isset( menuId ) ) return;
	if( !isset( selectedIndex ) || isEmpty( selectedIndex ) ) selectedIndex = 0;
	var myTab = new uiTabClass( menuId );
	myTab.initialIndex = selectedIndex ;
	myTab.firstRun=true;
	myTab.overClassName='over';
	myTab.selectedClassName='selected';
	myTab.onSelect=function( item , index , pastItem , pastIndex ){
		var panel = getObj( panelId );
		if( !isset( panel ) ) return;
		if( isset(pastIndex) ) jml.obj.set( jml.xml.node.byPosition( pastIndex , panel ) , 'display' , 'none' );
		jml.obj.set( jml.xml.node.byPosition( index , panel ) , 'display' , 'block' );
		// all custom call here...
	}
}

function psaClass() {
	var c1=jml.obj,c2=jml.xml.node,c3=jml.events,c4=jml.server,c5=new displayScreenClass(),c6=jml.jme;
	var jme1 = new c6.motion() ;
	var jme2 = new c6.motion() ;
	var host;
	var id = 'layermsg';
	return {
		$ : function() {
			host = this;
			return this;
		},
		changeMenuClass : function (position){
	      var someNodeList = $('menuTypePSA').getElementsByTagName('td');
	      var nodes = $A(someNodeList);
	
	      nodes.each(function(node, index){
	        if (index != position) node.className = 'tabs';
	        else node.className = 'tabs-active';
	      });
	    },
		reloadListingBy : function(type, page, order) {
			var cx = new c4.connection();
			self.scrollTo(0, 200)//go back to top of the form
			var id='errorLayer';		
			var sortValue=null;
			var sortValue=getObj('sortOrder').className;	
			
			if(!empty(order)){				
				if(sortValue=='sortBy'){
					getObj('sortOrder').className='sortByUp';
				}else{
					getObj('sortOrder').className='sortBy';
				}
			}
			
			!isset(type) ? type = 'all' : null;
			!isset(page) ? page = 1 : null;

			cx.url = host.urlReloadBy;
			cx.data = {	type:type,
						page:page,
						sort : getObj('sortOrder').className,
						category : getObj('classification_option').value
					  };
			cx.onLoad = function(data) {
				var dta = decode(data);
				c1.set('psalisting', 'innerHTML', data);
				//c1.set('psadetail', 'innerHTML', '');
				reloadMap(page, type);
				ddmenu_category_sort.initialize() ;
				c5.remove();
			}
			cx.onError = function(id, msg) {
				alert(id + ", msg = " + msg);
			};
			cx.connect();
		},
		loadClassification : function() {
			genericPrototype(host.urlLoadClassification + '/id/' + $('category').value, 'loadSubCategoryCbk');
		},
		reloadEvent : function(psaid) {
			var cx = new c4.connection();
			//self.scrollTo(0, 200)//go back to top of the form
			var id='psadetail';
			jme1.onMotionFinished = function( target , property ){
				cx.url = host.urlreloadEvent ;
				cx.data = {	psa:psaid } ;
				cx.onLoad = function(data) {
					c1.set(id, 'innerHTML', data);
					host.loading = 0;
				
                    host.reloadSocialToolsLink(psaid);
					host.setActivePSAClass(psaid);
					jme2.start( { target : target , property : 'alpha' , end : 100 , duration : 18 , equation : 'easeOut' , id : null } ) ;
					c5.remove();
				}
				cx.onError = function(id, msg) {
					alert(id + ", msg = " + msg);
				};
				cx.connect();			
			}
			jme1.start( { target : getObj( id ) , property : 'alpha' , end : 0 , duration : 18 , equation : 'easeOut' , id : null } ) ;
		},
		setActivePSAClass : function(psaid) {
			isset(host.currentPSA) ? manageCssClass( host.currentPSA , "active" , false ) : false; 
			manageCssClass( 'psa_' + psaid , "active" , true ) ; 
			host.currentPSA = 'psa_' + psaid;
		},
        reloadSocialToolsLink : function(psaid) {
  
        	url = host.urlReloadTools + '/psaid/' + psaid;
            genericPrototype(url,'reloadSocialToolsLinkCbk');
        },
		saveData : function () {
			//alert('saveData');
			getObj('savingmsg').style.display = 'block';	
			getObj('btnsubmit').style.display = 'none';
			c1.set('globalerr_msg', 'innerHTML', '');
			genericPrototype(host.urlSaveData, 'psaSaveDataCbk', 'post', Form.serialize($('formPSAData'), true));
		},
		savePreview : function () {
			//getObj('savingmsg').style.display = 'block';	
			//getObj('btnsubmit').style.display = 'none';
			c1.set('globalerr_msg', 'innerHTML', '');
			genericPrototype(host.urlPreview, 'psaPreviewCbk', 'post', Form.serialize($('formPSAData'), true));
		},
		psaDelete : function (id) {
			genericPrototype(host.urlDeleteData + '/psaid/' + id, 'psaDeleteDataCbk');
		},
		reloadCalendar : function (month, year) {
			var cx = new c4.connection();
			cx.url = host.urlreloadCalendar;
			cx.data = { month : month,
						year : year
					  }; 
			cx.onLoad = function(data) {
				var dta = decode(data);
				if (dta.result_code == 1) {
					c1.set('psaCalendar', 'innerHTML', dta.data.html);
					c1.set('psaCalendarTitle', 'innerHTML', dta.data.title);
				} 
			} 
			cx.onError = function(id, msg) {
				alert(id + ", msg = " + msg);
			};
			cx.connect();
		},
	urlReloadBy : null,
	urlDeleteData : null,
	urlLoadClassification : null,
	urlreloadEvent : null,
	urlSaveData : null,
	urlPreview : null,
    urlReloadTools : null,
	urlreloadCalendar : null,
	loading : 0,
	currentPSA : null,
	clearScreen:function(){c5.remove();}
	}.$();
}

function reloadSocialToolsLinkCbk (transport) {

	if (200 == transport.status) {
		response = transport.responseText;
		$('PSAGeneralTools').update(response);
	} 
}


function psaDeleteDataCbk (transport) {
	if (200 == transport.status) {
		var response = transport.responseText.evalJSON();
		if (response.error == 1)  new Effect.Fade('psa_' + response.psaid, { duration:1});
		else $('psadelete_' + response.psaid).update(response.error);
	}
}

function psaPreviewCbk (transport) {
	if (200 == transport.status) {
		//$('globalerr_msg').update(transport.responseText);
		var response = transport.responseText.evalJSON();
		if (response.error == 1) {
			showAddress(true);
			jQuery('#psaPreview').html(response.preview);
			jQuery('#psaPreview').show();
			jQuery('#psaFullForm').hide();
			$('contactFormBloc').scrollTo();
		} else {	
			$('globalerr_msg').update(response.error);
			$('globalerr_msg').scrollTo();
		}
	}
	
	
}

function psaSaveDataCbk (transport) {
	if (200 == transport.status) {
		//$('globalerr_msg').update(transport.responseText);
		var response = transport.responseText.evalJSON();
		if (response.error == 1) {
			if (global == 'psamodification') successMessageForm(response.savemessage);
			else window.location.href=response.redirection; 
		} else {	
			$('globalerr_msg').update(response.error);
			$('globalerr_msg').scrollTo();
		}
	}
}

function loadSubCategoryCbk(transport) {
	if (200 == transport.status) {
		response = transport.responseText
		$('psaSubForm').update(response);
		$('divMapGlobal').show();
	} else {
		failureFunc(transport);
	}
}

function miscClass() {
	var host;
	var id = 'layermsg';
	return {
		$ : function() {
			host = this;
			return this;
		},
		sendData : function(successFunc) {
			genericPrototype(host.urlSendData, successFunc, 'post', Form.serialize($('formData'), true));
		},
		urlSendData : null
	}.$();
}

function pollClass() {
	var host;
	var id = 'layermsg';
	return {
		$ : function() {
			host = this;
			return this;
		},
		validate : function(emptyOption) {
			if ($('polloptionhidden').value == '') {
				$('label').className='errorBox';
				$('label').update(emptyOption);
			} else {
				$('label').update();
				$('label').hide();
				genericPrototype(host.urlSavePollData, 'pollReloadCbk', 'post', Form.serialize($('pollform'), true));
			}
		},
		urlSendData : null,
		urlSavePollData : null
	}.$();
}


function pollReloadCbk(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (1 == response.error) {
			$('pollreload').update(response.msg);
		} else if (3 == response.error) {
			$('label').className='errorBox';
			$('label').update(response.msg2);
			$('label').show();
			$('pollreload').update(response.msg);
		}
	} 
}

function miscCBK(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (0 == response.error) {
			$('miscFormBloc').update(response.msg);
		} else {
			reloadCaptcha('captchabox');
			$('globalerr_msg').update(response.msg);
		}
	} else {
		reloadCaptcha('captchabox');
		$('globalerr_msg').update(response.msg);
	}
}

function manageCssClass( o , c , b ){
	var c1=jml.obj;
	if( !isset( getObj( o ) ) ) return ;
	var s = 'className' , n = c1.get( o , s ) ;
	if( !isset( n ) ) n = '' ;
	var t = b && n.indexOf( c ) == -1 ? n + " " + c : !b && n.indexOf( c ) != -1 ? n.replace( new RegExp( "(\\b" + c + "\\b)+" , "gi" ) , "" ) : null ;
	if( isset( t ) ) c1.set( o , s , t ) ;
} ;

function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		return false;
	}
}

function galleryManager() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		loadGallery : function(page, categorySelect, callback) {
			reload('galleryAlbumreload');
			genericPrototype(host.urlLoadGallery + '/categorySelect/'+ categorySelect + '/page/' + page, callback);
			$('categorySelect').value=categorySelect;
		},
		loadCategory : function(page,callback) {
			var categorySelect=$('categorySelect').value;
			genericPrototype(host.urlLoadCategory + '/categorySelect/'+ categorySelect + '/page/' + page, callback);
		},
		urlLoadGallery :null,
		urlLoadCategory :null
	}.$();
}


function dataLoadCategory(transport) {

	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('galleryCategory').update(response.data); // update hidden
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}


function dataLoadGallery(transport) {

	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('galleryAlbum').update(response.data); // update hidden
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}

function albumManager() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		loadVideoList : function(page, albumid, callback) {
			reload('videoListreload');
			genericPrototype(host.urlLoadVideoList + '/albumid/'+ albumid + '/page/' + page, callback);
		},
		loadPhotoList : function(page, albumid, callback) {
			reload('photoListreload');
			genericPrototype(host.urlLoadPhotoList + '/albumid/'+ albumid + '/page/' + page, callback);
		},
		loadAlbumList : function(page, callback) {
			reload('albumListreload');
			genericPrototype(host.urlLoadAlbumList + '/page/' + page, callback);
		},
		urlLoadVideoList :null,
		urlLoadAlbumList :null,
		urlLoadPhotoList :null
	}.$();
}


function dataLoadVideoList(transport) {

	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('videoList').update(response.data); // update hidden														// field
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}


function dataLoadPhotoList(transport) {

	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('photoList').update(response.data); // update hidden														// field
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}

function dataLoadAlbumList(transport) {

	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('albumList').update(response.data); // update hidden														// field
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}



function ratingManager() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		addRecommend : function(assetid, legacytype , callback) {
			genericPrototype(host.urlAddRecommend + '/assetid/'+assetid+'/legacytype/'+legacytype , callback);
		},
		urlAddRecommend :null
	}.$();
}



function dataAddRecommend(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			$('message_recommend').className='confirmBox';
			$('message_recommend').update(response.success);
			var resultat=$('nbRating').innerHTML;
			$('nbRating').update(parseInt(resultat)+1);
		} else {
			$('message_recommend').className='errorBox';
			$('message_recommend').update(response.error);
		}
	} else {
		failureFunc(response);
	}
}

function commentClass() {
	var host;
	return {
		$ : function() {
			host = this;
			return this;
		},
	SaveComment : function(object, id) {
			$('commentFormLoading').style.display = 'block';
			$('formPostComment').style.display = 'none';
			genericPrototype(host.urlSaveComment, 'saveCommentCbk', 'post', Form.serialize($('formCommentData'), true));
	},
	reloadListing : function(object, id, page) {
		genericPrototype(host.urlReloadListing + '/page/' + page + '/object/' + object + '/id/' + id + '/page/' + page, 'reloadCommentListingCbk');
	},
	BlackList : function(object, id, commentID) {
		genericPrototype(host.urlBlacklist + '/commentID/' + commentID + '/object/' + object + '/id/' + id , 'blackListCbk');
	},
	urlReloadListing : null,
	urlSaveComment : null,
	urlBlacklist : null,
	clearScreen:function(){c5.remove();}
	}.$();
}

function blackListCbk(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (response.error == 0) {
			$('commentdd_' + response.commentID).update(response.message);
		} 
	} 
}

function saveCommentCbk(transport) {
	$('statusLayer').update();
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (response.error == 0) {
			$('commentFormLoading').update(response.message);
			genericPrototype(response.urlreloadlisting, 'reloadCommentListingCbk');
		} else {
			$('commentFormLoading').style.display = 'none';
			$('formPostComment').style.display = 'block';
			$('statusLayer').className='errorBox';
			$('statusLayer').update(response.message);
		}
	} else {
		$('commentFormLoading').style.display = 'none';
		$('formPostComment').style.display = 'block';
		$('commentFormLoading').update('Error');
	}
}

function reloadCommentListingCbk(transport) {
	if (200 == transport.status) {
		$('assetComments').update(transport.responseText);
	} else {
		$('commentFormLoading').update('Error');
	}
}

function menuCategory(select) {

	var elementContent = $('menuCategory');
	elementSelect = elementContent.getElementsBySelector('li');
	elementSelect.each( function(e) {
		e.className = '';
	});
	$(select).className='active';

}


function empty(mixed_var) {
	var key;
	if (mixed_var === "" || mixed_var === 0 || mixed_var === "0"
			|| mixed_var === null || mixed_var === false
			|| mixed_var === undefined) {
		return true;
	}
	if (typeof mixed_var == 'object') {
		for (key in mixed_var) {
			return false;
		}
		return true;
	}
	return false;
}

function reload(id,msg) {
	var img='<img src="/library/images/icons/loader.gif" /> ';
	showMsg = !isset(msg) ? '' : msg;
	$(id).update("<div id='reload'>"+img+showMsg+"</div>");
}

function showLayer(layer) {
	var c1 = jml.obj
	c1.set(layer, 'display', 'block');
}

function successMessageForm(msg) {
	var showMsg;
	if ($('statusLayer') == undefined) { alert('Sorry! Element "statusLayer" do not exist'); }
	showLayer('statusLayer');
	showMsg = !isset(msg) ? 'Data saved' : msg;
	$('statusLayer').className='confirmBox';
	$('statusLayer').update(showMsg);	

}

function errorMessageForm(msg) {
	var showMsg;
	if ($('statusLayer') == undefined) { alert('Sorry! Element "statusLayer" do not exist'); }
	showLayer('statusLayer');
	showMsg = !isset(msg) ? 'Error data save' : msg;
	$('statusLayer').className='errorBox';
	$('statusLayer').update(showMsg);

}

function pendingMessageForm(msg) {
	var showMsg;
	var img;
	showLayer('statusLayer');
	img='<img src="/library/images/icons/loader.gif" /> ';
	showMsg = !isset(msg) ? ' Wait ...' : msg;
	$('statusLayer').className='pendingBox';
	$('statusLayer').update(img+showMsg);
}

function formsClass() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		saveAction : function(msg) {
			window.scrollTo(0, 100);
			pendingMessageForm(msg);
			genericPrototype(host.urlSave, formsSaveAction, 'post', Form.serialize($(host.formName), true));
		},
		
		urlSave :null,
		formName :null
	}.$();
}

function formsSaveAction(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			successMessageForm(response.success);
			if (response.type == 'insert') {
				window.location.href = response.redirection;
			}
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}




/*
 * 
 * GESTION ASSET ***************************
 * ************************************************
 * 
 */

function assetClass() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		saveAction : function(callback,msg) {
			window.scrollTo(0, 100);
			pendingMessageForm(msg);
			genericPrototype(host.urlSave, callback, 'post', Form.serialize($(host.formName), true));
			
		},
		deleteAction : function(id,message) {
			if (confirm(message)) { 
			genericPrototype(host.urlDelete + '/asset/'+id , 'assetDeleteAction');
			}
			
		},
		deletealbumAction : function(id,message) {
			if (confirm(message)) {
			genericPrototype(host.urlDeleteAlbum + '/album/'+id , 'assetDeleteAction');
			}
		},
		urlSave :null,
		urlDelete :null,
		urlDeleteAlbum :null,
		formName :null
	}.$();
}


function assetSaveAction(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			successMessageForm(response.success);
			window.location.href = response.redirection;
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}


function assetSavephotoAction(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			successMessageForm(response.success);
			window.location.href = response.redirection;
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}


function assetSavevideoAction(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();
		if (empty(response.error)) {
			successMessageForm(response.success);
			window.location.href = response.redirection;
		} else {
			// remise a jour de limit upload dans swf upload
			var elementUL = $('ul_thumbnails');
			elementSelect = elementUL.getElementsBySelector('li');
			swfu.setFileUploadLimit(parseInt(swfu.settings.file_upload_limit) + parseInt(elementSelect.size()));
			
			//vide ul
			$('ul_thumbnails').update();
			$('divFileProgressContainer').update();
			failureFunc(response);
		}
	} else {
		$('ul_thumbnails').update();
		$('divFileProgressContainer').update();
		failureFunc(response);
	}
}

function assetDeleteAction(transport) {
	if (200 == transport.status) {

		response = transport.responseText.evalJSON();
		
		if (empty(response.error)) {
			if (!empty(response.redirection)) {
				window.location.href=response.redirection;
			}
			$(response.row).hide();
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}

function textResizeClass(){
	var c1=jml.obj,c2=jml.xml.node,c3=jml.events,c4=jml.cookie;
	var size=1;
	function init(){
		var o1=c4.get('textSize');
		if(isset(o1)&&isset(o1.size)){
			size=o1.size;
			setSize();
		}
	}
	function setSize(){
		var a1=acquireTarget();
		if(isset(a1)){
			for(var i=0;i<a1.length;i++){
				var s1=c1.get(a1[i],'className');
				if(s1.indexOf('size')) s1=s1.replace(/size\d+/,'');
				s1  = s1+' size'+size;
				c1.set(a1[i],'className',s1);
			}
		}
		c4.set('textSize',{size:size},99);
	}
	function acquireTarget(){ return c2.byPartialAttributeValue('class','textBox',document.body); }
	return {
		$:function(){
			c3.add(window,'load',init);
			return this;
		},
		changeSize:function(){
			size=size==2?1:size+1;
			setSize();
		}
	}.$();
}

function animAlbum(){
	menucateg = jQuery("#menuCategory li").size()

	if(menucateg > 1 ){
		widthSize = 0
		menuPadding = 10
		countitem = 0
		widthContainer = jQuery("#galleryCategory").width()
		totalWidth = 0
		var sizeMenu = jQuery("#menuCategory li").size()
		jQuery("#menuCategory li").each(function(){
			caller = this
			countitem += 1
			widthSize = widthSize+"px"
			jQuery(this).css("left",widthSize )
			widthSize = parseFloat(widthSize)
			
			widthSize += jQuery(this).width() + menuPadding
			
			
			cssWidth = jQuery(this).width()
			cssWidth += "px"
			jQuery(this).css("width",cssWidth )
			
			container = widthSize + 200
			container = container + "px"
			jQuery("#menuCategory").css("width",container)
			
			if(countitem == sizeMenu){
				totalWidth = jQuery(this).width()
				totalLeft = jQuery(this).css("left")
				totalLeft = parseFloat(totalLeft)
				
				totalWidth = totalWidth + totalLeft
				totalWidth =  totalWidth + "px"
			
				jQuery("#menuCategory").css("width",totalWidth)
				totalWidth = parseFloat(totalWidth)
				
				marginLeft = jQuery("#menuCategory").css("marginLeft")
				marginLeft = parseFloat(marginLeft)
				moveright = totalWidth +marginLeft
				if(widthContainer >moveright){
					jQuery("a.slideRight").css("display","none")
					jQuery("a.slideLeft").css("display","none")
				}
			}
		})
		jQuery("a.slideRight").hover(function() {	
			// Stuff to do when the mouse enters the element;
			movingInterval = setInterval("slidingRight()",20)
			slidingRight = function(){
				
				marginLeft = jQuery("#menuCategory").css("marginLeft")
				marginLeft = parseFloat(marginLeft)
				moveright = totalWidth +marginLeft
			
				if(widthContainer<moveright){

					marginLeft -= 3
					marginLeft = marginLeft + "px"
					jQuery("#menuCategory").css("marginLeft", marginLeft)
				}
			}
		}, function() {
			// Stuff to do when the mouse leaves the element;
			clearInterval(movingInterval)
		});
		
		
		jQuery("a.slideLeft").hover(function() {
		
			// Stuff to do when the mouse enters the element;
			movingInterval = setInterval("slidingLeft()",20)
			slidingLeft = function(){
				marginLeft = jQuery("#menuCategory").css("marginLeft")
				marginLeft = parseFloat(marginLeft)
				if(marginLeft<0){
					marginLeft += 3
					marginLeft = marginLeft + "px"
					jQuery("#menuCategory").css("marginLeft", marginLeft)
				}
			}
		
		}, function() {
			// Stuff to do when the mouse leaves the element;
			clearInterval(movingInterval)
		});
	}else{
		jQuery("a.slideRight").css("display","none")
					jQuery("a.slideLeft").css("display","none")
	}
}	
function reloadFC(id) { 
	var h = $('currentFC_' + id).innerHTML;
	$('currentFC').update(h);
	var elementUL = $('ulFCClass');
	elementSelect = elementUL.getElementsBySelector('li');
	elementSelect.each( function(e) {
		e.removeClassName('active');
	});
	$('FCli_' + id).addClassName('active');
}

function changeoptionClass() {
	var host;

	return {
		$ : function() {
			return host = this;
		},
		changeAction : function() {
			genericPrototype(host.urlChange, 'changeFunction', 'post', Form.serialize($(host.formName), true));
			
		},
		urlChange :null,
		formName :null
	}.$();
}

function changeFunction(transport) {
	if (200 == transport.status) {
		response = transport.responseText.evalJSON();	
		if (empty(response.error)) {
			$(response.target).update(response.msg);
			if (!empty(response.reload)) {
				$('classification_option').value=null;
				psa.reloadListingBy('all');
			}
		} else {
			failureFunc(response);
		}
	} else {
		failureFunc(response);
	}
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

function mustLoginCheck(obj,isLogged,lang,div,href) {
	if (isLogged==''){
		var errors=new Array();

		errors['fr']='Vous devez &ecirc;tre membre <a href="' + href + '">Connectez-vous</a>.';
		errors['en']='You have to be logged in <a href="' + href + '">Log in</a>.';
	
		$(div).className='errorBox';
		$(div).update(errors[lang]);
		$(div).show();
		return false;
	}else{
		return true;
	}
}

