/*
'------------------------------------------------------------------------
'  文件名:      Js_Error.js
'  作者：	Jula
'  文件功能大致描述:用于控制文件(html or asp)中的客户端的脚本错误的，可以显示
'  		　　脚本错误的信息，行数。　	
'  文件接口参数：无              
'  版本：1.0, 2002.6.15 
'
'  log:
'	2005.3.19 为IE添加javascript调用堆栈显示；
'
'  备注：没有解决关于include js文件中出错的显示是那个js文件的功能。
'  Copyright 2002 julei@北京师范大学信息科学学院.  All Rights Reserved.
'-----------------------------------------------------------------------
*/
document._error_messages = new Array();
/**
*
Error Object: 
--------------------------------------------------------------------------------
Property Value    
name 		TypeError 
message 	标题 
number 		-2146823281 
description 	描述 
**/
var __wOutPut;
var __errCount=0;
function __doError(msg,url,ln) {
	var orgFun="window.onerror.caller";
	var rtn=new Array();
	if(eval(orgFun)!=null){
		rtn[rtn.length]=eval(orgFun)+"\r\n";
		while(eval(orgFun+".caller")!=null){
			orgFun+=".caller";
			rtn[rtn.length]=eval(orgFun)+"\r\n";
		}
	}
	else{
		rtn[rtn.length]="语法错误 created by Script Parser;\r\n";
	}
	var _error_obj = {"msg" : msg, "url" : url, "ln" : ln,"callstack":rtn.join("Called by****************************\r\n")};
	
	document._error_messages[document._error_messages.length] = _error_obj;
	/*好像有个bug，document对象得不到错误的个数；好像是下面打开窗体，因此永远都是一个错误计数。*/
	__errCount++;
	
	str = ""
	str += "<title>客户端脚本出现错误的报告</title>"
	str += "<script>window.onload=new Function('showError()');"
	str += 'var nr=0;'
	str += 'var ct='+__errCount+';'
	str += 'function next() {'
	str += '   var errorArray = window.opener.document._error_messages;'
	str += '   try{'	
	str += '   var oldnr=nr;'	
	str += '   nr=Math.min(window.opener.document._error_messages.length-1,nr+1);'
	str += '   showError();'
	str += '   prevbtn.disabled=false;'
	str += '   nextbtn.disabled=false;'
	//str += '      if(nr==oldnr){nextbtn.disabled=true;} '
	str += '   }'
	str += '   catch(oException){'
	str += '   alert(\'你已经关闭了原文件\');'
	str += '   }'
	str += '}'
	str += 'function previous() {'
	str += '   var errorArray = window.opener.document._error_messages;'
	str += '   try{'	
	str += '   nr=Math.max(0,nr-1);'
	str += '   showError();'
	str += '   prevbtn.disabled=false;'
	str += '   nextbtn.disabled=false;'
	str += '      if(nr==0){prevbtn.disabled=true;} '
	str += '   }'
	str += '   catch(oException){'
	str += '   alert(\'你已经关闭了原文件\');'
	str += '   }'
	str += '}'
	str += 'function showError() {'
	str += '   errorArray = window.opener.document._error_messages;'
	str += '   if (errorArray.length != 0 && nr >= 0 && nr < errorArray.length) {'
	str += '      url.innerText = errorArray[nr].url;'
	str += '      msg.innerText = errorArray[nr].msg;'
	str += '      ln.innerText = errorArray[nr].ln;'
	str += '      callstack.innerText = errorArray[nr].callstack;'
	str += '      if(nr==0){prevbtn.disabled=true;} '
	str += '   }'
	str += '}</script>'
	str += "<style>"
	str += "body {background: white; color: black; border: 10 solid navy; font-family: tahoma, arial, helvitica; font-size: 12px; margin: 0;}"
	str += "p {font-family: tahoma, arial, helvitica; font-size: 12px; margin-left: 10px; margin-right: 10px;}"
	str += "h4 {font-family: arial black; font-style: italic; margin-bottom: -15; margin-left: 10; color:navy}"
	str += "button {margin: 0; border: 1 solid #dddddd; background: #eeeeee; color: black; font-family: tahoma, arial; width: 100}"
	str += "a {color: navy;}"
	str += "a:hover {color: blue;}"
	str += "</style>"
	str += '<body scroll="no">'
	str += "<h4>客户端脚本出现错误的报告</h4>"
	str += '<p>一个错误发生在原文件中(或它include的脚本文件中)<br><strong id="url"></strong><br>这使得页面不能正确被浏览</p>'
	str += '<p style="margin-bottom: 5;">请记录告知<a href="mailto:julei@travelsky.com">Jula</a> </p>'
	str += '<table style="width: 100%;height:auto;" cellspacing=0 cellpadding=10><tr><td>'
	str += '<button onclick=\'if (infoArea.style.display!="block") {infoArea.style.display = "block";window.resizeTo(400,420);this.innerText="隐藏错误";}else {infoArea.style.display="none";window.resizeTo(400,219);this.innerText="Show Error";}\''
	str += 'onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">显示错误</button>'
	str += '</td><td align="RIGHT"><button onclick="window.close()" onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">关闭报告</button>'
	str += '</td></tr></table>'
	str += '<div id="infoArea" style="display: none;">'
	str += '<div id="info" style="background: #eeeeee; margin: 10; margin-bottom: 0; border: 1 solid #dddddd;">'
	str += '<table>'
	str += '<tr><td><p>错误信息:</p></td><td><p id="msg"></p></td></tr>'
	str += '<tr><td><p>所在行（也可能是include文件的行数）:</p></td><td><p id="ln"></p></td></tr>'
	str += '<tr><td colspan=2><p style="cursor:hand;" onclick="switchCallStack();">Js调用堆栈(IE支持):</p><div style="display:none;" id="callstack"></div></td></tr>'
	str += '</table>'
	str += '</div>'
	str += '<script>'
	str += 'function switchCallStack(){'
	str += '  var obj=document.getElementById("callstack");'
	str += '  obj.style.display=obj.style.display=="none"?"block":"none";'
	str += '}'
	str += '</script>'
	str += '<table style="width: 100%;" cellspacing=0 cellpadding=10><tr><td>'
	str += '<button onclick="previous()" id=prevbtn onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">前面一个</button>'
	str += '</td><td align=right><button id=nextbtn onclick="next()" onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">下一个</button>'
	str += '</td></tr></table>'
	str += '</div>'
	str += '</body>'

	if (!__wOutPut || __wOutPut.closed) {
		__wOutPut = window.open("","_webclient_error_win","width=400,height=220,resizable=1");
		var d = __wOutPut.document;
		d.open();
		d.write(str);
		d.close();
		__wOutPut.focus();
	}
	return true;
}
if ( window.onerror != null ) {
	var __oldOnerror = window.onerror;
	window.onerror = function ( e ) {
		__oldOnerror( e );
		__doError();
	};
}
else{
	window.onerror = __doError;
}

