$('#newsletter-form').submit(function() {
  alert('Handler for .submit() called.');
  return false;
});


//blanks a form input field. useful for having form labels as their default values.

function blank(a) { 
	if(a.value == a.defaultValue) a.value = "" 
}

//returns form to default value if unclicked and left blank
		
function unblank(a) { 
	if(a.value == "") a.value = a.defaultValue; 
}

function disable(a) {
	a.disabled = "true";
}

function enableElement(myButtonStatus, targetElement) {
	
	if(myButtonStatus==false) {
		$("#submit_button").attr('disabled', true);
	}
	else{
		$("#submit_button").attr('disabled', false);
	}
}

/**
 * Initiates Graph Functions
 **/
 function graphit($graph_id,$lines,$bar_margins,$bar_speed,$animate){
 
 $v = new Object(); // create graph object
 $v.graphid = $graph_id; // id of graph container, example "graph1" or "myGraph"
 $v.values = new Array(); // array of values
 $v.heights = new Array(); // array of bar heights
 $v.colors = new Array(); // colors for bars
 $v.lines = $lines; // number of lines - keep this 10 unless you want to write a bunch more code
 $v.bm = $bar_margins; // margins between the bars
 $v.mx = 0; // highest number, or rounded up number
 $v.gw = $('#'+$v.graphid+' .graph').width(); // graph width
 $v.gh = $('#'+$v.graphid+' .graph').height(); // graph height
 $v.speed = $bar_speed; // speed for bar animation in milliseconds
 $v.animate = $animate; // determines if animation on bars are run, set to FALSE if multiple charts
 
 getValues(); // load the values & colors for bars into $v object
 graphLines(); // makes the lines for the chart
 graphBars(); // make the bars
 if($v.animate)
 animateBars(0); // animate and show the bars
 }
 
 /**
 * Makes the HTML for the lines on the chart, and places them into the page.
 **/
 function graphLines(){
 $r = ($v.mx < 100)?10:100; // determine to round up to 10 or 100
 $v.mx = roundUp($v.mx,$r); // round up to get the max number for lines on chart
 $d = $v.mx / $v.lines; // determines the increment for the chart line numbers    
 
 // Loop through and create the html for the divs that will make up the lines & numbers
 $html = ""; $i = $v.mx;
 if($i>0 && $d>0){
 while($i >= 0){
 $html += graphLinesHelper($i, $v.mx);
 $i = $i - $d;
 }
 }
 $('#'+$v.graphid+' .graph').html($html); // Put the lines into the html
 $margin = $v.gh / $v.lines; // Determine the margin size for line spacing
 $('#'+$v.graphid+' .line').css("margin-bottom",$margin + "px");    // Add the margins to the lines
 }
 
 /**
 * Creates the html for the graph lines and numbers
 **/
 function graphLinesHelper($num, $maxNum){
 $fix = ($i == $maxNum || $i == 0)? "fix ":""; // adds class .fix, which removes the "border" for top and bottom lines
 return "<div class='"+$fix+"line'><span>" + $num + "</span></div>";
 }
 
 /**
 * A Simple Round Up Function
 **/
 function roundUp($n,$r){
 return (($n%$r) > 0)?$n-($n%$r) + $r:$n;
 }
 
 /**
 * Gets the values & colors from the HTML <labels> and saves them into $v ohject
 **/
 function getValues(){
 $lbls = $('#'+$v.graphid+' .values span'); // assigns the span DOM object to be looped through
 // loop through
 for($i=0;$i <= $lbls.length-1; $i++){
 $vals = parseFloat($lbls.eq($i).text());
 $v.colors.push($lbls.eq($i).css('background-color'));
 $v.mx = ($vals > $v.mx)?$vals:$v.mx;
 $v.values.push($vals);
 }
 }
 
 /**
 * Creates the HTML for the Bars, adds colors, widths, and margins for proper spacing.
 * Then Puts it on the page.
 **/
 function graphBars(){
 $xbars  = $v.values.length; // number of bars
 $barW    = ($v.gw-($xbars * ($v.bm))) / $xbars;
 $mL     = ($('#'+$v.graphid+' .line span').width()) + ($v.bm/2);
 $html="";
 for($i=1;$i<=$xbars;$i++){
 $v.heights.push(($v.gh / $v.mx) * $v.values[$i-1]);
 $ht = ($v.animate == true)?0:$v.heights[$i-1];
 $html += "<div class='bar' id='"+$v.graphid+"_bar_"+($i-1)+"' style='height: "+$ht+"px; margin-top: -"+($ht+1)+"px; ";
 $html += "background-color: "+$v.colors[$i-1]+"; margin-left: "+$mL+"px'>&nbsp;</div>";
 $mL = $mL + $barW + $v.bm;
 }
 $($html).insertAfter('#'+$v.graphid+' .graph');
 $('#'+$v.graphid+' .bar').css("width", $barW + "px");
 }
 
 /**
 * Animates the Bars to the correct heights.
 **/
 function animateBars($i){
 if($i == $v.values.length){ return; }
 $('#'+$v.graphid+'_bar_'+$i).animate({
 marginTop: "-" + ($v.heights[$i] + 1) + "px",
 height: ($v.heights[$i]) + "px"
 },$v.speed,"swing", function(){animateBars($i+1); });
 }

