(function($) {

	jQuery.rtn = {	};

	jQuery.rtn.dialog = {
		/* Buttons */
		BUTTON_CANCEL: {
			"Cancel": function() {
				$(this).dialog('destroy');
			}
		},
		BUTTON_TURNED_IN_LESSON: {
			"Continue": function() {
				$(this).dialog('destroy');
				TurnedInHeaderOut();
			}
		},
		BUTTON_TURNIN_LESSON : {
			"Turn In" : function() {
				$(this).dialog('destroy');
				FormConfirmSubmit();
			}
		},
		POST_ANNOUNCEMENT: {
			"Post Announcement": function() {

				var subject = $("#txt1").val();
				var message = $("#msg").val();
				var class_id = $("#class_id").val();
				var user_id = $("#user_id").val();
				var errors = [];

				if (message == 'Type away...'){
					errors.push('No message enetered');
				}
				if (message.length > 200){
					errors.push('Message must be less than 200 characters long.');
				}
				if (subject.length > 250){
					errors.push('Subject must be less than 250 characters long.');
				}
				if(errors.length > 0){
					$(this).dialog('destroy');
					$.rtn.dialog.error($.rtn.dialog.BOX_ANNOUNCEMENT_FAILED, errors);
				} else {
					$(this).dialog('destroy');
					$.getJSON('../includes/js/json_announcement.php',{
					u: user_id, c: class_id, s: subject, m: message},
					 function(json){
						$.rtn.dialog.alert($.rtn.dialog.BOX_ANNOUNCEMENT_SUCCESS);
					});
				}

				//document.location.href = "../rtnexperience/teacher_course_home.php";
				}
		},
		POST_CONTACT_SEND: {
			"Send": function() {
				var CNTVars = {
					From	: $('input[name=FRM_CNT_From]').val(),
					Email	: $('input[name=FRM_CNT_Email]').val(),
					Subject : $('input[name=FRM_CNT_Subject]').val(),
					Body	: $('textarea[name=FRM_CNT_Body]').val()
				};
				var errors = [];

				// Valid Email -----------------------------------------[BD]
				function ValidEmail(Email) {
					var RegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

					if(RegExp.test(Email) == false) {
						return true;
					} else {
						return false;
					}
				}
				//------------------------------------------------------[BD]

				// Error Checking --------------------------------------[BD]
				if ( ValidEmail(CNTVars.From) )
					errors.push('Please enter a valid email address.');

				if (CNTVars.Subject == 'Type Subject Here' || CNTVars.Subject == ' ')
					errors.push('Please enter a subject.');

				if (CNTVars.Body == 'Type away' || CNTVars.Body == ' ')
					errors.push('Please enter the body of your message.');

				if (errors.length > 0) {
					$('.ContactErrors').remove();
					$('.FRM_Row:first').before('<ul class="ContactErrors"><li>' + errors.join('</li><li>') + '</li></ul>');
					return;
				}
				//------------------------------------------------------[BD]

				// Success ---------------------------------------------[BD]
				$(this).dialog('destroy');
					$.getJSON('../rtnexperience/contact.email.process.php', {
						From	: CNTVars.From,
						Email	: CNTVars.Email,
						Subject	: CNTVars.Subject,
						Body	: CNTVars.Body
					}, function(json){
						$.rtn.dialog.alert($.rtn.dialog.POST_CONTACT_SEND_SUCCESS);
					});
				}
				//------------------------------------------------------[BD]
		},
		BUTTON_CONTINUE: {
			"Continue": function() { $(this).dialog('destroy'); }
		},
		BUTTON_CONTINUE_HOME: {
			"Continue": function() { document.location.href = "/"; }
		},
		BUTTON_LOGIN: {
			"Continue": function() { document.location.href = "/login.php"; }
		},
        BUTTON_SIGNUP: {
			"Sign Up": function() { document.location.href = "/signup.php"; }
		},
		BUTTON_TRYAGAIN: {
			"Try Again": function() { $(this).dialog('destroy'); }
		},
        BUTTON_CONTINUE_CLICK: {
			"Continue Anyway": function() {
				$('a').unbind('click.protect');
				$.rtn.dialog.followLink($.rtn.dialog.protectEvent);
				$(this).dialog('destroy');
			}
		},
		BUTTON_CONTINUE_CLICK2: {
			"Continue": function() {
				$('a').unbind('click.protect');
				$.rtn.dialog.followLink($.rtn.dialog.protectEvent);
			}
		},
		BUTTON_CONTINUE_CUSTOM: {
			"Continue": function() {
				$('#frm-vehicle-continue').unbind('submit');
				$('#frm-vehicle-continue').submit();
			}
		},
		BUTTON_NEW_WINDOW: {
			"Download File": function() {
				protectEvent = jQuery.rtn.dialog.protectEvent;
				$('a').unbind('click.protect');
				$(protectEvent.target).click();
				window.open($.rtn.dialog.getLink(protectEvent));
				$(this).dialog('destroy');
			}
		},
		BUTTON_REFRESH: {
			"Continue": function() {
				$(this).dialog('destroy');
				document.location.reload(true);
			}
		},
		BUTTON_CLOSE: {
			"Close": function() {
				$(this).dialog('destroy');
			}
		},
        BUTTON_REQUEST: {
            "Request a new Confirmation Email": function() {
                document.location.href = "/login_resend_confirmation.php";
            }
        },
        BUTTION_CONTINUE_CONFIRMATION: {
            "Continue": function() { document.location.href = "/login.php"; }
        },
        BUTTION_STAY_LOGGED_IN: {
            "Ok"		: function() { 
							stayLoggedIn();
							setTimeout('$.rtn.dialog.alert($.rtn.dialog.BOX_STAY_LOGGED_IN)', 900000);
							$(this).dialog('destroy');
						}
        },
		BUTTON_DELETE_VIDEO: {
			"Continue": function() {
				$(this).dialog('destroy');
				confirmVideoDelete();
			}
		},
		BUTTON_CANCEL_VIDEO_UPLOAD: {
			"Continue": function() {
				$(this).dialog('destroy');
				reloadVideoWindow();
			}
		},
		/* Templates */
		BOX_STAY_LOGGED_IN: {
			title: "Warning!",
			text: "Your session is about to time out. Please click OK to stay logged in. Otherwise you may lose your work.",
			arrButtons: ['BUTTION_STAY_LOGGED_IN']
		},
		BOX_EMAIL_IN_USE: {
			title: "Oops!",
			text: "That email address is already in use.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_EMAIL_NOT_VALID: {
			title			: "Try Again!",
			text			: "<b>Yikes!</b><br /><br />We weren't able to find an account associated with that email address.",
			arrButtons		: ['BUTTON_TRYAGAIN', 'BUTTON_SIGNUP'],
			rtnDialogClass	: 'DAG_ForgotPassword'
		},
		NO_TEAM_NAME: {
			title: "Oops!",
			text: "You need to enter a team name to be able to save it!",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_POST_ANNOUNCEMENT: {
			title: "<font style='font-size: 16.21px; color: #ffffff; font-family: Trebuchet MS;'><b>Post Announcement</b></font> ",
			text: "<font style='font-size: 12px; color: #666666; font-family: arial;'>Post an announcement to your entire class right here: </font>",
			input_Subject: " <input type='text' style='font-size: 12px; color: #666666; width: 99%; font-family: arial;' id='txt1' onfocus=\"if ($('#txt1').val()=='Subject'){$('#txt1').val('');}\" onblur=\"if($('#txt1').val()==''){$('#txt1').val('Subject');}\" value ='Subject' MAXLENGTH = '100' />",
			input_Text: " <textarea class=\"text-area\" style='font-size: 12px; color: #666666; font-family: arial; width: 100%' rows=\"2\" id='msg' onfocus=\"if ($('#msg').val()=='Type away...'){$('#msg').val('');}\" onblur=\"if($('#msg').val()==''){$('#msg').val('Type away...').trigger('keyup');}\">Type away...</textarea> ",
			arrButtons: ['BUTTON_CANCEL', 'POST_ANNOUNCEMENT']
		},
		BOX_ANNOUNCEMENT_FAILED: {
			title: "Oops!",
			text: "Announcement was NOT posted.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_ANNOUNCEMENT_SUCCESS: {
			title: "Yay!",
			text: "Announcement was posted.",
			arrButtons: ['BUTTON_REFRESH']
		},
		BOX_FEEDBACK_SUCCESS: {
			title: "Yay!",
			text: "Feedback was sent.",
			arrButtons: ['BUTTON_REFRESH']
		},
		BOX_LESSON_SAVE: {
			title: "Yay!",
			text: "Your lesson answers were saved.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_LESSON_PURPOSE_INCOMPLETE: {
			title: "Hold up!",
			text: "You must add the team purpose.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_LESSON_BLOG_INCOMPLETE: {
			title: "Hold up!",
			text: "You must complete the blog first.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_FIELD_EMPTY: {
			title: "Hold up!",
			text: "You have to create a team name before you continue.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_WATCH_VIDEO: {
			title: "Hold up!",
			text: "You have to watch the entire lesson video to turn in your assignment!",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_INVALID_ACCOUNT: {
			title: "Yikes!",
			text: "We are unable to find an account associated with that email address.",
			arrButtons: ['BUTTON_TRYAGAIN', 'BUTTON_SIGNUP']
		},
		BOX_INVALID_ADDRESS: {
			title: "Oops!",
			text: "The location you entered is not valid.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_INVALID_LOGIN: {
			title: "Yikes!",
			text: "We are unable log you in with that email/password combination.",
			arrButtons: ['BUTTON_TRYAGAIN', 'BUTTON_SIGNUP']
		},
		BOX_NO_LOGIN: {
			title: "Oh no you didn't!",
			text: "You must first login to go there.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		MAINTENANCE: {
			title: "Maintenance!",
			text: "We're sorry but Roadtripnation.org is closed for maintenance Monday, Feb 22.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_CONFIRM_EMAIL: {
			title: "Yay!",
			text: "We've sent you a confirmation email! Please confirm your account by clicking on the confirmation link.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_FAVORITE_LOGIN: {
			title: "Hold up!",
			text: "In order to favorite something, you must be signed in!",
			arrButtons: ['BUTTON_LOGIN']
		},
		BOX_SUBSCRIBE_LOGIN: {
			title: "Hold up!",
			text: "In order to update your subscription, you must be signed in!",
			arrButtons: ['BUTTON_LOGIN']
		},
		BOX_SUBSCRIBE_UPDATED: {
			title: "Sweet!",
			text: "Your subscription has been updated!",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_NAVIGATE_AWAY: {
			title: "Hold up!",
			text: "Are you sure you want to navigate away from this page?",
			arrButtons: ['BUTTON_CANCEL','BUTTON_CONTINUE_CLICK']
		},
		BOX_FILE_SUCCESS: {
			title: "Yay!",
			text: "Your file was successfully uploaded.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_FILE_SIZE_FAILED: {
			title: "Whoops!",
			text: "Upload file size cannot be greater than 2MB.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_VIDEO_SIZE_FAILED: {
			title: "Whoops!",
			text: "Upload file size cannot be greater than 100MB or 3 minutes in length.",
			arrButtons: ['BUTTON_CANCEL_VIDEO_UPLOAD']
		},
		BOX_FILE_FORMAT_FAILED: {
			title: "Whoops!",
			text: "Images must be in one of these formats: .jpg, .gif, or .png.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_VIDEO_FORMAT_FAILED: {
			title: "Whoops!",
			text: "Videos must be in one of these formats: .avi, .flv, .mp4, .mpg, .wmv, or .mov.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_VIDEO_MISSING_FIELD: {
			title: "Whoops!",
			text: "Please complete your Video Detail by uploading a video and completing all required fields.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_FILE_FAILED: {
			title: "Whoops!",
			text: "An error occurred while uploading your file. Please try again.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_MISSING_FIELD: {
			title: "Whoops!",
			text: "You've missed a required field.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_MISSING_FIELD_LESSON: {
			title			: "Hold up!",
			text			: "You must answer the <nobr>question(s)</nobr> before you can turn in this assignment.",
			arrButtons		: ['BUTTON_CONTINUE'],
			rtnDialogClass	: 'DAG_Lesson'
		},
		BOX_MISSING_FIELD_LESSON19: {
			title			: "Hold up!",
			text			: "You haven't completed your Conversation Request.  Please ensure your text is correct and click on the \"Create Conversation Request\" button before you Turn In your assignment.",
			arrButtons		: ['BUTTON_CONTINUE'],
			rtnDialogClass	: 'DAG_Lesson'
		},
		BOX_CONFIRM_TURNIN_LESSON: {
			title			: "Hold up!",
			text			: "Are you sure you want to turn in this assignment? You will not be able to edit your <nobr>response(s)</nobr> once you've done this.",
			arrButtons		: ['BUTTON_TURNIN_LESSON', 'BUTTON_CANCEL'],
			rtnDialogClass	: 'DAG_Lesson'
		},
		BOX_CONFIRM_TURNED_IN_LESSON: {
			title			: "Confirmation",
			text			: "<b>Thanks</b><br /><br />This assignment has been turned in.",
			arrButtons		: ['BUTTON_TURNED_IN_LESSON'],
			rtnDialogClass	: 'DAG_Lesson'
		},
		BOX_ALREADY_EMAILED: {
			title: "Hang on!",
			text: "We've already sent an email to that person!",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_CONFIRM_DELETE: {
			title: "Not so fast!",
			text: "Are you sure you want to delete?"
		},
		BOX_CONFIRM_VIDEO_DELETE: {
			title: "Not so fast!",
			text: "Are you sure you want to delete this video?",
			arrButtons: ['BUTTON_DELETE_VIDEO', 'BUTTON_CANCEL']
		},
		BOX_CANCEL_VIDEO_UPLOAD: {
			title: "Not so fast!",
			text: "Your video is not done uploading. Are you sure you want to cancel uploading?",
			arrButtons: ['BUTTON_CANCEL_VIDEO_UPLOAD', 'BUTTON_CANCEL']
		},
		BOX_CONFIRM_VIDEO_DOWNLOAD: {
			title: "Wait!",
			text: "Before you download this file, please keep in mind all video content can only be uploaded on the Roadtrip Nation Website, not other websites like YouTube, Myspace or other media related sites.",
			arrButtons: ['BUTTON_NEW_WINDOW']
		},
		BOX_EMAIL_SENT: {
			title			: "Confirmation",
			text			: "<b>Thanks!</b><br /><br />Your email has been sent to support@roadtripnation.org",
			arrButtons		: ['BUTTON_CONTINUE_HOME'],
			rtnDialogClass	: 'DAG_ForgotPassword'
		},
		BOX_EMAIL_NOT_SENT: {
			title: "Whoops!",
			text: "Something went wrong. Your email was not sent. Please try again.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_UPDATED: {
			title: "Yay!",
			text: "Your information has been updated.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_CONFIRMATION_EMAIL:{
			title			: "Confirm Email",
			text			: "Please check your inbox for an email from Roadtrip Nation containing a link and your username. Please click on the link to confirm your email address. You will be able to login afterwards.",
			arrButtons		: ['BUTTON_REQUEST', 'BUTTON_CONTINUE']

		},
		BOX_UPDATED_CONTINUE: {
			title: "Yay!",
			text: "Your information has been updated.",
			arrButtons: ['BUTTON_CONTINUE_CLICK2']
		},
		BOX_UPDATED_CUSTOM: {
			title: "Yay!",
			text: "Your information has been updated.",
			arrButtons: ['BUTTON_CONTINUE_CUSTOM']
		},
		BOX_ADDED: {
			title: "Yay!",
			text: "Your information has been added.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_ADDED_CONTINUE: {
			title: "Yay!",
			text: "Your information has been added.",
			arrButtons: ['BUTTON_CONTINUE_CLICK2']
		},
		BOX_ADDED_CUSTOM: {
			title: "Yay!",
			text: "Your information has been added.",
			arrButtons: ['BUTTON_CONTINUE_CUSTOM']
		},
		BOX_INFORMATION_UPDATED: {
			title: "Yay!",
			text: "Your information has been updated.",
			arrButtons: ['BUTTON_CONTINUE']
		},
        BOX_INFORMATION_NOT_UPDATED: {
			title: "Whoops!",
			text: "That team name already exists. Please try again.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_MISSING_STEP: {
			title: "Whoops!",
			text: "You've missed a required step in the application.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_FEEDBACK_SENT: {
			title: "Thanks!",
			text: "Your feedback has been sent.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_MORE_INFO_NEEDED: {
			title: "Whoops!",
			text: "Looks like your team needs to add some more information to complete your application.",
			arrButtons: ['BUTTON_CONTINUE']
		},
		BOX_NO_LOGIN: {
			title: "Whoops!",
			text: "Looks like you need to login before you can see My Courses",
			arrButtons: ['BUTTON_TRYAGAIN', 'BUTTON_SIGNUP']
		},
		BOX_INVALID_SURVEY: {
			title: "Whoops!",
			text: "Please complete the survey before you submit.",
			arrButtons: ['BUTTON_TRYAGAIN']
		},
		BOX_INVALID_SURVEY_SUBMIT: {
			title: "Yikes!",
			text: "Looks like your survey was not submitted. Please try agina or contact support@roadtripnation.org.",
			arrButtons: ['BUTTON_TRYAGAIN']
		},
        BOX_CONFIRMATION_CONTIUNE: {
            title: "Yay!",
            text: "A new confirmation email was sent out to you.  Please check your email and click on the link provided.",
            arrButtons: ['BUTTION_CONTINUE_CONFIRMATION']
        },
        BOX_CONFIRMATION_ERROR: {
            title: "Yikes!",
            text: "Looks like the email address you entered is not valid.  Are you sure you are using the right email address?",
            arrButtons: ['BUTTON_TRYAGAIN']
        },
		// Contact Page Dialog ---------------------------------[BD]
		BOX_CNT_SEND: {
			title				: 'Contact',
			text				: '',
			FRM_CNT_TextInput	: [
				'<label for="FRM_CNT_From"><span>From:</span><input type="text" id="FRM_CNT_From" name="FRM_CNT_From" value="Your e-mail address" onfocus="if ($(this).val() == \'Your e-mail address\') {$(this).val(\'\');}" onblur="if ($(this).val() == \'\') {$(this).val(\'Your e-mail address\');}" /></label>',
				'<label for="FRM_CNT_Email"><span>To:</span><input type="text" id="FRM_CNT_Email" name="FRM_CNT_Email" readonly="readonly" value="<support@roadtripnation.org>" /></label>',
				'<label for="FRM_CNT_Subject"><span>Subject:</span><input type="text" class="FRM_CNT_Subject" id="FRM_CNT_Subject" name="FRM_CNT_Subject" value="Type Subject Here" onfocus="if ($(this).val() == \'Type Subject Here\') {$(this).val(\'\');}" onblur="if ($(this).val() == \'\') {$(this).val(\'Type Subject Here\');}"/></label>'
			],
			FRM_CNT_Textarea	: [
				'<label for="FRM_CNT_Body"><span>Body:</span><textarea id="FRM_CNT_Body" name="FRM_CNT_Body" onfocus="if ($(this).val() == \'Type away\') {$(this).val(\'\');}" onblur="if ($(this).val() == \'\') {$(this).val(\'Type away\');}">Type away</textarea></label>'
			],
			arrButtons			: ['POST_CONTACT_SEND', 'BUTTON_CANCEL'],
			rtnDialogClass		: 'DAG_Contact'
		},
		POST_CONTACT_SEND_SUCCESS: {
			title		: "Woohoo! Your e-mail was successfully sent.",
			text		: "Thank you for your inquiry.<br />We will respond to you just as soon as we can.",
			arrButtons	: ['BUTTON_CLOSE'],
			rtnDialogClass		: 'DAG_Contact'
		},
		//------------------------------------------------------[BD]

		getLink: function(protectEvent) {
			return (protectEvent.target.tagName == 'A') ?
				protectEvent.target.href :
				$(protectEvent.target).parent('a').attr('href');
		},

		followLink: function(protectEvent) {
			// Trigger and bound events
			$(protectEvent.target).click();

			// Find parent tag in the case of <a><img/></a>
			document.location.href = $.rtn.dialog.getLink(protectEvent);
		},

		alert: function(options) {
			if (options.arrButtons) {
				options.buttons = {};
				for (btn in options.arrButtons) {
					$.extend(options.buttons, this[options.arrButtons[btn]]);
				}
			}

			settings = {
				width		: 500,
				draggable	: false,
				modal		: true,
				dialogClass : options.rtnDialogClass

			};
			$.extend(settings, options);

			if ($('#dialog').length < 1)
				$('<div id="dialog"></div>').appendTo('body');

				
			$('#dialog').html(options.text);
			$('#dialog').dialog(settings);

			$('button:last').addClass("grayBtn");
			$('.grayBtn').css('background-color','#ccc');
			$('.ui-dialog-buttonpane button:eq(0)').focus().blur(); //takes focus off any links in .ui-dialog-content

			if (options.input_Subject) {
				$('<div id="subject" style="padding-top: 8px;width:100%">'+options.input_Subject+'</div>').appendTo('#dialog');
				//$('#subject').append(options.input_Subject);
			}

			if (options.input_Text) {
				$('<div id="message" style="padding-top: 8px;width:100%">'+options.input_Text+'<span id="char_count">200</span> Characters Left'+'</div>').appendTo('#dialog');
				$('#msg').startCounting({limit:200});
			}

			// Contact Page Dialog Options -------------------------[BD]
			if (options.FRM_CNT_TextInput) {
				jQuery.each(options.FRM_CNT_TextInput, function(){
					$('<div class="FRM_Row FRM_Row_TextInput">' + this + '</div>').appendTo('#dialog');
				});
			}

			if (options.FRM_CNT_Textarea) {
				jQuery.each(options.FRM_CNT_Textarea, function(){
					$('<div class="FRM_Row FRM_Row_Textarea">' + this + '</div>').appendTo('#dialog');
				});
			}
			//------------------------------------------------------[BD]
		},

		error: function(options, errors) {
			settings = clone(options);
			settings.text += "<br>";
			for (i in errors) {
				settings.text += "<br>" + errors[i];
			}

			this.alert(settings);
			return false;
		},

		confirm: function(template, options) {
			settings = clone(template);

			$.extend(settings, options);

			settings.buttons = {
				"Cancel":   function() {
					$(this).dialog('destroy');

					if (options.callbackCancel) options.callbackCancel();
				},
				"Continue": function() {
					$(this).dialog('destroy');
					if (options.callbackContinue) options.callbackContinue();
				}
			};
			settings.arrButtons = null;

			this.alert(settings);
		},

		protected: [],
		protect: function(form) {

			var showProtect = function(event) {
				// var prot = $.rtn.dialog.protected;

				for (i = 0; i < $.rtn.dialog.protected.length; ++i) {
					if ($.rtn.dialog.protected[i] == this) return;
				}

				$.rtn.dialog.protected.push(this);


				$('a').bind('click.protect', function(event) {
					$.rtn.dialog.protectEvent = event;
					event.preventDefault();
					event.stopPropagation();
					$.rtn.dialog.alert($.rtn.dialog.BOX_NAVIGATE_AWAY);
				});
			}



			if ($.browser.msie)
				$(':input', form).bind('change.rtn-protect', showProtect);
			else
				form.bind('change.rtn-protect', showProtect);
		},

		unprotect: function(form) {
			var protected = $.rtn.dialog.protected;

			form.each(function() {
				for (i = 0; i < protected.length; ++i) {
					if (protected[i] == this)
						protected.splice(i, 1);
				}
			});

			// alert(protected.length);
			if (protected.length == 0) {
				$('a').unbind('click.protect');
			}
		}


	}
})(jQuery);

function Clone() { }
function clone(obj) {
    Clone.prototype = obj;
    return new Clone();
}

(function($) {

$.fn.startCounting = function(options){

var defaults = {
limit: 30
};

options = $.extend( defaults, options);

return $(this).each( function(i) {

var elem = $(this);
elem.after('');
elem.keyup( function(i) {
var limit = options.limit;
var text = elem.val();
var textlength = text.length;


//elem.next('.counting_class').val( limit + ' / ' + limit);
//elem.val(text.substr(0,limit));
$('#char_count').html(limit - textlength);
});
elem.trigger('keyup');
});
};

})(jQuery);