﻿// JScript File

function mouseOver(img,path){
	img.src = path
}


function mouseOut(img,path){
	img.src = path
}



/* Using for show or hide sub menu of current menu */
function displayMenuContent(id,img) {

    // close previous div
    if (divPrevious != "" && divPrevious != id) {
        // if previous div is opened, close it
        if (document.getElementById(divPrevious).style.display == "") {
            // changed previous image
            imgPrevious.src = "images/arrow.gif";
            // close previous div
            document.getElementById(divPrevious).style.display = "none";
        }
    }
    
    // active current div
    if (id != null) {
        if (document.getElementById(id).style.display == "none") {
            // changed image
            if (img != null) {
                img.src = "images/arrow-down.gif";
            }
            // close div
            document.getElementById(id).style.display = "";

        } else {
            // changed image
            if (img != null) {
                img.src = "images/arrow.gif";
            }
            // open div
            document.getElementById(id).style.display = "none";
            
        }
    }
    
    // remove previous div if it same with id
    if (divPrevious == id) {
        // remove previous action
        divPrevious = "";
        imgPrevious = null;
    } else {
        // store current object to check at next action
        divPrevious = id;
        imgPrevious = img;
    }
}


/*using for open div of current page*/
function initDisplayMenu() {
    // get page name
    var page = getPageName();
    
    var divName = "";
    var imgName = "";
    // find it in collection
    for (i=0; i<arrMenu.length; i++) {
		if (arrMenu[i] == undefined)
			continue;
		if (page == arrMenu[i][0]) {
		    // set div of current item is open state
            document.getElementById(arrMenu[i][2]).style.display = "none";
            // show div
            displayMenuContent(arrMenu[i][2], document.getElementById(arrMenu[i][3]));
            break;
		}
	}
}


function setMenuItemBgColor() {
    var page = getPageName();
    var itemColor;
    var activeColor;
    
    for (i=0; i<arrMenu.length; i++) {
		if (arrMenu[i] == undefined)
			continue;
		if (document.getElementById(arrMenu[i][4]) != null) {
		    if (arrMenu[i][0] == page) {
                if (arrMenu[i][1] == "menu") {
		            document.getElementById(arrMenu[i][4]).style.backgroundColor = "#000088";
		        } else if (arrMenu[i][1] == "submenu") {
		            document.getElementById(arrMenu[i][4]).style.backgroundColor = "#ddffff";
		        }
            } else {
                if (arrMenu[i][1] == "menu") {
		            document.getElementById(arrMenu[i][4]).style.backgroundColor = "#0055cc";
		        } else if (arrMenu[i][1] == "submenu") {
		            document.getElementById(arrMenu[i][4]).style.backgroundColor = "#ddeeff";
		        }
            }
		}
	}
}


/*Using for get page name from current url*/
function getPageName() {
    // get current url
    var url = document.location.href.toLowerCase();
    var pos = -1;
    
    // rejec all parameter of url
    pos = url.lastIndexOf('?');
    
    if (pos > 0) {
        url = url.substr(0,pos);
    }
    
    var page;
    pos = url.lastIndexOf('/');
    var dot = -1;
    dot = url.lastIndexOf('.');
    
    // get page name
    if (pos > 0 && dot > 0 && dot > pos) {
        page = url.substr(pos+1,dot-pos-1);
    }
    
    return page;
}

// do not use
function preloadImages() {
	var d = document;
	
	if(d.images){
	    
		if(!d.MM_p)
			d.MM_p=new Array();
			
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
	}
}