var DEFAULT_CONTENT_PATH = "";
var submitting = false;
function doAction(actionName, param, notLockForm) { 
   if(!submitting) {
       if(!param) param = "";
	   try {
	      HtmlEditor.SaveHtmlContent(); 
	   }
	   catch(e) {
	   
	   }
	   if(!formOnSubmit()) {
	   	  return;
	   }
	   var form = document.forms[0];
	   var action = form.action;
	   var index = action.lastIndexOf(".shtml");
	   if(index == - 1) {
	   	  return;
	   }
	   index = action.lastIndexOf("/", index);
	   if(index == - 1)return;
   	   form.action = action.substring(0, index + 1) + actionName + ".shtml" +(param == "" ? "" : "?" + param);
	   
	   if(!notLockForm) {
	   	  submitting = true;
	   	  beginSubmit();
	   }
	   form.submit();
	}
}
function submitForm(notLockForm) { 
   if(submitting)return false;
   try {
      HtmlEditor.SaveHtmlContent(); 
   }
   catch(e) {
   }
   if(!formOnSubmit()) {
   	  return;
   }
   if(!notLockForm) {
	   submitting = true;
	   beginSubmit();
   }
   document.forms[0].submit();
}
function beginSubmit() {
	if(document.forms[0].target && document.forms[0].target!="_self") {
		submitting = false;
		return;
	}
	var cover = createCover(window, 0);
	var div = document.createElement("div");
	div.innerHTML = '\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019\uFF0E\uFF0E\uFF0E'; //<img style="border:none" src="' + getContextPath() + '/jeaf/common/img/loading.gif">
	div.style.cssText = "border:1 solid #aaaaaa; background:#ffff66; position:absolute; padding:5px; font-family:\u5B8B\u4F53; font-size:12px";
	div.style.left = cover.offsetWidth - 181;
	div.style.top = 1;
	div.style.width = 180;
	div.style.height = 25;
	cover.appendChild(div);
}
function getCurrentAction() {
	var action = window.location.pathname;
	var endIndex = action.lastIndexOf(".shtml");
	if(endIndex == - 1) {
		endIndex = action.lastIndexOf(".do");
	   	if(endIndex == - 1)return "";
	}
	var beginIndex = action.lastIndexOf("/", endIndex);
	return action.substring(beginIndex + 1, endIndex);
}
function formOnSubmit() {
	return true;
}
function parseJSObject(text) { 
	if(text.substring(0, "LISTBEGIN[".length)=="LISTBEGIN[") { 
		var list = new Array();
		parseJSObjectList(text, 0, list);
		return list;
	}
	else {
		var	object = new Object();
		parseSingleJSObject(text, 0, object);
		return object;
	}
}
function parseSingleJSObject(text, beginIndex, object) { 
	var objectEnd = -1, listEnd = -1, propertyEnd = -1, objValueEnd = -1;
	while(objectEnd==-1 && (propertyEnd=text.indexOf("=", beginIndex))!=-1) {
		
		var propertyName = text.substring(beginIndex, propertyEnd);
		object.attributes = object.attributes ? object.attributes + "," + propertyName : propertyName;
		beginIndex = propertyEnd + 1;
		var propertyValue = null;
		if(text.substr(beginIndex, "LISTBEGIN[".length)=="LISTBEGIN[") { 
			propertyValue = new Array();
			beginIndex = parseJSObjectList(text, beginIndex, propertyValue);
		}
		else if(text.substr(beginIndex, "OBJECTBEGIN[".length)=="OBJECTBEGIN[") { 
			propertyValue = new Object();
			beginIndex = parseSingleJSObject(text, beginIndex + "OBJECTBEGIN[".length, propertyValue);
		}
		objectEnd = text.indexOf("?", beginIndex);
		if(objectEnd==-1) {
			objectEnd = text.length;
		}
		listEnd = text.indexOf("]LISTEND", beginIndex);
		if(listEnd==-1) {
			listEnd = text.length;
		}
		objValueEnd = text.indexOf("]OBJECTEND", beginIndex);
		if(objValueEnd==-1) {
			objValueEnd = text.length;
		}
		objectEnd = Math.min(Math.min(listEnd, objectEnd), objValueEnd);
		propertyEnd = text.indexOf("&", beginIndex);
		if(propertyEnd==-1 || propertyEnd>objectEnd) {
			propertyEnd = objectEnd;
		}
		else {
			objectEnd = -1;
		}
		
		if(propertyValue==null) {
			propertyValue = text.substring(beginIndex, propertyEnd);
		}
		if(propertyValue!="") {
			try {
				eval("object." + propertyName.replace("function", "FUNCTION") + "=propertyValue");
			}
			catch(e) {
			}
		}
		beginIndex = propertyEnd + 1;
	}
	if(objectEnd==-1) {
	    return text.length();
	}
	else if(objectEnd==objValueEnd) {
	    return objectEnd + "]OBJECTEND".length;
	}
	else if(objectEnd==listEnd) {
	    return objectEnd + "]LISTEND".length;
	}
	else {
	    return objectEnd + 1;
	}
}
function parseJSObjectList(text, beginIndex, list) { 
	var index = 0;
	beginIndex += "LISTBEGIN[".length;
	while(text.substring(beginIndex - "]LISTEND".length, beginIndex)!="]LISTEND") {
		var object = new Object();
		beginIndex = parseSingleJSObject(text, beginIndex, object);
		list[index++] = object;
	}
	return beginIndex;
}
function toJavaObject(object) { 
	if(object[0]) { 
		return toJavaObjectList(object);
	}
	var text = "";
	var attributes = object.attributes.split(",");
	for(var i = 0; i < attributes.length; i++) {
		var value = eval("object." + attributes[i].replace("function", "FUNCTION"));
		if(value) {
			if(value[0]) {
				text += (text == "" ? "" : "&") + attributes[i] + "=" + toJavaObjectList(value);
			}
			else if(value.className) {
				text += (text == "" ? "" : "&") + attributes[i] + "=" + "OBJECTBEGIN[" + toJavaObject(value) + "]OBJECTEND";
			}
			else {
				text += (text == "" ? "" : "&") + attributes[i] + "=" + value;
			}
		}
	}
	return text;
}
function toJavaObjectList(array) { 
	var text = "";
	try {
		for(var i=0; i<array.length; i++) {
			text += (text == "" ? "" : "?") + toJavaObject(array[i]);
		}
	}
	catch(e) {
	}
	return "LISTBEGIN[" + text + "]LISTEND";
}
function validateFieldRequired(src, required, fieldName) { 
   if(src.value == "" && required) {
      alert((fieldName ? fieldName : "\u5185\u5BB9") + "\u4E0D\u80FD\u4E3A\u7A7A\uFF01");
      src.focus();
      return "NaN";
   }
   return src.value;
}
function validateStringField(src, mask, required, fieldName) {
   var value = validateFieldRequired(src, required, fieldName);
   if(value == "" || value == "NaN") {
      return value;
   }
   if(mask && mask != "") {
      var newMask = mask.replace(new RegExp("\\x27", "g"), "\\x27").replace(new RegExp(",", "g"), "");
      if(value.search(new RegExp("[" + newMask + "]")) != - 1) {
         alert((fieldName ? fieldName : "\u8F93\u5165\u5185\u5BB9") + "\u4E0D\u80FD\u5305\u542B" + mask + "\u7B49\u5B57\u7B26\uFF01");
         src.focus();
         src.select();
         return "NaN";
      }
   }
   return value;
}
function validateNumberField(src, required, fieldName) {
   var value = validateFieldRequired(src, required, fieldName);
   if(value == "" || value == "NaN") {
      return value;
   }
   var value = new Number(value);
   if(isNaN(value)) {
      alert((fieldName ? fieldName : "\u60A8") + "\u8F93\u5165\u7684\u6570\u5B57\u4E0D\u6B63\u786E\uFF01");
      src.focus();
      src.select();
      return "NaN";
   }
   return value;
}
function validateDateField(src, required, fieldName) {
   var value = validateFieldRequired(src, required, fieldName);
   if(value == "" || value == "NaN") {
      return value;
   }
   var dateValue = new Date(value.replace(new RegExp("-", "g"), "/"));
   if(isNaN(dateValue)) {
      alert((fieldName ? fieldName : "\u60A8") + "\u8F93\u5165\u7684\u65E5\u671F\u683C\u5F0F\u4E0D\u6B63\u786E\uFF01");
      src.focus();
      src.select();
      return "NaN";
   }
   return value;
}
function openLoginDialog(scriptAfterLogined) {
	var resetSessionUrl = url = location.protocol + "//" + location.host + ":" + location.port + getContextPath() + "/jeaf/sso/resetSession.shtml";
	var url = getContextPath() + "/jeaf/sso/loginDialog.shtml";
	url+= "?resetSessionUrl=" + resetSessionUrl;
	url+= (scriptAfterLogined ? "&scriptAfterLogined=" + utf8Encode(scriptAfterLogined) : "");
	openDialog(url, 350, 180);
}
function logout(url, anonymousEnable) {
	if(!url) {
		url = top.location.href;
	}
	else if(url.indexOf("http://")==-1 && url.indexOf("https://")==-1) {
		url = top.location.protocol + "//" + location.host + url;
	}
	window.top.location = getContextPath() + '/jeaf/sso/logout.shtml?' + (anonymousEnable ? 'anonymousEnable=true&' : '') + 'redirect=' + utf8Encode(url);
}
function createWorkflowInstnace(applicationName, formName, workflowEntriesAsText, openFeatues) { 
   var workflowEntriyList = parseJSObject(workflowEntriesAsText);
   if(workflowEntriyList.length == 1 && workflowEntriyList[0].activityEntries.length==1) {
      newWorkflowInstnace(getContextPath(), applicationName, formName, workflowEntriyList[0].workflowId + "." + workflowEntriyList[0].activityEntries[0].id, openFeatues);
      return;
   }
   var menuDefinition = new Array();
   var j = 0;
   for(var i = 0; i < workflowEntriyList.length; i++) {
      var menuItem = new Object();
	  menuDefinition[j++] = menuItem;
	  menuItem.title = workflowEntriyList[i].workflowName;
      menuItem.id = workflowEntriyList[i].workflowId;
      if(workflowEntriyList[i].activityEntries.length==1) {
          menuItem.id += "." + workflowEntriyList[i].activityEntries[0].id;
	  }
	  else {
	      for(var k=0; k<workflowEntriyList[i].activityEntries.length; k++) {
	      	 var menuItem = new Object();
	      	 menuDefinition[j++] = menuItem;
    	     menuItem.subMenu = true;
        	 menuItem.id = workflowEntriyList[i].activityEntries[k].id;
	         menuItem.title = workflowEntriyList[i].activityEntries[k].name;
    	  }
      }
   }
   showMenu(menuDefinition, "newWorkflowInstnace(\"" + getContextPath() + "\", \"" + applicationName + "\", \"" + formName + "\", \"{selectedId}\", \"" + openFeatues + "\")", event.srcElement);
   return;
}
function newWorkflowInstnace(contextPath, applicationName, formName, workflowId, openFeatues, param) { 
   openurl(contextPath + "/" + applicationName + "/" + formName + ".shtml?act=create&workflowId=" + workflowId.split(".")[0] + "&activityId=" + workflowId.split(".")[1], openFeatues, applicationName + formName);
}
function newrecord(applicationName, formName, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=create" + (param ? "&" + param : ""), openFeatues, applicationName + formName);
}
function openconfig(applicationName, formName, configKey, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml" + (configKey != "" ? "?configKey=" + configKey : ""), openFeatues, applicationName + formName + configKey);
}
function newconfig(applicationName, formName, configKey, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=create" +(configKey != "" ? "&configKey=" + configKey : ""), openFeatues, applicationName + formName + configKey);
}
function openrecord(applicationName, formName, id, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=open&id=" + id, openFeatues, id);
}
function editrecord(applicationName, formName, id, openFeatues, workItemId, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=edit" + (param ? "&" + param : "") +  "&id=" + id + (workItemId && workItemId>0 ? "&workItemId=" + workItemId : ""), openFeatues, id);
}
function openurl(url, openFeatues, name) { 
   var fullScreen = false;
   if(!openFeatues) {
      openFeatues = "";
   }
   else {
      var parameters = getParmemters(openFeatues);
      var mode = getParameter(parameters, "mode");
      var width = getParameter(parameters, "width");
      var height = getParameter(parameters, "height");
      var sWidth = screen.availWidth;
      var sHeight = screen.availHeight;
      if(mode == "fullscreen") {
         fullScreen = true;
         openFeatues = "left=0,top=0,width=" +(sWidth - 8) + ",height=" +(sHeight - 24);
      }
      else if(mode == "center") {
         if(width != null && height != null) {
            openFeatues = "left=" +((sWidth - width) /2)+",top="+((sHeight-height)/ 2) + ",width=" + width + ",height=" + height;
         }
      }
      else {
         openFeatues = width == null ? "" : "width=" + width;
         openFeatues += height == null ? "" :(openFeatues == "" ? "" : ",") + "height=" + height;
      }
      openFeatues += ",";
   }
   var win = window.open(url, (name ? ("" + name).replace(new RegExp("[-./]", "g"), "") : ""), openFeatues + "scrollbars=yes,status=no,resizable=yes,toolbar=no,menubar=no,location=no", false);
   if(fullScreen) {
   		win.resizeTo(sWidth, sHeight);
   }
   win.focus();
}
function getParmemters(src) {
   var temp = src.split(",");
   var len = temp.length;
   var parameters = new Array(len);
   for(var i = 0; i < len; i++) {
      parameters[i] = temp[i].split("=");
   }
   return parameters;
}
function getParameter(parameters, name) {
   var i, len = parameters.length;
   for(i = 0; i < len && parameters[i][0] != name; i++);
   return (i == len ? null : parameters[i][1]);
}
function getAbsolutePosition(obj) { 
   var pos = new Object();
   pos.left = 0;
   pos.top = 0;
   while(obj.tagName.toLowerCase()!="body") {
      pos.left += obj.offsetLeft;
      pos.top += obj.offsetTop;
      obj = obj.offsetParent;
   }
   return pos;
}
function getElement(parentElement, tagName, id) { 
   var elements = parentElement.getElementsByTagName(tagName);
   for(var i = 0; elements && i < elements.length; i++) {
      if(elements[i].id == id || elements[i].name == id) {
         return elements[i];
      }
   }
   return null;
}
function openApplicationConfig() { 
   var url = "/jeaf/eai/openConfigure.shtml";
   url += "?set=" + getContextPath().substring(1);
   url += "&application=" + document.getElementsByName("prefix")[0].value;
   url += "&from=" + window.location.protocol + "//" + window.location.host + getContextPath() + "/jeaf/application/openapplication.shtml?prefix=" + document.getElementsByName("prefix")[0].value + "&view=" + document.getElementsByName("view")[0].value;
   top.location = url;
}
function getContextPath() { 
	if(event && event.srcElement) { 
		var obj = event.srcElement;
		while(obj.tagName!="BODY") {
			var input = getElement(obj, "input", "contextPath");
			if(input!=null) {
				return input.value;
			}
			obj = obj.offsetParent;
		}
	}
	return document.getElementById("contextPath") ? document.getElementById("contextPath").value : DEFAULT_CONTENT_PATH;
}
function getMoneyCapital(money) { 
	money = new Number(money);
	if(isNaN(money) || money==0 || money>999999999999.99) {
        return "";
    }
    var nums = "\u96F6,\u58F9,\u8D30,\u53C1,\u8086,\u4F0D,\u9646,\u67D2,\u634C,\u7396,\u62FE,\u4F70,\u4EDF,\u842C,\u4EBF".split(",");
    var capital = "\u5143";
    money = Math.round(money*100);
    if(money % 100 ==0) {
        capital += "\u6574";
    }
    else {
        capital += nums[Math.floor(money % 100 / 10)] + "\u89D2";
        capital += nums[money % 10] + "\u5206";
    }
    money = Math.floor(money/100);
    var i = 0;
    do {
        if(i%4==0) {
        	capital = (i==0 ? "" : nums[12 + i/4]) + capital;
        }
        else {
        	capital = nums[9 + i%4] + capital;
        }
        i++;
        capital = '<font style="text-decoration:underline">&nbsp;' + nums[money%10] + '&nbsp;</font>' + capital;
        money = Math.floor(money/10);
    }while(money>0);
    return capital;
}
function trim(str) {
	return str.replace(/(^\s*)|(\s*$)/g,'');
}
function ltrim(str) {
	return str.replace(/^\s*/g,'');
}
function rtrim(str) {
	return str.replace(/\s*$/g,'');
}
function generateSeq() {
	var now = new Date();
	return "seq=" + (now.getSeconds()*1000 + now.getMilliseconds());
}
function sendMail(mailAddress, name) {
	openurl(getContextPath() + "/webmail/mail.shtml?to=" + utf8Encode(name ? "\"" + name + "\" <" + mailAddress + ">" : mailAddress), "width=760,height=520", "mail");
}
function getTimeValue(fieldName) {
	var time = document.getElementsByName(fieldName)[0].value;
	if(time=="") {
		return "";
	}
	return new Date(time.replace(new RegExp("-", "g"), "/").replace(new RegExp("\\x2E0", "g"), ""));
}
function getPropertyValue(properties, propertyName, nextPropertyName) {
	var index = properties.indexOf(propertyName + "=");
	if(index==-1) {
		return "";
	}
	index += propertyName.length + 1;
	var indexNext = -1;
	if(nextPropertyName && nextPropertyName!="") {
		indexNext = properties.indexOf("&" + nextPropertyName + "=", index);
		if(indexNext==-1) {
			indexNext = properties.indexOf("&", index);
		}
	}
	return (indexNext==-1 ? properties.substring(index) : properties.substring(index, indexNext));
}
function removeQueryParameter(queryString, parameterName) { 
	if(!queryString || queryString=="") {
		return queryString;
	}
	var beginIndex = queryString.indexOf(parameterName + "=");
	if(beginIndex==-1) {
		return queryString;
	}
	var endIndex = queryString.indexOf('&', beginIndex);
	return (endIndex==-1 ? queryString.substring(0, beginIndex) : queryString.substring(0, beginIndex) + queryString.substring(endIndex + 1));
}
function setQueryParameter(queryString, parameterName, parameterValue) { 
	queryString = removeQueryParameter(queryString, parameterName);
	if(!queryString) {
		queryString = "";
	}
	return queryString + (queryString=="" ? "" : "&") + parameterName + "=" + utf8Encode(parameterValue);
}
function reloadValidateCodeImage(validateCodeImageId) { 
	if(!validateCodeImageId) {
		validateCodeImageId = "validateCodeImage";
	}
	var src = document.getElementById(validateCodeImageId).src;
	var index = src.lastIndexOf("?");
	if(index!=-1) {
		src = src.substring(0, index);
	}
	document.getElementById(validateCodeImageId).src = src + "?reload=true&" + generateSeq();
}
var BROWSER_INFO = { 
	IsIE		: /*@cc_on!@*/false,
	IsIE7		: /*@cc_on!@*/false && ( parseInt( navigator.userAgent.toLowerCase().match( /msie (\d+)/ )[1], 10 ) >= 7 ),
	IsIE6		: /*@cc_on!@*/false && ( parseInt( navigator.userAgent.toLowerCase().match( /msie (\d+)/ )[1], 10 ) >= 6 ),
	IsSafari	: navigator.userAgent.toLowerCase().indexOf(' applewebkit/')!=-1,		// Read "IsWebKit"
	IsOpera		: !!window.opera,
	IsAIR		: navigator.userAgent.toLowerCase().indexOf(' adobeair/')!=-1,
	IsMac		: navigator.userAgent.toLowerCase().indexOf('macintosh')!=-1
}

function openDialog(dialogUrl, width, height) { 
	var topWindow = getTopWindow();
	if(("" + width).lastIndexOf('%')!=-1) {
		width = topWindow.document.body.clientWidth * Number(width.substring(0, width.length - 1)) / 100;
	}
	if(("" + height).lastIndexOf('%')!=-1) {
		height = topWindow.document.body.clientHeight * Number(height.substring(0, height.length - 1)) / 100;
	}
	
	if(topWindow.document.body.clientWidth<width || topWindow.document.body.clientHeight<height) {
		var left =(screen.width - width)/2;
	   	var top =(screen.height - height - 16)/2;
	   	var win = window.open(dialogUrl, "dialog", "left=" + left + "px,top=" + top + "px,width=" + width + "px,height=" + height + "px,status=0,help=0,scrollbars=1,resizable=1", true);
	   	win.focus();
	   	return;
	}
	
	var cover = createCover(topWindow, 30);
	var top  = Math.max((cover.offsetHeight - height - 20) / 2, 0);
	var left = Math.max((cover.offsetWidth - width - 20)  / 2, 0);
	
	
	var dialog = topWindow.document.createElement( 'iframe' ) ;
	dialog.frameBorder = 0 ;
	dialog.allowTransparency = false ;
	
	dialog.style.position = (BROWSER_INFO.IsIE ? 'absolute' : 'fixed');
	dialog.src = getContextPath() + "/jeaf/dialog/dialog.html?dialogUrl=" + dialogUrl;
	dialog.style.left = left + 'px';
	dialog.style.top = top + 'px';
	dialog.style.width = width + 'px';
	dialog.style.height = height + 'px';
	dialog.opener = window;
	dialog.id = "dialog";
	cover.appendChild(dialog);
}
function closeDialog() { 
	if(!window.frameElement) { 
		window.close();
	}
	else {
		destoryCover(getTopWindow(), getDialogFrame().parentNode);
	}
}
function createCover(parentWindow, opacity) { 
	var cover = parentWindow.document.createElement("div");
	cover.style.position = (BROWSER_INFO.IsIE ? 'absolute' : 'fixed');
	cover.style.left = parentWindow.document.body.scrollLeft + 'px';
	cover.style.top = parentWindow.document.body.scrollTop + 'px';
	cover.style.width = parentWindow.document.body.clientWidth + 'px';
	cover.style.height = parentWindow.document.body.clientHeight + 'px';
	cover.id = 'cover';
	cover.style.backgroundColor = "transparent";
	
	var coverFrame = parentWindow.document.createElement( 'iframe' ) ;
	coverFrame.frameBorder = 0 ;
	coverFrame.allowTransparency = true ;
	coverFrame.style.position = (BROWSER_INFO.IsIE ? 'absolute' : 'fixed');
	coverFrame.style.left = '0px';
	coverFrame.style.top = '0px';
	coverFrame.style.width = cover.style.width;
	coverFrame.style.height = cover.style.height;
	coverFrame.style.filter = 'alpha(opacity=' + opacity + ');';
	coverFrame.style.opacity = opacity;
	cover.appendChild(coverFrame);
	var childNodes = parentWindow.document.body.childNodes;
	if(childNodes.length==0) {
		parentWindow.document.body.appendChild(cover);
	}
	else {
		var maxZIndex = 0;
		for(var i=0; i<childNodes.length; i++) {
			if(childNodes[i].style && childNodes[i].style.zIndex) {
				var zIndex = childNodes[i].style.zIndex;
				if(zIndex!="") {
					zIndex = parseInt(zIndex);
					if(zIndex>maxZIndex) {
						maxZIndex = zIndex;
					}
				}
			}
		}
		cover.style.zIndex = maxZIndex + 1;
		parentWindow.document.body.insertBefore(cover, childNodes(0));
	}
	var adjustCoverSize = function()  {
		cover.style.left = parentWindow.document.body.scrollLeft + 'px';
		cover.style.top = parentWindow.document.body.scrollTop + 'px';
		cover.style.width = parentWindow.document.body.clientWidth + 'px';
		cover.style.height = parentWindow.document.body.clientHeight + 'px';
		coverFrame.style.width = cover.style.width;
		coverFrame.style.height = cover.style.height;
	};
	cover.adjustCoverSize = adjustCoverSize;
	parentWindow.attachEvent('onresize', adjustCoverSize);
	parentWindow.attachEvent('onscroll', adjustCoverSize);
	return cover;
}
function destoryCover(parentWindow, cover) { 
	parentWindow.detachEvent('onresize', cover.adjustCoverSize);
	parentWindow.detachEvent('onscroll', cover.adjustCoverSize);
	cover.parentNode.removeChild(cover);
}
function getTopWindow() { 
	var topWindow = window;
	while(topWindow.frameElement) {
		if(topWindow.frameElement.tagName.toLowerCase() == "frame") {
			break;
		}
		topWindow = topWindow.frameElement.ownerDocument.parentWindow;
	}
	return topWindow;
}
function getDialogOpener() { 
	if(!window.frameElement) {
		return window.opener;
	}
	return getDialogFrame().opener;
}
function getDialogFrame() { 
	var dialog = window.frameElement;
	while(dialog.id!='dialog') {
		dialog = dialog.ownerDocument.parentWindow.frameElement;
	}
	return dialog;
}

function openListDialog(title, type, source, width, height, multiSelect, param, scriptEndSelect, key) {
   var url = getContextPath() + "/jeaf/dialog/listDialog.shtml?title=" + utf8Encode(title) + "&type=" + type + "&source=" + source + "&multiSelect=" + multiSelect + "&param=" + utf8Encode(param) +(scriptEndSelect ? "&script=" + utf8Encode(scriptEndSelect) : "") +(key ? "&key=" + utf8Encode(key) : "");
   openDialog(url, width, height);
}

function openSelectDialog(applicationName, dialogName, width, height, multiSelect, param, scriptEndSelect, defaultCategory, key, separator, paging) {
   var url = getContextPath() + "/jeaf/dialog/viewSelectDialog.shtml";
   url += "?applicationName=" + applicationName; 
   url += "&viewName=" + dialogName; 
   url += "&multiSelect=" + multiSelect; 
   url += "&param=" + utf8Encode(param); 
   url += (scriptEndSelect && scriptEndSelect!="" ? "&script=" + utf8Encode(scriptEndSelect) : ""); 
   url += (defaultCategory && defaultCategory!="" ? "&viewPackage.categories=" + utf8Encode(defaultCategory) : ""); 
   url += (key && key!="" ? "&key=" + utf8Encode(key) : ""); 
   url += (separator && separator!="" ? "&separator=" + utf8Encode(separator) : ""); 
   url += (paging ? "&paging=true" : "");
   openDialog(url, width, height);
}
function openSelectUserDialog(width, height, multiSelect, param, scriptEndSelect, types, key, separator, dialogType, assignOrgId, hideRoot, leafNodeOnly) {
   var url = getContextPath() + "/jeaf/usermanage/" + dialogType + ".shtml";
   url += "?multiSelect=" + multiSelect; 
   url += "&param=" + utf8Encode(param); 
   url += (scriptEndSelect && scriptEndSelect!="" ? "&script=" + utf8Encode(scriptEndSelect) : ""); 
   url += (types && types!="" ? "&selectNodeTypes=" + types : ""); 
   url += (key && key!="" ? "&key=" + utf8Encode(key) : ""); 
   url += ("&separator=" + (separator && separator!="" ?  utf8Encode(separator) : ",")); 
   url += (assignOrgId && assignOrgId!="" ? "&parentNodeId=" + assignOrgId : ""); 
   url += "&hideRoot=true"; //\u603B\u662F\u9690\u85CF\u6839\u76EE\u5F55,url += (hideRoot ? "&hideRoot=true" : "");
   url += (leafNodeOnly ? "&leafNodeOnly=true" : "");
   openDialog(url, width, height);
}
function selectPerson(width, height, multiSelect, param, scriptEndSelect, personTypes, key, separator, assignOrgId, hideRoot) {
   if(!personTypes || personTypes=="" || personTypes=="all") {
      personTypes = "employee,student,teacher";
   }
   openSelectUserDialog(width, height, multiSelect, param, scriptEndSelect, personTypes, key, separator, "selectPerson", assignOrgId, hideRoot, true);
}
function selectOrg(width, height, multiSelect, param, scriptEndSelect, orgTypes, key, separator, assignOrgId, hideRoot, leafNodeOnly) {
   if(!orgTypes || orgTypes=="") {
      orgTypes = "all";
   }
   openSelectUserDialog(width, height, multiSelect, param, scriptEndSelect, orgTypes, key, separator, "selectOrg", assignOrgId, hideRoot, leafNodeOnly);
}
function selectRole(width, height, multiSelect, param, scriptEndSelect, key, separator, assignOrgId, hideRoot) {
   openSelectUserDialog(width, height, multiSelect, param, scriptEndSelect, "role", key, separator, "selectRole", assignOrgId, hideRoot, true);
}
function selectPersonByRole(width, height, multiSelect, param, scriptEndSelect, key, separator, assignOrgId, hideRoot) {
   openSelectUserDialog(width, height, multiSelect, param, scriptEndSelect, "employee,student,teacher", key, separator, "selectRoleMember", assignOrgId, hideRoot, true);
}
function adjustPriority(applicationName, viewName, title, width, height) {
   var left =(screen.width - width)/2;
   var top =(screen.height - height - 16)/2;
   var url = getContextPath() + "/jeaf/dialog/adjustPriority.shtml";
   url += "?prefix=" + applicationName; 
   url += "&viewName=" + viewName; 
   url += "&title=" + utf8Encode(title); 
   openDialog(url, width, height);
}
function selectAttachment(selectorUrl, recordId, attachmentType, width, height, scriptRunAfterSelect) {
	var url = getContextPath() + selectorUrl;
	url += (selectorUrl.lastIndexOf('?')==-1 ? '?' : '&') + 'id=' + recordId;
	url += '&attachmentSelector.scriptRunAfterSelect=' + scriptRunAfterSelect;
	url += '&attachmentSelector.type=' + attachmentType;
	openDialog(url, width, height);
}
function utf8Encode(s1) {
	var s = escape(s1);
	var sa = s.split("%");
    var retV ="";
    if(sa[0] != "") {
       retV = sa[0];
    }
    for(var i = 1; i < sa.length; i ++) {
         if(sa[i].substring(0,1) == "u") {
             retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5))) + sa[i].substring(5);
         }
         else {
         	retV += "%" + sa[i];
         }
    }
    return retV;
}
function Str2Hex(s) {
    var c = "";
    var n;
    var ss = "0123456789ABCDEF";
    var digS = "";
    for(var i = 0; i < s.length; i ++) {
       c = s.charAt(i);
       n = ss.indexOf(c);
       digS += Dec2Dig(eval(n));
    }
    return digS;
}
function Dec2Dig(n1) {
    var s = "";
    var n2 = 0;
    for(var i = 0; i < 4; i++) {
		n2 = Math.pow(2,3 - i);
		if(n1 >= n2) {
			s += '1';
			n1 = n1 - n2;
       	}
       	else {
			s += '0';
       	}
    }
    return s;
}
function Dig2Dec(s) {
    var retV = 0;
    if(s.length == 4) {
        for(var i = 0; i < 4; i ++) {
            retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
        }
        return retV;
    }
    return -1;
} 
function Hex2Utf8(s) {
   var retS = "";
   var tempS = "";
   var ss = "";
   if(s.length == 16) {
       tempS = "1110" + s.substring(0, 4);
       tempS += "10" +  s.substring(4, 10); 
       tempS += "10" + s.substring(10,16); 
       var sss = "0123456789ABCDEF";
       for(var i = 0; i < 3; i ++) {
          retS += "%";
          ss = tempS.substring(i * 8, (eval(i)+1)*8);
          retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
          retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
       }
       return retS;
   }
   return "";
}
function utf8Decode(szInput) {
	var x,wch,wch1,wch2,uch="",szRet="";
	for (x=0; x<szInput.length; x++) {
		if (szInput.charAt(x)=="%") {
			wch =parseInt(szInput.charAt(++x) + szInput.charAt(++x),16);
			if (!wch) {
				break;
			}
			if (!(wch & 0x80)) {
				wch = wch;
			}
			else if (!(wch & 0x20)) {
				x++;
				wch1 = parseInt(szInput.charAt(++x) + szInput.charAt(++x),16);
				wch = (wch & 0x1F)<< 6;
				wch1 = wch1 & 0x3F;
				wch = wch + wch1;
			}
			else {
				x++;
				wch1 = parseInt(szInput.charAt(++x) + szInput.charAt(++x),16);
				x++;
				wch2 = parseInt(szInput.charAt(++x) + szInput.charAt(++x),16);
				wch = (wch & 0x0F)<< 12;
				wch1 = (wch1 & 0x3F)<< 6;
				wch2 = (wch2 & 0x3F);
				wch = wch + wch1 + wch2;
			}
			szRet += String.fromCharCode(wch);
		}
		else {
			szRet += szInput.charAt(x);
		}
	}
	return szRet;
}
var xmlHttp;
var xmlHttpBusy = false;
var xmlHttpRequests; 
function xmlHttpOpenRequest(url, method, data, processFunction) {
	if(!xmlHttp) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") 
		xmlHttpRequests = new Array();
	}
	var request = new Object();
	request.url = url;
	request.method = method;
	request.data = data;
	request.processFunction = processFunction;
	xmlHttpRequests[xmlHttpRequests.length] = request;
	if(!xmlHttpBusy) {
		 xmlHttpSendRequest();
	}
}
function xmlHttpGetResponse() {
	return xmlHttp.responseText;
}
function xmlHttpStateChange() {
	if(xmlHttp.readyState != 4) {
		return;
	}
	var request = xmlHttpRequests[0];
	eval(request.processFunction);
	xmlHttpRequests = xmlHttpRequests.slice(1);
	if(xmlHttpRequests.length==0) {
		xmlHttpBusy = false;
	}
	else {
		xmlHttpSendRequest();
	}
}
function xmlHttpSendRequest() {
	var request = xmlHttpRequests[0];
	xmlHttpBusy = true;
	xmlHttp.open(request.method, request.url, true); 
	xmlHttp.onreadystatechange = xmlHttpStateChange;
	xmlHttp.send(request.data);
}
function xmlHttpWriteResponse(iframeName) { 
	var doc = frames[iframeName].document;
	doc.open();
	doc.write(xmlHttpGetResponse());
	doc.close();
}
if(typeof(HTMLElement)!="undefined" && !window.opera) { 
    HTMLElement.prototype.__defineGetter__("outerHTML",function() { 
        var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++) 
        if(a[i].specified) 
            str+=" "+a[i].name+'="'+a[i].value+'"'; 
        if(!this.canHaveChildren) 
            return str+" />"; 
        return str+">"+this.innerHTML+"</"+this.tagName+">"; 
    });
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s) { 
        var r = this.ownerDocument.createRange(); 
        r.setStartBefore(this); 
        var df = r.createContextualFragment(s); 
        this.parentNode.replaceChild(df, this); 
        return s; 
    }); 
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function() { 
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase()); 
    }); 
}

