if (!window['_SPIRE_LIB_JS']) {
	var _SPIRE_LIB_JS = 1;
	
	var __BROWSER__ = (/Safari/i.test(navigator.userAgent) ? 'safari' : (window.opera ? 'opera' : (document.all ? 'msie' : (document.addEventListener ? 'mozilla' : '?'))));

function packArray(arr, vv) {
	if (!vv) { var pre = 'var '; vv = 't'; } else {var pre = '';}
	var res = pre + vv + '= new Array();\n';
	for (var v in arr) {
		if (typeof (arr[v]) == 'object') {res = res +  packArray(arr[v], vv + "['" + v + "']");}
			else {res = res + vv + "['" + v + "']=" + arr[v];}
		res = res + ';';
	}
	return res;
}

function unpackArray(str) {
	var res = [];
	if (str) {
		eval(str);
		if (t) { res = t; }
	}
	
	return res;
}


function $(e){if(typeof e=='string'){e=document.getElementById(e);}return e;}
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!==null){n.push(v);}}return n;}


/**
 *
 * Cookie related function
 *
 */
function setCookie( name, value, expires, path, domain, secure ) {
	/* set time, it's in milliseconds */
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )	{ expires = expires * 1000 * 60 * 60 * 24; }
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; }
	if ( start == -1 ) {return null;}
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) {end = document.cookie.length;}
	return unescape( document.cookie.substring( len, end ) );
}


function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) { document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";}
}

function setCookieArray( name, value, expires, path, domain, secure ) {
	var s;
	s = packArray(value);
	setCookie( name, s, expires, path, domain, secure );
}

function getCookieArray( name ) {
	var s;
	s = getCookie( name );
	return unpackArray(s);
}


function hideEl(id) {
	var el = document.getElementById(id);
	if (el) {
		el.style.display = 'none';
	}
}

function showEl(id) {
	var el = document.getElementById(id);
	if (el) {
		el.style.display = '';
	}
}

function pasteInto(id, data) {
	var el = document.getElementById(id);
	if (el) {
		
		if (document.all && !window.opera ) {
			el.style.filter = "progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=25)";
			el.filters[0].progress = 0;
			el.filters[0].apply();
		}
		
		el.innerHTML = data;
		if (document.all && !window.opera) {
			el.filters[0].play();
		}
		
		var re = /<script.*?>/g;
		var m1 = data.split(re);
		if (m1.length > 1) {
			for(var i=1; i<m1.length; i++) {
				var m2 = m1[i].split('</script>');
				if(m2 && m2[0]) {
					try {
						eval(m2[0]);
					} catch(e){};
				}
			}
		}		
	}
}

/**
 * onLoad pool
 * Note: original onload is not modified
 * functions will be executed upon DOM readiness
 */
var load_handlers = [];
var _handlersRun = false;

function runLoadHandlers() {
	if (_handlersRun) {return;}
	_handlersRun = true;
	for (var i = 0; i < load_handlers.length; i++) {
		load_handlers[i]();
	}
}

function addLoadHandler(handler) {
	load_handlers.push(handler);
}


switch (__BROWSER__) {

	case 'mozilla':
	case 'opera':
		document.addEventListener("DOMContentLoaded", function(){runLoadHandlers();}, false);
	break;
	case 'msie':
		document.write('<script type="text/javascript" id="onLoadHandlersTag" defer="defer" src="javascript:void(0)"><\/script>');
		var onLoadHandlersTag = $('onLoadHandlersTag');
		onLoadHandlersTag.onreadystatechange=function() {if (this.readyState=="complete"){setTimeout(runLoadHandlers, 1);}}
	break;
	case 'safari':
		var _lhTimer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){clearInterval(_lhTimer);runLoadHandlers();}}, 10);
	break;
	default:
		alert('onLoad pool could not detect your browser.');
}



// Additional JS stuff

var t = null;
function lookUpPT(val, ds, cb, els, inct) {
	pasteInto(ds, '<em>Searching..</em>');
	clearTimeout(t);
	var sI = 0;
	if (inct) {
		if ($(inct)) {
			sI = $(inct).checked;
		}
	}
	top.loadXMLDoc('/.ajax/?f=find-common-task&cb=pasteInto&id=' + ds + '&s=' + val + '&rcb=' + cb + (els ? '&els='+els : '') + (sI ? '&si=1' : ''));
}

function tt(e, val, ds, cb, els, inct) {
	clearTimeout(t);
	if (e.keyCode != 13) {
		t = setTimeout('lookUpPT(\''+val+'\', \''+ds+'\', \''+cb+'\',\''+els+'\', \''+inct+'\')', 750);
	} else {
		lookUpPT(val, ds, cb, els, inct);
	}
}

function insertRowInTable(tableId, afterId, before) {
	
	var tObj = document.getElementById(tableId);
	if (!tObj) {return false;}
	var b = tObj.getElementsByTagName('tbody');
	if (!b.length) {return false;}
	tObj = b[0];
	var insertPos = -1; // Last
	if (afterId) {
		if (afterId == 'first') {
			insertPos = 0;
		} else {
			var trS = tObj.getElementsByTagName("tr");
			for (var i = 0; i < trS.length; i++) {
				if (trS[i].id == afterId) {
					insertPos = before ? i + before : i;
					break;
				}
			}
		}
	}
	
	return insertPos;
}

function putDataIntoRow(rowObj, xmlData, className) {
	if (!rowObj) {
		return;
	}
	
	if (xmlData) {
		if (xmlData.hasChildNodes()) {
			var children = xmlData.getElementsByTagName('td');
			for (var i=0; i<children.length; i++) {
				var cellObj = rowObj.insertCell(rowObj.childNodes.length);
				if (document.all) {
					cellObj.innerHTML = serializeNode(children[i]);
				} else{
					for (var j=0; j<children[i].childNodes.length; j++) {
						cellObj.appendChild(children[i].childNodes[j]);
					}
				}
				if (className) {
					cellObj.className = className;
				}
			}
		}
	}
}

function parseDataIntoTable(tableId, xmlData, afterId, before) {
	if (xmlData) {
		if (xmlData.hasChildNodes()) {
			var rows = xmlData.getElementsByTagName('tr');
			var targetRowIdx = insertRowInTable(tableId, afterId, before);
			for (var i=0; i<rows.length; i++) {
				var tObj = document.getElementById(tableId);
				var insertIdx = targetRowIdx >= 0 ? targetRowIdx + i : targetRowIdx;
				var rObj = tObj.insertRow(insertIdx);
				rObj.id = 'ajaxDataTR-' + afterId + '-' + i;
				putDataIntoRow(rObj, rows[i], 'table-body-td-' + (i % 2));
				rObj.className = "table-body-row-" + (i % 2);
			}
		}
	}
}

function LinksOnClick(xHow, xCode){
  var objLinks = document.links;
  for(var i=0;i<objLinks.length;i++){
    //link with onclick
    if(objLinks[i].onclick && xHow){  
        objLinks[i].onclick = new Function(xCode + objLinks[i].onclick.toString().getFuncBody());
    }
    //link without onclick
    else if(xHow){  
      objLinks[i].onclick = new Function(xCode);
    }
	//remove return false link with onclick
    else if(!xHow && objLinks[i].onclick.toString().indexOf(xCode) != -1){  
      var strClick = objLinks[i].onclick.toString().getFuncBody().replace(xCode,"");
      objLinks[i].onclick = new Function(strClick);
    }
  }
}

/**
String util function
*/
String.prototype.replaceAll = function(find, replace) {
	var str = this;
	while (str.indexOf(find) > -1) {
		str = str.replace(find, replace);
	}
	return str;
}

String.prototype.getFuncBody = function(){ 
  var str=this.toString(); 
  str=str.replace(/[^{]+{/,"");
  str=str.substring(0,str.length-1);   
  str = str.replace(/\n/gi,"");
  if(!str.match(/\(.*\)/gi)) {str += ")";}
  return str; 
} 

var Titler = {
	title: '',
	show: '',
	
	tm1: [],
	tm2: null,
	
	doShow: function () {
		if (Titler.show) {
			document.title = Titler.show + '..........';
			/*for(var i=0; i<10; i++) {clearTimeout(Titler.tm1[i]);}
			clearTimeout(Titler.tm2);
			
			for(i=0; i<10; i++) {
				var txt = '';
				for (var j=i; j<10; j++) {
					txt += '.';
				}
				txt += Titler.show;
				for (j=0; j<i; j++) {
					txt += '.';
				}
				Titler.tm1[i] = setTimeout('document.title="'+txt+'";', 1000 + 250 * i);
			}
			
			Titler.tm2 = setTimeout(function() {Titler.doShow();}, 4000);*/
		}
	},
	
	doHide: function () {
		/*clearTimeout(Titler.tm2);
		for(var i=0; i<10; i++) {clearTimeout(Titler.tm1[i]);}*/
		document.title = Titler.title;
	},

	start: function (text) {
		Titler.show = text;
		if (!this.title) {this.title = document.title;}
		/*if (window['_a']) {
			_a.addEvent(document, "blur", Titler.doShow);
			_a.addEvent(document, "focus", Titler.doHide);
		}*/
		Titler.doShow();
	},
	
	stop: function() {
		if (window['_a']) {
			_a.removeEvent(document, "blur", Titler.doShow);
			_a.removeEvent(document, "focus", Titler.doHide);
			Titler.doHide();
		}
	}
}

}