$(document).ready(function() {

  $("#historyTable tr:first").css("background-color", "#82B587");
  $("#historyTable th").css("background-color", "#BDCB9A");
  $("#historyTable").css("border-bottom", "solid 2px #82B587");
  $(".formTable tr td:first").css("font-weight", "bold");
  $(".formTable input[type=text]'").css("width", "100%");

  //$(".question").wTooltip();  
  
  var height = $(window).height();
  $("#mainContent").css("min-height", height-125);
  
});
$(window).resize(function(){
  var height = $(window).height();
  $("#mainContent").css("min-height", height-125);
  drawChart();
});


function toggle_chart_data(x, the_data){
	if(x.checked==true){
		chart.showDataColumns(the_data);
	}
	else{
		chart.hideDataColumns(the_data);
	}
}

function connect_user(user_id, f){
	
	$.post("functions.php", { "f": f, "user_id": user_id },
  function(data){
    //alert(data.result);
  }, "json");

}
function move_news(news_id, update){
  
  $.post("functions.php", { "f": "move_news", "news_id": news_id, "update": update },
  function(data){
    $("#box_"+news_id).slideUp("slow");
  }, "json");
  
}//end function move_news
function new_news(id, news_title, news_body, news_notes, news_link, news_publisher, news_image, s){

  $.post("functions.php", { "f": "write_news", "id": id, "news_title": news_title, "news_body": news_body, "news_notes": news_notes, "news_link": news_link, "news_publisher": news_publisher, "news_image": news_image, "s": s  },
  function(data){
    
    //alert(data.result);
    if(data.result=="success"){
      document.location = "?news&success";
    }
    
  }, "json");

}//end function new_news
function edit_news(id){
  
  $.post("functions.php", { "f": "edit_news", "id": id },
  function(data){
    
    //alert(data.result);
    if(data.result=="success"){
      
      document.newNewsForm.news_title.value = data.news_title;
      document.newNewsForm.news_body.value = data.news_body;
      document.newNewsForm.news_notes.value = data.news_notes;
      document.newNewsForm.news_link.value = data.news_link;
      document.newNewsForm.news_publisher.value = data.news_publisher;
      document.newNewsForm.news_image.value = data.news_image;
      document.newNewsForm.id.value = data.id;
      $("#message").text("(Editing)");
      
    }
    
  }, "json");
  
}//end function edit_news
function send_tweet(message){

  $.post("functions.php", { "f": "send_tweet", "message": message },
  function(data){
    
    if(data.result=="success"){
      
      document.sendTweetForm.message.value = "";
      
    }
    
  }, "json");

}//end function send_tweet
function update_tweet_field(){
  var textlen = document.sendTweetForm.message.value.length;
  if(textlen>130){
    $("#text_count").css("color", "#B5340D");
  }
  else if(textlen>120){
    $("#text_count").css("color", "#F58122");
  }
  else{
    $("#text_count").css("color", "#AAAAAA");
  }
  if(textlen>140){
    //$("input[type='submit']").hide();
    $("input[type='submit']").attr("disabled", "true");
  }
  else{
    //$("input[type='submit']").show();
    $("input[type='submit']").removeAttr("disabled");
  }
  $("#text_count").text(140-textlen);
}

function toggle_graph(){
  var n_h;
  var h = $("#chart_div").height();
  if(h<300){
    n_h = 550;
    $("#toggle_chart_link").html("Smaller");
  }
  else{
    n_h = 250;
    $("#toggle_chart_link").html("Larger");
  }
  $("#chart_div").height(n_h);
  drawChart();
}//end funciton toggle_graph

function popupWindow(x){
  
  window.open('popup.php?msg='+x, 'popup_explanation', 'width=400,height=300,scrollbars=yes,resizeable=yes');
  
}//end function popupWindow