/* 	All actions involving serverside interaction are performed through the
	interface defined by these functions. These functions have different definitions
	for windows client and web clients (this set is for web client).
*/

//variable to disable form buttons while behind scenes processing (eg, checking lookups) is completed.
var bFormDisabled=false;

function PT_popupWindow(p_sURL,p_sStyle)
{
	var sHeight;
	var sWidth;
	var oWindow;
	
	//options for window style are:
	// LINKER - sized for the generic linker 
	// SMALL - small popup
	// LARGE - almost full screen popup
	// TAXBROWSER - for the taxonomy browser
	// RULECONDITION - for rule conditions
	// SYNCPROG - for synchronisation progress
	// add others as necessary...
	switch (p_sStyle){
		case 'LOGIN':
			sHeight='200';
			sWidth='200';
			break;
		case 'LOOKUP':
			sHeight='450';
			sWidth='850';
			break;
		case 'LINKER':
			sHeight='400';
			sWidth='750';
			break;
		case 'SECURITY':
			sHeight='600';
			sWidth='780';
			break;s
		case 'SMALL':
			sHeight='450';
			sWidth='500';
			break;
		case 'LARGE':
			sHeight='650';
			sWidth='850';
			break;
		case 'TAXBROWSER':
			sHeight='600';
			sWidth='800';
			break;
		case 'RULECONDITION':
			sHeight='170';
			sWidth='650';
			break;
		case 'SYNCPROG':
			sHeight='250';
			sWidth='400';
			break;
		case 'CALENDAR':
			sHeight='420';
			sWidth='350';
			break;
	}
	var sOptions
	sOptions = 'resizable=yes,location=no,menubar=no,toolbar=no,directories=no,height='+sHeight;
	sOptions = sOptions+',width='+sWidth;

	var lTop = ((screen.Height) - sHeight) / 2
	var lLeft = ((screen.Width) - sWidth) / 2

	sOptions = sOptions+',top='+lTop;
	sOptions = sOptions+',left='+lLeft;
	oWindow = window.open(p_sURL,'_blank',sOptions);
	if (window.wPopUpWin)
		{
		wPopUpWin = oWindow;
		}
	return oWindow;
}

function PT_close()
{
	window.close();
}

function PT_CloseChildPopup()
	{
	//closes popup window pointed to by wPopUpWin
	// doesn't matter if there isn't a variable called wPopUpWin
	// this line checks for it (doing 'window.' in front of the variable stops
	// 'undefined' error message if wPopUpWin does not exist
	if (window.wPopUpWin)
		{
		if (wPopUpWin!=null)
			{
			wPopUpWin.close();
			}
		}
	}
	
function PT_submit(p_sFormname, p_sTargetFrameID, p_oTarget)
{
	//check if form is disabled
	if (p_sTargetFrameID==null)
		{
		//if we are a hpe,  open in parent
		var oField = document.getElementById('PT_ISHP')
		if (oField!=null)
			{
			if (oField.value=='1')
				{
				p_sTargetFrameID = '_parent';
				}
			}
		}
	if (!bFormDisabled){
		if (p_sTargetFrameID!=null)
			document.getElementById(p_sFormname).target = p_sTargetFrameID;
		else
			document.body.style.cursor='wait';
		document.getElementById(p_sFormname).submit();
	}
	//wait for a period and then retry
	else{
		var sCommand = 'PT_submit(';
		if (p_sFormname==null)
			sCommand = sCommand + 'null,';
		else
			sCommand = sCommand + '\''+p_sFormname+'\',';
		
		if (p_sTargetFrameID==null)
			sCommand = sCommand + 'null)';
		else
			sCommand = sCommand + '\''+p_sTargetFrameID+'\')';
		
		window.setTimeout(sCommand,1000);
	}
}

function PT_setFrameSRC(p_sDPString,p_sFrameID)
{
	if (p_sFrameID==null)
		{
		//if we are a hpe,  open in parent
		var oField = document.getElementById('PT_ISHP')
		if (oField!=null)
			{
			if (oField.value=='1')
				{
				p_sFrameID = '_parent';
				}
			}
		}

	if (p_sFrameID!=null)
		{
		if (p_sFrameID == '_parent')
			{
			window.parent.navigate(p_sDPString);
			}
		else
			{
			document.getElementById(p_sFrameID).src = p_sDPString;
			}
		}
	else
		{
		document.body.style.cursor='wait';
		window.navigate(p_sDPString);
		}
	}

function PT_openerDoc()
{
	return window.opener.document;
}

function PT_openerWin()
{
	return window.opener;
}

/* view an attachment */
function PT_viewDoc(p_sGUID,p_sURL,p_WinHoldingPopupVar)
{
	var sOptions
	var oWindow
	sOptions = 'resizable=yes,location=no,menubar=no,toolbar=no,directories=no,center=yes,height=650';
	sOptions = sOptions+',width=850';
	oWindow=window.open('drawpageNET.aspx?DOTNET=TRUE&DP=GDW&MODE=SHOWDOC&ATTACHMENTGUID=' + p_sGUID,'_blank',sOptions);
	if (p_WinHoldingPopupVar!=null)
		{
		p_WinHoldingPopupVar.wPopUpWin = oWindow;
		}
	else
		{
		this.wPopUpWin = oWindow;
		}
//	if (p_WinHoldingPopupVar!=null)
//		{
//		if (p_WinHoldingPopupVar.window.wPopUpWin)
//			{
//			p_WinHoldingPopupVar.wPopUpWin=oWindow;
//			}
//		}
	return oWindow; 
}

/* edit an attachment directly */
function PT_editDoc(p_sGUID)
{
	window.navigate('drawpageNET.aspx?DOTNET=TRUE&DP=GDW&MODE=EDITATTACHMENT&ATTACHMENTGUID=' + p_sGUID);
}

/* view a url directly */
function PT_viewImage(p_sURL,p_WinHoldingPopupVar)
{
	var sOptions
	var oWindow
	sOptions = 'resizable=yes,location=no,menubar=no,toolbar=no,directories=no,center=yes,height=650';
	sOptions = sOptions+',width=850';
	oWindow=window.open(p_sURL,'_blank',sOptions);
	if (p_WinHoldingPopupVar!=null)
		{
		p_WinHoldingPopupVar.wPopUpWin = oWindow;
		}
	else
		{
		this.wPopUpWin = oWindow;
		}
//	if (p_WinHoldingPopupVar!=null)
//		{
//		if (p_WinHoldingPopupVar.window.wPopUpWin)
//			{
//			p_WinHoldingPopupVar.wPopUpWin=oWindow;
//			}
//		}
	return oWindow; 
}

/* view an item profile*/
function PT_showKBProfile(p_sGUID)
{	
	var sDPStr = 'drawpageNET.aspx?DOTNET=TRUE&DP=KPORT&MODE=VIEWKTITEM&KTITEMGUID=' + p_sGUID;
	PT_setFrameSRC(sDPStr);
}

/*MWC related functions - called from the browser*/

function PT_mwcOpenWithByItemGUID(p_sGUIDs)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.OpenDocsWithFromItemGUID(p_sGUIDs);
}

function PT_mwcOpenWith(p_sDocIds)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.OpenDocsWith(p_sDocIds);
}

function PT_mwcPrintByItemGUID(p_sGUIDs)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.PrintDocsFromItemGUID(p_sGUIDs);
}

function PT_mwcPrint(p_sDocIds)
{
  	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.PrintDocs(p_sDocIds);
}

function PT_mwcSendToByItemGUID(p_sGUIDs,p_iUseShortcuts)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.EmailDocsFromItemGUID(p_sGUIDs,p_iUseShortcuts);
}
function PT_mwcSendTo(p_sDocIds,p_iUseShortcuts)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.EmailDocs(p_sDocIds,p_iUseShortcuts);
}

function PT_mwcCompareDocs(p_sGUIDs)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
        oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.CompareDocs(p_sGUIDs);
}

function PT_mwcAttach(p_sEmailID, p_sDocIds)
{
      var oMWC = new ActiveXObject("MWCWebLink.CLink");
      oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
      oMWC.AttachToMail(p_sEmailID,p_sDocIds);
}
 
function PT_mwcAttachByItemGuid(p_sEmailID, p_sGUIDs)
{
      var oMWC = new ActiveXObject("MWCWebLink.CLink");
      oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
      oMWC.AttachToMailFromItemGUID(p_sEmailID,p_sGUIDs);
}

function PT_mwcSaveToDisk(p_sGUIDs)
{
	var oMWC = new ActiveXObject("MWCWebLink.CLink");
	oMWC.sSessionID = 'PT_RS-' + document.getElementById('PT_USERSESSION').value;
	oMWC.SaveToDisk(p_sGUIDs);
}


