var isBrowserIE = (navigator.appName.indexOf("Microsoft") > -1);
var dispTag = (isBrowserIE)?"block":"table-row";
var dispTRTag = (document.all)?"block":"table-row";

function toogleDiv(objId,flagVar) {
	var obj = $(objId);
	var flag = (typeof flagVar != "undefined")?flagVar:(obj.style.display=="none");
	if (obj.tagName.toLowerCase() == "tr") {
		toggleTableRow(objId,flag);
		return;
	}
	obj.style.display=(flag)?"block":"none";
}
function toggleTableRow(row,flag) {
	var rowObj = $(row);
	if (rowObj.tagName != "TR") {
		return;
	}
	rowObj.style.display=(flag)?dispTRTag:"none";
}	
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

// adds active flash object to the page
function loadFlash(flashMovie, width, height) {
	// document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="' + flashMovie + '"><param name="quality" value="high"><embed src="' + flashMovie + '" quality="high" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>');
	//document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="wmode" value="transparent"><param name="movie" value="' + flashMovie + '"><param name="quality" value="high"><embed src="' + flashMovie + '" quality="high" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>');
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + flashMovie + '" /><param name="quality" value="best" /><embed src="' + flashMovie + '" quality="best" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>');
}

function $(id) {
	return document.getElementById(id);	
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
};

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
};

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
};

ajax = Class.create();
ajax.prototype = {
	initialize: function(url, options){
		this.transport = this.getTransport();
		this.postBody = options.postBody || '';
		this.method = options.method || 'post';
		this.onComplete = options.onComplete || null;
		this.update = $(options.update) || null;
		this.request(url);
	},

	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},

	onStateChange: function(){
		if (this.transport.readyState == 4 && this.transport.status == 200) {
			if (this.onComplete) 
				setTimeout(function(){this.onComplete(this.transport.responseText);}.bind(this), 10);
			if (this.update)
				setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
			this.transport.onreadystatechange = function(){};
		}
	},

	getTransport: function() {
		if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else return false;
	}
};

var remoteXMRequestCounter = 0;
var webServices = new Array();

function WebServiceCall(com,mth,arg,requestid,ss,varFx) {
	var rid = (typeof requestid != "undefined" && requestid != null)?requestid:remoteXMRequestCounter++;
	var styl = (typeof ss != "undefined" && ss != null)?ss:"";
	var xmlStr = '<component '+ ' name="' + com + '"'; 
	xmlStr = xmlStr + ' stylesheet="' + styl + '"'; 
	xmlStr = xmlStr + ' requestid="' + rid + '"'; 
	xmlStr = xmlStr + '>'; 
	xmlStr = xmlStr + '<method name="' + mth + '">'; 
	for (a in arg) { 
		//xmlStr = xmlStr + '<param name="'+a+'" value="'+escape(arg[a].replace('@','_a_'))+'"/>';
		xmlStr = xmlStr + '<param name="'+a+'"><![CDATA['+arg[a]+']]></param>';
		//xmlStr = xmlStr + '<'+a+'><![CDATA['+arg[a]+']]><'+a+'/>';
	}
	xmlStr = xmlStr + '</method>'; 
	xmlStr = xmlStr + '</component>'; 


	var fx = (typeof(varFx) != "undefined")?varFx:this[mth+"_Result"];
	new ajax("/lib/tax/xm/remote.cfm",{method:"post",postBody:"xmlInput="+escape(xmlStr),onComplete: fx});
};

var browser = navigator.appName;
function createRequestObject() {
	var ro;
	if (browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}