/*
Copyright: © 2009 WebSharks, Inc. ( coded in the USA )
<mailto:support@websharks-inc.com> <http://www.websharks-inc.com/>

Released under the terms of the GNU General Public License.
You should have received a copy of the GNU General Public License,
along with this software. In the main directory, see: /licensing/
If not, see: <http://www.gnu.org/licenses/>.
*/
/*
Global variables, duplicated from PHP / API Constants.
These are inserted dynamically.
*/
var S2MEMBER_VERSION = '3.1.2',S2MEMBER_CURRENT_USER_IS_LOGGED_IN = false,S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER = false,S2MEMBER_CURRENT_USER_ACCESS_LEVEL = -1,S2MEMBER_CURRENT_USER_ACCESS_LABEL = '',S2MEMBER_CURRENT_USER_SUBSCR_ID = '',S2MEMBER_CURRENT_USER_CUSTOM = '',S2MEMBER_CURRENT_USER_REGISTRATION_TIME = 0,S2MEMBER_CURRENT_USER_REGISTRATION_DAYS = 0,S2MEMBER_CURRENT_USER_DISPLAY_NAME = '',S2MEMBER_CURRENT_USER_FIRST_NAME = '',S2MEMBER_CURRENT_USER_LAST_NAME = '',S2MEMBER_CURRENT_USER_LOGIN = '',S2MEMBER_CURRENT_USER_EMAIL = '',S2MEMBER_CURRENT_USER_IP = '38.107.191.87',S2MEMBER_CURRENT_USER_ID = 0,S2MEMBER_CURRENT_USER_FIELDS = [],S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED = 0,S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED = false,S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY = 0,S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID = 0,S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_ID = 9,S2MEMBER_LOGIN_WELCOME_PAGE_ID = 68,S2MEMBER_CURRENT_USER_PROFILE_MODIFICATION_PAGE_URL = 'http://www.cepvancouver.org/wp/?s2member_profile=1',S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL = 'http://www.cepvancouver.org/wp/?page_id=0',S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL = 'http://www.cepvancouver.org/wp/member-services/',S2MEMBER_LOGIN_WELCOME_PAGE_URL = 'http://www.cepvancouver.org/wp/',S2MEMBER_LOGOUT_PAGE_URL = 'http://www.cepvancouver.org/wp/wp-login.php?action=logout&amp;_wpnonce=d42d2407ae',S2MEMBER_LOGIN_PAGE_URL = 'http://www.cepvancouver.org/wp/wp-login.php',S2MEMBER_LEVEL0_LABEL = 'Mailing List',S2MEMBER_LEVEL1_LABEL = 'General Membership',S2MEMBER_LEVEL2_LABEL = 'Sustaining Member',S2MEMBER_LEVEL3_LABEL = 'Partner',S2MEMBER_LEVEL4_LABEL = 'Sponsor',S2MEMBER_LEVEL0_FILE_DOWNLOADS_ALLOWED = 0,S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED = 0,S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED = 0,S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED = 0,S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED = 0,S2MEMBER_LEVEL0_FILE_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_LEVEL1_FILE_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_LEVEL2_FILE_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_LEVEL3_FILE_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_LEVEL4_FILE_DOWNLOADS_ALLOWED_DAYS = 0,S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS = '',S2MEMBER_REG_EMAIL_FROM_NAME = 'CEP Vancouver',S2MEMBER_REG_EMAIL_FROM_EMAIL = 'info@cepvancouver.org',S2MEMBER_PAYPAL_NOTIFY_URL = 'http://www.cepvancouver.org/wp/?s2member_paypal_notify=1',S2MEMBER_PAYPAL_RETURN_URL = 'http://www.cepvancouver.org/wp/?s2member_paypal_return=1',S2MEMBER_PAYPAL_ENDPOINT = 'www.paypal.com',S2MEMBER_PAYPAL_BUSINESS = 'payments@cepvancouver.org',S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0 = '',S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0 = '';
/*
Other scripting routines handled on document ready state.
Note: There is only one global variable here ( no conflicts ).
	ws_plugin__s2member_unique_files_downloaded
*/
jQuery (document).ready (function($)
	{
		/*
		Attach onclick handlers to download links.
		Members will need to confirm download processing.
		*/
		ws_plugin__s2member_unique_files_downloaded = []; /* Maintains real-time counts. */
		/* This is used in case a user downloads multiple files from a single page. */
		/**/
		if (S2MEMBER_CURRENT_USER_IS_LOGGED_IN && S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY < S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED)
			{
				$ ('a[href*=s2member_file_download]').click (function()
					{
						if (!this.href.match (/file_download_key\=(.+)/)) /* ~Only for links with NO key. */
							{
								var c = '** Please Confirm This File Download **\n\n';
								c += 'You\'ve downloaded ' + S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY + ' protected file' + ((S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY < 1 || S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY > 1) ? 's' : '') + ' in the last ' + S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS + ' days.\n\n';
								c += 'You\'re entitled to ' + ((S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED) ? 'UNLIMITED downloads though ( so, no worries ).' : S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED + ' unique downloads every ' + S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS + ' day period.');
								/**/
								if (confirm (c)) /* Force the user to confirm before we allow processing. */
									{
										if ($.inArray (this.href, ws_plugin__s2member_unique_files_downloaded) === -1) /* Real-time counting. */
											ws_plugin__s2member_unique_files_downloaded.push (this.href), S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY++;
										return true; /* Allow processing. */
									}
								else /* Do not process. */
									return false;
							}
					});
			}
		/*
		Attach form submission handler for registration validation.
		*/
		if (location.href.match (/\/wp-login\.php/))
			/**/
			$ ('div#login > form#registerform').submit (function()
				{
					var fieldErrors = '', fieldLabel = '';
					/**/
					$ (':input[aria-required=true]', this).each (function()
						{
							if (!$.trim ($ (this).val ()) && (fieldLabel = $.trim ($.trim ($ (this).parent ('label').html ()).split (/[\r\n\t\<]+/, 1)[0].replace (/\*/, ''))))
								fieldErrors += '• ' + fieldLabel + '\n'; /* Required fields. */
						});
					/**/
					if (fieldErrors = $.trim (fieldErrors))
						{
							alert ('Oops, you missed something:\n\n' + fieldErrors);
							return false;
						}
					/**/
					return true;
				});
		/*
		Attach form submission handler for profile modification validation.
		*/
		if (location.href.match (/\/\?s2member_profile\=1/))
			/**/
			$ ('form#ws-plugin--s2member-profile').submit (function()
				{
					var fieldErrors = '', fieldLabel = '';
					/**/
					$ (':input[aria-required=true]', this).each (function()
						{
							if (!$.trim ($ (this).val ()) && (fieldLabel = $.trim ($.trim ($ ('strong', $ (this).parent ('label')).html ()).split (/[\r\n\t\<]+/, 1)[0].replace (/\*/, ''))))
								fieldErrors += '• ' + fieldLabel + '\n'; /* Required fields. */
						});
					/**/
					if (fieldErrors = $.trim (fieldErrors))
						{
							alert ('Oops, you missed something:\n\n' + fieldErrors);
							return false;
						}
					/**/
					return true;
				});
	});