// Symbol inserter
var symbolInserted

// Row 1
var music2note=String.fromCharCode('9835');
var music1note=String.fromCharCode('9834');
var music8thNotes=String.fromCharCode('9836');
var heartFull=String.fromCharCode('9829');
var heartOpen=String.fromCharCode('9825');
var heartSideways=String.fromCharCode('10085');
var faceSmiley=String.fromCharCode('9786');
var faceFrown=String.fromCharCode('9785');
var star5pointOpen=String.fromCharCode('10025');
var star5pointSolid=String.fromCharCode('9733');
var male=String.fromCharCode('9794');
var female=String.fromCharCode('9792');
var sun=String.fromCharCode('9788');
var cloud=String.fromCharCode('9729');
var umbrella=String.fromCharCode('9730');
var peace=String.fromCharCode('9774');
var tao=String.fromCharCode('9775');
var starDavid=String.fromCharCode('10017');
var cross=String.fromCharCode('10013');
// Row 2
var mDash=String.fromCharCode('8212');
var nDash=String.fromCharCode('8211');
var exclamDbl=String.fromCharCode('8252');
var asterisk=String.fromCharCode('42');
var degree=String.fromCharCode('186');
var ellipses=String.fromCharCode('8230');
var bulletBold=String.fromCharCode('8226');
var arrowRtBold=String.fromCharCode('9658');
var arrowLeftBold=String.fromCharCode('9668');
var mailIcon=String.fromCharCode('9993');
var handPtRt=String.fromCharCode('9755');
var pencilRt=String.fromCharCode('9999');
var soundBlare=String.fromCharCode('9732');
var writingHand=String.fromCharCode('9997');
var blockSolid=String.fromCharCode('9608');
var blockLeft=String.fromCharCode('9612');
var blockRt=String.fromCharCode('9616');
var blockBottom=String.fromCharCode('9604');
var blockTop=String.fromCharCode('9600');
// Row 3
var oneHalf=String.fromCharCode('189');
var oneQuarter=String.fromCharCode('188');
var euro=String.fromCharCode('8364');
var poundSterling=String.fromCharCode('163');
var qMarkUpsideDn=String.fromCharCode('191');
var exclamUpsideDn=String.fromCharCode('161');
var copyright=String.fromCharCode('169');
var registered=String.fromCharCode('174');
var tm=String.fromCharCode('8482');
var checkmark=String.fromCharCode('10004');
var xMark=String.fromCharCode('10006');
var arrowUp=String.fromCharCode('8593');
var arrowDown=String.fromCharCode('8595');
// var chevronLeft=String.fromCharCode('171');
// var chevronRt=String.fromCharCode('187');
var approximately=String.fromCharCode('8776');
var notEqual=String.fromCharCode('8800');
var plusEqual=String.fromCharCode('177');
var lessThanEqual=String.fromCharCode('8804');
var greaterThanEqual=String.fromCharCode('8805');
var infinity=String.fromCharCode('8734');
// Row 4
var clubs=String.fromCharCode('9827');
var diamonds=String.fromCharCode('9830');
var spades=String.fromCharCode('9824');
var chessK_w=String.fromCharCode('9812');
var chessQ_w=String.fromCharCode('9813');
var chessR_w=String.fromCharCode('9814');
var chessB_w=String.fromCharCode('9815');
var chessN_w=String.fromCharCode('9816');
var chessP_w=String.fromCharCode('9817');
var chessK_b=String.fromCharCode('9818');
var chessQ_b=String.fromCharCode('9819');
var chessR_b=String.fromCharCode('9820');
var chessB_b=String.fromCharCode('9821');
var chessN_b=String.fromCharCode('9822');
var chessP_b=String.fromCharCode('9823');
var skullCrossbones=String.fromCharCode('9760');
var star8points=String.fromCharCode('10037');
var flowerPetals=String.fromCharCode('10045');
var starburst=String.fromCharCode('10042');

function Set_Cookie( name, value, expires, path, domain, secure ) 
//from http://techpatterns.com/downloads/javascript_cookies.php see also: http://www.quirksmode.org/js/cookies.html
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/* if the expires variable is set, make the correct expires time, the current script below will set
it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24 */

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
// End Set_Cookie

/*Set_Cookie( 'mycookie', 'input_username', 30, '/', '', '' );. Don't forget to put in empty quotes for the unused parameters or you'll get an error when you run the code. This makes the cookie named 'mycookie', with the value of 'visited 9 times', and with a life of 30 days, and the cookie is set to your root folder.

The Set_Cookie values for 'domain' and 'secure' are not utilized. Use 'domain' on the Javascript cookie if you are using it on a subdomain, like widgets.yoursite.com, where the cookie is set on the widgets subdomain, but you need it to be accessible over the whole yoursite.com domain.

It's good practice to not assume the path to the site root will be set the way you want it by default, so do this manually as a rule, '/'. If no value is set for expires, it will only last as long as the current session of the visitor, and will be automatically deleted when they close their browser. */


// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
// End Get_Cookie

  function insertSymbol(symbolInserted)
	   {
document.getElementById('input_message').value = document.getElementById('input_message').value + symbolInserted; 
document.getElementById('user_complete_count').value = document.getElementById('user_complete_count').value-1 //fixed by DGL
document.getElementById('input_message_count').value = document.getElementById('input_message_count').value-1 //fixed by DGL
document.getElementById('input_message').focus(); return true;
}

// Prefixes
var Retweet = 'http://twitter.com/home?status=RT @';
var Tweet = 'http://twitter.com/home?status=';
var Search = 'http://twitter.com/#!/search/realtime/';
var rt_keywords = 'rt%20OR%20%22r%2Ft%22%20OR%20retweet%20OR%20retweeting%20OR%20via%20%40';

// Suffixes
var Retweet_suffix = '%20--Retweet%3E%20';
var Share_suffix = '%20--Share%3A%20';

function rtSearch(input_username){ 
	var str_username=trim(document.getElementById(input_username).value);
	if(str_username == ""){
		alert("Type a Twitter username in the box under step 1 and try again");
		return false;
	} // if

var rt_search_url = Search+rt_keywords+EncodeURL(document.getElementById(input_username).value);
	open_newwindow(rt_search_url);
} // function

function retweet_Link(input_username, input_message, output_field){ 

	var str_username=trim(document.getElementById(input_username).value);
	var str_message=trim(document.getElementById(input_message).value);
	
	if(str_username == ""){
		alert("Type a Twitter username in the box under step 1 and try again");
		return false;
	} // if

	if(str_message == ""){
		alert("Type a message first and try again");
		return false;
	} // if
	
	// Step1 - RETWEET + USERNAME + TEXT MESSAGE
	var request_url_encoded = Retweet+EncodeURL(str_username+' '+str_message);
	
	// GET FIRST SHORT URL
	BitlyCB.shortenResponseFrt = function(Frtdata) {
		var first_result;
		for (var Frtr in Frtdata.results) {
			first_result = Frtdata.results[Frtr]; break;
		} // for
		
		var short_url = first_result['shortUrl'].toString();

		// Short URL + New preset text string
		document.getElementById(input_message).value = str_message+DecodeURL(Retweet_suffix)+short_url; 
		document.getElementById('input_message_count').value = document.getElementById('input_message').value.length;
		all_control_counter();
		document.getElementById(input_message).select();

	} // function

	BitlyClient.shorten(request_url_encoded, 'BitlyCB.shortenResponseFrt');
	
} // function

function share_Link(input_username, input_message, output_field){ 

	var str_username=trim(document.getElementById(input_username).value);
	var str_message=trim(document.getElementById(input_message).value);
	
	if(str_username == ""){
		alert("Type a Twitter username in the box under step 1 and try again");
		return false;
	} // if

	if(str_message == ""){
		alert("Type a message first and try again");
		return false;
	} // if
	
	// Step1 - RETWEET + USERNAME + TEXT MESSAGE
	var request_url_encoded = Retweet+EncodeURL(str_username+' '+str_message);
	
	// GET FIRST SHORT URL
	BitlyCB.shortenResponseFrt = function(Frtdata) {
		var first_result;
		for (var Frtr in Frtdata.results) {
			first_result = Frtdata.results[Frtr]; break;
		} // for
		
		var short_url = first_result['shortUrl'].toString();

		// Short URL + New preset text string
		document.getElementById(input_message).value = str_message+DecodeURL(Share_suffix)+short_url; 
		document.getElementById('input_message_count').value = document.getElementById('input_message').value.length;
		all_control_counter();
		document.getElementById(input_message).select();

	} // function

	BitlyClient.shorten(request_url_encoded, 'BitlyCB.shortenResponseFrt');
	
} // function

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
} // function

function message_only(input_message){
	
	var testString = Tweet+'testString';
	document.getElementById(input_message).value = testString;
	
} // function

// function tweet_it(url_input){
//	var new_url = Tweet+EncodeURL(document.getElementById(url_input).value);
//	open_newwindow(new_url);
// } // function


function tweet_it(url_input){ 
	var new_url = Tweet+EncodeURL(document.getElementById(url_input).value);
	open_newwindow(new_url);
} // function

function open_newwindow(new_url){

	if(new_url != Tweet){
		window.open(new_url, '', 'height=600,width=800,scrollbars=yes,resizable=yes');
	}else{
		alert("No URL is selected!");
	} // if
} // function

function CountLeft(field, count, max) {
 var count_f = document.getElementById(count);
 var input_f = document.getElementById(field);
 count_f.value = max - input_f.value.length;
 all_control_counter(); 
} // function

function all_control_counter(){ 

// additional counter
 var user_input_len = document.getElementById('input_username').value.length;
 if(user_input_len == 0){
	 user_input_count = 0;
 }else{
	 user_input_count = user_input_len+5;
 }
 document.getElementById('user_complete_count').value = 120-document.getElementById('input_message').value.length-user_input_count;
 document.getElementById('input_message_count').value = 140-document.getElementById('input_message').value.length; //fixed by DGL


} // function 

function EncodeURL(inputString){
	return encodeURIComponent(inputString);
} // function

function DecodeURL(inputString){
	return decodeURIComponent(inputString);
} // function

