﻿$(document).ready(function () {    
    $("#ctl00_phContent_txtDate").datepicker({dateFormat: "dd/mm/yy"});
    $(".booking-your-first-name").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-your-first-name").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"alphanum","first name","Field accepts letters, dashes and spaces.");
    });
    
    $(".booking-your-last-name").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-your-last-name").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"alphanum","last name","Field accepts letters, dashes and spaces.");
    });
    
    $(".booking-your-email").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-your-email").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"email","contact email","Must be a valid email address.");
    });
    
    $(".booking-your-mobile").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-your-mobile").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"telnumber","contact mobile","Must be a valid mobile number.");
    });
    
    $(".booking-your-tel").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-your-tel").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"telnumber","contact telephone","Must be a valid telephone number.");
    });
    
    $(".booking-num-attending").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-num-attending").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"number","null","Must be a number");
    });
    
    $(".booking-date").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $("a[rel=datepick]").click(function() {
        $('.booking-date').focus();
        return false;
    });
    
    $(".booking-date").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"date","dd/mm/yyyy","Must be a valid date.");
    });
    
    $(".booking-time").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-time").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"time","hh:mm","Must be a valid time.");
    });
    
    $(".booking-priv-card").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-priv-card").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"sqlinjection","card number","Must be a valid privilege card number.");
    });
    
    
    $(".booking-diet-reqs").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-diet-reqs").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"sqlinjection","any dietry requirements","Invalid characters found.");
    });
    
    $(".booking-other-occ").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-other-occ").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"sqlinjection","","Invalid characters found.");
    });
    
    $(".booking-anything-else").focus(function() {
        $(this).animate({color: "#c21b04"},300);
    });
    
    $(".booking-anything-else").blur(function() {
        $(this).animate({color: "#424242"},300);
        validate(("#"+$(this).attr("id")),"sqlinjection","anything else","Invalid characters found.");
    });
    
    $("#ctl00_phContent_txtTime").keypress(function(ev) {
        var c_val = $(this).val();
        var ord = c_val.length; // The ORD is the length BEFORE the event was fired.
        
        if(ev.which==8 || ev.which == 0 ) {
            return true;
        } else {
            switch(ord) {
                case 0:
                case 1:
                    if(!((ev.which>=48)&&(ev.which<=57))) { return false; }
                    break;
                case 2:
                    if(ev.which!=58) { return false; }
                    break;
                case 3:
                case 4:
                    if(!((ev.which>=48)&&(ev.which<=57))) { return false; }
                    break;
                default:
                    return false;
            }
        }
    });
});

