// Lock a submit button when clicked from being clicking again and change the value of the submit to a message, while preserving the submits name and value in a hidden input.
// License: http://www.gnu.org/licenses/lgpl.txt
// Homepage: http://blog.leenix.co.uk/2009/09/jquery-plugin-locksubmit-stop-submit.html
// Version 1.02

jQuery.fn.lockSubmit = function(options) {

	//Default text to change submit button too
	var settings = jQuery.extend({
		submitText: null,
		onAddCSS: null,
		onClickCSS: 'clicked'
	}, options);

	var clicked=false;

	//add CSS to this button
	if(settings.onAddCSS) {	this.addClass(settings.onAddCSS); }

	return this.click(function(e) {
    /* Trick for validete if this function have to run or not */
    if ($("#removeClicked").size() > 0) {
      if ($("#removeClicked").val() != "0") {
        $("#removeClicked").val(0);
        return false;
      }
    }
		if(clicked) {
			return false;
		}
		else
		{
			clicked=true;			
		
			//insert hidden field with name and value of submit
			jQuery(this).after("<input type='hidden' name='"+jQuery(this).attr("name")+"' value='"+jQuery(this).val()+"'>");
		
			//change text of the submit button
			if(settings.submitText) { jQuery(this).val(settings.submitText); }
			
			//add onClick CSS
			if(settings.onClickCSS) {
				if(settings.onAddCSS) {	jQuery(this).removeClass(settings.onAddCSS); }
				jQuery(this).addClass(settings.onClickCSS);
			}
		
			//rename and disable the submit button
			jQuery(this).attr("name", jQuery(this).attr("name")+"DISABLED");				
			
			return true;
		}
	});
};

jQuery(document).ready(function() {
    jQuery(':submit').lockSubmit();
});

// talent wizard
function saveAndExit(_form)
{
	if (confirm("Are you sure you want to Save and Exit?")) {
		$('#SaveAndExit').val('1');
		$(_form).submit();
		return false;
	}
}

// init bst ns
var bst = {};

bst.fb_callback = function() {
	var session_key = FB.Facebook.apiClient.get_session().session_key;
	$('#facebook_session_key').val(session_key);
	$('#loginForm').submit();
};

bst.fb_connect_current = function() {
	
	$("#connecting_facebook_spinner").show();
	
	var session_key = FB.Facebook.apiClient.get_session().session_key;
	$.post("/account/ajax_connecting_facebook", 
  	function(data) {
		
		var response = data.split("|");
			
		$("#connecting_facebook_spinner").hide();
		var _className = response[0];
		
		$("#connecting_facebook_response").attr("class", _className).html(response[1]).show()
		
  	}, 
	"json");
};
			
// Deactivate account Confirm alert
bst.account =
{
    deactivate : function()
    {
    	var answer = confirm ("If you deactivate your account, your profile and any information associated with it will be inaccessible. Are you sure you want to deactivate your account?")
    	if (answer) {
        	window.location = "/account/deactivate"
        }
    }
};
