function disableProgramm(thi,e, f, g ,h){
	//alert($(thi).attr('disabled'));
	if($(thi).is(':checked')===true){
		$('#'+e).attr('disabled', '').attr('class', 'sessionText');
		$('#'+f).attr('disabled', '').attr('class', 'sessionText');
		$('#'+g).attr('disabled', '').attr('class', 'sessionText');
		$('#'+h).attr('disabled', '');
		$('#img_calendar').bind('click', function(){
			makeDate('session-schedule-date');
		});
	}else{
		$('#'+e).attr('disabled', 'disabled').attr('class', 'sessionText elmDisabled');
		$('#'+f).attr('disabled', 'disabled').attr('class', 'sessionText elmDisabled');
		$('#'+g).attr('disabled', 'disabled').attr('class', 'sessionText elmDisabled');
		$('#'+h).attr('disabled', 'disabled');
		$('#img_calendar').unbind('click');
	}
}
$(document).ready(function(){
	$('.selectDash').combox({
		width:200, 
		fontSize:'13px', 
		padding : 4,
		textIndent : '20px',
		label:"Select one...", 
		onChange:function(e){			
			if (e!='') window.location.href = e;			
		}
	});
	
	hover_btn();
	//////BONTON SURVOL (le script est moche a cause de cette ***** d'IE)
	$('.btn_nav_session').each(function(i,elm){
		$(elm).parent().removeClass('btn_hover');
		$(elm).mouseenter(function(){
			$(elm).parent().addClass('btn_hover');
		});
		$(elm).mouseleave(function(){
			$(elm).parent().removeClass('btn_hover');
		});
		
	});
	//SLIDER SPONSOR PLAY
	if($('#sliderSponsor li').length>0)$('#sliderSponsor').wslide({
		width:380,
        height:130,
        horiz:true
	});
	
	hover_btn();
	settingOption();
	menuLogin();
	editDescription();
	
	// REPORTS
	if ($('#tweet-report').length>0) loadReportTweet(10,0);	
	if ($('#tweetos-report').length>0) loadReportTweetos(10,0);
});
function getSessionInfo() {
	var pSession = sessionId;

	$.ajax({
	   type: "POST",
	   url: domain+"objects/talkToManager.php?anticache="+Math.random(),
	   data: {'sessionId' : pSession,getSessionInfo:'ok'},
	   success: function(msg){
			alert(msg);			
		} 
	 });
}
function sendSessionLogs(url) {	
	var pSession = sessionId;
	
	$.ajax({
	   type: "POST",
	   url: domain+"objects/talkToManager.php?anticache="+Math.random(),
	   data: {'sessionId' : pSession,'url' : url,sendSessionLogs:'ok'},
	   success: function(msg){
			//alert(msg);			
		} 
	 });
}
function menuLogin(){
	$('.elm_session_menu').each(function(i,elm){
		var hover=false;
		$(elm).mouseenter(function(){
			$(elm).children('ul').show();
		});
		$(elm).mouseleave(function(){
			$(elm).children('ul').hide();
		});
	});
}
function makeDate(id){
	$('#'+id).datepicker('show');
} 
function settingOption(){
	var tmp_close = $('.sessionViewSetting').attr('rel');
	var tmp_view = 	$('.sessionViewSetting').html();
	
	$('.session_option_content').css('display', 'none');
	$('.sessionViewSetting').attr('class', $('.sessionViewSetting').attr('class')+' sessionYesViewSetting');
	
	if ($('.opened').length>0) // pre-opened settings
	{
		$('.opened .session_option_content').show();
		$('.opened .sessionViewSetting').html(tmp_close);
		$('.opened .sessionViewSetting').attr('class', 'sessionViewSetting sessionNoViewSetting');
		$.scrollTo($('.opened').position().top-50,800);
	}
	
	$('.sessionNav').children().each(function(i,elm){
		$(elm).click(function(){
			if(i===0 || i===2){
				$('.sessionViewSetting').parent().next('.session_option_content').show();
				$('.sessionViewSetting').html(tmp_close);
				$('.sessionViewSetting').attr('class', 'sessionViewSetting sessionNoViewSetting');
			}else if(i===1 || i ===3){
				$('.sessionViewSetting').parent().next('.session_option_content').hide();
				$('.sessionViewSetting').html(tmp_view);
				$('.sessionViewSetting').attr('class', 'sessionViewSetting sessionYesViewSetting');
			}
			
		});
		
	});

	
	$('.sessionViewSetting,.session_option_title h1 ').click(function(){
		if($(this).attr('class')==='sessionViewSetting sessionYesViewSetting' || $(this).attr('class')==='sessionViewSetting sessionNoViewSetting'){
			var elm = $(this);
			
		}else{
			var elm = $(this).nextAll('.sessionViewSetting');	
		}
	
		if(elm.attr('class')==="sessionViewSetting sessionYesViewSetting"){
			elm.parent().next('.session_option_content').show();
			elm.attr('class', 'sessionViewSetting sessionNoViewSetting');
			elm.html(tmp_close);
		}else{
			elm.parent().next('.session_option_content').hide();
			elm.attr('class', 'sessionViewSetting sessionYesViewSetting');
			elm.html(tmp_view);
		}
	});
	
}
function hover_btn(){
	$('.button').each(function(i,elm){
		$(elm).removeClass('btn_h');
		$(elm).mouseenter(function(){
			$(elm).addClass('btn_h');
		});
		$(elm).mouseleave(function(){
			$(elm).removeClass('btn_h');
		});
	});		
}
function editDescription(){
	$('#editTitleDescription').click(function(){
		$('#contentTitleDescription').fadeOut();
		$('#textTitleDescription').fadeIn()	
	});
	$('#editDescription').click(function(){
		$('#contentDescription').fadeOut();
		$('#textDescription').fadeIn()	
	});
	$('#editInfo').click(function(){
		$('#contentInfo').fadeOut();
		$('#textInfo').fadeIn()	
	});
	
	$('#sendTweet').click(function(){
		var tweet = $('#chpSendTweet').val();
		$.ajax({
		   type: "POST",
		   url: domain+'/do/twitter_update.php',
		   data: "tweet="+tweet,
		   success: function(msg){												
				if (msg=='') // success
				{
					$('#chpSendTweet').val('');
					$('#sendTweet').hide();
					$('#sendTweetOK').fadeIn();
					setTimeout("$('#sendTweetOK').fadeOut(400,function(){$('#sendTweet').show();}); ",3000);
				}
				else // fail
				{
					window.open('http://twitter.com/intent/tweet?text='+encodeURIComponent(tweet));
				}
		   }
		});		
	});
}
function sessionConfirm(){
	if($('#session_confirm').is(':checked') && $('#session_terms').is(':checked')){
		$('#sessionFormConfirm').submit();
	}else{
		$('#session_confirm').next('label').addClass('error');
		$('#session_terms').next('label').addClass('error');
		$('#session_confirm:checked').next('label').removeClass('error');
		$('#session_terms:checked').next('label').removeClass('error');
	}
}
function sessionTweet() {
	if ($('#session_tweetSession').is(':checked')) {
		$('#session_tweetContent').removeClass('disabled');
	}
	else {
		$('#session_tweetContent').addClass('disabled');
	}
}
function checkBattle() {
	if ($('.battleWord').length>0) {
		var count = 0;
		$('.battleWord').each(function(i,elm) {
			if ($.trim($(elm).val())!='') count++;
		});
		
		if (count>=2) return true;
		else {
			alert($('#battleError').html());
			return false;
		}
	}
	else return true;
}

/* REPORTS */

var reportSearch = '';
var reportTweetosFilter = 'TWEETS';
var reportTweetosOrder = 'DESC';

function report_search() {
	reportSearch = $('#search-tweet').attr('value');			
	loadReportTweet(10,0);
}
function loadReportTweet(num,page) {
	
	var moderation = -1;
	if ($('#input-apr').is(':checked')) moderation = 1;
	if ($('#input-rej').is(':checked')) moderation = 0;
	
	$('#tweet-report table').css('visibility','hidden');
	$('#tweetLoader').show();
	$('#tweet-report').load(domain+'/do/report_twp.php?sessionId='+$('#sessionId').val()+'&tweets='+num+'&page='+page+'&search='+reportSearch+'&moderation='+moderation,function() {
		if (page>0) {
			$('#tweet-report').css('visibility','hidden');
			$.scrollTo('#tweetTop',{duration: 800, onAfter: function(){
				$('#tweetLoader, #preloadingTweets').hide();
				$('#tweet-report').css('visibility','visible');
				}
			});
		}
		else {
			$('#tweetLoader, #preloadingTweets').hide();
			$('#tweet-report').css('visibility','visible');
		}
	});
	
	return false;
}

function orderReportTweetos(filter,order) {
	reportTweetosFilter = filter;
	reportTweetosOrder = order;
	
	loadReportTweetos(10,0);
}
function loadReportTweetos(num,page) {
	
	$('#tweetos-report table').css('visibility','hidden');
	$('#tweetosLoader').show();
	$('#tweetos-report').load(domain+'/do/report_twp.php?sessionId='+$('#sessionId').val()+'&tweetos='+num+'&page='+page+'&filter='+reportTweetosFilter+'&order='+reportTweetosOrder,function() {
		if (page>0) {
			$('#tweetos-report table').css('visibility','hidden');
			$.scrollTo('#tweetosTop',{duration: 800, onAfter: function(){
				$('#tweetosLoader, #preloadingTweetos').hide();
				$('#tweetos-report table').css('visibility','visible');
				}
			});
		}
		else {
			$('#tweetosLoader, #preloadingTweetos').hide();
			$('#tweetos-report table').css('visibility','visible');
		}
	});
	
	return false;
}

function shareReport() {
	share = $('<div></div>')
		.html('<iframe src="'+domain+'do/report_share.php?sessionId='+$('#sessionId').val()+'" width="100%" height="100%" frameborder="0"></iframe>')
		.dialog({
			autoOpen: false,
			resizable:false,
			draggable:false,
			modal:true,
			width: 500,
			height: 450,
			title: 'Share your report',
			close:function(){
				$('body').css('overflow', 'auto');
			}
	});

	share.dialog('open'); 
	$('body').css('overflow', 'hidden');
}

