/*	
	Script name: FwdSlashes
	author: sam AT sam-i-am.com
	date:  Thursday, July 12, 2001

	Purpose: This script reverses \ to \ in a selection. 
	
*/

var app = Application;
var active = app.ActiveDocument;
var MB_OK = 0;

function Main() {

	// define strText - the scope of the search
  	if(!app.ActiveDocument.SelText) 
  	{
		app.MessageBox("This will only run on a selection \n\naborting..","Escape String",MB_OK);
		return false;
  	}

  strText = app.ActiveDocument.SelText;

	// capture the position of the selection if there is one	
	var strScope = "selection";
	var selectStart = active.SelStart;

	// local variable for the new string to be returned
	strNew = strText;
	
	// match and replace / for \;  
	  var matchAmp = /\//gi;
	  strNew = strNew.replace(matchAmp,"\\");
	
	eval("app.ActiveDocument." +  ((app.ActiveDocument.SelText) ? "SelText" : "Text") + "= strNew");
	
	// reset selection to encompass all the new string
	var matchEOL = /\n/gi;
	if(matchEOL.test(strNew)) { 
		intLineEndings = strNew.match(matchEOL).length; 
		active.SelStart = selectStart;
		active.SelLength = Math.ceil(strNew.length - (intLineEndings+1 / 2));
	}
}
// misc functions..
function alert(txt) {
	app.MessageBox(txt, "HomeSite Script Msg",0);
}



