//onload functions
function onloads() {
	$('searchInput').focus();
	//setFocus();
	//RequestTrCode();
	//removeButtonUnderlines();

	new Ajax.Autocompleter("searchInput", "autocomplete_choices", "drop_search.php", {
		//paramName: "value", 
		//updateElement: addItemToList, 
		//indicator: 'indicator1',
		minChars: 3
	});

	
	
}


function DoSubmission() {
	document.cart_quantity.submit();
}	


function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}



/*
brand description on the index_products.tpl.php page. 
*/
function toggleBrandDescription(brandName) {
	//display
	if($('brandDescription').style.height == '130px') {
		$('brandDescription').style.height='';
		$('brandDescription').style.overflow='';
		$('brandReadMore').innerHTML='<<< Read less about '+brandName;
	//minimize
	} else {
		$('brandDescription').style.height='130px';
		$('brandDescription').style.overflow='hidden';
		$('brandReadMore').innerHTML='Read more about '+brandName+' >>>';
	}
}


//make sure there is atleast one product with a quantity of 1 or greater being added to the bag.
function validateAddToBagQuantity() {
	var selects = $$('select.productQuantity');
	var numberOfSelects = selects.length;
	for(i=0; i<numberOfSelects; i++) {
		if(selects[i].options[selects[i].selectedIndex].value > 0) {
			return true;
		}
	}
	alert('Please select a quantity');
	return false;
}


//display modal box verify delivery address overlay box
function verifyDeliveryAddress() {
	Modalbox.show($('verifyDeliveryAddress'), {title: 'Terms and Conditions', width: 450, height: 600});;
	
	return false;
}

function submitCheckoutConfirmationAfterAddressVerification() {

	//submit confirmation form
	document.checkout_confirmation.submit(); 
	
	//deactivate modal box so they can't change things. 
	Modalbox.deactivate();

}


//display modal box contact form submission overlay box
function displayFaqPopup() {
	Modalbox.show($('faqPopup'), {title: 'Is your question an FAQ?', width: 450, height: 400});;
	
	return false;
}

//used on product compare page.  found at http://codingforums.com/showthread.php?t=83993
document.getElementsByAttribute = function(attribute, value, tagName, parentElement) {
	var children = ($(parentElement) || document.body).getElementsByTagName((tagName || '*'));
	return $A(children).inject([], function(elements, child) {
		var attributeValue = child.getAttribute(attribute);
		if(attributeValue != null) {
			if(!value || attributeValue == value) {
				elements.push(child);
			}
		}
		return elements;
	});
}