/* displayDiv()
***************
*/
function displayDiv(id) {
   var theDiv = document.getElementById(id);

   if (theDiv.style.display == 'none') {
      showDiv(id);
   }
   else {
      hideDiv(id);
   }
}


/* showDiv()
************
*/
function showDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'block';
}


/* hideDiv()
************
*/
function hideDiv(id) {
   var theDiv = document.getElementById(id);

   theDiv.style.display = 'none';
}


/* redirect()
*************
Redirects to a specified web address.
*/
function redirect(newURL) {
   window.location = newURL;
}


/* removeElement()
******************
Removes a child element c from parent element p
*/
function removeElement(p, c) {
   if (p != c) {
      if (document.getElementById(c)) {
         var parentElement = document.getElementById(p);
         var childElement = document.getElementById(c);
         
         parentElement.removeChild(childElement);
      }
      else {
         return false;
      }
   }
   else {
      return false;
   }
}


/* strpos()
***********
Javascript equivalent.
*/
function strpos(haystack, needle, offset) {
	var i = (haystack+'').indexOf( needle, offset ); 
	return i===-1 ? -1 : i;
}


/** Custom Pages **/

/* subjectPreselect()
*********************
Depending on a url paramter, preselect
this dropdown. Used for the Find Distributor
links in the products section, and goes to 
the Contact page.
*/
function subjectPreselect(id) {
   var theSelect = document.getElementById(id);
	
   var regex = new RegExp("(subject=)([a-zA-Z0-9_]+)");
	var matches = regex.exec(location.href);
	
	// Put conditionals here
	
	if (matches != null) {
	  if (matches[2] == 'findDistributor') {
         theSelect.selectedIndex = 2;
		}
		else if (matches[2] == 'requestSample') {
         theSelect.selectedIndex = 3;
		}
    else if (matches[2] == 'requestPriceSheet') {
         theSelect.selectedIndex = 4;
		}

	}
	
	return;
}









