function browseForSave(filemess, filter,defaultname) {
if(!filemess)filemess = "Select the directory containing your context document";
if(typeof filter=="undefined")filter =  "Context Files (*.cml)|*.cml|XML Files(*.xml)|*.xml|All Files (*.*)|*.*";
var fileName;
if(!defaultname)defaultname = "MyMap";
try {
var ftype  = "HTM File";
var ending = ".htm";
if(filter.indexOf("kml")!=-1){ ftype = "KML Google Earth File"; ending = ".kml"; }
if(filter.indexOf("cml")!=-1){ ftype = "CML Context File"; ending=".cml"; }
if(filter.indexOf("js")!=-1) { ftype = "JSON Data File"; ending=".js"; }
var objDialog = new ActiveXObject("SAFRCFileDlg.FileSave");
objDialog.FileName = defaultname +ending;
objDialog.FileType = ftype;
var ret = objDialog.OpenFileSaveDlg();
fileName = objDialog.FileName;
var dot = fileName.lastIndexOf(".");
if(dot && dot != -1){
	fileName = fileName.substring(0,dot);
	}
}
catch (err) {
try {
var objDialog = new ActiveXObject("UserAccounts.CommonDialog");
objDialog.DialogTitle = filemess;
objDialog.Filter = filter;
objDialog.Flags = "&H80004";
objDialog.ShowOpen();
fileName = objDialog.FileName;
}
catch(err){
//must not be windows Xp
try { 
	var ComDlg = new ActiveXObject("MSComDlg.CommonDialog");
	ComDlg.DialogTitle = "SaveAs";
	ComDlg.Filter = filter;
	ComDlg.FilterIndex = 1;
	ComDlg.Flags = 0x200 | 0x1000 | 0x80000;
	ComDlg.MaxFileSize = 512;
	ComDlg.ShowOpen();
	fileName = ComDlg.fileName;
	}
	catch (newerr){
 		errnum = newerr.number & 0xFFFF; 
 		//user has pressed Cancel 
		if(errnum==32755)
			return "";
	
		var fpath = GetPath(filemess);
		fileName = prompt("What is the file's name",defaultname);
		fileName = fpath +"\\"+fileName;
		}
	}
}
return fileName;
}

function browseForFile(filemess, filter) {
if(!filemess)filemess = "Select the directory containing your context document";
if(!filter)filter =  "Context Files (*.cml)|*.cml|XML Files(*.xml)|*.xml|All Files (*.*)|*.*";
var fileName;
try {
var objDialog = new ActiveXObject("UserAccounts.CommonDialog");
objDialog.Filter = filter;
objDialog.Flags = "&H80004";
objDialog.ShowOpen();
fileName = objDialog.FileName;
}
catch(err){
	
//must not be windows Xp
try { 
	var ComDlg = new ActiveXObject("MSComDlg.CommonDialog");
	ComDlg.Filter = "Context Files (*.cml)|*.cml|XML Files(*.xml)|*.xml|All Files (*.*)|*.*";
	ComDlg.FilterIndex = 1;
	ComDlg.Flags = 0x200 | 0x1000 | 0x80000;
	ComDlg.MaxFileSize = 512;
	ComDlg.ShowOpen();
	fileName = ComDlg.fileName;
	}
catch (newerr){
	errnum = newerr.number & 0xFFFF; 
	//user has pressed Cancel 
	if(errnum==32755)
		return "";
	
	var fpath = GetPath(filemess);
	fileName = prompt("What is the file's name","context.cml");
	fileName = fpath +"\\"+fileName;
	}
}
return fileName;
}

