﻿//Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);
//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endReq);
//var ModalProgress;

//function beginReq(sender, args) {
//    // shows the Popup
//    if (ModalProgress == 'ctl00_Body_ModalProgress') {
//        var pop = $find(ModalProgress);
//        pop.show();
//    }    
//}

//function endReq(sender, args) {
//    //  hides the Popup
//    var pop = $find(ModalProgress);
//    if (pop != null) {
//        pop.hide();
//    }
//}

function toggleGroup(img, numberOfRows) {
    //  get a reference to the row and table
    var tr = img.parentNode.parentNode;
    var table = $get('orders');
    var src = img.src;
    //  do some simple math to determine how many
    //  rows we need to hide/show
    var startIndex = tr.rowIndex + 1;
    var stopIndex = startIndex + parseInt(numberOfRows);
    
    //  if the img src ends with plus, then we are expanding the
    //  rows.  go ahead and remove the hidden class from the rows
    //  and update the image src
    if (src.endsWith('plus2.gif')) {
        for(var i = startIndex; i < stopIndex; i++){
            Sys.UI.DomElement.removeCssClass(table.rows[i], 'hidden');
        }

        src = src.replace('plus2.gif', 'minus2.gif');
    }
    else{
        for(var i = startIndex; i < stopIndex; i++){
            Sys.UI.DomElement.addCssClass(table.rows[i], 'hidden');
        }

        src = src.replace('minus2.gif', 'plus2.gif');
    }
    
    //  update the src with the new value
    img.src = src;
}
// AsyncFileUpload Validation
function uploadError(sender, args) {
    $get('lblFuMsg').innerText = args.get_errorMessage();
    $get('lblFuMsg').style.color = "red";
}

function uploadComplete(sender, args) {
    var fileSize = parseInt(args.get_length());
    var contentType = args.get_contentType();
    var types = "text/html,text/plain,image/gif,image/x-xbitmap,image/x-xpixmap,image/x-png,image/jpeg,image/pjpeg,image/tiff,application/rtf,application/pdf,application/x-pdf,application/msword,application/vnd.ms-excel,application/x-msexcel,application/ms-excel,application/vnd.ms-works,application/vnd.ms-word,application/ms-word,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    var fileOk = types.split(",");
    var ok = 0;

    var counter = 0;

    try {
        while (counter < fileOk.length) {
            if (fileOk[counter] == contentType) {
                ok = 1;
            }
            counter += 1;
        }
    }
    catch (e) {
        alert(e.message);
    }

    try {
        if (ok == 1) {
            if (fileSize > 0 && fileSize < 5242881) {
                $get('lblFuMsg').innerText = "File uploaded!";
                $get('lblFuMsg').style.color = "green";
                return true;
            }
            else {
                args.set_cancel(true);
                $get('lblFuMsg').innerText = "File size must be 5MB or less.";
                $get('lblFuMsg').style.color = "red";
                return false;
            }
        }
        else {
            args.set_cancel(true);
            $get('lblFuMsg').innerText = "Please select an acceptable file type. (Plain Text, Word, Excel, PowerPoint, PDF, or Image)";
            $get('lblFuMsg').style.color = "red";
            return false;
        }
    }
    catch (e) {
        alert(e.message);
        return false;
    }
}

function uploadStarted(sender, args) {
    $get('lblFuMsg').innerText = "Upload started.";
    $get('lblFuMsg').style.color = "green";
}
