/*
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 Contants.
These are inserted dynamically.
*/
var S2MEMBER_VERSION = '3.0.9',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.92',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 = 232,S2MEMBER_LOGIN_WELCOME_PAGE_ID = 0,S2MEMBER_CURRENT_USER_PROFILE_MODIFICATION_PAGE_URL = 'http://www.noah-conference.com/?s2member_profile=1',S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL = 'http://www.noah-conference.com/?page_id=0',S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL = 'http://www.noah-conference.com/paypal-registration-process',S2MEMBER_LOGIN_WELCOME_PAGE_URL = 'http://www.noah-conference.com/wp/wp-admin',S2MEMBER_LOGOUT_PAGE_URL = 'http://www.noah-conference.com/wp/wp-login.php?action=logout&amp;_wpnonce=c66937072c',S2MEMBER_LOGIN_PAGE_URL = 'http://www.noah-conference.com/wp/wp-login.php',S2MEMBER_LEVEL1_LABEL = 'Friend',S2MEMBER_LEVEL2_LABEL = 'Corporate',S2MEMBER_LEVEL3_LABEL = 'Investor',S2MEMBER_LEVEL4_LABEL = 'Platinum',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_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 = 'Marco Rodzynek',S2MEMBER_REG_EMAIL_FROM_EMAIL = 'marco.rodzynek@noah-advisors.com',S2MEMBER_PAYPAL_NOTIFY_URL = 'http://www.noah-conference.com/?s2member_paypal_notify=1',S2MEMBER_PAYPAL_RETURN_URL = 'http://www.noah-conference.com/?s2member_paypal_return=1',S2MEMBER_PAYPAL_ENDPOINT = 'www.paypal.com',S2MEMBER_PAYPAL_BUSINESS = 'marco@rodzynek.com',S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0 = '',S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0 = '';
/*
Other scripting routines handled on document ready state.
*/
jQuery(document).ready (function($)
	{
		/*
		Attach onclick handlers to download links.
		Members will need to confirm download processing.
		*/
		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_AS_MEMBER && S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY < S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED)
			{
				$('a[href*=s2member_file_download]').click (function()
					{
						if (!this.href.match (/s2member_free_file_download_key\=(.+)/))
							{
								var c = '** Please Confirm This File Download **\n\n';
								c += 'You\'ve downloaded ' + S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY + ' 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' : S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED + ' unique') + ' downloads every ' + S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS + ' day period.\n\n';
								/**/
								if (confirm(c)) /* Force the user to confirm before we allow processing. */
									{
										if ($.inArray (this.href, s2member_unique_files_downloaded) === -1) /* Real-time counting. */
											s2member_unique_files_downloaded.push (this.href), S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY++;
										return true; /* Allow processing. */
									}
								else /* Do not process. */
									return false;
							}
						else /* Else relax the user, this is free. */
							{
								var c = 'This is a FREE download for members.\n';
								c += 'It does not count against your membership entitlement.\n\n';
								c += '~Enjoy~';
								/**/
								if (confirm(c))
									return true;
								else /* ? */
									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.value) && (fieldLabel = $.trim ($(this).parent ('label').text ().replace (/\*/, ''))))
								fieldErrors += '• ( ' + fieldLabel + ' ) is a required field.\n';
						});
					/**/
					if (fieldErrors = $.trim (fieldErrors))
						{
							alert('Please check the fields:\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.value) && (fieldLabel = $.trim ($('strong', $(this).parent ('label')).text ().replace (/\*/, ''))))
								fieldErrors += '• ( ' + fieldLabel + ' ) is a required field.\n';
						});
					/**/
					if (fieldErrors = $.trim (fieldErrors))
						{
							alert('Please check the fields:\n\n' + fieldErrors);
							return false;
						}
					/**/
					return true;
				});
	});