	
	// define the page info
emmapp.page = {
		
	childDialog: null,
	pageName: null,
	rowKey: null,
	pageKey: null,
	
	saveUrl: null,  // will be updated in jspPageInclude.jspf
	saveAddBaseUrl: null,
	saveDelBaseUrl: null,
	loginRequiredUrl: null, 
	contextPath: null,
	captchaImgUrl: null,
	ajaxElementBaseUrl: null,
	ajaxStoreUpdateBaseUrl: null,
	defaultSubmitAction: null,
	
	formId: "FORM_APP_PAGE_CONTENT",
	ROWKEY_SEPARATOR: "_S_",

	validationData: [],
	validationElements: [],
	enableOnBlurValidation: false,
	
	msgBuffer: [],
	oldFormData: null,
	
	// hold those element ids that are invalid in the page
	// for example, state - some countries/regions does not have states
	// it's keyed by element id and the value is boolean - true for invalid
	invalidElements: [],
	
	setInvalid: function(/*String*/id, /*boolean*/ flag) {

		var e = this.byId(id);
		this.invalidElements[e.id] = flag;
	//	e.value = "";  // why clear the value ????
		
		// hide the element, asusming the container is two levels higher
		// i.e. <div><span><SELECT ...></span></div>			
		var e_container = e.parentNode.parentNode;
		if (flag) {
			// hide the container
			e_container.style.visibility = 'hidden';
			e_container.style.display = 'none';
		} else {
			e_container.style.visibility = 'visible';
			e_container.style.display = 'block';
		}

		
	},
	
	isInvalid: function(/*String*/id) {
		return this.invalidElements[id] == true;
	},
	
	isFormChanged: function() {
		var newFormData = dojo.formToQuery(this.formId);
		
		console.debug("Old Form Data:");
		console.debug(this.oldFormData);
		console.debug("New Form Data:");
		console.debug(newFormData);
		return newFormData != this.oldFormData;

	},
	
	hasMsg: function() {
		return this.msgBuffer.length > 0;
	},
	
	clearMsg: function() {
		this.msgBuffer = [];
	},
	
	showMsg: function() {
		if ( this.msgBuffer.length > 0 ) {
			alert(this.msgBuffer.join("\r\n"));
		}
	},
	
	addMsg:  function(msg) {

		this.msgBuffer[this.msgBuffer.length] = msg;
	},
	
	checkCharacter: function(id){
		
		var e = emmapp.page.byId(id);
		var tempName = e.value;
		var count =0;
		if(typeof(tempName)!="undefined"&&tempName!=null&&tempName.length>=2){
			for(var i=0;i<tempName.length-1;i++){
				//Filtering Spaces
				tempName = e.value.replace(/\s/g,'');
				if(tempName.charAt(i).toUpperCase()==tempName.charAt(i+1).toUpperCase()){
					count++;
				}
			}
			if((count+1)==tempName.length){
				var name = dojo.attr(e, "nameText");
				var text = emmapp.msg.sameRepeatingCharacter(name);
				emmapp.page.addMsg(text);

			}
		}
		
	},
	
	// get element in page by id
	byId: function (id, rowKey) {
		
		var fullId = id;
		if ( id.indexOf(this.ROWKEY_SEPARATOR) < 0 ) {
			var key = rowKey;
			if ( key == null || typeof key == "undefined" ) {
				key = this.rowKey;
			}
			
			
			if ( key != null && key != "" && id.indexOf(key)<0 ) {
				fullId = key + this.ROWKEY_SEPARATOR + id;
			} 
		}
		
		return dojo.byId(fullId);
	},
	
	dijitById: function (id, rowKey) {
		var e = this.byId(id, rowKey);
		if ( e != null ) {
			return dijit.byId(e.id);
		}
		
		return null;
	},
	
	getRowKey: function(id) {
		
		if ( id ) {
			var i = id.lastIndexOf(this.ROWKEY_SEPARATOR);
			if ( i > 0 ) {
				return id.substring(0, i);
			}
		}
		
		return null;
	},
	

	selectAllCheckBoxes: function(/*dom*/field) {
		console.log("selectAllCheckBoxes called with: " + field);
		var tbody = field.parentNode.parentNode.parentNode;
		var myName = field.name;
		console.log("selectAllCheckBoxes in: " + tbody.className);
		var checkBoxes = tbody.getElementsByTagName("input");
		for (var i=0; i<checkBoxes.length; i++) {
			var name = checkBoxes[i].name;
			if (name != myName) {
				var checked = field.checked;
				checkBoxes[i].checked = checked;
			}
		}
	},
	
	setElementValue:function(e,oValue)
	{
		if(!e.type){
			return;
		}
		if(typeof(e)=='undefined'){
			return;
		}
		if( e.type == "select-one" || e.type == "select-multiple" ){
			for(var i=0;i<e.length;i++){
				if(e.options[i].value==oValue){
					e.options[i].selected=true;
					break;
				}
			}
		}
			
	},
	
	getObjectValue: function(/*DOM Element*/e) 
	{	
		var obj = e;
		var value = null;
		
		if ( obj.type )
		{
			//alert(objectName + "has type '" + obj.type + "'");
			
			if ( obj.type == "radio" && obj.checked ) {
				value =  obj.value;
			}
			else if ( obj.type == "select-one" || obj.type == "select-multiple" ) {
				index = obj.options.selectedIndex;
				if ( index >= 0 ) {
					value = obj.options[index].value;
				}
			} 
		}
		
		if (value == null && obj.value ) {
			value = obj.value;
		}

		console.debug("Object " + e.id + ", value: " + value);

		
		return value;	

	},
	
	getSaveWithAddUrl: function(actionTarget) {
		var x = this.saveAddBaseUrl.indexOf("?");
		if ( x > 0 ) {
				return this.saveAddBaseUrl.substring(0, x) + actionTarget + this.saveAddBaseUrl.substring(x);
		} else {
			return this.saveAddBaseUrl + actionTarget;
		}
	},
	
	getSaveWithDeleteUrl: function(actionTarget) {
		
		var x = this.saveDelBaseUrl.indexOf("?");
		if ( x > 0 ) {
				return this.saveDelBaseUrl.substring(0, x) + actionTarget + this.saveDelBaseUrl.substring(x);
		} else {
			return this.saveDelBaseUrl + actionTarget;
		}
			
	},
	
	validateAndSubmit: function(actionId, actionUrl, actionPage) {
		if ( this.validateForm() ) {
			this.submitForm(actionId, actionUrl, actionPage);
		}
	},
	
	setActionId: function(actionId) {
		if ( actionId != null && actionId != "" && typeof actionId != 'undefined') {
			var form = dojo.byId(this.formId);
			form.pageActionId.value = actionId;
		}
		
	},
	
	submitForm: function (actionId, actionUrl, actionPage) {
		
		var form = dojo.byId(this.formId);
		
		this.setActionId(actionId);
		
//			if ( actionId != null && actionId != "" && typeof actionId != 'undefined') {
//				//this._setPageAction(form, actionId, actionPage);
//				form.pageActionId.value = actionId;
//			}
	  
		// the action page is the page that triggered the action,
		// if this is the page of the controller, you do not need to set this 
		// only needed when the action is from a sidebar page
		if ( actionPage != null && actionPage != "" && typeof actionPage != "undefined") {
			form.actionPageName.value = actionPage;
		}

		// if url is not specified, use default form action
		if ( actionUrl != null && actionUrl != "" && typeof actionUrl != 'undefined') {
			form.action = actionUrl;
		} else {
			form.action = emmapp.page.saveUrl;
		}
				

		form.submit();
		
		emmapp.showWaitCursor();
	},
	
	addValidationData: function(data) {
		var size = this.validationData.length;
		this.validationData[size] = data;
		
		console.debug("validation data set: " + size);
		console.debug(this.validationData);
	},
	
	_removeProtocol: function(/*string*/ url) {
		var i = url.indexOf("://");
		if ( i > 0 ) {
			url = url.substring(i + 3);
		}
		
		return url;
	},
	
	_addProtocol: function(/*string*/ url) {
		var i = url.indexOf("://");
		if ( i < 0 ) {
			url = "http://" + url;
		}
		
		return url;
	},
	
	__checkDomain: function(/*DOM Element*/e) {
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}
		
		if ( e == null ) {	
			return true;
		}
		
		var v = e.value;
		if ( v == null || v == "") {
			return true;
		}
		
		v = this._removeProtocol(v);
		
//		var domain_regexp =/^[a-zA-Z0-9]+([a-zA-Z0-9\-\.]+)?\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)($|\/|(\.[a-zA-Z]{2}($|\/)))/;
		// some urls does not have the right domain
		// for exampel, http://ir.xyz.us
		var domain_regexp =/^[a-zA-Z0-9]+([a-zA-Z0-9\-\.]+)?($|\/|(\.[a-zA-Z]{2}($|\/)))/;
		if (v.match(domain_regexp)) {
	   		return true;
	 	} 
					
		return false;
	},
	
	checkEmail: function(/*DOM Element*/e, /*Array*/msgBuffer) {
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}

		this.normalizeInput(e, "");
		
		var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		var v = e.value;
		if ( v == null || v == "") {
			return true;
		}
		
		if (v.match(emailRegEx)) {
	   		return true;
	 	} else {
	 		//var msg = "'" + v + "' is not a valid email address.";
	 		var msg = emmapp.msg.invalidEmail(v);
	 		if ( dojo.isArray(msgBuffer) ) {
				msgBuffer[msgBuffer.length] = msg;
			} else {
				alert(msg);
			}
	 	}
		
		return false;
	},
	
	checkUrl: function(/*DOM Element*/e, /*boolean*/needProtocol, /*Array*/msgBuffer) {
		
		var ret = true;
		
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}
		
		console.log("&&&&&&&&&& value = " + e.value);
		
		this.normalizeInput(e, "");
		var v = e.value;
		if ( v != "") {		
			if ( !this.__checkDomain(e) ) {
				var text = dojo.attr(e, "nameText");
				/*
				if (text == "" ) {
					text = "The URL you entered is not valid, please try again.";
				} else {
					text = "'" + text + "' you entered is not valid, please try again.";
				}
				*/
				text = emmapp.msg.invalidUrl(text);
				
				if ( dojo.isArray(msgBuffer) ) {
					msgBuffer[msgBuffer.length] = text;
				} else {
					alert(text);
				}
				
				ret = false;
			}
			
			if ( needProtocol ) {
				v = this._addProtocol(v);
			} else {
				v = this._removeProtocol(v);
			}

			e.value = v;
		}
		
		return ret;
	},
	
	normalizeInput:  function(/*DOM Element*/e, replaceWith) {
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}

		var v = e.value;
		if ( v != "") {
			var v2 = emmapp.string.normalize(v, replaceWith);				
			if ( v2 != v) {
				e.value = v2;
			}
		}
	},
	
	makeTitle:  function(/*DOM Element*/e) {
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}

		var v = e.value;
		if ( v != "") {				
			e.value = emmapp.string.cnvrt2title(v);
		}
	},
	
	makePhone: function(/*DOM Element*/e) 
	{
		if ( dojo.isString(e) ) {
			 e = this.byId(e, null);
		}

		var v = e.value;
		if ( v != "") {		
			v = emmapp.string.alpha2numericPhone(v);
			e.value = emmapp.string.remove_non_digits(v);
		}
	},
	
	validateRequired: function (/*string*/id, /*Array*/messages) {
		
		if ( this.isInvalid(id) ) {
			return;
		}
		
		var v = null;
		var text = null;
		var w = dijit.byId(id);
		if ( w != null ) {
			text = w.attr("nameText");
			v = w.getValue();
			
			// if display value is an valid attribute, it can't be empty
			if ( w.declaredClass == 'emm.widget.FilteringSelect' ) {
				v = w.getDisplayedValue();
				
				// test
				this.__test();
			}
		
		} else {
			var e = dojo.byId(id);
			v = this.getObjectValue(e);
			text = dojo.attr(e, "nameText");
		}
		
		if ( v == null || v == "" || emmapp.string.alltrim(v) == "") {
			//var msg = "'" + text + "' is required";
			var msg = emmapp.msg.required(text);
			
			if ( messages != null ) {
				messages[messages.length] = msg;
			} else {
				alert(msg);
			}
			
			//alert(messages);							
			//alert(messages.join("\r\n"));
			
			console.debug(msg + ", the value is " + v);
		} else {
			console.debug(id + "=" + v);
		}
		
	},
	
	validateLength: function (/*string*/id, minSize, maxSize, /*Array*/messages) {
		if ( this.isInvalid(id) ) {
			return;
		}
		
		var v = null;
		var text = null;
		var w = dijit.byId(id);
		if ( w != null ) {
			text = w.attr("nameText");
			v = w.getValue();
		} else {
			var e = dojo.byId(id);
			v = this.getObjectValue(e);
			text = dojo.attr(e, "nameText");
		}
		
		var msg = null;
		var len = (v == null) ? 0 : v.length;
		console.debug(text + " - length: " + len + "minSize=" + minSize + ", maxSize=" + maxSize);
		if ( minSize > 1 && len < minSize) {
			//msg = "The length of '" + text + "' must be at least " + minSize + " characters.";
			msg = emmapp.msg.toShort(text, minSize);
		}
		
		if ( maxSize > 0 && len > maxSize) {
			//msg = "The length of '" + text + "' cannot exceed " + maxSize + " characters.";
			msg = emmapp.msg.toLong(text, maxSize);
		}
		
		if ( msg != null ) {
			if ( messages != null ) {
				messages[messages.length] = msg;
			} else {
				alert(msg);
			}
			
		}			
	},
	
	/* suppoted types are 
	 * date, datetime, email, fax, phone, phone_ext, url, normalized, title
	 */
	validateType: function (/*string or DOM*/e, type, /*Array*/msgBuffer) {
		
		var id = e;
		if ( !dojo.isString(e) ) {
			id = e.id;
		}
		
		if ( this.isInvalid(id) ) {
			return;
		}
		console.debug("validateType: " + e + ", " + type);
		
		if ( type == 'email' ) {
			this.checkEmail(e, msgBuffer)
		} else if ( type == 'url' ) {
			this.checkUrl(e, true, msgBuffer)
		} else if ( type == 'webdomain' ) {
			this.checkUrl(e, false, msgBuffer)
		} else if ( type == 'fax' || type == 'phone' || type == 'phone_ext' ) {
			this.makePhone(e);
		} else if ( type == 'normalized' ) {
			this.normalizeInput(e, ' ');
		} else if ( type == 'title' ) {
			this.makeTitle(e);
		} else if ( type == 'date' ) {
			
		} else if ( type == 'datetime' ) {
			
		} 
		
		console.debug("validateType: " + e + ", " + type +  "   ... done");

	},
	
	validateForm: function(/*Array*/msgBuffer) {

		var messages = [];
		var showMsg = true;
		if ( dojo.isArray(msgBuffer) ) {
			messages = msgBuffer;
			showMsg = false;
		}

		for (x in this.validationData) {
			var data = this.validationData[x];
			var items;
			
			// process the typped item
			items = data.typeItems;
			console.debug("typeItems " + items);
			if ( items ) {
				console.debug("typeItems - length " + items.length);
				for (x in items){
					var item = items[x];
					this.validateType(item.id, item.type, messages);
				}				
			}

			// process required
			items = data.requiredItems;
			if ( items ) {
				for (x in items){
					var item = items[x];
					this.validateRequired(item.id, messages);
				}				
			}
			
			// process size
			items = data.sizeItems;
			console.debug("sizeItems " + items);
			if ( items ) {
				console.debug("sizeItems - length " + items.length);
				for (x in items){
					var item = items[x];
					this.validateLength(item.id, item.minSize, item.maxSize, messages);
				}				
			}
							
		}
		
		if ( messages.length > 0 ) {
			if ( showMsg ) {
				alert(messages.join("\r\n"));
			}
			return false;
		}
		
		return true;
	},
	
	checkMissingFields: function() {

		for (x in this.validationData) {
			var data = this.validationData[x];
			var items;
			
			// process required
			items = data.requiredItems;
			//alert(items.length);
			if ( items ) {
				//alert(items);
				for (y in items){
					
					var item = items[y];
					//alert(item.id);
					this.markMissingField(item.id);
				}				
			}								
		}
			
		return true;
	},
	
	markMissingField: function (/*string*/id) {
		
		
		if ( this.isInvalid(id) ) {
			
			return;
		}
		
		
		var v = null;
		var text = null;
		var w = dijit.byId(id);
		
		
		if ( w != null ) {
			
			//alert("id=" + id + ", w=" + w);

			text = w.attr("nameText");
			v = w.getValue();
			
			
			// if display value is an valid attribute, it can't be empty
			if ( w.declaredClass == 'emm.widget.FilteringSelect' ) {
				v = w.getDisplayedValue();
			}
		
		} else {
			
			
			w = dojo.byId(id);
			
			//alert("w is "+w);
			
			v = this.getObjectValue(w);
			
			//alert("v is "+v);
			
			text = dojo.attr(w,"nameText");
			
			
			//alert("text is "+text);
			
			
		}
		
		if ( null == v || v == "" ) {
			
			//alert("fix me!" + w);
			w.style.background = "#FFFF00";
			//console.debug(msg + ", the value is " + v);
			var did = id + "_DOJO";
			w = dijit.byId(did);
			if ( w ) {
				//alert(did + "=" + w.domNode);
				if ( w.domNode ) {
					w = w.domNode;
				}
			
				w.style.background = "#FFFF00";
			}
		}
	
		
	},
	
	
	
	init: function() {

		console.debug("emmapp.page.init() ...");

		console.debug("emmapp.page.__fixLayout() ...");

//		this.__fixLayout();
		
		// note: this is the onblur event for all the fields that need validation
		// may cause usability issue since when u leave an element you will get an alert message
		// better set on specific pages only
		if ( this.enableOnBlurValidation ) {
			console.debug("emmapp.page.__attachValidatorEvents() ...");
			this.__attachValidatorEvents();
		}
		
		console.debug("emmapp.page.__attachSubmitEvent() ...");

		this.__attachSubmitEvent();
		
//			console.debug("emmapp.page.__setElementFocus() ...");
//			this.__setElementFocus();

		console.debug("emmapp.page.__doFormSmokeCheck() ...");
		this.__doFormSmokeCheck();

		// test
		this.__test();
		
		this.oldFormData = dojo.formToQuery(this.formId);
		
		console.debug("Old Form Data:");
		console.debug(this.oldFormData);

		console.debug("emmapp.page.init() ... done");

	},

	__test: function() {
		// test
		/*
		var e = this.byId("mem_orgid");
		if ( e != null ) {
			console.debug("mem_orgid.type: " + e.type);
			console.debug("mem_orgid.value: " + dojo.attr(e, "value"));
			
			var w = this.dijitById("mem_orgid");
			var v = w.getValue();
			console.debug("mem_orgid: " + w);
			console.debug("mem_orgid: " + v);
			
			console.debug("Form Data:" + dojo.formToQuery(this.formId));
			
		}
		*/
	},
	
	__attachSubmitEvent: function() {
		
		if ( !dojo.isFunction(this.defaultSubmitAction) ) {
			return;
		}

		var form = dojo.byId(this.formId);
		var self = this;
		var fun = function(evt) {
			if ( evt.keyCode == dojo.keys.ENTER) {
				var e = evt.target;
//					this.submitForm(actionId, actionUrl, actionPage)
//					alert("submit");
									
				// if the control is a dojo store, may need to set the hidden text 
				// since that depsnds on onblur to set the value
				// TODO
				if (e.form == form ) {
					//alert("submit: " + e.id);
					self.defaultSubmitAction();
				}
			}
		};
		
		
		for (var i = 0; i < form.length; i++ ) {
			var e = form[i];
	
			
			// special handling hehe
			// these two items handled by them self 
			// better handle later
			if ( e.id == "buz_sortby" || e.id =="mem_sortby") {
				continue;
			}

			if ( e.type != "hidden" && e.type != 'textarea') {
//					alert("onkeyup: " + e.id + " - " + e.type);
				dojo.connect(e, "onkeyup", fun);
			}				
		}

	},
	
	__doFormSmokeCheck: function() {
		var form = dojo.byId(this.formId);
		console.debug("form.length=" + form.length);
		for (var i = 0; i < form.length; i++ ) {
			var e = form[i];
			// if list does not have option, set as invalid
			//console.debug(e.type);
			if ( e.type == 'select-one' || e.type == 'select-multiple') {
				if ( dijit.byId(e.id) == null && e.options.length == 0 ) {
					emmapp.selectionlist.setSelectOptionHtml(e, "");
					this.setInvalid(e.id, true);
				}
			}
		}
	},
	
	
	__attachValidatorEvents: function() {
		var self = this;
		for (x in this.validationData) {
			var data = this.validationData[x];
			var items;
			
			// process the typped item
			items = data.typeItems;
			if ( items ) {
				for (x in items){
					var item = items[x];
					this.__attachvalidateTypeEvt(item.id, item.type);
				}				
			}

			// process required
			items = data.requiredItems;
			if ( items ) {
				for (x in items){
					var item = items[x];
					this.__attachvalidateRequiredEvt(item.id);
				}				
			}

			// process size
			items = data.sizeItems;
			if ( items ) {
				for (x in items){
					var item = items[x];
					this.__attachvalidateLengthEvt(item.id, item.minSize, item.maxSize);					
				}				
			}						
		} // end for
	},
	
	__attachvalidateTypeEvt: function(id, type) {
		var self = this;
		var fun = function(evt){
			self.validateType(id, type, null);
		};
		
		console.debug("onblur")

	},
	
	__attachvalidateLengthEvt: function(id, minSize, maxSize) {
		var self = this;			
		dojo.connect(this.byId(id), "onblur", function(evt){
			self.validateLength(id, minSize, maxSize, null);
		});

	},
	
	__attachvalidateRequiredEvt: function(id) {
		var self = this;			
		dojo.connect(this.byId(id), "onblur", function(evt){
			self.validateRequired(id, null);
		});

	},
	
	__fixLayout: function() {
		// fix page layout
//		var maxColumnHeight = 0;
//		if(dojo.byId("PAGE_CONTENT_LEFT_COLUMN"))maxColumnHeight = dojo.contentBox(dojo.byId("PAGE_CONTENT_LEFT_COLUMN")).h;
//		if(dojo.byId("PAGE_CONTENT_MAIN_COLUMN"))maxColumnHeight = Math.max(dojo.contentBox(dojo.byId("PAGE_CONTENT_MAIN_COLUMN")).h, maxColumnHeight);
//		if(dojo.byId("PAGE_CONTENT_RIGHT_COLUMN"))maxColumnHeight = Math.max(dojo.contentBox(dojo.byId("PAGE_CONTENT_RIGHT_COLUMN")).h, maxColumnHeight);
//		
//		if(dojo.byId("PAGE_CONTENT_LEFT_COLUMN"))dojo.byId("PAGE_CONTENT_LEFT_COLUMN").style.height=maxColumnHeight.toString()+"px";
//		if(dojo.byId("PAGE_CONTENT_MAIN_COLUMN"))dojo.byId("PAGE_CONTENT_MAIN_COLUMN").style.height=maxColumnHeight.toString()+"px";
//		if(dojo.byId("PAGE_CONTENT_RIGHT_COLUMN"))dojo.byId("PAGE_CONTENT_RIGHT_COLUMN").style.height=maxColumnHeight.toString()+"px";
//		
//		console.log(" maxColumnHeight = " + maxColumnHeight);
		
		var hx = 0;		
		var w_main = dijit.byId("PAGE_CONTENT_MAIN_COLUMN");
		var w_right = dijit.byId("PAGE_CONTENT_RIGHT_COLUMN");
		var delta = 54;
		if (w_right) hx =  Math.max(dojo.marginBox(w_right.containerNode).h-delta, hx);
		
		if (w_main) hx =  Math.max(dojo.marginBox(w_main.containerNode).h, hx);
		
		if ( w_right && w_main ) {
			w_right.containerNode.style.height=hx.toString() +"px";
			w_main.containerNode.style.height=hx.toString()+"px";
		}
		
		
		// adjust the last right nav item
		var w_last = dijit.byId("PAGE_CONTENT_RIGHT_COLUMN_LAST");
		if ( w_last ) {
			var cord_m = dojo.coords(w_main.containerNode);
			var cord_r = dojo.coords(w_last.containerNode);
			
            for(var i in cord_m) {
            console.debug(i, cord_m[i]);
            }

            for(var i in cord_r) {
                console.debug(i, cord_r[i]);
            }

			var diff = cord_m.y + cord_m.h - (cord_r.y + cord_r.h) - 20;
			console.log("diff = " + diff);
			console.log(" cord_r.y = " + cord_r.y);
			console.log(" cord_r.h = " + cord_r.h);
			console.log(" w_right.containerNode.style.height = " + w_right.containerNode.style.height);

			if ( diff > 0 ) {
				w_last.containerNode.style.height = cord_r.h + diff + "px";
			} 
		}
	
	},
	
	__fixLayout_test: function() {
		// fix page layout
		var maxColumnHeight = 0;
//		if(dojo.byId("PAGE_CONTENT_LEFT_COLUMN"))maxColumnHeight = dojo.contentBox(dojo.byId("PAGE_CONTENT_LEFT_COLUMN")).h;
		
		var e_m = dojo.byId("PAGE_CONTENT_MAIN_COLUMN");
		var e_r = dojo.byId("PAGE_CONTENT_RIGHT_COLUMN");
		var box_m = dojo.contentBox(e_m);
		var box_r = dojo.contentBox(e_r);		
		if(e_m) maxColumnHeight = Math.max(box_m.h, maxColumnHeight);
		if(e_r) maxColumnHeight = Math.max(box_r.h, maxColumnHeight);
		
		if ( e_m && e_r ) {
			e_m.style.height=maxColumnHeight.toString()+"px";
			e_r.style.height=maxColumnHeight.toString()+"px";
		}
		
		/*
		var e_last = dojo.byId("PAGE_CONTENT_RIGHT_COLUMN_xxx");
		if ( e_last ) {
			 var cord = dojo.coords(e_last);
			 var cord_r = dojo.coords(e_m);
//	            for(var i in cord) {
//	                console.debug(i, cord[i]);
//	            }
			 var diff = cord_r.t + cord_r.h - (cord.t + cord.h);
			 e_last.style.height = e_last.style.height + diff + "px";
			 
		console.log("diff = " + diff);
		console.log("pos.y = " + cord.y);
		console.log("pos.h= " + cord.h);
		
		}
		*/
		
//		var w_m = dijit.byId("PAGE_CONTENT_MAIN_COLUMN");
//		var w_r = dijit.byId("PAGE_CONTENT_RIGHT_COLUMN");
//
//		var box_m = dojo.contentBox(w_m.containerNode);
//		var box_r = dojo.contentBox(w_m.containerNode);
//		
//		var hx = 0;		
//		var w1 = dijit.byId("PAGE_CONTENT_RIGHT_COLUMN");
//		if (w1) hx =  Math.max(.h, hx);
//		
//		var w2 = dijit.byId("PAGE_CONTENT_MAIN_COLUMN");
//		if (w2) hx =  Math.max(dojo.contentBox(w2.containerNode).h, hx);
//		
//		if ( w1 && w2 ) {
//			w1.containerNode.style.height=hx.toString()+"px";
//			w2.containerNode.style.height=hx.toString()+"px";
//		}
//		
//		var x = dijit.byId("PAGE_CONTENT_RIGHT_COLUMN_xxx");
//		
//		console.log("x.containerNode.style.height = " + x.containerNode.style.height);
//		console.log("hx= " + hx.toString());
//		console.log("x.containerNode.style.bottom = " + x.containerNode.style.bottom);
//		
//		x.containerNode.style.height = x.containerNode.style.height + hx.toString() -  x.containerNode.style.bottom +"px";
	},
	
	__setElementFocus: function() {
		
//			// set focus
//			var url = location.href;
//			var i = url.indexOf("#");
//			if ( i >=0 ) {
//				var bookmark = url.substring(i+1);
//				var e = this.byId(bookmark);
//				//alert(e.tagName);
//				if ( e != null ) {
//					e.focus();
//				}
//			}		
	}

};

