// JavaScript Document

function TigerStripeTable()
{
	$("table.tigerstripe tbody tr.oddrow").removeClass("oddrow");
	$("table.tigerstripe tbody tr:not(.SpacerRow,.TigerStripeEception):odd").addClass("oddrow");	
	$("table.tigerstripe tbody tr:not(.nohover)").hover(
		  function () {
			$(this).addClass("TigerStripeHover") ;
		  }, 
		  function () {
			$(this).removeClass("TigerStripeHover") ;
		  }
	);
}

function LoadJSONResults(data){
	var resultErrors = "";
	var countErrors = 0 ;
	var resultWarnings = "";
	var countWarnings = 0 ;
	var resultSuccess = "";
	var countSuccess = 0 ;
	
	$.each(data.errors,function(i,item) {
		resultErrors += '<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>' + item + '</p>';
		countErrors++ ;
	});
	if ( resultErrors.length ) {
		resultErrors = '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">' + resultErrors + '</div>' ;
	}

	$.each(data.warnings,function(i,item) {
		resultWarnings += '<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>' + item + '</p>';
		countWarnings++;
	});
	if ( resultWarnings.length ) {
		resultWarnings = '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;">' + resultWarnings + '</div>' ;
	}
	
	$.each(data.success,function(i,item) {
		resultSuccess += '<p><span class="ui-icon ui-icon-check" style="float: left; margin-right: 0.3em;"></span>' + item + '</p>';
		countSuccess++ ;
	});
	if ( resultSuccess.length ) {
		resultSuccess = '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;">' + resultSuccess + '</div>' ;
	}
	$('#Results').html( resultErrors + resultWarnings + resultSuccess ).data("countErrors",countErrors ).data("countWarnings",countWarnings ).data("countSuccess",countSuccess );
}


function AddActionsToTable(  )
{
	$("table.AddLinksTable").each( function(i){
		//var ChartID = getChartFromId( $("#" + this.id ).attr("chartID") );
		var TableName = this.id ;
		var DataToDisplayName = this.id + "datatodisplay" ;
		var SaveToDisk = "<div class='TableToolBar'><form action='/SaveToExcel' class='SaveToExcel' method='post' target='_blank' style='display:inline' myTableName='" + TableName + "' myHiddenFieldName='" + DataToDisplayName + "'><input  type='image' src='http://www.sycara.com/images/icons/Floppy-48x48.png' width='12' height='12'><input type='hidden' id='" + DataToDisplayName + "' name='" + DataToDisplayName + "' /></form></div>" ;
		
		
		if ($("#" + DataToDisplayName ).length === 0 )
		{
			$("#" + TableName ).after( SaveToDisk ) ;
		}
	} ) ;
}


var AjaxCounter = 0 ;
function IncreaseAjaxCount()
{
	   AjaxCounter++ ;
	   $("#UpdateProgressIndicator").html("<img src='/assets/images/loading.gif' alt='' border='0' /> Loading content...(" + AjaxCounter + ")" ).show() ;
	   //alert( "AjaxCount + " + AjaxCount ) ;
}
function DecreaseAjaxCount()
{
	   AjaxCounter-- ;
	   //alert( "AjaxCount - " + AjaxCount ) ;
	   if ( AjaxCounter <= 0 )
	   {
		   $("#UpdateProgressIndicator").hide();
		   AjaxCounter = 0 ;
	   }
	   else {
		   $("#UpdateProgressIndicator").html("<img src='/assets/images/loading.gif' alt='' border='0' /> Loading content...(" + AjaxCounter + ")" ).show() ;
	   }
}



$(function() {
	$.ajaxSetup({
	  cache: false
	});
	
	
	$('.SaveToExcel').live( 'submit', function() {
	//onsubmit='$(\"#" + DataToDisplayName + "\").val( $(\"<div>\").append( $(\"#" + TableName + "\").eq(0).clone() ).html() )'
		var TableName = $(this).attr('myTableName') ;
		var DataToDisplayName = $(this).attr('myHiddenFieldName') ;
		$("#" + DataToDisplayName ).val( $("<div>").append( $('#' + TableName ).eq(0).clone() ).html() )
	} ) ;
	
	
	$("#UpdateProgressIndicator").bind("ajaxSend", function(){
		IncreaseAjaxCount() ;
	}).bind("ajaxComplete", function(){
		DecreaseAjaxCount() ;
	}).bind("ajaxStart", function(){
		AjaxCounter = 0 ;
		$("#UpdateProgressIndicator").hide();
	}).bind("ajaxStop", function(){
		AjaxCounter = 0 ;
		$("#UpdateProgressIndicator").hide();
	});
	

// Trim any input fields on any forms
	$("input").change( function() 
					{ 
						$(this).attr("value", $.trim( $(this).attr("value") )	);
					});
	$("textarea").change( function() {
						$(this).attr("value", $.trim( convertCharacter( $(this).attr("value") ) )	);
								   });

$("#PostBody").keyup( function() {
			var WordCount = CountWords( $(this).val()	) ;
			$('#PostBodyWordCount').html(WordCount + " Words");
									});
$("#EditPostBody").keyup( function() {
			var WordCount = CountWords( $(this).val()	) ;
			$('#EditPostBodyWordCount').html(WordCount + " Words");
									});
});


function convertCharacter( sVal ) {
	var myRegEx = new RegExp( String.fromCharCode( 8216 ) + "|" + String.fromCharCode( 8217 ), "g" );
	sVal = sVal.replace( myRegEx, "'" );
	var myRegEx = new RegExp( String.fromCharCode( 8220 ) + "|" + String.fromCharCode( 8221 ), "g" );
	sVal = sVal.replace( myRegEx, '"' );

	var myRegEx = new RegExp( String.fromCharCode( 61558 ) + "|" + String.fromCharCode( 8226 ) + "|" + String.fromCharCode( 61607 ), "g" );	
	sVal = sVal.replace( myRegEx, String.fromCharCode( 111 ) );

	var myRegEx = new RegExp( String.fromCharCode( 8211 ), "g" );
	sVal = sVal.replace( myRegEx, "-" );

	var myRegEx = new RegExp( String.fromCharCode( 8230 ), "g" );
	sVal = sVal.replace( myRegEx, "..." );

	var myRegEx = new RegExp( String.fromCharCode( 8482 ), "g" );
	sVal = sVal.replace( myRegEx, "TM" );

	var myRegEx = new RegExp( String.fromCharCode( 169 ), "g" );
	sVal = sVal.replace( myRegEx, "(c)" );

	var myRegEx = new RegExp( String.fromCharCode( 174 ), "g" );
	sVal = sVal.replace( myRegEx, "(r)" );

	var myRegEx = new RegExp( String.fromCharCode( 187 ), "g" );
	sVal = sVal.replace( myRegEx, ">>" );

	var myRegEx = new RegExp( String.fromCharCode( 171 ), "g" );
	sVal = sVal.replace( myRegEx, "<<" );
	
	return sVal ;
}



<!-- Original:  Shawn Seley -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function CountWords ( sString ) {
//if (show_word_count == null) {
//show_word_count = true;
//}
//if (show_char_count == null) {
//show_char_count = false;
//}
var char_count = sString.length;
var fullStr = sString + " ";
var removedHotLinks = fullStr.replace( /\[([^+]*)([^\]]*)\]/gi , "$1" ) ;

var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = removedHotLinks.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}//
//if (word_count == 1) {
//wordOrWords = " word";
//}
//else {
//wordOrWords = " words";
//}
//if (char_count == 1) {
//charOrChars = " character";
//} else {
//charOrChars = " characters";
//}
//if (show_word_count & show_char_count) {
//alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
//}
//else {
//if (show_word_count) {
//alert ("Word Count:  " + word_count + wordOrWords);
//}
//else {
//if (show_char_count) {
//alert ("Character Count:  " + char_count + charOrChars);
//      }
//   }
//}
return word_count;
}
//  End -->