﻿//===============================================================================
// * Namespace:   YouFound.ValidationElements
// * Description: Provides a common definition for all types of field validators
//                as they would otherwise need to be replicated through various
//                parts of the project.
//===============================================================================

$(function() {
	YouFound.ValidationElements = (function() {

		return {
			// *************** 
			//  PRODUCT
			// ***************


			// *************** 
			//  WEB PAGE
			// ***************
			
			NavNameField : new FormValidator.Element('navNameField', {
	            rules: {
	                required: {error: 'Type your navigation name.'},
	                minlength: {length: 6, error: 'Field must be at least 6 chars.'},
	                maxlength: {length: 15, error: 'Field must be less then 15 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),

			PageHeadingField : new FormValidator.Element('pageHeadingField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 35, error: 'Field must be less then 35 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),
			        
	        PageSummaryField : new FormValidator.Element('pageSummaryField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 250, error: 'Field must be less then 250 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),
	        
	        PageKeywordsField : new FormValidator.Element('pageKeywordsField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 100, error: 'Field must be less then 100 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),
	        
	        ContentField : new FormValidator.Element('contentField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 3000, error: 'Field must be less then 3000 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),

	        FirstNameField : new FormValidator.Element('firstNameField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 50, error: 'Field must be less then 50 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),

	        SurnameField : new FormValidator.Element('surnameField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 50, error: 'Field must be less then 50 chars.'}
	            },
	            valid: 'Field is successful.'
	        }),

	        TermsAgreeField : new FormValidator.CheckElement('termsAgreeField', {
	            rules: {
	                required: {error: 'You must agree to the Terms and Contidions of the site to create an account.'}
	            }
	        }),

			UsernameField : new FormValidator.Element('usernameField', {
				rules: {
					required: { error: 'Please enter your username.' },
					alphanum: { error: 'Only letters, numbers and "_" char are allowed.' },
					minlength: { length: 2, error: 'Your username needs to be at least 2 characters long.' },
					maxlength: { length: 50, error: 'Your username can not be more then 50 characters long.' },
					ajax: { url: '/AjaxCommon/IsValidUserName', error: 'This username is already taken.', cache: true }
				},
				valid: 'This username is available.'
			}),

			// Email
			EmailField : new FormValidator.Element('emailField', {
				rules: {
					required: { error: 'Please enter your email address.' },
					email: { error: 'The email address must be valid as it will be used to confirm your subscription.' },
					ajax: { url: '/AjaxCommon/IsValidUserEmail', error: 'This email address is already taken', cache: true }
				},
				valid: 'Email name is successful.'
			}),

			// Password
			PasswordField : new FormValidator.Element('passwordField', {
				rules: {
					required: { error: 'Please enter your password.' },
					minlength: { length: 6, error: 'Password should be at least 6 characters.' },
					maxlength: { length: 20, error: 'Password should be less then 20 characters.' },
					regexp: { regexp: /^[\d\w\.,-_]+$/, error: 'Your password must contain numbers (0-9) and letters (a-z). You may also use "." "," "-" "_"' }
				},
				valid: 'Password is correct.'
			}),

			// Confirm password
			ConfirmPasswordField : new FormValidator.Element('confirmPasswordField', {
				rules: {
					required: { error: 'Please enter your password.' },
					minlength: { length: 6, error: 'Password should be at least 6 characters.' },
					maxlength: { length: 20, error: 'Password should be less then 20 characters.' },
					regexp: { regexp: /^[\d\w\.,-_]+$/, error: 'Your password must contain numbers (0-9) and letters (a-z). You may also use "." "," "-" "_"' },
					equalTo: { value: $('#passwordField input'), error: 'Passwords do not match.' }
				},
				valid: 'The password and confirmation password match.'
			}),

			// Business name
			BusinessNameField : new FormValidator.Element('businessNameField', {
				rules: {
					required: { error: 'Please enter the name of your business.' },
					ajax: { url: '/AjaxCommon/IsValidBusinessName', error: 'rewritten in the ajax response', cache: false }
				},
				valid: 'This business name is available.'
			}),

			// Shortcut field
			RelativeShortcutUrlField : new FormValidator.Element('relativeShortcutUrlField', {
				rules: {
					required: { error: 'Please enter your Short Cut address.' },
					minlength: { length: 2, error: 'Short Cut address should be equal or more than 2 symbols.' },
					regexp: { regexp: /^[\d\w-_]+$/, error: 'Shortcut must contain numbers (0-9) and letters (a-z) and "-" or "_".' },
					ajax: { url: '/AjaxCommon/IsValidShortcutUrl', error: 'This url shortcut is already taken.', cache: true }
				},
				valid: 'Congratulations, the short cut URL is available.'
			}),

			// Business category
			CategoryField : new FormValidator.SelectElement('categoryField', {
				rules: {
					required: { error: 'Please select your businesses category.' }
				},
				valid: 'Category is successful.'
			}),

			// Business Industry
			IndustryField : new FormValidator.SelectElement('industryField', {
				rules: {
					required: {error: 'Please select your businesses industry.'}
				},
				valid: 'Industry is successful.'
			}),


			// State
			StateField : new FormValidator.SelectElement('stateField', {
				rules: {
					required: { error: 'Please select the state your business is in.' }
				},
				valid: 'State is successful.'
			}),

			// Area
			AreaField : new FormValidator.SelectElement('areaField', {
				rules: {
					required: { error: 'Please select the area your business is in.' }
				},
				valid: 'Area is successful.'
			}),


			// Company ABN
	        CompanyABNField : new FormValidator.Element('companyABNField', {
	            rules: {
	                required: {error: 'Field is empty. Please fill it.'},
	                maxlength: {length: 15, error: 'Field must be less then 15 chars.'},
					ajax: { url: '/AjaxCommon/IsValidABN', error: 'This ABN is already taken.', cache: false }
	            },
	            valid: 'Field is successful.'
	        })
		};

	})();
});

