function hiliteLorem(term){
	
	var content;
	var searchItem = term.toLowerCase();
	
	$$('p').each(function(item,index){
		content = item.innerHTML.clean().toLowerCase();
		if(content.contains(searchItem)){
			item.addClass('important');
			}
		})
		
	$$('li').each(function(item,index){
		content = item.innerHTML.clean().toLowerCase();
		if(content.contains(searchItem)){
			item.addClass('important');
			}
		})
		
	$$('span').each(function(item,index){
		content = item.innerHTML.clean().toLowerCase();
		if(content.contains(searchItem)){
			item.addClass('important');
			}
		})
		
	//for lorem links
	/*$$('a').each(function(item,index){
		href = item.get('href').clean().toLowerCase();
		if(href.contains(searchItem)){
			item.addClass('important');
			}
		})*/

	//for # links
	/*
	$$('a').each(function(item,index){
		href = item.get('href').clean().toLowerCase();
		if(href.contains('#')){
			item.addClass('blue');
			}
		})
	*/

	$$('img').each(function(item,index){
		alt = item.get('alt');
		if(alt == 'Intro Paragraph Heading'){
			item.addClass('important');
			}
		})
	
}
window.addEvent('domready', function() {
	hiliteLorem('lorem');
})

function validate(form){
	//get required fields
	var fields = $$('.req').map(function(f){
		return f.getChildren().getLast().get('tabindex').toInt();
	}).sort(function(a,b){return a - b;}).map(function(f){
		return $$('.req *[tabindex='+f+']');
	}).flatten();
	
	//validate
	var stop = true;
	fields.each(function(field,i){
		if(!stop){ return; }
		var value = field.get('value')||field.get('selectedIndex');
		if(!$defined(value)){ //if empty
			$('error').set({
				'styles': { 'display':'block' }, 
				'text': field.getParent('.req').get('rel')
			});
			var myFx = new Fx.Scroll(window).toTop();
			field.focus();
			stop = false;
		} else if(field.get('name')=='email' && !value.test(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,'i')){ //validate email addresses
			$('error').set({
				'styles': { 'display':'block' }, 
				'text': 'Invalid email address'
			});
			var myFx = new Fx.Scroll(window).toTop();
			field.focus();
			stop = false;
		} else if(field.get('name')=='phone' && !value.test(/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/,'i')){ //validate phone numbers
			$('error').set({
				'styles': { 'display':'block' }, 
				'text': 'Enter a valid US or Canadian telephone number'
			});
			var myFx = new Fx.Scroll(window).toTop();
			field.focus();
			stop = false;
		} else if(document.getElementById('00N40000001hwEI') != null)
			{
				var _countChecked = 0;
				var err = 0;
				var myMin = 1;
				var checkbox = document.getElementsByName('00N40000001hwEI');
				
				/* iterate through all the elements in the checkbox array */
				for(i=0;i<checkbox.length;i++)
				{
					/* and check to see if each is checked */
					if(checkbox[i].checked==true)
						/* if it is, increment a counter */
						{ _countChecked++; }
				}
				/* of is the count too low */
				if(_countChecked < myMin)
					{
					$('error').set({
						'styles': { 'display':'block' }, 
						'text': 'Please choose at least one product of interest'
					});
					var myFx = new Fx.Scroll(window).toTop();
					field.focus();
						err = 1; }
				if (err == 1) 
				{ 
					stop = false;
				}
			}
	});
	return stop; //will return false if any value is not defined properly
}

//ajax requests for success stories
function makeRequest(url,el) {
	var someRequest = new Request.HTML({
		url: url,
		method: 'GET',
		onSuccess: function(html) {
			
			//$(el).set('styles', {
				//'opacity': '0'
				//});
				
			$(el).innerHTML = this.response.html;
			
			myTween = new Fx.Tween($(el), { 
				property:'opacity', 
				link:'chain', 
				duration:'200'
				});
				
			(function(){ myTween.start(0,1); }).delay(100);
			
		},
		onFailure: function() {
			$(el).innerHTML = '<p>There was an error processing the request. Please try again.</p>';
		}
	}).send();
	
}


function showTab2(tabNo){
	for(i=0;i<10;i++){
		linkId = 'box-link' + i;
		contentId = 'box-content' + i;
		
		linkElem = document.getElementById(linkId);
		contentElem = document.getElementById(contentId);
		if(linkElem)
		{
			linkElem.className = '';
			contentElem.style.display = 'none';
			
		}
	}
	linkId = 'box-link' + tabNo;
	linkElem = document.getElementById(linkId);
	linkElem.className = 'active';
	
	contentId = 'box-content' + tabNo;
	contentElem = document.getElementById(contentId);
	contentElem.style.display = 'block';
	contentElem.style.background = 'red';
	
	return false;
}

function showTab(tabNo){
	for(i=0;i<10;i++){
		linkId = 'box-link' + i;
		contentId = 'box-content' + i;
		
		linkElem = $(linkId);
		contentElem = $(contentId);
		if(linkElem)
		{
			linkElem.className = '';
		
		}
	}
	
	linkId = 'box-link' + tabNo;
	linkElem = $(linkId);
	linkElem.className = 'selected';
	
	contentId = 'box-content' + tabNo;
	contentElem = $(contentId);
	$('display-content').innerHTML = contentElem.innerHTML;
	
	$('display-content').removeClass('introImage');
	
	return false;
}

function initFade(){
	setTimeout("doFade(0)",9000);
}

function doFade(imgNo){
	oldId = "art" + imgNo;
	newId = (imgNo+1) % 7;
	newId = "art" + newId;

// alert("oldId = " + oldId + " newId = " + newId);

	$(oldId).fade('out');
	$(newId).fade('in');

	imgNo = (imgNo+1) % 7;
	cmd = "doFade(" + imgNo + " );";

	setTimeout(cmd,9000);
}

// Unhide below to enable homepage hero randomization
//
//function initFade(intart){
//	setTimeout("doFade(" + intart + ")",9000);
//}
//
//function doFade(imgNo){
//	oldId = "art" + imgNo;
//	newId = (imgNo+1) % 6;
//	newId = "art" + newId;
//
//// alert("oldId = " + oldId + " newId = " + newId);
//
//	$(oldId).fade('out');
//	$(newId).fade('in');
//
//	imgNo = (imgNo+1) % 6;
//	cmd = "doFade(" + imgNo + " );";
//
//	setTimeout(cmd,9000);
//}

function showSlide(elem){
	clickId = elem.id;
	clickId = clickId.replace("slider-title-","");

	if(elem.className.indexOf('closed')>0){
		elem.className = "slider-title-opened";
		if(clickId==0){
			document.getElementById('slider-bottom').className = 'bottom-white-box-2-last';
			elem.onmouseover();
			}
	}else{
		elem.className = "slider-title-closed";
		if(clickId==0){
			elem.className = "slider-title-closed";
			document.getElementById('slider-bottom').className = 'bottom-white-box-2';
			elem.onmouseover();
			}
		
		}
	return false;
}



function sortNumber(a,b){
	return a - b;
}

window.addEvent('domready', function() {
	
	//this an IE helper for the table-based navigation for the boxes on the detail pages
	if($('white-box')){
		WBHeights = new Array;
		$$('#white-box td').each(function(item,index){
			//set width for IE
			//item.getElement('a').setStyle('width',(item.getStyle('width').toInt() - 20) + 'px');
		
			//setting heights for un-even TD heights
			WBHeights.push(item.getElement('a').getStyle('height').toInt());
			})
		
		//sorts low to high
		WBHeights.sort(sortNumber);
		$$('#white-box td').each(function(item,index){
			//set all heights to the tallest one
			item.getElement('a').setStyle('height', WBHeights.getLast() + 'px');
			})
			
		} //endif
			
})

<!-- Add 12.11.08 by JO -->
function Popon(){
	document.getElementById("divOverlay").style.display="block";
	document.getElementById("divPopup").style.display="block";
}
function Popoff(){
	document.getElementById("divOverlay").style.display="none";
	document.getElementById("divPopup").style.display="none";
}

	
/* Added by JO on 03.04.09 */
/* Function allows for a cookie to be set. */
function set_Cookie(dtk, cName, cValue){
	var daysToKeep = dtk;
	var expires = new Date();
	//alert(expires.getDate() + daysToKeep);
	expires.setDate(expires.getDate() + daysToKeep); 
	var CookieName = cName;
	
	var CookieValue = cValue;
	set_cookie(CookieName, CookieName, expires);
}