//========= HTML Utilities ==========

//--------------- Error Handling Utilities ---------------

/*

function addScript(name) {

	document.write("<script language=JavaScript src='" + name + ".js'><\/script>");

}

addScript("../scripts/version");

addScript("../scripts/string");

*/



var ERROR = {



	element: function(e,message) {

		e.innerText = "?";

		e.title += "Error: " + message + "\n";

	}



}





// =============== DOM Utilities ==============



var HTML = {



	// Returns a string value with quotes and escapes existing quotes so that it is valid HTML

	quotedString: function(s) {

		return '"'+s.replace(/"/g,"&quot;")+'"';

	},

	

	attribute: function(s,attrName) {	// Get the value of an attribute from an HTML fragment

		s = s.Range(new RegExp("\\s" + attrName + "\\s*=\\s*","i"));



		switch (s.charAt(0)) {

		case '"':

			s = s.Range(/"/,/"/);

			break;

		case "'":

			s = s.Range(/'/,/'/);

			break;

		default:

			s = s.Range("",/[\s>]/);

		}

		return s;

	},



	clientLeft: function(e) {

		var r = e.offsetLeft;

		while (e.offsetParent) {

			e = e.offsetParent;

			r += e.offsetLeft;

		}

		return r;

	},



	clientTop: function(e) {

		var r = e.offsetTop;

		while (e.offsetParent) {

			e = e.offsetParent;

			r += e.offsetTop;

		}

		return r;

	},

	

	////////////////////by dj added in 20030506///

	sectionLeft: function(e) {

		if(e&&e.className=="sMain")return 0;

		var r = e.offsetLeft;

		while (e.offsetParent) {

			e = e.offsetParent;

			if(e&&e.className=="sMain")break;

			r += e.offsetLeft;

		}

		return r;

	},



	sectionTop: function(e) {

		if(e&&e.className=="sMain")return 0;

		var r = e.offsetTop;

		while (e.offsetParent) {

			e = e.offsetParent;

			if(e&&e.className=="sMain")break;

			r += e.offsetTop;

		}

		return r;

	},

	//////////////////////////////////////////////



	href: {

	

		split: function(href) {	// Returns components of an href

		

			// Parse the href

			var re = /^([a-zA-Z]{3,10}:\/?\/?)?([^\/]*)?(\/[^?]*)?(\?.*)?$/.exec(href);

			

			// Return the components as an object

			if (re) {

				var r = {};

				r.protocol = re[1];

				r.host = re[2];

				r.pathName = re[3];

				r.search = re[4];

			} else {

				r = {protocol:"",host:"",pathName:"",search:""};

			}

			return r;

		},

		

		dir: function(href) {	// Get the directory for the specified href

			var p = href.lastIndexOf("/");

			if (p < 10) {

				return href + "/";

			} else {

				return href.substring(0,p+1);

			}

		},

		

		// Convert a URL to an explicit URL that includes the protocol

		explicit: function(url) {

			// Specify the protocol if it is not specified

			if (! /:\/\//.test(url)) url = "http:\/\/" + url;

	

			return url;

		},

		

// searchArgs - Convert a string to an object using URL parameter syntax

//	"?a=this&b=that" -> {a: "this", b: "that" }



		searchArgs: function(s) {

			var o = {};

			if (s && s.length && s.charAt(0) == "?") {

				s = s.substring(1);	// Skip leading question mark character

				var a = s.split("&");

				for (var i=0; i<a.length; i++) {

					var item = a[i];

					var p = item.indexOf("=");

					if ( p >= 0) {

						o[item.substring(0,p)] = item.substring(p+1);

					} else {

						o[item] = true;

					}

				}

			}

			return o;

		}

		

	},



	expandURL: function(url,baseURL) {		// Expand url reference from relative to absolute reference

	

		url = url.trim();

		if (url.IsStartWith("http")) return url;		// Already an absolute reference

		

		if (url.charAt(0) == "/") {					// Reference based on domain

			var r = HTML.href.split(baseURL);		// Split the parts of the base URL

			return r.protocol + r.host + url;

		} else {

			return HTML.href.dir(baseURL) + url;	// Reference within the current directory

		}



	},

	

	expandRefs: function(s,baseURL,fullURL) {		// Expand url references from relative to absolute references

	

	//	alert("s="+s+"baseURL="+baseURL+"\nfullURL="+fullURL);

		// Possible attribute formats:

		//		href='value'

		//		href="value"

		//		href=value

		//		there can be whitespace before or after the =

		// URL conventions

		//		href=home.htm	-> reference within the baseURL directory

		//		href=/home.htm	-> reference within the baseURL server

		//		href=//www.censoft.com/...		-> Keep as explicit location (shorthand)

		//		href=https?://...					-> Keep as explicit location

		// 	href=#target	-> insert in full URL beforehand

		//		href=(mailto:|javascript:)	-> keep as is

			

		var h2 = HTML.href.split(baseURL);			// Split the parts of the base URL

		var domain = h2.protocol + h2.host;	

		var dir = HTML.href.dir(baseURL);

		

		// Duplicated by replacement later

		// s = s.replace( /(\s(href|src|action|background)\s*=\s*["']?)\/\//gi, "$1" + h2.protocol );

		

		// Update HTML attributes href, src, action	

		if (domain) {

			// Convert references within the domain

			s = s.replace( /(\s(href|src|action|background)\s*=\s*["']?)\//gi, "$1" + domain + "/");

		}



		if (fullURL) {

			// Convert references within the domain

			s = s.replace( /(\s(href|src|action|background)\s*=\s*["']?)\#/gi, "$1" + fullURL + "#");

		}



		if (dir) {			

			// Convert explicit references to include a tab character (so they are not changed)

			s = s.replace(/(\s(href|src|action|background)\s*=)\s*(["']?(https?:|\/\/|javascript:|mailto:))/gi, "$1" + "\t" + "$3");		// Use tab to avoid matching in next step



			// Convert references within the directory

			s = s.replace(/(\s(href|src|action|background)\s*= *["']?)([^\/\t'"])/gi, "$1" + dir + "$3");

		}

		

		return s;

	},

	

	// Get a reference to an element based on its ID

	get: function(e) {

		if (!e) return null;

		return window[e];

	},

	

	setText: function(e,text) {	// Set the text for an html element

		if (!e) return;

		if (e.constructor == String) e = window[e];		// Argument can be name or element

		if (e) e.innerText = text;

	},

	

	setHTML: function(e,text) {	// Set the HTML for an html element

		if (!e) return;

		if (e.constructor == String) e = window[e];		// Argument can be name or element

		if (e) e.innerHTML = text;

	},

	

	setClass: function(e,text) {	// Set the HTML for an html element

		if (!e) return;

		if (e.constructor == String) e = window[e];		// Argument can be name or element

		if (e) e.className = text;

	},

	

	cleanTable: function(s,bCreateTH) {	// Clean the html source for a table

		s = s.strip(Tag("FONT|IMG|B|STRONG"),EndTag("FONT|B|STRONG"),TAG.comment).replaceAll(Tag.TABLE,"<table>").replaceAll(Tag.TD,"<td>").replaceAll(Tag("TR"),"<tr>");

		if (bCreateTH) {	// Convert the first row to TH from TD

			var tr = s.Tag("TR");

			var tr2 = tr.replace(Tag.TD,"<th>").replace(EndTag.TD,"</th>");

			tr2 = tr2.strip(Tag.A,EndTag.A,Tag.IMG);	// Strip links or img from the header

			if (tr2 != tr) s = s.replace(tr,tr2);

		}

		return s;

	},

	

	// e = parent element that IsContains the children

	// y = window coordinate that is the basis for selecting the child

	// --> {e=insertElement,where=where to insert}

	yToInsert: function(e,y) {	// Determine where to insert a child element based on the y coordinate

		var r = {};

		

		var Content_outscrollTop = 0;

		try{

			Content_outscrollTop = Content_out.scrollTop;

			y = y + Content_outscrollTop;

		}catch(e){}



		var top = e.offsetTop;

		var p = e.offsetParent;

		while (p) {

			top += p.offsetTop;

			p = p.offsetParent;

		}

		var c = e.children;

		if (y < top || ! c) {	// above object or no children

			r.e = e;

			r.where = "afterBegin";

		} else if (y > top + e.offsetHeight) {	// below children

			r.e = e;

			r.where = "beforeEnd";

		} else {

			for (var i=0; i<c.length; i++) {

				var ci = c[i];

				if (y < (top+ci.offsetTop+(ci.offsetHeight/2)) ) {	// Check if y is in the top half of the child

					r.e = ci;

					r.where = "beforeBegin";

					break;

				}

			}

			if (!r.e) {		// After all children

				r.e = e;

				r.where = "beforeEnd";

			}

		}

		return r;

	},

	//////////////////for sameRow///////////////////////////////////

	yToInsertforSameRow: function(e,y) {	// Determine where to insert a child element based on the y coordinate

		var r = {};

		

		var Content_outscrollTop = 0;

		try{

			Content_outscrollTop = Content_out.scrollTop;

			y = y + Content_outscrollTop;

		}catch(e){}

		

		var top = e.offsetTop;

		var p = e.offsetParent;

		while (p) {

			top += p.offsetTop;

			p = p.offsetParent;

		}

		var c = e.children;

		if (y < top || ! c) {	// above object or no children

			r.e = e;

			r.where = "afterBegin";

		} else if (y > top + e.offsetHeight) {	// below children

			r.e = e;

			r.where = "beforeEnd";

		} else {

		//	alert("y="+y);

			for (var i=0; i<c.length; i++) {

				var ci = c[i];

				if (y < (top+ci.offsetTop+ci.offsetHeight) ) {	// Check if y is in the top half of the child

					r.e = ci;

					r.where = "beforeBegin";

					break;

				}

			}

			if (!r.e) {		// After all children

				r.e = e;

				r.where = "beforeEnd";

			}

		}

		return r;

	},

	////////////////////////////////////////////////////////////////

	xToCell: function(oTR,x,initFunc) {		// get a TR cell based on an x coordinate

		// initFunc: function to apply to newly created cells

		var left = oTR.offsetLeft;

		var p = oTR.offsetParent;

		var c;

		while (p) {

			left += p.offsetLeft;

			p = p.offsetParent;

		}

		if (x < left) {

			c = oTR.insertCell(0);	// insert at beginning

		} else if (x > left + oTR.offsetWidth) {	// below children

			c = oTR.insertCell();		// append to end

		} else {

			var cells = oTR.cells;

			for (var i=0; i<cells.length; i++) {

				var cell = cells[i];

				if (x < left + cell.offsetLeft) {

					c = oTR.insertCell(i);	// Insert a new column before this column

					break;

				} else if (x <= left + cell.offsetLeft + cell.offsetWidth) {

					c = cell;		// Select this column

					initFunc = null;	// Do not need to initialize

					break;

				}

			}

			if (!c) c = oTR.insertCell();	// Default to append

		}

		if (initFunc) initFunc(c);

		return c;

	},

	////////////////for sameRow///////////////////////////

	deleteSameTable: function(djCell) {	// Delete the element if it has no children

		var djRow = djCell.parentElement;

		var index = djRow.cells.length - 1;

		for(var i = 0; i < djRow.cells.length;i++)

		{

			if(djRow.cells[i]==djCell)

			{

				index = i;

				break;	

			}

		}

		djRow.deleteCell(index);

		var djTab = djRow.parentElement.parentElement;

		///////////////当只有一个表格单元时则取出SECTION后，再删除表格///////////////////////////////

		if(djRow.cells.length == 1)

		{

			var se = HTML.firstChild.byClass(djRow.cells[0],"sMain");

			if(se&&djTab.tagName == "TABLE")

			{

				var c = VIEW.getColumn(se);		

				WEBBROWSER.moveElement(se,djTab,"beforeBegin");			// Move the section

			//	alert(se.id);

				se.atSameRow = "";

				djTab.deleteRow(0);

				djTab.removeNode(true);

				

			}

			return;

		}

		/////////////////////////////////////////////

		/////////////////当没有表格单元时则删除表格///////////////////////////////

		if(djRow.cells.length == 0)

		{

			if(djTab.tagName == "TABLE")

			{

				djTab.deleteRow(0);

				djTab.removeNode(true);

			}

			return;

		}

		

		

	},

	////////////////////////////////////////////

	deleteIfEmpty: function(e) {	// Delete the element if it has no children

		

		////////////////by dj in 20030508/////

		if(e && e.className == "cCol"&&e.tagName == "TD"){

			

			isLastCol = ContentTable.isLastCol(e);

			if(isLastCol){

				ContentTable.setPreColumnSpace(e,true);

			}

		}

		////////////////////////////////////////

	

		if (e && ! WEBBROWSER.firstChild(e) ) WEBBROWSER.removeNode(e);

	},

	

	autoSelect: function(e) {		// Change the user highlight to the specified element

		if (!e) e = event.srcElement;

		var r = e.document.body.createTextRange();

		r.moveToElementText(e);

		r.select();

	},



	deleteLastChild: function(e,tagName) {	// Delete the last child if it is the specified tagName

		var child = WEBBROWSER.lastChild(e);

		if (child && (! tagName || child.tagName == tagName)) WEBBROWSER.removeNode(child);	// Clear the child

	},

	

	className: {	// Utilities to manage class information for an element (supports multiple classes per element)

	

		// Add the specified class to the element

		add: function(e,className) {

			if (!e) return;

			if (e.className) { 

				e.className += " " + className;

			} else {

				e.className = className;

			}

		},



		// Remove the specified class from the element

		remove: function(e,className) {

			if (!e) return;

			e.className = e.className.replace(className,"").trim();

		},



		// Checks if the element is in the specified class

		member: function(e,className) {

			if (!e) return;

			return (e.className && e.className.indexOf(className) > -1);

		}	

	},

	eorp: {		// Utilities for accessing information from an element or a parent of the element

	

		// byClass - get the containing element with the specified className

		byClass: function(e,className){

			while ( e && e.className.indexOf(className) == -1) e = e.parentElement;

			return e;

		},

		

		// byTag - get the containing element with the specified tagName

		byTag: function(e,tagName){

			while ( e && e.tagName != tagName) {

				//alert(e.tagName);

				e = e.parentElement;

			}

			return e;

			

		},

		

		// byProp - get the containing element with the specified property

		byProp: function(e,propName) {

			while ( e && ! e[propName]) e = e.parentElement;

			return e;

		},

		

		// getProp - return the value of the specified property from the element or a parent

		getProp: function(e,propName) {

			while ( e && ! e[propName]) e = e.parentElement;

			return (e) ? e[propName] : null;

		},

		

		// Check if e is contained within e2

		within: function(e,e2) {

			while ( e && e != e2) e = e.parentElement;

			return (e) ? true : false;

		}



	},

	//

	// First Offspring is good for rifling through HTML elements looking for 

	// the first occurance of a class,TAG or property.  Great for finding the first TD or TR

	//

	

	firstOffspring: {

	

		byClass: function(e,className){

			var c = e;

			while (c) {				// Step through the children

				if (c && c.className.indexOf(className) != -1) return c;

				c = c.firstChild;

			}

			return null;

		},

		

		byTag: function(e,tagName){

			var c = e;

			while (c) {				// Step through the children

				if (c && c.tagName == tagName) return c;

				c =  c.firstChild;

			}

			return null;

		},

		

		byProp: function(e,propName) {

			var c = e;

			while (c) {				// Step through the children

				if (c && c[propName]) return c;

				c =  c.firstChild;

			}

			return null;

		}

	

	},

	

	firstChild: {		// Utilities for accessing information from a child of an element

	

		byClass: function(e,className){

			var c = e.children;

			for (var i=0; i<c.length; i++) {	// Step through the children

				var ci = c[i];

				if (ci && ci.className.indexOf(className) != -1) return ci;

			}

			return null;

		},

		

		byTag: function(e,tagName){

			var c = e.children;

			for (var i=0; i<c.length; i++) {	// Step through the children

				var ci = c[i];

				if (ci && ci.tagName == tagName) return ci;

			}

			return null;

		},

		

		byProp: function(e,propName) {

			var c = e.children;

			for (var i=0; i<c.length; i++) {	// Step through the children

				var ci = c[i];

				if (ci && ci[propName]) return ci;

			}

			return null;

		}

		

	},

	

	// outsideHTML(element) -> String

	// Returns the containing HTML TAG source without the innerHTML source

	// element - HTML element

	// Examples:

	//		"<p>Sample</b>" -> "<b></b>"



	outsideHTML: function(element) {

		var outer = element.outerHTML;

		if (! outer) return "";

		var outsideStart = outer.Match(TAG.all);	// Get the first TAG

		var p = outer.lastIndexOf("<");

		var outsideEnd = (p >=0) ? outer.substring(p): "";

		return outsideStart + outsideEnd;

	}

}





/*********************************************************************************

 * Object: MENU

 */



var MENU = {



	srcElement: null,	// The active source element

	e: null,			// The last source element that was displayed.  Used by other routines to determine menu context

	eMenu: null,



	

	// Initialize a menu table

	init: function(e) {

		// Check if the table was already initialized

		if (e.tagName != "TABLE" || e.onclick) return;

		

		e.cellSpacing = 0;

		e.cellPadding = 0;

		

		//e.onselectstart = EVENT.cancel;

		

		var rows = e.rows;

		for (var i=0; i<rows.length; i++) {

			var row = rows[i];

			row.onmouseover = MENU.highlight;

			row.onmouseout = MENU.clearHighlight;

		}

	},

	

	show: function () {

		var e = event.srcElement;

		var eventType = event.type;

		var eventClientX = event.clientX;		// Used for right click. put Menu

		var eventClientY = event.clientY;		// where the mouse was.





		if (e != MENU.srcElement) {

			e = HTML.eorp.byProp(e,"censoft_menu");

			if (MENU.srcElement && e) {

				if (MENU.srcElement.censoft_menu == e.censoft_menu) {

					MENU.hide();

					return;

				}

			}

		

			MENU.hide();



			if (e) {

				MENU.eMenu = e.censoft_menu;

				var x_offset = e.censoft_menu_align;

				MENU.srcElement = e;

				MENU.e = e;

				var theObj = window[MENU.eMenu];

				if (theObj) {

					MENU.init(theObj);

					var left = 0;

					var top = 0;				// Create temp vars because style adds pxs and makes it a string

					if (eventType == "contextmenu" || eventType == "mouseup" && event.button == 2) {		// RFD 03/14/00

						var left = eventClientX + document.body.scrollLeft - 5;

						var top = eventClientY + document.body.scrollTop -5 ;

					} else {

						if (x_offset > 0 || x_offset < 0) {

							var x_offset_pos = e.offsetWidth + 1 +(x_offset - 0);

							top -= 1;

						} else if  (x_offset == "CENTER") {

							x_offset_pos = e.offsetWidth / 2 +theObj.offsetWidth;

						} else if (x_offset && x_offset.match("LEFT")) {

							x_offset_pos = 0; //theObj.offsetWidth; Object width not needed because it messes up IE 4.

							var pattern = /\d+/;

							var topOffset = pattern.exec(x_offset);

							if (topOffset > 0) top = parseInt(topOffset[0]);

						} else {

							x_offset_pos = e.offsetWidth;

							if (theObj.className == "uMenu") 

								top += 5;

							else

								top -= 2;

						}

						left = e.offsetLeft + x_offset_pos;// - theObj.offsetWidth; it appears to always be zero, except in IE4 for the image in the combo-box.

						top += e.offsetTop + e.offsetHeight;

						while (e.offsetParent) {

							e = e.offsetParent;

							left += e.offsetLeft;

							top += e.offsetTop;

						}

					}

					//alert (left);

					if (left <1) left = 1;

					theObj.style.left = left;

					theObj.style.top = top;

					if (theObj.id == "eMenuView" && e.offsetHeight == 308) theObj.style.top = 66; // Added to set the menu higher when options clicked from left hand edit bar

					eAllMenus.style.display = '';

					theObj.style.visibility = 'visible';



					//disable the appropriate options if it is a master section

					MENU.setSectionMenuState( (MENU.srcElement.id) ? (MENU.srcElement.id) : (MENU.srcElement.censoft_object) );

					

					event.cancelBubble = true;		

				}

			}

		}

	},

	

	setSectionMenuState: function(sid) {

		var menuItems = VIEWLVL.disabledSMenuItems;

		var e = '';

		

		if( sid == 'master_sMenu_img' || sid == 'master') {

			for( var i=0; i < menuItems.length; i++ ) {

				e = document.all['eMenuSection_' + menuItems[i] + '_tr'];

				e.onclick = null;

				e.className = 'disabledToolMenu';

			}//end for

			

		} else {

			var item = '';

			for( var i=0; i < menuItems.length; i++ ) {

				item = menuItems[i];

				e = document.all['eMenuSection_' + item + '_tr'];

				e.onclick = new Function( PORTALPAGE.menu[item].action );

				e.className = "";

			}//end for

			

		}

	},

	

	highlight: function () {

		var e = event.srcElement;

		if (MENU.eMenu) {

			var oTR = HTML.eorp.byTag(e,"TR");

			if (oTR && !oTR.className) oTR.className = "uMenuHighlight";

		}

	},

	

	clearHighlight: function () {

		var e=event.srcElement;

		var oTR = HTML.eorp.byTag(e,"TR");

		if (oTR && oTR.className == "uMenuHighlight") oTR.className = "";

	},

		

	hide: function () {

		if (window.HEADER) HEADER.on=true;

		

		if (MENU.eMenu) {

			var theObj = window[MENU.eMenu];

			if (theObj) {

				theObj.style.visibility = 'hidden';

				eAllMenus.style.display = 'none';

				MENU.srcElement = null;

			}

		}

		

	},



	comboSelect: function (e,variable_name,display_name) {

		if (!e) {

			return;

		}

		while (e.tagName != "FORM") {

			e = e.parentElement;

			if (!e) {

				return;

			}

		}

		HTML.setText(document.forms[e.id].elements[0],variable_name);

		HTML.setText(document.forms[e.id].elements[0].nextSibling,display_name);

	}

	

}



/*********************************************************************************

 * Object: VIEWLVL

 * Purpose: Handles functionality of the page level sections and their interaction

 *			with the slave sections.

 */

var VIEWLVL = {

	// TODO:  This is a temporary solution to fix bug 3093 and 3094

	masterColumns: null,

	disabledSMenuItems: ['copy','del','input','refresh','chart','exportExcel'],

	goClicked: false,



	setTypeCntObj: function(conObjName,tgtName) {

		var pkg;

		

		if( !EP_VIEW.typeCntObjPkg ) {

			EP_VIEW.typeCntObjPkg = {};

		}

		

		if( !EP_VIEW.typeCntObjPkg[tgtName] ) {

			pkg = VIEW.CHOOSER_DATA.JSmapping[conObjName];

			EP_VIEW.typeCntObjPkg[tgtName] = pkg;

		}

	},

	

	removeHidTypes: function(outputs) {

		var lblID;

		var conObjPkgName;

		var out = [];

		

		for( var i=0; i < outputs.length; i++ ) {

			lblID = outputs[i];

			if( lblID.indexOf('|') != -1 ) {//type output

				conObjPkgName = EP_VIEW.typeCntObjPkg[lblID.Range('|','|')];

				//user does not the appropriate rights to page this contentObj

				if( contentScripts.IsContains(conObjPkgName) ) {

					out[out.length] = outputs[i]; //typed output that are visible

				}

			} else {

				out[out.length] = outputs[i]; //output without types

			}

		}//end for

		

		return out.clean();

	},

	

	clearInputs: function(sid) {

		//clear inputs on the section defintion

		var sDef = PORTALPAGE.getSectionObject(sid);

		var inp = sDef.inp.a;

		

		for( var i=0; i < inp.length; i++ ) {

			inp[i].v = ''; //clear all inputs

		}

		

		sDef.inp.a = inp; //set it to EP_VIEW.sections

		return inp;

	},

	

	//function to change old master map to use our new data structure for linking	

	modifyOldMap: function() {

		var vMasterMap = EP_VIEW.map.master;

		var slaveSections = null;

		

		for( var srcBinds in vMasterMap ) {

			slaveSections = vMasterMap[srcBinds];

			for( var i=0; i < slaveSections.length; i++ ) {

				if( !slaveSections[i].IsContains('|') ) {

					slaveSections[i] = slaveSections[i] + '.' + srcBinds + '|passthrough';

				}

			}//end for	

		}//end for

	},

	

	getInputs: function(){



		if(EP_VIEW.sections && EP_VIEW.sections['master']){

			return EP_VIEW.sections['master'].objects[0].inp.a;	

		}

		return null;

	},

	

	addInputFields: function (allLoadedObj) {

		var inFields = "";     //string of HTML inputs

		var inFieldsMarker = "";

		var prop = null;

		var obj = null;

		var objProp = null;

		var inputStr = '';

		var regExp = /\$/gi;

		var props = [];

		var listobj = null;

		var mInputs = this.getInputs();

		var masterMap = EP_VIEW.map['master'];

		var nxtPropCnt;

		var listURL = '';



		if(mInputs){

			for (var i=0; i<mInputs.length; i++) {

				var mInp = mInputs[i];

				var idx = 0;

				for (var j=0; j<mInputs.length; j++) {

					if(mInp.p.firstProp() == mInputs[j].p.firstProp() && mInp.n <= mInputs[j].n) {

						mInp = mInputs[j];

					}

				}

				mInp.canHaveListObj = true;

			}

			

			for (var i=0; i<mInputs.length; i++) {

				inputStr = '';

				props = [];



				objProp = mInputs[i].p.Range("",".");

				obj = allLoadedObj[objProp];

				

				if( obj ) {

					nxtPropCnt = 1;

					props[0] = obj[mInputs[i].p.Range(".","")];

					props[0].n = mInputs[i].n;

					props[0].v = mInputs[i].v;

					

					while (i+1 < mInputs.length && (mInputs[i].f != null && mInputs[i+1].f != null &&  (mInputs[i].f == mInputs[i+1].f))){ //has second field

						props[nxtPropCnt] = obj[mInputs[i+1].p.Range(".","")];

						props[nxtPropCnt].n = mInputs[i+1].n;

						props[nxtPropCnt].v = mInputs[i+1].v;

						i++;

						nxtPropCnt++;

					}//end if

					

					for(var y=0; y < props.length; y++) {

						prop = props[y];

						var id = prop.__p;

						var formId = id.replace(regExp, "");

						var inputVal = prop.v;

						

						if (!inputVal) {

							inputVal = "";

						}//end if

						

						if(prop._notShared){				

							id = objProp + "_" + id;

							formId = objProp + "_" + formId;

						}//end if

						

						switch(prop._inputType) {

							case 3:

								type = 'text';

								break;

							case 4:

								type = 'password';

								break;

							case 5:

								type = 'hidden';

								break;

						}//end switch

						inputStr += '<input class=iValue censoft_type=' + prop._type + ' censoft_dataInputs=' + prop.__p + ' id=' + id + ' name=' + prop.n + ' type=' + type + ' ' + ( (inputVal) ? ' value='+HTML.quotedString(inputVal) : "" ) + '>';

					}//end for

					

					//this is for the hyper links next to the input field.

					listobj = prop.__parent._listing;

					listURL = '';

					if(mInputs[i].canHaveListObj){

						if (listobj) {

							listURL = getListURL(listobj,formId);

						} else if( prop._type && TYPEOBJ.types[prop._type] && TYPEOBJ.types[prop._type].listing ) {

							listobj = TYPEOBJ.types[prop._type].listing;

							listURL = getListURL(listobj,formId);

						}

					}

				} else {

					nxtPropCnt = 1;

					//use the master section input definition since the content object has security on it.

					//we are doing this step because even through the slave section is not visible we need to render

					//the inputs as hidden so that when we save the page it doesn't delete it from the page definition

					//and since the inputs are hidden, section linking needs it to determine which input should be pushed.

					//ie inputs that are marked censoft_marker should not be pushed.

					props[0] = {};

					props[0].p = mInputs[i].p.Range('.','');

					props[0].n = mInputs[i].n;

					props[0].v = mInputs[i].v;



					while (i+1 < mInputs.length && (mInputs[i].f != null && mInputs[i+1].f != null &&  (mInputs[i].f == mInputs[i+1].f))){ //has second field

						props[nxtPropCnt] = {};

						props[nxtPropCnt].p = mInputs[i+1].p.Range('.','');

						props[nxtPropCnt].n = mInputs[i+1].n;

						props[nxtPropCnt].v = mInputs[i+1].v;

						i++;

						nxtPropCnt++;

					}

					

					for( var j=0; j < props.length; j++ ) {

						prop = props[j];

						var id = prop.p;

						inputStr += '<input censoft_marker=true type=hidden class=iValue id=' + id + '  name=' + prop.n + '  value=\"' + prop.v + '\" censoft_dataInputs=' + id + '>';

						for( var inpBind in masterMap ) {

							if( inpBind == id ) {

								var formId = id.replace(regExp, "");

								break;

							}

						}//end for

					}//end for

					

					prop = null;

				}//end contentScripts Check



				//this is the input field

				var censoft_con = objProp;



				if (prop && prop._inputType) {	

					inFields += "<tr id='" +formId + "_tr'><td class=iHLabel nowrap>" + prop._Name + "</td><td nowrap><FORM censoft_con='" + censoft_con + "' id=" + formId + " onsubmit='VIEWLVL.updateViews(\"master\");return false;'>";

					inFields += inputStr;

					inFields += "</form></td><td>" + listURL + "</td><td></td></tr>";

				} else {//input fields that has it's slave section not visible

					inFieldsMarker += "<tr censoft_marker=true id='" +formId + "_tr' style='display=\"none\"'><td class=iHLabel nowrap></td><td nowrap><FORM censoft_con='" + censoft_con + "' id=" + formId + ">";

					inFieldsMarker += inputStr;

					inFieldsMarker += "</form></td><td></td><td></td></tr>";

				}

			}//end for

		}//end if

	

		if(listURL) {

			var fPos = inFields.lastIndexOf("</td>");

		} else {

			var fPos = inFields.lastIndexOf("</td>") - 9;

		}



		if( inFields ) {

			inFields = inFields.substring(0, fPos) + '<form onsubmit="VIEWLVL.updateViews(\'master\');return false;" ><input type="submit" value="确定" id="upViewBtn" class=imgMap align=absMiddle></form>' + inFields.substring(fPos);

		//	alert(infields);

		}

		return inFields + inFieldsMarker;

	},

	

	retrieveCntObjFromRoot: function (objName,obj) {

		var obj0 = o.getRoot(objName);

		if( obj0 == null ) {

			//if counldn't get the obj b/c it has not load it yet then load it.

			var wp = SCRIPT.load(objName,null,null,true);

			

			if( wp && wp.status == 1 ) { //check the status

				obj0 = VIEWLVL.setContentObjToRoot(objName);

				return obj0; //return the loaded object

			}

			return obj; //if not in cache and can't load it then return the original obj

		}

		return obj0; //return the object from cache

	},



	setContentObjToRoot: function (objName) {

		obj = o.template(objName);

		return obj;

	},

	

	index: function(ar, id){

		var i;

		for (var i = 0; i <= ar.length; i++)

		{

			if(ar[i] == id)

				return i;	

		}

		

		return -1;

	},



	addMap: function(srcSectionId, tarSectionId, id)

	{

		if(!EP_VIEW.map){

			EP_VIEW.map = {};

		}

		if(!EP_VIEW.map[srcSectionId])

		{

			EP_VIEW.map[srcSectionId] = {};

		}

		if(EP_VIEW.map[srcSectionId][id])

		{

			if(!EP_VIEW.map[srcSectionId][id].IsContains(tarSectionId))

			{

				EP_VIEW.map[srcSectionId][id][EP_VIEW.map[srcSectionId][id].length] = tarSectionId;

			}

		}

		else

		{

			EP_VIEW.map[srcSectionId][id] = [tarSectionId];

		}

	},

	

	createTableInMasterSection: function(){

		if(!document.all.inputTable){

				var bs = '<table id="inputTable"></table>';

				var body = PORTALPAGE.getBody(document.all.master);			// Get the section body

				body.insertAdjacentHTML('BeforeEnd', bs);

		}

	},

	

	toggleGoBtn: function(formName){

		if(document.forms[formName].all.slaveCkb){

			if(document.forms[formName].all.slaveCkb.length){

				for(var i = 0; i < document.forms[formName].all.slaveCkb.length; i++){

					if(!document.forms[formName].all.slaveCkb[i].children[0].style.display == ''){

						return;

					}

				}

			}

			document.forms[formName].go.disabled = true;

		}

	},

	

	toggleInputs: function(inName, formName, labelName, disable){

	

		document.forms[formName].elements[inName].disabled = (disable) ? true : false;

			

		document.forms[formName].all[labelName].className = (disable) ? "blur" : "iHLabel";

		

		if(!disable){

			document.forms[formName].go.disabled = false;

		}

	},

	

	toggleLink: function(formName, disable, inName) {

		if(document.forms[formName].all.dlgLink)

		{	

			var inp = document.forms[formName][inName];

			if(inp && inp.parentElement && inp.parentElement.parentElement && inp.parentElement.parentElement.children[3] && inp.parentElement.parentElement.children[3].innerHTML != ''){

				document.forms[formName].all.dlgLink.className = (disable) ? "blurLink" : "click";

			}

		}

	},

	

	updateViews: function(srcSectionId){

		VIEWLVL.goClicked = true;

		VIEWLVL.markAndSweep(srcSectionId);

		VIEW.updateInputDef(srcSectionId);

		VIEWLVL.pushSrcInput(srcSectionId);

		VIEWLVL.refreshSection(srcSectionId); //embeds and non linked section

	},



	pushSrcSection: function() {

		var sectionObj;

		for( var section in EP_VIEW.map ) {

			if( section == 'master' && VIEW.isOldMasterInput ) {

				VIEWLVL.markAndSweep(section);	//old views don't have linkCnt in there section def.

			}//end if

			

			if( !document.all[section].censoft_marker ) {//not including the invisible one

				//pushing only root master sections

				sectionObj = PORTALPAGE.getSectionObject(section);

				if( sectionObj.linkCnt == 0 ) {//root master sections have a linkCnt of zero

					VIEWLVL.pushSrcInput(section);

				}//end if

			}//end if

		}//end for

	},

	

	pushSrcOutput: function(element,bError) {

		//push output values to the slave section input field

		var sMain = HTML.eorp.byClass(element, 'sMain');

		if(sMain){

			var srcSectionId = sMain.id;

			var bindElementId = null;

			var value = null;

	

			var rend= SECTION_RENDER.getRend(srcSectionId);

			switch (rend.fmt) {

			case 'S':

				bindElementId = element.parentElement.el_id;

				value = element.innerText;

				break;

			case 'V':

				var rowIndex = element.parentElement.rowIndex;

				var colIndex = element.cellIndex;	//label column

				bindElementId = element.parentElement.parentElement.rows(0).cells(colIndex).el_id;

				value = element.parentElement.parentElement.rows(rowIndex).cells(colIndex).innerText;

				break;

			case 'H':

			default:

				var colIndex = element.cellIndex;

				bindElementId = element.parentElement.el_id;

				value = element.parentElement.children[colIndex].innerText;

				break;

			}

				

			if(EP_VIEW.map && EP_VIEW.map[srcSectionId] && bindElementId && EP_VIEW.map[srcSectionId][bindElementId]){

				var oTR = PORTALPAGE.getElement(srcSectionId,bindElementId,0);

				var srcType = oTR.censoft_type;

				var pushEmpty = !( value == ' ' && !VIEWLVL.goClicked ); //don't push empty string if the page is loading.

				

				// blank source types occur when outputs aren't typed, but are used in wildcards

				if((!srcType || ( TYPEOBJ.types[srcType] && !TYPEOBJ.types[srcType].mDetail)) && pushEmpty ) {

					VIEWLVL.pushToSlave(srcSectionId,bindElementId,bError);

				}

			}//end if

		}

	},



	pushSrcInput: function(srcSectionId) {

		if(EP_VIEW.map){

			if(EP_VIEW.map[srcSectionId]){//section linking and page level section

				var oForm = null;

				var sourceTypes = null;

				var slaveSections = null;

				var srcBinds = null;

				var slaveInfo = null;

				var sectionId = null;

				var elementId = null;

				var obj = {};

				var tgt = null;

				var srcType = null;

				var xf = null;

				var oSrcInp = null;

				var formName = null;

				var linkCnt = null;

				var section = null;

				var slaveId = null;

				

				//only push input fields.

				if( srcSectionId != 'master' ) {

					var sBody = PORTALPAGE.getBody2(document.all[srcSectionId]);

					oForm = sBody.children[0].children[0];

					

					sourceTypes = TYPEOBJ.getSrcTypes(oForm);

				}



				srcBinds = EP_VIEW.map[srcSectionId];

				for( var i in srcBinds ){

					oSrcInp = PORTALPAGE.getElement(srcSectionId,i);

					if( oSrcInp ) {//check to see if the input is available

					  	//Check to see if the master element is an input

						srcType = oSrcInp.censoft_type;

						formName = i.replace(/\$/, "");

						

						if ( srcSectionId == 'master' )

						{

							if( !oSrcInp.censoft_marker ) {//if the slave section is visible

								VIEWLVL.pushToSlave(srcSectionId,i);

							}

						}

						else

						{

							for( var x=0; x < sourceTypes.length; x++ ) {

								if(sourceTypes[x] == srcType ){//master element is an input field

									//call the transform and push the data

									VIEWLVL.pushToSlave(srcSectionId,i);

								}//end if

							}//end for

						}

					}//end if

				}//end for

			}//end if

		}//end if

	},

	

	pushToSlave: function(srcSectionId,inputId,bError) {

		var slaveInfo = null;

		var slaveId = null;

		var slaveSections = [];

		var slaveInputId = null;

		var obj = null;



		if( EP_VIEW.map[srcSectionId] && EP_VIEW.map[srcSectionId][inputId] ) {

			slaveSections = EP_VIEW.map[srcSectionId][inputId];

			for( var y=0; y < slaveSections.length; y++ ) {

				slaveInfo = slaveSections[y];

				slaveId = slaveInfo.firstProp();

				slaveInputId = slaveInfo.Range('.','|');

				

				if( document.all[slaveId] && !document.all[slaveId].censoft_marker ) {

					obj = VIEWLVL.getObjValue(slaveInfo,srcSectionId,inputId,bError);

					

					if( obj ) {

						VIEWLVL.pushValue(slaveInfo,obj);

					}

				}

			}//end for

		}

	},



	getObjValue: function(slaveInfo,srcSectionId,inputId,bError) {

		var oSrc = PORTALPAGE.getElement(srcSectionId,inputId); //check for output element

		var srcType = oSrc.censoft_type;

		var sectionId = slaveInfo.firstProp();

		var value = '';

		var obj = null;

		

		if( slaveInfo.IsContains('|') ) {//master section using transform and types

			elementId = slaveInfo.Range('.', '|');

			xf = slaveInfo.Range('|','');

			obj = {};



			//construct transform rule

			var oTgtInp = PORTALPAGE.getElement(sectionId,elementId);



			obj['tgt'] = oTgtInp.censoft_type;//target binding will always be an input element

			obj['src'] = srcType;

			

			if( bError ) {

				value = '';

			} else if( oSrc.tagName == 'INPUT' ) {//input element

				value = oSrc.value;

			} else { //output element

				if( VIEWLVL.isMultiOutDone(srcSectionId,inputId) ) {

					value = VIEWLVL.getOutputElementValue(slaveInfo, srcSectionId, inputId);

				} else {

					return null; //don't push

				}

			}



			obj[obj.src] = value;

			obj['connect'] = VIEWLVL.getConnTFName(document.all[srcSectionId]);

		}

		

		return obj;

	},

	

	isMultiOutDone: function(srcSectionId,inputId) {

		

		var rend= SECTION_RENDER.getRend(srcSectionId);

		var oSrc = PORTALPAGE.getElement(srcSectionId,inputId,0);

		if( oSrc.el_id.indexOf('_$_') != -1 ) {//embed

			var oSrcId = oSrc.el_id.replace(/_\$_/gi,'|').replace(/\$/,'');

		} else {

			var oSrcId = oSrc.el_id.replace(/\__/gi, '.').replace(/\$/gi, '');//get rid of the $ and __

		}

		

		var length;

		

		switch (rend.fmt) {

			case 'S':

				length = oSrc.cells.length;

				break;

				

			case 'V':

				length = oSrc.parentElement.parentElement.rows.length-1;

				break;

				

			case 'H':

			default:

				length = oSrc.cells.length-1;

				break;

		}//end switch

		var body = PORTALPAGE.getBody(oSrc);			// Get the section body

		var dataObject = body.dataObject0;

		var odo;

		var boundOutputs;

		var cntDone=0;

		

		

		if( length == 1 ) return true;

		

		for( var i=0; i < length; i++ ) {

			odo = window[dataObject+i];

			boundOutputs = odo.__boundOutputs;

			for( var j=0; j < boundOutputs.length; j++ ) {

				if( oSrcId == boundOutputs[j].propPath ) {

					if( boundOutputs[j].done ) {

						cntDone++;

					}

				}

			}

		}

		

		return ( cntDone == length );

	},

	

	pushValue: function(slaveInfo,obj) {

		if( slaveInfo.IsContains('|') ) {//master section using transform and types

			var sectionId = slaveInfo.firstProp();

			var elementId = slaveInfo.Range('.', '|');

			var oTgtInp = PORTALPAGE.getElement(sectionId,elementId);

			xf = slaveInfo.Range('|','');

	

			TYPEOBJ.doTransform(oTgtInp, obj, xf);

		}

	},

	

	getConnTFName: function(e) {

		var sBody = PORTALPAGE.getBody(e);

	//	alert(sBody.outerHTML);

		// bulletproof for input_custom.htm, which calls this without an sBody

		if (!sBody) return null;  

		

		var rootObj = o.get(sBody.dataPage,DATAOBJ.roots.censoft);

		var conTF = null;

		

		if( rootObj && rootObj[sBody.dataOutputs] && rootObj[sBody.dataOutputs]._connect ) {

			conTF = rootObj[sBody.dataOutputs]._connect;

		} else if( rootObj._connect ) {

			conTF = rootObj._connect;

		}

		return conTF;

	},



	unSelectMasterDRow: function(oTable) {

		var rows = oTable.rows;

		var kids = null;

		var kid = null;

			

		//unselect previous item

		for( var i=0; i < rows.length; i++ ) {

			kids = rows[i].children;

			for( var j=0; j < kids.length; j++ ) {

				kid = kids[j];

				if( kid.children.length !=0 && kid.children[0].tagName == 'A' ) {

					if( kid.children[0].style.fontWeight == 'bold' ) {

						kid.children[0].style.fontWeight = '';

					}

				}

			}

		}

	},

	

	updateDetail: function(value) {

		var obj = {};

		var slaveInfo = null;

		var e = window.document.activeElement;

		var sMain = PORTALPAGE.get(e);

		var srcSectionId = sMain.id;

		var rend= SECTION_RENDER.getRend(srcSectionId);

		

		switch (rend.fmt) {

			case 'V':

				//need this b/c the binding id is in the previous sibling's <TR> TAG

				var cell = HTML.eorp.byProp(e,'censoft_id');

				var inputId = (cell) ? cell.censoft_id.Range('.','') : ''; //the containing cell

				break;

			case 'S':

			case 'H':

			 default:

				var inputId = HTML.eorp.byProp(e,'censoft_rule').el_id;

				break;

		}



		if( EP_VIEW.map && EP_VIEW.map[srcSectionId] && EP_VIEW.map[srcSectionId][inputId] ) {

			var oTR = PORTALPAGE.getElement(srcSectionId,inputId);

			var srcType = oTR.censoft_type;

			var oTable = HTML.eorp.byTag(e,'TABLE');

			var oTgtInp = null;

			VIEWLVL.unSelectMasterDRow(oTable);

			e.style.fontWeight = 'bold';	//select the item



			var slaveSections = EP_VIEW.map[srcSectionId][inputId];

			for( var k=0; k < slaveSections.length; k++ ) {

				slaveInfo = slaveSections[k];

				slaveId = slaveInfo.firstProp();

				

				//update the slave section linkCnt, can't do markAndSweep b/c the we are not waiting on any other

				//besides the onClick of the hyperlink.

				EP_VIEW.sections[slaveId].objects[0].linkCnt = 1;

				

				slaveInputId = slaveInfo.Range('.','|');

				oTgtInp = PORTALPAGE.getElement(slaveId,slaveInputId);

				

				obj['src'] = srcType;

				obj['tgt'] = oTgtInp.censoft_type;

				obj[obj.src] = value;

				obj['connect'] = VIEWLVL.getConnTFName(document.all[srcSectionId]);

				VIEWLVL.pushValue(slaveInfo,obj);

			}//end for

		} else {

			DIALOG.alert('You need to bind this output element to a section to use this feature');

		}//end if

	},

		

	cycle: function(srcId, tgtId) {

	//checks to see if the src and target bind are going to result into a cycle

	//return true or false

		if( EP_VIEW.map && EP_VIEW.map[tgtId] ) {

			var list = [];

			var currNode = null;

			var nodeChildren = [];

			list = [tgtId];		//init list



			for( var i=0; i < list.length; i++ ) {

				currNode = list[i].Range('','.');

				if( currNode == srcId ) {

					return true; // there is a cycle

				} else {

					//list[i]'s children to the list and remove list[i] from the list array

					if( EP_VIEW.map[currNode] ) {//add to list if there is a node

						//remove node from list

						list[i] = null;

						list = list.clean();

						

						//replace with it's children

						nodeChildren = VIEWLVL.getNodeChildren(currNode);	

						list = list.concat(nodeChildren);

						list = list.deleteDup();	//remove duplicates

						

						i=-1; //start over

					} else {

						//remove node from list array

						list[i] = null;

						list = list.clean();

						

						i=-1; //start over

					}

				}//end if

			}//end for

		}

		return false;

	},



	getNodeChildren: function(tgtId) {

		var vMap = EP_VIEW.map;

		var srcBinds = null;

		var bindList = [];

		srcBinds = vMap[tgtId];

			

		for( var bindType in srcBinds ) {

			bindList = bindList.concat(srcBinds[bindType]);

		}//end for

		

		return bindList;

	},



	markAndSweep: function(srcSectionId) {

		if( !EP_VIEW.map ) return;

		var bindMap = EP_VIEW.map;

		var srcBinds = bindMap[srcSectionId];

		var tgtSID = null;

		var tgtSecDef = null;

		var srcElement = null;

		

		VIEWLVL.clearLinkCnt(srcSectionId); //initialize all associated lnkCnts before performing mark and sweep

		for( var IOType in srcBinds ) {

			srcElement = srcBinds[IOType];

			for( var x=0; x < srcElement.length; x++ ){

				tgtSID = srcElement[x].firstProp();

				tgtSecDef = PORTALPAGE.getSectionObject(tgtSID);

			//	alert(tgtSecDef.outerHTML);

				tgtSecDef.linkCnt++;

				if( EP_VIEW.map[tgtSID] ) {

					VIEWLVL.markAndSweep(tgtSID);

				}

			}//end for

		}//end for



	},

	

	clearLinkCnt: function(srcSectionId) {

		var bindMap = EP_VIEW.map;

		var srcBinds = bindMap[srcSectionId];

		var tgtSID = null;

		var tgtSecDef = null;

		var srcElement = null;

		

		for( var IOType in srcBinds ) {

			srcElement = srcBinds[IOType];

			for( var x=0; x < srcElement.length; x++ ){

				tgtSID = srcElement[x].firstProp();

				tgtSecDef = PORTALPAGE.getSectionObject(tgtSID);

				tgtSecDef.linkCnt = 0;

			}//end for

		}//end for

	},



	isInpSlaved: function(inputId,slaveId) {

		var vMap = EP_VIEW.map;

		var srcBinds = null;

		var slaveList = null;

		

		//check to see if input type is slaved to source section

		for( var srcId in vMap ) {

			srcBinds = vMap[srcId];

			for( var bindType in srcBinds ) {

				slaveList = srcBinds[bindType];

				for( var j=0; j < slaveList.length; j++ ) {

					if( slaveList[j].firstProp() ==  slaveId && inputId == slaveList[j].Range('.','|') ) {

						return true;

					}

				}//end for

			}//end for

		}//end for

		return false;

	},

	

	refreshSection: function(propName) {

		if(propName != 'master'){

			var body = PORTALPAGE.getBody(document.all[propName]);			// Get the section body

			var dataObject = body.dataObject;

			setTimeout('DATAOBJ.refreshInputs(' +dataObject+ ')');

		}

	},

	

	updateMasters: function(sectionId, inputId){

		if(!EP_VIEW.map)

			return;

		var tarSectionId = (inputId) ? (sectionId + '.' + inputId) : (sectionId);

		var delimeter = (inputId) ? ('|') : ('.');

		for(var i in EP_VIEW.map){

			for(var j in EP_VIEW.map[i]){

				for(var k = 0; k < EP_VIEW.map[i][j].length; k++){

					// in the case that EP_VIEW.map[i][j][k] is Stock_sMain_48474747474.$co_name|coname2ticker

					if(EP_VIEW.map[i][j][k] == tarSectionId || EP_VIEW.map[i][j][k].Range('', delimeter) == tarSectionId){

						EP_VIEW.map[i][j][k] = null;

					}

				}

				

				// clean up the array...it's a little expensive but this gurantee that the map object has the

				// lastest stuff	

				EP_VIEW.map[i][j] = EP_VIEW.map[i][j].clean();

				

				// delete the input fields from the master section

				if(EP_VIEW.map[i][j].length == 0 && i== 'master'){

					var formName = j.replace(/\$/gi, "");

					VIEWLVL.deleteForm(formName+'_tr', EP_VIEW.map.master[i]);

					delete EP_VIEW.map[i][j];

					VIEW.updateInputDef('master');

				}

				else if(EP_VIEW.map[i][j].length == 0){

					delete EP_VIEW.map[i][j];

				}

			}

			if(EP_VIEW.map[i] == null){

				delete EP_VIEW.map[i];

			}

		}

	},

	

	updateSlaves: function(sectionId){

		if(!EP_VIEW.map)

			return;



		for(var i in EP_VIEW.map[sectionId]){

			var slavedSections = EP_VIEW.map[sectionId][i];

			var inputId = i;

			

			if(slavedSections){

				for(var j = 0; j < slavedSections.length; j++){

					var slavedSectionId = slavedSections[j];

					

					// in the case that slavedSectionId is Stock_sMain_48474747474.$co_name|coname2ticker

					if(slavedSections[j].indexOf('|') > -1){

						slavedSectionId = slavedSections[j].Range('', '.');

						inputId = slavedSections[j].Range('.', '|');

					}



					// get the row element

					var rowElement;

					var e = document.all[slavedSectionId].all[inputId];

					if (e.length)

					{

						rowElement= e[0].parentElement.parentElement;

					}

					else

					{

						rowElement = e.parentElement.parentElement;

					}

					//enable drag and drop

					rowElement.children[1].dragType = 'inputRow';

					// hide the chain gif

					rowElement.children[0].children[0].style.display = 'none';

					// hide the tool tip that tells which master this input binds to

					rowElement.children[0].children[0].title = '';

					// change the style class on the label (e.g from grey to drak blue)

					rowElement.children[1].className = "iHLabel";

					// enable the input text field again (there might be two input fields, one hidden and one visible)

					for(var k = 0; k < rowElement.children[2].children.length; k++){

						rowElement.children[2].children[k].disabled = false;

					}

					// hide the link to open an chooser dialgo (e.g Find Companies)

					if(rowElement.children[3].all.dlgLink){

						rowElement.children[3].all.dlgLink.className = "click";

					}

				}

			}

		}

		// after updating it's slave, delete the section from the map object

		delete EP_VIEW.map[sectionId];

	},

	

	deleteSection: function(sectionId){

		VIEWLVL.updateSlaves(sectionId);

		VIEWLVL.updateMasters(sectionId);

	},

	

	

	// delete the input field from the master section

	// remember that the input fields are wrapped inside a form

	deleteForm: function(formName, inputId){

		

		if(!EP_VIEW.map.master[inputId])

		{

			var inputTable = '';

			for(var i=0; i < document.all.inputTable.children[0].children.length; i++){

				if( document.all.inputTable.children[0].children[i].id != formName)

				{

					inputTable += document.all.inputTable.children[0].children[i].outerHTML;

				}

			}

			

			var pos = inputTable.indexOf("upViewBtn");

			if(pos == -1 && inputTable)

			{

				var fPos = inputTable.lastIndexOf("</TD>");

				inputTable = inputTable.substring(0, fPos) + '<form onsubmit="VIEWLVL.updateViews(\'master\');return false;"><input type="submit" value="确定" id="upViewBtn" class=imgMap align=absMiddle></form>' + inputTable.substring(fPos);

			}

			var sBody = (PORTALPAGE.getBody(document.all.master)).innerHTML; // the sBody div

				

			var sBody_New = sBody.replace(/<table id=inputTable[.|\W|\w]+/gi, ""); // wipped out the whole input table

				

			//reconstruct the whole sMain div (to fix a IE 4. bug)

			(PORTALPAGE.getBody(document.all.master)).innerHTML = sBody_New + '<table id=inputTable><tbody>' + inputTable + '</tbody></table>';

		}

	},

	

	// create an input field in the master section

	addForm: function(element, formName, labelName, inName, input){

		var ContentObjectName = PORTALPAGE.getBody(document.forms[formName]).dataPage;

		var formId = input.id.replace(/\$/gi, ""); // Co_Name (form name can't start with a $)

	//	alert(element.className);

	//	if(element.className)

		///////////////////will error////////////////

		if(!document.forms[formId]){

				

			var listUrlTd = "";

			if(element.parentElement.parentElement.all.dlgLink){

				listUrlTd = element.parentElement.parentElement.all.dlgLink.parentElement.innerHTML;

			}

			

			var hiddenInput = '';

			for(var i = 0; i < document.forms[formName].elements.length; i++) {

				if(document.forms[formName].elements[i].type == "hidden"){

					hiddenInput += document.forms[formName].elements[i].outerHTML;

				}//end if

			}//end for



			var labelTd = (document.forms[formName].all[labelName].outerHTML).replace(/dragType="inputRow"/, '');

			var inputTextTd = document.forms[formName].all[inName].outerHTML;			

			var re = new RegExp(formName);

			listUrlTd = listUrlTd.replace(re, formId);



			var inputField = '<form censoft_con="' + ContentObjectName + '" id="' + formId + '" onSubmit="VIEWLVL.updateViews(\'master\');return false">' + hiddenInput + inputTextTd + '</form>';



			var inputTable = '';

			for(var i=0; i < document.all.inputTable.children[0].children.length; i++) {

				if( document.all.inputTable.children[0].children[i].innerHTML.indexOf('upViewBtn') != -1) {

					var tds= document.all.inputTable.children[0].children[i];



					var newTR = '';

					for(var j = 0; j < tds.children.length; j++) {

						if(tds.children[j].outerHTML.indexOf('upViewBtn') != -1) {

							newTR += '<td></td>';

						} else {

							newTR +=tds.children[j].outerHTML;

						}//end if

					}//end for



					newTR = '<tr dropType="inputRow" id=' + tds.id + '>' + newTR + '</tr>';

					inputTable += newTR;

				} else {

					inputTable += document.all.inputTable.children[0].children[i].outerHTML;

				}//end if

			}//end for



			var goBtn = '<form onsubmit="VIEWLVL.updateViews(\'master\');return false;" ><input type="submit" value="确定" id="upViewBtn" class=imgMap align=absMiddle></form>';

			if(listUrlTd) {

				var newTR = '<tr dropType="inputRow" id=' + formId + '_tr' + ' >' + labelTd + '<td>' + inputField + '</td><td>' + listUrlTd + '</td><td>' + goBtn +  '</td></tr>';

			} else {

				var newTR = '<tr dropType="inputRow" id=' + formId + '_tr' + ' >' + labelTd + '<td>' + inputField + '</td><td>' + goBtn + '</td><td></td></tr>';

			}

			var sBody = (PORTALPAGE.getBody(document.all.master)).innerHTML; // the sBody div

			var sBody_New = sBody.replace(/<table id=inputTable[.|\W|\w]+/gi, ""); // wipped out the whole input table



			//reconstruct the whole sMain div (to fix a IE 4. bug)

			(PORTALPAGE.getBody(document.all.master)).innerHTML = sBody_New + '<table id=inputTable><tbody>' + inputTable + newTR + '</tbody></table>';

	

			var formLength = document.forms[formId].elements.length;

			for( var i=0; i < formLength; i++ ) {

				if(document.forms[formId].elements[i] && document.forms[formId].elements[i].type == 'text') {

					document.forms[formId].elements[i].focus();

				}

			}//end for

			

			TABLE.init(document.all.master.all['inputTable']);

			

			//update the master section definition input fields

			VIEW.updateInputDef('master');

		}

		else{

			input.value=document.forms[formId][input.id].value;

			//refresh the enslaved section since it's value is different

			var dataObject = PORTALPAGE.getBody(document.all[formName]).dataObject;

			setTimeout('DATAOBJ.refreshInputs('+dataObject+')');

		}

	},

	

	getSectionTitle: function(sectionId){

		var columns = EP_VIEW.columns;

		if(columns){

			for(var i = 0; i < columns.length; i++){

				for(var j = 0; j < columns[i].sections.length; j++){

					for(var k = 0; k < columns[i].sections[j].objects.length; k++){

						if(columns[i].sections[j].objects[k].id == sectionId){

							return columns[i].sections[j].title;

						}

					}

				}

			}

		}

		return '';

	},

	

	setBindedToolTip: function(element, sectionId, inputId){

		// if title is set, no need to set it again

		if(element.title){

			return;

		}

		for(var i in EP_VIEW.map){

			for(var j in EP_VIEW.map[i]){

				for(var k = 0; k < EP_VIEW.map[i][j].length; k++){

					// in the case that EP_VIEW.map[i][j][k] is Stock_sMain_48474747474.$co_name|coname2ticker

					if(EP_VIEW.map[i][j][k] == sectionId || EP_VIEW.map[i][j][k].Range('', '|') == sectionId + '.' + inputId){

						var labelName = null;

						var sectionTitle = PORTALPAGE.getTitle(document.all[i]);

						

						if( sectionTitle ) {

							sectionTitle = sectionTitle.innerText.trim();

						} else {

							sectionTitle = PORTALPAGE.getSection(document.all[i].id).title;

						}

						

						var srcOut = PORTALPAGE.getElement(i,j);



						if(i == 'master'){ // input element in Master section

							labelName = HTML.eorp.byTag(srcOut, 'TR').children[0].innerText;

						} else if( srcOut && !srcOut.length && srcOut.tagName == 'INPUT' ){ // input element

							labelName = srcOut.parentElement.parentElement.children[1].innerHTML;

						} else if( srcOut ) { // output element

							var rend= SECTION_RENDER.getRend(i);

							switch (rend.fmt) {

							case 'S':

								labelName = srcOut.innerText;

								break;

							case 'V':

								labelName = srcOut.innerText;

								break;

							case 'H':

							default:

								labelName = srcOut.children[0].innerText;

								break;

							}//end switch

						}//end if



						if( labelName ) {

							element.title = (loc.boundTip1 + labelName + loc.boundTip2 + sectionTitle + loc.boundTip3);

						} else if( labelName == '' ) {

							element.title = (loc.boundTip1 + sectionTitle + loc.boundTip3);

						}else {

							element.title = (loc.boundTipErr);

						}

						return;

					}

				}

			}

		}

	},

	

	// unbind an element

	unbindElement: function(element, labelName, inName, formName, tarSectionId){

		var inputId = document.forms[formName].elements[inName].id;

		VIEWLVL.updateMasters(tarSectionId, inputId);

		VIEWLVL.toggleLink(formName, false, inName);

		VIEWLVL.toggleInputs(inName, formName, labelName, false);

		//enable drag and drop

		document.all[tarSectionId].all[labelName].dragType = 'inputRow';

		element.style.display = 'none';

		element.title = '';

		//update the slave section input value.

		VIEW.updateInputDef(tarSectionId);

		//mark page dirty

		VIEW.modified();

	},

	

	// inputId is the input field id in the source section

	bindElement: function(srcSectionId, element, labelName, inName, formName, slaveInfo, inputId, bAddForm){

		// input.id is the input field id in the target section

		var inputField = document.forms[formName].elements[inName];

		var sectionId = slaveInfo.firstProp();

		var slaveInputId = slaveInfo.Range('.','|');

		var value = '';

		

		element.style.display = '';

		VIEWLVL.addMap(srcSectionId, slaveInfo, inputId);	//e.g Company_Search_49585858858, $Co_Name

		VIEWLVL.toggleGoBtn(formName);

		if(srcSectionId == 'master' && bAddForm){

			VIEWLVL.createTableInMasterSection();

			VIEWLVL.addForm(element, formName, labelName, inName, inputField);

		}



		VIEWLVL.toggleInputs(inName, formName, labelName, true);

		VIEWLVL.toggleLink(formName, true, inName);

		

		//disable drag and drop for target input

		document.all[sectionId].all[labelName].dragType = '';

		

		element.onMouseOver = 'VIEWLVL.setBindedToolTip(' + element + ',"' + sectionId + '","' + inputId + '")';



		var oSrc = PORTALPAGE.getElement(srcSectionId,inputId);

		if( oSrc ) {

			var srcType = oSrc.censoft_type;

			var oTgtInp = PORTALPAGE.getElement(sectionId,slaveInputId);

			if( TYPEOBJ.types[srcType] && TYPEOBJ.types[srcType].mDetail ) {

				value = VIEWLVL.getMDValue(srcSectionId,inputId);

				if( value ) {

					if( oTgtInp.value != value ) {

						oTgtInp.value = value;

						VIEWLVL.refreshSection(sectionId);

					}

				} else {

					oTgtInp.value = '';

					VIEWLVL.refreshSection(sectionId);

				}

			} else if( oSrc.tagName == 'INPUT' ) {//input element

				value = oSrc.value;

			} else {//output element

				value = VIEWLVL.getOutputElementValue(slaveInfo, srcSectionId, inputId);

			}//end if



			//need to update each target input

			EP_VIEW.sections[sectionId].objects[0].linkCnt++;

			if( value && oTgtInp.value != value) {

				var obj = VIEWLVL.getObjValue(slaveInfo,srcSectionId,inputId);

				if( obj ) {

					VIEWLVL.pushValue(slaveInfo,obj);

				}

			} else {

				if( value == '' ) {//push the empty value and refresh the section.

					oTgtInp.value = '';

					VIEWLVL.refreshSection(sectionId);

				}

			}//end if

		}//end if

		

		//clear the slave section input so that it wouldn't be saved in the page.

		VIEW.updateInputDef(sectionId);

		//mark page dirty

		VIEW.modified();

	},



	getOutputElementValue: function(slaveInfo, srcSectionId, inputId){

		var rend= SECTION_RENDER.getRend(srcSectionId);

		var oSrc = PORTALPAGE.getElement(srcSectionId,inputId,0);

		var value = '';

		var el = null;

		var length = null;

		var selectedTRFunc = slaveInfo.Range('|','');

		

		var transformObj = TYPEOBJ.getTransform(selectedTRFunc);

		

		switch (rend.fmt) {

		case 'S':

			var rowIndex = oSrc.rowIndex;

			length = oSrc.cells.length;

			for( var i = 0; i < length; i++ ) {

				el = oSrc.parentElement.rows[rowIndex + 1].cells[i]

				if(transformObj.bHtml){	

					value += ( !value ) ? el.innerHTML : ',' + el.innerHTML;	

				} else {

					value += ( !value ) ? el.innerText : ',' + el.innerText;

				}

			}

			break;

		case 'V':

			var colIndex = oSrc.cellIndex;

			var rowIndex = oSrc.parentElement.rowIndex;

			length = oSrc.parentElement.parentElement.rows.length;

			for( var i = 1; i < length; i++ ) {

				el = oSrc.parentElement.parentElement.rows[rowIndex+i].cells[colIndex];

				if(transformObj.bHtml){

					value += ( !value ) ? el.innerHTML : ',' + el.innerHTML;

				} else {

					value += ( !value ) ? el.innerText : ',' + el.innerText;

				}

			}

			break;

		case 'H':

		default:

			length = oSrc.cells.length;

			for( var i = 1; i < length; i++ ) {

			

				var child = oSrc.children[i].children[0];

				if( child && child.className == "imgMap" ) {//span TAG

					el = child;

				} else {

					el = oSrc.children[i];

				}

				

				if(transformObj.bHtml){

					value += ( !value ) ? el.innerHTML : ',' + el.innerHTML;

				} else {

					value += ( !value ) ? el.innerText : ',' + el.innerText;

				}

			}

			

			break;

		}

		

		if( value == ' ' || value == '&nbsp;') value = ''; //value variable is set to blank space b/c of .innerText is &nbsp;

		

		return value;

	},

	

	getMDValue: function(srcSectionId,inputId) {

		var value = '';

		var oTR;

		var oTD;

		

		var rend = SECTION_RENDER.getRend(srcSectionId);

		if (rend.fmt == 'H')

		{

			oTR = PORTALPAGE.getElement(srcSectionId,inputId);

			oTD = oTR.children[1];

		}

		else if (rend.fmt == 'V')

		{

			oTD = PORTALPAGE.getElement(srcSectionId,inputId);

		}

		else

		{

			oTR = PORTALPAGE.getElement(srcSectionId,inputId);

			oTD = oTR.children[0];

		}

		

		var oTable = HTML.firstOffspring.byTag(oTD,'TABLE');

		

		if( oTable ) {

			value = VIEWLVL.getMDOutputElementValue(oTable);

		}

		/*

		var oTable = null;

		

		if( oTD.children[0] ) {

			oTable = oTD.children[0].children[0];

			value = VIEWLVL.getMDOutputElementValue(oTable);

		}

		*/

		return value;

	},

	

	getMDOutputElementValue: function(oTable) {

		var rows = oTable.rows;

		var kids = null;

		var kid = null;

		var value = null;

		

		//unselect previous item

		for( var i=0; i < rows.length; i++ ) {

			kids = rows[i].children;

			for( var j=0; j < kids.length; j++ ) {

				kid = kids[j];

				if( kid.children.length !=0 && kid.children[0].tagName == 'A' ) {

					if( kid.children[0].style.fontWeight == 'bold' ) {

						value = kid.children[0].innerText;

						break;

					}

				}

			}

		}

		return value;

	},

	

	clickIt: function(element, formName){

		if(element.className == "blurLink"){

			return;

		}

		DIALOG.openHandle(formName);

	},

	

	isMasterSecPresented: function(){

	

		if((document.all.master) || (contentScripts.IsContains("master") && EP_VIEW.map && EP_VIEW.map.master)){

			return true;

		}

		return false;

	},



	isSlaved: function(sectionId){

		for(var i in EP_VIEW.map){

			for(var j in EP_VIEW.map[i]){

				// given an input id and and target section id, get the source section (e.g the master section id)	

				for(var k = 0; k < EP_VIEW.map[i][j].length; k++){

				// in the case that EP_VIEW.map[i][j][k] is Stock_sMain_48474747474.$co_name|coname2ticker

					if(EP_VIEW.map[i][j][k].firstProp() == sectionId ){

						return true;

					}

				}

			}

		}

		return false;

	},

	

	isGoDisabled: function(inFields,e) {//slave section form id

		if( !EP_VIEW.map || !inFields ) return false;



		var sectionId = PORTALPAGE.get(e).id;

		var arrOfTextType = inFields.match(/type='text'/g);

		if( !arrOfTextType ) return false;

	

		var numOfTextType = arrOfTextType.length;

		var vMap = EP_VIEW.map;

		var srcBinds = null;

		var slaveList = null;

		var slaveId = null;

		var numOfSlaveInp = 0;

		

		//loop through EP_VIEW.map and count the number of sectionId occurances

		for( var srcId in vMap ) {

			srcBinds = vMap[srcId];

			for( var bindType in srcBinds ) {

				slaveList = srcBinds[bindType];

				for( var i=0; i < slaveList.length; i++ ) {

					slaveId = slaveList[i].Range('','.');

					if( sectionId == slaveId ) {

						numOfSlaveInp++;

					}//end if

				}//end for

			}//end for

		}//end for

		

		if( numOfSlaveInp == numOfTextType ) return true;

		

		return false;

	}

}



// getPropOutputs - Recursive property name expansion

// Fills the outputs array with the full path to all properties in the specified object

// obj - source object

// prefix - property name prefix up to object specified

// filter - Regular Expression to indicate which properties to include.  This can also

//		be an array of expressions if specific criteria for each level in the hierarchy

//		is desired.

// outputs - Resulting array of property paths

// depth - Current recursive call depth



function getPropOutputs(obj,prefix,filter,outputs,depth) {



	var maxDepth = 5;	// Maximum recursive depth to evaluate

	

	if (filter.length) {

		var propFilter = (depth < filter.length) ? filter[depth] : null;

		var pathFilter = null;

	} else {

		propFilter = null;

		pathFilter = filter;

	}

	

	var props = o.props(obj);		// Get the set of children

	props.sort(SORT.byProp);		// Sort the properties

	

	for (var i=0; i<props.length; i++) {

		var prop = props[i];

		var propName = prop.name;

		if (!propFilter || propFilter.test(propName) ) {

			var propObj = prop.obj;

			var propPath = ((prefix) ? prefix+"." : "") + propName;	// Get full path to property

			//if ((depth == filter.length-1) && (!pathFilter || pathFilter.test(propPath))) {

			if ( (!pathFilter || pathFilter.test(propPath))) {

				if (propObj.constructor == Function || (propObj.constructor == Object && (propObj.__v || propObj._Function || propObj._DefaultV))) {

					outputs[outputs.length] = propPath;

				}

			}

			if (propObj && propObj.constructor == Object) {	// Property is a DataObject

				if (depth < maxDepth) getPropOutputs(propObj,propPath,filter,outputs,depth+1);

			}

		}

	}

}//end VIEWLVL object definition



// expandDataOutputs - 

// Expand the dataOutputs paramter value to support multiple values and wildcards

// Multiple values can be listed (e.g. name,ticker,price)

// * is a wildcard

//		n*,ticker	- matches all field names that start with "n" and then ticker

// Regular expression syntax can be used

//		/t/i,/n/i	- matches all field names that contain "n", "N", "t", or "T"

// If a value IsContains a "." character, then the matching is done at each level of

// the object model.  For example, "Profile.*" matches just the first level items

// within the profile.  "Profile*" matches multiple levels of items.



function expandDataOutputs(dataOutputs,obj) {

	var lblObj = DATAOBJ.get(obj,dataOutputs,true);

	if (dataOutputs.indexOf("*") > -1 || dataOutputs.indexOf("/") > -1) {

		var a = dataOutputs.split(",");

		var outputs = [];

		var pattern = new RegExp();

		for (var i=0;i<a.length;i++) {

			var item = a[i];

			if (item == "/") {

				outputs[outputs.length++] = item;

			} else if (item.charAt(0) == "/" || item.indexOf("*") > -1) {

				if (item.indexOf(".") > -1) {	// Match specific levels in object hierarchy

					var items = item.split(".");

					pattern[items.length-1] = [];

					for (var j=0; j<items.length; j++) {

						pattern[j] = items[j].toRegExp();					

					}

				} else {

					pattern = item.toRegExp();

				}

				getPropOutputs(obj,"",pattern,outputs,0);

			} else {

				outputs[outputs.length++] = item;

			}

		}

		return outputs;

	} else if ( obj._DefaultE && dataOutputs == "_DefaultV") {

		return obj._DefaultE.split (",");

	} else if (lblObj._DefaultE) {

		return lblObj._DefaultE.split(",");

	} else {

		return dataOutputs.split(",");

	}

}



//-------------------------------



function documentReady(eDoc) {

//DEBUG.writeln("documentReady");

	if (!eDoc) eDoc = document;

	var all = eDoc.all;

	for (var i=0; i<all.length; i++) {

		var e = all[i];

		if (e && e._init ) {

			// Initialize the objects

			var a = e._init.split(",");

			switch (a[0]) {

			case "section":

				PORTALPAGE.init(e,a[1]);

				break;

			case "form":

				VIEW.init(e);

				break;

			}

			e._init = "";

		}

		if (e && (e.censoft_id || e._status ) ) {

			elementReady(e);

		}

	}

//DEBUG.writeln("documentReady - done");

}



// clean out any inputs that have been deprecated

function cleanInputs(element) {

	var odo = o.getRoot(element.dataPage);

	var inps = element.dataInputs;

	if (!inps) {

		return '';

	}

	inps = inps.split(';');

	var newInps = [];

	var inp = '';

	for (var i=0; i<inps.length; i++) {

		inp = inps[i];

		inp = inp.substring(0,inp.indexOf('='));

		if (odo[inp] && odo[inp]._inputType) {

			newInps[newInps.length] = inps[i];

		}

	}

	element.dataInputs = newInps.join(';');

	return element.dataInputs;

}



function elementReady(element) {//debugger;

	// dataFormat values:

	//		"form" - Display the form section at the top

	//		"form2" - Form with property names instead of labels

	//		"table" - Table with horizontal records

	//		"table2" - Table with vertical records

	//		"label" - Label for a property

	

	//		"H" - Table with horizontal records

	//		"V" - Table with vertical records

	//		"H0" - Table with horizontal records and no form

	//		"V0" - Table with vertical records and not form

	//		"H2" - Table with horizontal records property names instead of labels

	

	if (!element) return;	// Make sure there is a valid element

//	alert(element.dataFormat);

	if (element._status == 0){

		element._status = 1;

	}

	

	if (element.dataFormat) {

	

		// Links to manipulate the setup of the object



		var dataFormat = element.dataFormat.toUpperCase();	

		var dataObject = element.dataObject;	// Name of the object variable associated with the form

		

		if (! dataObject){

			dataObject = WEBBROWSER.uniqueID(element) + "_o";

		}

		if (dataFormat == "FORM") dataFormat = "H";

		if (dataFormat == "FORM2") dataFormat = "H2";

		if (dataFormat == "TABLE") dataFormat = "H0";

		if (dataFormat == "TABLE2") dataFormat = "V0";

		

		if (dataFormat.IsStartWith("H") || dataFormat.IsStartWith("V") || dataFormat == 'S') {

			

			// Parse the inputs and determine the number of objects to use

			

			//var inputs = element.dataInputs;

			var inputs = "";

			if (element.dataPage) {

				var obj = window[dataObject] = o.template(element.dataPage);

				if(element.dataPage == 'master'){

					inputs = element.dataInputs;		

				} else {

					inputs = cleanInputs(element);

				}

			} else {

				obj = window[dataObject];

			}	

						

			var original_inputs = inputs;

			if (inputs == "undefined") inputs = "";



			if(element.dataPage == "master"){

				var rowCount = 1;

			} else if (inputs) {

				var inputField = inputs.Range("","=");

				var inputVal = inputs.Range("=",";");

				if (obj._multiInputs) {

					var inputs = inputVal.split(",");

				} else {

					var inputs = [];

					inputs[0] = inputVal;

				}

				

				var rowCount = inputs.length;

				

			} else {

				inputField = "";

				rowCount = 1;

			}



			if (rowCount < 1) rowCount = 1;

			

			// Initialize objects if they are being created and populate Inputs

			var dataObject0 = dataObject.replace(/_o\d+/,"_o");	// Basis for created objects	

			

			// Clear the reference to associated data objects	

			// This is used by the VIEW.refresh function to refresh the display

			element.censoft_objects = "";

			for (var i=0; i<rowCount; i++) {

			

				// Get the dataobject

				if (rowCount > 1) dataObject = dataObject0 + i;	// e.g. id_o1, id_o2, etc.

				if (element.dataPage) {

					var obj = window[dataObject] = o.template(element.dataPage);

				} else {

					obj = window[dataObject];

				}

				

				//variable array to be use to draw the inputs in the master section.

				var mInFields = [];

				var mDataPgName = [];

				

				// Set the input values for the dataobject

				

				if (inputs && i < inputs.length) {

					//temp variable

					var redirectObj = obj;

					

					if (original_inputs.match(";")){

						inputFields = original_inputs.split(";");

						mInFields[0] = original_inputs.Range(".","="); //initialize master section original input. (company.$co_name=yahoo).

						

						for (var j = 0; j < inputFields.length; j ++) {

							var inField = "";

							var inVal = inputFields[j].Range("=",";");



							if( element.dataPage == "master" ) {

								inField = inputFields[j].Range(".","=");

								mInFields[j] = inField;			

								mDataPgName[j] = inputFields[j].firstProp();

								

								redirectObj = VIEWLVL.retrieveCntObjFromRoot(mDataPgName[j],obj);

							} else {

								inField = inputFields[j].Range("","=");

							}//end if



							//need new obj redirect

							if (redirectObj._multiInputs){

								var inps = inVal.split(",");

								DATAOBJ.set(redirectObj,inField,inps[i]);

							} else {

								var inps = inVal;

								DATAOBJ.set(redirectObj,inField,inps);

							}//end if

						}//end for

					} else {

						

						if( inputField != "" ) {

							mDataPgName[0] = original_inputs.firstProp();	

							

							if( element.dataPage == "master" ) {

								//acct for the extra referencing ie.  Company_Search.$Co_Name=yahoo

								inputField = original_inputs.Range(".","=");

								mInFields[0] = inputField;

								

								redirectObj = VIEWLVL.retrieveCntObjFromRoot(mDataPgName[0],obj);

							}//end if

							

					   		DATAOBJ.set(redirectObj,inputField,inputs[i]);

					    } else {

							DATAOBJ.set(obj,inputField,inputs[i]);

						}//end if					

					}//end if

				}//end if

				

				if (i==0) {

					var obj0 = obj;	// remember the first object

				} else {

					element.censoft_objects += ",";

				}

				

				element.censoft_objects += dataObject;

				

			}

			

			

			var form = '';

			var formName = '';

			

			if (rowCount > 1){

				dataObject = dataObject0 + "0";

			}

			

			element.dataObject = dataObject;

			element.dataObject0 = dataObject0;

			element.dObj = obj0;	// Remember the object so that setup can display the field list

			

			if (!dataFormat.IsContains("0")) {

				

				formName = dataObject + "_form";

				if(element.dataPage){

					if(element.dataPage == "master" && mInFields.length != 0){

						formName = mInFields[0].replace(/\$/gi, ""); //first input in the master section.

						form = getMasterSectionInputForm();

					}

					else{

			

						form = getSectionInputForm(element, dataFormat, original_inputs, inputs);

						

					}

				}

			}

		//	alert(form.outerHTML);

			// Save off the DOM state of the inputs, whether hidden or displayed. RS 7/27

			if (element.children[0] && element.children[0].style) {

				var tempInputDisplay = element.children[0].style.display;

			} else {

				tempInputDisplay = "";

			}

			

			//Can't add the form for the master section here b/c the instruction text is not constructed yet.

			//The form is added before the end of this function.

			if( element.dataPage != "master" ) {

				element.innerHTML = form;		// Create the form elements

				var inputTable = PORTALPAGE.getInputs(element);

				TABLE.init(inputTable);

			}

			

			// Restore the DOM state of the inputs to either hidden or displayed. RS 7/27

			if (element.children[0]) {

				element.children[0].style.display = tempInputDisplay;

			}

			

			if (form && GLOBAL.allLoaded && element.dataPage != "master") {			// Set the focus to the first input value

				var eIn = window[formName].I2;

				if (eIn) {

					if ( GLOBAL.focusInput ) clearTimeout( GLOBAL.focusInput );

					GLOBAL.focusInput = setTimeout("window['"+formName+"'].I2.select()");

				}

			}

			

			// array of cells to initialize

			var aInit = [];	// elements to initialize

			

			if (element.dataOutputs) {

				var par = element.parentElement;

				if (par && par.tagName == "TD" &&par.className=="pubTB")

				{

					par = HTML.eorp.byClass(element,"sMain");	

				}

				

				if (par && par.tagName == "TD" && !par.className) par.className = "oNestedTableCell";



				var outputs = expandDataOutputs(element.dataOutputs,obj);

				

				var t = [outputs.length];	// Contents of table to create



				var lp;

				var lblObj;

				var lblID;

				var lblValue;

				for (var row=0; row<rowCount; row++) {

					if (rowCount > 1) dataObject = dataObject0 + row;	// e.g. id_o1, id_o2, etc.

					obj = window[dataObject];

					//alert("a");

					setTimeout("DATAOBJ.copyOutputs("+dataObject+")");	// copy values to the table

					for (var col=0;col<outputs.length;col++) {

						if (row == 0) {

							lblID = outputs[col];

							lblObj = DATAOBJ.get(obj,lblID,true);

							lblValue = null;

							

							if (lblObj) {

								lblValue = (dataFormat == "H2") ? '' : o.title(lblObj) ;

							} 



							t[col] = { id: lblID, l: lblValue, o: [rowCount]};

							t[col] = TYPEOBJ.setOutputRuleAndType(t[col], obj, outputs[col]); 



							if (!t[col].l) {

								lp = outputs[col].lastProp();

								if( lp.indexOf('|') != -1 ) {//embeds

									//if transform and types not available then don't display the output element

									if( TYPEOBJ.transforms[t[col].r.xf] && TYPEOBJ.types[ lp.Range('|','|') ] ) {

										t[col].l = TYPEOBJ.types[t[col].r.tgt].t;

									} else {

										//make output element hidden because the embedded element is under security

										t[col].l = ' '; //????????

									}//end if

								} else {//regular outputs

									t[col].l = o.title(obj[lp],lp);

								}//end if

							}//end if

						}//end if

						t[col].o[row] = dataObject+"."+outputs[col];

					}//end for

				}

				SECTION_RENDER.drawOutputTable(element, dataFormat, t, aInit);



				////////by dj for hidden simple section Label///////////

				if(outputs.length == 1){

				//	alert(element.outerHTML);

					 var sMain = HTML.eorp.byClass(element,"sMain");

					 var mainID = sMain.id;

					 var s = document.all[mainID+"_sectionLabel_0"];

					 if(s){

						s.style.display = "none";

					 }

					 

					 

					 

				}

				//////////////////////////////////////////////////////////



				//drawOutputTable(element, dataFormat, t, aInit, outputs, outputTypes, outputRules);

				var oTABLE = WEBBROWSER.lastChild(element);

				TABLE.init(oTABLE);

				

				// Hide the cell borders for certain objects

				if (/(Text|master|Custom_HTML|Image|Web_Page|Link|Web_Section|BBS_Views|eOnline_Views|HSX_Views)/.test(obj0.__p)) oTABLE.className += "2";

				

				//oTABLE.onselectstart = EVENT.cancel;

				oTABLE.censoft_object = obj0.__p;			// Remember the type of the object

				oTABLE.censoft_menu = "eMenuSection";

			}



			/**

			 * the form and table are now in the body

			 * it can be refreshed here

			 */

			if (element.className=="sBody" && !element._refreshed) {

				element = WEBBROWSER.refreshBody(element);		// needed to wake up IE4

			}



			// Initialize the cell contents

			// convert cell reference to an object reference

			oTABLE = WEBBROWSER.lastChild(element);



			//need the input value before we update the outputs, this is for embeds.

			var oTD = null;

			var censoft_id = null;

			var bTDArray = null;

			var conTF = VIEWLVL.getConnTFName(element);

			var sid = PORTALPAGE.get(element).id;

			for (var i=0; i<aInit.length; i++) {

				//oTD = document.all[aInit[i]];

				oTD = PORTALPAGE.getAllElements(sid,aInit[i]);

				for (var j=0; j<oTD.length; j++) {

					setTDOutput(oTD[j],formName,conTF);

				}

			}//end for

			

		} else if (dataFormat == "LABEL") {

			drawLabel(element)

		} else {	// Invalid dataFormat

			element.innerHTML = "<p title='Invalid dataFormat - " + dataFormat + "'>?</p>";

		}

		

	} else {

		invalidDataFormat(element);

	}



	//need to add the form here b/c the instruction text is not available yet.

//	alert(element.outerHTML);

	if( element.dataPage == "master" ) {

		//element.parentElement.children[1].insertAdjacentHTML('BeforeEnd', form);

		element.parentElement.children[0].insertAdjacentHTML('BeforeEnd', form);

	}



	/**

	 * refreshBody will refresh the body's html if it has not yet happened

	 */

//	 alert(element.tagName);

	//alert("finished");

	

	if (element.tagName=="DIV") {

		return WEBBROWSER.refreshBody(element);		// needed to wake up IE4

	} else {

		return PORTALPAGE.getBody(element);

	}

	

}



function setTDOutput(oTD,formName,conTF) {

	censoft_id = oTD.censoft_id;

//	alert(censoft_id.indexOf('|'));

	if( censoft_id.indexOf('|') != -1 ) {//embeds

		var objVal = {};

		TYPEOBJ.setBoundOutputs(oTD,objVal);

		TYPEOBJ.setOutput(oTD,formName,conTF,objVal);

	} else {//regular section outputs.

		// Initialize newly created elements in the table

		elementReady(oTD);

	}

}



function getMasterSectionInputForm(){

	var form = '';

	var listURL = "";

	var allLoadedObj = DATAOBJ.roots.censoft;

	var inFields = VIEWLVL.addInputFields(allLoadedObj);

	

	form = inFields;

	return '<table id="inputTable">' + form + '</table>';

}



function getSectionInputForm(element, dataFormat, original_inputs, inputs){

	var form = '';

	var formName = element.dataObject + "_form";

	var bHidden = true;		// Hidden input field indicator

	var inCount = 0;		// Number of input fields

	var inFields = "";		// Mandatory input fields

	var options = "";		// Optional input fields

	var hidden_table = "";

	var listURL = "";

	var listobj = element.dObj._listing;

	var inName = '';

	var labelName = '';

	var id = '';

	var formId = '';

	var sMain = HTML.eorp.byClass(element,"sMain");

	if (listobj) {

		if ( !listobj.input ) listobj.input = {};

		listobj.input.dataObject = element.dataObject;

		listURL = getListURL(listobj,formName);

	}

	var props = o.props(element.dObj,true);

	props.sort(SORT.byProp); // Sort the properties

	//Debug.debug();

	for (var i=0; i<props.length; i++) {

		var slaved = false;

		var prop = props[i];

		var propObj = prop.obj;

			

		if (propObj && propObj._inputType) {

			//get the link url from the listType object if there is a type match

			if(!listobj && propObj._type) {

				if( TYPEOBJ.types[propObj._type] && TYPEOBJ.types[propObj._type].listing ) { 

					listobj = TYPEOBJ.types[propObj._type].listing;

					if ( !listobj.input ) listobj.input = {};

					listobj.input.dataObject = element.dataObject;

					listURL = getListURL(listobj,formName);

				}

			}

			if (propObj._inputType == 5 || propObj._inputType == 3 || propObj._inputType == 4) {

				inCount++;

				inName = "I" + inCount;

				labelName = "L" + inCount;

				inputVal = original_inputs.Range(propObj.__p + "=", ";");

				if (!inputVal && propObj.__v) {

					inputVal = propObj.__v;

					inputs = inputVal;

				}

				id = propObj.__p;

				formId = id.replace(/\$/gi, "");

			}

			

			if( !propObj._type ) propObj._type = '';



			if (propObj._inputType == 5) {

				var hfStyle = '';

				inFields += "<tr" + hfStyle + "><td class=iHLabel></td><td nowrap><input censoft_dataInputs='" + propObj.__p + "' censoft_type='" + propObj._type + "' class=iValue type='hidden' id='" + id + "' name='" + inName + "' " + ( (inputs) ? ' value='+HTML.quotedString(inputVal) : "" ) + "></td><td></td></tr>";

				DATAOBJ.addForm(element.dObj,formName,inName,prop.name);							

			}else if (propObj._inputType == 3 || propObj._inputType == 4) { //mandatory text(3) or password(4) fields

				bHidden = false;

				if(propObj._notShared){

					id = element.dataPage + "_" + id;

					formId = element.dataPage + "_" + formId;

				}



				slaved = VIEWLVL.isInpSlaved(id, sMain.id);



				if(listobj){

					if(slaved)

					{

						listURL = listURL.replace(/class=click/gi, "class=blurLink");

					}

					if(!DIALOG.handles[formId])

						DIALOG.setHandle( listobj.url || "../dialog/input_select.htm" + (isGzipped ? ".gz" : "") , formId, (listobj.dim && listobj.dim.w) ? listobj.dim.w : 580, (listobj.dim && listobj.dim.h) ? listobj.dim.h : 420, listobj.input, listobj.xargs, listobj.modal==false ? false : true );

				}

				

				if (propObj._inputType == 4) {

					inFields += "<tr dropType='inputRow'><td id='slaveCkb'><img onMouseOver=\"VIEWLVL.setBindedToolTip(this,'" + sMain.id + "','" + id + "')\" " + (slaved ? "" : "style=\"display:none\"") + " src=\"" + '/img/chain1.gif'.absURL() + "\"  onclick=\"VIEWLVL.unbindElement(this,'" + labelName + "','" + inName + "','" + formName + "','" + sMain.id + "'); return false;\"></td><td " + ( (slaved) ? "dragType=\"\"" : "dragType=\"inputRow\"" ) + " nowrap id=" + labelName + (slaved ? " class=blur" : " class=iHLabel") + ">" + prop._Name + "</td><td nowrap><input censoft_dataInputs='" + propObj.__p + "' censoft_type='" + propObj._type + "' class=iValue type='password'" + (slaved ? " disabled" : "") + " id='" + id + "' name='" + inName + "' " + ( (inputs) ? ' value='+HTML.quotedString(inputVal) : "" ) + "></td><td></td></tr>"

				} else {

					//_inputType:3

					//alert("id="+id);

					var size=40;

					if(propObj._size)

						size=propObj._size;

					var inputEx='';

					var inputPropEx='';

					switch(propObj._inputTypeEx)

					{	

						case 'file':

							inputEx="<INPUT TYPE='file' ID='fileUpload' STYLE='display:none' onChange='"+id+".value = this.value;'>"

									+"<INPUT TYPE='button' class=viewGo onClick='fileUpload.click()' VALUE='浏览...'>";

							break;

						case 'select':

							var idSelect=id +"_select";

							var nameSelect= inName +"_select";

							//var onchange= propObj.onchange ? propObj.onchange

							inputPropEx=" STYLE='display:none' onchange='for(var i=0;i<"+idSelect+".options.length;i++){if("+idSelect+".options[i].value==this.value){"+idSelect+".selectedIndex=i;break;}}'"; 

							inputEx="<select id='" + idSelect +"' name='" + nameSelect +"' onChange='"+id+".value = this.options[this.selectedIndex].value;'>"

								+(propObj._options?propObj._options(inputVal) :"")

								+"</select>";

							break;

					}

					inFields += 

						"<tr dropType='inputRow'><td id='slaveCkb'><img onMouseOver=\"VIEWLVL.setBindedToolTip(this,'" + sMain.id + "','" + id + "')\" " + (slaved ? "" : "style=\"display:none\"") + " src=\"" + '/img/chain1.gif'.absURL() + "\" onclick=\"VIEWLVL.unbindElement(this,'" + labelName + "','" + inName + "','" + formName + "','" + sMain.id + "'); return false;\"></td><td " + ( (slaved) ? "dragType=\"\"" : "dragType=\"inputRow\"" ) + " nowrap id=" + labelName + (slaved ? " class=blur" : " class=iHLabel") + ">" + prop._Name + "</td>"

							+"<td nowrap>"

							+"<input censoft_dataInputs='" + propObj.__p + "' censoft_type='" + propObj._type + "'"

								+" class=iValue type='text' size=" + size + (slaved ? " disabled" : "") 

								+" id='" + id + "' name='" + inName + "' " 

								+ ( (inputs) ? ' value='+HTML.quotedString(inputVal) : "" ) +inputPropEx+ ">"

							+ inputEx

							+"</td><td></td></tr>";

				}

			//	alert("formName="+formName);

				DATAOBJ.addForm(element.dObj,formName,inName,prop.name);

			//	alert("form="+document.all[formName].outerHTML);

			} else {

				

				bHidden = false;

				if (inputField) {

					if (prop.name == inputField || !sel_display) {

						var sel_display = prop._Name;	// Select the specified input

						var sel_name = prop.name;

					}

				} else {

					if (propObj.__v) {

						inputVal = propObj.__v;

						inputs = inputVal;

					}

					sel_display = (propObj._inputType==2) ? prop._Name : "";		// Select the default item

					sel_name = (propObj._inputType==2) ? prop.name : "";

				}

				hidden_table += "<tr onclick='MENU.comboSelect(" + this + ")'><td>" + prop._Name + "</td></tr>";

			}

		}

	}

		

	if (inFields || hidden_table) {

		if (hidden_table) {

			inCount++;

			inName = "I" + inCount;

			options = '<tr><td nowrap width=115 height=18 valign=top>'

				+ '<input type=hidden name="' +inName + '_propPath" value = "' +sel_name + '">'

				+ '<span class=uMenuCombox censoft_menu = "eCompanySelect" onclick="MENU.show()" censoft_menu_align=LEFT id=test>' + sel_display + '</span></td><td>'

				+ '<IMG SRC="' + '/img/win_down.gif'.absURL() + '" censoft_menu ="eCompanySelect" onclick="MENU.show()" censoft_menu_align=-135 ALT="Click to select" name="pulldown">'

				+ '</td><td><input class=iValue type=text name="' + inName + '" ' + ( (inputs) ? ' value='+HTML.quotedString(inputVal) : '' ) + '></td>'

				+ '<td></td></tr>';

			DATAOBJ.addForm(element.dObj,formName,inName);

			hidden_table = "<table id=eCompanySelect class='uMenuCombo'>" + hidden_table + "</table>";

		}



		form = inFields + options;

		var disableGo = VIEWLVL.isGoDisabled(inFields,element);

		// Add the Go button

		if (bHidden) {

		//	alert(listURL);

			form = form.substring(0,form.length - 19) + 

				   '&nbsp;' + 

				   listURL + 

				//   '&nbsp; <span style="visibility:hidden"><input type=image src="'+ 

				//   '/img/spacer.gif'.absURL() + 

				//   '" name="go"' + (disableGo ? ' disabled=true' : ' disabled=false') + 

				//   ' class=imgMap align=absMiddle></span>'+

				   '</td><td style="vertical-align:middle;"></td></tr>';

		} else {

			form = form.substring(0,form.length - 19) + "&nbsp;&nbsp;<input type='submit' value='确定' name='go' class=viewGo align=absMiddle" + (disableGo ? ' disabled' : '') + "></td><td style='vertical-align:middle;'> " + listURL + "</td></tr>"

		}

		var sid = sMain.id;

		form = '<div class=iMain><form id="' + formName + '" onSubmit="VIEWLVL.updateViews(\'' + sid + '\');return false">'

			 + '<table cellspacing=0 cellpadding=3>' + form + '</table></form></div>';



	} 

	//alert(form);

	return form;



}



function drawLabel(element){



	if (element.censoft_id) {

		var fld = element.censoft_id;

		var p = fld.indexOf(".");

		if (p >= 0) {

			var objName = fld.substring(0,p);

			fld = fld.substring(p+1);

			//var obj = o.getRoot( objName );

			var obj = window[objName];

			if (!obj) obj = o.getRoot( objName );

			if (obj) {	// Make sure the DataObject is valid

				var fldObj = DATAOBJ.get(obj,fld,true);

				if (fldObj) {

					element.innerText = (fldObj._Name) ? fldObj._Name : fld;

				} else {

					ERROR.element(element,"Unknown object '" + fld + "'.");

				}

			} else {

				ERROR.element(element,"Unknown object '" + objName + "'.");

			}

		} else {

			ERROR.element(element,"The censoft_id '" + fld + "' must specify both an object and a property.");

		}

	} else {

		ERROR.element(element,"A value must be specified for censoft_id.");

	}

}



function invalidDataFormat(element){

	if (element.censoft_id) {

		var fld = element.censoft_id;

		var p = fld.indexOf(".");

		if (p >= 0) {	// The root object is specified

			var objName = fld.substring(0,p);

			fld = fld.substring(p+1);

			//var obj = o.getRoot( objName );



			var obj = o.prop(window,objName,true);

			if (!obj) obj = o.getRoot( objName );

		} else {

			var e = element;

			while (e && (! e.dObj)) e = e.parentElement;	// Get from a parent object if not found

			obj = e.dObj;

		}

		if (obj) {	// Make sure the DataObject is valid

			if (element.tagName == "INPUT") {

				var v = DATAOBJ.get(obj,fld,true);

				if (v && v.value) element.value = v.value;

				DATAOBJ.addInput(obj,fld,element);

			} else {

				DATAOBJ.addOutput(obj,fld,element);					

			}

		} else {

			ERROR.element(element,"Unknown object '" + objName + "'.");

		}

	} else {

		ERROR.element(element,"A value must be specified for censoft_id.");

	}

}



function getListURL(listobj,formName) {

	var listURL = '';

	

	DIALOG.setHandle( listobj.url || "../dialog/input_select.htm" + (isGzipped ? ".gz" : ""), formName, (listobj.dim && listobj.dim.w) ? listobj.dim.w : 580, (listobj.dim && listobj.dim.h) ? listobj.dim.h : 420, listobj.input, listobj.xargs, listobj.modal==false ? false : true );

	listURL = "<SPAN id=\"dlgLink\" class=click onclick=\"VIEWLVL.clickIt(this,'"+ formName +"');\">"+ listobj.name +"</SPAN>";	

	return listURL;

}


