/* 
 * All content copyright Mozzaiq, LLC
 * 
 * Plugin: Website Login/Authentication Script
 * Version: 0.7
 * Author: Mike Quinn (Mozzaiq)
 * 
 * Last Modified: April 16, 2009
 * Date Created: April 9, 2009
 * 
 * Usage Instructions:
 *   - The "login" method is applied to the HTML form containing 
 *     the userID & password fields
 * 
 * Assumptions:
 *   - The "userID" is the only text input in the login form
 *     (The HTML ID attribute of the userID field does not need to be specified) 
 *   - The "password" field is the only password input in the login form
 *     (The HTML ID attributed of the password field does not need to be specified)
 *   - The form has a "submit" button
 *   
 * Parameter Values:
 *   - processingID: ID of the div tag that contains the message to be shown during 
 *                   the authentication process
 *                   
 *   - resultID:     ID of the div tag where a message will be displayed to user 
 *   				 upon authentication failure
 *                   
 *   - remoteScript: URL of remote script file to use to authenticate user 
 *   		         credentials
 *   
 *   - idType: 		 There are two types of login IDs supported: email and username
 *   				 "email" utilizes the stored email address as the user login
 *   				 "username" utilizes a specific unique name stored for the user 
 *   				 on this website
 *   
 *   - successPage:  URL of the page to show user if the login credentials are
 *   				 verified
 *   
 */

(function($){  
	$.fn.calendar = function(options) {
		
		// set default parameter values
		var defaults = {
			processingID: "processing",
			resultID: "result",
			remoteScript: "calendar/newEvent.php",
			idType: "username",
			successPage: "a.php"
		};
		var options = $.extend(defaults, options);
				
		return this.each(function() {
			// "obj" is the login form to be submitted for authentication
			var obj = $(this);
			
			
			// Login form is submitted
			obj.submit(function() {
				$('#'+options.successID).hide();
				$('#'+options.errorID).hide();
				alert('Form Submitted');
				// Submit credentials for authentication
				$.post(options.remoteScript,
						{ title: $('#'+options.title).val(), location: $('#'+options.location).val(), description: $('#'+options.description).val(), startDate: $('#'+options.startDate).val(), endDate: $('#'+options.endDate).val(), email: $('#'+options.contactEmail).val() },
						function(response) {
							alert(response);
							// Response Format: SuccessFlag*Data
							//   - Authentication Success:  1*RedirectURL
				     		//   - Authentication Failure: 0*ErrorMessage			
							
							piece = response.split("*");
							if(piece[0] == 1) {
								$('#'+options.successID).html("Event successfully created");
								hideNewEventForm();
								$('#'+options.errorID).hide();
								$('#'+options.successID).show();
							}
							else {
								$('#'+options.successID).hide();
								$('#'+options.errorID).html(piece[1]);
								$('#'+options.errorID).show();
							}
							
							
						});
				return false;
			});			
		});
	};
})(jQuery); 

//var body = obj.html();

