/* sxa rtraction */
/* rtraction 2008 */


/* used for htx top slide up items */
var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
	//debugger;
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  
  if(d == 1)
  {
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.top = '-' + c.offsetHeight + 'px';
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }

    ChangeImage('imgarrow'+id, '/images/secondary_menu_arrow_up.gif');

    c.timer = setInterval(function()
    {ddSlide(c,1,id)},DDTIMER);
  }else{
    ChangeImage('imgarrow'+id, '/images/secondary_menu_arrow_down.gif');
    h.timer = setTimeout(function(){ddCollapse(c,id)},50);
  }
}

function ChangeImage(id, imgsrc)
{
    document.getElementById(id).src = imgsrc;
}

// collapse the menu //x
function ddCollapse(c,id){
  c.timer = setInterval(function(){ddSlide(c,-1,id)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown cent //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1,id)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d,id){
  var currh = c.offsetHeight;
  var dist;
  var childofc = document.getElementById(id+'-innerbackground');

  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.top = parseInt(c.style.top.replace('px','')) - parseInt(dist * d) + 'px';
  if(c.style.top == "-1px")
  	c.style.top = "0px";
  	
  c.style.height = currh + (dist * d) + 'px';
  
  //alert(childofc.style.opacity);
  // get the control for background opacity
  childofc.style.opacity = currh / c.maxh  - 0.32;
  
  if(!window.Node)
  	childofc.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh - 32)  + ')';
  else
  	childofc.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh - 32) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

/* MS fix for radio buttons inside of repeaters */
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

/* Script for changing menu classes */
function ChangeClass(e, classn)
{
	if(e)
	{
	    if(classn != null)
	    {
		    if(e.className != "Active" &&
		        e.className != classn + " Active")
		    {
		        e.className = classn;
		    }
		    else
		    {
		        e.className = classn + " Active";
		    }
		}
		else
		{
		    if(e.className != "Active" &&
		        e.className != "selected Active")
		    {
		        if(e.className == "selected")
		            e.className = "";
		        else
		            e.className = "selected";
		    }
		    else
		    {
		        if(e.className == "selected Active")
		            e.className = "Active";
		        else
		            e.className = "selected Active";
		    }
		}
	}
}

/* Script for changing menu classes */
function ChangeHTXClass(e)
{
	if(e)
	{    
	    if(e.className != "last signinhover htxselected")
	    {
		    if(e.className == "last signinhover")
		    {
			    e.className = "last signin";
		    }
		    else
		    {
			    e.className = "last signinhover";
		    }
		}
	}
}