/******************
CM_ADD-IN - setactive (last updated: 09/13/02)

This works in all browsers and enables you
to set another className for the menu that's
active. 

There are to ways to do this, either you set it 
manually or you add the line that makes it work
automaticly...

Arguments
name - the name of the item you want to set active
 - If you leave out the name, the script will *try*
 to do this automaticly, by adding the active
 name to the end of the url, the recieving it
 again after a click..
regClass - the className that you want the item to have
overClass - the overClass name you want (not required)
setParent - If you set this it will set the classes
	also to the parent element. Which means that if 
	the active element is in level 2 it will also
	set the parent level 1 element AND the parent
	level 0 element.

This does not work on the frames version yet.. At least
not properly.

Just add this code to the coolmenus js file
or link the cm_addins.js file to your page as well.
*****************/
makeCM.prototype.setactive = function(name,regClass,overClass,setParent){
	var m,loc,url,sep,j,i

if(!name){ //No name - so we look for a name - and set it to auto get name
//Set all menus
for ( var menu in this.m )
{
m = this.m[menu]
url = m.lnk
if(url){
if(url.indexOf("?")>-1) sep = "&"
else sep = "?"
m.lnk = url + sep + "cmactive=" + escape(m.name)
}
}

		//Trying to find if there's an active one now
		loc = location.search
		if(loc){
			if(loc.indexOf("cmactive=")>-1){ //We have an active one !!
				name = loc.substr(loc.indexOf("cmactive=")+9)
			}
		}		
	}
	m = this.m[name]
	if(!m){return}
	if(setParent){
		while(m.parent){
			this.setactive2(m,regClass,overClass,m.name)
			m = this.m[m.parent]
		}
		this.setactive2(m,regClass,overClass,m.name)
	}else this.setactive2(m,regClass,overClass,m.name)
}		
makeCM.prototype.setactive2 = function(m,regClass,overClass,name){
	//Find it in string so it will change for Netscape also (and for reuse browsers on the top level)
	var l,str,start,i,n
	l = m.lev
	if(!bw.reuse || l==0){
		if(!bw.usedom){
			str = this.l[l].str
			start = str.indexOf(name+'" class="'+m.cl+'"') 
			if(start >-1){ //If not --- problem :\
				str = str.replace(m.name+'" class="'+m.cl+'"',m.name+'" class="'+regClass+'"') 
				this.l[l].str = str
                               
			}
			if(overClass){
			str = this.l[l].str
			start = str.indexOf(name+'_1" class="'+m.cl2+'"') 
			if(start >-1){ //If not --- problem :\
				str = str.replace(m.name+'_1" class="'+m.cl2+'"',m.name+'_1" class="'+overClass+'"') 
				this.l[l].str = str
                               
			}
			}
	 
		}else{  //Find it for dom browsers
			for(i=0;i<this.l[0].m.length;i++){
				m = this.m[this.l[0].m[i]]
				if(m.name==name){
					n = i
					break;
				}
			}
			if(n>-1){ //Found it
				m.d2.className = regClass 
			
			}
		}
	}
	m.cl = regClass
	if(overClass) m.cl2 = overClass
}

