'
' Version MTM2 and MethodD (Project Map)
' October, 2003
'
dim SiteLanguage
SiteLanguage = "English"

dim OfficeSupported
dim Office8path, Office9path, Office10path, Office11path, OfficeDefault

' Office Versions Supported
' (each version needs to be in single quotes and separated by commas)

OfficeSupported = "'8','9','10', '11'"

' paths to templates, relative to the root
'
Office8path = "MethodC/Office_97"
Office9path = "MethodC/Office_2K"
Office10path ="MethodC/Office_XP"
Office11path ="MethodC/Office_2003"
OfficeDefault = "MethodC/Office_2K"

function GetOfficeFolder()
	dim version
	dim cookieString
	dim pos1
	cookieString = document.cookie

	version=""
	pos0 = Instr(cookieString,"OfficeVersion")
	if pos0 <> 0 then
	pos1 = Instr(pos0,cookieString, "=")
	if pos1<>0 then
		pos2 = instr(pos1, cookieString, ";")
		if pos2 <> 0 then
			version = mid(cookieString, pos1+1, pos2-pos1-1)
		else
			version = mid(cookieString, pos1+1)
		end if
	end if
	end if

	select case version
		case "8"
			GetOfficeFolder = Office8Path
		case "9"
			GetOfficeFolder = Office9Path
		case "10"
			GetOfficeFolder = Office10Path
		case "11"
			GetOfficeFolder = Office11Path
		case else
			GetOfficeFolder = OfficeDefault
			'window.location.href = OfficeDefault
			'window.showModalDialog  "../../../checkOffice.htm",,"dialogWidth:220px; dialogHeight:210px; center:yes"
			'GetOfficeFolder()
	end select
end function

function ChangeOfficeVersion()
	
	window.showModalDialog  "changeOffice.htm",,"dialogWidth:220px; dialogHeight:210px; center:yes"

end function

function OpenReadMe()
	
	window.showModalDialog  "ReadMe.htm",,"dialogWidth:420px; dialogHeight:410px; center:yes"

end function

function BrowseForDirectory(StartDirectory)

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim newdir

	set o = createObject("MethodaOpenObj70.Interface")
	newdir = o.BrowseForDirectory(StartDirectory)
	if newdir<>"" then document.all.dir.value = newdir
	set o = nothing
	window.focus()
	window.event.returnValue=false

end function	

function BrowseForFolderDirectory(StartDirectory)
	'
	' MTM2
	' works in conjunction with the Project Folder Template dialog
	'
	dim o
	dim newdir
	
	if OCXInstalled then
		set o = createObject("MethodaOpenObj70.Interface")
		newdir = o.BrowseForDirectory(StartDirectory)
		if newdir<>"" then document.all.foldertemplate_dir.value = newdir
		set o = nothing
	
	end if	
	window.focus()
	window.event.returnValue=false

end function

function BrowseDefaultFolder(StartDirectory)
	'
	' MTM2
	' works in conjunction with the Project Folder Template dialog
	'
	dim o
	dim newdir
	
	if OCXInstalled then
		set o = createObject("MethodaOpenObj70.Interface")
		newdir = o.BrowseForDirectory(StartDirectory)
		if newdir<>"" then document.all.folder_dir.value = newdir
		set o = nothing
	
	end if	
	window.focus()
	window.event.returnValue=false

end function	

function GetDefaultProjectDir()

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim defdir

	set o = createObject("MethodaOpenObj70.Interface")
	defdir = o.GetDefaultProjectDir()
	GetDefaultProjectDir = defdir

	set o = nothing

end function


function GetDefaultProjectFoldersDir()

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim defdir

	set o = createObject("MethodaOpenObj70.Interface")
	defdir = o.GetDefaultProjectFoldersDir()
	GetDefaultProjectFoldersDir = defdir

	set o = nothing

end function

'------------------------------------------
'Author Yakov LLX
'12/02/04
'Description: Same functionality as function "GetDefaultProjectFoldersDir()"
'Returns the path of the dir using the OCX
'------------------------------------------
function GetDefaultFoldersDir()

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim defdir

	set o = createObject("MethodaOpenObj70.Interface")
	defdir = o.GetDefaultProjectDir()
	GetDefaultFoldersDir = defdir

	set o = nothing

end function

function GetMethodCDirectory()

	' this function returns the full URL to the MethodC directory	
	winloc = window.location
	pos = instrrev(winloc, "/kits/",-1,1)
	
	if pos = 0 then
		pos = instrrev(winloc, "/Global_Interface/",-1,1)
	end if
	'
	' check if MethodD (Project Map)
	'
	if pos = 0 and instr(winloc,"MethodD")<>0 then
	   pos = instrrev(winloc,"/",-1,1)
  	   winloc = mid(winloc, 1, pos) & "Project Folders"
	   winloc = replace(winloc, "file:///", "file://")
	   GetMethodCDirectory = winloc
	elseif pos <> 0 then
		winloc = mid(winloc, 1, pos) & GetOfficeFolder()
		winloc = replace(winloc, "file:///", "file://")
		GetMethodCDirectory = winloc
	end if
	
end function


function SaveProjectAnchor()

	dim o
	dim defdir
	dim success

	defdir = document.all.foldertemplate_dir.value

	if defdir<>"" then 

		' record the new default project folders directory
		'
		set o = createObject("MethodaOpenObj70.Interface")
		o.SetDefaultProjectFoldersDir(defdir)
		if defdir = o.GetDefaultProjectFoldersDir() then
			If SiteLanguage = "Hebrew" then
				msgbox "ספריית עוגן הפרוייקט שונה בהצלחה",, "MethodA"
			Else
				msgbox "Your Project Anchor directory was successfully changed.",, "MethodA"
			End If
		else
			If SiteLanguage = "Hebrew" then
				msgbox "ספריית עוגן הפרוייקט לא שונה",, "MethodA"
			Else
				msgbox "Warning: Your Project Anchor directory was not changed.",, "MethodA"
			End If
		end if

		set o = nothing
		document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="hidden"
	End If

	window.event.returnValue=false


end function


'------------------------------------------
'Author Yakov LLX
'12/02/04
'Description: Same functionality as function 'SaveProjectAnchor'
'For the Default Folder change
'Saves directory info from Dialog box
'------------------------------------------
function SaveDefaultFolder()

	dim o
	dim defdir
	dim success

	defdir = document.all.folder_dir.value

	if defdir<>"" then 

		' record the new default project folders directory
		'
		set o = createObject("MethodaOpenObj70.Interface")
		o.SetDefaultProjectDir(defdir)
		if defdir = o.GetDefaultProjectDir() then
			If SiteLanguage = "Hebrew" then
				msgbox "ספריית ברירת המחדל שונה בהצלחה",, "MethodA"
			Else
				msgbox "The Default Folder directory was changed successfully",, "MethodA"
			End If
		else
			If SiteLanguage = "Hebrew" then
				msgbox "ספריית ברירת המחדל לא שונה",, "MethodA"
			Else
				msgbox "Warning: Your Default Folder directory was not changed.",, "MethodA"
			End If
		end if

		set o = nothing
		document.all.tags("DIV")("Default_Folder_Popup").style.visibility="hidden"
	End If

	window.event.returnValue=false


end function

function SaveDocument(FileType)

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim defdir
	dim FileToSave
	dim NewFileName
	dim success
	dim winloc

	set o = createObject("MethodaOpenObj70.Interface")

	if ucase(FileType) = "FOLDER" then

		defdir = document.all.foldertemplate_dir.value

		'defdir = o.BrowseForDirectory(defdir)
		'if defdir<>"" then 

			' record the new default project folders directory
			'
			If document.all.foldertemplate_checkbox.checked = True then
				o.SetDefaultProjectFoldersDir(defdir)
			End if

			FileToSave = document.all.foldertemplate_sourcefilename.value
			NewFileName = document.all.foldertemplate_filename.value
			FileType = document.all.foldertemplate_filetype.value
	

			' determine the full path to FileToSave
			'
			MethodCDir = GetMethodCDirectory()
			FileToSave = MethodCDir & "/" & FileToSave
	
			FileToSave = Replace(FileToSave,"%20"," ")	

			' copy the template document onto the client
			'
			success = o.CopyDocument(FileToSave, defdir, NewFileName, FileType)

		'else
		'	success = False
		'end if

		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="hidden"
		end if

	elseif ucase(FileType) = "MPP" then
	
		defdir = document.all.dir_project.value
		FileToSave = document.all.sourcefilename_project.value
		NewFileName = document.all.filename_project.value
		FileType = document.all.filetype_project.value

		' if checkbox is checked, the record the new default directory
		'
		If document.all.checkbox_project.checked = True then
			o.SetDefaultProjectDir(defdir)
		End If

		' determine the full path to FileToSave
		'
		MethodCDir = GetMethodCDirectory()
		FileToSave = MethodCDir & "/" & FileToSave

		FileToSave = Replace(FileToSave,"%20"," ")	

		' copy the template document onto the client and open it
		'
		success = o.CopyDocument(FileToSave, defdir, NewFileName, FileType)

		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup_project").style.visibility="hidden"
		end if

	else
		defdir = document.all.dir.value
		FileToSave = document.all.sourcefilename.value
		NewFileName = document.all.filename.value
		FileType = document.all.filetype.value
	
		' if checkbox is checked, the record the new default directory
		'
		If document.all.checkbox.checked = True then
			o.SetDefaultProjectDir(defdir)
		End If

		' determine the full path to FileToSave
		'
		MethodCDir = GetMethodCDirectory()
		FileToSave = MethodCDir & "/" & FileToSave

		FileToSave = Replace(FileToSave,"%20"," ")	

		' copy the template document onto the client
		'
		success = o.CopyDocument(FileToSave, defdir, NewFileName, FileType)

		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup").style.visibility="hidden"
		end if
	end if
		
	set o = nothing
	window.event.returnValue=false
	
end function


function SaveAndOpenDocument(FileType)

	'
	' MTM2
	' works in conjunction with the Project Folder dialog
	'

	dim o
	dim defdir
	dim FileToSave
	dim NewFileName
	dim success

	set o = createObject("MethodaOpenObj70.Interface")

	if ucase(FileType) = "FOLDER" then

		defdir = document.all.foldertemplate_dir.value
		'defdir = o.BrowseForDirectory(defdir)

		'if defdir<>"" then 

			' record the new default project folders directory
			'
			If document.all.checkbox.checked = True then
				o.SetDefaultProjectFoldersDir(defdir)
			End If

			FileToSave = document.all.foldertemplate_sourcefilename.value
			NewFileName = document.all.foldertemplate_filename.value
			FileType = document.all.foldertemplate_filetype.value

			' determine the full path to FileToSave
			'
			MethodCDir = GetMethodCDirectory()
			FileToSave = MethodCDir & "/" & FileToSave

			FileToSave = Replace(FileToSave,"%20"," ")	

			' copy the template document onto the client and open it
			'
			success = o.CopyAndOpenDocument(FileToSave, FileType, defdir, NewFileName)

		'else
		'	success = False
		'end if

		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="hidden"
		end if

	elseif ucase(FileType) = "MPP" then
	
		defdir = document.all.dir_project.value
		FileToSave = document.all.sourcefilename_project.value
		NewFileName = document.all.filename_project.value
		FileType = document.all.filetype_project.value

		' if checkbox is checked, the record the new default directory
		'
		If document.all.checkbox_project.checked = True then
			o.SetDefaultProjectDir(defdir)
		End If

		' determine the full path to FileToSave
		'
		MethodCDir = GetMethodCDirectory()
		FileToSave = MethodCDir & "/" & FileToSave

		FileToSave = Replace(FileToSave,"%20"," ")	

		' copy the template document onto the client and open it
		'
		success = o.CopyAndOpenDocument(FileToSave, FileType, defdir, NewFileName)
		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup_project").style.visibility="hidden"
		end if
		
	else

		defdir = document.all.dir.value
		FileToSave = document.all.sourcefilename.value
		NewFileName = document.all.filename.value
		FileType = document.all.filetype.value

		' if checkbox is checked, the record the new default directory
		'
		If document.all.checkbox.checked = True then
			o.SetDefaultProjectDir(defdir)
		End If

		' determine the full path to FileToSave
		'
		MethodCDir = GetMethodCDirectory()
		FileToSave = MethodCDir & "/" & FileToSave

		FileToSave = Replace(FileToSave,"%20"," ")	

		' copy the template document onto the client and open it
		'
		success = o.CopyAndOpenDocument(FileToSave, FileType, defdir, NewFileName)
		if success = False then
			msgbox "MethodA was unable to save the file."
		else
			document.all.tags("DIV")("project_folder_popup").style.visibility="hidden"
		end if
	end if
		
	set o = nothing
	window.event.returnValue=false
	
end function

Function DirectReminder( param, paramType, cleanName, strDialog )

	call HideAllLays()

'When OCX not installed yet show dialog
	
	set sDialog = document.all(strDialog)
	cookieName="Remind"
      ' 24-Nov-04
      ' Aliza
      ' We should check if the OCX is installed for this language
      'if OCXInstalled() then
       if OCXInstalledForSiteLanguage() then

		CookieName="RemindW"
		set sDialog = document.all(strDialog & "1")
	End If
	
	If getCookie( cookieName ) = "1" then
		openFile param, paramType
	Else
		sDialog.style.visibility = "visible"
		document.all.filename_remind.value = param
		document.all.filetype_remind.value = paramType
		document.all.cleanname_remind.value = cleanName
	End If
		
End Function


Function RemindOpenFile( param, paramType, checkBX, cookieName, oDialog )

	If checkBX then	setCookie cookieName, "1"
	openFile param, paramType
	oDialog.style.visibility = "hidden"		
	
End Function

Function RemindSeeLay( checkBX, cookieName, oDialog )

	If checkBX then	setCookie cookieName, "1"
	if instr(ucase(cstr(oDialog.id)),"FOLDER") <> 0 then
		SeeLay document.all.cleanname_remind.value,document.all.cleanname_remind.value, document.all.filetype_remind.value
	else
		SeeLay document.all.filename_remind.value,document.all.cleanname_remind.value, document.all.filetype_remind.value
	end if
	oDialog.style.visibility = "hidden"		

End Function


function openFile(param, paramType)

	'
	' MTM2
	' Open glufa in IE secondary window
	' -without use of OCX
	'
	pos = instrrev(param, "/")
	if pos <> 0 then param = mid(param, pos+1)
	MethodCDir = GetMethodCDirectory()
	param = MethodCDir & "/" & param
	param = Replace(param,"%20"," ")	
	window.open param
	
end function


function openFile_v6(param, paramType)
	' opens glufa using the OCX
	' (as done in the original v6.0)
	'msgbox param

	'show warning dialog
	'added by JG 3Oct02
      ' modified by DP 10Oct02
	'modified by RS 14Oct02

 	'ss=mid(param, 4, 3)
      'If ss="../" then 
	'direct="../../Global Interface/warning.htm"
      'Else
	'direct="../Global Interface/warning.htm"
      'End If
      'w=window.showModalDialog(direct, "pass", "dialogWidth:340px; dialogHeight:250px")
	'window.focus()
	'	

	'get directory where came from
	'(added for MethodD)
' scrap this, since userdata doesn't work like we need it to
'	mydir = GetDir()

	winloc = window.location
	pos = instr(1, winloc, "file:///")
	if pos > 0 then
		winloc = mid(winloc, 9)
	end if
	pos = instrrev(winloc, "/")
	winloc = mid(winloc, 1, pos)
	'msgbox winloc & " - after trimming off file"

	if mid(param,1,1) <> "." then
		param = winloc & param
		param = replace(param, "\", "/")
		'msgbox param & " - after joining on path"
		
	else
		pos2 = instrrev(winloc, "/")
		winloc = mid(winloc, 1, pos2-1)
		while mid(param,1,1) = "."
			'msgbox "entered else"
			pos2 = instrrev(winloc, "/")
			winloc = mid(winloc, 1, pos2-1)
			'msgbox winloc & " - after trimming off end of path"
			param = mid(param,4)
			'msgbox param & " - after trimming off beg of path"
		wend
		'msgbox param & " - after trimming ../"
		param = winloc & "/" &  param
	      'msgbox param & " - after joining on path"
	end if
	'msgbox window.location
	'msgbox param
	set o = createObject("MethodaOpenObj70.Interface")
	'msgbox "created"

	'RS 14Oct02 
	param = Replace(param,"%20"," ")	

	call o.setFile(cstr(param))
	'msgbox "setFile"

	call o.setFileType(cstr(paramType))
	'msgbox "setParamType"

'	'added for MethodD
'	call o.setDirectory(cstr(mydir))
'	msgbox "mydir=" & mydir
	
	OpenWord  = o.CopyAndOpenWordFrag()
	if OpenWord = false then
			msgbox "Cannot open document fragment.",, "LLX Data Management System"
	end if
set o = nothing
end function


function DetectOfficeVersion()
	dim version
	dim cookieString
	dim pos1
	cookieString = document.cookie

	version=""
	pos0 = Instr(cookieString,"OfficeVersion")
	if pos0 <> 0 then
		pos1 = Instr(pos0, cookieString, "=")
		if pos1<>0 then
			pos2 = instr(pos1, cookieString, ";")
			if pos2 <> 0 then
			version = mid(cookieString, pos1+1, pos2-pos1-1)
			else
				version = mid(cookieString, pos1+1)
			end if
		end if
	end if
	do while instr(OfficeSupported, "'" & version & "'") = 0
		window.showModalDialog  "checkOffice.htm",,"dialogWidth:220px; dialogHeight:210px; center:yes"
		cookieString = document.cookie
		version=""
		pos0 = Instr(cookieString,"OfficeVersion")
		if pos0 <> 0 then
			pos1 = Instr(pos0, cookieString, "=")
			if pos1<>0 then
				pos2 = instr(pos1, cookieString, ";")
				if pos2 <> 0 then
					version = mid(cookieString, pos1+1, pos2-pos1-1)
				else
					version = mid(cookieString, pos1+1)
				end if
			end if
		end if
	loop

end function



function GetDir()
' created for MethodD
' requires the div udata on the page
	  	dim elem

		set elem = document.all.udata
		elem.load "MethodD_dir"

'		msgbox "Data = " & elem.getAttribute("Directory")
'		if not isnull(elem.getAttribute("Directory")) then		
'		end if

		GetDir = elem.getAttribute("Directory")
		set elem = Nothing

end function

function SeeLay(SourceTemplateFilename, DefTemplateFileName, FileType)
'function SeeLay(SourceTemplateFilename, DefTemplateFileName, FileType, PackingList)
 
   '
    ' If Professional Edition (has OCX) then show the Project Folder Dialog
    ' If not, show a "demo graphic" of the dialog
    '
		 
     ' 24-Nov-04
     ' Aliza
     ' We should check if the OCX is installed for this language
     'if OCXInstalled() then
     if OCXInstalledForSiteLanguage() then

	if ucase(FileType) = "FOLDER" then

		' set the source template filename
		'
		document.all.foldertemplate_sourcefilename.value = SourceTemplateFilename

		' set the file type
		'
		document.all.foldertemplate_filetype.value = FileType
	
 		' set the default template filename to save to
		'
		document.all.foldertemplate_filename.value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectFoldersDir()
		document.all.foldertemplate_dir.value = defdir

		' make dialog visible
		'
		call HideAllLays()
		document.all.tags("DIV")("project_folder_popup_foldertemplate").style.top = document.body.scrollTop + 10 
		document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="visible"
	
	elseif ucase(FileType) = "MPP" then
		' set the source template filename
		'
		document.all.sourcefilename_project.value = SourceTemplateFilename
	
		' set the file type
		'
		document.all.filetype_project.value = FileType

	 	' set the default template filename to save to
		'
		document.all.filename_project.value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectDir()
		document.all.dir_project.value = defdir

		' reset the default directory checkbox
		'
		document.all.checkbox_project.checked = False

		' make dialog visible
		'
		call HideAllLays()
		document.all.tags("DIV")("project_folder_popup_project").style.top = document.body.scrollTop + 10 
		document.all.tags("DIV")("project_folder_popup_project").style.visibility="visible"
	
	else
		' set the source template filename
		'
		document.all.sourcefilename.value = SourceTemplateFilename
	
		' set the file type
		'
		document.all.filetype.value = FileType

	 	' set the default template filename to save to
		'
		document.all.filename.value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectDir()
		document.all.dir.value = defdir

		' reset the default directory checkbox
		'
		document.all.checkbox.checked = False

		' make dialog visible
		'
		call HideAllLays()
		document.all.tags("DIV")("project_folder_popup").style.top = document.body.scrollTop + 10 
		document.all.tags("DIV")("project_folder_popup").style.visibility="visible"
	end if

	window.event.returnValue=false

    else

	' rivkah added to show popup instead of htm file
	document.all("choose_mode_popup").style.top = document.body.scrollTop + 10
	document.all("choose_mode_popup").style.visibility="visible"
	document.all("sourcefilename_mode").value = SourceTemplateFilename
	document.all("filetype_mode").value = FileType
	document.all("filename_mode").value = DefTemplateFilename
	document.all("dir_mode").value = defdir
'	document.all.tags("DIV")("project_folder_demo_popup").style.top = document.body.scrollTop + 10 
'	document.all.tags("DIV")("project_folder_demo_popup").style.visibility="visible"
	window.event.returnValue=false

    end if

end function


function SeeLay_ChangeProjectAnchor()
    '
    ' If Professional Edition (has OCX) then show the Project Folder Dialog
    ' If not, show a "demo graphic" of the dialog
    '

    if OCXInstalled() then


	' get the default project directory and set it in the dialog
	'
	defdir = GetDefaultProjectFoldersDir()
	document.all.foldertemplate_dir.value = defdir

	' make dialog visible
	'
	document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="visible"

	window.event.returnValue=false

    else
'	document.all.tags("DIV")("project_folder_demo_popup").style.visibility="visible"
	window.event.returnValue=false

    end if

end function

'------------------------------------------
'Author Yakov LLX
'12/02/04
'Description: Same functionality as function "SeeLay_ChangeProjectAnchor()"
'Opens Dialog Box 
'------------------------------------------
function SeeLay_ChangeDefaultFolder()
    '
    ' If Professional Edition (has OCX) then show the Project Folder Dialog
    ' If not, show a "demo graphic" of the dialog
    '

    if OCXInstalled() then

	' get the default project directory and set it in the dialog
	'
	defdir = GetDefaultProjectDir()
	document.all.folder_dir.value = defdir

	' make dialog visible
	'
	document.all.tags("DIV")("Default_Folder_Popup").style.visibility="visible"

	window.event.returnValue=false

    else
'	document.all.tags("DIV")("project_folder_demo_popup").style.visibility="visible"
	window.event.returnValue=false

    end if
end function


function HideLay()
		
	document.all.tags("DIV")("project_folder_popup").style.visibility="hidden"
	window.event.returnValue=false

end function

function HideLay_project()
		
	document.all.tags("DIV")("project_folder_popup_project").style.visibility="hidden"
	window.event.returnValue=false

end function

function HideLay_foldertemplate()
		
	document.all.tags("DIV")("project_folder_popup_foldertemplate").style.visibility="hidden"
	window.event.returnValue=false

end function

'------------------------------------------
'Author Yakov LLX
'12/02/04
'Description: Same functionality as function "HideLay_foldertemplate()"
'Opens Dialog Box 
'------------------------------------------
function HideLay_folder()
		
	document.all.tags("DIV")("Default_Folder_Popup").style.visibility="hidden"
	window.event.returnValue=false

end function


function HideAllLays()
'------------------------------------------
'Author Joe LLX
'20-Dec-04
'closes all 4 dialog boxes
'------------------------------------------
on error resume next
document.all("project_folder_popup").style.visibility="hidden"
document.all("project_folder_popup_foldertemplate").style.visibility="hidden"
document.all("project_folder_popup_project").style.visibility="hidden"
document.all("choose_mode_popup").style.visibility="hidden"
document.all("project_folder_demo_popup").style.visibility="hidden"
document.all("Reminder_popup").style.visibility = "hidden"
document.all("Reminder_popup1").style.visibility = "hidden"
document.all("Reminder_Folders").style.visibility = "hidden"
document.all("Reminder_Folders1").style.visibility = "hidden"



end function


function SeeLay_SGM(SourceTemplateFilename, DefTemplateFileName, FileType)

    '
    ' If Professional Edition (has OCX) then show the Project Folder Dialog
    ' If not, show a "demo graphic" of the dialog
    '


    ' 29-Dec-03
    ' Aliza
    ' List of templates is no longer in an "IFRAME"
    ' therefore all Dialogs are now in the document (MethodC_Index.htm),
    ' rather than the parent (SGM.htm)
    
    ' 24-Nov-04
    ' Aliza
    ' We should check if the OCX is installed for this language
    'if OCXInstalled() then
    if OCXInstalledForSiteLanguage then
	if ucase(FileType) = "FOLDER" then

		' set the source template filename
		'
		document.all("foldertemplate_sourcefilename").value = SourceTemplateFilename
		'parent.document.all("foldertemplate_sourcefilename").value = SourceTemplateFilename

		' set the file type
		'
		document.all("foldertemplate_filetype").value = FileType
		'parent.document.all("foldertemplate_filetype").value = FileType

	 	' set the default template filename to save to
		'
		document.all("foldertemplate_filename").value = DefTemplateFilename
		'parent.document.all("foldertemplate_filename").value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectFoldersDir()
		document.all("foldertemplate_dir").value = defdir
		'parent.document.all("foldertemplate_dir").value = defdir

<!--		' reset the default directory checkbox
		'
		document.all("checkbox").checked = False
		'parent.document.all("checkbox").checked = False
-->
		' make dialog visible
		'
		'parent.tags("DIV")("project_folder_popup").style.visibility="visible"
		'if (cInt(document.body.scrollTop) > 101) then 
			document.all("project_folder_popup_foldertemplate").style.top = document.body.scrollTop + 10 
		'else
		'	document.all("project_folder_popup_foldertemplate").style.top = 101
		'end if
		document.all("project_folder_popup_foldertemplate").style.visibility="visible"
		'parent.document.all("project_folder_popup_foldertemplate").style.visibility="visible"

	elseif ucase(FileType) = "MPP" then
	
	' set the source template filename
		'
		document.all("sourcefilename_project").value = SourceTemplateFilename
		'parent.document.all("sourcefilename").value = SourceTemplateFilename

		' set the file type
		'
		document.all("filetype_project").value = FileType
		'parent.document.all("filetype").value = FileType

	 	' set the default template filename to save to
		'
		document.all("filename_project").value = DefTemplateFilename
		'parent.document.all("filename").value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectDir()
		document.all("dir_project").value = defdir
		'parent.document.all("dir").value = defdir

		' reset the default directory checkbox
		'
		document.all("checkbox_project").checked = False
		'parent.document.all("checkbox").checked = False

		' make dialog visible
		'
		'parent.tags("DIV")("project_folder_popup").style.visibility="visible"

		document.all("project_folder_popup_project").style.top = document.body.scrollTop + 10

		document.all("project_folder_popup_project").style.visibility="visible"
		'parent.document.all("project_folder_popup").style.visibility="visible"
		
	else
		' set the source template filename
		'
		document.all("sourcefilename").value = SourceTemplateFilename
		'parent.document.all("sourcefilename").value = SourceTemplateFilename

		' set the file type
		'
		document.all("filetype").value = FileType
		'parent.document.all("filetype").value = FileType

	 	' set the default template filename to save to
		'
		document.all("filename").value = DefTemplateFilename
		'parent.document.all("filename").value = DefTemplateFilename

		' get the default project directory and set it in the dialog
		'
		defdir = GetDefaultProjectDir()
		document.all("dir").value = defdir
		'parent.document.all("dir").value = defdir

		' reset the default directory checkbox
		'
		document.all("checkbox").checked = False
		'parent.document.all("checkbox").checked = False

		' make dialog visible
		'
		'parent.tags("DIV")("project_folder_popup").style.visibility="visible"

		document.all("project_folder_popup").style.top = document.body.scrollTop + 10

		document.all("project_folder_popup").style.visibility="visible"
		'parent.document.all("project_folder_popup").style.visibility="visible"

	end if

	window.event.returnValue=false

    else
    
	'retVal = window.showModalDialog("ChooseVersionPopup.htm",,"dialogWidth:600px;dialogHeight:350px")
	'if ucase(retVal) = "YES" then
       	'	'window.showModalDialog "downloadPopup.htm",,"dialogWidth:600px;dialogHeight:350px"
	'end if

	' rivkah added to show popup instead of htm file
	document.all("choose_mode_popup").style.top = document.body.scrollTop + 10
	document.all("choose_mode_popup").style.visibility="visible"
	document.all("sourcefilename_mode").value = SourceTemplateFilename
	document.all("filetype_mode").value = FileType
	document.all("filename_mode").value = DefTemplateFilename
	document.all("dir_mode").value = defdir
	
'	document.all("project_folder_demo_popup").style.top = document.body.scrollTop + 10 
'	document.all("project_folder_demo_popup").style.visibility="visible"
	'parent.document.all("project_folder_demo_popup").style.visibility="visible"
	window.event.returnValue=false

    end if


end function


function OCXInstalled() 

	on error resume next
	set o = createObject("MethodaOpenObj70.Interface")
	if err.number <> 0 then
		OCXInstalled = false
	else
		OCXInstalled = true
	end if

end function


function OCXInstalledForSiteLanguage() 

	on error resume next
	set o = createObject("MethodaOpenObj70.Interface")
	if err.number <> 0 then
		OCXInstalledForSiteLanguage = false
	elseif UCase(o.IsLanguageInstalled(SiteLanguage)) = "TRUE" then
		
		OCXInstalledForSiteLanguage = true
	else
		OCXInstalledForSiteLanguage = false
	end if

end function

function SetAppDirectory(appname,numdirectoriesup)

	dim o
	dim newdir
	dim winloc
	dim success


	if OCXInstalled() then
		winloc = window.location
		
		for i = 0 to numdirectoriesup
			winloc = mid(winloc,1,instrrev(winloc,"/",-1)-1)
		next
		winloc = replace(winloc, "%20", " ")
		
		set o = createObject("MethodaOpenObj70.Interface")
		success = o.SetAppDir(appname, winloc)
		set o = nothing
	end if

end function

function ChangeMode(mode)

select case (mode)
	case "Professional":
		document.all("choose_mode_popup").style.visibility="hidden"
		window.showModalDialog "../../../Global_Interface/downloadPopup.htm",,"dialogWidth:600px;dialogHeight:350px"

		SourceTemplateFilename = document.all("sourcefilename_mode").value 
		FileType = document.all("filetype_mode").value 
		DefTemplateFilename = document.all("filename_mode").value 
		defdir = document.all("dir_mode").value 
		
		call SeeLay(SourceTemplateFilename, DefTemplateFileName, FileType)

	case "Knowledge":
		document.all("choose_mode_popup").style.visibility="hidden"

	case else:
		document.all("choose_mode_popup").style.visibility="hidden"

end select

end function

function ChangeMode_SGM(mode)

select case (mode)
	case "Professional":
		document.all("choose_mode_popup").style.visibility="hidden"
		window.showModalDialog "downloadPopup.htm",,"dialogWidth:600px;dialogHeight:350px"

		SourceTemplateFilename = document.all("sourcefilename_mode").value 
		FileType = document.all("filetype_mode").value 
		DefTemplateFilename = document.all("filename_mode").value 
		defdir = document.all("dir_mode").value 
		
		call SeeLay_SGM(SourceTemplateFilename, DefTemplateFileName, FileType)

	case "Knowledge":
		document.all("choose_mode_popup").style.visibility="hidden"

	case else:
		document.all("choose_mode_popup").style.visibility="hidden"

end select

end function

function ChangeMode_Topics()
	document.all("choose_mode_popup").style.visibility="hidden"
	window.showModalDialog "../downloadPopup.htm",,"dialogWidth:600px;dialogHeight:350px"
end function

function ChangeMode_Remind(sDialog)
	sDialog.style.visibility="hidden"
	window.showModalDialog "../../../Global_Interface/downloadPopup.htm",,"dialogWidth:600px;dialogHeight:350px"
end function


Function getCookie(cookieName)

	dim value
	dim cookieString
	dim pos1
	cookieString = document.cookie

	value=""
	pos0 = Instr(cookieString,cookieName)
	if pos0 <> 0 then
		pos1 = Instr(pos0, cookieString, "=")
		if pos1<>0 then
			pos2 = instr(pos1, cookieString, ";")
			if pos2 <> 0 then
				value= mid(cookieString, pos1+1, pos2-pos1-1)
			else
				value= mid(cookieString, pos1+1)
			end if
		end if
	end if
	getCookie = value
	
End Function


Function setCookie(NameOfCookie, value)
'	Cookies must have numeral values

	thisCookie = NameOfCookie & "=" & escape(value)
	
	mExp = ";expires= " & DayOfWeek(Weekday("12/12/" & Year(DateAdd("yyyy", 2, Date( ) ) ) ) ) & "12/12/" & Year(DateAdd("yyyy", 2, Date( ) ) ) & " 23:59:59 GMT;path=/"

	thisCookie = thisCookie & mExp
	document.cookie = thisCookie
	
End Function

Function GetFileName( Path )

	rValue = Path
	if InStrRev(Path, "/") > 0 then rValue = mid(Path, InStrRev(Path,"/")+1)
	
	GetFileName = rValue
	
End Function

function DayOfWeek(day)

	Select Case day
		Case 1	  DayOfWeek = "Sun"
		Case 2	  DayOfWeek = "Mon"
		Case 3	  DayOfWeek = "Tue"
		Case 4	  DayOfWeek = "Wed"
		Case 5	  DayOfWeek = "Thu"
		Case 6	  DayOfWeek = "Fri"
		Case 7	  DayOfWeek = "Sat"
		Case null DayOfWeek = null
		Case else DayOfWeek = day
	End Select

End Function

' 24-Nov-04
' Aliza
' This function was moved from H_Topics/InstallMDM.htm
Function InstOCX()
      ' 24-Nov-04
      ' Aliza
      ' We should check if the OCX is installed for this language
      'if OCXInstalled() then
       if OCXInstalledForSiteLanguage then
		dlgExist.style.visibility = "visible"
	else
		choose_mode_popup.style.visibility = "visible"
	end if
End Function