
var subscriptionCenter = function()
{
	
	var popups;
	var global;
	var currentPopup;
	var scrollToElement;
	
	return{
		
		init: function()
		{
			
			global = this;
			
			this.formHelper.init();
			
			var currentPage = $('body > div').eq(0).attr('id');
			
			switch(currentPage)
			{
				
				case 'user_info':				
					this.userInfoForm.init();
				break;
				
				case 'welcome':
					this.welcomeForm.init();
				break;
				
				case 'unsubscribe':
					this.unsubscribeForm.init();
				break;
				
			}
			
		},
		
		formHelper: function()
		{
			
			var ref;
			
			return{
				
				init: function()
				{
					
					ref = this;
					
					global.popups = [
						{type: 'link', a:'#popup_dob_link', target: '#popup_dob', popup: null, onClose: null}, // DOB Popup
						{type: 'link', a:'#popup_mobile_link', target: '#popup_mobile', popup: null, onClose: null}, // Mobile Details Popup
						{type: 'manual', a:null, target: '#popup_error', popup: null, onClose: this.scrollToError}, // Ooops Error Popup
						{type: 'manual', a:null, target: '#bummer_popup_error', popup: null, onClose: null}, // Bummer Error Popup
						{type: 'manual', a:null, target: '#try_again_popup_error', popup: null, onClose: null}, // Try Again Error Popup
						{type: 'manual', a:null, target: '#try_again_signup_popup_error', popup: null, onClose: null}, // Try Again Signup Error Popup
						{type: 'manual', a:null, target: '#enter_email_popup_error', popup: null, onClose: null}, // Enter Email Error Popup
						{type: 'manual', a:null, target: '#email_optin_popup_error', popup: null, onClose: null} // Email Optin Error Popup
					];
					
					global.overrideEmailOptin = false;
					
					for(var i = 0; i < global.popups.length; i++)
					{
						
						var props = {target: $(global.popups[i].target)};
						var p = new subscriptionCenterPopup(props);
						var relJson = '{"id":' + '"' + i + '"}';
						
						global.popups[i].popup = p;
						
						if(global.popups[i].type == 'link')
						{
							
							$(global.popups[i].a).attr('rel', relJson).click(function(){
								
								if(currentPopup)
								{
									currentPopup.hide();
								}
								
								currentPopup = global.popups[global.utils.parseJson($(this).attr('rel')).id].popup;
								currentPopup.show();
								
								return false;
								
							});
							
						}
						
						$(global.popups[i].target).find('.popup_close_x').attr('rel', relJson).click(function(){
							
							global.popups[global.utils.parseJson($(this).attr('rel')).id].popup.hide();
							
							if(global.popups[global.utils.parseJson($(this).attr('rel')).id].onClose)
							{
								global.popups[global.utils.parseJson($(this).attr('rel')).id].onClose();
							}
							
							return false;
							
						});
						
						$(global.popups[i].target).find('.popup_close_btn').attr('rel', relJson).click(function(){
							
							global.popups[global.utils.parseJson($(this).attr('rel')).id].popup.hide();
							
							if(global.popups[global.utils.parseJson($(this).attr('rel')).id].onClose)
							{
								global.popups[global.utils.parseJson($(this).attr('rel')).id].onClose();
							}
							
							return false;
							
						});
						
					}
					
					// Supersleight PNG fix
					
					var pathToShim = 'http://image.email.subwayfreshbuzz.com/lib/fef71371736703/m/1/blank.gif';
					
					$('#logo > img').supersleight({shim: pathToShim});
					$('.popup_top').supersleight({shim: pathToShim});
					$('.popup_content_container').supersleight({shim: pathToShim});
					$('.popup_header > h1').supersleight({shim: pathToShim});
					$('.popup_close_btn > img').supersleight({shim: pathToShim});
					$('.popup_bottom').supersleight({shim: pathToShim});
					$('#page_header').supersleight({shim: pathToShim});
					$('#page_bottom').supersleight({shim: pathToShim});
					$('.popup_signup_btn').supersleight({shim: pathToShim});
					
					// Custom input buttons
					
					$('input[class*="custom_input_button"]').customInputButton();
					
					// Auto Tab mobile fields
					
					$('#mobile_area').keyup(function(event){
						global.utils.autoTab(event,$(this).attr('id'), 'mobile_local3', 3)
					});
					
					$('#mobile_local3').keyup(function(event){
						global.utils.autoTab(event,$(this).attr('id'), 'mobile_local4', 3)
					});
					
				},
				
				addFocusEvent: function(selector)
				{
					
					$(selector).find(':input[type="text"]').bind("focus", function(){ref.focusField(this)});
					
					this.addBlurEvent(selector);
					
				}, // End addFocusEvent
				
				addBlurEvent: function(selector)
				{
					
					$(selector).find(':input[type="text"]').bind("blur", function(){ref.blurField(this)});
					
				}, // End addBlurEvent
				
				focusField: function(element)
				{
					
					$(element).css("background-color", "#ff0");
					$(element).css("border", "1px solid #ccc");
					
				}, // End focusField
				
				blurField: function(element)
				{
					
					$(element).css("background-color", "#fff");
					$(element).css("border", "1px solid #ccc");
				
				}, // End blurField
				
				showError: function(element)
				{
					
					$(element).css("background-color", "#fbe4e5");
					$(element).css("border", "1px solid #f00");
					
				}, // End showError
				
				resetFormErrors: function(selector)
				{
					
					$(selector).find(':input[type="text"]').each(function(){ref.blurField($(this))});
					
				}, // End resetFormErrors
				
				showErrorBox: function(msg, element)
				{
					
					global.scrollToElement = element;
					$('#popup_error').find('.popup_error_message').html(msg);
					global.popups[2].popup.show();
					
				}, // End showErrorBox
				
				scrollToError: function()
				{
					
					var scrollTop = $(global.scrollToElement).offset().top - 30;
					
					$('html,body').animate({scrollTop: scrollTop}, 700);
					
				} ,// End scrollToError
			
				isOldEnough: function(month, day, year, age)
				{
					
					if(month == 0 || day == 0 || year == 0)
					{
						return false;
					}
					
					var d = new Date();
					var c_year = d.getFullYear();
					var c_month = d.getMonth() + 1;
					var c_day = d.getDate();
					var min_year = c_year - age;
					
					var alertMsg = "Date: " + d + "\n";
					alertMsg += "c_year: " + c_year + "\n";
					alertMsg += "c_month: " + c_month + "\n";
					alertMsg += "c_day: " + c_day + "\n";
					alertMsg += "min_year: " + min_year + "\n";
					alertMsg += "Month: " + month + "\n";
					alertMsg += "Day: " + day + "\n";
					alertMsg += "Year: " + year + "\n";
					
					if(year > min_year)
					{
						return false;	
					}
					
					if(year == min_year)
					{
						
						if(month > c_month)
						{
							return false;
						}
						
						if(month == c_month)
						{
							
							if(day > c_day)
							{
								return false;
							}
							
						}
					}
					
					return true;
					
				} // End isOldEnough
			
			}
			
		}(),
		
		userInfoForm: function()
		{
			
			var ref;
			
			return{
				
				init: function()
				{
					
					ref = this;
					
					//-----------------------------------------------------------------------------
					// We are populating the year select list here for TESTING ONLY.
					// When ready, this select list should be generated on the server.
					//-----------------------------------------------------------------------------
					
					/*
					$('#dob_year').html('');
					
					$('#dob_year').append($('<option value="">Year</option>'));
					
					for(var i = new Date().getFullYear(); i > 1899; i--)
					{
						
						$('#dob_year').append($('<option value="' + i + '">' + i + '</option>'));
						
					}
					*/
					
					$('.drop_select').dropSelect();
					$('input:checkbox').checkbox({empty: "http://image.email.subwayfreshbuzz.com/lib/fef71371736703/m/1/empty.png"});
					
					/*
						Mobile Number Check, If the number is completely filled out,
						check the checkbox, otherwise uncheck it
					*/
					
					$('#mobile_area').blur(function(){
						
						ref.updateMobileOptinCheckBox();
						
					});
					
					$('#mobile_local3').blur(function(){
						
						ref.updateMobileOptinCheckBox();
						
					});
					
					$('#mobile_local4').blur(function(){
						
						ref.updateMobileOptinCheckBox();
						
					});
					
					/*
						Direct Mailing Check, If Address, City, State, And Zip
						are all filled out, check it
					*/
					
					$('#address1').blur(function(){
						
						ref.updateDirectMailOptinCheckBox();
						
					});
					
					$('#city').blur(function(){
						
						ref.updateDirectMailOptinCheckBox();
						
					});
					
					$('#state > ul > li > div > ul > li').find("a").each(function(){
						$(this).bind("click", function(){
							ref.updateDirectMailOptinCheckBox();
						});
					});
					
					$('#zip5').blur(function(){
						
						ref.updateDirectMailOptinCheckBox();
						
					});
					
					// Email error popup optin button
					
					$('#email_optin_popup_optin_btn').click(function(){
						
						$('#optin_emails').attr("checked", "checked");
						
						currentPopup.hide();
						
						$("#user_info_form").submit();
						
						return false;
						
					});
					
					// Email error popup no thanks button
					
					$('#email_optin_popup_no_thanks_btn').click(function(){
						
						global.overrideEmailOptin = true;
						
						currentPopup.hide();
						
						$("#user_info_form").submit();
						
						return false;
						
					});

					this.initFormValidation();
					
				},
				
				updateMobileOptinCheckBox: function()
				{
					
					var num1 = $('#mobile_area').attr('value');
					var num2 = $('#mobile_local3').attr('value');
					var num3 = $('#mobile_local4').attr('value');
					
					if(num1.length == 3 && num2.length == 3 && num3.length == 4)
					{
						$('#optin_txt').attr('checked', 'checked');
					}
					else
					{
						$('#optin_txt').attr('checked', '');
					}
					
				},
				
				updateDirectMailOptinCheckBox: function()
				{
					
					var address1Val = $('#address1').attr('value').toString();
					var cityVal = $('#city').attr('value').toString();
					var zipVal = $('#zip5').attr('value').toString();
					var state = document.getElementById('drop_select_state');
					var stateVal = state.options[state.selectedIndex].value;
					
					if(address1Val.length == 0 || cityVal.length == 0 || zipVal.length == 0 || stateVal.length == 0)
					{
						$('#optin_mail').attr('checked', '');
					}
					else
					{
						$('#optin_mail').attr('checked', 'checked');
					}
					
				},
				
				initFormValidation: function()
				{
					
					global.formHelper.addFocusEvent('#user_info_form');
					
					$('#update_btn').bind("click", function(){
						
						global.formHelper.resetFormErrors('#user_info_form');
						
						$("#user_info_form").submit();
						
						return false;
						
					});
															
					$("#user_info_form").validate({
						focusInvalid: false,
						onfocusout: false,
						onkeyup: false,
						rules:{
							fname:{
								required: true,
								letterswithbasicpunc: true
							},
							lname:{
								required: true,
								letterswithbasicpunc: true
							},
							email:{
								required: true,
								email: true
							},
							email_re:{
								required: true,
								email: true,
								equalTo: '#email'
							},
							zip5:{
								required: true,
								digits: true,
								minlength: 5,
								maxlength: 5
							},
							dob_month:{
								required: true
							},
							dob_day:{
								required: true
							},
							dob_year:{
								required: true
							},
							mobile_area:{
								digits: true,
								required:{
									depends: function(){
										var num1 = global.utils.trim($('#mobile_local3').attr("value"));
										var num2 = global.utils.trim($('#mobile_local4').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
									}
								},
								minlength: 3,
								maxlength: 3
							},
							mobile_local3:{
								digits: true,
								required:{
									depends: function(){
										var num1 = global.utils.trim($('#mobile_areacode').attr("value"));
										var num2 = global.utils.trim($('#mobile_local4').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
									}
								},
								minlength: 3,
								maxlength: 3
							},
							mobile_local4:{
								digits: true,
								required:{
									depends: function(){
										var num1 = global.utils.trim($('#mobile_local3').attr("value"));
										var num2 = global.utils.trim($('#mobile_areacode').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
									}
								},
								minlength: 4,
								maxlength: 4
							}
						},
						messages:{
							fname:{
								required: "First Name",
								letterswithbasicpunc: "First name should only contain the following characters: [A-Z] [a-z] [ . , ' - ]"
							},
							lname:{
								required: "Last Name",
								letterswithbasicpunc: "Last name should only contain the following characters: [A-Z] [a-z] [ . , ' - ]"
							},
							email:{
								required: "Email Address",
								email: "Invalid email address"
							},
							email_re:{
								required: "Re-enter Email Address",
								email: "Your emails do not match",
								equalTo: "Your emails do not match"
							},
							zip5:{
								digits: "Zip code should only contain the following characters:  [0-9]",
								required: "Zip Code",
								minlength: "Invalid zip code",
								maxlength: "Invalid zip code"
							},
							dob_month:{
								required: "Date of Birth Month"
							},
							dob_day:{
								required: "Date of Birth Day"
							},
							dob_year:{
								required: "Date of Birth Year"
							},
							mobile_area:{
								required: "Mobile Area Code",
								digits: "Mobile number area code should only contain the following characters: [0-9]",
								minlength: "Invalid mobile area code",
								maxlength: "Invalid mobile number"
							},
							mobile_local3:{
								required: "Mobile Number Field 2",
								digits: "Mobile number field 2 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 2",
								maxlength: "Invalid mobile number field 2"
							},
							mobile_local4:{
								required: "Mobile Number Field 3",
								digits: "Mobile number field 3 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 3",
								maxlength: "Invalid mobile number field 3"
							}
						},
						highlight: function(element){
							global.formHelper.showError(element);
						},
						errorPlacement: function()
						{
							
						},
						showErrors: function(errorMap, errorList) {
							
							if(errorList.length > 0)
							{
								
								var errorMSG = "The following required fields are not complete:<br/>";
								
								for(var i = 0; i < errorList.length; i++)
								{
									
									errorMSG += errorList[i].message;
									
									if(i < errorList.length - 1)
									{
										errorMSG += "<br/>"
									}
									
								}
								
								global.formHelper.showErrorBox(errorMSG, errorList[0].element);
								this.defaultShowErrors();
							}
						},
						submitHandler: function(form)
						{
							
							var errorMSG = "";
							
							// Age Check
							
							var month = document.getElementById('drop_select_dob_month');
							var monthVal = month.options[month.selectedIndex].value;
							
							var day = document.getElementById('drop_select_dob_day')
							var dayVal = day.options[day.selectedIndex].value;
							
							var year = document.getElementById('drop_select_dob_year')
							var yearVal = year.options[year.selectedIndex].value;
							
							if(!global.formHelper.isOldEnough(monthVal, dayVal, yearVal, 13))
							{
								errorMSG = "You must be of a certain age to sign up for Fresh News and Offers from Subway<sup>&reg;</sup> restaurants.";
								showCustomError(2, errorMSG);
								return;
							}
							
							// Optin email check
							
							if($('#optin_emails').attr('checked').toString().toLowerCase() == "false" && !global.overrideEmailOptin)
							{
								
								errorMSG = "You're almost there. Just click the" + ' "' + "opt-in" + '"' + " box so that we can send you the freshest news and offers from SUBWAY<sup>&reg;</sup> restaurants.";
								currentPopup = global.popups[7].popup;
								showCustomError(7, errorMSG);
								return;
								
							}
							
							// Mobile optin check
							
							if($('#optin_txt').attr('checked').toString().toLowerCase() == "true")
							{
								
								var num1 = $('#mobile_area').attr('value');
								var num2 = $('#mobile_local3').attr('value');
								var num3 = $('#mobile_local4').attr('value');
								
								if(num1 == '' || num2 == '' || num3 == '')
								{
									
									errorMSG = "Looks like you want to be in the know. Take a moment to fill in your mobile number, and you'll be on your way to receiving the freshest news and offers from SUBWAY<sup>&reg;</sup> restaurants.";
									global.formHelper.showErrorBox(errorMSG, $('#mobile_area'));
									if($('#mobile_area').attr('value').toString().length == 0) global.formHelper.showError($('#mobile_area'));
									if($('#mobile_local3').attr('value').toString().length == 0) global.formHelper.showError($('#mobile_local3'));
									if($('#mobile_local4').attr('value').toString().length == 0) global.formHelper.showError($('#mobile_local4'));
									return;
									
								}
								
							}
							
							// Direct Mailing check
							
							if($('#optin_mail').attr('checked').toString().toLowerCase() == "true")
							{
								
								var state = document.getElementById('drop_select_state');
								var stateVal = state.options[state.selectedIndex].value;

								if($('#address1').attr('value').toString().length == 0 || $('#city').attr('value').toString().length == 0 ||  stateVal.length == 0)
								{
									errorMSG = "Looks like you want to be in the know. Take a moment to fill in your mailing address, and you'll be on your way to receiving the freshest news and offers from SUBWAY<sup>&reg;</sup> restaurants.";
									global.formHelper.showErrorBox(errorMSG, $('#address1'));
									if($('#address1').attr('value').toString().length == 0) global.formHelper.showError($('#address1'));
									if($('#city').attr('value').toString().length == 0) global.formHelper.showError($('#city'));
									return;
									
								}
								
							}
							
							form.submit();
							
						}
					});
					
				}
				
			}
			
		}(),
		
		welcomeForm: function()
		{
			
			var ref;
			
			return{
				
				init: function()
				{
					
					ref = this;
					
					this.initFormValidation();
					
				},
				
				initFormValidation: function()
				{
					
					global.formHelper.addFocusEvent('#welcome_email_form');
					global.formHelper.addFocusEvent('#welcome_mobile_form');
					
					$('#welcome_email_submit_btn').bind("click", function(){
						
						global.formHelper.resetFormErrors('#welcome_email_form');
						
						$("#welcome_email_form").submit();
						
						return false;
						
					});
					
					$('#welcome_mobile_submit_btn').bind("click", function(){
						
						global.formHelper.resetFormErrors('#welcome_mobile_form');
						
						$("#welcome_mobile_form").submit();
						
						return false;
						
					});
															
					$("#welcome_email_form").validate({
						focusInvalid: false,
						onfocusout: false,
						onkeyup: false,
						rules:{
							email:{
								required: true,
								email: true
							}
						},
						messages:{
							email:{
								required: "Email Address",
								email: "Invalid email address"
							}
						},
						highlight: function(element){
							global.formHelper.showError(element);
						},
						errorPlacement: function()
						{
							
						},
						showErrors: function(errorMap, errorList) {
							
							if(errorList.length > 0)
							{
								
								var errorMSG = "The following required fields are not complete:<br/>";
								
								for(var i = 0; i < errorList.length; i++)
								{
									
									errorMSG += errorList[i].message;
									
									if(i < errorList.length - 1)
									{
										errorMSG += "<br/>"
									}
									
								}
								
								global.formHelper.showErrorBox(errorMSG, errorList[0].element);
								this.defaultShowErrors();
							}
						},
						submitHandler: function(form)
						{
							form.submit();
						}
					});
					
					$("#welcome_mobile_form").validate({
						focusInvalid: false,
						onfocusout: false,
						onkeyup: false,
						rules:{
							mobile_area:{
								digits: true,
								required: true,
								minlength: 3,
								maxlength: 3
							},
							mobile_local3:{
								digits: true,
								required: true,
								minlength: 3,
								maxlength: 3
							},
							mobile_local4:{
								digits: true,
								required: true,
								minlength: 4,
								maxlength: 4
							}
						},
						messages:{
							mobile_area:{
								required: "Mobile Area Code",
								digits: "Mobile number area code should only contain the following characters: [0-9]",
								minlength: "Invalid mobile area code",
								maxlength: "Invalid mobile number"
							},
							mobile_local3:{
								required: "Mobile Number Field 2",
								digits: "Mobile number field 2 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 2",
								maxlength: "Invalid mobile number field 2"
							},
							mobile_local4:{
								required: "Mobile Number Field 3",
								digits: "Mobile number field 3 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 3",
								maxlength: "Invalid mobile number field 3"
							}
						},
						highlight: function(element){
							global.formHelper.showError(element);
						},
						errorPlacement: function()
						{
							
						},
						showErrors: function(errorMap, errorList) {
							
							if(errorList.length > 0)
							{
								
								var errorMSG = "The following required fields are not complete:<br/>";
								
								for(var i = 0; i < errorList.length; i++)
								{
									
									errorMSG += errorList[i].message;
									
									if(i < errorList.length - 1)
									{
										errorMSG += "<br/>"
									}
									
								}
								
								global.formHelper.showErrorBox(errorMSG, errorList[0].element);
								this.defaultShowErrors();
							}
						},
						submitHandler: function(form)
						{
							form.submit();
						}
					});
					
				}
			}
			
		}(), // End welcomeForm
		
		unsubscribeForm: function()
		{
			
			var ref;
			
			return{
				
				init: function()
				{
					
					ref = this;
					
					this.initFormValidation();
					
				},
				
				initFormValidation: function()
				{
					
					global.formHelper.addFocusEvent('#unsubscribe_form');
					
					$('#unsubscribe_form_submit_btn').bind("click", function(){
						
						global.formHelper.resetFormErrors('#unsubscribe_form');
						
						$("#unsubscribe_form").submit();
						
						return false;
						
					});
					
					$("#unsubscribe_form").validate({
						focusInvalid: false,
						onfocusout: false,
						onkeyup: false,
						rules:{
							email:{
								required:{
									depends: function(){
										var num1 = global.utils.trim($('#mobile_area').attr("value"));
										var num2 = global.utils.trim($('#mobile_local3').attr("value"));
										var num3 = global.utils.trim($('#mobile_local4').attr("value"));
										if(num1 == '' && num2 == '' && num3 == '')
										{
											return true;
										}
									}
								},
								email: true
							},
							mobile_area:{
								digits: true,
								required:{
									depends: function(){
										var email = global.utils.trim($('#email').attr("value"));
										var num1 = global.utils.trim($('#mobile_local3').attr("value"));
										var num2 = global.utils.trim($('#mobile_local4').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
										if(email == '')
										{
											return true;
										}
									}
								},
								minlength: 3,
								maxlength: 3
							},
							mobile_local3:{
								digits: true,
								required:{
									depends: function(){
										var email = global.utils.trim($('#email').attr("value"));
										var num1 = global.utils.trim($('#mobile_area').attr("value"));
										var num2 = global.utils.trim($('#mobile_local4').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
										if(email == '')
										{
											return true;
										}
									}
								},
								minlength: 3,
								maxlength: 3
							},
							mobile_local4:{
								digits: true,
								required:{
									depends: function(){
										var email = global.utils.trim($('#email').attr("value"));
										var num1 = global.utils.trim($('#mobile_area').attr("value"));
										var num2 = global.utils.trim($('#mobile_local3').attr("value"));
										if(num1 != '' || num2 != '')
										{
											return true;
										}
										if(email == '')
										{
											return true;
										}
									}
								},
								minlength: 4,
								maxlength: 4
							}
						},
						messages:{
							email:{
								required: "Email Address or Mobile Number",
								email: "Invalid email address"
							},
							mobile_area:{
								required: function()
								{
									var msg = "";
									var email = global.utils.trim($('#email').attr("value"));
									var num1 = global.utils.trim($('#mobile_local3').attr("value"));
									var num2 = global.utils.trim($('#mobile_local4').attr("value"));
									
									if(email != '' || num1 != '' || num2 != '')
									{
										msg = "Mobile Area Code";
									}
									
									return msg;
								},
								digits: "Mobile number area code should only contain the following characters: [0-9]",
								minlength: "Invalid mobile area code",
								maxlength: "Invalid mobile number"
							},
							mobile_local3:{
								required: function()
								{
									var msg = "";
									var email = global.utils.trim($('#email').attr("value"));
									var num1 = global.utils.trim($('#mobile_area').attr("value"));
									var num2 = global.utils.trim($('#mobile_local4').attr("value"));
									
									if(email != '' || num1 != '' || num2 != '')
									{
										msg = "Mobile Number Field 2";
									}
									
									return msg;
								},
								digits: "Mobile number field 2 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 2",
								maxlength: "Invalid mobile number field 2"
							},
							mobile_local4:{
								required: function()
								{
									var msg = "";
									var email = global.utils.trim($('#email').attr("value"));
									var num1 = global.utils.trim($('#mobile_area').attr("value"));
									var num2 = global.utils.trim($('#mobile_local3').attr("value"));
									
									if(email != '' || num1 != '' || num2 != '')
									{
										msg = "Mobile Number Field 3";
									}
									
									return msg;
								},
								digits: "Mobile number field 3 should only contain the following characters: [0-9]",
								minlength: "Invalid mobile number field 3",
								maxlength: "Invalid mobile number field 3"
							}
						},
						highlight: function(element){
							global.formHelper.showError(element);
						},
						errorPlacement: function()
						{
							
						},
						showErrors: function(errorMap, errorList) {
							
							if(errorList.length > 0)
							{
								
								var errorMSG = "The following required fields are not complete:<br/>";
								
								for(var i = 0; i < errorList.length; i++)
								{
									
									if(errorList[i].message != '')
									{
										errorMSG += errorList[i].message;
										
										if(i < errorList.length - 1)
										{
											errorMSG += "<br/>"
										}
									}
								}
								
								global.formHelper.showErrorBox(errorMSG, errorList[0].element);
								this.defaultShowErrors();
							}
						},
						submitHandler: function(form)
						{
							form.submit();
						}
					});
					
				}
				
			}
			
		}(), // End unsubscribeForm
		
		utils: function()
		{
			
			return{
				
				parseJson: function(string)
				{
					return(eval('(' + string + ')'));
				},
				
				trim: function(str)
				{
					
					return $.trim(str);
					
				}, // End Trim
				
				autoTab: function autoTab(event,field, to, len)
				{
					
					if(event.keyCode == 9) return; // Return if tab key was pressed
					
					f1 = document.getElementById(field)
					f2 = document.getElementById(to)
					if(f1.value.length >= len)
					{
						f2.focus()
					}
					
				} // End autoTab
				
			}
			
		}()
		
	}
	
}(); // End subscriptionCenter

var subscriptionCenterPopup = function(props)
{
	
	if(!props) return;
	
	this.target = $(props.target);
	this.isOpen = false;
	
}

subscriptionCenterPopup.prototype.show = function()
{

	this.target.centerInClient();
	
	if($.browser.msie)
	{	
		this.target.show();
	}
	else
	{
		this.target.fadeIn('fast');
	}
	
	this.isOpen = true;
	
}

subscriptionCenterPopup.prototype.hide = function()
{
	
	if($.browser.msie)
	{
		this.target.hide();
	}
	else
	{
		this.target.fadeOut('fast');
	}
	
	this.isOpen = false;
	
}

function showCustomError(id, msg)
{
	
	$(subscriptionCenter.popups[id].target).find('.popup_error_message').html(msg);
	subscriptionCenter.popups[id].popup.show();
	
}

$(document).ready(function(){
	
	subscriptionCenter.init();
	
});