image palcement JS

Hi folks

I have one old script and it was working very fine for InDesign CS2. I am learning JavaScript, and I want to convert it in JavaScript. Can any one help me out.


tell application "Adobe InDesign CS3"
	tell document 1
		set baselineVar to "Yes"
		set countVar to 0
		set imageCount to 0
		set docPath to file path as alias
		tell application "Finder"
			set imageFolder to folder (choose folder with prompt "Please choose the folder containing the appropriate MathType files") 
	end tell
		activate
		set allStories to stories
		repeat with s from 1 to count of items of allStories
			set theStory to item s of allStories
			if class of theStory is story then
				set theLim to count of words of theStory
				try
					repeat with i from 1 to theLim
						if word i of theStory contains "<<" then
							set theText to contents of word i of theStory as Unicode text
							set ImageStyle to "Body"
							if name of applied paragraph style of word i of theStory contains "q" then
								set ImageStyle to "Test"
							end if
							if name of applied paragraph style of word i of theStory contains "ans" then
								set ImageStyle to "Test"
							end if
							set theOffset to (offset of "<<" in theText)
							set endOffset to (offset of ">>" in theText)
							set imageName to characters (theOffset + 2) through (endOffset - 1) of theText as string
							set imageFolderPath to ((imageFolder as string) & imageName)
							set wholeTag to characters theOffset through (endOffset + 1) of theText as string
							if baselineVar = "Yes" then
								set baseline shift of characters theOffset through (endOffset + 1) of word i of theStory to -10.2
							end if
							delete characters theOffset through (endOffset) of word i of theStory
							tell theStory
								tell word i
									tell character theOffset
										place imageFolderPath as alias
										set countVar to (countVar + 1)
									end tell
								end tell
							end tell
						end if
					end repeat
				end try
			end if
		end repeat
	end tell
	activate
	if countVar = 0 then
		display dialog "No Images were found" buttons "OK" default button 1 with icon 2
	else if countVar = 1 then
		display dialog "1 lonely Images has been placed." buttons "OK" default button 1
	else
		display dialog (countVar as string) & " Images have been placed." buttons "OK" default button 1
	end if
end tell

Below is the JavaScript for InDesign CS3. Not completed it in process.


//Initializing the front document.
var myDoc = app.activeDocument;
var baselineVar = true;
var countVar = 0;
var imageCount = 0;
var docPath = myDoc.documentPath;
var myGraphicFolder = Folder.openDialog ("Choose Folder which contains images");
var allStories = myDoc.stories;
with (myDoc)
	{
		
	}

Thanks
Pooja