﻿$(document).ready(function() {
    if ($("#aspnetForm").length > 0) {
        $("#aspnetForm").validationEngine({ validationEventTriggers: "keyup blur", success: false, failure: function() { callFailFunction() } })

        if ($("#Quantity").length > 0) {
            $.validationEngine.loadValidation("#Quantity")
            //alert($("#aspnetForm").validationEngine({ returnIsValid: true }))
            //$.validationEngine.buildPrompt("#Quantity", "This is an example", "error")	 		 // Exterior prompt build example
            //$.validationEngine.closePrompt(".formError",true) 
        }
    }

});

function validate2fields() {
    var currentInt = null;
    var myInt = null;
    
    $('.huh').each(function() {
        if ($(this).val()) {
            var stock = null;
            stock = $(this)[0].title;
            myInt = parseInt($(this)[0].title);
            currentInt = parseInt($(this).val());
            if (currentInt > myInt) {
                $.validationEngine.settings.allrules["validate2fields"].alertText = "We have " + stock + " in stock please enter that amount or less";
                $.validationEngine.buildPrompt(this, "We have " + stock + " in stock please enter that amount or less", "error");
                return false;
            }
            else {

                return true;
            }
        }
        else {
            return true;
        }
        return true;
    });

    if (currentInt > myInt) {
    }
    else {
        return true;
    }
    /*
    $(":input").select( function () { 
      //$("div").text("Something was selected " + this.val()).show().fadeOut(1000); 
    });


    if ($("#Quantity").val() == "") {
        return true;
    } else {
    var myInt = parseInt($("#Quantity")[0].title);
    if ($("#Quantity").val() > myInt) {
        $.validationEngine.settings.allrules["validate2fields"].alertText = "We have " + $("#Quantity")[0].title + " in stock please enter that amount or less";
        //$.validationEngine.buildPrompt("#Quantity", "This is an example", "error")
            return false;
        }
        return true;
    }
    */
}
function callFailFunction() { alert("Please enter a valid amount.") }

