/*
	common.js (2008 version) ;

Update history ----------------------------------------
07/12 fixed "temp_dir" value.
      fixed "BAcommon" function.
-------------------------------------------------------
*/

function BAcommon() {
	this.env  = {};
	this.ns   = {};
	this.prfx = {};
	this.geom = {};

	this.env.ua       = navigator.userAgent;
	this.env.isMac    = this.env.ua.match(/Mac/),
	this.env.isWin    = this.env.ua.match(/Win/),
	this.env.isNN     = (document.layers),
	this.env.isMoz    = this.env.ua.match(/Gecko\//),
	this.env.isN6     = this.env.ua.match(/Netscape\/6/),
	this.env.isN7     = this.env.ua.match(/Netscape\/7/),
	this.env.isSafari = this.env.ua.match(/AppleWebKit/),
	this.env.isOpera  = (window.opera);
	this.env.isIE     = (document.all && !this.env.isOpera);
	this.env.ver      = navigator.appVersion;
	this.env.ver      = this.getUAVer();

	this.env.DOMok    = (document.documentElement && document.getElementsByTagName);
	this.ns.rootNS    = (this.env.DOMok) ? document.documentElement.namespaceURI : null;
	this.ns.xhtml1    = 'http://www.w3.org/1999/xhtml';
	this.ns.bAattrs   = 'urn:bA.attrs';
	this.prfx.bAattrs = 'bAattrs:';
	this.sharedDir    = this.getSharedDir();

	this.showErrMsg   = true;
	window.onerror    = this.errorHandler;
	try{document.execCommand("BackgroundImageCache", false, true);}catch(err){}
}

BAcommon.prototype = {
	getUAVer : function() {
		if(RegExp){
			if(this.env.isIE){
				return this.env.ua.match(/MSIE (\d(.\d+)?)/)[1];
			}
			if(this.env.isMoz){
				return this.env.ua.match(/(\d(.\d+)?) \(/)[1];
			}
			if(this.env.isNN || this.env.isN6 || this.env.isN7){
				return this.env.ua.match(/Netscape\/(\d(.\d+)?)/)[1];
			}
			if(this.env.isOpera){
				return this.env.ua.match(/Opera\/? ?(\d(\.\d+)?)/)[1];
			}
			return parseFloat(this.env.ver);
		}else{
			return undefined;
		}
	},

	getSharedDir : function() {
		var sheets = document.styleSheets;
		var ptn = /(.*\/?shared\/).+$/;
		//var temp_dir = window.location.protocol + '//' + window.location.host + '/main/eng/shared/'
		var temp_dir = window.location.protocol + '//' + window.location.host + '/shared/'
		return (sheets && sheets.length && sheets[0].href && sheets[0].href.match(ptn)) ? RegExp.$1 : temp_dir;
	},
	
	loadJS : function() {
		for(var i=0;i<arguments.length;i++){
			document.write('<script type="text/javascript" src="' + this.sharedDir + 'js/' + arguments[i] + '"><\/script>');
		}
	},

	loadReviseCSS : function() {
		var prefix = 'revise_';
		var suffix = '.css';
		var label  = (this.env.isIE  && this.env.isWin) ? '':
		             '';

		if (label && this.sharedDir) {
			var href = this.sharedDir + 'css/' + prefix + label + suffix;
		}
	},

	errorHandler : function() {
		if (this.showErrMsg) {
			var msg = 'Error: ' + arguments[0] + '\n' +
			          'File: '  + arguments[1] + '\n' + 
			          'Line: '  + arguments[2];
			alert(msg);
		}
		return true;
	}
};
var BA = new BAcommon;

BA.loadJS('prototypes.js','classnames.js','badom.js','baevent.js');
BA.loadJS('formctrl.js','toanchors.js');
if(!(BA.env.ua.isOpera && BA.env.ua.ver < 7)){
	BA.loadJS('rollover.js');
}
BA.loadJS('revise.js');
