//Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.


var helpDoc = MM.HELP_inspSsiCommon;

var gOrignalURL;
var gOrignalRadio;



	
function browseFile()
{
	fileName = browseForFileURL();  //returns a local filename
	if (fileName != "") 
	{
		findObject("editField").value= fileName;
	}
	setComment(0);
} // function browseFile()

function unchanged( type, url )
{
	if ( ( gOrignalRadio == type ) && ( gOrignalURL == url ) )
		return true;
	else
		return false;

} // unchanged()




function editInclude()
{
	var	absoluteURL;
	var docURL;
	var	isDocRelative;
	var relativeURL;
	var siteRootURL;
	var	temp;
	
	relativeURL = findObject("editField").value;

	if ( relativeURL.length <= 0 )
		return;//	Nothing to edit

	docURL = dreamweaver.getDocumentPath("DOCUMENT");
	siteRootURL	= dreamweaver.getSiteRoot();

	isDocRelative = (	
						( relativeURL.length > 3	)	&& 
						( '.' == relativeURL.charAt(0)	)	&&
						( '.' == relativeURL.charAt(1)	)	&& 
						( '/' == relativeURL.charAt(2)	)		
					);

	// Um, let's do some error checking here.

	if	(
			( ""  == siteRootURL			)	&&
			( '/' == relativeURL.charAt(0)	)
		)
	{
		window.alert(MM.MSG_NoSiteForSiteRelURLs);
		return;
	}
	else if	( ( isDocRelative )	&& ( ""  == docURL ) )
	{
		window.alert(MM.MSG_NotSavedForDocRelURLs);
		return;
	}
	
	absoluteURL = dreamweaver.relativeToAbsoluteURL( docURL, siteRootURL, relativeURL );

	if ( absoluteURL != "" )
	{
		dreamweaver.openDocument( absoluteURL );
		return;
	}
	// Should put up an error message here, but what it is I do not know.
} // function editInclude()


//	Returns either file" and "virtual".  Should be passed the unencoded
//	server-side include.  ssiStr should also be lcased before being passed in.
function ssiType( ssiStr ) 
{
	var fileStr;
	var virtualStr;

	fileStr			= ssiStr.indexOf("file");
	virtualStr		= ssiStr.indexOf("virtual");		

	if (	( virtualStr != -1 ) && ( fileStr == -1 )	) 
	{
		return "virtual";
	}
	else if  (	( fileStr != -1 ) && ( virtualStr == -1 )	) 
	{
		return "file";
	} 
	//	if we get here, then the words "file" and "virtural"
	//	both appear in the SSI ( one is in the file name! )
	else if ( virtualStr < fileStr )
	{
		return "virtual";
	}
	else 
	{
		return "file";
	} 
	
} // function ssiType() 

function virtualToFile ( relativeURL )
{
	var absoluteURL;
	var	docBaseURL;
	var docURL;
	var siteRootURL;

	docBaseURL	= docBase();
	if ( docBaseURL[docBaseURL.length-1] != '/' )
		docBaseURL = docBaseURL + '/';

	siteRootURL	= dreamweaver.getSiteRoot();
	absoluteURL = dreamweaver.relativeToAbsoluteURL( docBaseURL, siteRootURL, relativeURL ); 

	if ( 0 != absoluteURL.indexOf( docBaseURL ) )
	{
		window.alert( MM.MSG_CannotConvertURLToIncludeFile );
		return "";
	}

	fileURL = absoluteURL.substring( docBaseURL.length );

	return fileURL;
} // function virtualToFile()

