// ACTIVEXTAG.JS
/**
 * Generates an Object or Applet tag. Create a new instance, set whatever
 * properties you need, then call either toObjString() or toAppString() to get the tag as a string, or
 * call writeObj() or writeApp() to write the tag out.
 *
 * The properties width and height are required when creating a new
 * instance of the ActiveXTag, but there are setters to let you change them, as well.
 * That way, if you want to render more than one piece of content, you can do
 * so without creating a new instance of the tag.
 *
*/
 
 


/**
 * Creates a new instance of the ActiveXTag.
 * width: The width of your Flash content.
 * height: the height of your Flash content.
 *
 * These are the only 4 properites that are required.
 */
function ActiveXTag(width, height)
{
    if (arguments.length < 2)
    {
        throw new Error('You must pass in a width and height when creating a ActiveXTag.');
    }

    for (var i = 0; i < arguments.length; ++i)
    {
        if (arguments[i] == undefined || arguments[i] == null)
        {
            throw new Error('All constructor arguments must have values.');
        }
    }

    // Required
    this.width          =  width;
    this.height         =  height;

	this.id = null;
	this.codebase = null;
	this.script = false;
	this.txt = false;
    this.genericParam   = new Object();
    this.ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
}

/**
 * Specifies the location (URL) of the code to be loaded.
 */
ActiveXTag.prototype.setCode = function(code)
{
    this.code = code; 
}

/**
 * Specifies the classid to be loaded.
 */
ActiveXTag.prototype.setClassId = function(clsid)
{
    this.clsid = clsid; 
}

/**
 * Specifies the location (URL) of the codebase to be loaded.
 */
ActiveXTag.prototype.setCodebase = function(codebase)
{
    this.codebase = codebase; 
}

/**
 * Specifies the location (URL) of the archive to be loaded.
 */
ActiveXTag.prototype.setArchive = function(arc)
{
    this.arc = arc; 
}

/**
 * Specifies if MAYSCRIPT is included in Applet
 */
ActiveXTag.prototype.setMayScript = function(script)
{
    this.script = script; 
}

/**
 * Specifies if VIEWASTEXT is included in Applet
 */
ActiveXTag.prototype.setViewTxt = function(txt)
{
    this.txt = txt; 
}

/**
 * Specifies the width of the Flash content in either pixels or percentage of browser window. 
 */
ActiveXTag.prototype.setWidth = function(w)
{
    this.width = width; 
}

/**
 * Specifies the height of the Flash content in either pixels or percentage of browser window. 
 */
ActiveXTag.prototype.setHeight = function(h)
{
    this.h = height; 
}

/**
 * Identifies the content to the host environment (a web browser, for example) so that
 * it can be referenced using a scripting language.
 */
ActiveXTag.prototype.setId = function(id)
{
    this.id = id;
}
/**
 * Get the Object tag as a string. 
 */
ActiveXTag.prototype.toObjString = function()
{
	var errors = new String();
    if (this.clsid == undefined ) errors += "Classid, ";
    if (this.codebase == undefined ) errors += "Codebase, ";
	
    if ( errors.length > 0 ) {
		throw new Error('You must define ' + errors + 'when writing an ActiveXTag as an Object.');
	}
	
    var ActiveXTag = new String();
	ActiveXTag += '<object classid="clsid:'+this.clsid+'"';
	
	if (this.id != null) ActiveXTag += 'id="'+this.id+'" ';
	if (this.codebase != null) ActiveXTag += 'codebase="'+ this.codebase +'" ';
	
	ActiveXTag += 'width="'+this.width+'" ';
	ActiveXTag += 'height="'+this.height+'">';

	for (var n in this.genericParam)
	{
		if (this.genericParam[n] != undefined && this.genericParam[n] != null)
		{
			ActiveXTag += '<param name="'+n+'" value="'+this.genericParam[n]+'"/>';
		}
	}
	ActiveXTag += '</object>';
    return ActiveXTag;
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
ActiveXTag.prototype.writeObj = function(doc)
{
    doc.write(this.toObjString());
}

/**
 * Get the Applet tag as a string. 
 */
ActiveXTag.prototype.toAppString = function()
{
	var errors = new String();
    if (this.code == undefined ) errors += "Code, ";
    if (this.arc == undefined ) errors += "Archive, ";
	
    if ( errors.length > 0 ) {
		throw new Error('You must define ' + errors + 'when writing an ActiveXTag as an Applet.');
	}
	
    var ActiveXTag = new String();
	ActiveXTag += '<applet code="'+this.code+'"';
	
	if (this.id != null) ActiveXTag += 'id="'+this.id+'" ';
	if (this.codebase != null) ActiveXTag += 'codebase="'+ this.codebase +'" ';
	
	ActiveXTag += 'archive="'+this.arc+'"';
	if ( this.script ) ActiveXTag += 'MAYSCRIPT ';
	if ( this.txt ) ActiveXTag += 'VIEWASTEXT ';
	ActiveXTag += 'width="'+this.width+'" ';
	ActiveXTag += 'height="'+this.height+'">';

	for (var n in this.genericParam)
	{
		if (this.genericParam[n] != undefined && this.genericParam[n] != null)
		{
			ActiveXTag += '<param name="'+n+'" value="'+this.genericParam[n]+'"/>';
		}
	}
	ActiveXTag += '</applet>';
    return ActiveXTag;
}

/**
 * Write the Applet tag out. Pass in a reference to the document to write to. 
 */
ActiveXTag.prototype.writeApp = function(doc)
{
    doc.write(this.toAppString());
}
