// LightBox functions
function gradient(id, level)
{
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	return;
}
function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
}
// Open the lightbox
function openbox(div_id, fadin, call_type)
{
	var box = document.getElementById(div_id);
	var call_other_type = (call_type=='bullish'?'bearish':'bullish');
	// Enable the dark layer on the al page
	$('#lightbox_filter').css('height',$(document).height());
	$('#lightbox_filter').css('display','block');
	//document.getElementById('lightbox_filter').style.display='block';

	// Set the call type (Bullish or Bearish)
	document.getElementById('call_type').value=call_type;
	// Set the open rate
	document.getElementById('sentiment_pair_open').value=document.getElementById('last_last').innerHTML;
	// Change the bullish/bearish images
	$('#form_vote_'+call_type+'_img').attr('src','/images/sentiments/'+call_type+'_vote_small_chosen.png');
	$('#form_vote_'+call_other_type+'_img').attr('src','/images/sentiments/'+call_other_type+'_vote_small.png');
	// Center the position of the form
	var leftpos = ($(document).width() - 540) / 2;
	$(box).css('left',leftpos); 
	if(fadin){
		gradient(div_id, 0);
		fadein(div_id);
	}else{ 	
		box.style.display='block';
	}
	//document.getElementById('comment_text').focus();
	$("#comment_text").focus();
}
// Close the lightbox
function closebox(div_id)
{
   document.getElementById(div_id).style.display='none';
   document.getElementById('lightbox_filter').style.display='none';
}
// End LightBox functions
function ajax_set_session_and_continue_sentiments(redirect_to, uri, call_type, submit) {
	
	$.get('/common/ajax_func.php', {action: 'set_sessions_sentiments', uri: uri, call_type: call_type, submit: submit}, function(data) {
		window.location = redirect_to;
	});
}
function change_conviction(conv_type) {
	$('#conviction_img').attr('src','/images/sentiments/conviction_'+conv_type+'.gif');
	document.getElementById('conviction_value').value = conv_type;
}
function sentiment_change_img(id, img_src, check_chosen) {
	update = true;
	if(check_chosen==true) {
		if( ($('#'+id).attr('src') == '/images/sentiments/bearish_vote_small_chosen.png') || ($('#'+id).attr('src') == '/images/sentiments/bullish_vote_small_chosen.png')) {
			update = false;
		}
	}
	if(update==true){
		$('#'+id).attr('src','/images/sentiments/'+img_src);
	}
}
function sentiment_change_call(call_type) {
	sentiment_change_img('form_vote_'+call_type+'_img',call_type+'_vote_small_chosen.png');
	$('#call_type').val(call_type);
	var call_other_type = (call_type=='bullish'?'bearish':'bullish');
	sentiment_change_img('form_vote_'+call_other_type+'_img',call_other_type+'_vote_small.png');
}
function validate_sentiment_comment(session_logged) {

	if(session_logged=='true') { 
	    var output = '';
	    $("#comment_form_msgbox").fadeTo(200,0.1,function() { //start fading the messagebox
	      //add message and change the class of the box and start fading
	      if(output=='') {
	      	$(this).html('Sending.....').addClass('messageboxok').fadeTo(900,1,
	      	function() {
	      		//if(session_logged!='true') {
	      		//} else {
	          		$.get("/common/sentiments/sentiments_ajax.php",{ action:'add_comment', call_type:$('#call_type').val(), pair_ID:$('#pair_id').val(), open:$('#sentiment_pair_open').val(), conviction_value:$('#conviction_value').val(), sentiment_timeframe:$('#sentiment_timeframe').val(), text:$('#comment_text').val() } ,function(data) {
	          			sentiment_comment_added(data);
				   });
	          	//}
	      	});
	      } else {
	      	$(this).html(output).removeClass().addClass('messageboxerror').fadeTo(900,1);
	      }
	    });
	}
    return false;
}
function sentiment_comment_added(data) {
	   document.getElementById('sentiment_comment_box').style.display='none';
	   document.getElementById('lightbox_filter').style.display='none';
	   // update the percentage bar
	   $('#sentiments_box_container').html(data);
}
function follow111(follower) {
	jQuery("#"+follower).show();
	jQuery(document).mousemove(function(e){
		//alert(e.pageY);
		jQuery("#"+follower).css({
			top: e.pageY - 200 + "px",
			left: e.pageX - 45 + "px"
		});
	});
}
function disable_links_in_pitches_box() {
	$('#pitches_bullish_submit_row').remove();
	$('#pitches_bearish_submit_row').remove();
}
function sentimentLimitText(limitField, limitNum,_txt_qouta_too_long_pre,_txt_qouta_too_long_post) {
	if (limitField.value.length <= limitNum) {
		$('#comment_text_chars_count').html(limitField.value.length);
	} else {
        limitField.value = limitField.value.substring(0, limitNum);
        alert(_txt_qouta_too_long_pre+" "+limitNum+" "+_txt_qouta_too_long_post);
    } 
}
function show_sentiment_chart(strXML, div_container)
{
	var myChart = new FusionCharts("/common/flash-charts/FCF_Column2D.swf", "chart_"+div_container, "160", "130");
	myChart.setDataXML(strXML);
	myChart.render(div_container);
}