/* 
 * By Igor Zhukovsky. www.izhuk.com, April 2006.
 *
 * This class allows to output applet tags on a web page
 * dynamically, thus resolving the IE security issue.
 * (about the issue see http://izhuk.com/docs/ie7fix.html)
 *
 * How to use:
 *
 *  1. Refer to this script in your HTML page:
 *
 *     <script language="javascript" src="applet.js"></script>
 *
 *  2. Write JavaScript code:
 *
 *     var myapplet = new Applet(); // create an Applet object
 *
 *     //  assign necessary attributes
 *     myapplet.attr['code'] = 'MyClass.class';
 *     myapplet.attr['width']  = 200;
 *     myapplet.attr['height'] = 100;
 *     ....
 *
 *     // assign parameters if neccessary
 *     myapplet.param['param1'] = 'value1';
 *
 *     myapplet.write(); // output the applet tag
 */

function Applet(tag) {
	this.tag = tag;
	this.html = '';
    this.attr  = new Object(); // applet tag attributes
    this.param = new Object(); // applet parameters
	this.applet = new Object(); //sub applet (i.e. an <embed> tag in an <object> tag
    this.noJava = '<a href="http://adobe.com/go/getflash" target="_blank">Flash</a> and/or <a href="www.java.com" target="_blank">Java</a> is necessary to view this content.';
}

Applet.prototype.create = function() {
	var name = '';
	this.html = '';
	this.html += '<' + this.tag + ' ';

    // write attributes of the tag
    for (name in this.attr) {
        var value = this.attr[name];
		this.html += name + '="' + value + '" ';
    }
    this.html += '>';

    // write parameters
    for (name in this.param) {
        var value = this.param[name];
		this.html += '<param name="' + name + '" value="' + value + '">';
    }
	
	//sub tags
	for (name in this.applet){
		this.applet[name].create();
		this.html += this.applet[name].html;
	}
	
	this.html += '</' + this.tag + '>';	
}

Applet.prototype.write = function() {
	this.create();
	document.write(this.html);
}	
