var Script = function () {

    //$.validator.setDefaults({
        //submitHandler: function() { alert("submitted!"); }
    //});

    $().ready(function() {
        // validate the comment form when it is submitted
        $("#feedback_form").validate();
		
		// validate login form on keyup and submit
        $("#login_form").validate({
            rules: {
                username: "required",
                password: "required"
            },
            messages: {                
                username: "Please enter a Username.",
                password: "Please enter a password."
            }
        });
		
		// validate reset form on keyup and submit
        $("#forgotten_form").validate({
            rules: {
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {                
                email: "Please enter a valid email address."
            }
        });
		
		
		// validate pin form on keyup and submit
        $("#pin_form").validate({
            rules: {
                pin: "required"
            },
            messages: {                
                pin: "Please enter your pin."
            }
        });
		
		
		
		// validate signup form on keyup and submit
        $("#app-form").validate({
            rules: {
                surname: "required",
				firstname: "required",
				gender: "required",
				dob: "required",
				email: {
                    required: true,
                    email: true
                },
				phone: {
                    required: true,
                    minlength: 10
                },
                address: "required",
				city: "required",
				state: "required",
				zip: "required",
				country: "required",
				identification: "required",
				idno: {
                    required: true,
                    minlength: 5
                },
				expiry: {
                    required: true,
                    minlength: 10
                },
				//photo: "required",
                captcha: {
                    required: true,
                    minlength: 5
                }
            },
            messages: {                
                surname: {
                    required: "Please enter your surname."
                },
				firstname: {
                    required: "Please enter your firstname."
                },
				gender: {
                    required: "Please select your gender."
                },
				dob: {
                    required: "Please select your date of birth."
                },
				email: "Please enter a valid email address.",
				phone: {
                    required: "Please enter your phone number.",
                    minlength: "Your phone number must consist of at least 10 characters long."
                },
                address: "Please enter your address.",
				city: "Please enter your city.",
				state: "Please enter your state.",
				zip: "Please enter your zip.",
				country: "Please select your country.",
				identification: "Please select your identification type.",
                idno: {
                    required: "Please enter your identification number.",
                    minlength: "Your identification number must consist of at least 5 characters long."
                },
                expiry: {
                    required: "Please enter your id expiry date.",
                    minlength: "Your id expiry date must be at least 5 characters long."
                },
				//photo: {
                    //required: "Please select your passport photo."
                //},
                captcha: "Please enter the word above."
            }
        });
		
		
		// validate transfer form on keyup and submit
		$("#trans-form").validate({
            rules: {
				rcv_bk: {
                    required: true,
                    minlength: 5
                },
				name: "required",
				number: {
                    required: true,
                    minlength: 5
                },
				code: "required",
				amount: {
                    required: true,
                    number: true
                }
            },
            messages: {                
                rcv_bk: {
                    required: "Please enter Beneficiary's Bank.",
                    minlength: "Beneficiary's Bank  must consist of at least 5 characters long."
                },
				name: {
                    required: "Please enter Beneficiary's Name."
                },
				number: {
                    required: "Please enter Beneficiary's Account Number.",
                    minlength: "Beneficiary's Account Number must consist of at least 5 characters long."
                },
				code: {
                    required: "Please enter Transfer Code."
                },
				amount: {
                    required: "Enter Amount to Transfer.",
					number: "Amount should only be numbers."
                }
            }
        });
		
		
		// validate auth form on keyup and submit
        $("#auth-form").validate({
            rules: {
                code: "required"
            },
            messages: {                
                code: "Please enter a code."
            }
        });
		
		// validate msg form on keyup and submit
        $("#msg-form").validate({
            rules: {
				msg_subject: {
                    required: true,
					minlength: 5
                },
                msg_cnt: {
                    required: true,
					minlength: 5
                }
            },
            messages: {                
                msg_subject: {
                    required: "Please enter message subject.",
                    minlength: "Message subject must consist of at least 5 characters long."
                },
				msg_cnt: {
                    required: "Please enter Message.",
                    minlength: "Message must consist of at least 5 characters long."
                }
            }
        });
		
		
		// validate rply form on keyup and submit
        $("#rply-form").validate({
            rules: {
                rply_cnt: {
                    required: true,
					minlength: 5
                }
            },
            messages: {                
				rply_cnt: {
                    required: "Please enter Reply.",
                    minlength: "Reply must consist of at least 5 characters long."
                }
            }
        });
		
		
		// validate alrt form on keyup and submit
        $("#alrt-form").validate({
            rules: {
				alrt_subject: {
                    required: true,
					minlength: 5
                },
                alrt_cnt: {
                    required: true,
					minlength: 5
                }
            },
            messages: {                
                alrt_subject: {
                    required: "Please enter alert subject.",
                    minlength: "Alert subject must consist of at least 5 characters long."
                },
				alrt_cnt: {
                    required: "Please enter Alert Message.",
                    minlength: "Alert Message must consist of at least 5 characters long."
                }
            }
        });
		
		
		// validate pwd form on keyup and submit
        $("#pwd-form").validate({
            rules: {
                cpass: {
                    required: true,
					minlength: 4
                },
				pass1: {
                    required: true,
					minlength: 6
                },
				pass2: {
                    required: true,
					minlength: 6,
					equalTo: "#pass1"
                }
            },
            messages: {                
				cpass: {
                    required: "Please enter Current Password.",
                    minlength: "Current Password must consist of at least 4 characters long."
                },
				pass1: {
                    required: "Please enter New Password.",
                    minlength: "New Password must consist of at least 6 characters long."
                },
				pass2: {
                    required: "Please Confirm New Password.",
                    minlength: "Confirm Password must consist of at least 6 characters long.",
					equalTo: "Confirm Password must be the same as New Password above."
                }
            }
        });
		
		
		// validate PIN form on keyup and submit
        $("#pin-form").validate({
            rules: {
                cpin: {
                    required: true,
					minlength: 4
                },
				pin1: {
                    required: true,
					minlength: 4
                },
				pin2: {
                    required: true,
					minlength: 4,
					equalTo: "#pin1"
                }
            },
            messages: {                
				cpin: {
                    required: "Please enter Current PIN.",
                    minlength: "Current PIN must consist of at least 4 characters long."
                },
				pin1: {
                    required: "Please enter New PIN.",
                    minlength: "New PIN must consist of at least 4 characters long."
                },
				pin2: {
                    required: "Please Confirm New PIN.",
                    minlength: "Confirm PIN must consist of at least 4 characters long.",
					equalTo: "Confirm PIN must be the same as New PIN above."
                }
            }
        });
		
		
		// validate spl form on keyup and submit
        $("#spl-form").validate({
            rules: {
				pass: {
                    required: true,
					minlength: 6
                },
				pass2: {
                    required: true,
					minlength: 6,
					equalTo: "#pass"
                },
				pin: {
                    required: true,
					minlength: 4
                },
				pin2: {
                    required: true,
					minlength: 4,
					equalTo: "#pin"
                },
				secq: "required",
				seca: "required",
				photo: "required"
            },
            messages: {                
				pass: {
                    required: "Please enter New Password.",
                    minlength: "New Password must consist of at least 6 characters long."
                },
				pass2: {
                    required: "Please Confirm New Password.",
                    minlength: "Confirm Password must consist of at least 6 characters long.",
					equalTo: "Confirm Password must be the same as New Password above."
                },
				pin: {
                    required: "Please enter New PIN.",
                    minlength: "New PIN must consist of at least 4 characters long."
                },
				pin2: {
                    required: "Please Confirm New PIN.",
                    minlength: "Confirm PIN must consist of at least 4 characters long.",
					equalTo: "Confirm PIN must be the same as New PIN above."
                },
				secq: "Please enter a security question.",
				seca: "Please enter your answer.",
				photo: "Please upload a Passport Photograph."
            }
        });
		
		
		// validate activate form form on keyup and submit
		$("#activate-form").validate({
			rules: {
				acc: "required",
				user: "required",
				pass: {
					required: true,
					minlength: 6
				},
				pin: {
					required: true,
					minlength: 4,
					maxlength: 4
				},
                code1: {
					required: true,
					minlength: 6
				},
                code2: {
					required: true,
					minlength: 9
				},
                code3: {
					required: true,
					minlength: 13
				},
				status: "required",
				type: "required",
				currency: "required"
				//photo: "required"
			},
			messages: {
				acc: "Please enter account number.",
				user: "Please enter User ID.",
				pass: {
					required: "Please enter a Password.",
					minlength: "Your Password must consist of at least 6 characters long."
				},
				pin: {
					required: "Please provide a PIN.",
					minlength: "Your Password must consist of at least 4",
					maxlength: "Your PIN must be at most 4 characters long."
				},
                code1: {
					required: "Please enter a Code.",
					minlength: "Your Code must consist of at least 6 characters long."
				},
                code2: {
					required: "Please enter a Code.",
					minlength: "Your Code must consist of at least 9 characters long."
				},
                code13: {
					required: "Please enter a Code.",
					minlength: "Your Code must consist of at least 13 characters long."
				},
				status: "Please select account status.",
				type: "Please enter account type.",
				currency: "Please select currency."
				//photo: "Please upload a Passport Photograph."
			}
		});
		
		
		// validate activate form form on keyup and submit
		$("#add-trans").validate({
			rules: {
				date: "required",
				details: "required",
				type: "required",
				amount: {
                    required: true,
                    number: true
                }
			},
			messages: {                
				date: "Please select transaction date.",
				details: "Please enter transaction details.",
				type: "Please select transaction type.",
				amount: {
                    required: "Enter transaction amount.",
					number: "Amount should only be in numbers."
                }
			}
		});
		
		
		
		// validate signup form on keyup and submit
        $("#register_form").validate({
            rules: {
                fullname: {
                    required: true,
                    minlength: 6
                },
                address: {
                    required: true,
                    minlength: 10
                },
                username: {
                    required: true,
                    minlength: 5
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
                topic: {
                    required: "#newsletter:checked",
                    minlength: 2
                },
                agree: "required"
            },
            messages: {                
                fullname: {
                    required: "Please enter a Full Name.",
                    minlength: "Your Full Name must consist of at least 6 characters long."
                },
                address: {
                    required: "Please enter a Address.",
                    minlength: "Your Address must consist of at least 10 characters long."
                },
                username: {
                    required: "Please enter a Username.",
                    minlength: "Your username must consist of at least 5 characters long."
                },
                password: {
                    required: "Please provide a password.",
                    minlength: "Your password must be at least 5 characters long."
                },
                confirm_password: {
                    required: "Please provide a password.",
                    minlength: "Your password must be at least 5 characters long.",
                    equalTo: "Please enter the same password as above."
                },
                email: "Please enter a valid email address.",
                agree: "Please accept our terms & condition."
            }
        });


        // propose username by combining first- and lastname
        $("#username").focus(function() {
            var firstname = $("#firstname").val();
            var lastname = $("#lastname").val();
            if(firstname && lastname && !this.value) {
                this.value = firstname + "." + lastname;
            }
        });

        //code to hide topic selection, disable for demo
        var newsletter = $("#newsletter");
        // newsletter topics are optional, hide at first
        var inital = newsletter.is(":checked");
        var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
        var topicInputs = topics.find("input").attr("disabled", !inital);
        // show when newsletter is checked
        newsletter.click(function() {
            topics[this.checked ? "removeClass" : "addClass"]("gray");
            topicInputs.attr("disabled", !this.checked);
        });
    });


}();