/**
*
*/
	var tplOpenWindows = new Array;
	function tplOpenWindow(name, url, width, height, options, onReturn) 
	{
		var defopt = new Array;
		
		defopt['fullscreen'] = 'no';
		defopt['toolbar'] = 'no';
		defopt['status'] = 'no';
		defopt['menubar'] = 'no';
		defopt['scrollbars'] = 'auto';
		defopt['resizable'] = 'yes';
		defopt['directories'] = 'no';
		defopt['location'] = 'no';

		if (typeof event != 'undefined'
			&& event != null) 
		{
			defopt['left'] = event.clientX - (width / 2);
			defopt['top']  = event.clientY - (height / 2);

			if (defopt['left'] + width > 800) {
				defopt['left'] = 50;
			} //if

			if (defopt['top'] + height > 600) {
				defopt['top'] = 50;
			} //if
		} //if
		else 
		{
			defopt['left'] = 50;
			defopt['top']  = 50;  
		} //else

		defopt['width'] = width;
		defopt['height'] = height;

		if (typeof options != 'undefined' && typeof options == 'string') 
		{
			newOpt = options.split(',');

			options = new Array;
			for (i in newOpt) 
			{
				tmp = newOpt[i].split('=');

				options[tmp[0].trim()] = tmp[1].trim();
			} //for
		} //if

		var opt = new Array;

		for (x in defopt) 
		{
			if (typeof options != 'undefined' && typeof options[x] != 'undefined') 
			{
				opt[opt.length] = x + '=' + options[x];
			} //if
			else 
			{
			    opt[opt.length] = x + '=' + defopt[x];
			} //else			
		} //for

		opt.join(',');

		if (tplOpenWindows[name]) 
		{
			tplOpenWindows[name].close();
		} //if

		tplOpenWindows[name] = window.open(url, name, opt);

		if (typeof onReturn != 'undefined') 
		{
		// this is the function to call with a return value
			tplOpenWindows[name].onReturn = onReturn;
			
			if (typeof window.onReturns == 'undefined') 
			{
				window.onReturns = new Array;
			} //if

			window.onReturns[tplOpenWindows[name]] = onReturn;
		} //if

		return tplOpenWindows[name];
	} //func

	function popupCalendar(date) {
		date = showModalDialog("/common/scripts/calendar/calendar.html?date=" + date, null, "scrollbars:no;status:no;dialogWidth:200px;dialogHeight:190px;help:no");
		if (date) {
			return date;
		}
	}

	var tplIncludedFiles = new Array;
	function tplInclude(id, file, callBack, vars) 
	{
		var head = document.getElementsByTagName('head').item(0);
		var queryStr = '';

		if (typeof head == 'undefined') 
		{
			return false;
		} //if

		tplIncluded = callBack;

		if (typeof tplIncludedFiles[id] != 'undefined') 
		{ 
			head.removeChild(tplIncludedFiles[id]); 
		} //if

		if (typeof vars != 'undefined' && vars.length > 0) 
		{
			queryStr = tplArray2Query(vars);

			if (queryStr.length > 0) 
			{
				queryStr = '?' + queryStr;
			} //if
		} //if

		tplIncludedFiles[id] = document.createElement('script');
		tplIncludedFiles[id].src  = file + queryStr;
		tplIncludedFiles[id].type = 'text/javascript';
		tplIncludedFiles[id].id   = id;

		head.appendChild(tplIncludedFiles[id]);
	} //func

/**
*
*/
	function tplArray2Query(ary) {
		strs = new Array;
		size = ary.length;
		str = '';
		for (i = 0; i < size; i = i + 2) {
			if (i > 0) {
				str = str + '&';
			} //if
			str =  str + ary[i] + '=' + ary[i + 1];
		} //for

		return str;
	} //func


	String.prototype.ltrim = function () {
		return this.replace(/^\s+/,'');
	}

	String.prototype.rtrim = function () {
		return this.replace(/\s+$/,'');
	}
	String.prototype.trim = function () {
		return this.replace(/^\s+/,'').replace(/\s+$/,'');
	}
                    
/*
	function tplArray2Query(ary) {
		strs = new Array;
		for (i in ary) {
			strs[strs.length] = i + '=' + ary[i];
		} //for

		strs.join('&');

		return strs;
	} //func
*/