

$(function(){
	//Form recherche : validation sans bouton
	//-------------------------------------------------
	if($(".header_search_form").length>0){
		$(".header_search_form").each(function(){
			var form = $(this);
			$(this).children(".submitbutton").hide();
			$(this).children(".queryfield").each(function(){
				$(this).keypress(function(event) {
  					if (event.keyCode == '13') {
     					form.submit();
   					}
				});
			});
		});
	}
	if($(".basic_search_form").length>0){
		$(".basic_search_form").each(function(){
			var form = $(this);
			$(this).children(".submitbutton").hide();
			$(this).children(".queryfield").each(function(){
				$(this).keypress(function(event) {
  					if (event.keyCode == '13') {
     					form.submit();
   					}
				});
			});
		});
	}
	//Form Select Doc : validation sans bouton
	//-------------------------------------------------
	if($(".show_doc_form").length>0){
		$(".show_doc_form").each(function(){
			var form = $(this);
			
			$(this).children(".queryfield").each(function(){
				$(this).msDropDown();
			});
			
			if (! $.browser.msie || $.browser.version.substr(0,1) >= 7){
				$(this).children(".submitbutton").hide();
			}
			$(this).children(".queryfield").each(function(){
				$(this).change(function(event) {
  					form.submit();
				});
			});
			$(this).children(".dd").children(".ddChild").children("a").each(function(){
				$(this).click(function(){	
					form.submit();
				});
			});
		});
	}
	//Form VL chart : validation sans bouton
	//-------------------------------------------------
	if($("#navchart_form2").length>0){
		$("#navchart_form2").each(function(){
			var form = $(this);
			$(this).children().children(".submitbutton").hide();
//			form.parent(".spgp_fund_courbes_datesform").prev(".spgp_fund_courbes_charts").children(".spgp_fund_courbes_chart").hide();
			form.parent(".spgp_fund_courbes_datesform").prev(".spgp_fund_courbes_charts").children(".spgp_fund_courbes_chart").addClass('superLeft');		
//  			form.parent().prev().children(".spgp_fund_courbes_chart_1").show();
  			form.parent().prev().children(".spgp_fund_courbes_chart_1").removeClass('superLeft');
  			//form.parent().prev().children(".spgp_fund_courbes_chart_1").show('left', '0px');  			
  			
  			form.parent().parent().children("h3").hide();
  			form.parent().parent().children("h3.chart_title_1").show();
			$(this).children().children(".selectfield").each(function(){
				$(this).change(function(event) {
					//alert('changement pour '+$(this).val());
  					//form.parent(".spgp_fund_courbes_datesform").prev(".spgp_fund_courbes_charts").children(".spgp_fund_courbes_chart").hide();
  					form.parent(".spgp_fund_courbes_datesform").prev(".spgp_fund_courbes_charts").children(".spgp_fund_courbes_chart").addClass('superLeft');
  					//form.parent().prev().children(".spgp_fund_courbes_chart_"+$(this).val()).show();								
  					form.parent().prev().children(".spgp_fund_courbes_chart_"+$(this).val()).removeClass('superLeft');								
  					form.parent().parent().children("h3").hide();
  					form.parent().parent().children("h3.chart_title_"+$(this).val()).show();  					
  					//alert('fin changement pour h3.chart_title_'+$(this).val());
				});
			});
		});
	}
	//Tableau de fonds : infobulle
	//-------------------------------------------------
	if($(".spgp_funds_recap_table").length>0){
		$(".spgp_funds_recap_table a").each(function(){
			if($(this).next(".tooltip").length>0){
				var content = $(this).next(".tooltip").html();
				$(this).next(".tooltip").hide();
				//alert(content);
				$(this).qtip({
		         	content: content, 
		         	position: {
	                  	corner: {
	                     	tooltip: 'leftMiddle', 
	                     	target: 'rightMiddle'
	                  	}
	               	},
		         	style: {
	                  	border: {
	                     	width: 0,
	                     	radius: 3,
	                     	color: '#d4d9df'
	                  	},
	                  	background: '#ffffff',
	                  	padding: 5, 
	                  	textAlign: 'left',
	                  	tip: true,
	                  	name: 'light' 
	               }
		      	});
			}	      	
		});
	}
	//Tableau des fonds: switch
	//-------------------------------------------------
	if($(".spgp_funds_recaps").length>0){
		$(".spgp_funds_recaps").each(function(){
			var div = $(this);
			$(this).children(".spgp_funds_recap_").hide();
			$(this).children(".spgp_funds_recap_1").show();
			$(this).children(".spgp_funds_recap_").children(".morebutton").show();
			$(this).children(".spgp_funds_recap_").children(".morebutton").each(function(){
				$(this).click(function(event) {
  					$(this).parent().parent().children().toggle();
				});
			});
		});
	}
	
	//Onglets des fonds
	//-------------------------------------------------
	if($("#spgp_fund_tabs").length>0){
		$("#spgp_fund_tabs").tabs();
	}
	
	//Avertissement de fond
	//-------------------------------------------------
	if($("#dialog-message").length>0){
		$("#dialog-message").dialog({
			width: 500,
			resizable: false,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
	
	//Datepicker
	//-------------------------------------------------
	$.datepicker.setDefaults($.datepicker.regional['fr']);
	var dates = $("#input_01, #input_02").datepicker({
		defaultDate: "+1w",
		changeMonth: true,
		changeYear: true,
		numberOfMonths: 1,
		dateFormat: 'dd/mm/yy',
		onSelect: function(selectedDate) {
			var option = this.id == "input_01" ? "minDate" : "maxDate";
			var instance = $(this).data("datepicker");
			var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
			dates.not(this).datepicker("option", option, date);
		}
	});
	
	
	//Print
	//-------------------------------------------------
	if($(".header_print a").length>0){
		$(".header_print a").click(function(event) {
			if( 1 == 2 && ! $.browser.msie){
				$(".column_2").printElement({
					printMode:'popup',
					leaveOpen:true,
					pageTitle:'SPGP',
					overrideElementCSS:'true',
					printBodyOptions:{
			           		styleToAdd:'background: #ffffff;'
			       		}
				});
			} else {
				try{
					document.getElementById('spgp_fund_tabs_1').className  = '';
					document.getElementById('spgp_fund_tabs_2').className  = '';
					document.getElementById('spgp_fund_tabs_3').className  = '';
					document.getElementById('spgp_fund_tabs_4').className  = '';
					document.getElementById('spgp_fund_tabs_5').className  = '';					
				} catch(err) {}
				
				window.print();
				location.reload();
			}
		});
	}
	
	

	
	
});
