  
  function changeBySwfChangeLib(filePath, widthX, HeightX){
  	  var so = new SWFObject(filePath, "star", widthX, HeightX, "6", null,"star_style");
      so.write("innerSwf");
      var swfDiv = document.getElementById("innerSwf");
      swfDiv.style.zIndex = -100;
      
  }
    
  /* replace swf source ; to support multiple singers event */
  function changeSWFsource(sourceName){ 
     var swfSrc = sourceName;
     
     var swfFile = document.getElementById("star");
     if( swfFile != null){
     	  var srcFile = swfFile.childNodes;
        if(srcFile == null || srcFile.length == 0){
            return;
        }
        var width = swfFile.getAttribute("width");
        var Height = swfFile.getAttribute("height");
        var paramArr = new Array(0);
        for(var i = 0 ; i< srcFile.length ; i++){
            var swfChild = srcFile[i];
            <!-- for firefox -->
            if(swfChild.src != null && swfChild.src != "undefined" && swfChild.src.lastIndexOf(".swf") == swfChild.src.length-4 ){
            	  var filePath = swfChild.src;
                var fileName = filePath.substring(filePath.lastIndexOf("/")+1,swfChild.src.length-4);
                if(fileName == swfSrc){
                    return ;
                }                
                swfChild.src = filePath.replace(fileName, swfSrc);
            }
            <!-- for ie -->
            if(swfChild.getAttribute("value") != null  &&
                swfChild.getAttribute("value").lastIndexOf(".swf") == swfChild.getAttribute("value").length-4 ){
                
            	  swfChild.setAttribute("name",swfChild.getAttribute("name"));
            	  var filePath = swfChild.getAttribute("value");  
            //	  filePath = filePath.substring( filePath ,filePath.lastIndexOf(".swf")+4) 
            	  var fileName = filePath.substring(filePath.lastIndexOf("/")+1,filePath.length-4);
            	  if(fileName == swfSrc){
                    return ;
                }
                var replaceFile = filePath.replace(fileName, swfSrc);
            //    FlashReplace.replace("innerSwf", replaceFile,"star", width, Height,6,paramArr);    	
                changeBySwfChangeLib(replaceFile,width,Height);  
                
            }
        }
     }
  }
  
  function showOneSinger(blockIndex,singerIndex){
    for( var i = 1; i <= 5 ; i++){ 
  	   for( var j = 1; j <= 10 ; j++){
           var divContent = document.getElementById("block"+i+"_"+"downloadcontent"+j);
           if( divContent != null ){
                if(blockIndex == i && singerIndex == j){   	 
                	    divContent.style.visibility="visible";
                      divContent.style.display="block";
   	  	        }else{
   	  	          	 divContent.style.visibility="hidden";
                     divContent.style.display="none"; 
   	  	        }
           }
           divContent = null;
       }
    }
    
  }
  
  function getSingerIndex(){
      for( var i = 1; i <= 5 ; i++){ 
  	      for( var j = 1; j <= 5 ; j++){
  	      	  var layerId = "block"+i+"_"+"downloadcontent" +j;
          	  var divLayer = document.getElementById(layerId);
          	  if(divLayer != null && divLayer.style.visibility=='visible'){
          	      return j;
          	      
          	  }
          }
      }
      return 1;
  }
  //掃一遍所有的Content;找出visible
  function checkShowSwf(blockIndex){
  	  var singerIndex = getSingerIndex();
  	  
      showOneSinger(blockIndex,singerIndex);
      changeSWFsource("singer"+singerIndex);  
  }
  
  function showEventBlock(divFormat,divId){
     var allCount = 4 ;
     var divId = divId;
    
     for(var i=1 ; i <= allCount ; i++){
     	  var divName= divFormat + i;
        var divLayer = document.getElementById(divName);
        
        if( divLayer != null){
        	  if(i != divId){
        	  	  divLayer.style.visibility="hidden";
                divLayer.style.display="none";          
          	}else{
          	//	 alert(divName);
          		  divLayer.style.visibility="visible";
                divLayer.style.display="block";
        	  }
        } 
        divLayer = null;
     } 
     if(divId == 0){
     	 
       	hideAllDownloadContent();
    	  showMvSource();
    	  changeSWFsource("top");
     }else{
     
       	hiddenMvSource();
        hideMessageContent();
        checkShowSwf(divId);
    	  
     }
      setTitleUnChanege();
  }
  
  function showEventBlockButSwfSource(divFormat,divId){
     var allCount = 4 ;
     var divId = divId;
     
     for(var i=0 ; i <= allCount ; i++){
     	  var divName= divFormat + i;
        var divLayer = document.getElementById(divName);
        if( divLayer != null){
        	  if(i != divId){
        	  	  divLayer.style.visibility="hidden";
                divLayer.style.display="none";          
          	}else{
        	  	  divLayer.style.visibility="visible";
                divLayer.style.display="block";
        	  }
        } 
        divLayer = null;
     }
  }
   
  
  function showSingerBlock(divFormat ,contentId,singerCount){
  	 var allCount = singerCount;
  	 hideMessageContent();  //display singer source,hidden message block 
  	 var showBlock = 0;	   
     for(var blockIndex=1 ; blockIndex<= 3 ; blockIndex++){
         var blockLayer = document.getElementById("downloadblock"+blockIndex);
         if( blockLayer != null && blockLayer.style.visibility == "visible" ){
             showBlock = blockIndex;
         }
         blockLayer = null;
         //no block be showed
         if(blockIndex == 3 && showBlock ==0){
             showBlock = 1;
             showEventBlockButSwfSource("downloadblock",1);
         }
     }
    
     for(var i=0 ; i <= allCount ; i++){
         var divName = "block"+showBlock+"_"+"downloadcontent" + i;
         var divLayer = document.getElementById(divName);
         if( divLayer != null ){
         	   if( i != contentId ){
         	       divLayer.style.visibility="hidden";
                 divLayer.style.display="none";       
         	   }else if( i == contentId){
                 divLayer.style.visibility="visible";
                 divLayer.style.display="block";
             }
         } 
         divLayer = null;
     }
     hiddenMvSource();
     
     if(singerCount >1 ){    	    
     	    changeSingerName(contentId -1,singerCount);
     	    changeSWFsource("singer"+contentId); 
     	    
     }
      setTitleUnChanege();
  }
  
  function hideAllDownloadContent(){
      for( var i = 0; i < 5 ; i++){
          for( var j = 0; j < 10 ; j++){
      	      var divContent = document.getElementById("block"+i+"_"+"downloadcontent"+j);
              if( j > 1 && divContent != null){
   	  	          divContent.style.visibility="hidden";
                  divContent.style.display="none";   
              }else if(i==1 && j == 1){
                	divContent.style.visibility="hidden";
                  divContent.style.display="none";   
              }
          }
      }
  } 
  
  //hide message content
  function hideMessageContent(){
      var divContent2 = document.getElementById('downloadblock'+'0');
      divContent2.style.visibility="hidden";
      divContent2.style.display="none";  
      
      // this.donothing();
      hiddenMvSource();
      //  alert("!");
      divContent2 = null; 
  } 
  
  function donothing(){
  	var divContentUnexist = document.getElementById("unexist");
  	return ;
  }
  
  
  //hide messageMenu , show downloadMenu
  function showDownloadMenu(divFormat,singerIndex){
  	  var singerCount = 4;
  	  var downloadMenu = document.getElementById("menuPanel1");
      if(downloadMenu != null){
           downloadMenu.style.visibility="hidden";
           downloadMenu.style.display="none";
      }
      downloadMenu = null;
      var downloadMenu = document.getElementById("menuPanel");
      if(downloadMenu != null){
           downloadMenu.style.visibility="visible";
           downloadMenu.style.display="block"; 
           showSingerBlock(divFormat,singerIndex,singerCount) ;         
      }
      downloadMenu = null;
      hiddenMvSource();
      setTitleUnChanege();
  }
  
  //hide messageMenu , show downloadMenu
  function showMessageMenu(divFormat,singerIndex){
  	  var downloadMenu = document.getElementById("menuPanel");
      if(downloadMenu != null){
           downloadMenu.style.visibility="hidden";
           downloadMenu.style.display="none";
      }
      downloadMenu = null;
      var downloadMenu = document.getElementById("menuPanel1");
      if(downloadMenu != null){
           downloadMenu.style.visibility="visible";
           downloadMenu.style.display="block"; 
           downloadMenu.style.zIndex="4000";
           showEventBlock(divFormat,singerIndex);
      }
      downloadMenu = null;
      showMvSource();
      setTitleUnChanege();
  }    
  
  function resizeHeader(){
      parent.document.all("frameidHeader").style.height=document.body.scrollHeight;
      parent.document.all("frameidHeader").style.width=document.body.scrollWidth; 
      resizeFooter();
  }
  
  function resizeFooter(){
      parent.document.all("frameidFooter").style.height=document.body.scrollHeight;
      parent.document.all("frameidFooter").style.width=document.body.scrollWidth; 
  }
  
  function hiddenMvSource(){
  	  var mv = document.getElementById("mvSource");
      if(mv != null){
           mv.style.visibility="hidden";
           mv.style.display="none";
      }
  }
  
  function showMvSource(){
      var mv = document.getElementById("mvSource");
      if(mv != null){
           mv.style.visibility="visible";
           mv.style.display="block";
      }	
  	
  }
  
  function prelistenX(title,eventId,rbtCode,contextPath) {
  	  showListenWindow(rbtCode);
  }

  function prelisten(title,eventId,rbtCode,contextPath) { 
  	  pop=window.open("/mktpromoevent/safePreview.jsp?eventId="+eventId+"&rbtCode="+rbtCode+"&title="+title,"WG_Preview_MIDI"
              ,'scrollbars=0,status=yes,width=289,height=151,left=300,top=270');
              
  }
  
  function hideMessageContentTestCache(testA){
  	var catcheVar = testA ;
  	if(testA  > 0){
  	    hideMessageContent();
  	}
  }
  
  function showListenWindow(rbtCode){
  	    var mv = document.getElementById(rbtCode);
  	    mv.style.visibility="visible";
        mv.style.display="block";
        var x =800;
        var y =700; 
        
    	  delayPlay(rbtCode+"wma"); 
    } 
     
    function delayPlay(wmaName){ 
    	  window.setTimeout(startPlay(wmaName),200);    	  
    }
    
    function startPlay(wmaName){    		
    		
    		var midiFile = document.getElementById(wmaName);
    //		alert(wmaName);
    		midiFile.play();
    		//midiFile.setAttribute("AutoStart","true");
    }
     
    function closePlayer(rbtCode){    	 
    	  var midiFile = document.getElementById(rbtCode+"wma");
    	  midiFile.pause();
    	  var mv = document.getElementById(rbtCode);
    	  mv.style.visibility="hidden";
        mv.style.display="none";
    }
    
/*
	FlashReplace is developed by Robert Nyman, http://www.robertnyman.com. License and downloads: http://code.google.com/p/flashreplace/
*/
// ---
var FlashReplace = {
	elmToReplace : null,
	flashIsInstalled : null,
	defaultFlashVersion : 7,
	replace : function (elmToReplace, src, id, width, height, version, params){
		this.elmToReplace = document.getElementById(elmToReplace);
		this.flashIsInstalled = this.checkForFlash(version || this.defaultFlashVersion);
		
		if(this.elmToReplace && this.flashIsInstalled){
			
			var obj = '<object' + ((window.ActiveXObject)? ' id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="' + src + '"' : '');			
			obj += ' width="' + width + '"';
			obj += ' height="' + height + '"';
			obj += '>';
			var param = '<param';
			param += ' name="movie"';
			param += ' value="' + src + '"';
			param += '>';
			param += '';
			
			param += '<param';
			param += ' name="Wmode"';
			param += ' value="Transparent"';
			param += '>';
			param += '';
			var extraParams = '';
			var extraAttributes = '';
			for(var i = 0 ; i  < params.length ; i= i+2){
				if(params[i] != null && params[i] != "undefined"){
				    extraParams += '<param name="' + params[i] + '" value="' + params[i+1] + '">';
				}
		    extraAttributes += ' ' + i + '="' + params[i] + '"'; 
			}
			 
			var embed = '<embed id="' + id + '" src="' + src + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"';
			var embedEnd = extraAttributes + '></embed>';
			var objEnd = '</object>';
			this.elmToReplace.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;
		}
	},
	
	checkForFlash : function (version){
		this.flashIsInstalled = false;
		var flash;
		if(window.ActiveXObject){
			try{
				flash = new ActiveXObject(("ShockwaveFlash.ShockwaveFlash." + version));
				this.flashIsInstalled = true;
			}
			catch(e){
				// Throws an error if the version isn't available			
			}
		}
		else if(navigator.plugins && navigator.mimeTypes.length > 0){
			flash = navigator.plugins["Shockwave Flash"];
			if(flash){
				var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/, "$1");
				if(flashVersion >= version){
					this.flashIsInstalled = true;
				}
			}
		}
		return this.flashIsInstalled;
	}
};
// ---

//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

	function showDownloadWindow(downloadCode){
		var downloadUrl = 'http://rbt.vibo.net.tw/web/web/search_c.jsp?hitkeyword=hitkeywprd&searchselect=song&swarselect1=code&searchvalue='+downloadCode;
		window.open(downloadUrl, 'RBT', config='height=200,width=600,resizable=yes,location=yes');
	}
