﻿
if (window.wesoft_escape==null)
{
	window.wesoft_escape = escape;
	window.escape = function(parameter)
	{
		parameter = window.wesoft_escape(parameter);
		parameter = parameter.replace(/\+/g,'%2b');	// “+”
  	parameter = parameter.replace(/\//g,'%2f');	// “/”
		return parameter;
	}
}

if (window.wesoft_unescape==null)
{
	window.wesoft_unescape = unescape;
	window.unescape = function(parameter)
	{
 		parameter = parameter.replace(/%2b/g,'+');
  	parameter = parameter.replace(/%2f/g,'/');
		return window.wesoft_unescape(parameter);
	}
}

String.prototype.replaceAll = function (srcReg,dstStr)
{
	if (typeof(srcReg)=='string')
		srcReg = new RegExp(srcReg,'g');
	return this.replace(srcReg,dstStr);
}
 
if (window.wesoft_window_showModalDialog==null)
{
	window.wesoft_window_showModalDialog = window.showModalDialog;
	window.showModalDialog = function(sUrl)
	{
		if (ScreenMode==0 && sUrl.toUpperCase().indexOf(".ASPX")>0)
		{
			if (sUrl.toUpperCase().indexOf("_SID")==-1)
				sUrl += "&_SID="+GetSystemID();
		}
		var vArguments = null;
		var sFeatures = "";
		if(arguments.length >1)
			vArguments = arguments[1];
		if(arguments.length >2)
			sFeatures = arguments[2];

		return window.wesoft_window_showModalDialog(sUrl,window,sFeatures);
	}
}

if (window.wesoft_window_open==null && ScreenMode==0)
{
	window.wesoft_window_open = window.open;
	window.open = function (sUrl,sWinName,sFeatures,bReplace)
	{
		if (sUrl.toUpperCase().indexOf(".ASPX")>0)
		{
			if (sUrl.toUpperCase().indexOf("_SID")==-1)
				sUrl += "&_SID="+GetSystemID();
		}
		if (typeof(sFeatures)=="undefined")
			sFeatures = "menubar=0,toolbar=0,directories=0,location=0,status=0,scrollbars=0,resizable=1";
		if (typeof(sWinName)=="undefined")
			sWinName = "_blank";
		if (typeof(bReplace)=="undefined")
			bReplace = false;
	
		return wesoft_window_open(sUrl,sWinName,sFeatures,bReplace);
	}
}

function Href2Open()
{	// 页面链接转化为window.open方法
	if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) 
  {
  	var _href = lnks[i].getAttribute("href");
  	if (_href==null || _href=="#") continue;
  	if (_href.indexOf("javascript:")==0) continue;

    var _target = lnks[i].target;
    if (_target=="_self" || _target=="") continue;
    
    lnks[i]._target = lnks[i].target; 
    lnks[i].target = "_self"; 
    lnks[i]._href = lnks[i].href; 
    lnks[i].href = "#"; 
    lnks[i].onclick = function() 
    {
      window.open(this._href,this._target);
    }
	}
}

function doBackEvent(eventName,parameterLists,pfd)
{
	if (typeof(pfd)=="undefined") pfd = 0;
	__doPostBack('BackCode|'+pfd+'|'+eventName,parameterLists);
}

function callBackEvent(eventName,parameterLists,pfd,urls)
{
	if (typeof(pfd)=="undefined") pfd = 0;
	if (typeof(urls)=="undefined")
	{
		if (typeof(GetTrueUrl)=='undefined')
			urls = document.location.href;
		else
			urls = GetTrueUrl();
 	}
 	var res = Wesoft.Sys.FrameWork.Common.Base.FunctionBase.ExecuteAjaxEventsInterface(eventName,parameterLists,pfd,urls);
	if(res.error)
	{ 
		showAjaxProError(res.error); 
		return null;
	}else
	{
		if (res.value==null) return null;
		if (res.value.length>2 && res.value.substring(0,1)=="{" && res.value.substring(res.value.length-1)=="}")
		{
			var json = null;
			try{
      	json = JSON.parse(res.value);
			}catch(e)
			{
				alert("结果转换成Json对象时出现错误："+e.message+"\n"+res.value);
			}
			return json;
		}else
			return res.value;
	}
}

function callBackEventDataSet(eventName,parameterLists,pfd,urls)
{
	if (typeof(pfd)=="undefined") pfd = 0;
	if (typeof(urls)=="undefined") urls = document.location.href;
 	var res = Wesoft.Sys.FrameWork.Common.Base.FunctionBase.ExecuteAjaxDataSetEventsInterface(eventName,parameterLists,pfd,urls);
	if(res.error)
	{ 
		showAjaxProError(res.error); 
		return null;
	}else
		return res.value;
}
function IsLogon()					{return callBackEvent("IsLogon","");}
function GetToken()					{return callBackEvent("GetToken","");}
function GetPersonListByDepID(depid)	{return callBackEventDataSet("GetPersonListByDepID",depid+"");}
function HasRight(menuid,pfd,rightKey)						{return callBackEvent("HasRight",menuid+"|"+pfd+"|"+rightKey);}
function HasMenuRight(systemid,menuName)					{return callBackEvent("HasMenuRight",systemid+"|"+menuName);}
function IsRoleMember(roleNameID,personID)
{
	if (typeof(personID)!="undefined") roleNameID = roleNameID+"|"+personID;
	return callBackEvent("IsRoleMember",roleNameID);
}
function IsGroupMember(groupNameID,personID)
{
	if (typeof(personID)!="undefined") groupNameID = groupNameID+"|"+personID;
	return callBackEvent("IsGroupMember",groupNameID);
}
function GetParameter(parameterPath,parameterName)
{
	return callBackEvent("GetParameter",parameterPath+"|"+parameterName);
}
function GetPersonInfo(personID,fieldName)
{
	return callBackEvent("GetPersonInfo",personID+"|"+fieldName);
}
function SendMessageToPerson(personID,message)
{
	return callBackEvent("SendMessageToPerson",personID+"|"+escape(fieldName));
}
//ajax错误检查
function showAjaxProError(error, customMessage)
{
	if(!window.AjaxProDEBUG) {
		var msg = !customMessage ? error.Message : customMessage;
		alert("系统错误\n\n" + msg);        
	} else {
		var win = window.open("AjaxProError", "");
		var doc = win.document;    
		doc.write("<html><head><title>AjaxProError:")
		doc.write(error.Type);
		doc.write("</title></head><body><div><h3>");
		doc.write("AjaxPro 调用发生未处理的异常");
		doc.write("</h3>");
		doc.write("<pre>");
		doc.write("Type" + ":\n   " + error.Type + "\n"); // 异常类型
		doc.write("Message" + ":\n   " + error.Message + "\n"); // 异常信息  
		doc.write("Stack" + ":\n" + error.Stack + "\n"); // 堆栈跟踪
		doc.write("TargetSite" + ":\n   " + error.TargetSite + "\n"); // 引发异常的方法
		doc.write("Source" + ":\n   " + error.Source + "\n"); // 导致异常的对象 
		doc.write("</pre>");    
		doc.write((new Date()).toLocaleString());
		doc.write("<br/><br/>");
		doc.write("<input type='button' value='close' onclick='window.close()' />");
		doc.write("</div>");
		doc.close();
	}
	return false; 
}

function SetAutoSize(_document)
{
	var aList = null;
	if(arguments.length == 0)
	{
		aList = document.getElementsByName('AutoSize');
	}
	else
	{
		aList = _document.getElementsByName('AutoSize');
	}
	for(var i = 0 ; i <aList.length ; i ++)
	{
		if (aList[i].style.display=="none")
		{
			var div = aList[i].parentElement;
			if (div.offsetWidth>0)
			{
				div.style.width = div.offsetWidth - 10;
				aList[i].style.display = "";
			}
		}
	}
}

function PageReSize(_document)
{
	var aList = null;
	if(arguments.length == 0)
	{
		aList = document.getElementsByName('AutoSize');
	}
	else
	{
		aList = _document.getElementsByName('AutoSize');
	}

	for(var i = 0 ; i <aList.length ; i ++)
	{
		var div = aList[i].parentElement;
		div.style.width = "100%";
		aList[i].style.display = "none";
	}
	
	setTimeout('SetAutoSize()',200);
}

function getLeft(e){ 
	var offset=e.offsetLeft; 
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent); 
	return offset; 
}

function getTop(e){ 
	var offset=e.offsetTop; 
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent); 
	return offset; 
}

function clearAllNode(parentNode)
{
	while (parentNode.firstChild) 
	{
	  var oldNode = parentNode.removeChild(parentNode.firstChild);
	  oldNode = null;
	}
} 

function GetFieldValue(dataSetRow,fieldName)
{
	var v = dataSetRow[fieldName];
	if (typeof(v)=="undefined")
	{
		v = dataSetRow[fieldName.toUpperCase()];
		if (typeof(v)=="undefined")
		{
			alert("字段名称“"+fieldName+"”错误！");
			v = null;
		}
	}
	return v;
}

document.ondblclick=function()
{
	if (event.ctrlKey && event.altKey) 
	{
		if (GetParameter("\\Sys\\FrameWork\\InterFace\\Action\\","CodeDebug")=="0")
		{
			alert("在线调试代码功能已被禁用！");
			return;
		}
		GetFrameWindow()._GlobalVar = GetCookie("CodeDebug");
		if (GetFrameWindow()._GlobalVar == null)
			GetFrameWindow()._GlobalVar = "";

		var urls = "/BasePage.aspx?_Ascx=/Sys/FrameWork/Common/Ascx/TextEditor.ascx";
		var reValue = window.showModalDialog(urls,GetFrameWindow(),'DialogHeight:550px;DialogWidth:800px;status:no;');
		GetFrameWindow()._GlobalVar = null;
		if(reValue && reValue != "None") 
		{
			try
			{
				SetCookie("CodeDebug",reValue,0);
				eval(unescape(reValue));
			}catch(E)
			{
				alert("调试代码错误：\n"+reValue+"\n\n错误信息："+E.message);
			}
		}
	}
}

// 简洁右键菜单代码
var menuItems = "";
var showSubMenuHandle = null;
var parentMenu = null;
var subMenuVisible = false;
var menuAutoHideHandle = 0;
function onMenuMove(menu,isOver)
{
	clearTimeout(menuAutoHideHandle);
	menuAutoHideHandle = 0;
	if (isOver)
		menu.isOver='1';
	else
		menu.isOver='0';

	if (isOver)
	{
		menu.style.display='';
	}else{
		if (subMenuVisible && menu.firstChild.id=="popMenu") // 是主菜单，且2级菜单在显示中
			;//menu.style.display='';
		else
		{
			menu.style.display='none';
			subMenuVisible = false;
		}
		try{clearTimeout(showSubMenuHandle)}catch(e){}
		if (popMenu.parentElement.isOver=='0' && popSubMenu.parentElement.isOver=='0')
		{
			if (menuAutoHideHandle==0)
				menuAutoHideHandle = setTimeout(function(){
						menuAutoHideHandle = 0;
						popMenu.parentElement.style.display = 'none';
						popSubMenu.parentElement.style.display = 'none';
					},3000);
		}
	}
}
function hidePopMenu()
{
	menuAutoHideHandle = 0;
	popMenu.parentElement.style.display = 'none';
	popSubMenu.parentElement.style.display = 'none';
}
function showPopMenu(showOnIframe)
{
	show_Pop_Menu(false,showOnIframe);
}
function showSubMenu(showOnIframe)
{
	subMenuVisible = true;
	show_Pop_Menu(true,showOnIframe);
}
var menuBorderSpace = 5;
function show_Pop_Menu(isSubMenu,showOnIframe)
{
  if (typeof(isSubMenu) == 'undefined') isSubMenu = false;
  
  var theMenu = popMenu;
  if (isSubMenu) theMenu = popSubMenu;
  var MenuItem = theMenu.firstChild.firstChild.firstChild;
  
	theMenu.style.backgroundImage = "url(/Sys/ExtControl/ig_common/Images/"+GetStyleID()+"/ig_menu2003SpacerBlue.gif)";
	theMenu.style.backgroundColor = GetStyleColor_BaseColor();
	clearAllNode(MenuItem);
	MenuItem.innerHTML = "<table style='MARGIN: 1px;width:170px' cellSpacing=0 cellPadding=0 width=100 border=0>"+menuItems+"</table>";
  if (menuItems != "") {
      theMenu.parentElement.style.display = '';
  }
	menuItems = "";
	if (isSubMenu)
	{
    theMenu.parentElement.style.posLeft = getLeft(parentMenu)+parentMenu.clientWidth;
    theMenu.parentElement.style.posTop  = getTop(parentMenu);

		if (theMenu.parentElement.style.posLeft > document.body.clientWidth + document.body.scrollLeft - MenuItem.clientWidth)
			theMenu.parentElement.style.posLeft = document.body.clientWidth + document.body.scrollLeft - MenuItem.clientWidth  - parentMenu.clientWidth - 5;
		if (theMenu.parentElement.style.posTop > document.body.clientHeight + document.body.scrollTop - MenuItem.clientHeight)
			theMenu.parentElement.style.posTop = document.body.clientHeight + document.body.scrollTop - MenuItem.clientHeight - 5;
		return;
	}

  if (typeof(showOnIframe) != 'undefined') {
    var offset = showOnIframe.screenTop - window.screenTop;
    theMenu.parentElement.style.posLeft = showOnIframe.event.clientX -5 ;
    theMenu.parentElement.style.posTop  = showOnIframe.event.clientY + offset - 5;
  } 
  else {
		theMenu.parentElement.style.posLeft = window.event.clientX + document.body.scrollLeft - 5;
		if (theMenu.parentElement.style.posLeft > document.body.clientWidth + document.body.scrollLeft - MenuItem.clientWidth)
			theMenu.parentElement.style.posLeft = document.body.clientWidth + document.body.scrollLeft - MenuItem.clientWidth - 5;
		theMenu.parentElement.style.posTop  = window.event.clientY + document.body.scrollTop - 5;
		if (theMenu.parentElement.style.posTop > document.body.clientHeight + document.body.scrollTop - MenuItem.clientHeight)
			theMenu.parentElement.style.posTop = document.body.clientHeight + document.body.scrollTop - MenuItem.clientHeight - 5;
	}
}
function activePopMenu(node)
{
	node.style.fontSize = '9pt';
	node.style.color = '#FFFFFF';
	node.style.background = GetStyleColor_DeepColor();
	node.style.cursor ='hand';
	if (node.hasSubMenu=="true")
	{
		parentMenu = node;
		try{clearTimeout(showSubMenuHandle)}catch(e){}
		showSubMenuHandle = setTimeout(function(){
				subMenuVisible = false;
				node.onclick();
			},600);
	}
}
function inactivePopMenu(node)
{
	node.style.fontSize = '9pt';
	node.style.color = '#000000';
	node.style.background = "";
}
function AddMenuItem(menuName,menuTitle,menuClick,menuIcon,hasSubMenu,menuKey)
{
    if (typeof(hasSubMenu) == 'undefined') hasSubMenu = false;
    if (typeof(menuKey) == 'undefined') menuKey = "";

    if (menuTitle==null || menuTitle=="") menuTitle = menuName;
    menuItems += "      <tr id='"+menuKey+"' onmouseover=activePopMenu(this) onclick='"+menuClick+"' onmouseout=inactivePopMenu(this) hasSubMenu="+hasSubMenu+">";
    menuItems += "        <td width=25 height=20 align=center>";
    menuItems += "          <IMG src='"+menuIcon+"' border=0 >";
    menuItems += "        </td>";
    menuItems += "        <td height=20 width='100%' style='Padding-left:10px;Padding-right:10px' align=left nowrap title='"+menuTitle+"'>"+menuName+"</td>";
    if (hasSubMenu)
    {
		menuItems += "    <td align=right>";
		menuItems += "      &nbsp&nbsp<IMG src='/Sys/FrameWork/Common/Images/icon/arrow/arrow_next.gif' border=0 >";
		menuItems += "    </td>";
    }
    menuItems += "      </tr>";
}
function SetShortMenuState(menuKey,state)
{
	var menuTR = document.getElementById(menuKey);
	if (!menuTR)
	{
			alert("没有找到菜单ID："+menuKey);
			return;
	}
	if (state==0)
		menuTR.style.display="none";
	else if (state==1)
		menuTR.style.display="";
}
function SetShortMenuVisible(menuKey,visible)
{
	if (visible)
		SetShortMenuState(menuKey,1);
	else
		SetShortMenuState(menuKey,0);
}


