/* IF NOT IN FRAME LOAD FRAME FOR SOUND */

if(top.frames.length==0 && document.URL.indexOf("sound=yes")==-1){
	
	document.write('<frameset rows="*,0" frameborder="0">'+
	'<frame name="main" src="'+document.URL+'?sound=yes" frameborder="0" marginheight="0" marginwidth="0" resizeable="no" />'
	+'<frame id="sframe" name="soundframe" src="sound.htm" frameborder="0"  marginheight="0" marginwidth="0" resizeable="no" />'
	+'</frameset>');
	
}



var fx = new Array();var fx2 = new Array();var fx3 = new Array(); dropfx = new Array();dropfx2 = new Array();
var lastTab=0;

var soundplaying = ReadCookie("soundplaying");
window.addEvent('domready', function(){
			// REPLACE SELECT TAGS WITH FANCY DROP DOWNS
			dropdown('baseprod', 'selectboxes');
			dropdown('industry', 'selectboxes');
			dropdown('fda', 'selectboxes');
			
			// RESET CSS STYLE DISPLAY TO AUTO FOR ULs
			var uls = $$('#nav li.off ul');
			uls.each(function(element) { element.style.display="block"; });
			
			// ADD EFFECT TO NAVIGATION
			var list = $$('#nav a.topnavlink');
			
			list.each(function(element) {
				i=element.id.match(/\d+/);
				if(i>0){
					if($('nav'+i)){ // IF HAS SUBITEMS ADD DROP DOWN
						fx[i] = new Fx.Slide($('nav'+i), {duration: 500, wait: false, mode: 'vertical', onComplete: function(el){
								slideInAllExcept1(); }}).hide();
						fx2[i] = new Fx.Style($('nav'+i), 'opacity', {duration: 800, wait: false});
                		
						$('topnav'+i).addEvent('mouseenter', function(){
							
							$('topnav'+element.id.match(/\d+/)).addClass("over");
							fx[element.id.match(/\d+/)].slideIn();
							fx2[element.id.match(/\d+/)].start(0,1);

							lastTab = element.id.match(/\d+/);
						});
						$('topnav'+i).addEvent('mouseleave', function(){ 
							fx[element.id.match(/\d+/)].slideOut();
							fx2[element.id.match(/\d+/)].start(1,0);
							$('topnav'+element.id.match(/\d+/)).removeClass("over");
						});
					} else { // IF EMPTY ONLY ADD CLASS ONMOUSEOVER
						$('topnav'+i).addEvent('mouseenter', function(){
							$('topnav'+element.id.match(/\d+/)).addClass("over");
							lastTab = element.id.match(/\d+/);
						});			
						$('topnav'+i).addEvent('mouseleave', function(){ 
							$('topnav'+element.id.match(/\d+/)).removeClass("over");
						});			
					}
				}
			});
			
			// OPEN CURRENT SECTION IN NAVIGATION -> HAS CLASS ON
			if($E('#nav li.on')){
			ul = $E('#nav li.on'); 
				fx[ul.id.match(/\d+/)].show();
				fx2[ul.id.match(/\d+/)].start();
			}
			
			// ADD ONCLICK FUNCTIONALITY TO SEARCH FIELDS
			$('fulltext').onclick = function(){	if(this.title=this.value) this.value="";}
			$('prodname').onclick = function(){	if(this.title=this.value) this.value="";}
			
			
			
			/* SET SOUND CONTROL */
// 			$('soundcontrol').addEvent('click', function(el){ togglesound(); }	);
			// SET STATE OF BUTTON

			
// 			if(soundplaying=="false"){
// 				top.frames[1].startstopsound(false);$('soundcontrol').src="img/soundoff.gif";
// 			}
	
});


function slideInAllExcept1(){
	var list = $$('#nav a.topnavlink');
	
	list.each(function(element) {
			i=element.id.match(/\d+/);
			if(fx[i]){
				if(i>0 && Math.abs(i)!=Math.abs(lastTab)){
					fx[i].hide();
					fx2[i].set(0);
				}
			}
	});	
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function dropdown(id, rootid){
	
	var selecttag = $(id);
	var roottag = $(rootid);
	
	var list = $$("#"+id+" option");
	var numitems = list.length;
	

	var fieldname = selecttag.name;
	var items = new Array(numitems);
	var values = new Array(numitems);var selected = new Array(numitems); var toupdate;
	i=0;
	list.each(function(element) {
			items[i] = element.innerHTML; 
			values[i] = element.value;
			if(element.selected)
			selected[i] = true; else selected[i] = false; 
			i++;
	});
	
	var dropdown = document.createElement('div');
	 	dropdown.className = "selectfield";
		dropdown.id = id+"-div";
	
	var hiddenfield = generateINPUT("hidden",fieldname,"","","",id+"-hide");
		dropdown.appendChild(hiddenfield);
	
	var labelspan = document.createElement('span');
		labelspan.className ="label";
		labelspan.id = id+"-label";
		var labelspan2 = document.createElement('span');
		labelspan2.appendChild(document.createTextNode(items[0]));
		labelspan.appendChild(labelspan2);
		dropdown.appendChild(labelspan);
		
	var wrapper = document.createElement('div');
	 	wrapper.className = "wrapper";
		wrapper.id = id+"-wrapper";	
	var ullist = document.createElement('ul');	
		ullist.id = id+"-ul";
	
	toupdate = "##";
	for(p=1; p<numitems; p++){
		var liitem = document.createElement('li');
		liitem.onclick = function(){	
			updateDropDown(id, this);
		};
		liitem.innerHTML=items[p];
		liitem.title = values[p];
		ullist.appendChild(liitem);
		if(selected[p]) toupdate = liitem;
	}
	
	
	wrapper.appendChild(ullist);
	dropdown.appendChild(wrapper);
	
	dropfx2[id]=false; 
	dropfx[id] = new Fx.Slide(wrapper, {onComplete: function(){ if(dropfx2[id]){ dropfx2[id]=false;}else{dropfx2[id]=true;}} }).hide();
	
	labelspan.onclick= function(){
		dropfx[id].toggle();
	};
	dropdown.mouseout = function(){
		dropfx[id].hide();
	};
	
		
	roottag.appendChild(dropdown);
	roottag.removeChild(selecttag);
	
	// SELECT WHAT WAS POSTED (i.e. is selected)
    if(toupdate!="##") updateDropDown(id, toupdate);
}

function generateINPUT(type,name,value,classname,title,id){
	var input = document.createElement('input');
	input.type   	= type;
	input.name 		= name;
	input.id 			= id;
	input.value 	= value;		
	input.title 	= title;		

	return(input);
}

function updateDropDown(id, element){
	
	var ullist = element.parentNode.getElementsByTagName("li");
	
	// IF FIRST SELECT PUT LABEL IN LIST:
	if($(id+'-hide').value ==""){
	var label = document.createElement('li');
		label.title = "";
		label.innerHTML = $(id+"-label").firstChild.innerHTML;
		label.style.fontWeight = "bold";
		label.style.fontStyle = "italic";
		label.style.paddingLeft = "2px";
		label.onclick = function(){	
			updateDropDown(id, this);
		};
		element.parentNode.insertBefore(label, ullist[0]);
		dropfx[id].show();
	}
	$(id+"-label").firstChild.innerHTML = element.innerHTML;
	
	$(id+'-hide').value = element.title;	
	

	
	for(var i=1; i< ullist.length; i++){
		ullist[i].style.fontWeight ="normal";
	}
	
	// MARK SELECTED ITEM
	element.style.fontWeight = "bold";
	dropfx[id].hide();
	
	// IF LABEL FIRST NEWLY SELECTED REMOVE IT FROM LIST:
	if(element.title==""){
		element.parentNode.removeChild(element);
	}
	
}



// var soundon = true;
// function togglesound(){
// 	if(soundon){
// 		SetCookie("soundplaying","false",1/2);
// 		soundon = false;
// 		top.frames[1].startstopsound(false);
// 		$('soundcontrol').src="img/soundoff.gif";
// 		
// 	} else {
// 		SetCookie("soundplaying","true",1/2);
// 		soundon = true;
// 		top.frames[1].startstopsound(true);		
// 		$('soundcontrol').src="img/soundon.gif";		
// 	}
// }


// SEND FORM UPON ENTER
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

