﻿	// 如文件修改后不正常，UltraEdit文件-〉转换-〉ACSCII转UTF8
	var WebPageFormName = "MainForm";
	var _GlobalVar = null;
	var _Session = new Array();

	if (typeof(ScreenMode)!="undefined")
	{
		if (top.dialogArguments != undefined)	
		{
			windowMode=1;
		}else{ 
			if (top.opener != undefined)
			{
				try{
					var _s = top.opener.top.GetFrameWindow;
					windowMode=2;
				}catch(e)
				{
					windowMode=0;
				}
			}
		}
	}
	window.onerror = function(sMsg,sUrl,sLine) { GetFrameWindow().SetStatusMessage("警告："+sMsg+"  行号："+sLine+"  地址："+sUrl);return true; } 

	function SessionPush(obj)
	{
		if ( _Session[_Session.length - 1] != obj)
		{_Session.push(obj);}
	}	
	
	function SessionPop()
	{
		if(_Session.length>0)
		{return _Session.pop();}
		else return null;
	}
		
	function SessionClear()
	{
		_Session = new Array();
	}
		
	//var mainFrameWindow;	
	var statusMessage=" 操作员：徐四海";

	function SetStatusMessage(msg)
	{ 
		if (msg!="") msg = "◆ "+msg;
		if (GetUserName()!="")
		{
			msg = " 〖用户："+GetUserName()+"〗       " + msg;
			if (GetDepName()!="")
			{msg = " 【部门："+GetDepName()+"】 " + msg;}
		}
		top.window.status=msg;
	}

	function getStatusMessage(){return statusMessage;}

	function setHomePage()
	{
		var strHref=window.location.href;
		this.style.behavior='url(#default#homepage)';
		this.setHomePage(GetIndexPage());
	}	
	
	function Window_Resize(_document)
	{
		var winMode = _document.parentWindow.windowMode;  // winMode: 0-框架窗口；1-模式窗口；2-弹出窗口; -1 -孤立的窗口
		if (PageScrollMode!=-1)
		{
			if (PageScrollMode==0)
			{
				_document.body.scroll = "no";
			}else{
				_document.body.scroll = "yes";
			}
			return;
		}
		/*if (winMode==1)
		{ //1-模式窗口
			_document.body.scroll = "no";
			return;
		}*/

		var isMainPage = true;
		if (document.all)
			isMainPage = _document.parentWindow.name=='MainFunctionFrame';
		if (isMainPage) 
			top.MainFunctionFrame.height = "100%";

		if (winMode==-1) ScreentWidth = "100%";
		var isWebSite  = ScreentWidth != "100%";
		var FrameHeight    = _document.body.clientHeight;
		var FramePageHeight= _document.body.scrollHeight;
		var FrameWidth     = _document.body.clientWidth;
		var FramePageWidth = _document.body.scrollWidth;

		if (isWebSite && isMainPage)
		{
			if (FrameHeight < FramePageHeight - 5)
				top.MainFunctionFrame.height = FramePageHeight;
		}else{
			if (FrameHeight < FramePageHeight - 5 || FrameWidth < FramePageWidth - 5)
				_document.body.scroll="yes";
			else
				_document.body.scroll="no";
		}
	}
	
	function SelectColor(defaultColor)
	{
		var color = showModalDialog("../../Common/Html/SelectColor.html",defaultColor,'DialogHeight:270px;DialogWidth:420px;status:no;');
		return color;
	}
	
	function SelectDate()
	{
		var date = window.showModalDialog("/BasePage.aspx?_Ascx=/Sys/FrameWork/Common/Ascx/SelectDate.ascx",window,"dialogHeight:210px; dialogWidth:296px;status:no;scroll:no");
		if (date)
			return date;
		else
			return "";		
	}
	
	function Set_SelectDate(obj){var _date = SelectDate();obj.value = _date;}
	
	function NotNull(str)
	{
		if (str == null)
			return "";
		else
			return str;
	}

	function WaitingBegin(){WaitingBegin("");}
	function WaitingBegin(msg)
	{
		try{
			if (msg == null || msg == "") msg = GetFrameWindow().document.getElementById("WaitingWindow").title;
			GetFrameWindow().document.getElementById("WaitingWindowMessage").innerText = msg;		
			GetFrameWindow().document.getElementById("WaitingWindow").style.display="";
		}catch(e){;}
	}
	function WaitingEnd(){
		try{
			GetFrameWindow().document.getElementById("WaitingWindow").style.display="none";
		}catch(e){;}
	}
	
	function GetServerData(ascx)
	{
		//alert("废止使用：GetServerData(ascx)");
		return window.showModalDialog("/Sys/FrameWork/Common/BasePage/ServerData.aspx?ascx="+ascx,window,"dialogleft=2000px; dialogtop=2000px;dialogwidth=0px; dialogheight=0px; status=no; help=no; scroll=no;");
	}
	
	//后台反函数为Wesoft.Sys.FrameWork.Common.Utils.WesoftString.ToScriptTextSafe
	function FromScriptTextSafe(str)
	{
		str = str.replace(/＜/g,"<");
		str = str.replace(/＞/g,">");
		str = str.replace(/＇/g,"'");
		str = str.replace(/＂/g,'"');
		str = str.replace(/@#/g,"\r\n");

		return str;
	}

	function NameValueEnity(name,value){
		this.Name = name;
		this.Value = value;
	}

	function AddParameterToURL(curl,parameterList)
	{
		if (parameterList == null || parameterList =="")
			return curl;

		var ParArray  = new Array();
		var TempArray = new Array();
		var	params = parameterList.split("&");   
		for (var i=0;i<	params.length;i++)
		{
			var temp=params[i];
			var p = temp.indexOf("=");
			var pName  = temp.substring(0,p);
			var pValue = temp.substring(p+1);

			ParArray.push(new NameValueEnity(pName,pValue));
		}			

		var ind =curl.indexOf("?");
		var newPar = curl.substring(ind);
	
		if( newPar != null && newPar !=""){
			var	params = newPar.split("&");   
			for (var i=0;i<	params.length;i++)
			{
				var temp=params[i];
				var p = temp.indexOf("=");
				var pName  = temp.substring(0,p);
				var pValue = temp.substring(p+1);
				TempArray.push(new NameValueEnity(pName,pValue));
			}	
		}

		for(var i=0;i<ParArray.length;i++)
		{
			var temp=ParArray[i];
			var has =0;
			for(var j=0;j<TempArray.length;j++)
			{
				var myTemp = TempArray[j];
				if(temp.Name == myTemp.Name)
				{
					myTemp.Value = temp.Value;
					has =1;
				}
			}
			if(has ==0)
				TempArray.push(temp);
		}

		var parString = "";
		for(var i=0;i<TempArray.length;i++)
		{
			var myTemp = TempArray[i];
			parString+=myTemp.Name;
			parString+="=";
			parString+=myTemp.Value;
			parString+="&"			
		}
		curl = curl.substring(0,ind)+parString;
		curl = curl.substring(0,curl.lastIndexOf("&"));

		return curl;
	}
	
	function GotoSystem(sid,screenMode,newWindow)
	{
		var url = "";
		if (screenMode==0)
			url = "/Sys/FrameWork/SysModule/MainFrame/MainFrame.aspx?_SID=";
		else
			url = "/MainPage.aspx?_SID=";
		url = url + sid;
		if (newWindow)
			window.open(url);
		else
			top.location = url;
	} 
	
	function OpenOATaskURL(url){window.open('/index.aspx?_SID=OA&TaskURL='+escape(url),'WesoftWCP');}

	function getRadioValue(name){
		var value="";
		var fm = document.getElementsByName(WebPageFormName);
		for(i=0;i<document.all.MainForm.elements.length;i++)
		{ 
			if(document.all.MainForm.elements[i].type=="radio" && document.all.MainForm.elements[i].checked && document.all.MainForm.elements[i].name==name)
			{
				value=document.all.MainForm.elements[i].value;
				break;
			}
		}
		return value;
	}
		
	function GetUrlHost()
	{
		var url = document.location.href;
		var p = url.indexOf("/",10);
		return url.substr(0,p);
	}
	
	function RemoveUrlHost(html)
	{
		return html.replace(GetUrlHost(),"");
	}
	
	function Confirm(theWindow,title)
	{
		var captionyes 		= arguments.length>=3?arguments[2]:"是";
		var captionno 		= arguments.length>=4?arguments[3]:"否";
		var captioncancel = arguments.length>=5?arguments[4]:"取消";
		var remarkyes 		= arguments.length>=6?arguments[5]:"";
		var remarkno 			= arguments.length>=7?arguments[6]:"";
		var remarkcancel 	= arguments.length>=8?arguments[7]:"";
		var _url="/Sys/FrameWork/Common/Html/Confirm.html?title="+escape(title)
					+"&captionyes="+escape(captionyes)
					+"&captionno="+escape(captionno)
					+"&captioncancel="+escape(captioncancel)
					+"&remarkyes="+escape(remarkyes)
					+"&remarkno="+escape(remarkno)
					+"&remarkcancel="+escape(remarkcancel);

		var retv = theWindow.showModalDialog(_url,theWindow,"dialogWidth:432px;dialogHeight:170px;status:no;scroll:no");
		if (typeof(retv)=='undefined')
		{
			retv = -1;
		}
		return retv;
	}

	// 控制鼠标右键菜单
	function ControlContextMenu()
	{
		document.oncontextmenu = function()
		{
			if (event.srcElement.oncontextmenu)
				return false;
			
			try{HideAdviceMenu();}catch(e){;}
			var isText=(event.srcElement.tagName=='INPUT'||event.srcElement.type=='text'); 
			return isText
		};
	}
	
	// 控制页面内容选定
	function ControlSelectMenu()
	{
		document.onselectstart = function()
		{
			var isText=(event.srcElement.tagName=='INPUT'||event.srcElement.tagName=='TEXTAREA'||event.srcElement.type=='text');
			return isText
		};
	}

	// 关闭弹出页面并调用父页面的关闭事件，第2个参数可选，即当前功能的PFD
	function CloseReturn(returnValues)
	{
		var _pfd = arguments.length>=2?arguments[1]:0;
		if (returnValues && window.opener)
		{
			if (typeof(returnValues)!="string")
			{
				alert("CloseReturn弹出窗口回调函数只能返回字符串类型的返回值！");
				return;
			}
			if (returnValues.indexOf("'")>=0)
			{
				alert("CloseReturn弹出窗口回调函数返回的返回值中不能出现单引号！");
				return;
			}
			var cmd = "window.opener.subWindowClose";
			if (_pfd!=0)
				cmd += "_"+_pfd;

			if(typeof(eval(cmd))=="object")  
			{
				eval(cmd + "('"+escape(returnValues)+"');");
			}else
			{
				cmd = cmd.substring(cmd.lastIndexOf(".")+1,cmd.length);
				//alert('本弹出页面具有返回值，但父页面已关闭或没有处理函数 '+cmd+' ！');
			}
		}
		top.close();
	}
	
	

	function GetFrameWindow()
	{ 
		if (top.dialogArguments != undefined)	
		{
			return top.dialogArguments.GetFrameWindow();
		}else{
			if (top.opener != undefined)
			{
				if (!top.opener.closed)
				try{
					return top.opener.top.GetFrameWindow();
				}catch(e)
				{
					//alert("GetFrameWindow()");
				}
			}
			return top;
		}
	}
	
	function SetCookie(cName,cValue)
	{
		document.cookie = cName +"="+ escape(cValue)+";path=/";
	}

	function GetCookie(cName)
	{
		var cookies = document.cookie.split(';');
		for (var i=0;i<cookies.length;i++)
		{
			var cookieName = cookies[i].split('=');
			if (cookieName[0].trim()==cName)
			{
				if (cookieName.length!=2)
					return "";
				else
					return unescape(cookieName[1]);
			}
		}
		return "";
	}
	
	function GotoPage(currentDocument,gotoUrl)
	{
		//if (GetCookie("GotoPage")!="")
		//{
		//	alert("GotoPage函数不能连续使用！");
		//	return;
		//}
		SetCookie("GotoPage",currentDocument.location.toString());
		currentDocument.location=gotoUrl;	
	}
	
	function GotoBack(currentDocument)
	{		
		GotoBack(currentDocument,null);
	}	
	
	function GotoBack(currentDocument,parameterList)
	{
		var curl = GetCookie("GotoPage");
		if (curl=="")
		{
			history.back();
			return;
		}
		SetCookie("GotoPage","");
		currentDocument.location = AddParameterToURL(curl,parameterList);
	} 

	function LogOut()
	{
		top.document.location = GetIndexPage() + "?events=logoff";
	}

	/*function GetSessionID()
	{
		return GetCookie("ASP.NET_SessionId");
	}*/

	function GetParentWindow()
	{
		if (windowMode==1)
			return window.dialogArguments;
		else
		if (windowMode==0)
			return window;
		else
			return window.opener;
	}

	function ShowObject(obj)
	{
		var s = "";
		if (typeof(obj)=="string")
			s = obj;
		else if (typeof(obj)=="object")
		{
			for (prop in obj) 
			{ 
				s += prop + "=" + obj[prop]+"\n"; 
			} 
		}else
			s = obj;
		
		alert(s);
	}
	
	function GetRealID(uniqueID)
	{
		if (DotNetVersion=="1.1")
		{
			uniqueID = uniqueID.replace(/_/g,"");
			uniqueID = uniqueID.replace(/:/g,"");
		}else
		if (DotNetVersion=="2.0")
		{
		}else
		{
		}

		return uniqueID;
	}

	function WordEditor(id,openMode,fromModelID)
	{	//id:打开或编辑的Word文件ID;openMode:  2-读写；  1-只读;fromModelID:新建时的模板文件ID
		if (typeof(fromModelID)=='undefined')
			fromModelID = 0;
		var urls = "/BasePage.aspx?_SID=OA&_Ascx=/Sys/FrameWork/Common/Ascx/WordEditor/DocumentEditor.ascx&ResourceClass=Other&ResourceID="+id+"&openMode="+openMode+"&CopyFromID="+fromModelID;
		var reValue = window.showModalDialog(urls,window,'DialogTop=0;DialogLeft=0;DialogHeight='+window.screen.availHeight+'px;DialogWidth='+window.screen.availWidth+'px;status=no;');
		if(id==0 && reValue)
	    return reValue.resourceID;
		else
			return 0;
	}
	