
	function checkFrmShorten() {
		  
		if ($('input#urlIn')) {
			var long_url = $('input#urlIn').val();
			var url      = "http://api.socialflow.biz:4005/jsonrpc"; 			
			if (long_url == "") {				
				$('#frmUrl span')[0].style.color = 'red';
				return false;
			}
			else {
				$.get("/url/shorten", { long_url: long_url },					
				
				 	function(data){	
						$('#urlTarget').empty();
						$('<p><a href="' + data + '" target="none">' + data + '</a></p>').appendTo("#urlTarget");					
						jQuery(document).trigger('close.facebox');
  					});

				  return false;
			}
		}
	}

$(document).ready(function() {

	$('a[rel*=facebox]').facebox()

	// Calculate char count for id = field_to_count inputs
	// get current number of characters
	if ('defined' == $('#field_to_count')) {
		$('#counter').html($('#field_to_count').val().length + ' chars');
	}
	
	$('#field_to_count').keyup(function()
	{
		// get new length of characters
		$('#counter').html($(this).val().length + ' chars');
	});

// 	THIS WORKS WELL IN FF, BUT IE DOESN'T LIKE IT AT ALL, SO LEAVING OUT FOR NOW
// 	// Adding in calendar&time fields
// 	function addField () {
// 			$("input:radio[name='status'][value='Publish On']").next('.fb_option').after('<input type="text" id="timeDate" name="timeDate"><br />');
// 			$('#timeDate').datetimepicker({ 
// 				dateFormat: 'yy-mm-dd',
// 				timeFormat: ' hh:ii:ss',
// 				showButtonPanel: true				
// 			});	
// 	}
// 
// 	// Bind this event to the radio button click in the add / edit form
// 	$("input:radio[name='status']").click(function() {
// 	    if(this.value == 'Publish On') {
// 	      	// Add in Date field
// 	      	console.log("Fired the click handler for status change");
// 			addField();
// 			$(this).unbind('click');
// 	    }else{
// 	      	console.log("Fired the unbind click handler for status change");
// 	        $('#timeDate').next('br').remove();
// 	        $('#timeDate').remove();	        
// 			$("input:radio[name='status'][value='Publish On']").bind('click', addField);
// 	    }
// 	});
// 
// 	// Adding in calendar&time fields
// 	function addPipelineField (id) {
// 			console.log("In the addPipelineField function for id " + id);
// 			$("input:radio[id='" + id + "'][value='Publish On']").next().after('<input type="text" id="timeDate' + id +'" name="not_before_date"><br />');
// 			$('#timeDate' + id).datetimepicker({ 
// 				dateFormat: 'yy-mm-dd',
// 				timeFormat: ' hh:ii:ss',
// 				showButtonPanel: true				
// 			});	
// 	}
// 
// 	// Bind this event to the radio button click in the add / edit form
// 	$("input:radio[name='pipeline_status']").click(function() {
// 	    if(this.value == 'Publish On') {
// 	      	// Add in Date field
// 	      	console.log("Fired the click handler for pipeline status change " + this.id);
// 			addPipelineField(this.id);
// 	    }else{
// 	      	console.log("Fired the unbind click handler for pipeline status change " + this.id);
// 	        $('#timeDate' + this.id).next('br').remove();
// 	        $('#timeDate' + this.id).remove();	        
// 	    }
// 	});

	// Add Calendar to ToolContainer Publish On field
	$('#toolContainer_dateTime').datetimepicker({ 
		dateFormat: 'yy-mm-dd',
		timeFormat: ' hh:ii:ss',
		showButtonPanel: true				
	});

	// Turn it on if we have a not before date
	$('#not_before_date').datetimepicker({ 
		dateFormat: 'yy-mm-dd',
		timeFormat: ' hh:ii:ss',
		showButtonPanel: true				
	});

	// Turn it on if we have an expiration date
	$('#expiration_date').datetimepicker({ 
		dateFormat: 'yy-mm-dd',
		timeFormat: ' hh:ii:ss',
		showButtonPanel: true				
	});

	// Turn it on if we have a start date
	$('#start_date').datetimepicker({ 
		dateFormat: 'yy-mm-dd',
		timeFormat: ' hh:ii:ss',
		showButtonPanel: true,				
		showHourData: false
	});

	// Turn it on if we have an end date
	$('#end_date').datetimepicker({ 
		dateFormat: 'yy-mm-dd',
		timeFormat: ' hh:ii:ss',
		showButtonPanel: true,				
		showHourData: false
	});

// 	
// 	// Begin Drag and drop sort
// 	$(function() {
// 		$("#doSort").sortable({ opacity: 0.6, cursor: 'move', update: function() {
// 			var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
// 			$.post("updateDB.php", order);
// 		}
// 		});
// 	});
	
});

     
