
function handleLink(url,id) {
	//console.log("handleLink('"+url+"','"+id+"') called.");
	document.cookie="_windowName="+escape(window.name);
	if (url.indexOf('_popupPageName=') > 0 && url.indexOf('_startPopup=true') > 0) {
		var target	= url.split('_popupPageName=',2)[1].split('&',2)[0];
		var url2	= url.split('_startPopup=true&');
		url2		= url2.join('');
		target		= "popupWindow_" + target + "_" + (id ? id : 0);
		win = window.open(url2,	target, "menubar=yes,width=950,height=700,toolbar=no,scrollbars=yes");
		if (!win) {
			//Catch the popup blocker
			alert('Please disable your popup blocker!!');
		}
		else {
			win.focus();
		}
	}
	else if (url.indexOf('_ajaxReplace=') > 0) {
	}
	else if (url.indexOf('_overlayName=') >0 ) {
	}
	else
		//window.location = url;
		return true;
	return false;
}

jQuery.fn.extend({
  processSum: function(updateOnly) {
	this.each(function() {
		var form = $(this);
		var sums = $(":text[sum]", form);
		if (sums.length > 0) {
			var cellArray = [];
			var cells = $.grep($(":text",form),function(n,i) {
				var name = $.trim($(n).attr('name'));
				cellArray[name] = $(n);
				return name.match(/^[A-Za-z_]+\d*$/);
			});
			var processRange = function(range) {
				var items = range.match(/([A-Za-z_]+)|(\d+)/g);
				var rtn = new Array();
				for(ch = items[0]; ch <= items[2]; ) {
					for (i = parseInt(items[1]); i <= parseInt(items[3]); i++) {
						if (cellArray[ch+i] != undefined)
							rtn.push( ch + i);
					}
					// increment the text part of the string.
					ch = ch.substring(0, ch.length-1) + String.fromCharCode(ch.charCodeAt(ch.length-1)+1);
				}
				return rtn.join('+');
			}

			var processFloat = function(name) {
				if (cellArray[name] == undefined)
					throw ("UNKNOWN field name, " + name);
				var cell = cellArray[name];

				return (cell.val().length == 0) ? 0 : parseFloat(cell.val().replace(/,/g,''));
			}

			var updateCells = function() {
				$(sums).each(function(i,n) {
					var stg = $(n).attr('sum');
					var s = stg.match(/[A-Za-z_]+\d+\.\.[A-Za-z_]+\d+/g);
					if (s) $.each(s, function(i,n) {
						stg = stg.replace(n,processRange(n));
					});
					stg = stg.replace(/([A-Za-z_]+\d*)/g,"processFloat('$1')");
					var rtn = 0;
					try {
						eval("rtn = " + stg + ';');
					} catch (e) {
						alert("Error in evaluating the sum data: "+(e.message ? e.message : e)+ "\n"+stg);
					}
					$(n).val(rtn);
				});
			};
			if (updateOnly==undefined || !updateOnly) {
				$(cells).change(function(n) {
					updateCells();
				});
			}
			updateCells();
		}
    });
	return this;
  }
});
