document._error_messages = new Array();
var nr=0;
var sp = "**";

function submiterrors() {
	_error_obj = {msg : msg, url : url, ln : ln};
	document._error_messages[document._error_messages.length] = _error_obj;
	errorArray = document._error_messages;
	var tmp = "";
	nr=0;
	for (var i = 0; i < errorArray.length; i++) {
		tmp += errorArray[i].url + sp;
		tmp += errorArray[i].msg + sp;
		tmp += errorArray[i].ln + "||";
	}
	document.getElementById('errorimg').src="/reportjserror.jsp?errors="+tmp;
	window.status  = "Done";
	w.innerHTML="";
}

function next() {
	nr=Math.min(document._error_messages.length-1,nr+1);
	showError();
}

function previous() {
	nr=Math.max(0,nr-1);
	showError();
}

function showError() { 
	errorArray = document._error_messages;
	if (errorArray.length != 0 && nr >= 0 && nr < errorArray.length) {
		document.getElementById("url").innerHTML = errorArray[nr].url;
		document.getElementById("msg").innerHTML = errorArray[nr].msg;
		document.getElementById("ln").innerHTML = errorArray[nr].ln;
	}
	//submiterrors();
}

function doError(msg,url,ln) {
	var _error_obj = {msg : msg, url : url, ln : ln};
	document._error_messages[document._error_messages.length] = _error_obj;

	str = ""
	str += "<table width='100%' cellspacing='0' cellpadding='0' border='0'>";
	str += "<tr><td width='100%' align='center'>";
	str += "<table width='500' cellspacing='0' cellpadding='0' border='0' class='tablebody'>";
	str += "<tr><td width='500%' class='blueErrorBorder'>";
	str += "<style>";
	str += ".tablebody {background: #ffffff; color: #000000; border: 3px solid #007FD6; font-family: Tahoma, Arial, Helvitica; Font-size: 12px; margin:0px; padding:5px;}"
	str += "p {font-family: tahoma, arial, helvitica; font-size: 12px; margin-left: 10px; margin-right: 10px;}";
	str += "h1	{font-family: arial black; font-style: italic; margin-left: 10; color:#000000; font-size:13pt;}" ;
	str += "p.heading {font-family: arial black; font-style: italic; margin-bottom: -15; margin-left: 10; color:#A2CC1D; font-size:13pt;}";
	str += "button {margin: 0; border: 1 solid #dddddd; background: #eeeeee; color: black; font-family: tahoma, arial; width: 100px }";
	str += "a {color: #007FD6;}";
	str += ".blueErrorBorder {border:10px solid #000000;}";
	str += "</style>";	
	str += "<h1>For Your Information!</h1>";
	str += '<p>An error occurred in the file <br><strong id="url"></strong><br>This might prevent the page from working correctly.</p>';
	str += '<p style="margin-bottom: 5;">If this error persists please contact <a href="mailto:accountqueries@vcint.com">accountqueries@vcint.com</a></p>';
	str += '<table style="width: 100%;" cellspacing=0 cellpadding=10><tr><td>';
	str += '<button onclick=\'if (document.getElementById("infoArea").style.display!="block") {document.getElementById("infoArea").style.display = "block";this.innerHTML="Hide Error";}else {document.getElementById("infoArea").style.display="none";this.innerHTML="Show Error";}\'';
	str += 'onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">Show Error</button>';
	str += '</td><td align="RIGHT"><button onclick="submiterrors();" onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">Close</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>Message:</p></td><td><p id="msg"></p></td></tr>';
	str += '<tr><td><p>Line:</p></td><td><p id="ln"></p></td></tr>';
	str += '</table>';
	str += '</div>';
	str += '<table style="width: 100%;" cellspacing=0 cellpadding=10><tr><td>';
	str += '<button onclick="previous()" onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">Previous</button>';
	str += '</td><td align=right><button onclick="next()" onmouseover="this.style.borderColor=\'black\'" onmouseout="this.style.borderColor=\'#dddddd\'">Next</button>';
	str += '</td></tr></table>';
	str += '</div>';
	str += '<img style="display:none;" src="/images/trans.gif" id="errorimg">';
	str += '</td></tr></table>';
	str += '</td></tr></table>';

	if (w) {
		w.innerHTML = str;
		showError();
	}
	 if(self['_hbOnError']){
	 	_hbOnError('JS Error at line '+ln+' on: '+hbx.pn + ' | '+msg);
	 }
	
	return true;
}

window.onerror = doError;