


// run on pageload
dom_addLoadEvent(FixExternalLinks);
dom_addLoadEvent(correctPNG);



// corrects PNG images to get PNG transparency to work in IE
function correctPNG() 
{
   for(var i=0; i<document.images.length; i++)
   {
          var img = document.images[i];
          var imgName = img.src.toUpperCase();
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left") imgStyle = "float:left;" + imgStyle;
                if (img.align == "right") imgStyle = "float:right;" + imgStyle;
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle ;          
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                i = i-1;
          }
   }
}



// swaps an image with a specific id to a new image url
function swap(id, url)
{
	var oImg = document.getElementById(id);
	oImg.src = url;
}



// toggle for left menu options
function toggleMainNav(oThisMenuLink)
{
	var oThisMenuLinksArrowImageArray = oThisMenuLink.parentNode.getElementsByTagName("img");
	var oThisMenuLinksArrowImage = oThisMenuLinksArrowImageArray[0];
	var oThisParentContainer = oThisMenuLink.parentNode.parentNode;	
	var arrNavDivs = dom_getElementsByClassName(document, 'div', 'mainnav_mainlevel');

	// close all other submenus
	/*
	for (var i=0; i<arrNavDivs.length; i++)
	{
		if (arrNavDivs[i] !== oThisParentContainer)
		{
			dom_removeClassName(arrNavDivs[i], 'onstate');
		}
	}	
	*/
	
	// open or close (toggle) proper submenu (and title text for arrow image)
	if (!dom_hasClassName(oThisParentContainer, 'onstate'))
	{
		dom_addClassName(oThisParentContainer, 'onstate');
		oThisMenuLinksArrowImage.setAttribute('alt', 'click to hide');
		oThisMenuLinksArrowImage.setAttribute('title', 'click to hide');
	}
	else
	{
		dom_removeClassName(oThisParentContainer, 'onstate');
		oThisMenuLinksArrowImage.setAttribute('alt', 'click to expand');
		oThisMenuLinksArrowImage.setAttribute('title', 'click to expand');
	}
	
}



// toggle for tab content boxes
function toggleTabContent(oThisMenuLink, iTabContentId)
{
	var oThisContentDiv = document.getElementById('tabcontent_' + iTabContentId);
	var arrMenuLinks = dom_getElementsByClassName(document, 'a', 'tabbedboxmenulink');
	var arrContentDivs = dom_getElementsByClassName(document, 'div', 'tabbedboxcontent');

	// close all other content boxes
	for (var i=0; i<arrContentDivs.length; i++)
	{
		if (arrContentDivs[i] !== oThisContentDiv)
		{
			dom_removeClassName(arrContentDivs[i], 'onstate');
		}
	}	

	// open or close (toggle) proper content box
	if (!dom_hasClassName(oThisContentDiv, 'onstate'))
	{
		dom_addClassName(oThisContentDiv, 'onstate');
	}

	// close all other tab links
	for (var i=0; i<arrMenuLinks.length; i++)
	{
		if (arrMenuLinks[i] !== oThisMenuLink)
		{
			dom_removeClassName(arrMenuLinks[i], 'onstate');
		}
	}	

	// open or close (toggle) proper tab link
	if (!dom_hasClassName(oThisMenuLink, 'onstate'))
	{
		dom_addClassName(oThisMenuLink, 'onstate');
	}
	
	return false;
}

function CreateBookmarkLink() {
    title = document.title;url=location.href;
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { // Opera Hotlist
        return true; }
}

function open_popup(url, w, h, resize, scroll,wname) {
/* place this in onclick or href: "javascript:open_popup('[url]','[width of window]','[height of window]','[resize option]','[scroll opiton]','[windowname]');" */
 wname = (wname == null) ? "popwin" : wname.replace(new RegExp(/ /g), "");
 scroll = ((scroll == null)||(scroll=='')||(scroll==1)||(scroll=='1'))? 'yes':'no';
 resize = ((resize == null)||(resize=='')||(resize==1)||(resize=='1'))? 'yes':'no';
 var properties = "toolbar=0,scrollbars="+scroll+",location=0,statusbar=1,menubar=0,resizable="+resize;
 properties += ",width="+ w +",height="+ h;
 child = window.open(url,wname,properties);
 child.focus();
}























// ### General Utility & DOM Handling Functions Below This Line



// ### gets an array of objects that match the input start element, tag name, and class name
// Ways of calling the function are:
// To get all a elements in the document with a “info-links” class. 
// getElementsByClassName(document, "a", "info-links"); 
// To get all div elements within the element named “container”, with a “col” and a “left” class. 
// getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]); 
function dom_getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + 
            oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + 
        oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}



function dom_addClassName(oElm, strClassName)
{
	var strCurrentClass = oElm.className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}



function dom_removeClassName(oElm, strClassName)
{
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}



function dom_hasClassName(oElm, strClassName)
{  
	return oElm.className.match(new RegExp('(\\s|^)'+strClassName+'(\\s|$)'));
}



// ### adds a function to run at onLoad
function dom_addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

///function to set a page as a homepage for both IE and FF (works only if the 
///security settings allows it, in the production case we catch the permission
///denied error and bow out gracefully
function SetHomePage(page)
{
    if(document.all)
    {
        this.style.behavior='url(#default#homepage)'; 
        this.setHomePage(page);
    }
    else
    {
        try
        {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',page);
         }  
         catch(e)  
         {  
            //alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
         }
    }
}





