/* LASERBAND 2008 WEBSITE JAVASCRIPT */

var saveHistory = true;
var searchJs=0;

var currenttab='';
var pfsearch='';
var section='';
var glasttab='';
var nextto='';
var gparent='';

/* ajax loading is disabled for ie6 since it sucks */
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

/* + icons show this as their title */
var plusTitle = 'Click to view information about this item.';
var plusTitleLit = 'Click to close and continue slide show.';

/* how fast everything slides in ms */
var slideShowSpeed = 4500;

/* how fast the slides fade in ms */
var loadDelay=500;

var picDir="styles/laserband/";
/* all the backgrounds to cycle */
var Pic = new Array();
Pic[0] = 'deimages/bgBaby.jpg';
Pic[1] = 'deimages/bgAdult.jpg';
Pic[2] = 'deimages/bgChart.jpg';
Pic[3] = 'deimages/bgSpecial.jpg';

/* preload images that may be dynamic */
var PreloadImages = new Array();
PreloadImages[0]  = 'deimages/bgBlue.gif';
PreloadImages[1]  = 'deimages/bgBaby.jpg';
PreloadImages[2]  = 'deimages/bgAdult.jpg';
PreloadImages[3]  = 'deimages/bgChart.jpg';
PreloadImages[4]  = 'deimages/bgSpecial.jpg';
PreloadImages[5]  = 'deimages/navBgLit.gif';
PreloadImages[6]  = 'deimages/navRightLit.gif';

/* load time testing - are they worth it?
PreloadImages[7]  = 'deimages/buttons/similarProductLit.gif';
PreloadImages[8]  = 'deimages/buttons/findProductsLit.gif';
PreloadImages[14] = 'deimages/buttons/similarProductLit.gif';
PreloadImages[16] = 'deimages/tabRightMed.gif';
PreloadImages[17] = 'deimages/tabRightLite.gif';
PreloadImages[18] = 'deimages/tabRightLit.gif';
PreloadImages[19] = 'deimages/tabRight.gif';
PreloadImages[20] = 'deimages/tabLeftLit.gif';
*/

/* define vars used */
var t;
var tp;
var j = 0
var p = Pic.length;
var preload = PreloadImages.length;

var runshow=true;
var prevpic=Pic[0];
		

/* font size + - control */
var min=10;
var max=18;

function showHide(layer, link){
	var change=$(layer).style;

//$('hiddenupdate').style.display = 'block';

	

	if(change.display == "block"){
		change.display="none";

			if(layer == "forwardNews"){
					
				$('newsFwdInput').value='email addresses separate by ","s';
				$('fwdReplyToInput').value='reply-to address';
				
				$j('#labelRecipients').show();
				$j('#fwdText').val('');
				

				$('newsForwardBoxContent').style.display='block';
				$('newsForwardBoxClose').style.display='none';
				$('forwardBoxExtraFields').style.display='block';
			}
			if(layer =="forwardBox"){

				$('fwdInput').value='email addresses separate by ","s';
				$('fwdReplyToInput').value='reply-to address';
				
				$j('#labelRecipients').show();
				$j('#fwdText').val('');
				
				$('forwardBoxContent').style.display='block';
				$('forwardBoxClose').style.display='none';
				$('forwardBoxExtraFields').style.display='block';
				
			}


	} else {
	
		change.display="block";
		change.position = 'absolute';
		change.left = (mouse.x + 50) + 'px';
		
		opacity(layer, 0, 100, loadDelay);

	}

}


function submitForward(productId, addresses, news){

	if(news){

		$j('#labelRecipients').hide();
		$j('#forwardBoxExtraFields').hide();
		$j('#newsForwardBoxContent').hide();
		$j('#newsForwardBoxClose').show();

		if($j('#fwdReplyToInput').value == 'reply-to address') { $j('#fwdReplyToInput').value = ''; }
		
		addresses = $('newsFwdInput').value;
		replyTo = $('fwdReplyToInput').value;
		comments = $('fwdText').value;
		

		$('newsFwdInput').value="Sending e-mail to addresses...";
		new Ajax.Updater('hiddenupdate', 'index.php?pageId=28&mode=mod_laser&action=forwardNews', { parameters: { productId: productId, addresses: addresses,  replyTo: replyTo, comments: comments }, method: 'get', evalScripts: true, onComplete: function() { $('newsFwdInput').value='E-mail(s) sent.'; }
		});

	} else {
		
		$j('#labelRecipients').hide();
		$j('#forwardBoxExtraFields').hide();
		$j('#forwardBoxContent').hide();
		$j('#forwardBoxClose').show();

		addresses = $('fwdInput').value;
		replyTo = $('fwdReplyToInput').value;
		comments = $('fwdText').value;
		
		$('fwdInput').value="Sending e-mail to addresses...";
		new Ajax.Updater('hiddenupdate', 'index.php?pageId=28&mode=mod_laser&action=forward', { parameters: { productId: productId, addresses: addresses,  replyTo: replyTo, comments: comments }, method: 'get', evalScripts: true, onComplete: function() { $('fwdInput').value='E-mail(s) sent.'; }
		});

	}
}

function clearForwardBox(searchbox){
	if(searchbox.value == 'email addresses separate by ","s') searchbox.value='';
}

function clearTextBox(searchbox, text){

	if(searchbox.value == text) searchbox.value='';
}

/* change the class for top nav */
function changeClass(eleid, newclass, me){
		$(eleid).className=newclass;
		if(newclass == "navspacehover"){
			me.className='navitemLit';
		} else me.className='navitem';

		
}

/* change the + buttons when hovered */
function changeButton(popup, me){
	if($(popup).style.display != "block"){
		if(me.className == "plusButtonLit"){
		 me.className="plusButton";
		 } else me.className="plusButtonLit";
	}
}


function startSlideShow(){
	t = setTimeout('runSlideShow()', slideShowSpeed)
}

function loadProductPopup(popup, productId){

	var popupElement=$(popup);
	if(popupElement.style.display == "block"){
		popupElement.style.display='none'; 
	} else popupElement.style.display='block'; 

}



function closeAllOpenPopUps()
{
	jQuery.each(openPopups, function(index, popup){

		//alert(popup + ' ' + openItems[index]);
		loadPopup(popup, openItems[index], 1);
		
	});
	openPopups = [];
	openItems = [];

}

function resetProductTabs()
{

	if($('prodTabIdeal')) $('prodTabIdeal').hide();
	if($('prodTabCompanion')) $('prodTabCompanion').hide();
	if($('prodTabSpec')) $('prodTabSpec').hide();
	if($('prodTabOrdering')) $('prodTabOrdering').hide();
	if($('prodTabResources')) $('prodTabResources').hide();
	if($('prodTabFeatures')) $('prodTabFeatures').show();

	tabNav('tab2a', 'tab1a', 'productTabHeader', 'tab6a');

}

/* load the popups and change + buttons t itle */

var openPopups = [];
var openItems = [];

function loadPopup(popup, item, alt){

	openPopups.push(popup); openItems.push(item);

	var me = $(item);
	var popupElement=$(popup);
	if(popupElement.style.display == "block"){
		me.title=plusTitle;
		popupElement.style.display='none'; 
		clearTimeout(t);
		runshow=true;
		if(alt) me.className='plusButton'
		startSlideShow();

	} else {
		switch(popup){
			/* these need to be updates to pull from db.. popup table */
			
			case "popupSpecialArea":
				new Ajax.Updater('specialPopup', 'index.php?pageId=28&mode=mod_laser&popup='+popup+'&action=showPopup&productCategoryId=4&productId=89&homePagePopup=true', { method: 'get' });
			break;
			case "popupChartArea":
				new Ajax.Updater('chartPopup', 'index.php?pageId=28&mode=mod_laser&popup='+popup+'&action=showPopup&productCategoryId=3&productId=40&homePagePopup=true', { method: 'get' });
			break;
			case "popupAdultArea":
				new Ajax.Updater('adultPopup', 'index.php?pageId=28&mode=mod_laser&popup='+popup+'&action=showPopup&productCategoryId=1&productId=86&homePagePopup=true', { method: 'get' });
			break;
			case "popupBaby2Area":
				new Ajax.Updater('babyPopup2', 'index.php?pageId=28&mode=mod_laser&popup='+popup+'&action=showPopup&productCategoryId=2&productId=78&homePagePopup=true', { method: 'get' });
			break;
			case "popupBabyArea":
				new Ajax.Updater('babyPopup', 'index.php?pageId=28&mode=mod_laser&popup='+popup+'&action=showPopup&productCategoryId=2&productId=98&homePagePopup=true', { method: 'get' });
			break;
		}


		me.title=plusTitleLit;
		popupElement.style.display='block'; 
		me.className='plusButtonLit'
		runshow=false;
		clearTimeout(t);
	}

}

function createNewsPage(newsId, pageId) {
	//alert('createNewsPage');
	saveHistory = false;
	//loadNav('newsresources');
	//window.location='index.php?pageId=9&next=1';
	section = 'newsresources';

	runshow=false;
	clearTimeout(t);

	blendimage('homebg', 'blendimage', 'deimages/bgBlueShaded.gif',400,prevpic);
	$('homebox').className='bluehomebox';
	
	var reset='';

	hideAll(reset);
-

	//document.title='Case Studies';
	ajaxLoading('ajaxUpdater', 'loadingNews');
	new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxNews&newsPage=9&next=1', { method: 'get' , evalScripts: true, onComplete: function() { 
	
		
	$('ajaxUpdater').style.display='block';

	$j.ajax({
				type: "POST",
				url: "index.php",
				data: "pageId=28&mode=mod_laser&action=getNewsTypePageId&newsId=" + newsId,
				success: function(pageId){
					if(!pageId) pageId = parseInt(pageId);
					
					page = $j.trim(pageId);

					switch(pageId) {
						case "9":
							
							currenttab='newsTab1';
							glasttab='newsTab6';
							nextto='';
							gparent='newsMainHeader';

							tabNav('newsTab1', '', 'newsMainHeader', 'newsTab6');

						break;
						case "10":

							currenttab='newsTab2';
							glasttab='newsTab6';
							nextto='newsTab1';
							gparent='newsMainHeader';

							tabNav('newsTab2', 'newsTab1', 'newsMainHeader', 'newsTab6');
						break;
						case "11":

							currenttab='newsTab3';
							glasttab='newsTab6';
							nextto='newsTab2';
							gparent='newsMainHeader';

							tabNav('newsTab3', 'newsTab2', 'newsMainHeader', 'newsTab6');
						break;
						case "53":

							currenttab='newsTab4';
							glasttab='newsTab6';
							nextto='newsTab3';
							gparent='newsMainHeader';

							tabNav('newsTab4', 'newsTab3', 'newsMainHeader', 'newsTab6');
						break;
						case "167":
							currenttab='newsTab5';
							glasttab='newsTab6';
							nextto='newsTab4';
							gparent='newsMainHeader';

							tabNav('newsTab5', 'newsTab3', 'newsMainHeader', 'newsTab6');
							
						break;

						case "184":
							currenttab='newsTab6';
							glasttab='newsTab6';
							nextto='newsTab5';
							gparent='newsMainHeader';

							tabNav('newsTab6', 'newsTab3', 'newsMainHeader', 'newsTab6');
							
						break;

						default:
							//alert(pageId);
						break;

					}
					

					saveHistory = true;
					if(newsId != 0) loadNewsItem(newsId, pageId); 

				}
			});

		}});

}

function tabNav(me, tab, parent, lasttab){
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i < divs.length; i++){
		var thisDiv=divs[i];
		/* reset all tabs to default */
		if(thisDiv.className == "item nextto" && thisDiv.parentNode.id == parent
			|| thisDiv.className == "item current" && thisDiv.parentNode.id == parent
			|| thisDiv.className == "item currentdark" && thisDiv.parentNode.id == parent) thisDiv.className="item";
		/* set last tab to not have slash */
		if(thisDiv.id == lasttab && thisDiv.parentNode.id == parent)thisDiv.className="item nextto";
	}
	/* set the next tab to the active one to not have slash */
	if(tab && $(tab)) $(tab).className='item nextto';

	/* set the new tab to the right lite */
	if($(me)){
		me=$(me);
		if(me){
			if(me.id.substr(0, 9) == "searchTab"){
				me.className='item currentdark';
			} else me.className='item current';
		}
	}
}

/* change tabs at bottom of index */
function changeTab(me, tab, pos, updatediv, parent, lasttab){
	var productTab = 0;

	if(me == "tab1a" || me == "tab2a" || me == "tab3a" || me == "tab4a" || me == "tab5a" || me == "tab6a") {
		productTab = 1;
	}

	currenttab=me;
	glasttab=lasttab;
	nextto=tab;
	gparent=parent;

	if(saveHistory){
		var complexObject = new Object();
		complexObject.value1 = me;
		complexObject.value2 = tab;
		complexObject.value3 = pos;
		complexObject.value4 = updatediv;
		complexObject.value5 = parent;
		complexObject.value6 = lasttab;

		if(productTab == 0) dhtmlHistory.add('loadtab' + $(me).id, complexObject);
	}

	/* reset all tabs & load new tab */
	tabNav(me, tab, parent, lasttab);


	if($(me)){
		me=$(me);
	} else return false;


	/* load the tabs content */
	if(me.id == "searchTab1"){
		$('searchTabResults2').style.display='none';
		$('searchTabResults').style.display='block';
	}

	if(me.id == "searchTab2"){
		$('searchTabResults2').style.display='block';
		$('searchTabResults').style.display='none';
	}


	if(me.id == "tab1" || me.id == "tab2" || me.id == "tab3" || me.id == "tab4" || me.id == "tab5"){
			var tabPage='';
			if(me.id == "tab1") tabPage='4';
			if(me.id == "tab2") tabPage='5';
			if(me.id == "tab3") tabPage='6';
			if(me.id == "tab4") tabPage='7';
			if(me.id == "tab5") tabPage='8';
			if(me.id == "tab6") tabPage='9';

		ajaxLoading('homeTab', 'loadingSmall');
		new Ajax.Updater('homeTab', 'index.php?pageId='+tabPage, { method: 'get' });
	}

	if(me.id == "tab1a"){

		$j('.productTab').each(function(){
			$j(this).hide();		
		});
		$j('#prodTabIdeal').show();
	}

	if(me.id == "tab2a"){

		$j('.productTab').each(function(){
			$j(this).hide();		
		});

		$j('#prodTabFeatures').show();
	}

	if(me.id == "tab3a"){
	
		$j('.productTab').each(function(){
			$j(this).hide();		
		});
		
		$j('#prodTabSpec').show();
	}

	if(me.id == "tab4a"){
		
		$j('.productTab').each(function(){
			$j(this).hide();		
		});
		
		$j('#prodTabCompanion').show();
	}

	if(me.id == "tab5a"){
	
		$j('.productTab').each(function(){
			$j(this).hide();		
		});

		$j('#prodTabOrdering').show();
	}

	if(me.id == "tab6a"){

		$j('.productTab').each(function(){
			$j(this).hide();		
		});

		$j('#prodTabResources').show();
	}



	/* MORE INFO AND ORDERING INFO */
	if(me.id == "tab1d"){	
		$('informationBar').innerHTML='';
		new Ajax.Updater('informationBar', 'index.php?pageId=28&mode=mod_laser&action=loadPageContent&loadId=36&productId='+updatediv, { method: 'get' , evalScripts: true  });

		ajaxLoading('tabContentd', 'loadingNewsTab');
		new Ajax.Updater('tabContentd', 'index.php?pageId=28&mode=mod_laser&action=loadPageContent&loadId=34&productId='+updatediv, { method: 'get' , evalScripts: true  });


	}
	if(me.id == "tab2d"){
		$('informationBar').innerHTML='';
		new Ajax.Updater('informationBar', 'index.php?pageId=28&mode=mod_laser&action=loadPageContent&loadId=35&productId='+updatediv, { method: 'get' , evalScripts: true  });
	
		ajaxLoading('tabContentd', 'loadingNewsTab');
		new Ajax.Updater('tabContentd', 'index.php?pageId=28&mode=mod_laser&action=loadPageContent&loadId=33&productId='+updatediv, { method: 'get' , evalScripts: true  });
	}


	/* NEWS TABS */

	if(me.id.substr(0, 7) == "newsTab"){

		changeOpac('0', 'newsHelp');
		changeOpac('0', 'newsNav');
		changeOpac('0', 'newsContact');
		changeOpac('0', 'newsletterSub');
		$('newsNav').innerHTML='';




		ajaxLoading(updatediv, 'loadingNewsTab');


		if(me.id == "newsTab1"){
			document.title='Case Studies';
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=9', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=9&newsType=1&next=1', { method: 'get', evalScripts: true });

			$('newsHelp').style.display='none';
			opacity('newsContact', 0, 100, loadDelay);

		} else if(me.id == "newsTab2") {
			document.title='Company News';
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=10', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=10&newsType=11&next=1', { method: 'get', evalScripts: true });
			$('newsHelp').style.display='block';
			opacity('newsHelp', 0, 100, loadDelay);

		} else if(me.id == "newsTab3") {
			document.title='Industry News';
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=11', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=11&newsType=2&next=1', { method: 'get', evalScripts: true });
			$('newsHelp').style.display='block';
			opacity('newsHelp', 0, 100, loadDelay);

		} else if(me.id == "newsTab4") {
			document.title='Newsletter';
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=53', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=53&newsType=3&next=1', { method: 'get', evalScripts: true });
			$('newsContact').style.display='none';
			$('newsHelp').style.display='block';
			opacity('newsHelp', 0, 100, loadDelay);
			$('newsletterSub').style.display='block';
			opacity('newsletterSub', 0, 100, loadDelay);
		} else if(me.id == "newsTab5") {
			document.title='Videos'; 
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=167', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=167&newsType=13&next=1', { method: 'get', evalScripts: true });
			$('newsHelp').style.display='block';
			opacity('newsHelp', 0, 100, loadDelay);

		}
		 else if(me.id == "newsTab6") {
			document.title='Testimonials'; 
			new Ajax.Updater("newsNav", 'index.php?pageId=28&action=newsNav&newsPage=184', { method: 'get' });
			new Ajax.Updater(updatediv, 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=184&newsType=14&next=1', { method: 'get', evalScripts: true });
			$('newsHelp').style.display='block';
			opacity('newsHelp', 0, 100, loadDelay);

		}
	
		opacity('newsNav', 0, 100, loadDelay);
	}

}




function submitForm(form, type){

	elementsForms = document.getElementsByName("required[]");
	for (var intCounter = 0; intCounter < elementsForms.length; intCounter++)  {
		var required=elementsForms[intCounter].value;
		var msg='The following field is required:\n' + required.replace('_', ' ') + '\n';

		items=document.getElementsByName(required);
		var content=items[0].value;

		if(!content){
			alert(msg);
			items[0].focus();
			return false;
		}
	}

	if(saveHistory) dhtmlHistory.add('submit' + type, type);

	if(type == "newsletter"){
		new Ajax.Updater('newsLetterSignup', 'scripts/processForm.php', { method: 'post', parameters: $(type).serialize() } );
	} else if(type == "orderinfo" || type == "moreinfo") {new Ajax.Updater('tabContentd', 'scripts/processForm.php', { method: 'post', parameters: $(type).serialize() } );}
	else {$(type).submit();}
}


function loadNewsPage(newsPage, newsType){
	var complexObject = new Object();
	complexObject.value1 = newsPage;
	complexObject.value2 = newsType;
	if(saveHistory) dhtmlHistory.add('loadnews' + newsPage, complexObject);

	ajaxLoading('tabContentc');
	new Ajax.Updater('tabContentc', 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsHome=9&newsType='+newsType+'&next=' + newsPage, { method: 'get', evalScripts: true });

}

function loadNewsItem(item, item2){
//value1: 202, value2: 11, tab: newsTab3, lasttab: newsTab5, nextto: newsTab2, parent: newsMainHeader
	if(saveHistory){
		var complexObject = new Object();
		complexObject.value1 = item;
		complexObject.value2 = item2;
		complexObject.tab = currenttab;
		complexObject.lasttab = glasttab;
		complexObject.nextto = nextto;
		complexObject.parent = gparent;

		//alert('value1: ' + item + ', value2: ' + item2 + ', tab: ' + currenttab + ', lasttab: ' + glasttab + ', nextto: ' + nextto + ', parent: ' + gparent);

		dhtmlHistory.add('newsitem' + item, complexObject);
	}

	ajaxLoading('tabContentc');
	new Ajax.Updater('tabContentc', 'index.php?pageId=28&mode=mod_laser&action=loadNews&newsPage='+item+'&newsHome='+item2, { method: 'get' , evalScripts: true });
}

function createProductPage(productId) {

	saveHistory = true;

	$j.ajax({
			type: "POST",
			url: "index.php",
			data: "pageId=28&mode=mod_laser&action=getProductCategoryId&productId=" + productId,
			success: function(categoryId){

				categoryId = parseInt(categoryId);
				
				//alert(categoryId);
				//tab:products, staylit:, productId:89, productCategoryId:4
					loadNav('products', '', productId, categoryId);
				}
				
		});

}

function resetNav(tab){
	$(tab+'txt').onmouseover="javascript: changeClass('"+tab+"', 'navspacehover', this);";
	$(tab+'txt').onmouseout="javascript: changeClass('"+tab+"', 'navspace', this);";
	$(tab+'txt').className='navitem';
	$(tab).className='navspace';

}

function resetAllNavs(){
		resetNav('nav1');
		resetNav('nav2');
		resetNav('nav3');
		resetNav('nav4');
}

function hideAll(reset){

	$('popupBaby').style.display='none';	
	$('popupBaby2').style.display='none';	
	$('icon1').className='iconButton';	

	$('popupAdult').style.display='none';	
	$('icon2').className='iconButton';	

	$('popupChart').style.display='none';	
	$('icon3').className='iconButton';	

	$('popupSpecial').style.display='none';
	$('icon4').className='iconButton';	

	$('icons').style.display='none';
	$('findbutton').style.display='none';
	
	if(!reset){
		resetNav('nav1');
		resetNav('nav2');
		resetNav('nav3');
		resetNav('nav4');
	}

	var divs = document.getElementsByTagName('a'); 
	for(i=0; i < divs.length; i++){
		var thisDiv=divs[i];

		if (thisDiv.className == "navrightlinklit") thisDiv.className="navrightlink";
	}


	if ($('hometabs')) $('hometabs').style.display='none';
	if ($('hometabs')) changeOpac('0', 'hometabs');

	if ($('navProducts')) $('navProducts').style.display='none';
	if ($('productTabs')) $('productTabs').style.display='none';
	if ($('productTabs')) changeOpac('0', 'productTabs');

	if ($('ajaxUpdater')) $('ajaxUpdater').innerHTML='';



	if ($('productOverview')) $('productOverview').style.display='none';
	if ($('productPageTabs')) $('productPageTabs').style.display='none';
	if ($('productPageTabs')) changeOpac('0', 'productPageTabs');

	if ($('newsTabs')) $('newsTabs').style.display='none';
	if ($('genericTabs')) $('genericTabs').style.display='none';


	if ($('categoryLanding')) $('categoryLanding').style.display='none';
	if ($('miniFinder')) $('miniFinder').style.display='none';
	$('prodFinderLeft').style.display='none';

}

function loadGenericPage(pageId, pageUrl){
	var section = "loadgpage";

	if(pageId){
		if(saveHistory) dhtmlHistory.add('loadgpage' + pageId, pageId);

		ajaxLoading('genericArea');
		new Ajax.Updater('genericArea', 'index.php?pageId=28&mode=mod_laser&action=loadPageContent&loadId='+pageId, { method: 'get', evalScripts: true  });
	} else if(pageUrl){
		window.location=pageUrl;
	}
}

function resetCatSearch(catnum){
	if($('prodSearchFormA')){
		var formname = 'prodSearchFormA';
		resetFilters(formname, 'nosubmit');
	//	new Ajax.Updater(formname+'Results', 'index.php?pageId=28&action=searchResults&format=&print=&solutions=&formname='+formname+'&productCategoryId='+catnum, { method: 'get', evalScripts: true });

		
		$j.ajax({
			type: 'POST',
			url: 'index.php',
			cache: false,
			data: {'pageId': 28, 'action': 'searchResults', 'formname': formname, 'productCategoryId': catnum },
			success: function(t){ $j('#' + formname+'Results').html(t); }
		});


	}
}

function loadMainNav(tab, title, save){
	var cat="";
	var pic="";
	runshow=false;
	clearTimeout(t);

	closeAllOpenPopUps();
	resetProductTabs();
	
	if($('homebox') && IE6 == false){

		document.title=title;

		$('homebox').className='homebox';
		
		hideAll();
		
		changePopups('hide');
	
		changeOpac('0', 'productOverview');

		if (tab == "nav1"){
			pic = Pic[1];
			new Ajax.Updater('productsOverviewTxt', 'index.php?pageId=18', { method: 'get' });
			cat ="adult";
			catnum=1;
		}
		if (tab == "nav2"){
			pic = Pic[0];
			new Ajax.Updater('productsOverviewTxt', 'index.php?pageId=19', { method: 'get' });
			cat ="baby";
			catnum=2;
		}

		if (tab == "nav3"){
			pic = Pic[2];
			new Ajax.Updater('productsOverviewTxt', 'index.php?pageId=20', { method: 'get' });
			cat ="chart";
			catnum=3;
		}

		if (tab == "nav4"){
			pic = Pic[3];
			new Ajax.Updater('productsOverviewTxt', 'index.php?pageId=21', { method: 'get' });
			cat ="special";
			catnum=4;
		}

		var complexObject = new Object();
		complexObject.value1 = tab;
		complexObject.value2 = title;

		if(saveHistory) dhtmlHistory.add('category'+cat, complexObject);

		ajaxLoading('productPageFeatured', 'loadingSmall2');
		new Ajax.Updater('productPageFeatured', 'index.php?pageId=13&productCategoryId='+catnum, { method: 'get' });


		resetCatSearch(catnum);

		$('prodSearchFormABackTo').style.display='none';

		$('prodSearchFormAViewAllCont').style.display='block';
		$('prodSearchFormAViewAllCont').className='navPain navPainAlt' ;
		$('prodSearchFormANav1').className='navPain navPainAlt';
		$('prodSearchFormANav2').className='navPain navPainAlt';
		$('prodSearchFormANav3').className='navPainTall navPainAlt';
		$('prodSearchFormAResults').innerHTML='';
		$('prodSearchFormAViewProductsLink').style.display='none';

		$('productOverview').style.display='block';
		$('productPageTabs').style.display='block';
		$('miniFinder').style.display='block';
		$('prodFinderLeft').style.display='none';

		$(tab+'txt').onmouseover='';
		$(tab+'txt').onmouseout='';
		$(tab+'txt').className='navitemLit';
		$(tab).className='navspacehover';
		opacity('productPageTabs', 0, 100, loadDelay);
		opacity('productOverview', 0, 100, loadDelay);


		var formname = 'prodSearchFormA';
		if($(formname+'Title')) $(formname+'Title').innerHTML=title;
		if($(formname+'ViewAll')) $(formname+'ViewAll').innerHTML= 'View All ' + title;
		if($(formname+'filterTitle2')) $(formname+'filterTitle2').innerHTML= 'Filter ' +title;

		blendimage('homebg', 'blendimage', pic, loadDelay, prevpic); 
} else { 
		if (tab == "nav1") window.location='index.php?pageId=14';
		if (tab == "nav2") window.location='index.php?pageId=15';
		if (tab == "nav3") window.location='index.php?pageId=16';
		if (tab == "nav4") window.location='index.php?pageId=17';
	}
}

function changePopups(way, all){

	if(way == "show"){
		dis = 'block';
	} else if (way == "hide"){
		dis = 'none';
	}
		$('plusAdult').style.display=dis;
		$('plusBaby').style.display=dis;
		$('plusBaby2').style.display=dis;
		$('plusChart').style.display=dis;
		$('plusSpecial').style.display=dis;

		if (way == "hide"){
			$('plusAdult').className='plusButton';
			$('plusBaby').className='plusButton';
			$('plusBaby2').className='plusButton';
			$('plusChart').className='plusButton';
			$('plusSpecial').className='plusButton';

			$('popupAdultArea').style.display=dis;
			$('popupBabyArea').style.display=dis;
			$('popupBaby2Area').style.display=dis;
			$('popupChartArea').style.display=dis;
			$('popupSpecialArea').style.display=dis;
		}
}


function loadHome(){

	closeAllOpenPopUps();
	resetProductTabs();

	if($('homebox') && IE6 == false){

		document.title='LaserBand&reg; Patient Identification';

		 if(saveHistory) dhtmlHistory.add("home", "loadHome");

		runshow=false;
		clearTimeout(t);

		$('homebox').className='homebox';

		hideAll();
		
		changePopups('show');

		new Ajax.Updater('homeFeatured', 'index.php?pageId=12', { method: 'get' });

		$('hometabs').style.display='block';
		opacity('hometabs', 0, 100, loadDelay);
		
		$('icons').style.display='block';
		$('findbutton').style.display='block';
		
		$('ajaxUpdater').innerHTML='';

		blendimage('homebg', 'blendimage', Pic[j],400, prevpic); 
		
		runshow=true;
		runSlideShow();
	} else 
		{ 
			//window.location.reload(); 
			window.location='index.php';	
		}
}


function loadSearchPage(page){


	if(page){ 

		$('homebg').style.backgroundImage = '';
		$('blendimage').style.backgroundImage = '';

		hideAll();
		//loadMainNav('nav2', 'PED/Baby Products')
		if(saveHistory) dhtmlHistory.add('loadpage' + page, page);
		

		

		runshow=false;
		clearTimeout(t);
		blendimage('homebg', 'blendimage', 'deimages/bgBlueShaded.gif',400,prevpic);
		//$('homebg').hide();
		$('homebox').className='bluehomebox';

		resetProductTabs();
		
		
		if(page == "all"){
			page = "&next=1&view=" + page;
		} else page = "&next=" + page;

		var url = 'index.php?pageId=28&mode=mod_laser&action=ajaxSearchResults' + page;
		
		blueMini();
		pfsearch = false;

		document.title='Search Results';
		ajaxLoading('catLandingContent');
		//new Ajax.Updater('catLandingContent', url, { method: 'get', evalScripts: true });

		$j.post(url, function(t){ $j('#catLandingContent').html(t); });
		
		$('miniFinder').style.display='block';
		$('prodFinderLeft').style.display='none';
		
		$('categoryLanding').style.display='block';
		
	}
}


function blueMini(){
	$('prodSearchFormABackTo').style.display='none';
	$('prodSearchFormAViewAllCont').style.display='block';
	$('prodSearchFormAViewAllCont').className='navPain';
	$('prodSearchFormANav1').className='navPain';
	$('prodSearchFormANav2').className='navPain';
	$('prodSearchFormANav3').className='navPainTall';
}

function loadNav(tab, staylit, productId, productCategoryId, pageId){
	
	//alert(tab + ', ' + staylit + ', ' + productId + ', ' + productCategoryId);
	resetProductTabs();

	var section = tab;
	if($('homebox') && IE6 == false){
		var complexObject = new Object();
			complexObject.tab = tab;
			complexObject.staylit = staylit;
			complexObject.productId = productId;
			complexObject.productCategoryId = productCategoryId;

		if(tab != "search"){
			var hist='page'+tab;
		} else {
			var hist='page'+tab+searchJs;
			searchJs++;
		}

		if(tab == "products") {
			var hist='pageproducts'+productId;
		}

		if(saveHistory) dhtmlHistory.add(hist, complexObject);


		if(tab != "productFinder"){
			runshow=false;
			clearTimeout(t);

			blendimage('homebg', 'blendimage', 'deimages/bgBlueShaded.gif',400,prevpic);
			$('homebox').className='bluehomebox';
			
			if(tab =="search" || tab == "products" || tab == "searchall"){
				var reset='yes';
			} else var reset='';

			hideAll(reset);

			if(staylit) staylit.className="navrightlinklit";
			if(staylit && tab == 'whatsNew') staylit.className="whatsNewLinkLit";
		}
	
		switch (tab){

			case "categoryLanding":
				$('categoryLanding').style.display='block';
				$('newsTabs').style.display='block';
			break;


			case "pfsearch":
				resetAllNavs(); 
				pfsearch = true;

				$('PFBackTo').style.display='none';
				if($('miniFinder')) $('miniFinder').style.display = 'none';
				$('overlay').style.display = 'none';
				$('fullScreenPopup').style.display = 'none';
				if($('prodFinderLeft')) $('prodFinderLeft').style.display='block';
	
				document.title='Search Results';
				ajaxLoading('catLandingContent');
				new Ajax.Updater('catLandingContent', 'index.php?pageId=28&mode=mod_laser&action=ajaxSearchResults&next=1', { method: 'post', evalScripts: true });
				$('categoryLanding').style.display='block';
			break;

			case "search":
				blueMini();
				pfsearch = false;

				document.title='Search Results';
				ajaxLoading('catLandingContent');
				new Ajax.Updater('catLandingContent', 'index.php?pageId=28&mode=mod_laser&action=ajaxSearchResults&next=1', { method: 'post', evalScripts: true });
				
				$('miniFinder').style.display='block';
				$('prodFinderLeft').style.display='none';
				
				$('categoryLanding').style.display='block';
			break;

			case "searchall":
				document.title='Search Results';
				pfsearch = false;

				blueMini();

				ajaxLoading('catLandingContent');
				new Ajax.Updater('catLandingContent', 'index.php?pageId=28&mode=mod_laser&action=ajaxSearchResults&next=1&mode=searchall&view=all', { method: 'post', evalScripts: true });

				$('miniFinder').style.display='block';
				$('prodFinderLeft').style.display='none';

				$('categoryLanding').style.display='block';

			break;

			case "products":
				
				if(productCategoryId){
					/* when loading a product it should reset the nav & left search to match category defined */
					resetAllNavs();

					$('nav'+productCategoryId+'txt').onmouseover='';
					$('nav'+productCategoryId+'txt').onmouseout='';
					$('nav'+productCategoryId+'txt').className='navitemLit';
					
					resetCatSearch(productCategoryId);
					
					var navTitle=$('nav'+productCategoryId+'link').innerHTML;
					var formname = 'prodSearchFormA';
					if($(formname+'Title')) $(formname+'Title').innerHTML=navTitle;
					if($(formname+'ViewAll')) $(formname+'ViewAll').innerHTML= 'View All '+navTitle;
					if($(formname+'filterTitle2')) $(formname+'filterTitle2').innerHTML= 'Filter '+navTitle;
				}

				ajaxLoading('productUpdateDiv');
				$('productDetailTab').innerHTML='';

				//new Ajax.Updater('mainNavigation', 'index.php?pageId=28&mode=mod_laser&action=showMainNavigation&productId='+productId, { method: 'get' });

				new Ajax.Request('index.php?pageId=28&mode=mod_laser&action=showProduct&productId='+productId, {
					method:'get',
					onSuccess: function(transport){
						$('productUpdateDiv').innerHTML=transport.responseText;
						transport.responseText.evalScripts();
						initialize();
					}
				  });


				new Ajax.Request('index.php?pageId=28&mode=mod_laser&action=showProductTabs&productId='+productId, {
					method:'get',
					onSuccess: function(transport){
						$('productDetailTab').innerHTML=transport.responseText;
						$('navProducts').style.display='block';
						$('productTabs').style.display='block';
						//alert($('productTabs').innerHTML);
						opacity('productTabs', 0, 100, loadDelay);
					}
				  });

				if(pfsearch){
					$('prodFinderLeft').style.display='block';
					$('PFBackTo').style.display='block';
				} else {
									/* reset mini search to color for this section */
					$('prodSearchFormAViewAllCont').style.display='none';
					$('prodSearchFormABackTo').style.display='block';
					$('prodSearchFormABackTo').className='navPain';
					$('prodSearchFormANav1').className='navPain';
					$('prodSearchFormANav2').className='navPain';
					$('prodSearchFormANav3').className='navPainTall';
				
					$('miniFinder').style.display='block';
					$('prodFinderLeft').style.display='none';
				}


			break;

			case "productList":
				$('navBlueProducts').style.display='block';
				$('newsTabs').style.display='block';
			break;



			/* these pages load into the ajaxUpdater div, they were not loaded onload */
			case "newsresources":
				document.title='Case Studies';
				ajaxLoading('ajaxUpdater', 'loadingNews');
				new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxNews&newsPage=9&next=1', { method: 'get' , evalScripts: true  });
				$('ajaxUpdater').style.display='block';
			break;

			case "generic":
				ajaxLoading('ajaxUpdater', 'loadingNews');
				new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadGeneric&loadPage=23', { method: 'get' , evalScripts: true  });
				$('ajaxUpdater').style.display='block';
			break;

			case "orderInfo":
				ajaxLoading('ajaxUpdater', 'loadingNews');
				new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxInformation&loadPage=33&productId='+productId, { method: 'get' , evalScripts: true  });
				$('ajaxUpdater').style.display='block';
			break;

			case "moreInfo":
				ajaxLoading('ajaxUpdater', 'loadingNews');
				new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxInformation&loadPage=34&productId='+productId, { method: 'get' , evalScripts: true  });
				$('ajaxUpdater').style.display='block';
			break;
			case "whatsNew":
				//alert('ajax' + pageId);
				document.title='What\'s New';
				ajaxLoading('ajaxUpdater', 'loadingNews');
				new Ajax.Updater('ajaxUpdater', 'index.php?pageId=28&mode=mod_laser&action=loadAjaxWhatsNew&whatsNewPage=' + pageId, { method: 'get' , evalScripts: true  });
				$('ajaxUpdater').style.display='block';
			break;
		}
	} else {
		/* 
			User has Javascript but isnt on the home page
				- go directly to pages		*/
		switch (tab){
			case "products":
				window.location='index.php?pageId=25&mode=mod_laser&action=showProduct&productId='+productId;
			break;
			case "pfsearch":
				window.location='index.php?pageId=135&next=1';
			break;
			case "search":
				window.location='index.php?pageId=27&next=1';
			break;
			case "searchall":
				window.location='index.php?pageId=27&mode=searchall&next=1&view=all';
			break;
			case "newsresources":
				window.location='index.php?pageId=9&next=1';
			break;
			case "adultproducts":
				window.location='index.php?pageId=9';
			break;
			case "generic":
				window.location='index.php?pageId=23';
			break;
			case "productFinder":
				popup('fullScreenPopup');
			break;
			case "orderInfo":
				window.location='index.php?pageId=33&productId='+productId;
			break;
			case "moreInfo":
				window.location='index.php?pageId=34&productId='+productId;
			break;
			case "whatsNew":
				window.location='index.php?pageId='+pageId;
			break;
		}
	}


}



/* 
	slide show js from: http://www.codelifter.com/main/javascript/slideshow2.html
	adapted to use the fade js 

*/


function loadSlideSection(section){
	var loadpic=Pic[section-1];
	var prevpic =Pic[j];
	clearTimeout(t);
	blendimage('homebg', 'blendimage', loadpic,400,prevpic); 
}



function runSlideShow(){
	var loadpic=Pic[j];
	var prevpic =Pic[j-1];
	
	if (runshow == true){
		blendimage('homebg', 'blendimage', loadpic,400,prevpic); 

		j = j + 1
		if (j > (p-1)) j=0
		  
		t = setTimeout('runSlideShow()', slideShowSpeed)
	}
	Pic[-1] = 'deimages/bgSpecial.jpg'

}

function resetItem(item){
		var sel = $(item);
		if(sel){
			for (var i=0;i<sel.options.length;i++) {
				sel.options[i].selected = false;
			}
			sel.options[0].selected = true;
		}
}
function resetText(item, match){
	if(item.value == match) item.value='';
}


function searchByFormat(formatId){
	if(formatId == "clear"){
		var pars = 'formatId=clear';
	} else {
		var enable = $('item'+formatId).checked;
		var pars = 'formatId='+escape(formatId)+'&enable='+escape(enable);
	}
	ajaxLoading('fullScreenUpdate', 'loadingSearchFormat');
	$('fullScreenView').style.display='none';
	new Ajax.Updater('fullScreenUpdate', 'index.php?pageId=28&action=searchResultsAdvanced', { method: 'get', parameters: pars, evalScripts: true });


}

function resetFilters(reset, dontsend){
		resetItem(reset+'Format');
		resetItem(reset+'Print');
		resetItem(reset+'Solutions');
		if(!dontsend) $(reset).submit();
}

function doSearch(formname){
	var format=$(formname+'Format').value;
	var print=$(formname+'Print').value;
	var solutions=$(formname+'Solutions').value;

    var pars = 'format='+escape(format)+'&print='+escape(print)+'&solutions='+escape(solutions);
	new Ajax.Updater(formname+'Results', 'index.php?pageId=28&action=searchResults&formname='+formname, { method: 'post', parameters: pars, evalScripts: true });
}




/* load the slide show and images */
function onLoad(){

	var preLoad = new Array()
	for (i = 0; i < preload; i++){
	   preLoad[i] = new Image()
	   preLoad[i].src = picDir+PreloadImages[i]
	}

	initMenus();

	initializeAjaxHistory();

	if($('homebox')){

	/* find all popups and set them to be opacity */
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i < divs.length; i++){
		var thisDiv=divs[i];
		if(thisDiv.id){
			var myclass=thisDiv.className;			
			
			if (myclass == "popup" || myclass == "bottomArrow"){
				changeOpac("90", thisDiv.id);
			} else if(myclass == "fulltab"){
				changeOpac("0", thisDiv.id);
			} else if(myclass == "prodIcon"){
				changeOpac("35", thisDiv.id);
			}
		}
	}
	changeOpac("90", "backgroundCover");
	changeOpac("90", "forwardBox");

		new Ajax.Updater('homeTab', 'index.php?pageId=4', { method: 'get' });
		if(IE6 == false){
			preLoad;
			//Pic[-1] = '';
			runSlideShow();
		}
	}
	
	if($('prodTabFeatures')) $('prodTabFeatures').style.display='block';

}


/* change images, show tabs, update icon list */
function blendimage(divid, imageid, imagefile, millisec, prev) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

	if($(imageid)){

		$(divid).style.backgroundImage= "url(" + picDir+prev + ")"; 
		$(divid).style.backgroundRepeat= "no-repeat"; 
		changeOpac(0, imageid);
		
		$(imageid).style.backgroundImage= "url(" + picDir+imagefile + ")"; 
		$(imageid).style.backgroundRepeat= "no-repeat"; 

		/* show/hide images + buttons */

		
		if(imagefile == "deimages/bgBaby.jpg"){
			$('icon1').className='iconButtonLit';	
			$('popupBaby').style.display='block';	
			$('popupBaby2').style.display='block';	
		} else {
			$('popupBaby').style.display='none';	
			$('popupBaby2').style.display='none';	
			$('icon1').className='iconButton';	
		}

		 
		if(imagefile == "deimages/bgAdult.jpg"){
			$('popupAdult').style.display='block';	
			$('icon2').className='iconButtonLit';	
		} else {
			$('popupAdult').style.display='none';	
			$('icon2').className='iconButton';	
		}


		if(imagefile == "deimages/bgChart.jpg"){
			$('popupChart').style.display='block';	
			$('icon3').className='iconButtonLit';	
		} else {
			$('popupChart').style.display='none';	
			$('icon3').className='iconButton';	
		}


		if(imagefile == "deimages/bgSpecial.jpg"){
			$('popupSpecial').style.display='block';	
			$('icon4').className='iconButtonLit';	
		} else {
			$('popupSpecial').style.display='none';
			$('icon4').className='iconButton';	
		}

		prevpic=imagefile;

		opacity(imageid, 0, 100, loadDelay);
	}
}