Saturday, January 24, 2009

Java : Simple Program to Create zip file.

It can be used to zip both a file or a Directory. Directory is ziped along with its subdirectory structure. Just Provide the proper source and run the code.


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class CreateZip {
   
    //function to zip a single file
    //Parameters List :
    //zipSrc : source file which to be ziped
    //zipName : Give desire name to zip file
    //destination folder where to create zip file
    public void zipFile(File zipSrc,String zipName,String destFolder) {
       
        System.out.println("zipFile :: "+zipSrc.getPath()+" "+zipName+" "+destFolder);
       
        try {           
                   
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destFolder+File.separator+zipName));
                   
            FileInputStream fis = new FileInputStream(zipSrc);
           
            ZipEntry zipEntry = new ZipEntry(zipSrc.getName());
           
            zos.putNextEntry(zipEntry);
           
            int bytes = 0;
            byte[] buffer = new byte[2156];
           
            bytes = fis.read(buffer);
           
            while (bytes != -1) {
                zos.write(buffer, 0, bytes);
                bytes = fis.read(buffer);
            }
           
            fis.close();
            zos.flush();
            zos.close();
           
        } catch (Exception e) {
           
            System.out.println("Exception :: "+e);
           
        }
    }
   
    //function to zip a folder containing multiple files
    //Parameters List :
    //zipSrc : source folder which to be ziped
    //zipName : Give desire name to zip file
    //destination folder where to create zip file
    public void zipDirectory(File zipSrc,String zipName,String destFolder) {
       
        System.out.println("zipDirectory :: "+zipSrc.getPath()+" "+zipName+" "+destFolder);
       
        try {
           
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destFolder+File.separator+zipName));
           
            zipDirectoryUtil(zipSrc.getPath(),zos,"");
            zos.close();       
        }
        catch (Exception e) {
           
            e.printStackTrace();
        }
       
    }
   
    public void zipDirectoryUtil(String directory,ZipOutputStream zos,String path) {
       
        try {
           
            File zipDir = new File(directory);
           
            String[] allFiles = zipDir.list();
           
            int bytes = 0;
            byte[] buffer = new byte[2156];
           
            for (String eachFile : allFiles) {
               
                File file = new File(zipDir,eachFile);
               
                if(file.isDirectory()) {
                   
                    zipDirectoryUtil(file.getPath(),zos,path+file.getName()+File.separator);
                    continue;
                }
               
            FileInputStream fis = new FileInputStream(file);
           
            ZipEntry zipEntry = new ZipEntry(path+file.getName());
           
            zos.putNextEntry(zipEntry);
           
            bytes = fis.read(buffer);
           
            while (bytes != -1) {
                zos.write(buffer, 0, bytes);
                bytes = fis.read(buffer);
            }
            fis.close();
           
            }
        }
        catch (Exception e) {
           
            e.printStackTrace();
        }
    }
   
    public static void main(String[] args) {
       
        CreateZip obj = new CreateZip();
       
        obj.zipFile(new File("C:\\MY\\Code\\Photo.jpg"),"img.zip","D:\\Test\\data");
       
        obj.zipDirectory(new File("C:\\MY\\Code\\com"),"com.zip","D:\\Test\\data");

    }

}

Java : Simple Program for Unzipping a File

Just provide a zip file which to be unziped and run the code.


import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Unziping {
  
    //Function to unzip a file, provide source zip file and destination directory where to unzip a file
    public void unzip(File zipFile,String destFolder) {
      
        System.out.println("Unzip :: "+zipFile.getPath()+" into "+destFolder);
      
        try {
            ZipFile zip = new ZipFile(zipFile);
          
            File dest = new File(destFolder);
          
            Enumeration files = zip.entries();
          
            File file;
            FileOutputStream fos;
          
            int bytes = 0;
            byte[] buffer = new byte[2156];
          
            while (files.hasMoreElements()) {
              
                ZipEntry entry = (ZipEntry)files.nextElement();
              
                InputStream eis = zip.getInputStream(entry);
                file = new File(dest.getAbsolutePath() + File.separator + entry.getName());
              
                if (entry.isDirectory()) {
                    file.mkdirs();
                    continue;
                }
                else {
                    file.getParentFile().mkdirs();
                    file.createNewFile();
                }
              
                fos = new FileOutputStream(file);
              
                while ((bytes = eis.read(buffer)) != -1) {
                    fos.write(buffer, 0, bytes);
                  }
              
                fos.close();              
            }          
          
        } catch (Exception e) {
          
            e.printStackTrace();
        }
    }
  
    public static void main(String[] args) {
      
        Unziping obj = new Unziping();
      
        obj.unzip(new File("C:\\MY\\Code\\com.zip"),"C:\\MY\\Code");
    }

}

JSP : Simple File Uploading Codes.

We will see how to upload a file using JSP, you can upload a file to your desire location with desire name. Please see the simple self explanatory codes below.

Please add below mentioned jar files in your applications classpath.





1st HTML interface (can be used in JSP as well)

FileUploadingInterface.HTML


<HTML>
<HEAD>
<TITLE>File Uploading Interface</TITLE>
</HEAD>
<BODY>
<center>
<h3>Simple File Uploading Example</h3>
<form action="ProcessUploadedFile.jsp" method="post" enctype="multipart/form-data">
Name <input type="text" name="userName"> (optional) </br></br>
File <input type="file" name="file1"> </br></br> <!-- Here You Can Add more numbers of Files For Uploading -->
<input type="submit" value="Submit">
</form>
</center>
</BODY>
</HTML>



2nd JSP code


ProcessUploadedFile.jsp


<%@ page import="java.io.*" %>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (!isMultipart)
{
}
else
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try
{
items = upload.parseRequest(request);
}
catch (FileUploadException e)
{
e.printStackTrace();
}

Iterator itr = items.iterator();

while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();

//Get Other Form Fileds Values in this Block
if (item.isFormField())
{
String itemName = item.getFieldName();
String itemValue = item.getString();
String name = "";
if (itemName.equals("userName"))
name = item.getString();

out.println("User Name "+name);
}
//Get File type Values Here, it could be one or multiple File
else
{
try
{
String itemName = item.getName();

//userFieldName is what u provided in html file
String userFieldName = item.getFieldName();

if(itemName != null)
{
if(itemName.equals(""))
{
//If Nothing Uploaded
out.println("No File Uploaded");
}
else
{
//Provide Destination Folder, Where Uploaded File to be saved
boolean folderMade = (new File("d:/UploadedFileFolder")).mkdirs();

// This is required to filter out file name from complete file path.
int idx = itemName.lastIndexOf("\\");

String filename = "";

if(idx > -1)
{
//in case of IE, it sends complete path. Hence only file name must be filtered out.
idx=idx+1;
filename = itemName.substring(idx);
}
else
{
//in case of other borwsers, its just filename
filename = itemName;
}

File savedFile = new File("d:/UploadedFileFolder/"+filename);
item.write(savedFile);

//Get path of the saved file
String path = savedFile.getPath();

out.println("File Uploaded Sucessfully "+path);

}
}
}//try
catch(Exception e)
{
e.printStackTrace();
}
}//else
}//while
}//else
%>

Java : Simple program to copy Directory (subdirectories and files) from specified source to specified destination.

Here is the code of the program :




import java.io.*;
import java.text.SimpleDateFormat;

public class DirectoryCopier
{
public static void main(String[] args) throws IOException
{
//Creating instance of DirectoryCopier
DirectoryCopier cd = new DirectoryCopier();

//Specifying Source Directory
String source = "D:\\Blog";

//Creating File of source directory
File src = new File(source);

//Specifying Destination Directory
String destination = "C:\\copyOfBlog";

File dst = new File(destination);

//Calling method DirectoryCopier with source and destination
cd.DirectoryCopier(src, dst);
}

public void DirectoryCopier(File srcPath, File dstPath) throws IOException
{
//If Source is a Directory
if (srcPath.isDirectory())
{
System.out.println(srcPath + "is directory.");

//If Destination directory not exists, create it
if (!dstPath.exists())
{
System.out.println("calling mkdir " + dstPath);
dstPath.mkdir();
}

//Get All Available Files in this source directory
String files[] = srcPath.list();

//Iterate each file
for(int i = 0; i < files.length; i++)
{
System.out.println("--Source "+srcPath);
System.out.println("--Destination "+dstPath);

//Recursively calling DirectoryCopier
DirectoryCopier(new File(srcPath, files[i]),new File(dstPath, files[i]));
}
}
//If Source is a leaf node
else
{
//If Source does not exists print it and exit
if(!srcPath.exists())
{
System.out.println("File or directory does not exist.");
System.exit(0);
}
else
{
System.out.println("Source "+srcPath);
System.out.println("Destination "+dstPath);

//Copying by bytes
FileInputStream in = new FileInputStream(srcPath);
FileOutputStream out = new FileOutputStream(dstPath);

// Transfer bytes from in to out
byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}

in.close();
out.close();
}

}
System.out.println("Directory copied.");
}
}

Java: Simple Program To Read Excel File

There are two simple methods, Below both programs produces same output

1st Method : Using POI (Note : Download POI to run this code)


import java.io.*;
import java.util.*;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;

public class ExcelReadIterator
{
public static void main(String[] args) throws Exception
{
InputStream ExcelFileToRead = new FileInputStream("ExcelFile.xls");
HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);

HSSFSheet sheet=wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;

Iterator rows=sheet.rowIterator();

while (rows.hasNext())
{
row=rows.next();
Iterator cells=row.cellIterator();
while (cells.hasNext())
{
cell=cells.next();

if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING)
{
System.out.print(cell.getStringCellValue()+" ");
}
else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
{
System.out.print(cell.getNumericCellValue()+" ");
}
else
{
//U Can Handel Boolean, Formula, Errors
}
}
System.out.println();
}

}
}




2nd Method : Using Virtual DB (This is simple method, directly u can run this code)



import java.sql.*;

public class ReadExcel
{
public static void main (String[] args)
{
String ExcelFileToRead = "ExcelFile.xls";

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+ExcelFileToRead);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("Select * from [Sheet1$]");


while(rset.next())
{
System.out.println(rset.getString(1)+" "+rset.getString(2)+" "+rset.getString(3)) ;
}



}
catch(Exception ex)
{
ex.printStackTrace();
}
}


}

Friday, January 23, 2009

Java IO: Simple Java Program To Read Text File

Here is the simple code to read text file.You need to import java.io package...
Just used File, FileReader & BufferedReader. Simply copy paste the below code and provide txt file path to read.



import java.io.*;

public class ReadTextFile
{
public static void main(String[] args)
{
//Prove Text File to Read
String TextFileToRead = "TextFile.txt";

try
{
File file=new File(TextFileToRead);
FileReader fr =new FileReader(file);
BufferedReader br = new BufferedReader(fr);

String iterateEachLine = "";

while((iterateEachLine=br.readLine())!=null)
{
System.out.println(iterateEachLine);
}
br.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}

}
}

Java: Iterate ArrayList, Hashtable, TreeSet, LinkedHashMap

In the Java Code u can get All types of iterate all in one program. You can Iterate ArrayList, Hashtable, TreeSet, LinkedHashMap

ArrayList is an ordered Collection by Index

HashTable is Unorderd and Unsorted

TreeSet is a Sorted Collection in natural order

LinkedHashMap is Sorted Collection in insertion order




import java.util.*;

public class Iterators
{
public static void main(String[] args)
{
//Initilize ArrayList
ArrayList<String> arrayList = new ArrayList<String>();

//Initilize HashTable
Hashtable<String,Integer> hashTable = new Hashtable<String,Integer>();

//Initilize TreeSet
TreeSet<Integer> treeSet = new TreeSet<Integer>();

//Iterate LinkedHashMap
LinkedHashMap<Integer,String> linkedHashMap = new LinkedHashMap<Integer,String>();

//putting Values
for(int i=1;i<=10;i++)
{
arrayList.add("val"+i);
hashTable.put("keyHT"+i,i);
treeSet.add(i);
linkedHashMap.put(i,"keyLHM"+i);
}

//Iterating ArrayList
//ArrayList is an ordered Collection by Index
for(int i=0;i<arrayList.size();i++)
{
System.out.println(arrayList.get(i));
}

//Iterating HashTable
//HashTable is Unorderd and Unsorted
Enumeration<String> enu1 = hashTable.keys();
while(enu1.hasMoreElements())
{
String key=enu1.nextElement();
System.out.println(key+" "+hashTable.get(key));
}

//Iterating TreeSet
//TreeSet is a Sorted Collection in natural order
Iterator<Integer> itr1 = treeSet.iterator();
while(itr1.hasNext())
{
System.out.println(itr1.next());
}

//Iterating LinkedHashMap Key-Value pair
//LinkedHashMap is Sorted Collection in insertion order
Set<Integer> lSet= linkedHashMap.keySet();
Iterator<Integer> itr2 = lSet.iterator();
while(itr2.hasNext())
{
Integer key = itr2.next();
System.out.println(key+" "+linkedHashMap.get(key));
}

//Other Method to Iterate LinkedHashMap (Only Values)
Collection<String> col = linkedHashMap.values();
Iterator<String> itr3 = col.iterator();//obtain an Iterator for Collection
while(itr3.hasNext())//iterate through LinkedHashMap values iterator
{
System.out.println(itr3.next());
}

}
}

JavaScript : Get date in format (dd/mm/yyyy). Get today's date, tomorrow's date, yesterday's date, first and last date of week & Month

Here in this code u can get Date in format dd/mm/yyyy, Aslo u can customize its default view accordingly. Get today's date, tomorrow's date, yesterday's date, Also u can get first and last date of current week and first and last date of current month.


<HTML>
<HEAD>
<TITLE>Java Script Date Example</TITLE>
<script type="text/javascript">
function showDate()
{
var type = document.myForm.type.value;//get request type

var today = new Date();//get today's date

var yesterday = new Date();;
yesterday.setDate(today.getDate() - 1);//get yesterday's date

var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);//get tomorrow's date

//get first and last day of week
var day = today.getDay();//returns 0-6 accordingly
var fistDayOfWeek;
var lastDayOfWeek;

//assumeing monday is first day and sunday is last day
switch (day)
{
case 0:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() + 7);
lastDayOfWeek = new Date();
//lastDayOfWeek.setDate(today.getDate() + 0);
break;
case 1:
fistDayOfWeek = new Date();
//fistDayOfWeek.setDate(today.getDate() - 0);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 6);
break;
case 2:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 1);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 5);
break;
case 3:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 2);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 4);
break;
case 4:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 3);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 3);
break;
case 5:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 4);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 2);
break;
case 6:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 5);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 1);
break;
}

//get first and last day of month
var month = today.getMonth();
var year = today.getYear();

var fdtm = new Date(year, month, 1);//first day of month

var ldtm = new Date(year, month + 1, 0);//last day of month

//Show Result depending upon type
if(type == 'today')
{
document.getElementById("displayResult").innerHTML = "Today's Date : "+today.defaultView();
}
else if(type == 'yesterday')
{
document.getElementById("displayResult").innerHTML = "Yesterday's Date : "+yesterday.defaultView();

}
else if(type == 'tomorrow')
{
document.getElementById("displayResult").innerHTML = "Tomorrow's Date : "+tomorrow.defaultView();
}
else if(type == 'week')
{
document.getElementById("displayResult").innerHTML = "Ist Day of Week : "+fistDayOfWeek.defaultView()+" Last Day of week : "+lastDayOfWeek.defaultView();
}
else if(type == 'month')
{
document.getElementById("displayResult").innerHTML = "Ist Day of Month : "+fdtm.defaultView()+" Last Day of Month : "+ldtm.defaultView();
}
}

//customize function used for default view
Date.prototype.defaultView=function()
{
var dd=this.getDate();
if(dd<10)dd='0'+dd;
var mm=this.getMonth()+1;
if(mm<10)mm='0'+mm;
var yyyy=this.getFullYear();

var y = yyyy % 100;
y += (y < 38) ? 2000 : 1900;
//return y;


//alert(y);
return String(dd+"\/"+mm+"\/"+y)
}
</script>
</HEAD>
<BODY>
<CENTER>
<h3>Simple Java Script Date Example</h3>
<form action="#" name="myForm">
Select
<select name="type" onchange="showDate()">
<option value="today">today</option>
<option value="yesterday">yesterday</option>
<option value="tomorrow">tomorrow</option>
<option value="week">this week</option>
<option value="month">this month</option>
</select>
</br></br>
<div id="displayResult">
</div>
</form>
</CENTER>
</BODY>
</HTML>

JavaScript : Validate Run Time Generated checkbox.

Assume in this Example Checkbox generated at run time by JSP,Servlet,ASP etc.
And Before Submiting Form U wan't to assure user selected atleast 1 checkBox
If there is one or more checkbox generated at run time Use this example. Here if there is 1 checkbox its length comes 'undefined', in the below code it is 'undefined' is handled.




<HTML>
<HEAD>
<TITLE>Validate run Time CheckBox</TITLE>
</HEAD>
<script type="text/javascript">
function validate()
{
var len = document.myForm.number.length;
var count = 0;

//len is undefined when there is 1 checkbox
if(len != undefined)
{
//for greater than 1 checkbox
for (i = 0; i < len; i ++)
{
if (document.myForm.number[i].checked)
count++;
}
}
else
{
//for only 1 checkbox
if (document.myForm.number.checked)
count++;
}

if(count == 0)
{
alert("Atleast Select One Check Box");
return false;
}
else
{
alert("Selected "+count);
return true;
}
return false;
}
</script>
<BODY>
<CENTER>
<h3>Run-Time Created Checkbox Validate Example</h3>

<!--
Assume in this Example Checkbox generated at run time by JSP,Servlet,ASP etc.
And Before Submiting Form U wan't to assure user selected atleast 1 checkBox
If there is one or more checkbox generated at run time Use this example
-->

<form action="#" name="myForm" method="post" onsubmit="return validate()">
<TABLE border="1" width="40%">
<tr>
<td>One</td>
<td><input type="checkbox" name="number" value="one"></td>
</tr>
<tr>
<td>Two</td>
<td><input type="checkbox" name="number"value="two"></td>
</tr>
<tr>
<td>Three</td>
<td><input type="checkbox" name="number" value="three"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit">
</td>
</tr>
</TABLE>
</form>
</CENTER>
</BODY>
</HTML>

JavaScript : Pop-up Div with Background disabled

This HTML codes shows a simple pop-up Div, with background disabled. It can also customize according to user needs. It can also be used as simple pop-up window with background disabled.



<HTML>
<HEAD>
<TITLE>PopUp Div + Background Disable</TITLE>
<style>
.parentDisable
{
z-index:999;
width:100%;
height:100%;
display:none;
position:absolute;
top:0;
left:0;
background-color: #ccc;
color: #aaa;
opacity: .4;
filter: alpha(opacity=50);
}
#popup
{
width:300;
height:200;
position:absolute;
top:200px;
left:300px;
color: #000;
background-color: #fff;
}
</style>
<script type="text/javascript">
function pop(div)
{
document.getElementById(div).style.display='block';
return false
}
function hide(div)
{
document.getElementById(div).style.display='none';
return false
}
</script>
</HEAD>
<BODY>
<div id="pop1" class="parentDisable">
<table border="1" id="popup">
<tr><td>This is popup 1</td></tr>
<tr><td><a href="#" onClick="return hide('pop1')">Close</a></td></tr>
</table>
</div>
<div id="pop2" class="parentDisable">
<table border="1" id="popup">
<tr><td>This is popup 2</td></tr>
<tr><td><a href="#" onClick="return hide('pop2')">Close</a></td></tr>
</table>
</div>
<CENTER>
<h3>Simple Popup Div + Background Disable Example</h3>
</br></br>
<a href="#" onClick="return pop('pop1')">Popup 1</a>
</br></br>
<a href="#" onClick="return pop('pop2')">Popup 2</a>

</CENTER>
</BODY>
</HTML>

Thursday, January 22, 2009

JavaScript : Resizeable Popup Window.

this Html code can be used to show popup window. It resize atomatically with the given data.
But it is browser dependent, works well with mozilla, IE 6,7.




<HTML>
<HEAD>
<TITLE>Resizeable Popup Window</TITLE>
<script type="text/javascript">

PositionX = 200;
PositionY = 100;

defaultWidth = 500;
defaultHeight = 400;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = false;


if (parseInt(navigator.appVersion.charAt(0))>=4)
{
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle)
{
if (isNN)
{
imgWin=window.open('about:blank','',optNN);
}
if (isIE)
{
imgWin=window.open('about:blank','',optIE);
}
with (imgWin.document)
{
writeln('<html><head><title>'+imageTitle+'</title><style>body{margin:0px;}</style>');
writeln('<sc'+'ript>');
writeln('var isNN,isIE;');
writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');
writeln('if (isIE){');
writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');
writeln('if (isNN){');
writeln('window.innerWidth=document.images["Madan"].width;');
writeln('window.innerHeight=document.images["Madan"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');
writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor="#FFFFFF" scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor="#FFFFFF" scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Madan" src='+imageURL+' style="display:block"></body></html>');
close();
}
}
</script>
</HEAD>

<BODY>
<CENTER>
<h3>Simple Resizeable Popup Window Example</h3>
</br></br>
<a href="javascript:popImage('image1.gif','image1')">image1</a>
</br></br>
<a href="javascript:popImage('image2.gif','image2')">image2</a>
</CENTER>
</BODY>
</HTML>