// ## ADRIEL SYSTEM JavaScript LIBRARY ##
// <script src="http://4umi.com/web/javascript/array.js" type="text/javascript"></script >

// MAKE THE indexOf METHOD WORK IN Internet Explorer
// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};


function windowPop(url, popupName, width, height, left, top) {
	popWindow = window.open(url, popupName, ["width="+width+", height="+height+", left="+left+", top="+top+", scrollbars=yes, menubar=no, location=no, status=no, resizable=yes"]);
	popWindow.top.focus();
	}


function loadInParent(url, closeSelf) {
	self.opener.location = url;
	if (closeSelf) self.close();
	}


function closeBox(divID) {
	divID.style.display = 'none';
	}


function toggleBoxSize(divID, buttonID) {
	toggleLayer(divID);
	button = document.getElementById(buttonID);
	if (button.innerHTML == "minimize") {
		button.innerHTML = "maximize";
	} else if (button.innerHTML == "maximize") {
		button.innerHTML = "minimize";
	} // END if
}


function toggleButton(myForm, myButton) {
	var form = document.forms[myForm];
	var formName = form.name;
	var button = form.elements[myButton];
	var buttonStatus = button.disabled;
//	alert('buttonStatus is '+buttonStatus);
	if (buttonStatus == true) { //THE BUTTON IS DISABLED, LET'S ENABLE IT
		button.disabled = "";
	} else { // THE BUTTON IS ENABLED, LET'S DISABLE IT
		button.disabled = "true";
	} // END if
}


function toggleContent(objectID, content1, content2) {
	object = document.getElementById(objectID);
	if (object.innerHTML == content1) {
		object.innerHTML = content2;
	} else if (object.innerHTML == content2) {
		object.innerHTML = content1;
	} // END if
} // END toggleContent() FUNCTION


function toggleFormElement(formName, elementName, elementType) {
	element = document.forms[formName].elements[elementName];
	if (!elementType) elementType = "checkbox";

	switch (elementType) {
	case "checkbox":
		if (element.checked == false) {
			element.checked = true;
		} else if (element.checked == true) {
			element.checked = false;
		} // END if STATEMENT
	break;
	} // END elementType SWITCH
}


function toggleLayer(whichLayer) {
//	alert("whichLayer is " +whichLayer+ " Ok?");
	var elem, vis;
	if(document.getElementById) // this is the way the standards work
	  elem = document.getElementById(whichLayer);
	vis = elem.style;
// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	  vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
} // END toggleLayer() FUNCTION


function switchLayer(newLayerID, currentLayerID, layerHolderID) {
	// VARS: newLayer should be an ID name
	// VARS: currentLayer should be an ID name
	// VARS: layerHolder should be an ID name
	// FIRST DETERMINE THE CURRENT LAYER
	if (layerHolderID == null || layerHolderID == "") layerHolderID = "layerHolder";
  var layerHolder = document.getElementById(layerHolderID);
  if (currentLayerID == null || currentLayerID == "") { // THE CURRENT LAYER WASN'T SPECIFIED, SO LOOK FOR IT IN THE LAYER HOLDER
	var currentLayerID = layerHolder.value;
  }

  if(document.getElementById) // this is the way the standards work
    var layerToHide = document.getElementById(currentLayerID);
    var visCurrent = layerToHide.style;
    visCurrent.display = 'none';

  // NOW SHOW THE NEW ONE IN ITS PLACE
  var layerToShow, visNew;
  if(document.getElementById) // this is the way the standards work
    layerToShow = document.getElementById(newLayerID);
  visNew = layerToShow.style;
  visNew.display = 'block';
  
  // FINALLY, UPDATE THE layerHolder ELEMENT TO STORE THE VALUE OF THE NEW CURRENT LAYER
  layerHolder.value = newLayerID;
} // END switchLayer() FUNCTION


function switchTab(newLayerID, oldLayerID, layerHolderID, triggerTab) {
	// VARS: newLayerID should be an ID name
	// VARS: oldLayerID should be an ID name
	// VARS: layerHolderID should be null, or an ID name
	// VARS: triggerTab should be a DOM element called by "this"

	// SET THE TAB COLORS
	if (oldLayerID == "") {
		myLayerHolder = document.getElementById("layerHolder");
		oldLayerID = myLayerHolder.value;
	}
	oldTab = document.getElementById("tab "+oldLayerID);
	oldTab.className = "stdTab";
	triggerTab.className = "stdTab tabCurrent";

	// FEED THE INFO DIRECTLY TO THE switchLayer() FUNCTION
	switchLayer(newLayerID, oldLayerID, layerHolderID);
	
	// NOW SET THE SESSION VARIABLE FOR THE CURRENT LAYER
	callAHAH("adrielQuickActions.php?action=setSessionVar&varName=currentLayer&varValue="+newLayerID, "currentLayerHolder", "", "ERROR: Could not use callAHAH.");

} // END switchTab() FUNCTION


function updateTab(tab, mouseStatus) {
	// VARS: tab is a DOM object called by "this"
	// VARS: mouseStatus is a keyword for where the mouse is
	
	myLayerHolder = document.getElementById("layerHolder");
	currentLayerID = myLayerHolder.value;
	
	if (mouseStatus == "over") {
		tab.className='stdTab tabHover';
	} else if (mouseStatus == "off") {		
		if (tab.id == "tab "+currentLayerID) {
			tab.className='stdTab tabCurrent';
		} else {
			tab.className='stdTab';
		}
	} else if (mouseStatus == "click") {
		tab.className='stdTab tabCurrent';
	} else {
		tab.style.backgroundColor='#FF0000';
	} // END if STATEMENT FOR mouseStatus
	
	// RUN THE fixer() FUNCTION TO PREVENT SOME ELEMENTS FROM DISAPPEARING.  *weird!*
	fixer();
} // END updateTab() FUNCTION


function setOpacity(elementID, opacity) {
	// VARS: elementID should be an ID
	// VARS: opacity should be a whole number
	element = document.getElementById(elementID);
	
	// DETERMINE WHAT TO DO, BASED ON THE BROWSER
	if (navigator.appName.indexOf("Netscape")!=-1 &&parseInt(navigator.appVersion)>=5) {
		element.style.MozOpacity = opacity/100; // MOZILLA PROPERTY
	} else if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4) {
		element.filters.alpha.opacity = opacity; // IE PROPERT
	} else {
		elementStyle.opacity = opacity; // GENERAL PROPERTY
	} // END if STATEMENT FOR navigator
} // END setOpacity() FUNCTION


function fixer() {
	// SOMEHOW, THIS FUNCTION FIXES THE DISAPPEARING PROBLEM IN I.E. CAUSED BY THE UPDATE FUNCTIONS
	if (document.getElementById("fixer") != null) {
		document.getElementById("fixer").className="";
	} // END if
} // END fixer() FUNCTION


function updateButton(button, mouseStatus, additionalClass) {
	// THIS FUNCTION UPDATES A BUTTON TO LOOK NICE WHEN YOU DO SOMETHING WITH YOUR MOUSE
	// VARS:button is a DOM object called by "this"
	// VARS: mouseStatus is a keyword for where the mouse is
	if (mouseStatus == "over") {
		if (additionalClass != null) {
			button.className='stdButton buttonHover '+additionalClass;
		} else {
			button.className='stdButton buttonHover';
		} // END if
	} else if (mouseStatus == "off") {
		if (additionalClass != null) {
			button.className='stdButton '+additionalClass;
		} else {
			button.className='stdButton';
		} // END if
	} else {
		button.style.backgroundColor='#FF0000';
	} // END if STATEMENT FOR mouseStatus
} // END updateButton() FUNCTION


function updateMainMenuButton(button, mouseStatus) {
	// VARS:button is a DOM object called by "this"
	// VARS: mouseStatus is a keyword for where the mouse is
	if (mouseStatus == "over") {
		button.className='mainMenuButton buttonHover';
	} else if (mouseStatus == "off") {
		button.className='mainMenuButton';
	} else {
		button.style.backgroundColor='#FF0000';
	} // END if STATEMENT FOR mouseStatus
} // END updateMainMenuButton() FUNCTION


function saveFormChanges(containerDivID, formName) {
	containerDiv = document.getElementById(containerDivID);
	containerDiv.style.backgroundColor = "#AAFFAA";
} // END saveFormChanges() FUNCTION


function addElement(containerID, newElementID, innerContent, display, position, width, height, border, backgroundColor, color) {
  var containerDiv = document.getElementById(containerID);
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  
  var newdiv = document.createElement('div');
  if (newElementID == null || newElementID == '') {
		var divID = 'newdiv'+num;
  } else {
	  var divID = newElementID;
  } // END if
  newdiv.id = divID;
  containerDiv.appendChild(newdiv);
  
  // SET OUR STYLE ELEMENTS
  newdivStyle = newdiv.style;
  newdivStyle.display = display;
  newdivStyle.position = position;
  newdivStyle.width = width;
  newdivStyle.height = height;
  newdivStyle.border = border;
  newdivStyle.backgroundColor = backgroundColor;
  newdivStyle.color = color;

  if (innerContent == undefined) {
  	newdiv.innerHTML = divID+" <a href='#' onClick='removeElement(this.parentNode)'><b>[-]</b></a>";
	} else {
  newdiv.innerHTML = innerContent;
  } // END if
}


function removeElement(referringDiv) {
	containerDiv = referringDiv.parentNode;
	containerDiv.removeChild(referringDiv);
}


// Function to Strip Whitespace From a String:
function strip_spaces(mystr) {
  var newstring = "";
  if (mystr.indexOf(' ') != -1) {
	string = mystr.split(' ');
    for (var i=0, length=string.length; i<length; i++) {
		newstring += string[i];
    } // END for
    return newstring;
  } else { return mystr; } // END if
} // END strip_spaces FUNCTION


function matchHeight(targetClass) {
	findTarget = new RegExp(targetClass);
     var divs,contDivs,maxHeight,divHeight,d;

     // get all <div> elements in the document
     divs=document.getElementsByTagName('div');
     contDivs=[];

     // initialize maximum height value
     maxHeight=0;

     // iterate over all <div> elements in the document
     for(var i=0;i<divs.length;i++){
          // make collection with <div> elements with class attribute from var 'targetClass'
          if(findTarget.test(divs[i].className)){
                d=divs[i];
                contDivs[contDivs.length]=d;

                // determine height for <div> element
                if (d.offsetHeight) {
                     divHeight=d.offsetHeight;
                } else if(d.style.pixelHeight){
                     divHeight=d.style.pixelHeight;
                }

                // calculate maximum height
                maxHeight=Math.max(maxHeight,divHeight);
          }
     }

     // assign maximum height value to all of 'targetClass' <div> elements
     for(var i=0;i<contDivs.length;i++){
          contDivs[i].style.height=maxHeight;
     }
}




// MORE ADVANCED FUNCTIONS FOR SPECIFIC USES
// ####################################################################
// ADRIEL CONTENT MODIFIERS
function contentOptions(contentAction, containerDivID, tableName, myIDfield, myIDvalue, columnName, columnValue, whereConditions, orderBy) {	 
	var modifyBox = "<form action='adrielMail-subscriptions.php' method='POST'>"
	 + "<input type='text' name='" + columnName + "' value='" + columnValue + "'>"
	 + "<input type='hidden' name='columnName' value='" + columnName + "'>"
	 + "<input type='hidden' name='tableName' value='" + tableName + "'>"
	 + "<input type='hidden' name='myIDfield' value='" + myIDfield + "'>"
	 + "<input type='hidden' name='myIDvalue' value='" + myIDvalue + "'>"
	 + "<input type='hidden' name='action' value='update_info'>"
	 + "<input type='hidden' name='whereConditions' value='" + whereConditions + "'>"
	 + "<input type='hidden' name='orderBy' value='" + orderBy + "'>"
	 + "<input type='submit' value='update'>"
	 + "<a href='javascript:closeBox(" + containerDivID + ")'><b>cancel</b></a></form>";

	var deleteBox = "<form action='adrielMail-subscriptions.php' method='POST'>"
	 + "<div class='headline2' align='center'>ARE YOU SURE YOU WANT TO DELETE THIS CUSTOMER?<br>"
	 + "<input type='hidden' name='tableName' value='" + tableName + "'>"
	 + "<input type='hidden' name='myIDfield' value='" + myIDfield + "'>"
	 + "<input type='hidden' name='myIDvalue' value='" + myIDvalue + "'>"
	 + "<input type='hidden' name='action' value='delete_customer'>"
	 + "<input type='hidden' name='whereConditions' value='" + whereConditions + "'>"
	 + "<input type='hidden' name='orderBy' value='" + orderBy + "'>"
	 + "<input type='button' onClick='javascript:closeBox(" + containerDivID + ");' value='NO, keep them'> &nbsp; &nbsp; "
	 + "<input type='submit' value='YES, delete them!'>"
	 + "</form></div>";

	 var newdiv = document.createElement('div');
	 var divIdName = contentAction + '_box';
	 newdiv.setAttribute('id', divIdName);

	 if (contentAction == "MODIFY") {
	 newdiv.innerHTML = modifyBox;
	 } else if (contentAction == "DELETE") {
	 newdiv.innerHTML = deleteBox;
	 } else {
	 newdiv.innerHTML = 'Uh oh... there was a problem...';
	 	}
	 
	 var containerDiv = document.getElementById(containerDivID);
	 containerDiv.appendChild(newdiv);
	 containerDiv.style.display = 'block';
	}

// ####################################################################
// CHECKOUT AND STORE FUNCTIONS
function addToCart(formName) {
	document.forms[formName].submit(); 
	}

function addToCartPopup(formName) {
	windowPop("", "myCartWindow", 560, 400, 50, 100)
    var a = window.setTimeout("document." +formName+ ".submit();",500); 
	}

function fillAllForms (allFormValues) {
	document.ContactInfo_form.bill_Firstname.value = allFormValues['bill_Firstname'];
//	document.ContactInfo_form.bill_Middlename.value = allFormValues['bill_Middlename'];
	document.ContactInfo_form.bill_Lastname.value = allFormValues['bill_Lastname'];
	
	document.ContactInfo_form.bill_phoneAreaCode1.value = allFormValues['bill_phoneAreaCode1'];
	document.ContactInfo_form.bill_phoneLocalA1.value = allFormValues['bill_phoneLocalA1'];
	document.ContactInfo_form.bill_phoneLocalB1.value = allFormValues['bill_phoneLocalB1'];
	document.ContactInfo_form.bill_phoneExt1.value = allFormValues['bill_phoneExt1'];
	document.ContactInfo_form.bill_phoneTypeID1.selectedIndex = allFormValues['bill_phoneTypeID1'];
	
	document.ContactInfo_form.bill_phoneAreaCode2.value = allFormValues['bill_phoneAreaCode2'];
	document.ContactInfo_form.bill_phoneLocalA2.value = allFormValues['bill_phoneLocalA2'];
	document.ContactInfo_form.bill_phoneLocalB2.value = allFormValues['bill_phoneLocalB2'];
	document.ContactInfo_form.bill_phoneExt2.value = allFormValues['bill_phoneExt2'];
	document.ContactInfo_form.bill_phoneTypeID2.selectedIndex = allFormValues['bill_phoneTypeID2'];
	
	document.ContactInfo_form.bill_phoneAreaCode3.value = allFormValues['bill_phoneAreaCode3'];
	document.ContactInfo_form.bill_phoneLocalA3.value = allFormValues['bill_phoneLocalA3'];
	document.ContactInfo_form.bill_phoneLocalB3.value = allFormValues['bill_phoneLocalB3'];
	document.ContactInfo_form.bill_phoneTypeID3.selectedIndex = allFormValues['bill_phoneTypeID3'];
	
	document.ContactInfo_form.bill_Email1.value = allFormValues['bill_Email1'];
	document.ContactInfo_form.bill_Email1confirm.value = allFormValues['bill_Email1confirm'];
	document.ContactInfo_form.bill_Email2.value = allFormValues['bill_Email2'];
	
	document.ContactInfo_form.bill_Address1.value = allFormValues['bill_Address1'];
	document.ContactInfo_form.bill_Address2.value = allFormValues['bill_Address2'];
	document.ContactInfo_form.bill_City.value = allFormValues['bill_City'];
	document.ContactInfo_form.bill_State.value = allFormValues['bill_State'];			
	document.ContactInfo_form.bill_Country.selectedIndex = allFormValues['bill_Country'];
	document.ContactInfo_form.bill_Postal_Code.value = allFormValues['bill_Postal_Code'];
	
	// SHIP INFO FORMS
	document.ContactInfo_form.ship_Firstname.value = allFormValues['ship_Firstname'];
//	document.ContactInfo_form.ship_Middlename.value = allFormValues['ship_Middlename'];
	document.ContactInfo_form.ship_Lastname.value = allFormValues['ship_Lastname'];
	
	document.ContactInfo_form.ship_phoneAreaCode1.value = allFormValues['ship_phoneAreaCode1'];
	document.ContactInfo_form.ship_phoneLocalA1.value = allFormValues['ship_phoneLocalA1'];
	document.ContactInfo_form.ship_phoneLocalB1.value = allFormValues['ship_phoneLocalB1'];
	document.ContactInfo_form.ship_phoneExt1.value = allFormValues['ship_phoneExt1'];
	document.ContactInfo_form.ship_phoneTypeID1.selectedIndex = allFormValues['ship_phoneTypeID1'];
	
	document.ContactInfo_form.ship_phoneAreaCode2.value = allFormValues['ship_phoneAreaCode2'];
	document.ContactInfo_form.ship_phoneLocalA2.value = allFormValues['ship_phoneLocalA2'];
	document.ContactInfo_form.ship_phoneLocalB2.value = allFormValues['ship_phoneLocalB2'];
	document.ContactInfo_form.ship_phoneExt2.value = allFormValues['ship_phoneExt2'];
	document.ContactInfo_form.ship_phoneTypeID2.selectedIndex = allFormValues['ship_phoneTypeID2'];
	
	document.ContactInfo_form.ship_phoneAreaCode3.value = allFormValues['ship_phoneAreaCode3'];
	document.ContactInfo_form.ship_phoneLocalA3.value = allFormValues['ship_phoneLocalA3'];
	document.ContactInfo_form.ship_phoneLocalB3.value = allFormValues['ship_phoneLocalB3'];
	document.ContactInfo_form.ship_phoneTypeID3.selectedIndex = allFormValues['ship_phoneTypeID3'];
	
	document.ContactInfo_form.ship_Email1.value = allFormValues['ship_Email1'];
	document.ContactInfo_form.ship_Email1confirm.value = allFormValues['ship_Email1confirm'];
	document.ContactInfo_form.ship_Email2.value = allFormValues['ship_Email2'];
	
	document.ContactInfo_form.ship_Address1.value = allFormValues['ship_Address1'];
	document.ContactInfo_form.ship_Address2.value = allFormValues['ship_Address2'];
	document.ContactInfo_form.ship_City.value = allFormValues['ship_City'];
	document.ContactInfo_form.ship_State.value = allFormValues['ship_State'];			
	document.ContactInfo_form.ship_Country.selectedIndex = allFormValues['ship_Country'];
	document.ContactInfo_form.ship_Postal_Code.value = allFormValues['ship_Postal_Code'];
} // END fillAllForms() FUNCTION

function fillShipForms() {
	document.ContactInfo_form.ship_Firstname.value = document.ContactInfo_form.bill_Firstname.value;
//	document.ContactInfo_form.ship_Middlename.value = document.ContactInfo_form.bill_Middlename.value;
	document.ContactInfo_form.ship_Lastname.value = document.ContactInfo_form.bill_Lastname.value;
	
	document.ContactInfo_form.ship_phoneAreaCode1.value = document.ContactInfo_form.bill_phoneAreaCode1.value;
	document.ContactInfo_form.ship_phoneLocalA1.value = document.ContactInfo_form.bill_phoneLocalA1.value;
	document.ContactInfo_form.ship_phoneLocalB1.value = document.ContactInfo_form.bill_phoneLocalB1.value;
	document.ContactInfo_form.ship_phoneExt1.value = document.ContactInfo_form.bill_phoneExt1.value;
	document.ContactInfo_form.ship_phoneTypeID1.selectedIndex = document.ContactInfo_form.bill_phoneTypeID1.selectedIndex;
	
	document.ContactInfo_form.ship_phoneAreaCode2.value = document.ContactInfo_form.bill_phoneAreaCode2.value;
	document.ContactInfo_form.ship_phoneLocalA2.value = document.ContactInfo_form.bill_phoneLocalA2.value;
	document.ContactInfo_form.ship_phoneLocalB2.value = document.ContactInfo_form.bill_phoneLocalB2.value;
	document.ContactInfo_form.ship_phoneExt2.value = document.ContactInfo_form.bill_phoneExt2.value;
	document.ContactInfo_form.ship_phoneTypeID2.selectedIndex = document.ContactInfo_form.bill_phoneTypeID2.selectedIndex;
	
	document.ContactInfo_form.ship_phoneAreaCode3.value = document.ContactInfo_form.bill_phoneAreaCode3.value;
	document.ContactInfo_form.ship_phoneLocalA3.value = document.ContactInfo_form.bill_phoneLocalA3.value;
	document.ContactInfo_form.ship_phoneLocalB3.value = document.ContactInfo_form.bill_phoneLocalB3.value;
	document.ContactInfo_form.ship_phoneTypeID3.selectedIndex = document.ContactInfo_form.bill_phoneTypeID3.selectedIndex;
	
	document.ContactInfo_form.ship_Email1.value = document.ContactInfo_form.bill_Email1.value;
	document.ContactInfo_form.ship_Email2.value = document.ContactInfo_form.bill_Email2.value;
	
	document.ContactInfo_form.ship_Address1.value = document.ContactInfo_form.bill_Address1.value;
	document.ContactInfo_form.ship_Address2.value = document.ContactInfo_form.bill_Address2.value;
	document.ContactInfo_form.ship_City.value = document.ContactInfo_form.bill_City.value;
	document.ContactInfo_form.ship_State.value = document.ContactInfo_form.bill_State.value;			
	document.ContactInfo_form.ship_Country.selectedIndex = document.ContactInfo_form.bill_Country.selectedIndex;
	document.ContactInfo_form.ship_Postal_Code.value = document.ContactInfo_form.bill_Postal_Code.value;
}

function clearBillForms() {
	document.ContactInfo_form.bill_Firstname.value = '';
//	document.ContactInfo_form.bill_Middlename.value = '';
	document.ContactInfo_form.bill_Lastname.value = '';
	
	document.ContactInfo_form.bill_phoneAreaCode1.value = '';
	document.ContactInfo_form.bill_phoneLocalA1.value = '';
	document.ContactInfo_form.bill_phoneLocalB1.value = '';
	document.ContactInfo_form.bill_phoneExt1.value = '';
	document.ContactInfo_form.bill_phoneTypeID1.selectedIndex = 0;
	
	document.ContactInfo_form.bill_phoneAreaCode2.value = '';
	document.ContactInfo_form.bill_phoneLocalA2.value = '';
	document.ContactInfo_form.bill_phoneLocalB2.value = '';
	document.ContactInfo_form.bill_phoneExt2.value = '';
	document.ContactInfo_form.bill_phoneTypeID2.selectedIndex = 0;
	
	document.ContactInfo_form.bill_phoneAreaCode3.value = '';
	document.ContactInfo_form.bill_phoneLocalA3.value = '';
	document.ContactInfo_form.bill_phoneLocalB3.value = '';
	document.ContactInfo_form.bill_phoneTypeID3.selectedIndex = 0;
	
	document.ContactInfo_form.bill_Email1.value = '';
	document.ContactInfo_form.bill_Email1confirm.value = '';
	document.ContactInfo_form.bill_Email2.value = '';
	
	document.ContactInfo_form.bill_Address1.value = '';
	document.ContactInfo_form.bill_Address2.value = '';
	document.ContactInfo_form.bill_City.value = '';
	document.ContactInfo_form.bill_State.value = '';			
	document.ContactInfo_form.bill_Country.selectedIndex = 223;
	document.ContactInfo_form.bill_Postal_Code.value = '';
} // END clearBillForms FUNCTION
	
	
function clearShipForms() {
	document.ContactInfo_form.ship_Firstname.value = '';
//	document.ContactInfo_form.ship_Middlename.value = '';
	document.ContactInfo_form.ship_Lastname.value = '';
	
	document.ContactInfo_form.ship_phoneAreaCode1.value = '';
	document.ContactInfo_form.ship_phoneLocalA1.value = '';
	document.ContactInfo_form.ship_phoneLocalB1.value = '';
	document.ContactInfo_form.ship_phoneExt1.value = '';
	document.ContactInfo_form.ship_phoneTypeID1.selectedIndex = 0;
	
	document.ContactInfo_form.ship_phoneAreaCode2.value = '';
	document.ContactInfo_form.ship_phoneLocalA2.value = '';
	document.ContactInfo_form.ship_phoneLocalB2.value = '';
	document.ContactInfo_form.ship_phoneExt2.value = '';
	document.ContactInfo_form.ship_phoneTypeID2.selectedIndex = 0;
	
	document.ContactInfo_form.ship_phoneAreaCode3.value = '';
	document.ContactInfo_form.ship_phoneLocalA3.value = '';
	document.ContactInfo_form.ship_phoneLocalB3.value = '';
	document.ContactInfo_form.ship_phoneTypeID3.selectedIndex = 0;
	
	document.ContactInfo_form.ship_Email1.value = '';
	document.ContactInfo_form.ship_Email2.value = '';
	
	document.ContactInfo_form.ship_Address1.value = '';
	document.ContactInfo_form.ship_Address2.value = '';
	document.ContactInfo_form.ship_City.value = '';
	document.ContactInfo_form.ship_State.value = '';			
	document.ContactInfo_form.ship_Country.selectedIndex = 223;
	document.ContactInfo_form.ship_Postal_Code.value = '';

	document.ContactInfo_form.sameAsBilling.checked = false;
} // END clearShipForms() FUNCTION
		
		
function fillShipFormsChecker() {
	var checkboxChecked = document.ContactInfo_form.sameAsBilling.checked;
	if (checkboxChecked == false) {
		clearShipForms();
		} else if (checkboxChecked == true) {
		fillShipForms();
	} // END if STATEMENT
} // END fillShipFormsChecker() FUNCTION


function uncheckSameAsBilling() {
	document.ContactInfo_form.sameAsBilling.checked = false;
} // END uncheckSameAsBilling() FUNCTION


function setOptionMenuIndex(formName, menuName, indexValue) {
	// FIRST, INITIALIZE THE FORM AND ELEMENT VARIABLES SO WE HAVE SOMETHING TO WORK WITH
	//	document.forms[formName] = new Object();
	//	document.forms[formName].elements[menuName] = new Object();
	var myForm = document.forms[formName];
	var myMenu = document.forms[formName].elements[menuName];
	
	// NEXT , SEE IF THIS IS A DROP-DOWN BOX OR A RADIO BUTTON SET
	if (myMenu.length && !myMenu.type) {
		// THIS IS A RADIO SET, WHICH IS A NODE LIST
		newIndex = indexValue-1;
		myMenu[newIndex].checked = true;
	} else {
		// THIS MUST BE A SELECT LIST.  DETERMINE IF THE INDEX IS A STRING OR NUMBER	
		if (isNaN(indexValue)) {
			// GET THE NUMERICAL INDEX FOR THE GIVEN STRING
			var myOptions = [];
			var allOptions = document.forms[formName].elements[menuName].options;
			var allOptionsCount = allOptions.length;
			var i = 0;
				while (i < allOptionsCount) {
					myOptions[i] = allOptions[i].value;
					i++;
				} // END while LOOP
			var newIndexValue = myOptions.indexOf(indexValue);
			
		} else {
			if (indexValue != 0) { 
				newIndexValue = indexValue;
			} else { 
				newIndexValue = indexValue;
			} // END indexValue if CHECKER
		} // END isNaN CHECKER
	
		// FINALLY, SET THE NUMERICAL INDEX TO THE ONE WE SUPPLIED
		myMenu.selectedIndex = newIndexValue;
	} // END if STATEMENT FOR myMenu.type
} // END setOptionMenuIndex FUNCTION


function updatePhoneNickname(formName, selectObj, n) {
	// VARS: formName is simply the name of the form
	// VARS: is a SELECT object returned by the "this" keyword
	// VARS: n is the number of which phone number this is (1-4)
	var myForm = document.forms[formName];
	var currentIndex = selectObj.selectedIndex;
	var currentID = selectObj.options[currentIndex].value;
	var myNickname = "phoneNickname"+n;
	var nicknameField = myForm.elements[myNickname];
	switch (currentID) {
		case "1": nicknameField.value = "Home"; break;
		case "2": nicknameField.value = "Mobile"; break;
		case "3": nicknameField.value = "Work"; break;
		case "4": nicknameField.value = "Fax"; break;
		case "5": nicknameField.value = "Other"; break;
	} // END indexValue switch
//	alert("field is "+nicknameField.name+" and value is "+nicknameField.value);
}


function moveFocus(myForm) {
	if (myForm.elements["focusMover"].value != "") { // THIS VALUE WAS DEFINED ELSEWHERE, BUT AT LEAST IT'S THERE!;
		focusField = myForm.elements["focusMover"].value;
		myForm.elements[focusField].focus();
	} // END if STATEMENT
} // END moveFocus SWITCH


function compareFormFields(myForm, field1name, field2name, errorMsg) {
	var field1 = myForm.elements[field1name].value;
	var field2 = myForm.elements[field2name].value;
	
	if (myForm.elements["focusMover"].value == "") { // THE focusMover IS BLANK, SO COMPARE THE TWO FIELDS
		if (field1 != field2) {
			if (typeof errorMsg == "undefined" || errorMsg == "") {
				errorMsg = "Please make sure both fields match.";
			}
			alert(errorMsg);
			myForm.elements[field1name].focus();
		} // END if
	} // END if
}


function copyFormFieldValue(formName, fromField, toFieldName) {
	formName.elements[toFieldName].value = fromField.value;
}


function checkFormField(myForm, myField) {
	var fieldName = myField.name;
	var myDiv = document.getElementById(fieldName);
	var divClass = myDiv.className;
//	var myField = document.forms[formName].elements[fieldName];
	var fieldValue = myField.value;
	var previewButton = myForm.elements["previewButton"];
	
	if (fieldValue == "") { // THIS IS BLANK... IS IT REQUIRED?
		if (divClass == "checkoutRequired" || divClass == "checkoutRequiredSuccess") {
			myDiv.className = "checkoutRequiredError";
			previewButton.disabled = "true";
			previewButton.id = fieldName;
//			myField.focus();
		} // END divClass if STATEMENT
	} else { // THIS IS NOT BLANK... WHAT CLASS DO WE ASSIGN TO THE LABEL?
		if (divClass == "checkoutRequired" || divClass == "checkoutRequiredError") {
			myDiv.className = "checkoutRequiredSuccess";
		} // END divClass if STATEMENT
	} // END if
	if (previewButton.id != "") { // SOMETHING WAS TRIGGERED EARLIER AS AN INCOMPLETE FIELD, CHECK IT NOW
		var problemField = document.getElementById(previewButton.id);
		if (problemField.className != "checkoutRequiredError") {
			previewButton.id = "";
			previewButton.disabled = "";
		} // END problemField if
	} // END previewButton.id if
}


function checkDateFormat(myForm, myField) {
	var fieldValue = myField.value;
	var fieldLength = fieldValue.length;
	// FIRST CHECK THE LENGTH... IT SHOULD BE 4 (MMYY)
	if (fieldLength == 4) { // THE LENGTH IS CORRECT, NOW CHECK THE FORMAT
		if (fieldValue.indexOf("/") != -1) { 
			// THEY INCLUDED A SLASH, TELL THEM NO!
			alert("Please do not include the front-slash. The date should be formatted like this: MMYY");
			myField.focus();
		} // END "/" if
	} else {
		alert("Please make sure your expiration date is formatted like this: MMYY");
		myField.focus();
	} // END if
} // END checkDateFormat FUNCTION

/*
function checkFieldTypeAndLength(myForm, myField, desiredType=string, desiredLengthfieldToReference) {
	// 1. FORMAT THE FIELD WE'RE CHECKING BY STRIPPING THE SPACES, THEN GET THE LENGTH
	fieldValue = myField.value;
	if (isNaN(fieldValue) == true) { // THIS IS A STRING
	
	
	var checkField = strip_spaces(document.forms[formName].elements[fieldToCheck].value);	
	document.forms[formName].elements[fieldToCheck].value = checkField;
	var contentLength = document.forms[formName].elements[fieldToCheck].value.length;
	var desiredLength; // WE'LL USE THIS IN A MINUTE
	
	// 2. CREATE THE VARIABLE FOR THE REFERENCE FIELD AND USE THAT TO ASSIGN A VALUE TO desiredLength
	var referenceField = document.forms[formName].elements[fieldToReference].value;
	switch (referenceField) {
		case "VISA":
			desiredLength = 16;
		break;
		case "Master Card":
			desiredLength = 16;
		break;
		case "Discover":
			desiredLength = 16;
		break;
		case "AMEX":
			desiredLength = 15;
		break;
	} // END referenceField SWITCH
		
	// 3. NOW COMPARE contentLength TO desiredLength TO MAKE SURE THE CARD LENGTH IS RIGHT FOR THIS CARD TYPE
	if (contentLength != desiredLength) { // THIS CARD IS NOT THE RIGHT LENGTH, GIVE THEM AN ERROR
		alert("Please make sure the card number has the correct number of digits for your card type.");
		document.forms[formName].elements[fieldToCheck].focus();
		document.forms[formName].elements["focusMover"].value = fieldToCheck;
	} else { // THIS CARD IS THE RIGHT LENGTH, SO MOVE ON TO FURTHER CHECKS
		return Mod10(checkField);
	} // END contentLength if STATEMENT
} // END checkCardDigits FUNCTION
*/

function checkCardDigits(myForm, fieldToCheck, fieldToReference) {
	// 1. FORMAT THE FIELD WE'RE CHECKING BY STRIPPING THE SPACES, THEN GET THE LENGTH
//	var checkField = strip_spaces(myForm.elements[fieldToCheck].value);	
	myForm.elements[fieldToCheck].value = checkField;
	var contentLength = myForm.elements[fieldToCheck].value.length;
	var desiredLength; // WE'LL USE THIS IN A MINUTE
	
	// 2. CREATE THE VARIABLE FOR THE REFERENCE FIELD AND USE THAT TO ASSIGN A VALUE TO desiredLength
	var referenceField = myForm.elements[fieldToReference].value;
	switch (referenceField) {
		case "VISA":
			desiredLength = 16;
		break;
		case "Master Card":
			desiredLength = 16;
		break;
		case "Discover":
			desiredLength = 16;
		break;
		case "AMEX":
			desiredLength = 15;
		break;
	} // END referenceField SWITCH
		
	// 3. NOW COMPARE contentLength TO desiredLength TO MAKE SURE THE CARD LENGTH IS RIGHT FOR THIS CARD TYPE
	if (contentLength != desiredLength) { // THIS CARD IS NOT THE RIGHT LENGTH, GIVE THEM AN ERROR
		alert("Please make sure the card number has the correct number of digits for your card type.");
		myForm.elements[fieldToCheck].focus();
		myForm.elements["focusMover"].value = fieldToCheck;
	} else { // THIS CARD IS THE RIGHT LENGTH, SO MOVE ON TO FURTHER CHECKS
		return Mod10(checkField);
	} // END contentLength if STATEMENT
} // END checkCardDigits FUNCTION



function checkEmailFormat(input) {
//	var isEmail_re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
	if (input) {
	var isEmail_re = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
	result = String(input).search (isEmail_re);
	if (result == -1) {
		if (!String(input).match ("@")) {
			alert("Sorry, but you must include the \"@\" symbol in your e-mail address. (You entered \""+input+"\")");
		} else if (String(input).match (",")) {
			alert("Sorry, but commas are not allowed in e-mail addresses. (You entered \""+input+"\")");
		} else {
			alert("Sorry, but that doesn't look like a properly formed e-mail address. Please check it and try again. (You entered \""+input+"\")");
		} // END if STATEMENT FOR String input		
	} // END if STATEMENT FOR result
	} // END if STATEMENT FOR input
} // END checkValidEmail() FUNCTION


// #######################################################################
// BEGIN MOD 10 JAVASCRIPT CHECKER
// Found at The JavaScript Source!! http://javascript.internet.com
// Created by: David Leppek :: https://www.azcode.com/Mod10

function Mod10(ccNumb) {  // v2.0
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit
	
	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
	  temp = "" + sCCN.substring(j, j+1);
	  if (valid.indexOf(temp) == "-1"){bNum = false;}
	}
	
	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
	  /*alert("Not a Number");*/bResult = false;
	}
	
	// Determine if it is the proper length 
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
	  bResult = false;
	} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
	  if(len >= 15){  // 15 or 16 for Amex or V/MC
		for(var i=len;i>0;i--){  // LOOP throught the digits of the card
		  calc = parseInt(iCCN) % 10;  // right most digit
		  calc = parseInt(calc);  // assure it is an integer
		  iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
		  i--;  // decrement the count - move to the next digit in the card
		  iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
		  calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
		  calc = calc *2;                                 // multiply the digit by two
		  // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
		  // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
		  switch(calc){
			case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
			case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
			case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
			case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
			case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
			default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
		  }                                               
		iCCN = iCCN / 10;  // subtracts right most digit from ccNum
		iTotal += calc;  // running total of the card number as we loop
	  }  // END OF LOOP
	  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
		bResult = true;  // This IS (or could be) a valid credit card number.
	  } else {
		bResult = false;  // This could NOT be a valid credit card number
		}
	  }
	}
	// change alert to on-page display or other indication as needed.
	if(bResult) { // THIS IS A PROPERLY FORMED NUMBER
		document.forms["ContactInfo_form"].elements["focusMover"].value = "";
	}
	if(!bResult){ // THIS IS NOT A PROPERLY FORMED NUMBER
	  alert("We're sorry, but this is not a valid credit card number. Please try entering it again.");
	  document.forms["ContactInfo_form"].elements["focusMover"].value = "ccNum";
	}
	  return bResult; // Return the results
}
// END MOD 10 JAVASCRIPT CHECKER
// #######################################################################


function submitCheckoutForm(formName) {
	if (formName.elements["bill_Firstname"].value != "" && formName.elements["bill_Lastname"].value != "" && formName.elements["bill_Address1"].value != "" && formName.elements["bill_City"].value != "" && formName.elements["bill_State"].value != "" && formName.elements["bill_Postal_Code"].value != "" && formName.elements["bill_Country"].value != "" && formName.elements["bill_Email1"].value != "" && formName.elements["bill_phoneAreaCode1"].value != "" && formName.elements["bill_phoneLocalA1"].value != "" && formName.elements["bill_phoneLocalB1"].value != "" && formName.elements["ship_Firstname"].value != "" && formName.elements["ship_Lastname"].value != "" && formName.elements["ship_Address1"].value != "" && formName.elements["ship_City"].value != "" && formName.elements["ship_State"].value != "" && formName.elements["ship_Postal_Code"].value != "" && formName.elements["ship_Country"].value != "" && formName.elements["ship_phoneAreaCode1"].value != "" && formName.elements["ship_phoneLocalA1"].value != "" && formName.elements["ship_phoneLocalB1"].value != "" && formName.elements["ccType"].value != "" && formName.elements["ccNum"].value != "" && formName.elements["ccNumConfirm"].value != "" && formName.elements["ccExp"].value != "" && formName.elements["ccCode"].value != "" && formName.elements["ccName"].value != "") { // ALL THE REQUIRED FIELDS ARE FILLED IN, SO SUBMIT THE FORM!
	formName.submit();
	} else {
	alert("Uh oh, it looks like you haven't filled out all the required information. Please go back and check. Thanks!");
	} // END if
} // END submitCheckoutForm(formName) FUNCTION


function submitAdrielOrder() {
	document.changeContactInfo_form.goBack.disabled = "true";
	document.submitContactInfo_form.finalizeOrder.disabled = "true";
	document.submitContactInfo_form.submit();
}


function refreshPage(options) {
	var currentPage = unescape(window.location.pathname);
	if (options == undefined) {
		newPage = currentPage;
	} else {
		newPage = currentPage+'?'+options;
	}
	window.location.replace(newPage);
}



/********************************************************************************************/
/* AHAH functions by Phil Ballard                                                           */
/* This code is intended for study purposes.                                                */
/* You may use these functions as you wish, for commercial or non-commercial applications,  */
/* but please note that the author offers no guarantees to their usefulness, suitability or */
/* correctness, and accepts no liability for any losses caused by their use.                */
/********************************************************************************************/

function callAHAH(url, pageElement, callMessage, errorMessage) {
	// VARS: url IS THE URL OF THE PAGE TO DO THE WORK
	// VARS: pageElement IS THE ELEMENT ON THE CURRENT PAGE THAT RECEIVES THE OUTPUT
	// VARS: callMessage IS THE MESSAGE
	// VARS: errorMessage IS WHAT IT SHOWS IF THERE IS A PROBLEM
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseAHAH(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
  }

function responseAHAH(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
         } else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
         }
      }
  }

// END AHAH FUNCTIONS
// ####################################################################################
// ####################################################################################
// ##### SIMPLE AJAX FUNCTIONS BY PHILLIP GONZALES!!! #####

function makeXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		// branch for Firefox, IE7, Safari and other browsers
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// branch for IE6 and prior versions: use Windows ActiveX
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} // END if STATEMENT FOR object
	return req;
}

function openXMLFile(fileName) {
	req = makeXMLHttpRequest();
	
	
} // END openXMLFile() FUNCTION

function submitAJAXForm(formName, url, outputElementID, respFormat) {
	// VARS: formName is, well, the name of the form we're submitting!
	// VARS: formMethod is either "GET" or "POST"
	// VARS: url is the address of the page to process the request
	// outputElementID is the ID of a div element to show the status
	outputElement = document.getElementById(outputElementID);

//	if (async == null) { async = true; }
	// STEP 1: GET OUR FORM INFORMATION AND PROCESS IT FOR SENDING
	var formElements_arr = document.forms[formName].elements;
	method = document.forms[formName].method;
	if (method == "get" || method == "GET") {
		formMethod = "GET";
	} else if (method == "post" || method == "POST") {
		formMethod = "POST";
	} else {
		alert("ERROR: Invalid form method. The method returned: "+method);
	} // END if STATEMENT FOR method
	
	params = "formMethod="+formMethod+"&";
	for(i=0; i < formElements_arr.length; i++) {
		elementName = formElements_arr[i].name;
		elementType = formElements_arr[i].type;
		// CHECK IF THIS IS A RADIO BUTTON
		if (elementType == "radio") {
			// THIS IS A RADIO BUTTON! FIGURE OUT WHICH IS THE CHECKED ONE, AND MAKE THAT OUR VALUE
			if (formElements_arr[i].checked == true) elementValue = formElements_arr[i].value;
		} else {
			elementValue = formElements_arr[i].value;
		} // END if
		params += elementName+"="+elementValue+"&";
	} // END for LOOP
	params = params.substring(0, (params.length)-1);

	// STEP 2: INSTANTIATE A NEW req OBJECT AND OPEN OUR PAGE ("set the stage")
	req = makeXMLHttpRequest();

	if (req) { // MAKE SURE WE GOT THE req OBJECT PROPERLY
		
		req.open(formMethod, url); // SET THE STAGE FOR THE ACTION
		req.onreadystatechange = processReqChange; // WHEN WE GET A RESPONSE, WHO PROCESSES IT?

		// SET THE HEADERS SO WE KNOW THIS IS A FORM SUBMISSION
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		
		// STEP 3: SEND THE FORM!
		if (formMethod == "GET") {
			req.send(params); // TELL IT TO *GO*!
		} else if (formMethod == "POST") {
			req.send(params);
		} // END if STATEMENT FOR formMethod
		
		// STEP 4: PROCESS THE RESULTS
		if (req.readyState == 4) {
			alert("all done!");
		} // END if STATEMENT FOR req.readyState
	} else {
		alert("Uh oh, there was a problem!  No 'req' variable was available. Please contact Tech Support.");
	} // END if STATEMENT FOR req
} // END submitAJAXForm() FUNCTION


function processReqChange() {
	// THIS FUNCTION PROCESS WHAT HAPPENS EACH TIME A req OBJECT CHANGES STATE	
	// SET THE MESSAGE WE DISPLAY, DEPENDING ON THE readyState OF THE req OBJECT
	respFormat = "XML";

	switch (req.readyState) {
		case 1:
			outputElement.innerHTML = "loading.";
		break;
		case 2: 
			outputElement.innerHTML = "loading..";
		break;
		case 3: 
			outputElement.innerHTML = "loading...";
		break;
		case 4: 
			// MAKE SURE THE HTTP STATUS IS OK
			if (req.status == 200) {
				// PROCESS THE XML-FORMATTED RESULTS				
				if (respFormat == "TEXT") {
					// SEND THIS INFORMATION BACK AS STRAIGHT TEXT
					response = req.responseText;
					outputElement.innerHTML = response;
				} else {
					if (req.responseXML == null) {
						outputElement.innerHTML = "Sorry, there was a problem. Please contact Tech Support and send them these details...<br>\n" + req.responseText;
					} else {
						// GET THE DOCUMENT ELEMENT OF THIS AS XML
						response = req.responseXML.documentElement;
	//					walkXMLTree(response);
	
						if (response.firstChild.tagName == "parsererror") {
							if (response.firstChild.textContent) {
								errorText = response.firstChild.textContent;
							} else {
								errorText = "Sorry, there was an error, but we could not retrieve it.";
							} // end IF STATEMENT FOR response.firstChild.whatever
							responseText = req.responseText;
							outputElement.innerHTML = errorText+"<br><br>"+responseText;
						} else {
	/*						updateTag_arr = response.getElementsByTagName("updateResult");
							// DETERMINE WHERE WE SHOULD LOOK FOR OUR OUTPUT: innerText OR textContent
							var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
							if(!hasInnerText){
								updateResult = updateTag_arr[0].textContent;
							} else{
								updateResult = updateTag_arr[0].innerText;
							}
	*/
	
							resultList = response.getElementsByTagName("resultElement")[0].childNodes;
							var resultElement = "";
							for (i=0; i<resultList.length; i++) {
								resultElement += resultList[i].data;		
							} // END for LOOP FOR resultList
	
							outputElement.innerHTML = resultElement;
						} // END if STATEMENT FOR ERROR CHECKING
					} // END if STATEMENT FOR req.responseXML == null
				} // END if STATEMENT FOR respFormat
			} else {
				outputElement.innerHTML = "ERROR: "+req.statusText+" ("+req.status+")";
			} // END if
		break;
	} // END switch
} // END processReqChange() FUNCTION


function AJAXsearchResults(inputID, formName, outputElementID) {
//	formName = form.name;
	url = "/adriel/includes/adrielENGINE.php";
	outputElement = document.getElementById(outputElementID);
	input = document.getElementById(inputID);
	
	inputWidth = "400px";
	
	outputElement.style.display = "block";
	outputElement.style.width = inputWidth;
	
	submitAJAXForm(formName, url, outputElementID);
} // END AJAXsearchResults() FUNCTION



function walkXMLTree(responseObject) {
	nodeList = responseObject.childNodes;
	for (i=0; i<nodeList.length; i++) {
		alert("node is "+nodeList[i].nodeName);
//		alert("node length is "+nodeList.length);
	}
} // END walkXMLTree() FUNCTION

function updateAJAXForm(formName, url, outputElementID) {
	
} // END updateAJAXForm() FUNCTION

// ##### END AJAX FUNCTIONS #####
// ####################################################################################