//Copyright 2000 Macromedia, Inc. All rights reserved.

function canInspectSelection() 
{

    //do some Mac positioning
	var curSelection	= dreamweaver.getSelection();
	var theObj			= dreamweaver.offsetsToNode(curSelection[0],curSelection[0]+1);
	var translatorClass;
	var lockType;

	if ( theObj.nodeType != Node.ELEMENT_NODE )
	{
		return false; 
	}

	translatorClass = theObj.getAttribute("translatorClass");
	if ( translatorClass != "MM_SSI" )
	{
		return false;
	}

	lockType = theObj.getAttribute("type");
	if ( lockType != "ssi_include" )
	{
		return false;
	}

	return true;
} // function canInspectSelection()

function inspectSelection() 
{
	var curSelection;
	var editFieldStr;
	var fileRadObj;
	var fileStr;
	var includeStr;
	var	origAttr;
	var quoteStr;
	var quoteStrLast;
	var ssiStr;
	var theObj;
	var virtualRadObj;
	var virtualStr;

	//	Get the selection and the data from the selection
	curSelection = dreamweaver.getSelection();
	theObj = dreamweaver.offsetsToNode(curSelection[0],curSelection[0]+1);

 	if (theObj.nodeType != Node.ELEMENT_NODE) 
	{
		return;
	}
	
	origAttr		= theObj.getAttribute("ORIG");
	ssiStr			= unescape( origAttr );

	quoteStr		= ssiStr.indexOf('"');
	quoteStrLast	= ssiStr.lastIndexOf('"');
	editFieldStr	= ssiStr.substring(quoteStr+1,quoteStrLast);
	gOrignalURL		= editFieldStr;
	findObject("editField").value = editFieldStr;
	fileRadObj		= findObject("radioFile");
	virtualRadObj	= findObject("radioVirtual");	
	gOrignalRadio = ssiType( ssiStr.toLowerCase() );

	if ( gOrignalRadio == "virtual" )
	{
		virtualRadObj.checked	= true;
		fileRadObj.checked		= false;
	}
	else 
	{
		fileRadObj.checked		= true; 
		virtualRadObj.checked	= false;
	} 

} // function inspectSelection() 
	

// whichButton is 0 for no button clicked, 1 for the virtual button,
// 2 for the file button
function setComment(whichButton) 
{
	var	afterSelStr;
	var beforeSelStr;
	var curSelection;
	var docSrcStr;
	var entireDocObj;
	var newInc;
	var theObj;

	curSelection	= dreamweaver.getSelection();
	theObj			= dreamweaver.offsetsToNode(curSelection[0],curSelection[0]+1);

	if (theObj.nodeType == Node.ELEMENT_NODE) 
	{
		var radioStr;
		var fileRadObj = findObject("radioFile");
		var virtualRadObj = findObject("radioVirtual");
		if (whichButton == 1) 
		{
			// virtual button was checked
			fileRadObj.checked		= false;
			virtualRadObj.checked	= true;
		} 
		else if (whichButton == 2) 
		{
			// file button was checked
			virtualRadObj.checked	= false;
			fileRadObj.checked		= true;
		}

		var URL = findObject("editField").value;
		if (fileRadObj.checked) 
		{
			// verify that it's okay as a file-type URL


			radioStr = "file";
			if (URL.charAt(0) == '/' || URL.indexOf("../") != -1)
			{
				var fileURL;
				
				relativeURL = findObject("editField").value;
				fileURL = virtualToFile(relativeURL);	

				if ( fileURL == "" )
				{		
					radioStr = "virtual";
					virtualRadObj.checked = true;
					fileRadObj.checked = false;
					return;
				}
				else
				{
					URL = fileURL;
					findObject("editField").value = fileURL;
				}

			}	
			
			// file button was checked
			virtualRadObj.checked	= false;
			fileRadObj.checked		= true;	
		} 
		else 
		{
			radioStr = "virtual";
			virtualRadObj.checked	= true;
			fileRadObj.checked		= false;
		}

		if ( unchanged( radioStr, URL ) )
			return;

		newInc		= "<!--#include " + radioStr + "=" + '"' + URL + '"' +" -->";

		//window.alert( newInc );

		var entireDocObj = dreamweaver.getDocumentDOM("document");
		var docSrc = entireDocObj.documentElement.outerHTML;

		beforeSelStr = docSrc.substring(0, curSelection[0] );
	//	window.alert("Selection was ["+curSelection[0]+","+curSelection[1]);
		afterSelStr  = docSrc.substring(curSelection[1]);
	//	window.alert("Selection was ["+curSelection[0]+","+curSelection[1]);
		docSrc		 = beforeSelStr + newInc + afterSelStr;


		dreamweaver.editLockedRegions(curSelection);
		entireDocObj.documentElement.outerHTML = docSrc;
		dreamweaver.setSelection(curSelection[0], curSelection[0]+1)
		//window.alert( docSrc );
	
	}
} // function setComment(whichButton) 

