/*
Title: Webpage Disable/Re-Enable 
Author: Damian J Trabel
Company: Luciq, Inc.
Prerequisites:
Created: 2005.12.18
Modified: 2005.12.18
Notes: 
*/

//----------------------------------------------------------Variables---------------------------------------------------------
 
var elementArrayButtons      = null;
var elementArrayShortButtons = null;
var elementArrayTextFields   = null;
var elementArrayTextAreas    = null;
var elementArraySelects      = null;
var elementArrayCheckboxes   = null;
var elementArrayRadios       = null;
var elementArrayLinks        = null;

var stateArrayButtons      = null;
var stateArrayShortButtons = null;
var stateArrayTextFields   = null;
var stateArrayTextAreas    = null;
var stateArraySelects      = null;
var stateArrayCheckboxes   = null;
var stateArrayRadios       = null;
var stateArrayLinkHrefs    = null;
var stateArrayLinkOnclicks = null;
var stateArrayLinkColors   = null;
     
var elementCountButton   = 0;
var elementCountInput    = 0;
var elementCountText     = 0;
var elementCountTextarea = 0;
var elementCountSelect   = 0;
var elementCountA        = 0;

//----------------------------------------------------------Functions---------------------------------------------------------

function disableButton(){
  var myArguments = disableButton.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.cursor = "default";
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	  myArguments[i].disabled = true;
	}// end for
}// end disableButton

function enableButton(){
	var myArguments = enableButton.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].disabled = false;
	  myArguments[i].style.cursor = "pointer";
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	}// end for
}// end enableButton

function disableShortButton(){
  var myArguments = disableShortButton.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	  myArguments[i].disabled = true;
	  myArguments[i].style.cursor = "default";
	}// end for
}// end disableButton

function enableShortButton(){
  var myArguments = enableShortButton.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#343434";
	  myArguments[i].disabled = false;
	  myArguments[i].style.cursor = "pointer";
	}// end for
}// end enableButton

function disableTextField(){
  var myArguments = disableTextField.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	  myArguments[i].style.color = "#505050";
	  myArguments[i].readOnly = true;
	  myArguments[i].style.cursor = "default";
	}// end for
}// end disableTextField

function protectTextField(){
  var myArguments = protectTextField.arguments;
	for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	  myArguments[i].style.color = "#000000";
	  myArguments[i].readOnly = true;
	  myArguments[i].style.cursor = "default";
	}// end for
}// end protectTextField

function enableTextField(){
  var myArguments = enableTextField.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#FFFFFF";
	  myArguments[i].style.color = "#000000";
	  myArguments[i].disabled = false;
	  myArguments[i].readOnly = false;
	  myArguments[i].style.cursor = "text";
	}// end for
}// end enableTextField

function disableSelect(){
  var myArguments = disableSelect.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#F0F0F0";
	  myArguments[i].style.color = "#000000";
	  myArguments[i].disabled = true;
	}// end for
}// end disableSelect

function enableSelect(){
  var myArguments = enableSelect.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].style.backgroundColor = "#FFFFFF";
	  myArguments[i].style.color = "#000000";
	  myArguments[i].disabled = false;
	  myArguments[i].readOnly = false;
	}// end for
}// end enableSelect

function disableCheckbox(){
	var myArguments = disableCheckbox.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].disabled = true;
	}// end for
}// end disableCheckbox

function enableCheckbox(){
  var myArguments = enableCheckbox.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].disabled = false;
	}// end for
}// end enableCheckbox

function disableRadio(){
  var myArguments = disableRadio.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].disabled = true;
	}// end for
}// end disableCheckbox

function enableRadio(){
	var myArguments = enableRadio.arguments;
  for(var i=0; i<myArguments.length; i++){
	  myArguments[i].disabled = false;
	}// end for
}// end enableCheckbox

// protect all functions -------------------------------------------------------------

function protectAllTextFields(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].type == "text"){
		  protectTextField(myArray[i]);
		}// end if
	}// end for
}// end protectAllTextFields

function enableAllTextFields(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].type == "text"){
		  enableTextField(myArray[i]);
		}// end if
	}// end for
}// end enableAllTextFields

function disableAllTextFields(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].type == "text"){
		  disableTextField(myArray[i]);
		}// end if
	}// end for
}// end disableAllTextFields

function enableAllSelects(){
  var myArray = document.getElementsByTagName("select");
	for(var i=0; i<myArray.length; i++){
		enableSelect(myArray[i]);
	}// end for
}// end enableAllSelects

function disableAllSelects(){
  var myArray = document.getElementsByTagName("select");
	for(var i=0; i<myArray.length; i++){
		disableSelect(myArray[i]);
	}// end for
}// end disableAllSelects

function protectAllSelects(){
  var myArray = document.getElementsByTagName("select");
	for(var i=0; i<myArray.length; i++){
		protectSelect(myArray[i]);
	}// end for
}// end disableAllSelects

function enableAllCheckboxes(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].type == "checkbox"){
		  enableCheckbox(myArray[i]);
		}// end if
	}// end for
}// end disableAllCheckboxes

function disableAllCheckboxes(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].type == "checkbox"){
		  disableCheckbox(myArray[i]);
		}// end if
	}// end for
}// end disableAllCheckboxes

function disableAllButtons(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if((myArray[i].type == "button" || myArray[i].type == "submit") && myArray[i].className != "shortButton"){
		  disableButton(myArray[i]);
		}// end if
	}// end for
	myArray = document.getElementsByTagName("button");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].className != "shortButton"){
		  disableButton(myArray[i]);
		}// end if
	}// end for
}// end disableAllButtons

function enableAllButtons(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if((myArray[i].type == "button" || myArray[i].type == "submit") && myArray[i].className != "shortButton"){
		  enableButton(myArray[i]);
		}// end if
	}// end for
	myArray = document.getElementsByTagName("button");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].className != "shortButton"){
		  enableButton(myArray[i]);
		}// end if
	}// end for
}// end enableAllButtons

function disableAllShortButtons(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if((myArray[i].type == "button" || myArray[i].type == "submit") && myArray[i].className == "shortButton"){
		  disableShortButton(myArray[i]);
		}// end if
	}// end for
	myArray = document.getElementsByTagName("button");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].className == "shortButton"){
		  disableShortButton(myArray[i]);
		}// end if
	}// end for
}// end disableAllShortButtons

function enableAllShortButtons(){
  var myArray = document.getElementsByTagName("input");
	for(var i=0; i<myArray.length; i++){
		if((myArray[i].type == "button" || myArray[i].type == "submit") && myArray[i].className == "shortButton"){
		  enableShortButton(myArray[i]);
		}// end if
	}// end for
	myArray = document.getElementsByTagName("button");
	for(var i=0; i<myArray.length; i++){
		if(myArray[i].className == "shortButton"){
		  enableShortButton(myArray[i]);
		}// end if
	}// end for
}// end enableAllShortButtons

    
function reEnableAllLinks(){
  try{
    if(stateArrayLinkHrefs != null){
      var myArray = getAllLinks();
	    for(var i=0; i<myArray.length; i++){
		    myArray[i].style.color = stateArrayLinkColors[i];
		    myArray[i].style.cursor= "pointer";
	      //myArray[i].href        = stateArrayLinkHrefs[i];
		    myArray[i].onclick     = stateArrayLinkOnclicks[i];
	    }// end for
	    stateArrayLinkOnclicks = null;
	    stateArrayLinkHrefs    = null;
      stateArrayLinkColors   = null;
    }// end if
  }catch(e){alert(e.description);}
}// end enableAllLinks

function tempDisableAllLinks(){
  if(stateArrayLinkHrefs == null){
    try{
      var myArray = getAllLinks();
      stateArrayLinkHrefs    = new Array();
      stateArrayLinkOnclicks = new Array();
      stateArrayLinkColors   = new Array();
	    for(var i=0; i<myArray.length; i++){
	      //stateArrayLinkHrefs[i]    = myArray[i].href;
        stateArrayLinkOnclicks[i] = myArray[i].onclick;
		    stateArrayLinkColors[i]   = myArray[i].style.color;
	      //myArray[i].href           = "#";
		    myArray[i].onclick        = "return false;";
		    myArray[i].style.color    = "#A0A0A0";
		    myArray[i].style.cursor   = "default";
	    }// end for
	  }
	  catch(e){
	    alert("An error occurred while disabling link: " + e.description);
	  }// end try/catch
	}// end if
}// end disableAllLinks
    
function reEnableAllTextFields(){
  if(stateArrayTextFields != null){
    var myArray = getAllTextFields();
	  for(var i=0; i<myArray.length; i++){
		  if(!stateArrayTextFields[i]){
		    enableTextField(myArray[i]);
		  }// end if
	  }// end for
	  stateArrayTextFields = null;
	}// end if
}// end reEnableAllTextFields

function tempDisableAllTextFields(){
  if(stateArrayTextFields == null){
    stateArrayTextFields = new Array();
    var myArray = getAllTextFields();
	  for(var i=0; i<myArray.length; i++){
		  stateArrayTextFields[i] = (myArray[i].disabled || myArray[i].readOnly);
		  disableTextField(myArray[i]);
	  }// end for
	}// end if
}// end tempDisableAllTextFields

function reEnableAllSelects(){
  if(stateArraySelects != null){
    var myArray = getAllSelects();
	  for(var i=0; i<myArray.length; i++){
	    if(!stateArraySelects[i]){
		    enableSelect(myArray[i]);
		  }// end if
	  }// end for
	  stateArraySelects = null;
	}// end if
}// end reEnableAllSelects

function tempDisableAllSelects(){
  if(stateArraySelects == null){
    stateArraySelects = new Array();
    var myArray = getAllSelects();
	  for(var i=0; i<myArray.length; i++){
	    stateArraySelects[i] = (myArray[i].disabled || myArray[i].readOnly);
		  disableSelect(myArray[i]);
	  }// end for
	}// end if
}// end tempDisableAllSelects 


function tempDisableAllCheckboxes(){
  if(stateArrayCheckboxes == null){
    stateArrayCheckboxes = new Array();
    var myArray = getAllCheckboxes();
	  for(var i=0; i<myArray.length; i++){
		  stateArrayCheckboxes[i] = myArray[i].disabled;
		  disableCheckbox(myArray[i]);
	  }// end for
	}// end if
}// end tempDisableAllCheckboxes  

function reEnableAllCheckboxes(){
  if(stateArrayCheckboxes != null){
    var myArray = getAllCheckboxes();
	  for(var i=0; i<myArray.length; i++){
		  if(!stateArrayCheckboxes[i]){
		    enableCheckbox(myArray[i]);
		  }// end if
	  }// end for
	  stateArrayCheckboxes = null;
  }// end if
}// end reEnableAllCheckboxes

function tempDisableAllButtons(){
  if(stateArrayButtons == null){
    stateArrayButtons = new Array();
    var myArray = getAllButtons();
	  for(var i=0; i<myArray.length; i++){
		  stateArrayButtons[i] = myArray[i].disabled;
		  disableButton(myArray[i]);
	  }// end for
	}// end if
}// end disableAllButtons

function reEnableAllButtons(){
  if(stateArrayButtons != null){
    var myArray = getAllButtons();
	  for(var i=0; i<myArray.length; i++){
		  if(!stateArrayButtons[i]){
		    enableButton(myArray[i]);
		  }// end if
	  }// end for
	  stateArrayButtons = null;
	}// end if
}// end enableAllButtons
    

function tempDisableAllShortButtons(){
  if(stateArrayShortButtons == null){
    stateArrayShortButtons = new Array();
    var myArray = getAllShortButtons();
	  for(var i=0; i<myArray.length; i++){
		  stateArrayShortButtons[i] = myArray[i].disabled;
		  disableShortButton(myArray[i]);
	  }// end for
	}// end if
}// end tempDisableAllShortButtons

function reEnableAllShortButtons(){
  if(stateArrayShortButtons != null){
    var myArray = getAllShortButtons();
	  for(var i=0; i<myArray.length; i++){
		  if(!stateArrayShortButtons[i]){
		    enableShortButton(myArray[i]);
		  }// end if
	  }// end for
	  stateArrayShortButtons = null;
	}// end if
}// end reEnableAllShortButtons
    

function tempDisableAllRadios(){
  if(stateArrayRadios == null){
    stateArrayRadios = new Array();
    var myArray = getAllRadios();
	  for(var i=0; i<myArray.length; i++){
		  stateArrayRadios[i] = myArray[i].disabled;
		  disableRadio(myArray[i]);
	  }// end for
	}// end if
}// end tempDisableAllRadios

function reEnableAllRadios(){
  if(stateArrayRadios != null){
    var myArray = getAllRadios();
	  for(var i=0; i<myArray.length; i++){
		  if(!stateArrayRadios[i]){
		    enableRadio(myArray[i]);
		  }// end if
	  }// end for
	  stateArrayRadios = null;
	}// end if
}// end reEnableAllRadios


function getAllLinks(){

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("a");
  
  if(elementArrayLinks != null && elementCountA == tArray1.length){
    myArray = elementArrayLinks;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
		  myArray[myCount] = tArray1[i];
		  myCount++;
    }// end for
    elementCountA     = tArray1.length;
    elementArrayLinks = myArray;
  }// end if/else
  
  return myArray;
  
}// end getAllLinks

function getAllTextFields(){
  
  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("input");
  var tArray2 = document.getElementsByTagName("textarea");
  
  if(elementArrayTextFields != null && elementCountInput == tArray1.length && elementCountTextarea == tArray2.length){
    myArray = elementArrayTextFields;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
      if(tArray1[i].type == "text" || tArray1[i].type == "password"){
		    myArray[myCount] = tArray1[i];
		    myCount++;
		  }// end if
    }// end for   
    for(var i=0; i<tArray2.length; i++){
		  myArray[myCount] = tArray2[i];
		  myCount++;
    }// end for
    elementCountInput      = tArray1.length;
    elementCountTextarea   = tArray2.length;
    elementArrayTextFields = myArray;
  }// end if/else
  
  return myArray;
  
}// end getAllTextFields

function getAllSelects(){	

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("select");
  
  if(elementArraySelects != null && elementCountSelect == tArray1.length){
    myArray = elementArraySelects;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
		  myArray[myCount] = tArray1[i];
		  myCount++;
    }// end for
    elementCountSelect  = tArray1.length;
    elementArraySelects = myArray;
  }// end if/else
  
  return myArray;

}// end getAllSelects 

function getAllCheckboxes(){

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("input");
  
  if(elementArrayCheckboxes != null && elementCountInput == tArray1.length){
    myArray = elementArrayCheckboxes;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
	    if(tArray1[i].type == "checkbox"){
		    myArray[myCount] = tArray1[i];
		    myCount++;
	    }// end if
    }// end for
    elementCountInput      = tArray1.length;
    elementArrayCheckboxes = myArray;
  }// end if/else
	
	return myArray;
	
}// end getAllCheckboxes 

function getAllButtons(){

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("input");
  var tArray2 = document.getElementsByTagName("button");
  
  if(elementArrayButtons != null && elementCountInput == tArray1.length && elementCountButton == tArray2.length){
    myArray = elementArrayButtons;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
      if((tArray1[i].type == "button" || tArray1[i].type == "submit" || tArray1[i].type == "reset") && tArray1[i].className != "shortButton"){
		    myArray[myCount] = tArray1[i];
		    myCount++;
		  }// end if
    }// end for
    for(var i=0; i<tArray2.length; i++){
      if(tArray2[i].className != "shortButton"){
		    myArray[myCount] = tArray2[i];
		    myCount++;
		  }// end if
    }// end for
    elementCountInput   = tArray1.length;
    elementCountButton  = tArray2.length;
    elementArrayButtons = myArray;
  }// end if/else
  
  return myArray;

}// end getAllButtons

function getAllShortButtons(){

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("input");
  var tArray2 = document.getElementsByTagName("button");
  
  if(elementArrayShortButtons != null && elementCountInput == tArray1.length && elementCountButton == tArray2.length){
    myArray = elementArrayShortButtons;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
      if((tArray1[i].type == "button" || tArray1[i].type == "submit" || tArray1[i].type == "reset") && tArray1[i].className == "shortButton"){
		    myArray[myCount] = tArray1[i];
		    myCount++;
		  }// end if
    }// end for
    for(var i=0; i<tArray2.length; i++){
      if(tArray2[i].className == "shortButton"){
		    myArray[myCount] = tArray2[i];
		    myCount++;
		  }// end if
    }// end for
    elementCountInput        = tArray1.length;
    elementCountButton       = tArray2.length;
    elementArrayShortButtons = myArray;
  }// end if/else
    
  return myArray;

}// end getAllShortButtons

function getAllRadios(){

  var myArray = new Array();
  var tArray1 = document.getElementsByTagName("input");
  
  if(elementArrayRadios != null && elementCountInput == tArray1.length){
    myArray = elementArrayRadios;
  }
  else{
    var myCount = 0;
    for(var i=0; i<tArray1.length; i++){
      if(tArray1[i].type == "radio"){
		    myArray[myCount] = tArray1[i];
		    myCount++;
		  }// end if
    }// end for
    elementCountInput  = tArray1.length;
    elementArrayRadios = myArray;
  }// end if
    
  return myArray;

}// end getAllRadios
    

function tempDisableAllElements(){
  window.status = "Accessing Data...";/*
  tempDisableAllButtons();
  tempDisableAllShortButtons();
  tempDisableAllTextFields();
  tempDisableAllSelects();
  tempDisableAllCheckboxes();
  tempDisableAllLinks();
  tempDisableAllRadios();*/
}// end disableAllElements

function reEnableAllElements(){
  try{
    reEnableAllButtons();
  }
  catch(e){
    alert("Error reEnabling buttons: " + e.description + ".");
  }
  try{
    reEnableAllShortButtons();
  }
  catch(e){
    alert("Error reEnabling shortbuttons: " + e.description + ".");
  }
  try{
    reEnableAllTextFields();
  }
  catch(e){
    alert("Error reEnabling textfields: " + e.description + ".");
  }
  try{
    reEnableAllSelects();
  }
  catch(e){
    alert("Error reEnabling selects: " + e.description + ".");
  }
  try{
    reEnableAllCheckboxes();
  }
  catch(e){
    alert("Error reEnabling checkboxes: " + e.description + ".");
  }
  try{
    reEnableAllLinks();
  }
  catch(e){
    alert("Error reEnabling links: " + e.description + ".");
  }
  try{
    reEnableAllRadios();
  }
  catch(e){
    alert("Error reEnabling radios: " + e.description + ".");
  }
  window.status = "";
}// end reEnableAllElements
