function hidePage(id)
{
		obj=document.getElementById(id);
		obj.style.display="none";
//alert("Hide "+id);
}
function showPage(id)
{
		obj=document.getElementById(id);
		obj.style.display="block";
//alert("Show "+id);
}

function show(a) {
  str = '';
  for (i = 0; i != a.length; i++) {
    str = str + a[i].toString() + '\n';
  }
  alert(str);
}
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;

  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");

    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }

    }
  }

  return strReturn;
}

function openWindow(url)
{
var newwindow;
	newwindow=window.open(url,'_blank',' height=600, width=1000,  menubar=yes, toolbar=yes, location=yes, resizable=yes, scrollbars=yes, status=yes');
	if (window.focus) {newwindow.focus()}
}
function openSmallWindow(url,nam,wd,ht,lpad)
{
var aw;
var ah;
if (window.screen) {
    aw = screen.availWidth;
    ah = screen.availHeight;
  }

myimage=new Image();
myimage.src=url;
var name='name';
if (nam) { name=nam;}
if (wd > 0) {w=wd;}
else {w=myimage.width;}
if (ht > 0) { h=ht;}
else { h=myimage.height; }
th=ah;
if (h > ah) {
	tw=parseInt((ah/h)*w);
	xw=parseInt((ah/h)*w);
	th=ah
	}
else {
	tw=w;
	xw=w;
	th=h;
	}
if (lpad) { lft=lpad;}
else { lft=parseInt((aw-xw)/2);}
//alert(url + "," + nam + "," + wd + "," + ht + "," + lpad+" aw:"+aw + " ah:" + ah + " w:" + w + "  h:"+h+" tw:"+tw+" xw:"+xw);
var options='left='+lft+', width='+tw+' , height='+th+', menubar=no,toolbar=no, location=no, resizable=no, scrollbars=no, status=no';
var newwindow;
	newwindow=window.open(url,name,options);
	if (window.focus) {newwindow.focus()}
}

// //////////////////////////////////////////////////////////////////////
function setActiveState(){

  var menu=(getURLParam("menu"));  
  var sub1=(getURLParam("sub1"));  
  var sub2=(getURLParam("sub2"));
  var changeColor="#b37533"; //"bd9247"; //"#f8cb2b";
  //var changeColor="#000000"; //"bd9247"; //"#f8cb2b";

  var x="";
  var CURR_MENU;
	var spc=40;

  if (menu != "") {
	x="sm_"+menu;
	// change the color of the link based on browser type
	CURR_MENU=document.getElementById(x);
  	if( document.getElementsByTagName ) { //Mozilla
		CURR_MENU.style.color=changeColor;
		CURR_MENU.style.fontWeight="bold";
	} 
	else { 
		alert("A");
		setStyleById(x,"color",changeColor);
		setStyleById(x,"fontWeight","bold");
	}
	//document.getElementById(x).style.backgroundColor="#e6e6e6";

	// find how many items on the main "menu" list, the length and avg width
	var mainmenu_count=document.getElementById("menu").getElementsByTagName("a").length;
	var mainmenu_length=displayObjPropByName("menu","offsetWidth");
	var mainmenuitem_width= mainmenu_length / mainmenu_count;

 
	var menu_x=displayObjPropByName("menu","offsetLeft");

	var x_left, menu_loc, loc, wdth, xloc, new_TotalWidth, x_left, fldW, fldX
	var ttlWidth, tmany, wmany;
	var s1_many, s1_length, s2_many, s2_length;

	// number of items on the sub1 menu
	tmany=document.getElementById("sub1").getElementsByTagName("a").length ;
	wmany=document.getElementById("sub1").id ;
	s1_many=document.getElementById("sub1").getElementsByTagName("a").length ;
	//s1_length=displayObjPropByName("sub1","offsetWidth");
	s1_length=document.getElementById("sub1").offsetWidth;
	//alert("count:"+mainmenu_count+" mainmenu_length:"+mainmenu_length+" s1_many:"+s1_many+" s1_length:"+s1_length);

	//find all the elements of "sub1" sub-menu
   
	var divs = document.getElementById("sub1").getElementsByTagName("a");
	ttlWidth=0;
	for(var i=0; i < divs.length; i++)
	{
		var div = divs[i];
		var id = div.id;
		document.getElementById(id).style.width="";//needed to trick mozilla

		var a=document.getElementById(id).offsetWidth;
		var b=document.getElementById(id).offsetParent.offsetWidth;
		if (document.all) { ttlWidth+=b; } //ie
		else { ttlWidth+=a;}
		//alert("a:"+a+"    b:"+b);
		//document.getElementById(id).style.backgroundColor="#e6e6e6";//alert(id+" w:"+a);
		document.getElementById(id).style.whiteSpace="nowrap";//alert(id+" w:"+a);
	}

	//alert("ttlWidth:"+ttlWidth);

	fldW=mainmenu_length/mainmenu_count;
	fldX=s1_length/s1_many;
	if (document.all) { //ie
		x_left=displayObjPropByName(x,"offsetParent").offsetLeft;
		wdth=ttlWidth+(5*(s1_many)); 
		menu_loc=x_left +(fldW/2) - (ttlWidth/2);  //link pressed
		loc=menu_loc ;
	}
	else {
		x_left=displayObjPropByName(x,"offsetLeft")-menu_x;

		wdth=ttlWidth+(10*(s1_many)); 
		menu_loc=x_left  +(fldW/2) - (wdth/2);  //link pressed
		loc=menu_loc ;
	}


	// try to pad left with ... assume average fld width=90px

	new_TotalWidth= (loc + wdth ) ;
	xloc=loc;

	if (new_TotalWidth > s1_length) {
		xloc= loc - ((new_TotalWidth - s1_length));
	}
	if (xloc < 0) xloc=0;
	xloc= xloc+"px";
	wdth=wdth + "px";

	//alert("loc:"+loc+"  x_left:"+x_left+"  wdth:"+wdth);

	//alert("menu_x  "+xloc);
	//  WE HAVE TO FIX Setting STYLE IN IE.
       if( document.getElementsByTagName ) { 
		obj=document.getElementById("sub1");
		obj.style.paddingLeft=xloc;
		obj.style.width=wdth;
	}
	else {
		setStyleById("sub1","paddingLeft",xloc);
		setStyleById("sub1","width",wdth);
	}

	//alert (wmany+"   menuitem:"+menuitem_width+"   xloc:"+xloc+"   menu_loc:"+menu_loc+"  NTW:"+new_TotalWidth+"    loc:"+loc+" tmany:"+tmany+" width:"+wdth);

	if (sub1 != "") {
		x=x+"_"+sub1;

        	obj=document.getElementById(x);

		// change from darkbrown/bold to black/normal on 2/15/2008
  		if( document.getElementsByTagName ) { 
			obj.style.color="#000000"; //changeColor;
			//obj.style.fontWeight="bold";
		} //MOZILLA
		else { 
			alert("A");
			setStyleById(x,"color",changeColor);
			setStyleById(x,"fontWeight","bold");
		}
//alert(x);




	s2_many=document.getElementById("sub2").getElementsByTagName("a").length ;
	s2_length=document.getElementById("sub2").offsetWidth;

	//find all the elements of "sub1" sub-menu
   
	var divs = document.getElementById("sub2").getElementsByTagName("a");
	ttlWidth=0;
	for(var i=0; i < divs.length; i++)
	{
		var div = divs[i];
		var id = div.id;
		var a=document.getElementById(id).offsetWidth;
		var b=document.getElementById(id).offsetParent.offsetWidth;
		if (document.all) { ttlWidth+=b; } //ie
		else { ttlWidth+=a;}
		//alert("a:"+a+"    b:"+b);
		//document.getElementById(id).style.backgroundColor="#e6e6e6";//alert(id+" w:"+a);
		document.getElementById(id).style.whiteSpace="nowrap";//alert(id+" w:"+a);
	}

	//alert("ttlWidth:"+ttlWidth);

	fldW=s1_length/s1_many;
	fldX=s2_length/s2_many;
	if (document.all) { //ie
		x_left=displayObjPropByName(x,"offsetParent").offsetLeft;
		wdth=ttlWidth+(5*(s2_many)); 
		menu_loc=x_left +(fldW/2) - (ttlWidth/2);  //link pressed
		loc=menu_loc ;
	}
	else {
		x_left=displayObjPropByName(x,"offsetLeft")-menu_x;

		wdth=ttlWidth+(5*(s2_many)); 
		menu_loc=x_left  +(fldW/2) - (wdth/2);  //link pressed
		loc=menu_loc ;
	}


	// try to pad left with ... assume average fld width=90px

	new_TotalWidth= (loc + wdth ) ;
	xloc=loc;

	if (new_TotalWidth > s2_length) {
		xloc= loc - ((new_TotalWidth - s2_length));
	}
	if (xloc < 0) xloc=0;
	xloc= xloc+"px";
	wdth=wdth + "px";

	//alert("loc:"+loc+"  x_left:"+x_left+"  wdth:"+wdth);

	//alert("menu_x  "+xloc);
	//  WE HAVE TO FIX Setting STYLE IN IE.
      if( document.getElementsByTagName ) { 
		obj=document.getElementById("sub2");
		obj.style.paddingLeft=xloc;
		obj.style.width=wdth;
	}
	else {
		setStyleById("sub2","paddingLeft",xloc);
		setStyleById("sub2","width",wdth);
	}

	//alert (wmany+"   menuitem:"+menuitem_width+"   xloc:"+xloc+"   menu_loc:"+menu_loc+"  NTW:"+new_TotalWidth+"    loc:"+loc+" tmany:"+tmany+" width:"+wdth);


		if (sub2 != "") {
			x=x+"_"+sub2;
	        	obj=document.getElementById(x);

  			if( document.getElementsByTagName ) { 
				obj.style.color=changeColor;
				obj.style.fontWeight="bold";
			} //MOZILLA
			else { 
				alert("A");
				setStyleById(x,"color",changeColor);
				setStyleById(x,"fontWeight","bold");
			}
		}


	}
	
  }

//    for(var i in obj){
// 	alert("A:"+i+" " +obj[i]);
//    }

 
  //return true;

}
function displayObjPropByName(nm,typ){
var pete;

var obj=document.getElementById(nm);
    for(var i in obj){
 	if (i==typ) pete=obj[i];
    }

	return pete;
}


function findPosition( oLink ) {



var mylist=document.getElementById("menu");
alert("nav:"+nav+" - mylist"+mylist.length);


  if( oLink.offsetParent ) {

    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;

    }
    //alert (posX+" . "+posY);
    return {x: posX, y:posY };

  } else {
    //alert(oLink.x+" - "+oLink.y);
    return { x: oLink.x, y: oLink.y };
  }
}


