﻿//this function is usually used where we have a submit button that needs to disable all other buttons
//when pressed. On the form, the button that we want to execute is hidden but enabled and an HTML button
//is visible in its place. When the HTML button is pressed it calls the click event of the hidden server button.
function DisableAllControls(controlEnabledID) {
    //if(document.getElementById('validEmail').style.display
    //this is the control we want to keep anabled
    var controlEnabled = document.getElementById(controlEnabledID);

    //get all elements from the form
    var count = document.forms[0].elements.length;
    for (i = 0; i < count; i++) {
        var element = document.forms[0].elements[i];
        element.onclick = noClick;
//        //if element is not part of the breadcrumb control
//        if (element.id.indexOf('pagebc') == -1) {
//            //if element is not hidden (for breadcrumb textboxes or any other non-visible control)
//            if (element.type != 'hidden') {
//                //if element is not the control we want to keep enabled, disable it
//                if (controlEnabled != element) {
//                    if (element.type == 'text') {
//                        element.style.backgroundColor = 'silver';
//                        element.style.foreColor = 'black';
//                        element.readOnly = true;
//                    }
//                    else {
//                        element.onclick = noClick;
//                        //element.disabled = 'true';
//                    }
//                }
//                else {
////                    var newButton = document.createElement('button');
////                    var buttonIdName = 'my' + 'Button';
////                    newButton.setAttribute('id', buttonIdName);
////                    newButton.value = controlEnabled.value;
////                    newButton.style.width = controlEnabled.style.width;
////                    newButton.className = controlEnabled.className;
////                    var elementPos=0;
////                    for(i=0;i<controlEnabled.parentElement.children.length;i++)
////                    {
////                        if (controlEnabled.parentElement.children[i].id == controlEnabled.id)
////                        {
////                            elementPos = i;
////                            //controlEnabled.parentElement.children[0] = controlEnabled;
////                        }
////                    }
//                    //controlEnabled.parentElement.appendChild(newButton);
//                    //controlEnabled.parentElement.children[elementPos] = newButton;
//                   // element.style.display = 'none';
//                    element.onclick = noClick;
//                    //element.onclick = new function() { return false; element.disabled = true; };
////                    newButton.disabled = true;
//                    
//                }
//            }
//        }

    }
}

 function noClick() 
    { 
//        alert("Chill - You already submitted this page once. "+ 
//                "Submitting it twice isn't going to make the "+  
//                "server go faster.  Quit hitting the "+ 
//                "freakin' button!"); 

        return false; 
    } 


function addElement() {
//    var ni = document.getElementById('myDiv');
//    var numi = document.getElementById('theValue');
//    var num = (document.getElementById('theValue').value - 1) + 2;
//    numi.value = num;
//    var newButton = document.createElement('button');
//    var buttonIdName = 'my' + 'Button';
//    newButton.setAttribute('id', buttonIdName);
//    newButton.text = element.text;
//    newdiv.innerHTML = 'Element Number ' + num + ' has been added! <a href=\'#\' onclick=\'removeElement(' + divIdName + ')\'>Remove the div "' + divIdName + '"</a>';
//    ni.appendChild(newdiv);
}
