function addEvent( elm, evType, fn, useCapture ) {
	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;
	}
}

// avoid empty search queries
function searchbox_submit(search_words) {
	if( 1 < search_words.length ) {
		return true;
	} else {
		alert( 'Enter a valid search word' );
		return false;
	}
}

// activate drop-down for submenu (li>ul) on nav-featured
// suckerfish menus from http://htmldog.com/articles/suckerfish/dropdowns/
addEvent(
	window,
	'load',
	function() {
		var sfEls = document.getElementById('nav-featured').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"), '');
			}
		}
	},
	false
);

function is_email( el ) {
	el = el.value;
	return (
		   4 < el.length
		&& 1 < el.indexOf(     '@' )
		&& 3 < el.lastIndexOf( '.' )
		&&     el.lastIndexOf( '.' ) < (el.length - 1)
		)
		? true
  		: false
		;
}
function is_filled( el ) {
	return ( el.value == '' || el.value == null )
		? false
		: true
		;
}

/* ==========================================================
   FUNCTION: isCreditCard(st)
   THIS FUNCTION IS TAKEN FROM:
   http://developer.netscape.com/library/examples/...
                    .../javascript/formval/FormChek.js
   INPUT:    st - a string representing a credit card number
   RETURNS:  true, if card number passes Luhn Mod-10 test
	         false, otherwise
   ========================================================== */
function isCreditCard( st ) {
  // Encoding only works on cards with less than 19 digits
	if( st.length > 19 || 13 > st.length ) { return false; }
	var sum = 0;
	var mul = 1;
	l = st.length;
	for( var i = 0; i < l; i++ ) {
		var digit = st.substring( l-i-1, l-i );
		var tproduct = parseInt( digit, 10 ) * mul;
		if( tproduct >= 10 ) {
			sum += (tproduct % 10) + 1;
		} else {
			sum += tproduct;
		}
		if( mul == 1 ) {
			mul++;
		} else {
			mul--;
		}
	}
	return ( (sum % 10) == 0 );
}

