/**
* Functions to add the SMS sending functionality, using jQuery UI and some character limiting
*
* @author Fruitbowl Media, Liam Gooding
* @author URL: http://www.fruitbowlmedia.com, http://liamgooding.com, http://twitter.com/liamgooding
*
**/
jQuery(document).ready(function($){
	
	$("#feedback").dialog({
		modal: true,
		autoOpen:false,
		buttons: {
			Ok: function() {
				$( this ).dialog( "close" );
			}
		}
	});
						
	$("#sms-send").hide();
	$("#sms-form-wrap").dialog({
		autoOpen: false,
		modal:true,
		title: 'Contact TNE Electrical via SMS text message',
		width:500,
		height:400,
		buttons: {
			Cancel: function() {
				$( this ).dialog( "close" );
			},
			Send: function() {
				$("#sms-form").slideUp().before("Sending...");
				$.post("/functions/tne-sms-sender.php", $("#sms-form").serialize(),
					function(data) {
						$("#feedback span").text(data);
						$("#feedback").dialog('open');
						$("#sms-form :input").not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');	
						$("#sms-form-wrap").dialog( "close" );
					});
			}
		}
	
	});
	
	$("#open-sms, .open-sms").click(function(){
		$("#sms-form-wrap").dialog("open");
		$("#sms-form").show();
		return false;
	});
	
	$('#sms-message').textLimit(70,function( length, limit ){
		$("#sms-limitleft span").text( limit - length );
	});
});
