// sfHover
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function popupwindow(infoUrl){
	window.open(infoUrl, "fitquip", "height=620,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}


// open external link in new tab/window
// use rel="external" instead of target="_blank"
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
    }
}
window.onload = externalLinks;




// Hides emails from spam
var user;
var domain;
var suffix;
function ehide(user, domain, suffix){
	document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '" >' + user + '@' + domain + '.' + suffix + '</a>');
}





// cmxform
if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );
function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();  
  // Processing
  $( 'form.cmxform' ).find( 'li' ).not( '.nocmx' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();  
  // Show forms
  $( 'form.cmxform' ).show().end();
}

function ValidateSortBox ( form ) {
	with (form) {

		if ( iSort.value == '' ){
			return false;
		}
		else {
			return true;
		}
	}
}


function ValidateCategorySortBox ( form ) {
	with (form) {

		if ( iSort.value == '' ){
			return false;
		}
		else {
			location.href = Part1.value + iSort.value + Part2.value;

			return false;
			//return true;
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}







//Handle hiding or showing the current id
function ShowOrHideTable(sTheID) {

	if ( document.getElementById(sTheID).style.display == "" )  {
		document.getElementById(sTheID).style.display = "none";
	}
	else {
		HideAll("menu_");
		document.getElementById(sTheID).style.display = "";
	}
}

function HideAll(sPrefix) {

	var oTags = document.getElementsByTagName("*");
	var iPrefixLength = sPrefix.length;

	//Loop through the entire document looking at each tag
	for (var i = 0; i < oTags.length; i++) {
		//If the current tag supports having an ID, continue
		if ( oTags[i].id ) {
			//If the current tag has an ID, continue
			if ( oTags[i].id.length > iPrefixLength ) {
				//Check to see if the current ID is prefixed with what we are trying to hide
				if ( oTags[i].id.substring(0,iPrefixLength) == sPrefix ) {
					document.getElementById(oTags[i].id).style.display = "none";
				}
			}
		}
	}
}


function ShowOrHideTable(sTheID) {

	if ( document.getElementById(sTheID).style.display == "" )  {
		document.getElementById(sTheID).style.display = "none";
	}
	else {
		HideAll("item_");
		document.getElementById(sTheID).style.display = "";
	}
}

function HideAll(sPrefix) {

	var oTags = document.getElementsByTagName("*");
	var iPrefixLength = sPrefix.length;

	//Loop through the entire document looking at each tag
	for (var i = 0; i < oTags.length; i++) {
		//If the current tag supports having an ID, continue
		if ( oTags[i].id ) {
			//If the current tag has an ID, continue
			if ( oTags[i].id.length > iPrefixLength ) {
				//Check to see if the current ID is prefixed with what we are trying to hide
				if ( oTags[i].id.substring(0,iPrefixLength) == sPrefix ) {
					document.getElementById(oTags[i].id).style.display = "none";
				}
			}
		}
	}
}


