// Script to open a popup window with four parameters

var PicWin;
var newPicHeight;
var truePicHeight;
var _caption;
function picture(picname,picheight,picwidth,pictitle) {
	if(PicWin && !PicWin.closed) { PicWin.close();}
	
var addedHeight = 25;   // estimated extra height required for one line	of text
var charMultiple = 6;	// estimated pixels per word

var charReq = charMultiple * pictitle.length;
var linesReq = Math.round((charReq / picwidth) + .4);
if (linesReq > 1)
{addedHeight -=1 ; 
addedHeight += ((linesReq-1)*16);	// final fig is estimated extra window height for all text
}

if (pictitle !=""){
var allWords = pictitle.split(" ");
var wordCount = (allWords.length);
var wordsPerLine = Math.round(wordCount/linesReq);

var eachLine = new Array();
var thisLine = ""; var incrementedVal=0; var totalWords = 0;
var newTitle = ""; var thisLoop;

for (var loopthrough = 0; loopthrough < linesReq; loopthrough ++)
{	eachLine[loopthrough]="";thisLoop = 0;
	for (i= incrementedVal; i < (incrementedVal + wordsPerLine); i++)
	  		{if (allWords[i]){
				eachLine[loopthrough] += allWords[i]+" ";
				totalWords+=1;}
			}
			thisLoop=i;
	thisLine = eachLine[loopthrough];
	incrementedVal += wordsPerLine;
	if (loopthrough < (linesReq-1)){thisLine +="<br>";}
	newTitle += thisLine;
}
if(totalWords<wordCount){newTitle+= " " + allWords[(thisLoop)];}
pictitle = newTitle;
}

  _winName = "BigPicWindow";
  newPicHeight = picheight *1;
  truePicHeight = newPicHeight
  newPicHeight = newPicHeight + addedHeight;
  _extended_height = "height=" + newPicHeight;
  _extended_width = "width=" + picwidth;
  _extended_urlLoc = picname;
  _caption = pictitle;

  PicWin=window.open

("",_winName,'status=0,scrollbars=0,resizable=0,' + _extended_height + ',' + _extended_width + ',screenX=50,screenY=50,top=150,left=150');

  PicWin.document.open();
  PicWin.document.writeln('<html>');
  PicWin.document.writeln('<head>');
  PicWin.document.writeln('<title>C-track vehicle tracking</title>');
  PicWin.document.writeln('</head>');
  PicWin.document.writeln('<body topmargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">');

// Firefox rejected "text-align : center;" as a style attribute for either table cell or p, although Explorer accepted it in td.

PicWin.document.writeln('<table border="0" margin = "0" cellspacing="0" padding="0" style="border-collapse:collapse; height:25px; width: ' + (picwidth +5 ) + 'px;"><tr><td width="' + picwidth + '" border="0" margin = "0" style = "background-color: #3A5CA6; color: white;vertical-align: middle; font-family:Trebuchet MS,Arial,Helvetica,Geneva,Sans-serif,sans-serif; font-size:9pt";><p align="center" style = "width: ' + picwidth + 'px;"><b>' + _caption + '</p></b></td></tr></table>');

  PicWin.document.writeln('<img src="' + picname + '" width = "' + picwidth + '">');

  PicWin.document.writeln('</body>');
  PicWin.document.writeln('</html>');
  PicWin.document.close();
}