/*------------------------------------------------
/	2005.04.12 pk
/	Submits form when shipping address changes
/	writes a hidden form field to pass to backend 
/	putting the hidden form field here so hidden form
/ 	field doesn't get added twice
--------------------------------------------------*/

// 2005.12.14 pkelley/kyeo
// Takes a comma-separated argument and creates an array out of it.
// If the argument contains only 1 value (instead of a comma separated list), make that a 1 element array
// Used in FormGroupCreditCard component by the following JS -- toggleDisplay and toggleDisabled
function createArray(myval)
{
	var a = new Array();
	var input = myval;

	// if it's not array create one so we can loop over it
	if (input.constructor.toString().indexOf("Array") == -1) {
		// to do - remove any spaces form commas separated list
		a = input.split(",");
	}
	else {
		a = input;
	}
	return a;
}

// 2005.12.14 kyeo
// Disables a form field by setting an attribute "disabled" so the field will not be sent to the server
function toggleDisabled(myDiv,field,action)
{
	var a = new Array();
	a = createArray(myDiv);

	for (var i=0; i<a.length; i++) {
		if ( document.getElementById(a[i]) ) {
			var myField = document.getElementById(a[i]).getElementsByTagName(field);

			for (var x = 0; x<myField.length; x++) {
				if (action == 'set') myField[x].setAttribute('disabled','true');
				else myField[x].removeAttribute('disabled');
			}
		}
//		else { alert("no such value"); }
	}
}

// 2005.12.14 pkelley/kyeo
// Changes the class to hidden which is defined in the css
// as Display: none
// Pass in a comma separated list/array/scalar of ids
function toggleDisplay(tag, display) 
{
	var a = new Array();
	a = createArray(tag);

	var id = "";
	var show = (display == "show") ? true : false;

	for (var i=0; i<a.length; i++) {
		id = document.getElementById(a[i]);
		if (id) {
			if (show) id.className = "";
			else id.className = "hidden";
		}
	}	
}