// $Id: ui.js,v 1.15 2000/12/21 18:40:17 aepsa Exp $

function TBrowser() {
	var fileExtensionRegExp=/^.*\/(.+)page=(.+)$/;
	var documentLocation=new String(document.location.href);        
	//this.name=documentLocation.replace(fileExtensionRegExp, "$1");
        this.name=documentLocation.replace(fileExtensionRegExp, "$2");        
	//this.ext=documentLocation.replace(fileExtensionRegExp, "$2");
        this.ext='jsp';
	this.host=document.location.host;
	this.useFlash=false;
	this.isIE=navigator.appName.indexOf("Microsoft")!=-1;
	this.isUnix=navigator.userAgent.indexOf("X11")!=-1;
	this.buttons=new Array();
	this.flashIDs=new Array();
	this.addButton=TBrowserAddButton;
	this.addFlashButtons=TBrowserAddFlashButtons;
	this.writeButton=TBrowserWriteButton;
	this.setEnabledButton=TBrowserSetEnabledButton;
	this.initEnabledButton=TBrowserInitEnabledButton;
	this.setFlash=TBrowserSetFlash;
	this.setFlashID=TBrowserSetFlashID;
}

function TBrowserAddButton(name, width, height) {
	var button=new TButton(this, name, width, height);
	this.buttons[button.name]=button;
}

function TBrowserAddFlashButtons(name,width,height,bgcolor) {
	var flashbuttons=new TFlashButtons(this,name,width,height,bgcolor);
	this.buttons[name]=flashbuttons;
}

function TBrowserWriteButton(name,flashID) {
	if(!this.useFlash || this.isUnix) {
		this.buttons[name].write();
	}
	else if(flashID) { //Here we only want to write the SWF file corresponding to the first ID.
		this.buttons[this.flashIDs[flashID]].write();
	}
}

function TBrowserSetEnabledButton(name, state,flashID) {
	if(!this.useFlash || this.isUnix) {
		this.buttons[name].setEnabled(state);
	}
	else {
		this.buttons[this.flashIDs[flashID]].setEnabled(state);
	}
}

function TBrowserInitEnabledButton(flashID) {
	if(!this.useFlash || this.isUnix) {
		this.buttons[this.name].setEnabled(true);
	}
	else {
		this.buttons[this.flashIDs[flashID]].setEnabled(true);
	}
}

function TBrowserSetFlash(useFlash) {
	this.useFlash=useFlash;
}

function TBrowserSetFlashID(id) {
	this.flashIDs[id]=id;
}

function TButton(browser, name, width, height) {
	this.browser=browser;
	//var targetFileExtensionRegExp=/^(.+)\.(.+)$/;
        var targetFileExtensionRegExp=/^(.+)page=(.+)$/;
	//this.name=name.replace(targetFileExtensionRegExp, "$1");
	//this.ext=name.replace(targetFileExtensionRegExp, "$2");
        this.name=name.replace(targetFileExtensionRegExp, "$2");   
        this.ext='jsp';
	this.width=width;
	this.height=height;
	this.write=TButtonWrite;
	this.setEnabled=TButtonSetEnabled;
	this.prePage='index.' + this.ext + '?page=';
        /*
	if(this.browser.ext=='html' && this.ext=='html') {
		this.prePage='';
	} else if(this.browser.ext=='html' && this.ext=='cgi') {
		this.prePage='cgi-bin/';
	} else if(this.browser.ext=='cgi' && this.ext=='html') {
		this.prePage='../';
	} else if(this.browser.ext=='cgi' && this.ext=='cgi') {
		this.prePage='';
	} else {
		this.prePage='';
	} */        
	//this.postPage=this.ext;
        this.postPage='';
	//this.preImage=this.browser.ext=='html'?'images/':'../images/';
        this.preImage='images/';
	this.postImage='gif';
}

function TFlashButtons(browser,name,width,height,bgcolor) {
	this.browser=browser;
	this.name=name;        
	this.width=width;
	this.height=height;
	this.bgcolor=bgcolor;
	this.write=TFlashButtonsWrite;
	//this.preImage=this.browser.ext=='html'?'images/':'../images/';
        this.preImage='images/';
	this.setEnabled=TButtonSetEnabled;
}

function TButtonWrite() {
	if(this.name!=this.browser.name) {
                /*
		document.write('<a href="' + this.prePage + this.name + '.'+ this.postPage +'" onmouseover="javascript:browser.setEnabledButton(\'' + this.name + '\', true);" onmouseout="javascript:browser.setEnabledButton(\'' + this.name + '\', false);">');
		document.write('<img name="' + this.name + '" src="' + this.preImage + 'botao_' + this.name + '.' + this.postImage + '" width="' + this.width + '" height="' + this.height + '" border="0">');
		document.writeln('</a>');                
                */
		document.write('<a href="'+ this.prePage + this.name +'" onmouseover="javascript:browser.setEnabledButton(\'' + this.name + '\', true);" onmouseout="javascript:browser.setEnabledButton(\'' + this.name + '\', false);">');
		document.write('<img name="' + this.name + '" src="' + this.preImage + 'botao_' + this.name + '.' + this.postImage + '" width="' + this.width + '" height="' + this.height + '" border="0">');
		document.writeln('</a>');
	} else {
		document.write('<img name="' + this.name + '" src="' + this.preImage + 'botao_' + this.name + 'ON.' + this.postImage + '" width="' + this.width + '" height="' + this.height + '" border="0">');
	}
}

function TFlashButtonsWrite() {
	document.writeln('<object id="' + this.name + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + this.width + '" height="' + this.height + '">');
	document.writeln('<param name="movie" value="' + this.preImage + this.name + '.swf">');
	document.writeln('<param name="bgcolor" value="' + this.bgcolor + '">');
	document.writeln('<param name="swliveconnect" value="true">');
	document.writeln('<param name="play" value="false">');
	document.writeln('<param name="quality" value="best">');
	document.writeln('<embed src="' + this.preImage + this.name + '.swf" type="application/x-shockwave-flash" width="' + this.width + '" height="' + this.height + '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" quality="best" play="false" name="' + this.name + '" swliveconnect="true" bgcolor="' + this.bgcolor + '">');
	document.writeln('</embed>');
	document.writeln('</object>');
}

function TButtonSetEnabled(state) {
	if(!this.browser.useFlash || this.browser.isUnix) {
		if(state) {
			document.images[this.name].src=this.preImage+"botao_"+this.name+"ON."+this.postImage;
		} else {
			document.images[this.name].src=this.preImage+"botao_" + this.name + "."+this.postImage;
		}
	} else {
		if(state) {
			selectionFactory = this.browser.isIE ? eval('top.' + this.name) : top.document.embeds[this.name];                        
//			selectionFactory.SetVariable("ext",this.browser.ext);                        
			selectionFactory.TGotoLabel("_level0",this.browser.name);                        
		} else {
			// do nothing
		}
	}
}

var browser=new TBrowser();
