﻿/// <reference path="../jquery-1.5-vsdoc.js" />
/// <reference path="../jquery.validate.js" />
/// <reference path="../jquery.validate.unobtrusive.js" />

$(document).ready(function () {
    $('.showPassword').showPassword('.passwordChecker', { text: 'Verify your password', className: 'showPasswordClass' });
    $("select, input:checkbox, input:radio, input:file").uniform();
});


//$(function () {

//    $("#back-step").live('click', function () {
//        $("#next-step").text("Next");
//        var $step = $(".wizard-step:visible"); // get current step
//        if ($step.prev().hasClass("wizard-step")) { // is there any previous step?
//            $step.hide().prev().fadeIn();  // show it and hide current step

//            // disable backstep button?
//            if (!$step.prev().prev().hasClass("wizard-step")) {
//                $("#back-step").disableBt();
//            }
//        }
//    });

//    // "NEXT" has been pressed? Show next step
//    // ---------------------------------------
//    $("#next-step").live('click', function () {

//        var $step = $(".wizard-step:visible"); // get current step
//        var action = $(".wizard-step:visible .validationController");

//        var formData = $('form').serialize();

//        if (!isValid($step)) {
//            return;
//        }

//        if (hasNextStep($step)) {
//            showNextStep($step);
//        } else {
//            $.ajax({
//                url: 'registration/registerTeam',
//                data: formData,
//                type: 'POST'
//            });
//        }        
//    });

//    // When user leaves txt box, validate against the client if it has remote class attribute
//    // --------------------------------------------------------------------------------------
//    $(".remote").live('blur', function () {
//        var txtBox = this;
//        var formData = $('form').serialize() + "&field=" + txtBox.name;
//        
//        if (!$('form').validate().element(txtBox)) {
//            return;
//        }

//        $("span[data-valmsg-for='" + txtBox.name + "']").removeClass("ok");

//        $.ajax({
//            success: function (result) {
//                if (result == "OK") {
//                    $("span[data-valmsg-for='" + txtBox.name + "']").addClass("ok");
//                }
//                else {
//                    $("span[data-valmsg-for='" + txtBox.name + "']")
//                        .removeClass("field-validation-valid")
//                        .addClass("field-validation-error")
//                        .html('<span>' + result + '</span>');                    
//                }
//            },
//            error: function (request, textStatus, errorThrown) { returnValue = false; },
//            url: 'registration/validateTeamOrganiserField',
//            data: formData,
//            type: 'POST'
//        });
//    });
//});

//function isValid($step) {

//    // obtain validator
//    // ----------------
//    var validator = $("form").validate();
//    var anyError = false;

//    $step.find("input").each(function () {

//        // validate every input element inside this step
//        // ---------------------------------------------
//        if (!validator.element(this)) { 
//            anyError = true;
//        }
//    });

//    // Client side error found
//    // -----------------------
//    if (anyError) {
//        return false;
//    }

//    // Do we need to validate against the server?
//    // ------------------------------------------
//    if ($step.hasClass("validate")) {

//        // Perform server side validation (if required)
//        // --------------------------------------------
//        return validateAgainstServer($step);
//    }

//    return true;
//}


//function showNextStep($step)
//{

//    if (hasNextStep($step)) { // is there any next step?        

//        // Validation is all ok.. show next step
//        // -------------------------------------
//        $step.hide().next().fadeIn();  // show it and hide current step
//        $("#back-step").enableBt();   // recall to show backStep button

//        var $newStep = $(".wizard-step:visible");
//        if (!hasNextStep($newStep)) {
//            $("#next-step").text("Register");   // recall to show backStep button
//        }
//        else {
//            $("#next-step").text("Next");   // recall to show backStep button
//        }
//    }

//    else { // this is last step, submit form
//        $("form").submit();
//    }
//}

//function hasNextStep($step) {
//    return ($step.next().hasClass("wizard-step"))
//}


//// Returns true, if valid
//// ----------------------
//function validateAgainstServer($step) {
//    var action = $step.find(".validationController");
//    var returnVal = false;

//    var formData = $('form').serialize();
//    $("#next-step").disableBt();
//    $("#next-step").text("Checking..");


//    $.ajax({
//        beforeSend: function () {
//            var validator = $("form").validate();
//            //validator.resetForm();
//        },
//        success: function (result) {
//            if (result == "OK") {
//                showNextStep($step);
//            }
//            else {
//                $step.html(result);
//                $("select, input:checkbox, input:radio, input:file").uniform();
//                returnVal = false;
//            }

//            $("#next-step").enableBt();
//            $("#next-step").text("Next");
//        },
//        error: function (request, textStatus, errorThrown) {
//            $("#next-step").enableBt();
//            $("#next-step").text("Next");
//            returnValue = false;
//        },
//        url: 'registration/' + action.val(),
//        data: formData,
//        type: 'POST'
//    });

//    return returnVal;
//}

























//$(function () {
//   
//    $("#back-step").live('click', function () {
//        $("#next-step").text("Next");
//        var $step = $(".wizard-step:visible"); // get current step
//        if ($step.prev().hasClass("wizard-step")) { // is there any previous step?
//            $step.hide().prev().fadeIn();  // show it and hide current step

//            // disable backstep button?
//            if (!$step.prev().prev().hasClass("wizard-step")) {
//                $("#back-step").disableBt();
//            }
//        }
//    });


//    // attach nextStep button handler       
//    $("#next-step").live('click', function () {

//        var $step = $(".wizard-step:visible"); // get current step
//        var controller = $(".wizard-step:visible .validationController");

//        $('form').validate();
//        if (!$('form').valid()) {
//            return false;
//        }

//        if (!performValidation($step, controller.val())) {
//            return false;
//        }

//        //            var validator = $("form").validate(); // obtain validator
//        //            var anyError = false;
//        //            $step.find("input").each(function () {
//        //                alert(!validator.element(this));
//        //                if (!validator.element(this)) { // validate every input element inside this step
//        //                    anyError = true;
//        //                }
//        //            });

//        //            if (anyError)
//        //                return false; // exit if any error found

//        if ($step.next().hasClass("confirm")) { // is it confirmation?
//            // show confirmation asynchronously
//            $.post("/wizard/confirm", $("form").serialize(), function (r) {
//                // inject response in confirmation step
//                $(".wizard-step.confirm").html(r);
//            });

//        }

//        if ($step.next().hasClass("wizard-step")) { // is there any next step?
//            $step.hide().next().fadeIn();  // show it and hide current step
//            $("#back-step").enableBt();   // recall to show backStep button

//            var $newStep = $(".wizard-step:visible");
//            if (!$newStep.next().hasClass("wizard-step")) {
//                $("#next-step").text("Register");   // recall to show backStep button
//            }
//            else {
//                $("#next-step").text("Next");   // recall to show backStep button
//            }
//        }

//        else { // this is last step, submit form
//            $("form").submit();
//        }


//    });

//});

//function performValidation(wizardDiv, action) {
//            
//    var selectedform =  $('form');
//    var formData = selectedform.serialize();
//    var returnValue = false;

//    $.ajax({
//        success: function (result) {
//            if (result == "OK") {
//                returnValue = true;
//            }
//            wizardDiv.html(result);
//            returnValue = false;
//        },
//        error: function (request, textStatus, errorThrown) { returnValue = false; },
//        url: 'registration/' + action,
//        data: formData,
//        type: 'POST'
//    });

//    return returnValue;
//}
