/* ----------------------------- Quick find mod --------------------------------------- */
function set_select(this_idx)
{

  if ( this_idx != null)
    document.Search.Select_Agency.selectedIndex = this_idx;


}
/* ----------------------------- Quick find mod --------------------------------------- */


/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenu(obj,nest){
	nest=(!nest) ? "":'document.'+nest+'.';
   	this.css= bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;
	this.elm= bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
	this.ref= bw.dom || bw.ie4? document:bw.ns4?eval(nest+"document.layers." +obj+".document"):0;
	this.x= bw.ns4?this.css.left:bw.opera5?this.css.pixelLeft:this.elm.offsetLeft;
	this.y= bw.ns4?this.css.top:bw.opera5?this.css.pixelTop:this.elm.offsetTop;
	this.height= bw.ns4?this.ref.height:bw.opera5?this.css.pixelHeight:this.elm.offsetHeight;
	this.hideIt= b_hideIt;
	this.showIt= b_showIt;
	this.moveIt= b_moveIt;
	this.status= 0;
	return this;
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_moveIt(x,y){this.x=x; this.y=y; /*this.css.left=this.x+px;*/ this.css.top=this.y+px;}
/************************************************************************************
Initiating the page and making the menu
************************************************************************************/
function foldInit(){


	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (bw.opera5) bw.ns6 = 0
	
	//Creating the foldoutmenu
	oFold = new Array();
	y = 0;
	for (var i=0; i<mainmenus; i++){
		oFold[i] = new makeMenu('divFold'+i,'divFoldCont');
		oFold[i].moveIt(0,y);
		oFold[i].size = oFold[i].height;
		y += oFold[i].height+pxbetweenmain;
		if (bw.ns4) oFold[i].css.clip.bottom = 500;
		oFold[i].sub = new Array();
		oFold[i].subs = top_subs;
		suby = oFold[i].height+pxbetweensub;
		for (var j=0; j<submenus[i]; j++){
			oFold[i].sub[j] = new makeMenu('divFoldSub'+i+'_'+j,'divFoldCont.document.divFold'+i);
			oFold[i].sub[j].sub = new makeMenu('divFoldSub'+i+'_'+j+'_0','divFoldCont.document.divFold'+i+'.document.divFoldSub'+i+'_'+j);
			oFold[i].sub[j].hideIt();
			oFold[i].sub[j].sub.hideIt();
			oFold[i].sub[j].moveIt(10,suby);
			suby += oFold[i].sub[j].height+pxbetweensub;
		}
	}
  	oFoldCont = new makeMenu('divFoldCont');
	if (bw.ns4) oFoldCont.css.clip.bottom = 800;
  	oFoldCont.showIt(); //Showing the menu when the menu have been "created"


 
          if(  (idx_sub=cur_choice.indexOf("subfoldmenu(0,")) != -1 || cur_choice.indexOf("foldmenu(0)") != -1)

         {   

             foldmenu(0);
 
             //check if a subfolder in deeper menu level2 
             if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(0, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }

         }
         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(1,")) != -1 || cur_choice.indexOf("foldmenu(1)") != -1)
       {   

             foldmenu(1);
 
             //check if a subfolder in deeper menu level2 
             if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(1, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }

         }
         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(2,")) != -1 || cur_choice.indexOf("foldmenu(2)") != -1)
         {

             foldmenu(2); 
			  if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(2, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 
         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(3,")) != -1 || cur_choice.indexOf("foldmenu(3)") != -1)
         {
		 
             foldmenu(3); 
			  if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(3, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 

         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(4,")) != -1 || cur_choice.indexOf("foldmenu(4)") != -1)
         {
             foldmenu(4);
			  if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(4, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 
         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(5,")) != -1 || cur_choice.indexOf("foldmenu(5)") != -1)
         {
             foldmenu(5);
			 if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(5, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 

         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(6,")) != -1 || cur_choice.indexOf("foldmenu(6)") != -1)
         {
             foldmenu(6); 
			 if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(6, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 
         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(7,")) != -1 || cur_choice.indexOf("foldmenu(7)") != -1)
         {
             foldmenu(7); 
			 if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(7, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 

         else if(  (idx_sub=cur_choice.indexOf("subfoldmenu(8,")) != -1 || cur_choice.indexOf("foldmenu(8)") != -1)
         {
             foldmenu(8); 
			 if(idx_sub != -1)
             {
                  cur_sub_option = cur_choice.substring(idx_sub+14); //grab the 2nd arg 
                  idx = cur_sub_option.indexOf("\)");
                  subfoldmenu(8, parseInt(cur_sub_option.substring(0,idx)) ); // DO IT!!!

             }
         } 
         else if(  cur_choice.indexOf("subfoldmenu(9,") != -1 || cur_choice.indexOf("foldmenu(9)") != -1)
         {
             foldmenu(9); 
         } 

         else if(  cur_choice.indexOf("subfoldmenu(10,") != -1 || cur_choice.indexOf("foldmenu(10)") != -1)
         {
             foldmenu(10); 
         } 

         else if(  cur_choice.indexOf("subfoldmenu(11,") != -1 || cur_choice.indexOf("foldmenu(11)") != -1)
         {
             foldmenu(11); 
         } 

         else if(  cur_choice.indexOf("subfoldmenu(12,") != -1 || cur_choice.indexOf("foldmenu(12)") != -1)
         {
             foldmenu(12); 
         } 		 

         else if(  cur_choice.indexOf("subfoldmenu(13,") != -1 || cur_choice.indexOf("foldmenu(13)") != -1)
         {
             foldmenu(13); 
         } 
		 
         else if(  cur_choice.indexOf("subfoldmenu(14,") != -1 || cur_choice.indexOf("foldmenu(14)") != -1)
         {
             foldmenu(14); 
         } 
		 
         else if(  cur_choice.indexOf("subfoldmenu(15,") != -1 || cur_choice.indexOf("foldmenu(15)") != -1)
         {
             foldmenu(15); 
         } 		 		 
// --- end of  setup the menu properly from calling page

}
/************************************************************************************
Object function to the top of the menus.
************************************************************************************/
function top_subs(show, num){
	for (var j=0; j<this.sub.length; j++){
		if (show){
			this.sub[j].showIt()
			if (foldImg) this.ref["imgFold"+num].src = foldoutImg.src
			if (substayfolded){if(this.sub[j].sub.status) this.sub[j].sub.showIt()
			}else{
				if (foldImg) this.sub[j].ref["imgFold"+num+"Sub"+j].src = foldsubinImg.src
				this.sub[j].sub.hideIt()
			}
		}else{
			this.sub[j].hideIt()
			if (foldImg) this.ref["imgFold"+num].src = foldinImg.src
			if (!substayfolded) this.sub[j].sub.hideIt()
			else if (substayfolded) this.sub[j].sub.css.visibility="hidden"
		}
	}
}
/************************************************************************************
Checking height of the menus, and moves them to the correct position.
************************************************************************************/
function checkheight(org){
	if(mainstayfolded) istart=org; else istart=0
	for(i=istart;i<oFold.length;i++){
		oFold[i].size=oFold[i].height
		for(j=0;j<oFold[i].sub.length;j++){
			oFold[i].sub[j].size=oFold[i].sub[j].height+pxbetweensub
			if(oFold[i].sub[j].status){
				oFold[i].size+=oFold[i].sub[j].size
				if(oFold[i].sub[j].sub.status){
					oFold[i].size+=oFold[i].sub[j].sub.height+pxbetweensub
					oFold[i].sub[j].size+=oFold[i].sub[j].sub.height+pxbetweensub
				}
			}
			if(j!=0) oFold[i].sub[j].moveIt(10,oFold[i].sub[j-1].y+oFold[i].sub[j-1].size)
		}
		if(i!=0) oFold[i].moveIt(0,oFold[i-1].y+oFold[i-1].size+pxbetweenmain)
	}
}
/************************************************************************************
Fold in and out the submenus.
************************************************************************************/
function subfoldmenu(main,sub){


	if (!substayfolded){
		for (var i=0; i<oFold[main].sub.length; i++){
			if (i!=sub){
				oFold[main].sub[i].sub.hideIt();
				if (foldImg) oFold[main].sub[i].ref["imgFold"+main+"Sub"+i].src = foldsubinImg.src
			}
		}
	}
	if (!oFold[main].sub[sub].sub.status){
		oFold[main].sub[sub].sub.showIt()
		if(foldImg) oFold[main].sub[sub].ref["imgFold"+main+"Sub"+sub].src = foldsuboutImg.src
	}
	else{
		oFold[main].sub[sub].sub.hideIt()
		if(foldImg) oFold[main].sub[sub].ref["imgFold"+main+"Sub"+sub].src = foldsubinImg.src
	}
	checkheight(main)
}
/************************************************************************************
Fold in and out the mainmenus
************************************************************************************/
function foldmenu(num){
	if (!mainstayfolded){
		for(var i=0; i<oFold.length; i++){
			if(i!=num) oFold[i].subs(0,i)
		}
	}
	if (!oFold[num].sub[0].status) oFold[num].subs(1,num)
	else oFold[num].subs(0,num)
	checkheight(num)
}
//Initiating the menus onload, if the browser is ok.
if(bw.bw) onload = foldInit;



