﻿function ReloadImage(imgName, stringSrc)
{
	imgName.src = stringSrc;
}
function getElement(name)
{
	var result = null;
	var objs = document.getElementsByName(name);
	if(objs)
	{
		var o=objs[0];
		result=o;
	}
	return result;
}
function gname(name){return document.getElementsByTagName?document.getElementsByTagName(name):new Array()}
// ----------------------- //
// --	Popup Function	-- //
// ----------------------- //
function Popup(url, windowName)
{
	var x = window.open(url, windowName, "height=650,width=600,top=20,left=200,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no");
	if(x != null)
		x.focus();
}
function PopupSmall(url, windowName)
{
	var x = window.open(url, windowName, "height=350,width=500,top=30,left=220,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no");
	if(x != null)
		x.focus();
}
// ----------------------- //
// --	Cookie Function	-- //
// ----------------------- //
function SetCookie(name, value, expiresMins)
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (expiresMins > 0) ? expiresMins * 60 : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString())) +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) +((secure == true) ? "; secure" : "");
}
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break; 
	}
	return null;
}

// ----------------------- //
// --	  Progress  	-- //
// ----------------------- //
function WriteProgress(percent)
{
    var filterWidth = parseInt(((100 - percent) * 7) / 10);
    filterWidth = filterWidth + 1;
    document.write("<div class=\"showProgressContainer\" title=\"");
    document.write(percent);
    document.write("%\"><div class=\"showProgressFilter\" style=\"width:");
    document.write(filterWidth);
    document.write("px;\"></div></div>");
}

/*View Course*/
function ViewCourse(serialNo)
{
	var x =window.open("../Course/" + serialNo + "/Enter.ppc", "Course", "height=572,width=807,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no");
	if(x != null)
		x.focus();
}

function ClickButton(event, buttonid){var btnObj = $(buttonid);	if (btnObj)	{var e = (event||window.event);if (e.keyCode == 13){btnObj.click();return false;}}return true;}

// ----------------------- //
// --	Monthly Detail	-- //
// ----------------------- //
function ViewMonthDetail(year, month)
{
	var x = window.open("MonthlyDetail.aspx?Year=" + year + "&Month=" + month, "MonthlyDetail", "height=400,width=690,top=100,left=200,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
	if(x != null)
		x.focus();
}

// ----------------------- //
// -- Swith Searh Panel -- //
// ----------------------- //
function SwitchSearchPanel(divName, objImg)
{
    var objDiv = $(divName);
    if(objDiv != null)
    {
        if(objDiv.style.display == "none")
        {
	        objDiv.style.display = "block";
	        objImg.src = rootThemePath + "searchpanelminus.jpg";
        }
        else
        {
	        objDiv.style.display = "none";
	        objImg.src = rootThemePath + "searchpanelplus.jpg";
        }
    }
}
function HideSearhPanel()
{
    objDiv = $("searchPanelContent");
    objImg = $("searchPanelImage");
    if(objDiv != null)
        objDiv.style.display = "none";
    if(objImg != null)
        objImg.src = rootThemePath + "searchpanelplus.jpg";
}

function SelectOaPortal(intKey)
{
    var head1 = $("dv_newcourseH");
    var head2 = $("dv_newsH");
    
    var s1 = $("dv_newcourse");
    var s2 = $("dv_news");
    
    switch(intKey)
    {
        case 1:
        head1.className = "imodnava";
        head2.className = "imodnavb";
        s1.style.display = "block";
        s2.style.display = "none";
        break;
        case 2:
        head1.className = "imodnavb";
        head2.className = "imodnava";
        s1.style.display = "none";
        s2.style.display = "block";
        break;
        case 3:
        head1.className = "imodnavb";
        head2.className = "imodnavb";
        s1.style.display = "none";
        s2.style.display = "none";
        break;
        default:
        head1.className = "imodnava";
        head2.className = "imodnavb";
        s1.style.display = "block";
        s2.style.display = "none";   
    }
}

// ----------------------- //
// -- Swith CourseList  -- //
// ----------------------- //
function SwitchCourseSerial(serialID)
{        
    var serial = "dd_Serial_" + serialID;   
    var objArray = document.getElementsByName(serial);
    
    var objImg = $("img_" + serialID);
    if (objImg.src.indexOf("icon_open.gif") > 0)
        objImg.src = objImg.src.replace("open", "close");
    else if (objImg.src.indexOf("icon_close.gif") > 0)
        objImg.src = objImg.src.replace("close", "open");
            
    for(i = 0; i < objArray.length; i++)
    {        
        if (objArray[i].style.display == "none")
        {                         
            objArray[i].style.display = "block";
        }
        else
        {               
            objArray[i].style.display = "none";
        }
    }
}

function SwitchCourseGroup(groupID)
{
    var objContent = $("dv_Content_" + groupID);
    if (objContent.style.display == "none")
        objContent.style.display = "block";
    else
        objContent.style.display = "none";    
}

function SwitchMenu(menuID)
{
    for(i = 1; i <= 4; i++)
    {
        var objA = $("menu" + menuID);
        objA.style.color = "#fff";
    }
    var objS = $("menu" + menuID);
    objS.style.color = "#fe4f22";
}

// ----------------------- //
// -- Swith Menu Panel --- //
// ----------------------- //
function SwitchDL(id)
{
    var objDiv = $("dl_" + id);
    if(objDiv != null)
    {
        if(objDiv.style.display == "none")
        {
	        objDiv.style.display = "block";
        }
        else
        {
	        objDiv.style.display = "none";
        }
    }
}

// ----------------------- //
// ---- Add Favorite ---- //
// ----------------------- //
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

// ----------------------- //
// ---- Set Home Page ---- //
// ----------------------- //

function SetHomePage(obj, vrl)
{        
    try
    {
        obj.style.behavior='url(#default#homepage)';
        obj.setHomePage(vrl);
    }
    catch(e)
    {
        if(window.netscape) {
            try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                    alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',vrl);
         }
    }
}