﻿// JScript File
function validateOrderTodayForm(string_containerName)
{ 
    var form_currentForm = object_GeneralUtilities_GetObject('aspnetForm');
    var string_currentElementName;
    var object_controlType;
    var object_currentControl;
    var int_currentIndex;
    var int_selectedValue;
   
    var divContainer = $('#' + string_containerName);
    
    var dropDownObjects = divContainer.find('select');
   
    for (var i = 0; i < dropDownObjects.length; i++)
    {
        var string_friendlyName = dropDownObjects[i].getAttribute("friendlyName");
        
        if(!bool_validateOrderTodayDropDownObject(dropDownObjects[i].id, true, string_friendlyName))
            return false;
    }

    var textBox_quantityBox = object_GeneralUtilities_GetObject('textBoxQuantity');

    if (textBox_quantityBox != null && !bool_GeneralUtilities_StringIsValidPositiveInteger(textBox_quantityBox.value))
    {
          $(textBox_quantityBox).parents("form:first").validationEngine({promptPosition: textBox_quantityBox.getAttribute("promptPosition")=="" ? "topRight" : textBox_quantityBox.getAttribute("promptPosition"), inlineValidation: false});
          $.validationEngine.buildPrompt(textBox_quantityBox, "Please enter a valid quantity", "error");

      //alert("Please enter a valid quantity.");
      return false;
    }
    else
    {
        $.validationEngine.closePrompt(textBox_quantityBox);
    }
     
    return true;
}

function bool_validateOrderTodayDropDownObject(string_objectName, bool_highlightObject, string_objectFriendlyName)
{
    var object_currentFormObject = object_GeneralUtilities_GetObject(string_objectName);
    
    if (object_currentFormObject != null)
    {
        int_currentIndex = object_currentFormObject.selectedIndex;
        int_selectedValue = object_currentFormObject.options[int_currentIndex].value;
        
        if (bool_GeneralUtilities_StringIsValidInteger(int_selectedValue))
        {
            if (int_selectedValue == -1)
            {                            
                if(bool_highlightObject)
                {
                    if (!string_objectFriendlyName)
                        string_objectFriendlyName = object_currentFormObject.getAttribute("friendlyName");
                
                    $(object_currentFormObject).parents("form:first").validationEngine({promptPosition: object_currentFormObject.getAttribute("promptPosition")=="" ? "topRight" : object_currentFormObject.getAttribute("promptPosition"), inlineValidation: false});
                    $.validationEngine.buildPrompt(object_currentFormObject, ((string_objectName != null && string_objectName != "") ? "Please select " + string_GeneralUtilities_AttemptToGetArticleForWord(string_objectFriendlyName) + " " + string_objectFriendlyName : "Please make a selection"), "error");
                } 
                return false;
            }
            else
            {
                $.validationEngine.closePrompt(object_currentFormObject);
            }
        }
    }
    
    return true;
}

