

/// validationsummary.js
/// MAJOR HACK:
/// This script overrides the ValidationSummaryOnSubmit function in 
/// the default validation script provided by ASP.NET.
/// The function is overriden to customize the appearance of the 
/// validation summary control.

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") {
                summary.style.display = "";

                if (typeof(summary.displaymode) != "string") {
                    summary.displaymode = "BulletList";
                }

                switch (summary.displaymode) {
                
						  // HACK:
						  // These values were changed to tweak 
						  // the display of the validation summary control
                    case "List":
                        headerSep = "<br>";
                        first = "";
                        pre = "&nbsp;";
                        post = "<br/>";
                        last = "";
                        break;
                        
                    case "BulletList":
                    default: 
                        headerSep = "";
                        first = "<ul>";
                        pre = "<li>";
                        post = "</li>";
                        last = "</ul>";
                        break;
                        
                    case "SingleParagraph":
                        headerSep = " ";
                        first = "";
                        pre = "";
                        post = " ";
                        last = "";
                        break;
                }
                
                s = "";
                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + headerSep;
                }
                s += first;
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        s += pre + Page_Validators[i].errormessage + post;
                    }
                }   
                s += last;
                summary.innerHTML = s; 
                summary.style.marginBottom = "2em";
                window.scrollTo(0,0);
            }
            
            if (summary.showmessagebox == "True") {
                s = "";
                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + "<BR>";
                }
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        switch (summary.displaymode) {
                            case "List":
                                s += Page_Validators[i].errormessage + "<BR>";
                                break;
                                
                            case "BulletList":
                            default: 
                                s += "  - " + Page_Validators[i].errormessage + "<BR>";
                                break;
                                
                            case "SingleParagraph":
                                s += Page_Validators[i].errormessage + " ";
                                break;
                        }
                    }
                }
                span = document.createElement("SPAN");
                span.innerHTML = s;
                s = span.innerText;
                alert(s);
            }
        }
    }
}

