var g_httpCgiUrl = "/stellent/websites/get_page.asp?";
var g_HttpBrowserFullCgiPath = "/stellent/idcplg/";

/////////////////////////////////////////////////////////////////////////////
// Function : openPrintWindow
// Comments :
/////////////////////////////////////////////////////////////////////////////

function openPrintWindow() {

	if (location.href.search(/\?/) != -1) {
		window.open(location.href + '&printonly=1','','toolbar=yes,location=no,directories=no,menubar=no,scrollbars=yes,width=640,height=480');
	}
	else {
		window.open(location.href + '?printonly=1','','toolbar=yes,location=no,directories=no,menubar=no,scrollbars=yes,width=640,height=480');
	}

}

/////////////////////////////////////////////////////////////////////////////
// Function : printWindow
// Comments :
/////////////////////////////////////////////////////////////////////////////

function printWindow() {

	window.open('/stellent/websites/printpage.asp?ref=' + window.location.href,'printWindow','toolbar=yes,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=480');

}

/////////////////////////////////////////////////////////////////////////////
// Function : emailWindow
// Comments :
/////////////////////////////////////////////////////////////////////////////

function emailWindow() {
	window.open('/stellent/idcplg?IdcService=GET_SEND_LINK_BY_EMAIL_FORM&coreContentOnly=1&link=' + escape(window.location.href),'','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=510');
}

/////////////////////////////////////////////////////////////////////////////
// Function : bookmark
// Comments :
/////////////////////////////////////////////////////////////////////////////
function bookmark(dDocName,anchorname)
{
	if ((dDocName.search("http://") != -1) || (dDocName.search("https://") != -1))
		window.open(dDocName);
	else
	{
		var newUrl = "";
		//newUrl += g_httpCgiUrl;
		// Old way (6.2)
		//newUrl += "/intradoc-cgi/idc_cgi_isapi.dll";

		newUrl += "/stellent/idcplg";
		newUrl += "?IdcService=SS_GET_PAGE&ssDocName=" + dDocName;

		var currentUrl = "" + window.location;

		// Continue propagation of the "SSContributor" parameter
		//if( SSContributor )
		//{
		//	var paramName = "SSContributor=";
		//	var pos = currentUrl.indexOf( paramName );
		//	if( pos != -1 )
		//	{
		//		var subStr = currentUrl.substring( pos+paramName.length, pos+paramName.length+1 );
		//		if( isTrue( subStr ) )
		//		{
		//			newUrl += "&" + paramName + "true";
		//		}
		//	}
		//}

		// Continue propagation of the "previewId" parameter
		var previewId = "previewId=";
		var posStart = currentUrl.indexOf( previewId );
		if( posStart != -1 )
		{
			var posEnd = currentUrl.indexOf("&", posStart);
			var value = "";
			if (posEnd == -1)
			{
				value = currentUrl.substring(posStart+previewId.length, currentUrl.length);
			}
			else
			{
				value = currentUrl.substring(posStart+previewId.length, posEnd);
			}
			newUrl += "&" + previewId + value;
		}

		//newURL += "#" + anchorname;

		// Navigate to the new url
		window.location = newUrl+"#"+anchorname;
	}
}

/////////////////////////////////////////////////////////////////////////////
// Function : bookmarkWindow
// Comments :
/////////////////////////////////////////////////////////////////////////////

function bookmarkWindow(dDocName,anchorname,theToolbar,theStatus,theMenubar,theScrollbars,theResizable,theDirectories,theLocation,theWidth,theHeight)
{
	if ((dDocName.search("http://") != -1) || (dDocName.search("https://") != -1))
		//window.open(dDocName);
		window.open(dDocName,"newWindow","toolbar="+theToolbar+",status="+theStatus+",menubar="+theMenubar+",scrollbars="+theScrollbars+",resizable="+theResizable+",directories="+theDirectories+",location="+theLocation+",width="+theWidth+",height="+theHeight+",screenX=200,screenY=200,left=200,top=100")
	else
	{
		
		var newUrl = "";
		//newUrl += g_httpCgiUrl;
		// Old way (6.2)
		//newUrl += "/intradoc-cgi/idc_cgi_isapi.dll";

		newUrl += "/stellent/idcplg";
		newUrl += "?IdcService=GET_DYNAMIC_CONVERSION&dDocName=" + dDocName;
		newUrl += "&RevisionSelectionMethod=Latest";
		
		var currentUrl = "" + window.location;

		// Continue propagation of the "SSContributor" parameter
		//if( SSContributor )
		//{
		//	var paramName = "SSContributor=";
		//	var pos = currentUrl.indexOf( paramName );
		//	if( pos != -1 )
		//	{
		//		var subStr = currentUrl.substring( pos+paramName.length, pos+paramName.length+1 );
		//		if( isTrue( subStr ) )
		//		{
		//			newUrl += "&" + paramName + "true";
		//		}
		//	}
		//}

		// Continue propagation of the "previewId" parameter
		var previewId = "previewId=";
		var posStart = currentUrl.indexOf( previewId );
		if( posStart != -1 )
		{
			var posEnd = currentUrl.indexOf("&", posStart);
			var value = "";
			if (posEnd == -1)
			{
				value = currentUrl.substring(posStart+previewId.length, currentUrl.length);
			}
			else
			{
				value = currentUrl.substring(posStart+previewId.length, posEnd);
			}
			newUrl += "&" + previewId + value;
		}

		//newURL += "#" + anchorname;

		// Navigate to the new url
		//window.location = newUrl+"#"+anchorname;
		
		var windowName = new String(Math.round(Math.random() * 100000));
		
		// Navigate to the new url
		//window.open(newUrl, "newWindow")
		window.open(newUrl+"#"+anchorname,windowName,"toolbar="+theToolbar+",status="+theStatus+",menubar="+theMenubar+",scrollbars="+theScrollbars+",resizable="+theResizable+",directories="+theDirectories+",location="+theLocation+",width="+theWidth+",height="+theHeight+",screenX=200,screenY=200,left=200,top=100")
		
	}
}

// customWindow Function
// Gregory Reddin greddin@komen.org
// This function will force a document to open inside a new window
// without a page wrapper. The window can be controlled by specifying 
// the following parameters:
//
// dDocName,theToolbar,theStatus,theMenubar,theScrollbars,
// theResizable,theDirectories,theLocation,theWidth,theHeight
// 
// Sample Usage: (0 = off / 1 = on)
// <a href="javascript:customWindow('AboutBreastCancer',0,0,0,1,1,0,0,200,200);">Link</a>
// The line above opens the document named "AboutBreastCancer" in a new window 
// that has toolbar=off, statusbar=off, menubar=off, scrollbars=on, the window is resizable, 
// directories=off, location(address bar)=off, window width is 200 pixels, and 
// window height is 200 pixels.


function customWindow(dDocName,theToolbar,theStatus,theMenubar,theScrollbars,theResizable,theDirectories,theLocation,theWidth,theHeight) {

	if ((dDocName.search("http://") != -1) || (dDocName.search("https://") != -1) || (dDocName.search("/") != -1))
		// window.open(dDocName);
		window.open(dDocName,"newWindow","toolbar="+theToolbar+",status="+theStatus+",menubar="+theMenubar+",scrollbars="+theScrollbars+",resizable="+theResizable+",directories="+theDirectories+",location="+theLocation+",width="+theWidth+",height="+theHeight+",screenX=200,screenY=200,left=200,top=100")
	else
	{
		var newUrl = "";
		//newUrl += g_httpCgiUrl;
		// Old way (6.2)
		//newUrl += "/intradoc-cgi/idc_cgi_isapi.dll";

		newUrl += "/stellent/idcplg";
		newUrl += "?IdcService=GET_DYNAMIC_CONVERSION&dDocName=" + dDocName;
		newUrl += "&RevisionSelectionMethod=Latest";

		var currentUrl = "" + window.location;

		// Continue propagation of the "SSContributor" parameter
//		if( SSContributor )
//		{
//			var paramName = "SSContributor=";
//			var pos = currentUrl.indexOf( paramName );
//			if( pos != -1 )
//			{
//				var subStr = currentUrl.substring( pos+paramName.length, pos+paramName.length+1 );
//				if( isTrue( subStr ) )
//				{
//					newUrl += "&" + paramName + "true";
//				}
//			}
//		}

		// Continue propagation of the "previewId" parameter
		var previewId = "previewId=";
		var posStart = currentUrl.indexOf( previewId );
		if( posStart != -1 )
		{
			var posEnd = currentUrl.indexOf("&", posStart);
			var value = "";
			if (posEnd == -1)
			{
				value = currentUrl.substring(posStart+previewId.length, currentUrl.length);
			}
			else
			{
				value = currentUrl.substring(posStart+previewId.length, posEnd);
			}
			newUrl += "&" + previewId + value;
		}

		var windowName = new String(Math.round(Math.random() * 100000));
		
		// Navigate to the new url
		//window.open(newUrl, "newWindow")
		window.open(newUrl,windowName,"toolbar="+theToolbar+",status="+theStatus+",menubar="+theMenubar+",scrollbars="+theScrollbars+",resizable="+theResizable+",directories="+theDirectories+",location="+theLocation+",width="+theWidth+",height="+theHeight+",screenX=200,screenY=200,left=200,top=100")
	}

	// Please provide the proper parameters
	// dDocName
	// theToolbar
	// theStatus
	// theMenubar
	// theScrollbars
	// theResizable
	// theDirectories
	// theLocation
	// theWidth
	// theHeight
	//window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,screenX=200,screenY=200,left=200,top=100,width="+theWidth+",height="+theHeight)
}

//////////////////////////////////////////////////////////////////////////////////
// Function : getfile
// Comments : Prompts the user to open or save a native file
// Parameters needed : ContentID
//////////////////////////////////////////////////////////////////////////////////

function getfile(dDocName) {

	var newUrl = "";
	newUrl += g_HttpBrowserFullCgiPath;
	newUrl += "?IdcService=GET_FILE&dDocName=" + dDocName;
	newUrl += "&Rendition=Primary";
	newUrl += "&RevisionSelectionMethod=Latest";

	window.location = newUrl;
}

