var submitting = false;
function doAction(actionName, param, notLockForm, formName) { 
   if(!submitting) {
       if(!param) param = "";
	   try {
	      HtmlEditor.SaveHtmlContent(); 
	   }
	   catch(e) {
	   
	   }
	   if(!formOnSubmit()) {
	   	  return;
	   }
	   var form = !formName || formName=='' ? document.forms[0] : document.forms[formName];
	   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(formName);
	   }
	   resetBoxElements(form);
	   form.submit();
	}
}
function submitForm(notLockForm, formName) { 
   if(submitting) {
   	  return false;
   }
   try {
      HtmlEditor.SaveHtmlContent(); 
   }
   catch(e) {
   }
   if(!formOnSubmit()) {
   	  return;
   }
   if(!notLockForm) {
	   submitting = true;
	   beginSubmit(formName);
   }
   var form = !formName || formName=='' ? document.forms[0] : document.forms[formName];
   resetBoxElements(form);
   form.submit();
}
function resetBoxElements(form) { 
	var inputs = form.getElementsByTagName("input");
	if(!inputs[0]) {
		return;
	}
	var uncheckedFields = new Array();
	var processedFields = "";
	for(var i=0; i<inputs.length; i++) {
		if(!inputs[i].type || !inputs[i].name) {
			continue;
		}
		var type = inputs[i].type.toLowerCase();
		if(type!="checkbox" && type!="radio" || processedFields.indexOf("[" + inputs[i].name + "]")!=-1) {
			continue;
		}
		processedFields += "[" + inputs[i].name + "]";
		
		var checked = false;
		for(j=i; j<inputs.length; j++) {
			if(inputs[i].name==inputs[j].name && inputs[j].checked) {
				checked = true;
				break;
			}
		}
		if(!checked) {
			uncheckedFields.push(inputs[i].name);
		}
	}
	for(var i=0; i<uncheckedFields.length; i++) {
		var hidden = document.createElement("input");
		hidden.type = "hidden";
		hidden.name = uncheckedFields[i];
		hidden.value = "";
		form.appendChild(hidden);
	}
}
function beginSubmit(formName) { 
	var form = !formName || formName=='' ? document.forms[0] : document.forms[formName];
	if(form.target && form.target!="_self") {
		submitting = false;
		return;
	}
	var cover = createCover(window, 0);
	var div = document.createElement("div");
	div.innerHTML = '\u6B63\u5728\u5904\u7406\u4E2D, \u8BF7\u7A0D\u5019...'; //<img style="border:none" src="' + getContextPath() + '/jeaf/common/img/loading.gif">
	div.style.cssText = "border:1 solid #aaaaaa; background:#ffff66; position:absolute; padding:3px; font-family:\u5B8B\u4F53; font-size:12px";
	div.style.left = cover.offsetWidth - 161;
	div.style.top = 1;
	div.style.width = 160;
	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 createActiveXObject(classid, id) {
	var obj = document.getElementById(id);
	if(obj) {
		return obj;
	}
	obj = document.createElement("object");
	obj.classid = classid;
	obj.id = id;
	document.body.appendChild(obj);
	return obj;
}

function toJavaObject(jsObject) {
	var processedObjects = new Array();
	return recursionToJavaObject(jsObject, processedObjects);
}

function recursionToJavaObject(jsObject, processedObjects) {
	var objectIndex = processedObjects.length - 1;
	for(; objectIndex>=0 && processedObjects[objectIndex]!=jsObject; objectIndex--);
	if(objectIndex!=-1) {
		return "OBJECTREF=" + objectIndex;
	}
    if(!jsObject) {
        return "";
    }
    if(jsObject[0]) { 
        return listToJavaObject(jsObject, processedObjects);
    }
    processedObjects[processedObjects.length] = jsObject;
    var text = "";
	var attributes = jsObject.attributes.split(",");
	for(var i = 0; i < attributes.length; i++) {
		var value = eval("jsObject." + attributes[i].replace("function", "FUNCTION"));
		if(!value) {
			continue;
		}
		if(value[0]) { 
			text += (text == "" ? "" : "&") + attributes[i] + "=" + listToJavaObject(value, processedObjects);
		}
		else if(value.className) { 
			text += (text == "" ? "" : "&") + attributes[i] + "=" + "OBJECTBEGIN[" + recursionToJavaObject(value, processedObjects) + "]OBJECTEND";
		}
		else { 
			text += (text == "" ? "" : "&") + attributes[i] + "=" + value;
		}
	}
	return text;
}

function listToJavaObject(jsObjects, processedObjects) {
    if(!jsObjects==null || !jsObjects[0]) {
        return "";
    }
    var text = null
    for(var i=0; i<jsObjects.length; i++) {
        text = (text==null ? "" : text + "?")  + recursionToJavaObject(jsObjects[i], processedObjects);
    }
    return text=="" ? "" : "LISTBEGIN[" + text + "]LISTEND";
}

function parseJSObject(text) {
    var processedObjects = new Array();
    var beginIndex = new Array();
    beginIndex[0] = 0;
    var jsObject;
    if(text.substring(0, "LISTBEGIN[".length)=="LISTBEGIN[") { 
		jsObject = parseJSList(new Array(text), beginIndex, processedObjects);
	}
	else {
		jsObject = parseSingleObject(new Array(text), beginIndex, processedObjects);
	}
	processedObjects.length = 0;
	return jsObject;
}

function parseJSList(text, beginIndex, processedObjects) {
    var list = new Array();
	beginIndex[0] += "LISTBEGIN[".length;
	while(text[0].substring(beginIndex[0] - "]LISTEND".length, beginIndex[0])!="]LISTEND") {
		list[list.length] = parseSingleObject(text, beginIndex, processedObjects);
	}
	return list;
}

function parseSingleObject(text, beginIndex, processedObjects) {
    var objectEnd = -1, listEnd = -1, objValueEnd = -1, propertyEnd;
    var object = new Object();
	while(objectEnd==-1 && (propertyEnd=text[0].indexOf("=", beginIndex[0]))!=-1) {
		
		var propertyName = text[0].substring(beginIndex[0], propertyEnd);
		object.attributes = object.attributes ? object.attributes + "," + propertyName : propertyName;
		beginIndex[0] = propertyEnd + 1;
		var propertyValue = null;
		if(text[0].substring(beginIndex[0]).substring(0, "LISTBEGIN[".length)=="LISTBEGIN[") { 
		    propertyValue = parseJSList(text, beginIndex, processedObjects);
		}
		else if(text[0].substring(beginIndex[0]).substring(0, "OBJECTBEGIN[".length)=="OBJECTBEGIN[") { 
		    beginIndex[0] += "OBJECTBEGIN[".length;
		    propertyValue = parseSingleObject(text, beginIndex, processedObjects);
		}
		objectEnd = text[0].indexOf("?", beginIndex[0]);
		if(objectEnd==-1) {
			objectEnd = text[0].length;
		}
		listEnd = text[0].indexOf("]LISTEND", beginIndex[0]);
		if(listEnd==-1) {
			listEnd = text[0].length;
		}
		objValueEnd = text[0].indexOf("]OBJECTEND", beginIndex[0]);
		if(objValueEnd==-1) {
		    objValueEnd = text[0].length;
		}
		objectEnd = Math.min(Math.min(listEnd, objectEnd),objValueEnd);
		propertyEnd = text[0].indexOf("&", beginIndex[0]);
		if(propertyEnd==-1 || propertyEnd>objectEnd) {
			propertyEnd = objectEnd;
		}
		else {
			objectEnd = -1;
		}
		
		if(propertyValue==null) {
			propertyValue = text[0].substring(beginIndex[0], propertyEnd);
		}
		if(propertyName=="OBJECTREF") { 
			object = processedObjects[new Number(propertyValue)];
		}
		else if(propertyValue!=null && propertyValue!="") {
			try {
				eval("object." + propertyName.replace("function", "FUNCTION") + "=propertyValue");
			}
			catch(e) {
			
			}
			if(propertyName=="className") {
				processedObjects[processedObjects.length] = object;
			}
		}
		beginIndex[0] = propertyEnd + 1;
	}
	if(objectEnd==-1) {
	    beginIndex[0] = text[0].length;
	}
	else if(objectEnd==objValueEnd) {
	    beginIndex[0] = objectEnd + "]OBJECTEND".length;
	}
	else if(objectEnd==listEnd) {
	    beginIndex[0] = objectEnd + "]LISTEND".length;
	}
	else {
	    beginIndex[0] = objectEnd + 1;
	}
	return object;
}
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 redirect = url = location.protocol + "//" + location.host + ":" + location.port + getContextPath() + "/jeaf/sessionmanage/resetSession.shtml";
	redirect += (scriptAfterLogined ? "?scriptAfterLogined=" + utf8Encode(scriptAfterLogined) : "");
	openDialog(getContextPath() + "/jeaf/sessionmanage/loginDialog.shtml?redirect=" + utf8Encode(redirect), 350, 180, "\u767B\u5F55");
}
function logout(redirect, external) {
	if(!redirect) {
		redirect = top.location.href;
	}
	else if(redirect.indexOf("http://")==-1 && redirect.indexOf("https://")==-1) {
		redirect = top.location.protocol + "//" + location.host + redirect;
	}
	window.top.location = getContextPath() + '/jeaf/sessionmanage/logout.shtml?' + (external ? 'external=true&' : '') + 'redirect=' + utf8Encode(redirect);
}
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] + "&" + generateSeq(), openFeatues, applicationName + formName);
}
function newrecord(applicationName, formName, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=create" + (param ? "&" + param : "") + "&" + generateSeq(), openFeatues, applicationName + formName);
}
function openconfig(applicationName, formName, configKey, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml" + (configKey != "" ? "?configKey=" + configKey : ""), openFeatues, applicationName + formName + configKey);
}
function openrecord(applicationName, formName, id, openFeatues, param) { 
   openurl(getContextPath() + "/" + applicationName + "/" + formName + ".shtml?act=open&id=" + id + "&" + generateSeq(), 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 : "") + "&" + generateSeq(), 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) {
   		try {
	   		win.resizeTo(sWidth, sHeight);
	   	}
	   	catch(e) {
	   		
	   	}
   }
   try {
   		win.focus();
   }
   catch(e) {
   		
   }
}
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 getParentElement(element, tagName) { 
	var parentElement = element.parentElement;
	while(parentElement.tagName.toLowerCase()!="body") {
		if(parentElement.tagName.toLowerCase()==tagName.toLowerCase()) {
			return parentElement;
		}
		parentElement = parentElement.parentElement;
	}
	return null;
}
var contextPath = null;
function getContextPath() { 
	if(contextPath!=null) {
		return contextPath;	
	}
	var scripts = document.getElementsByTagName("script");
	for(var i=0; i<scripts.length; i++) {
		if(scripts[i].src.indexOf("common.js")==-1) {
			continue;
		}
		var url = resetUrl(scripts[i].src);
		var endIndex = url.indexOf("/jeaf/common/js/common.js");
		if(endIndex==-1) {
			continue;
		}
		var beginIndex = url.indexOf("://");
		beginIndex = (beginIndex==-1 ? 0 : url.indexOf("/", beginIndex + 3));
		contextPath = url.substring(beginIndex, endIndex);
	}
	return contextPath;
}
function resetUrl(url) { //\u91CD\u7F6EURL,\u5220\u6389".."
	if(url.indexOf("://")==-1 && url.substring(0,1)!='/') {
		url = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1) + url;
	}
	var values = url.split("/");
	url = values[values.length-1];
	var skip = 0;
	for(var j=values.length-2; j>=0; j--) {
		if(values[j]=="..") {
			skip++;
		}
		else if(skip==0 || (skip--)==0) {
			url = values[j] + "/" + url;
		}
	}
	return url;
}
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.getHours() * 60 + now.getMinutes()) * 60 + now.getSeconds())*1000 + now.getMilliseconds());
}
function sendMail(mailAddress, name) {
	openurl(getContextPath() + "/webmail/mail.shtml?mailTo=" + utf8Encode(name ? "\"" + name + "\" &lt;" + mailAddress + "&gt;" : 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 encodePropertyValue(propertyValue) { 
	return propertyValue.replace(new RegExp("%", "g"), "%25").replace(new RegExp("&", "g"), "%26").replace(new RegExp("=", "g"), "%3D");
}
function getPropertyValue(properties, propertyName, defaultValue) { 
	if(!properties || properties=='') {
		return defaultValue ? defaultValue : "";
	}
	var index = properties.indexOf(propertyName + "=");
	if(index==-1) {
		return defaultValue ? defaultValue : "";
	}
	index += propertyName.length + 1;
	var indexNext = properties.indexOf("&", index);
	var propertyValue = (indexNext==-1 ? properties.substring(index) : properties.substring(index, indexNext));
	return propertyValue.replace(new RegExp("%26", "g"), "&").replace(new RegExp("%3D", "g"), "=").replace(new RegExp("%25", "g"), "%");
}
function getMetaContent(doc, name) {
	var metas = doc.getElementsByTagName("meta");
	if(!metas) {
		return null;
	}
	for(var i=metas.length-1; i>=0; i--) {
		if(metas[i].name==name) {
			return metas[i].content;
		}
	}
	return null;
}
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, dialogTitle, callback) { 
	var topWindow = getTopWindow();
	var clientWidth = getClientWidth(topWindow.document);
	var clientHeight = getClientHeight(topWindow.document);
	if(("" + width).lastIndexOf('%')!=-1) {
		width = clientWidth * Number(width.substring(0, width.length - 1)) / 100;
	}
	if(("" + height).lastIndexOf('%')!=-1) {
		height = clientHeight * Number(height.substring(0, height.length - 1)) / 100;
	}
	
	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 = true;
	
	
	dialog.style.position = (BROWSER_INFO.IsIE ? 'absolute' : 'fixed');
	var url = getContextPath() + "/jeaf/dialog/dialog.shtml";
	var siteId = getPropertyValue(location.href, "siteId")
	url += "?dialogUrl=" + utf8Encode(dialogUrl) + (siteId && siteId!="" ? "&siteId=" + siteId : "") + (dialogTitle ? "&dialogTitle=" + dialogTitle : "");
	dialog.src = url;
	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";
	dialog.callback = callback;
	cover.appendChild(dialog);
}
function getClientWidth(doc) { 
	var clientWidth = doc.documentElement.clientWidth;
	if(clientWidth==0) {
		clientWidth = doc.body.clientWidth;
	}
	return clientWidth;
}
function getClientHeight(doc) { 
	var clientHeight = doc.documentElement.clientHeight;
	if(clientHeight==0) {
		clientHeight = doc.body.clientHeight;
	}
	return clientHeight;
}
function getScrollTop(doc) { 
	var scrollTop = doc.documentElement.scrollTop;
	if(scrollTop==0) {
		scrollTop = doc.body.scrollTop;
	}
	return scrollTop;
}
function getScrollLeft(doc) { 
	var scrollLeft = doc.documentElement.scrollLeft;
	if(scrollLeft==0) {
		scrollLeft = doc.body.scrollLeft;
	}
	return scrollLeft;
}
function getSpacing(obj, place) { //\u83B7\u53D6\u5BF9\u8C61\u95F4\u9699,place=['left', 'top', 'right', 'bottom']
	var margin, padding;
	if(!document.all) { 
		var win = (obj.ownerDocument.parentWindow ? obj.ownerDocument.parentWindow : obj.ownerDocument.defaultView);
		margin = win.getComputedStyle(obj, null).getPropertyValue('margin-' + place);
		padding = win.getComputedStyle(obj, null).getPropertyValue('padding-' + place);
	}
	else { 
		if("left"==place) {
			margin = obj.currentStyle.marginLeft;
			padding = obj.currentStyle.paddingLeft;
		}
		else if("top"==place) {
			margin = obj.currentStyle.marginTop;
			padding = obj.currentStyle.paddingTop;
		}
		else if("right"==place) {
			margin = obj.currentStyle.marginRight;
			padding = obj.currentStyle.paddingRight;
		}
		else if("bottom"==place) {
			margin = obj.currentStyle.marginBottom;
			padding = obj.currentStyle.paddingBottom;
		}
	}
	margin = !margin ? 0 : Number(margin.replace("px", ""));
	padding = !padding ? 0 : Number(padding.replace("px", ""));
	return (isNaN(margin) ? 0 : margin) + (isNaN(padding) ? 0 : padding);
}
function getBorderWidth(obj, place) { //\u83B7\u53D6\u8FB9\u6846\u5BBD\u5EA6,place=['left', 'top', 'right', 'bottom']
	var width;
	if(!document.all) { 
		var win = (obj.ownerDocument.parentWindow ? obj.ownerDocument.parentWindow : obj.ownerDocument.defaultView);
		width = win.getComputedStyle(obj, null).getPropertyValue('border-' + place + "-width");
	}
	else { 
		if("left"==place) {
			width = obj.currentStyle.borderLeftWidth;
		}
		else if("top"==place) {
			width = obj.currentStyle.borderTopWidth;
		}
		else if("right"==place) {
			width = obj.currentStyle.borderRightWidth;
		}
		else if("bottom"==place) {
			width = obj.currentStyle.borderBottomWidth;
		}
	}
	width = !width ? 0 : Number(width.replace("px", ""));
	return (isNaN(width) ? 0 : width)
}
function closeDialog() { 
	if(!window.frameElement) { 
		window.close();
		return;
	}
	var dialogFrame = getDialogFrame();
	try {
		
		var voidUrl = getVoidUrl();
		var iframe = dialogFrame.contentWindow.document.getElementById("dialogBody");
		iframe.src = voidUrl;
		iframe.removeNode(true);
		dialogFrame.src = voidUrl;
	}
	catch(e) {
		
	}
	destoryCover(getTopWindow(), dialogFrame.parentNode);
	dialogFrame.removeNode(true);
}
function getDialogOpener() { 
	return getDialogFrame().opener;
}
function getDialogCallback() { 
	return getDialogFrame().callback;
}
function getDialogFrame() { 
	var dialog = window.frameElement;
	while(dialog.id!='dialog') {
		dialog = (dialog.ownerDocument.parentWindow ? dialog.ownerDocument.parentWindow : dialog.ownerDocument.defaultView).frameElement;
	}
	return dialog;
}
function getVoidUrl() {
	//if(FCK_IS_CUSTOM_DOMAIN)return "javascript: void( function() {document.open();document.write('<html><head><title></title></head><body></body></html>');document.domain = '"+FCK_RUNTIME_DOMAIN+"';document.close();}() ) ;";
	if(BROWSER_INFO.IsIE) {
		if(BROWSER_INFO.IsIE7||!BROWSER_INFO.IsIE6) {
			return "";
		}
		else {
			return "javascript: '';";
		}
	};
	return "javascript: void(0);";
}
function createCover(parentWindow, opacity) { 
	var cover = parentWindow.document.createElement("div");
	cover.style.position = (document.all ? 'absolute' : 'fixed');
	cover.id = 'cover';
	cover.style.backgroundColor = "transparent";
	
	var coverFrame = parentWindow.document.createElement( 'iframe' ) ;
	coverFrame.frameBorder = 0 ;
	coverFrame.allowTransparency = true ;
	coverFrame.style.position = (document.all ? 'absolute' : 'fixed');
	coverFrame.style.left = '0px';
	coverFrame.style.top = '0px';
	coverFrame.style.width = '100%';
	coverFrame.style.height = '100%';
	cover.appendChild(coverFrame);
	var childNodes = parentWindow.document.body.childNodes;
	if(childNodes.length==0) {
		parentWindow.document.body.appendChild(cover);
	}
	else {
		parentWindow.document.body.insertBefore(cover, childNodes[0]);
	}
	if(!parentWindow.covers) {
		parentWindow.covers = new Array();
	}
	parentWindow.covers[parentWindow.covers.length] = cover;
	
	if(parentWindow.covers[0]==cover) {
		try {
			var clientWidth = parentWindow.document.body.clientWidth;
			
			cover.savedOverflowX = parentWindow.document.body.style.overflowX;
			cover.savedOverflowY = parentWindow.document.body.style.overflowY;
			cover.savedDocumentElementOverflowX = parentWindow.document.documentElement.style.overflowX;
			cover.savedDocumentElementOverflowY = parentWindow.document.documentElement.style.overflowY;
			cover.savedMarginRight = parentWindow.document.body.style.marginRight;
			
			parentWindow.document.body.style.overflowX = 'hidden';
			parentWindow.document.body.style.overflowY = 'hidden';
			parentWindow.document.documentElement.style.overflowX = 'hidden';
			parentWindow.document.documentElement.style.overflowY = 'hidden';
			
			if(parentWindow.document.body.clientWidth!=clientWidth) { 
				
				var marginRight = 0;
				try {
					marginRight = Number(parentWindow.document.body.style.marginRight.replace("px", ""));
				}
				catch(e) {
				
				}
				parentWindow.document.body.style.marginRight = marginRight + (parentWindow.document.body.clientWidth - clientWidth);
			}
		}
		catch(e) {
			
		}
	}
	
	cover.style.left = getScrollLeft(parentWindow.document) + 'px';
	cover.style.top = getScrollTop(parentWindow.document) + 'px';
	cover.style.width = getClientWidth(parentWindow.document) + 'px';
	cover.style.height = getClientHeight(parentWindow.document) + 'px';
	var coverFrame = cover.childNodes[0];
	if(document.all) {
		coverFrame.style.filter = 'alpha(opacity=' + opacity + ');';
	}
	else {
		coverFrame.style.opacity = (opacity / 100.0);
	}
	
	var childNodes = parentWindow.document.body.childNodes;
	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;
	
	var adjustCoverSize = function()  {
		cover.style.left = getScrollLeft(parentWindow.document) + 'px';
		cover.style.top = getScrollTop(parentWindow.document) + 'px';
		cover.style.width = getClientWidth(parentWindow.document) + 'px';
		cover.style.height = getClientHeight(parentWindow.document) + 'px';
		coverFrame.style.width = cover.style.width;
		coverFrame.style.height = cover.style.height;
	};
	cover.adjustCoverSize = adjustCoverSize;
	if(document.all) {
		parentWindow.attachEvent('onresize', adjustCoverSize);
		parentWindow.attachEvent('onscroll', adjustCoverSize);
	}
	else {
		parentWindow.addEventListener("resize", adjustCoverSize, false);
		parentWindow.addEventListener("scroll", adjustCoverSize, false);
	}
	return cover;
}
function destoryCover(parentWindow, cover) { 
	
	if(document.all) {
		parentWindow.detachEvent('onresize', cover.adjustCoverSize);
		parentWindow.detachEvent('onscroll', cover.adjustCoverSize);
	}
	else {
		parentWindow.removeEventListener("resize", cover.adjustCoverSize, false);
		parentWindow.removeEventListener("scroll", cover.adjustCoverSize, false);
	}
	cover.adjustCoverSize = null;
	
	if(parentWindow.covers[0]==cover) { 
		
		try {
			parentWindow.document.body.style.overflowX = cover.savedOverflowX;
			parentWindow.document.body.style.overflowY = cover.savedOverflowY;
		}
		catch(e) {
			
		}
		try {
			parentWindow.document.documentElement.style.overflowX = cover.savedDocumentElementOverflowX;
			parentWindow.document.documentElement.style.overflowY = cover.savedDocumentElementOverflowY;
		}
		catch(e) {
			
		}
		try {
			parentWindow.document.body.style.marginRight = cover.savedMarginRight;
		}
		catch(e) {
			
		}
	}
	cover.parentNode.removeChild(cover);
	var newCovers = new Array(parentWindow.covers.length - 1);
	for(var i=0; i<parentWindow.covers.length - 1; i++) {
		newCovers[i] = parentWindow.covers[i];
	}
	parentWindow.covers = newCovers;
}
function getTopWindow() { 
	var topWindow = window;
	while(topWindow.frameElement) {
		if(topWindow.frameElement.tagName.toLowerCase() == "frame") {
			break;
		}
		var win = topWindow.frameElement.ownerDocument.parentWindow ? topWindow.frameElement.ownerDocument.parentWindow : topWindow.frameElement.ownerDocument.defaultView;
		if(!win) {
			break;
		}
		topWindow = win;
	}
	return topWindow;
}

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

function openInputDialog(dialogTitle, fieldLabel, defaultFieldValue, width, height, script, callback) {
   var url = getContextPath() + "/jeaf/dialog/inputDialog.shtml" +
   			 "?title=" + utf8Encode(dialogTitle) +
   			 "&fieldLabel=" + utf8Encode(fieldLabel) +
   			 "&fieldValue=" + utf8Encode(defaultFieldValue) +
   			 "&script=" + utf8Encode(script);
   openDialog(url, width, height, dialogTitle, callback);
}

function openMessageDialog(dialogTitle, message, buttonNames, type, width, height, script, callback) {
   var url = getContextPath() + "/jeaf/dialog/messageDialog.shtml" +
   			 "?title=" + utf8Encode(dialogTitle) +
   			 "&message=" + utf8Encode(message) +
   			 "&buttonNames=" + utf8Encode(buttonNames) +
   			 "&type=" + type +
   			 "&script=" + utf8Encode(script);
   openDialog(url, width, height, dialogTitle, callback);
}

function openSelectDialog(applicationName, viewName, width, height, multiSelect, param, scriptEndSelect, defaultCategory, key, separator, paging, dialogParameter) {
   var url = getContextPath() + "/jeaf/dialog/viewSelectDialog.shtml";
   url += "?applicationName=" + applicationName; 
   url += "&viewName=" + viewName; 
   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" : "");
   url += (dialogParameter ? "&" + dialogParameter : "");
   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 userPageTemplateConfigure(userId) { 
   var url = getContextPath() + "/cms/sitemanage/selectInternalPage.shtml";
   url += "?selectNodeTypes=page";
   url += "&currentApplicationName=jeaf/usermanage"; 
   url += "&script=" + utf8Encode("openUserPageTemplateView('" + userId + "', '{id}'.split('__')[0], '{id}'.split('__')[1])");
   url += "&userId=" + userId;
   openDialog(url, 550, 350);
}
function openUserPageTemplateView(userId, applicationName, pageName) { 
   var url = getContextPath() + "/jeaf/usermanage/admin/selectTemplate.shtml";
   url += "?applicationName=" + applicationName;
   url += "&pageName=" + pageName; 
   url += "&userId=" + userId;
   openDialog(url, 550, 350);
}
function adjustPriority(applicationName, viewName, title, width, height, parameter) {
   var left =(screen.width - width)/2;
   var top =(screen.height - height - 16)/2;
   var url = getContextPath() + "/jeaf/dialog/adjustPriority.shtml";
   url += "?applicationName=" + applicationName; 
   url += "&viewName=" + viewName; 
   url += "&title=" + utf8Encode(title); 
   if(parameter && parameter!="") {
   	  url += "&" + parameter;
   }
   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) {
		if(!document.all) { 
			xmlHttp = new XMLHttpRequest();
		}
		else { 
			try { 
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		    }
		    catch(e) {
				try { 
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				}
				catch(xe) {
					xmlHttp = null;
				}
			}
		}
		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()); 
    }); 
}
function appendJsFile(doc, jsFile, scriptId) {
	var head = doc.getElementsByTagName("head")[0];
	var scripts = head.getElementsByTagName("script");
	if(scripts && scripts.length>0) {
		for(var i=0; i<scripts.length; i++) {
			if(scripts[i].src==jsFile) {
				return;
			}
		}
	}
	if(scriptId) {
		var script = document.getElementById(scriptId);
	   	if(script) {
	   	 	script.parentNode.removeChild(script);
	   	}
   	}
	var script = doc.createElement("script");
	if(scriptId) {
		script.id = scriptId;
	}
	script.src = jsFile;
	script.language = 'JavaScript';
	head.appendChild(script);
}
function appendCssFile(doc, cssId, cssUrl) {
	var head = getHead(doc);
	var links = head.getElementsByTagName("link");
	if(links && links.length>0) {
		for(var i=0; i<links.length; i++) {
			if(links[i].href==cssUrl) {
				return;
			}
			else if(links[i].id && links[i].id==cssId) {
				links[i].href = cssUrl;
				return;
			}
		}
	}
	var link = doc.createElement("link");
	link.href = cssUrl;
	link.id = cssId;
	link.rel = "stylesheet";
	link.type = "text/css";
	head.appendChild(link);
}
function appendStyle(doc, styleId, styleSheet) {
	
	var head = getHead(doc);
	
    var style = doc.createElement("style");
    style.type = "text/css";
    style.id = styleId;
    head.appendChild(style);
    
    var css = styleId && styleId!="" ? doc.styleSheets[styleId] : doc.styleSheets[0];
 	for(var i=0; i<styleSheet.rules.length; i++) {
		var cssText = styleSheet.rules[i].style.cssText;
		if(cssText && cssText!="") {
			try {
				if(css.cssRules) { 
					css.insertRule(styleSheet.rules[i].selectorText + "{" + cssText + "}", i);
				}
				else {
					css.addRule(styleSheet.rules[i].selectorText, styleSheet.rules[i].style.cssText);
				}
			}
			catch(e) {
			
			}
		}
	}
}
function cloneStyle(fromDocument, toDocument) {
	if(!fromDocument || !toDocument || fromDocument==toDocument) {
		return;
	}
	if(!fromDocument.styleSheets) {
		return;
	}
	for(var i=0; i<fromDocument.styleSheets.length; i++) {
		var ownerNode = (fromDocument.styleSheets[i].ownerNode ? fromDocument.styleSheets[i].ownerNode : fromDocument.styleSheets[i].owningElement);
		if("style"==ownerNode.tagName.toLowerCase()) { 
			appendStyle(toDocument, "", fromDocument.styleSheets[i]);
		}
		else if("link"==ownerNode.tagName.toLowerCase()) { 
			appendCssFile(toDocument, "", ownerNode.href); 
		}
    }
}
function getHead(doc) {
	
	var head = doc.getElementsByTagName("head")[0];
	if(!head) {
		head = doc.createElement("head");
		if(doc.getFirstChild()) {
			doc.insertBefore(head, doc.getFirstChild());
		}
		else {
			doc.appendChild(head);
		}
	}
	return head;
}
function insertField(fieldName, inputFieldName) {
	document.getElementsByName(inputFieldName)[0].focus();
	var range = document.selection.createRange();
	range.text = "<" + fieldName + ">";
}
function decToHex(dec) {
	var hexa="0123456789ABCDEF"; 
	var hex=""; 
	while(dec>15) { 
		tmp=dec-(Math.floor(dec/16))*16; 
		hex=hexa.charAt(tmp)+hex; 
		dec=Math.floor(dec/16); 
	} 
	hex=hexa.charAt(dec)+hex;
	return(hex);
}
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.leftTrim = function() {
	return this.replace(/(^\s*)/g, "");
}
String.prototype.rightTrim = function() {
	return this.replace(/(\s*$)/g, "");
}
function clickElement(element) { 
	if(document.all) { 
		element.click();
	} 
	else {
		var win = (element.ownerDocument.parentWindow ? element.ownerDocument.parentWindow : element.ownerDocument.defaultView);
		win.clicked = false;
		var clickIt = function() {
			if(win.clicked) {
				win.clicked = false;
			}
			else {
				var evt = win.document.createEvent("MouseEvents");
				evt.initMouseEvent('click', true, true, win, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
				element.dispatchEvent(evt);
				win.clicked = true;
			}
		};
		win.setTimeout(clickIt, 10);
	}
}
function addEvent(element, eventName, func) { 
	if(element.attachEvent) { 
		element.attachEvent("on" + eventName, func);
	}
	else if(element.addEventListener) { 
		element.addEventListener(eventName, func, true);
	}
	else { 
		element["on" + eventName] = func;
	}
}
function setElementHTML(element, html, inner) { 
	
	html = html.replace(/<a(?=\s).*?\shref=((?:(?:\s*)("|').*?\2)|(?:[^"'][^ >]+))/gi,'$& _savedurl=$1');
	html = html.replace(/<img(?=\s).*?\ssrc=((?:(?:\s*)("|').*?\2)|(?:[^"'][^ >]+))/gi,'$& _savedurl=$1');
	html = html.replace(/<area(?=\s).*?\shref=((?:(?:\s*)("|').*?\2)|(?:[^"'][^ >]+))/gi,'$& _savedurl=$1');
	var parentElement;
	
	if(inner) {
		parentElement = element;
		element.innerHTML = html;
	}
	else  { 
		parentElement = element.parentElement;
		element.outerHTML = html;
	}
	
	var tags = [["img", "src"], ["a", "href"], ["area", "href"]];
	for(var i=0; i<tags.length; i++) {
		var elements = parentElement.getElementsByTagName(tags[i][0]);
		if(!elements) {
			return;
		}
		for(var j=0; j<elements.length; j++) {
			var value = elements[j].getAttribute("_savedurl");
			if(value) {
				elements[j].setAttribute(tags[i][1], value);
				elements[j].removeAttribute("_savedurl");
			}
		}
	}
}

