﻿/*Quick Shipment Quote */

function ValidateDims(s, e) {
    var l = document.getElementById(s.id.replace('valDim', 'txtLength')).value;
    var w = document.getElementById(s.id.replace('valDim', 'txtWidth')).value;
    var h = document.getElementById(s.id.replace('valDim', 'txtHeight')).value;
    if (!isNaN(parseFloat(l)) || !isNaN(parseFloat(w)) || !isNaN(parseFloat(h)))
        e.IsValid = l * w * h;
    else
        e.IsValid = true;
}

var resultheight = 0;
var step = 0;

function SlideDown() {
    var elem = document.getElementById('trackresult');
    resultheight = elem.offsetHeight;
    if (resultheight < 160) {
        resultheight = 160;
    }
    step = 10;
    elem.style.height = '0px';
    elem.style.visibility = 'visible';
    resize();
}

function SlideUp() {
    var elem = document.getElementById('trackresult');
    step = -10;
    resize();
}

function resize() {
    var elem = document.getElementById('trackresult');
    var curheight = parseInt(elem.style.height);
    curheight += step;
    if (curheight <= 0) {
        curheight = 0;
        elem.style.display = 'none';
    }
    else if (curheight > resultheight) {
        curheight = resultheight;
    }
    try {
        elem.style.height = curheight + 'px';
        if ((step < 0 && curheight > 0) || (step > 0 && curheight < resultheight)) {
            window.setTimeout(function () { resize() }, 10);
        }
    }
    catch (err) { }
}

/*Quick Shipment Quote End*/

if (!Array.indexOf) {
    Array.prototype.indexOf = function (searchObject) {
        if (this.length == 0)
            return -1; //if the length of the array is 0, then there can be no matches.  

        var intAryPosMatchFoundIn = 0;
        for (var i = 0; i < this.length; i++) {
            if (this[i] == searchObject) {
                intAryPosMatchFoundIn = i;
                break;
            }
            else
                intAryPosMatchFoundIn = -1;
        }
        return intAryPosMatchFoundIn;
    }
}

function validatePage() {
    var blnReturn = true;

    //Do nothing if client side validation is not enabled.  
    if (typeof (Page_Validators) == "undefined") return true;
    if (typeof (Page_ValidationSummaries) == "undefined") return true;

    for (var i = 0; i < Page_ValidationSummaries.length; i++)
        if (Page_ValidationSummaries[i].validationGroup != null) {
            Page_ClientValidate(Page_ValidationSummaries[i].validationGroup.toString());
        }

    for (var i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i]);
        if (!Page_Validators[i].isvalid)
            blnReturn = false;
    }

    //Figure out which validation groups have errors, store a list of these validation groups in an array.  
    var aryValGrpsWithErrors = [];
    for (var i = 0; i < Page_Validators.length; i++) {
        if (!Page_Validators[i].isvalid) {
            //This particular validator has thrown an error.  
            //If we haven't already registered the validation group this erroring validation control is a part of, do so now.  
            if (typeof (Page_Validators[i].validationGroup) != "undefined" && aryValGrpsWithErrors.indexOf(Page_Validators[i].validationGroup.toString()) == -1)
                aryValGrpsWithErrors[aryValGrpsWithErrors.length++] = Page_Validators[i].validationGroup.toString();
        }
    }

    //Now display every validation summary that has !isvalid validation controls in it.  
    for (var i = 0; i < Page_ValidationSummaries.length; i++) {
        if (typeof (Page_ValidationSummaries[i].validationGroup) != "undefined" && aryValGrpsWithErrors.indexOf(Page_ValidationSummaries[i].validationGroup.toString()) != -1) {
            Page_ValidationSummaries[i].style.display = "";
        }
        else {
            //The current validation summary does not have any error messages in it, so make sure it's hidden.  
            Page_ValidationSummaries[i].style.display = "none";
        }
    }
    Page_BlockSubmit = false;
    return blnReturn;
}
