/******************************************************************************
*
*	Pivotal eService 5.0
*
*	File:		error.js 
*	Purpose:	Error message javascript functions. Used to display the error
*				box.
*	Date:		January 1, 2003
*
*	Revision	Date			Authour		Description
*	P5i6.12		May 4, 2005		Kevin		Popup message box when Critical or Urgent is select in 
*											the Severity dropdown menu
*   P5i6.16		Aug 12,2005		Jonathan	Added a new message type for the Attachment announcement.
*	P5i6.17		Aug 25, 2005 	ZS			Added a new message title type for preventing addition
*											of a step when SI is closed for more than 14 days.
*	P5i6.25		May 16, 2006	ZS			Enhanced this script to support ok/Cancel dialog. 
*   P5i6.33		Feb 9, 2007		JF			Added new error message case statement
******************************************************************************/

var ICON_TYPE_ERROR = 1;
var ICON_TYPE_INFO = 2;

//P5i6.25 ZS May 16, 2006
var ICON_TYPE_QUESTION = 3;

var ERROR_ICON = "<img src='images/Dialog_ErrorIco.gif' hspace='24'>\n";
var INFO_ICON = "<img src='images/Dialog_InfoIco.gif'  hspace='24'>\n";

//P5i6.25 ZS May 16, 2006
var QUESTION_ICON = "<img src='images/metal-Question.gif'  hspace='24'>\n";

var TITLE_TYPE_CLIENT_ERROR = 1;
var TITLE_TYPE_SERVER_ERROR = 2;
var TITLE_TYPE_LE_ERROR = 3;
var TITLE_TYPE_PARSER_ERROR = 4;
var TITLE_TYPE_PHUB_INFO = 5;
var TITLE_TYPE_VALIDATION_ERROR = 6;

//P5i6.25 ZS May 16, 2006
var TITLE_TYPE_QUESTION = 7;

var PAGE_TITLE_ERROR;
var PAGE_TITLE_INFO;

//P5i6.25 ZS May 16, 2006
var PAGE_TITLE_QUESTION;

var ERR_DEFAULT_TITLE;

var Netscape = (navigator.appName == "Netscape");
var PivotalInfoWindow = new Object();

//P5i6.25 ZS May 18, 2006
var ModalDialogInterval;

//P5i6.25 ZS May 18, 2006
function ModalDialogMaintainFocus()
{
  try
  {
    if (PivotalInfoWindow.win.closed)
     {
        window.clearInterval(ModalDialogInterval);
        eval(PivotalInfoWindow.returnFunc);       
        return;
     }
    PivotalInfoWindow.win.focus(); 
  }
  catch (everything) {   }
}

//P5i6.25 ZS May 18, 2006    
function ModalDialogRemoveWatch()
{
PivotalInfoWindow.returnedValue = '';
PivotalInfoWindow.returnFunc = '';
}


function openErrorDialog(returnFunc, nTitleType, strErrorMessage, nIconType)
{
	PivotalInfoWindow.returnFunc = returnFunc;
	PivotalInfoWindow.returnedValue = "";
	PivotalInfoWindow.url = "about:blank";//url
	PivotalInfoWindow.width = 500;
	PivotalInfoWindow.height = 180;
	PivotalInfoWindow.titleType = nTitleType;
	PivotalInfoWindow.errMessage = strErrorMessage;
	PivotalInfoWindow.icon = nIconType;
	PivotalInfoWindow.attr = "status=no,toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,fullscreen=0";
	PivotalInfoWindow.name = (new Date()).getSeconds().toString();

	if (Netscape) {
		PivotalInfoWindow.left = window.screenX + ((window.outerWidth - PivotalInfoWindow.width) / 2);
		PivotalInfoWindow.top = window.screenY + ((window.outerHeight - PivotalInfoWindow.height) / 2);
		var attr = "screenX=" + PivotalInfoWindow.left + ",screenY=" + PivotalInfoWindow.top + ",width=" + PivotalInfoWindow.width + ",height=" + PivotalInfoWindow.height + "," + PivotalInfoWindow.attr;
	} else {
		PivotalInfoWindow.left = (screen.width - PivotalInfoWindow.width) / 2;
		PivotalInfoWindow.top = (screen.height - PivotalInfoWindow.height) / 2;
		var attr = "left=" + PivotalInfoWindow.left + ",top=" + PivotalInfoWindow.top + ",width=" + PivotalInfoWindow.width + ",height=" + PivotalInfoWindow.height + "," + PivotalInfoWindow.attr;
	}
	//P5i6.25 ZS May 18, 2006
	if (nIconType == 3)
		ModalDialogRemoveWatch();

	PivotalInfoWindow.strHTML = generateStringValueHTML( PivotalInfoWindow.titleType, strErrorMessage, PivotalInfoWindow.icon )
	PivotalInfoWindow.win=window.open(PivotalInfoWindow.url, PivotalInfoWindow.name, attr);
	PivotalInfoWindow.win.document.open();
	PivotalInfoWindow.win.document.write( PivotalInfoWindow.strHTML );
	PivotalInfoWindow.win.document.close();
	PivotalInfoWindow.win.focus();
	
	//P5i6.25 ZS May 18, 2006
	if (nIconType == 3)
	{
		ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5);
		g_userNotified = true;
		return true ;
	}	
	else
		return false;
}


function generateStringValueHTML( nTitleType, strErrorMessage, nIconType )
{
	var strHTML;
	var imgIconType;
	var strTitleType;
	var strPageTitle
	
	switch (nIconType)
	{
		case 1: 
			imgIconType = ERROR_ICON;
			break;
			
		case 2:
			imgIconType = INFO_ICON;
			break;
		//P5i6.25 ZS May 18, 2006	
		case 3:
			imgIconType = QUESTION_ICON;
			break;
			
		default:
			imgIconType = ERROR_ICON;
			break;	
	}
	
		if (imgIconType == ERROR_ICON)
	{
		strPageTitle = PAGE_TITLE_ERROR;
	}
	
	if (imgIconType == INFO_ICON)
	{
		strPageTitle = PAGE_TITLE_INFO;
	}
	
	//P5i6.25 ZS May 16, 2006
	if (imgIconType == QUESTION_ICON)
	{
		strPageTitle = PAGE_TITLE_QUESTION;
	}
	
	switch (nTitleType)
	{
		case 1:
			strTitleType = g_LDSTRING_HEADER_ERROR_CLIENT_ERROR; //ERR_CLIENT_TITLE;
			break;
	
		case 2:
			strTitleType = g_LDSTRING_HEADER_ERROR_SERVER_ERROR; //ERR_SERVER_TITLE;
			break;
		
		case 3:
			strTitleType = g_LDSTRING_HEADER_ERROR_LCS_ERROR; //ERR_LE_TITLE;
			break;
			
		case 4:
			strTitleType = g_LDSTRING_HEADER_ERROR_PARSE_ERROR; //ERR_PARSER_TITLE;
			break;

		case 5:
			strTitleType = g_LDSTRING_HEADER_ERROR_HEADER_INFORMATION; //INFO_ESERVICE_TITLE;
			break;
		
		case 6:
			strTitleType = g_LDSTRING_HEADER_ERROR_VALIDATION_ERROR; //ERR_VALIDATION_TITLE;
			break;
			
		case 7: 
			strTitleType = g_LDSTRING_HEADER_ERROR_ESERVICE_ERROR; //ERR_DEFAULT_TITLE;
			break;
			
		//P5i6.12 May 4, 2005 Kevin - Popup message box when Critical or Urgent is select in the Severity dropdown menu
		case 8:
			strTitleType = g_LDSTRING_MESSAGE_GENERAL; //MESSAGE_GENERAL;
			break;
			
		//P5i6.16 Aug 12, 2005 Jonathan - Added a new type for the Attachment announcement
		case 9:
			strTitleType = g_LDSTRING_MESSAGE_ATTACHMENT; //MESSAGE_ATTACHMENT;
			break;
			
		//P5i6.17 Aug 25, 2005 	ZS
		case 10:
			strTitleType = g_LDSTRING_MESSAGE_TITLE_CLOSE_INCIDENT_STEP; //;
			break;
			
		//P5i6.25 May 16, 2005 	ZS
		case 11:
			strTitleType = "Product changed";
			break;
			
		//P5i6.33 Feb 9, 2007 JF
		case 12:
			strTitleType = g_LDSTRING_MESSAGE_TITLE_COMPANY_PROFILE;
			break;
			
		default:
			strTitleType = g_LDSTRING_HEADER_ERROR_ESERVICE_ERROR; //ERR_DEFAULT_TITLE;
			break;
	}
	
	strHTML = "";
	strHTML = strHTML + "<HTML>\n";
	strHTML = strHTML + "<HEAD>\n";
	strHTML = strHTML + "<LINK href='css/error.css' rel='STYLESHEET' type='text/css'>\n";
	strHTML = strHTML + "<script language='javascript'>\n";
	strHTML = strHTML + "var Netscape = (navigator.appName == 'Netscape')\n";
	strHTML = strHTML + "function onLoadDialog() {\n";
	strHTML = strHTML + "window.resizeBy(0, document.body.scrollHeight-document.body.offsetHeight+5);\n";
	strHTML = strHTML + "}\n";
	strHTML = strHTML + "function closeInfo() {\n";
	strHTML = strHTML + "window.close();\n";
	strHTML = strHTML + "}\n";
	//P5i6.25 May 16, 2006 ZS
	strHTML = strHTML + "function buttonOkClick() {\n";
	if (nIconType == '3') {
		strHTML = strHTML + "opener.PivotalInfoWindow.returnedValue = true;\n";
		strHTML = strHTML + "opener.modalPromptCallBackSave();\n";
	}
	strHTML = strHTML + "closeInfo();\n";
	strHTML = strHTML + "return true;\n";
	strHTML = strHTML + "}\n";	
	strHTML = strHTML + "function buttonCancelClick() {\n";
	//P5i6.25 May 16, 2006 ZS
	if (nIconType == '3') {
		strHTML = strHTML + "opener.PivotalInfoWindow.returnedValue = false;\n";
		strHTML = strHTML + "opener.modalPromptCallBackSave();\n";
	}
	strHTML = strHTML + "closeInfo();\n";
	strHTML = strHTML + "return false;\n";
	strHTML = strHTML + "}\n";
	strHTML = strHTML + "</script>\n";
	strHTML = strHTML + "</HEAD>\n";
	//P5i6.25 May 16, 2006 ZS
	if (nIconType == '3')	
		strHTML = strHTML + "<BODY onLoad='onLoadDialog()' onblur='window.focus();' >\n";
	else
		strHTML = strHTML + "<BODY onLoad='onLoadDialog()'>\n";
	strHTML = strHTML + "<TABLE id='contentTable' bgcolor='#CCCCCC' cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
	strHTML = strHTML + "<TR><TD colSpan='3' valign='top'>\n";
	strHTML = strHTML + "<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'>\n";
	strHTML = strHTML + "<TR><TD class='loginTabHeader'  width='35%'><img src='images/spacer.gif' border=0 alt=''></TD>\n";
	strHTML = strHTML + "<TD class='loginTab'><IMG src='images/login_UpperTab.gif' border='0'></TD>\n";
	strHTML = strHTML + "<TD class='loginHeader'><img src='images/spacer.gif' border=0 alt=''></TD></TR>\n";
	strHTML = strHTML + "</TABLE>\n";
	strHTML = strHTML + "</TD></TR>\n";
	strHTML = strHTML + "<TR><TD colSpan='3'><img src='images/spacer.gif' border=0 alt=''></TD></TR>\n";
	strHTML = strHTML + "<TR><TD colSpan='3'class='errorTitle'>" + strTitleType + "</TD></TR>\n";
	strHTML = strHTML + "<TR><TD colSpan='3'><img src='images/spacer.gif' border=0 alt=''></TD></TR>\n";
	strHTML = strHTML + "<TR><TD colSpan='3'>\n";
	strHTML = strHTML + "<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'>\n";
	strHTML = strHTML + "<TR><TD><img src='images/spacer.gif' border=0 alt='' height=1 width=1></TD>\n";
	strHTML = strHTML + "<TD width=100%><img src='images/spacer.gif' border=0 alt='' height=1 width=1></TD>\n";
	strHTML = strHTML + "<TD><img src='images/spacer.gif' border=0 alt='' height=1 width=70></TD></TR>\n";
	strHTML = strHTML + "<TR><TD rowspan='2' valign='top'>"+ imgIconType +"</TD>\n";
	strHTML = strHTML + "<TD colspan=2 valign='top'class='normalSmallText'>"+ strErrorMessage +"</TD></TR>\n";
	//P5i6.25 May 16, 2006 ZS
	if (nIconType == '3')
		strHTML = strHTML + "<TR><TD valign='top' align='center'><form name='errorButton' style='margin:0;padding:0;'><input type='button' value='Yes' onclick='buttonOkClick()' class='errorButton' style='margin-top:25'/><input type='button' value='No' onclick='buttonCancelClick()' class='errorButton' style='margin-top:25'/></form></TD>\n";
	else
		strHTML = strHTML + "<TR><TD valign='top' align='center'><form name='errorButton' style='margin:0;padding:0;'><input type='button' value='ok' onclick='buttonCancelClick()' class='errorButton' style='margin-top:25'/></form></TD>\n";
	strHTML = strHTML + "<TD class='normalSmallText'>&nbsp;</TD></TR>\n";
	strHTML = strHTML + "</TABLE>\n";
	strHTML = strHTML + "</TD></TR>\n";
	strHTML = strHTML + "<TR><TD colSpan='3'>\n";
	strHTML = strHTML + "<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'>\n";
	strHTML = strHTML + "<TR><TD class='loginBottom' width='10%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>\n";
	strHTML = strHTML + "<TD class='loginBottom' valign='bottom' align='right'><IMG src='images/logonCorner1.gif' border='0'></TD>\n";
	strHTML = strHTML + "<TD class='loginBottomBack' valign='bottom' align='right' width='35%'><IMG src='images/logonCorner2.gif' border='0'></TD></TR>\n";
	strHTML = strHTML + "</TABLE>\n";
	strHTML = strHTML + "</TD></TR>\n";

	strHTML = strHTML + "</TABLE>\n";
	strHTML = strHTML + "</BODY>\n";
	strHTML = strHTML + "</HTML>\n";
	
	return strHTML;

}

