/* popupInit start */
function popupInit() {  
  var nav = document.getElementById("navmain");
  var sidebars = getElementsByClassName(document.getElementById("maincontent"), "ul", "seeAlso");
  var sidebar = (sidebars != null) ? sidebars[0] : null;
  var sitemaps = getElementsByClassName(document.getElementById("maincontent"), "div", "sitemap-list");
  var sitemap = (sitemaps != null) ? sitemaps[0] : null;
  
  replacePopup(nav);   
  replacePopup(sidebar);    
  replacePopup(sitemap);
}

function replacePopup(container) {
  if (container) {    
    var links = container.getElementsByTagName("a");
    for (var i=0; i<links.length; i++) {
      if (links[i].href.indexOf("/resources/ftp-access/login.aspx") != -1) {
        links[i].onclick = popUpFTPAccess;
      }
    } 
  }
}
/* popupInit end */

/* popup FTP access start */
function popUpFTPAccess() {  
  opwin('http://ftp.colorcraft.com.hk/login.aspx',680,400,'no','no','no');    
  return false;
}
/* popup FTP access end */

/* popup win start */
function opwin(__url, __w, __h,__r,__sb,__s,__align,__mb,__loc){
	__r = (__r==null) ? 'yes' : __r;
	__sb = (__sb==null) ? 'yes' : __sb;
	__s = (__s==null) ? '1' : __s;
	__mb = (__mb==null) ? 'yes' : __mb;
	__loc = (__loc==null) ? 'yes' : __loc;
	cw = 0;
	ch = 0;
	if (window.screen) {
	    w = Math.floor(screen.availWidth/3);
	    h = Math.floor(screen.availHeight/3);
		if (__align=="TR"){
		    cw = Math.floor(screen.availWidth-__w-8);
		    ch = Math.floor((screen.availHeight-__h)/2);
		}else if (__align=="LR"){
		    cw = Math.floor(screen.availWidth-__w-8);
		    ch = Math.floor(screen.availHeight-__h-35);
		}else if (__align=="UL"){
		    cw = 0;
		    ch = 0;
		}else if (__align=="UC"){
		    cw = Math.floor((screen.availWidth-__w)/2);
		    ch = 0;
		}else{
		    cw = Math.floor((screen.availWidth-__w)/2);
		    ch = Math.floor((screen.availHeight-__h)/2);
		}
	}
	var param = 'resizable='+__r+',scrollbars='+__sb+',status='+__s+',left='+cw+',top='+ch;
	param += (__w==null) ? param : ",width="+__w;
	param += (__h==null) ? param : ",height="+__h;
	var winName = "myxfnpopupwin";
	
	var mywin = window.open(__url,winName,param);
	mywin.opener = this;
	
	if (mywin.focus){
		mywin.focus();
	}
}
/* popup win end */

/*  Swap div  */

function HideDIV(d) { document.getElementById(d).style.display = "none"; }
function DisplayDIV(d) { document.getElementById(d).style.display = "block"; }


/* css class helper function start */
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

function addClassName(oElm, strClassName){
	var strCurrentClass = oElm.className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}

function removeClassName(oElm, strClassName){
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}
/* css class helper function end */

/* graphic randomizer start */
graphicsRandomizer = function(id, images) {
  this.id = id;
  this.images = images;
}

graphicsRandomizer.prototype = {
  display : function(){
    if (document.getElementById(this.id)) {                
      var ranNum = Math.floor(Math.random() * this.images.length);      
      document.getElementById(this.id).src = this.images[ranNum];
    }
  }
}
/* graphic randomizer end */

function init() {  
  navInit();
  imgRollOverInit();
  popupInit();
  
  if(typeof(mainInitFollowup)=="function") mainInitFollowup();
}

/* addEvent(window, 'load', init); */
var mainInitFollowup;
if(typeof(window.onload)=="function") mainInitFollowup = window.onload;
window.onload = init;
