
// selected a band from the drop down, go to that band page
function goBandPage() {
	if ($('select_band').value) {
		window.location = 'index.php?page=one_band&aid=' + $('select_band').value;
	}
}

// when billing & shipping are the same, copy over values from shipping
function copyAddresses() {
	if ($('same_addresses').checked) {
		$('Name').value = $('sh_first_name').value + ' ' + $('sh_last_name').value;
		$('Street').value = $('sh_address').value;
		$('Street2').value = $('sh_address2').value;
		$('City').value = $('sh_city').value;
		$('State').value = $('sh_state').value;
		$('otherstate').value = $('sh_otherstate').value;
		$('Zip').value = $('sh_zip').value;
		$('Country').value = $('sh_country').value;
	}
}

function checkForm() {
	var blank = '';
	if (!$('sh_first_name').value) {
		blank += "Shipping First Name\n";
	}
	if (!$('sh_last_name').value) {
		blank += "Shipping Last Name\n";
	}
	if (!$('sh_address').value) {
		blank += "Shipping Address\n";
	}
	if (!$('sh_city').value) {
		blank += "Shipping City\n";
	}
	if (!$('sh_state').value && !$('sh_otherstate').value) {
		blank += "Shipping State (or other state)\n";
	}
	if (!$('sh_zip').value) {
		blank += "Shipping Zip\n";
	}
	if (!$('sh_country').value) {
		blank += "Shipping Country\n";
	}
	if (!$('Email').value) {
		blank += "Email\n";
	}

	if (!$('Name').value) {
		blank += "Name on Card\n";
	}
	if (!$('Street').value) {
		blank += "Billing Address\n";
	}
	if (!$('City').value) {
		blank += "Billing City\n";
	}
	if (!$('State').value && !$('otherstate').value) {
		blank += "Billing State (or other state)\n";
	}
	if (!$('Zip').value) {
		blank += "Billing Zip\n";
	}
	if (!$('Country').value) {
		blank += "Billing Country\n";
	}


	if (blank) {
		alert("The following fields must be filled in\n" + blank);
		return false;
	}
	return true;
}

// prototype $ function - http://prototype.conio.net/
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;
    elements.push(element);
  }
  return elements;
}


// create generic listener tool
function addEvent(elm, evType, fn, useCapture) {
  // cross-browser event handling for IE5+, NS6 and Mozilla 
  // By Scott Andrew 
  if (elm.addEventListener) { 
    elm.addEventListener(evType, fn, useCapture); 
    return true; 
  } else if (elm.attachEvent) { 
    var r = elm.attachEvent('on' + evType, fn); 
    return r; 
  } else {
    elm['on' + evType] = fn;
  }
}

function addListeners() {
  if (!document.getElementById){
    return;
  }
	if ($('same_addresses')) {
		addEvent($('same_addresses'), 'click', copyAddresses, false);
	}
	if ($('select_band')) {
		addEvent($('select_band'), 'change', goBandPage, false);
	}
}


addEvent(window, 'load', addListeners, false);


