﻿// This functions is responsible for drawing the ASP.NET validation summary.
// We replace the standard function that is provided by ASP.NET by evaluating this script after the standard ASP.NET script.
// It is modified from the standard to present errors in the standard Cubiks layout.

function ValidationSummaryOnSubmit()
{
    if (typeof(Page_ValidationSummaries) == "undefined") 
        return;
    var summary, sums, s;
    for (sums = 0; sums < Page_ValidationSummaries.length; sums++)
    {
        summary = Page_ValidationSummaries[sums];
        summary.style.display = "none";
        if (!Page_IsValid)
        {
            if (summary.showsummary == "False" || Page_Validators.length==0)
            {
                addClassName(summary, "hidden");
            }
            else
            {
                summary.style.display = "";
                removeClassName(summary, "hidden");

                s= "";
                if (typeof(summary.headertext) == "string")
                    s+= "<h2>" + summary.headertext + "</h2>";
                s+= '<ul>';
                for (i=0; i<Page_Validators.length; i++)
                {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string")
                        s += "<li>" + Page_Validators[i].errormessage + '</li>';
                }   
                s+= '</ul>';

                summary.innerHTML = s; 
                window.scrollTo(0,0);
            }
        }
    }
}

// This functions is responsible for validating an individual validation control.
// We replace the standard function that is provided by ASP.NET by evaluating this script after the standard ASP.NET script.
// It is modified from the standard to update the 'controltovalidate' to include an error indicator.

function ValidatorValidate(val, validationGroup, event)
{
    val.isvalid = true;
    if ((typeof(val.enabled) == "undefined" || val.enabled != false) && IsValidationGroupMatch(val, validationGroup))
    {
        if (typeof(val.evaluationfunction) == "function")
        {
           val.isvalid = val.evaluationfunction(val);
           ShowOrHideValidationMarker(val.controltovalidate, val.isvalid);
           if (!val.isvalid && Page_InvalidControlToBeFocused == null && typeof(val.focusOnError) == "string" && val.focusOnError == "t")
            {
                ValidatorSetFocus(val, event);
            }
        }
    }
    ValidatorUpdateDisplay(val);
}

var col__submitted= false;

function enableFormSubmission()
{
    col__submitted= false;
}

// This functions is responsible for submitting the ASP.NET form.
// We replace the standard function that is provided by ASP.NET by evaluating this script after the standard ASP.NET script.
// It is modified from the standard to show the hourglass after pressing submit (for most but not all pages), and to disable the submit button for 5 seconds.

function __doPostBack(eventTarget, eventArgument)
{
    var hourGlass = document.getElementById('master_hourglass');
    var form = document.getElementById('aspnetForm');

    if (!theForm.onsubmit || (theForm.onsubmit() != false))
    {
        if ((typeof (disableHourGlassOnPageExit) == "undefined" || disableHourGlassOnPageExit == false) && hourGlass != null)
        {
            toggleVisibility(document.getElementById('master_hourglass'));
            toggleVisibility(document.getElementById('aspnetForm'));
        }
        if (!col__submitted) 
        {            
            col__submitted = true;
            setTimeout("enableFormSubmission();", 5000);
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
}

// This functions is responsible for handling default buttons specified on ASP.NET panels
// We replace the standard function that is provided by ASP.NET by evaluating this script after the standard ASP.NET script.
// It is modified from the standard to support LinkButtons as we as inputs of type button (specifically for firefox).

function WebForm_FireDefaultButton(event, target)
{
    if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")))
    {
        var defaultButton;
        
        if (__nonMSDOMBrowser)
        {
            defaultButton = document.getElementById(target);
        }
        else
        {
            defaultButton = document.all[target];
        }
        
        if (defaultButton)
        {
            if (typeof(defaultButton.click) != "undefined") // click the button if it is a button
                defaultButton.click();
            else if (typeof(defaultButton.href) != "undefined") // evaluate the javascript on a link href if there is any
                eval(new String(defaultButton.href).replace(/%20/g, ' ')); // remove %20 that FF has put in place of spaces
            event.cancelBubble = true;
            if (event.stopPropagation)
                event.stopPropagation();
            return false;
        }
    }
    return true;
}

// WARNING! OverrideASPJSLoaded() MUST BE THE LAST FUNC IN OverrideASP.JS
function OverrideASPJSLoaded() { return true; }

// Decrease count of pages left to load, so that we know when to hide the hourglass and show the mainpage
if (typeof(jsScriptCount) != "undefined")
    jsScriptCount--;
