// Variables
IsExMenuOn = false;
ActiveSubmenuID = "";
ActiveDisplayID = "";
ActiveDisplayImage = "";

// Handle the mouse over for submenu items.
function ExSubmenuMouseover(src)
{
    submenuicon = eval(src + "_sm");
    submenuspacer1 = eval(src + "_sp1");
    submenuspacer2 = eval(src + "_sp2");
    submenutext = eval(src + "_st");

    // Highlight the cells.
    submenuicon.className = "submenutable_iconover";
    submenuspacer1.className = "submenutable_sp1over";
    submenuspacer2.className = "submenutable_sp2over";
    submenutext.className = "submenutable_over";
}

// Handle the mouse out event for submenu items.
function ExSubmenuMouseout(src)
{
    submenuicon = eval(src + "_sm");
    submenuspacer1 = eval(src + "_sp1");
    subspacer2 = eval(src + "_sp2");
    submenutext = eval(src + "_st");

    // Clear the highlighting.
    submenuicon.className ="submenutable_icon";
    submenuspacer1.className = "submenutable_sp1";
    submenuspacer2.className = "submenutable_sp2";
    submenutext.className ="submenutable";
}

function SubmenuMouseover(e)
{
    // Set the cursor.
    //e.style.cursor = "default";
    // Highlight the cell.
    e.style.backgroundColor="#BDDBFF";
}

// Handle the mouse out event for submenu items.
function SubmenuMouseout(e)
{
    // Clear the highlighting.
    e.style.backgroundColor='#F7F7F7'
    e.style.color = "#000000";
}

// Starting with the given node, find the nearest containing element
// with the specified tag name.
function getContainerWith(node, tagName, id)
{
    while (node != null) {
    if (node.tagName != null && node.tagName == tagName && node.id == id)
    return node;
    node = node.parentNode;
    }
    return node;
}
    
// Special function for ToolbarExercise mouseout to prevent it from going to normal during showmenu.
function mouseoutToolbarExercise()
{
    if (IsExMenuOn == true)
        return;
    changePicture("ToolbarExercise", "images/toolbarstart.gif");
}

// Special function for ToolbarExercise mouseover to prevent it from going to normal during showmenu.
function mouseoverToolbarExercise()
{
    if (IsExMenuOn == true)
        return;

    changePicture("ToolbarExercise", "images/toolbarstart_over.gif");
}

// Special function for ToolbarExercise mousedown to prevent it from going to normal during showmenu.
function mousedowmToolbarExercise()
{
    if (IsStartMenuOn)
        StartMenuHide();

    if (IsExMenuOn != true)
    {
        changePicture('ToolbarExercise','images/toolbarstart_clicked.gif');
        ExMenuShow();    
    }        
    else
    {
        ExMenuHide();
        changePicture("ToolbarExercise", "images/toolbarstart_over.gif");
    }
}

// Show the main exercise menu.
//
function ExMenuShow()
{
    var e = document.getElementById('ToolbarExercise');
    var m = document.getElementById('ExMenu');
    m.style.left = getPageOffsetLeft(e) - 4;
    m.style.top = getPageOffsetTop(e) - 194-33-15;
    m.style.display = "";
    IsExMenuOn = true;
}

// Hide the main exercise menu.
function ExMenuHide()
{
    // Hide active.
    if (ActiveSubmenuID != "")
        ExMenuHideSub(ActiveSubmenuID);
        
    ActiveSubmenuID = "";
    
    // Unhighlight active.
    if (ActiveDisplayID != "")
        changePicture(ActiveDisplayID, (ActiveDisplayImage + ".gif"));
        
    ActiveDisplayID = "";
    ActiveDisplayImage = "";
    
    var m = document.getElementById('ExMenu');
    m.style.display = "none";
    
    IsExMenuOn = false;
    changePicture("ToolbarExercise", "images/toolbarstart.gif");
}

function ExMenuShowSub(DisplayID, SubmenuID, ImageName)
{
    // Hide active.
    if (ActiveSubmenuID != "")
    ExMenuHideSub(ActiveSubmenuID);
    
    // Unhighlight active.
    if (ActiveDisplayID != "")
    changePicture(ActiveDisplayID, (ActiveDisplayImage + ".gif"));
    
    // Highlight the Display.
    changePicture(DisplayID, (ImageName + "_over.gif"));
    ActiveDisplayImage = ImageName;
    ActiveDisplayID = DisplayID;
    
    // Show the submenu.
    ExMenuShowSubmenu(DisplayID, SubmenuID);
}

// ************************************************************
// Show an exercise submenu.
function ExMenuShowSubmenu(DisplayID, SubmenuID)
{
    // Variables
    var Submenu;
    var Element;
    
    // Hide the current submenu.
    if (ActiveSubmenuID != "")
        ExMenuHideSub(ActiveSubmenuID);
        
    // Record the change.
    ActiveSubmenuID = SubmenuID;
    
    // Get the submenu element.
    Submenu = document.getElementById(SubmenuID);
    if (Submenu == null)
        return;
        
    // Get the display element.
    Display = document.getElementById(DisplayID);
    if (Display == null)
        return;
        
    // Set the submenu position.
    Submenu.style.left = getPageOffsetLeft(Display) + Display.clientWidth - 5;
    Submenu.style.top = getPageOffsetTop(Display);
    
    
    // Display the submenu.
    Submenu.style.display = "";
}

// Hide an exercise submenu.
function ExMenuHideSub(SubmenuID)
{
    // Variables
    var Submenu;
    
    // Get the submenu element.
    Submenu = document.getElementById(SubmenuID);
    if (Submenu == null)
        return;
        
    // Hide the submenu.
    Submenu.style.display = "none";
    
    // Clear the record.
    ActiveSubmenuID = "";
}

//Determine which browser is being used for compatibility.
function Browser()
{
    var ua, s, i;
    this.isIE = false; // Internet Explorer
    this.isOP = false; // Opera
    this.isNS = false; // Netscape
    this.version = null;
    ua = navigator.userAgent;
    s = "Opera";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isOP = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }
   
    // Treat any other "Gecko" browser as Netscape 6.1.
    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = 6.1;
        return;
    }
    
    s = "MSIE";
    if ((i = ua.indexOf(s)))
    {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }
}
var browser = new Browser();

// Capture mouse clicks on the page so any active button can be deactivated.
document.onmousedown = pageMousedown;

// Handle page mouse clicks and hide the menu if the click is outside the menu.
function pageMousedown(event)
{
    var el;
    var mb;
    var sb;
    
    // If there is no active button, exit.
    if (IsExMenuOn == false && IsStartMenuOn == false)
    return;
    
    // Find the element that was clicked on.
    if (browser.isIE)
        el = window.event.srcElement;
    else
        el = (event.target.tagName ? event.target : event.target.parentNode);

    // Find the activating button.
    mb = document.getElementById('ToolbarExercise');
    sb = document.getElementById('Start');
    
    // If the active button was clicked on, or a menu link was clicked on, exit.
    if (el == mb || el == sb || el.id.indexOf("MenuLink") >= 0 || el.id.indexOf("_st") >= 0)
        return;

    // Clear the menu.
    ExMenuHide();
    StartMenuHide();
}

// ******************************************************
// Change the picture.
//
function changePicture(id,imageName)
{
    var e;
    e = document.getElementById(id);
    e.src=imageName;
    //if (IsExMenuOn && id == "ToolbarExercise")
    //{
    //    ExMenuHide();
    //}
}

// ******************************************************
// Get element offsets relative to the page.
//
function getPageOffsetLeft(el)
{
    var x;
    x = el.offsetLeft;
    if (el.offsetParent != null)
        x += getPageOffsetLeft(el.offsetParent);
        
    return x;
}

function getPageOffsetTop(el)
{
    var y;
    y = el.offsetTop;
    if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
    return y;
}
// ÏÔÊ¾±êÌâ
function changeTitle(Title){
document.getElementById("title").innerText = Title;
}

function changeTags(Sid,Cid){
	document.getElementById("Ta").style.display="none";
	document.getElementById("Tb").style.display="none";
	document.getElementById("Tc").style.display="none";
	document.getElementById("Td").style.display="none";
	document.getElementById("Te").style.display="none";
	document.getElementById("T"+Sid).style.display="block";
	
	document.getElementById("Sa1").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sa2").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sa3").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sa4").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sa5").style.background = "url(images/ie7_nomal.gif)";
	//document.getElementById("Sa6").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sb1").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sb2").style.background = "url(images/ie7_nomal.gif)";
	//document.getElementById("Sb3").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sb4").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sc1").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sc2").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sc3").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sc4").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sd1").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sd2").style.background = "url(images/ie7_nomal.gif)";
	//document.getElementById("Sd3").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Sd4").style.background = "url(images/ie7_nomal.gif)";
	//document.getElementById("Se1").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("Se2").style.background = "url(images/ie7_nomal.gif)";
	document.getElementById("S"+Sid+Cid).style.background = "url(images/ie7_hight.gif)";
}

function showimages(itemId){
	var obj = document.getElementById("vista"+itemId);
	obj.style.display = "block";
	document.getElementById("vista0").style.display="none";

}
function hiddleimages(itemId){
	var obj = document.getElementById("vista"+itemId);
	obj.style.display="none";
	document.getElementById("vista0").style.display="block";
}