var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';
 

function ModalDialogMaintainFocus()
{
  try
  {
    if (ModalDialogWindow.closed)
     {
        window.clearInterval(ModalDialogInterval);
        eval(ModalDialog.eventhandler);       
        return;
     }
    ModalDialogWindow.focus(); 
  }
  catch (everything) {   }
}
        
 function ModalDialogRemoveWatch()
 {
    ModalDialog.value = '';
    ModalDialog.eventhandler = '';
 }
        
 function ModalDialogShow(Title,Buttons,EventHandler)
 {
   ModalDialogRemoveWatch();
   ModalDialog.eventhandler = EventHandler;

   var args='width=310,height=500,left=325,top=300,toolbar=0,';
       args+='location=0,status=0,menubar=0,scrollbars=1,resizable=1';  

   ModalDialogWindow=window.open("","",args); 
   ModalDialogWindow.document.open(); 
   ModalDialogWindow.document.write('<html>\n');
   ModalDialogWindow.document.write('<head>\n'); 
   ModalDialogWindow.document.write('<title>' + Title + '</title>\n');
   ModalDialogWindow.document.write('<script' + ' language=JavaScript>\n');
   ModalDialogWindow.document.write('function CloseForm(Response) \n');
   ModalDialogWindow.document.write('{ \n');
   ModalDialogWindow.document.write(' window.opener.ModalDialog.value = Response; \n');
   ModalDialogWindow.document.write(' window.close(); \n');
   ModalDialogWindow.document.write('} \n');
   ModalDialogWindow.document.write('</script' + '>\n');        


   ModalDialogWindow.document.write('<link href="css/msdsAdmin.css" rel="stylesheet" type="text/css">\n');        
   ModalDialogWindow.document.write('<link href="css/msdsnav.css" rel="stylesheet" type="text/css">\n');        
   ModalDialogWindow.document.write('<link href="css/msds_extantion.css" rel="stylesheet" type="text/css">\n');        
   ModalDialogWindow.document.write('<link href="css/default_extantion.css" rel="stylesheet" type="text/css">\n');        
   
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/tabs.js"></script>\n');        
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/mm.js"></script>\n');        
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/msds.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/tabs.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/unload.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/unload_new.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/fileOpenDialog.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/expandCollapse.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/appRoutines.js"></script>\n');
//   ModalDialogWindow.document.write('<script type="text/javascript" src="js/prototype.js"></script>\n');

   ModalDialogWindow.document.write('</head>\n');   
   ModalDialogWindow.document.write('<body onblur="window.focus();">\n');
   
   ModalDialogWindow.document.write('<div id="wrapper_select_image"><div id="header"><div id="content">\n');
   ModalDialogWindow.document.write('<table width="100%" cellpadding="0" cellspacing="0" class="requests_table">\n');
   ModalDialogWindow.document.write('<tr valign="top" ><td colspan="2" class="titlerow">Select the image</td></tr>\n');
   ModalDialogWindow.document.write('<tr bgcolor="#DBEFD6"><td height="20" nowrap bgcolor="#DBEFD6" class="label"><div align="center">Image</div></td><td nowrap bgcolor="#DBEFD6" class="label"><div align="left">Image File Name</div></td></tr>\n');
   
   ModalDialogWindow.document.write(Buttons);

   ModalDialogWindow.document.write('</table></div></div></div>\n');
   
   ModalDialogWindow.document.write('</body>\n');
   ModalDialogWindow.document.write('</html>\n'); 
   ModalDialogWindow.document.close(); 
   ModalDialogWindow.focus(); 
   ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5);

 }

  function SelectFileName(EventHandler, imageUrl)
  {
 	var	fileNamesCount = $('fileNameDTOsCount').value;
 	var	fileNamePrefix = 'fileName';
	
    var Buttons=''; 

	for( i=0; i<fileNamesCount; i++ )
	{
		fileName = $('fileName' + i).value;

		Buttons += '<tr onmouseover="style.background = \'#eeeeee\'"	onmouseout="style.background = \'transparent\'">\n';
//		Buttons += '<tr>\n';
        Buttons += '<td width="50" align="center" valign="middle"><img src="'+ imageUrl + fileName +'" width="50"></td>\n';
        Buttons += '<td align="left" valign="middle"><div class="label" ><a href=javascript:CloseForm("'+ fileName +'");>'+fileName+'</a></div></td>\n';
        Buttons += '</tr>\n';     
	}

    ModalDialogShow("MSDS - Select File Name",Buttons,EventHandler);
  }
 
 function SelectFileNameReturnMethod(path)
{
	var newFileName = ModalDialog.value;
	reString = /\w+/;

	if( newFileName!=null && reString.test(newFileName) ){
	    $('nmFileName').value = newFileName;
	    $('messageDataModified').show();
		$('isDataChanged').value = 1;
		$('iconSelected').src = path+newFileName;
	}
	
    ModalDialogRemoveWatch();
}


