//
// Object tag replacing script.
//
//
// *** IMPORANT NOTE ***:
//  Do not embed this function directry into HTML.
//  This function should be located on external js file.
//
// How to use.
//  ex. replace object tag with this comportnent.
// 
// original object tag:
////////////////////////////////
//  <object widht="12%" height="34%" standby="now loading..." classid="clsid:uuid" codebase="http://uri.of.codebase/" id="id_in_dhml"></object>
////////////////////////////////
//
// translated tags:
////////////////////////////////
//  <span class="mp_object_placeholder" id="nin-i_no_mojiretsu"><!-- dummy stuff. this is required --></span>
//  <script language="JScript"><!--
//  create_control("nin-i_no_mojiretsu", // should be unique. any string accepted.
//                 "12%",
//                 "34%",
//                 "now loading...",
//                 "clsid:uuid",
//                 "http://uri.of.codebase/",
//                 "id_in_dhml",
//                 ""); // not used.
//  // --></script>
////////////////////////////////
//
//
// create_control function prototype:
// function create_control( spanid,   // should be as same as <span> tag's id
//                          width,    // widht of compornent.
//                          height,   // height of compornent.
//                          standby,  // standby string.
//                          clsid,    // class id of object.
//                          codebase, // codebase of compornent
//                          objid,    // id string will be bound to ths object.
//                          evname)   // not used now. // ryu1k_2006-04-07
//

// Usage example 1.
////////////////////////////////
// <span class="mp_object_placeholder" id="be_unique_1babdab02eaabbc748fb241b6086569c"><!-- dummy stuff. this is required --></span>
// <script language="JScript"><!--
//  create_control("be_unique_1babdab02eaabbc748fb241b6086569c",
//                 "$width",
//                 "$p_height",
//                 "",
//                 "CLSID:67C1FA99-7563-415F-83C0-341CA4B8E85F",
//                 "$CABS_URL/MpPlayer.cab#version=$MPPLAYER_VERSION",
//                 "MpPlayer",
//                 "InitializeDone");
// // --></script>
////////////////////////////////

// Usage example 2.
////////////////////////////////
// <span class="mp_object_placeholder" id="be_unique_99d254ef1cc29c160cc3f1d1aa8715c6"><!-- dummy stuff. this is required --></span>
// <script language="JScript"><!--
// create_control("be_unique_99d254ef1cc29c160cc3f1d1aa8715c6",
//                "$width",
//                "$height",
//                "Loading 2D Control. . .",
//                "clsid:F31E00A8-AFC1-11D4-884B-00A0C9E22778",
//                "$CABS_URL/MP2D.cab#version=$MPCAB_VERSION",
//                "Mp2d1",
//                "InitializeDone");
// // --></script>
////////////////////////////////


function create_control1( divid,
			  width, height, standby, 
			  clsid, codebase, objid) 
{
      // obsolete
    var obj = document.createElement('object');
    document.getElementById( divid ).appendChild( obj );
    obj.width    = width   ;   
    obj.height   = height  ;  
    obj.standby  = standby ;   
    obj.classid  = clsid   ;   
    obj.codebase = codebase;   
    obj.id       = objid   ; 
}

function create_control_ih( divid,
			    width, height, standby, 
			    clsid, codebase, objid,
			    evname)
{
      // can avoid MS's ActiveX behavior patch.
    var div = document.getElementById( divid );
    if ( ! div ) { 
	alert("failed to create ActiveX object.\n" + 
	      "Technnical note: divid and spanid differs?"); 
	return;
    }
    div.innerHTML = 
	'<object'    +
	' width='    + '"' + width    + '"' +  
	' height='   + '"' + height   + '"' + 
	' standby='  + '"' + standby  + '"' +  
	' classid='  + '"' + clsid    + '"' +  
	' codebase=' + '"' + codebase + '"' +  
	' id='       + '"' + objid    + '"' + '></object>';
}

function create_control_dw( divid, // divid not used.
			    width, height, standby, 
			    clsid, codebase, objid, 
			    evname)
{ 
      // inner HTML don't work on older browsers.
    if( !evname ) { evname = "onload"; }
    if( !objid || objid.length == 0 ) { objid = "dummyobjid"; }
    document.write( '<object'    + 
		    ' width='    + '"' + width    + '"' +  
		    ' height='   + '"' + height   + '"' + 
		    ' standby='  + '"' + standby  + '"' +  
		    ' classid='  + '"' + clsid    + '"' +  
		    ' codebase=' + '"' + codebase + '"' +  
		    ' id='       + '"' + objid    + '"' + 
		    '></object>');
}


function is_nt51_or_newer()
{
    var ua = navigator.userAgent;
    if ( -1 == ua.indexOf("MSIE"          ) ) { return false;}
    if ( -1 == ua.indexOf("Windows NT"    ) ) { return false;}
    if ( -1 != ua.indexOf("Windows NT 4"  ) ) { return false;}
    if ( -1 != ua.indexOf("Windows NT 5.0") ) { return false;}
    return true;
}

function is_ie50()
{
    var ua = navigator.userAgent;
    if ( -1 == ua.indexOf("MSIE 5") )   { return false;}
    if ( -1 != ua.indexOf("MSIE 5.5") ) { return false;}
    return true; // this is IE 5.0x, 5.1, 5.2
}


create_control = create_control_ih;


function create_control_g( unique_id, attrs, params )
{
      // can avoid MS's ActiveX behavior patch.
    var span = document.getElementById( unique_id );
    if ( ! span ) { 
	alert("failed to create ActiveX object.\n" + 
	      "Technnical note: spanid and spanid differs?"); 
	return;
    }

    var ihtext = '<object ';
    var alen = attrs.length;
    
    for( var i = 0; i<alen; i++ ) {
	if( ! attrs[i] ) { continue; }
	if( attrs[i].length > 1 ) {
	    if( -1 == attrs[i][1].indexOf("'") ) {
		ihtext += attrs[i][0] + "='" + attrs[i][1] + "'";
	    } else {
		ihtext += attrs[i][0] + '="' + attrs[i][1] + '"';
	    }
	} else {
	    ihtext += attrs[i][0];
	}
    }
    ihtext += ">";
    if ( params ) {
	ihtext += params;
    }
    ihtext += "</object>";
    span.innerHTML = ihtext;
}
