function openImg(xmlPath, branding, width, height, type, isAdmin, isVIN, initSlide)
{
	//check dimensions
	var screenWidth = screen.availWidth - 10;
	var screenHeight = screen.availHeight - 60;
	if (width > screenWidth) width = screenWidth;			//if (width < 445) width = 445; // default minimum size
	if (height > screenHeight) height = screenHeight; 		//if (height < 545) height = 545; // default minium size
	//create window
	page = "/Presenter/shellLarge.htm?xmlPath=" + escape(xmlPath) + 
	        "&branding=" + branding + 
	        "&width=" + width + 
	        "&height=" + height + 
	        "&type=" + type + 
	        "&IsAdmin=" + isAdmin + "&IsVIN=" + isVIN + 
	        "&initSlide=" + initSlide + 
	        "&viaScript=1&startedFrom=Proceedings";

	var winName = "p" + initSlide + "_" + branding;
	var winFeatures = "toolbar=no,location=no,status=no,scrollbars=no,resizable=yes,width=" + width + ",height=" + height;
	var popWin2 = window.open(page, winName, winFeatures);
	popWin2.focus();    
}

function GetImageHtml(theimage)
{
	var _w = theimage.getAttribute("width");
	if (_w)  _w = " width=" + _w; else _w = '';
	var _h = theimage.getAttribute("height");
	if (_h) _h = " height=" + _h; else _h = '';
    //" align=\"" + theimage.getAttribute("align") + "\"" +	
	return "<img class=\"ImageDB\" vspace=\"5\" hspace=\"5\" " + 
				" src=\"" + theimage.getAttribute("src") + "\"" +
				" id=\"" + theimage.getAttribute("id") + "\"" +
				" alt=\"" + escape(theimage.getAttribute("alt")) + "\"" +
				" style=\"" + theimage.getAttribute("style") + "\"" +
				_w +
				_h +
			" />";
}

function GetImageId(theimage)
{
    return theimage.getAttribute("id").replace("img", '');
}

function GetImageWidth(theimage)
{
    var w = theimage.getAttribute("width");
    if (!w) 
    {
        w = 0;
        var src = theimage.getAttribute("src");
        var pat = new RegExp("w=\\d{3}");
        var m = src.match(pat);
        if (m!=null)
            w = m.toString().replace("w=", "");
    }
    return w;
}

function GetOriginalWidth(FileRepositoryId)
{
    var retval = 0;
    for (var i = 0; i<JSON_SubDocumentFiles.length; i++)
        if (FileRepositoryId == JSON_SubDocumentFiles[i].x)
            return JSON_SubDocumentFiles[i].w;
    return screen.availWidth-10;
}

function GetOriginalHeight(FileRepositoryId)
{
    var retval = 0;
    for (var i = 0; i<JSON_SubDocumentFiles.length; i++)
        if (FileRepositoryId == JSON_SubDocumentFiles[i].x)
            return JSON_SubDocumentFiles[i].h;
    return screen.availHeight-60;
}

function GetCaption(index)
{
    return JSON_SubDocumentFiles[index].c;
}

function ReformatImages()
{
  // get all images
  var allimages = document.getElementsByTagName("img");
  var imagelist = new Array();
  // get image that are database driven
  for (var i=0; i<allimages.length; i++)
	if (allimages[i].className=='ImageDB')
		imagelist.push(allimages[i]);
  // fix the db images now
  for (var i=0; i<imagelist.length; i++)
  {
	var _img = imagelist[i];
	var _type = _img.getAttribute("TABLETYPE");
	var _title = _img.getAttribute("alt");
	if (_title==null) _title="";
    while (_title.indexOf("\\\"") != -1) _title = _title.replace( "\\\"", '"'); // fix any double escape
	var _caption = GetCaption(i); //_img.getAttribute("CAPTION");
	if (_caption==null) _caption="";
	while (_caption.indexOf("\\\"") != -1) _caption = _caption.replace( "\\\"", '"');  // fix any double escape
	var _align = _img.getAttribute("align");
	var _w = GetImageWidth(_img); //_img.getAttribute("width");
	if (_w==null) _w = "0";
	var newHTML = '';

	newHTML = GetImageHtml(_img);

    // make it clickable
    if (subdocumentid>0)
    {
        newHTML = newHTML.replace("<img ", "<img border=0 ");
        newHTML = newHTML.replace("<IMG ", "<img border=0 ");
        var xmlpath = "/AppUtil/Data/SubDocumentSlideShow.ashx%3Fsubdocid%3D" + subdocumentid;
        var imgid = GetImageId(_img);
        var ow = GetOriginalWidth(imgid);
        var oh = GetOriginalHeight(imgid);
        var w1 = ow;
        var h1 = oh;
        if (ow<355 && oh<330)
        {
            w1 = 440;
            h1 = 560;
        }    
        else
        {
            w1 = ow+85;
            h1 = oh+175;
        }
        var isvin = (location.href.toLowerCase().indexOf("/members/") != -1);
        isvin = (isvin ? "1" : "0");

        if (ow>_w)
            newHTML = "<a href=\"javascript: openImg('" + xmlpath + "', 'generic', " + w1 + ", " + h1 + ", 'large', 0, " + isvin + ", " + i + ")\">" + newHTML + "</a>";

    }

	switch (_type)
	{
		case "1":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\" NAME=\"ImageCell1\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\" NAME=\"ImageCell2\"><TR><TD BGCOLOR=\"#C8C8DC\"><CENTER><STRONG CLASS=\"Title7\"><I>" + _title + "</I></STRONG></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "</CENTER><BR><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "2":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"White\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\" NAME=\"ImageCell1\"><TR><TD BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\" NAME=\"ImageCell2\"><TR><TD BGCOLOR=\"#C8C8DC\"><CENTER><STRONG CLASS=\"Title7\"><I>" + _title + "</I></STRONG></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "</CENTER><BR><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "3":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER><STRONG CLASS=\"Title7\"><I>" + _title + "</I></STRONG></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "4":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER><STRONG CLASS=\"Title7\"><I>" + _title + "</I></STRONG></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "5":
			//no title,caption or border
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "6":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER><SPAN CLASS=\"Boards\">" + _title + "</SPAN></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></CENTER></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "7":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER><STRONG CLASS=\"Title\">" + _title + "</STRONG><BR><SPAN CLASS=\"Boards\">" + _caption + "</SPAN></CENTER></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "8":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\" NAME=\"ImageCell1\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\" NAME=\"ImageCell2\"><TR><TD BGCOLOR=\"#C8C8DC\"><CENTER><STRONG CLASS=\"Title7\"><I>" + _title + "</I></STRONG></CENTER></TD></TR><TR><TD style='text-align:center' BGCOLOR=\"White\">" + newHTML + "<br><SPAN CLASS=\"Boards\"><!--" + _caption + "--></SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
		case "9":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE ALIGN=\"CENTER\" WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER><TEXTAREA COLS=\"36\" ROWS=\"5\" NAME=\"Caption\" WRAP=\"VIRTUAL\" CLASS=\"Boards\" STYLE=\"width: '100%'\">" + _caption + "</TEXTAREA></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE>";
			break;
		case "10":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE ALIGN=\"CENTER\" WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"><TR><TD BGCOLOR=\"White\"><CENTER>" + newHTML + "<BR></CENTER><TEXTAREA COLS=\"36\" ROWS=\"6\" NAME=\"Caption\" WRAP=\"VIRTUAL\" CLASS=\"Boards\" STYLE=\"width: '100%'\">" + _title + "\r\n" + _caption + "</TEXTAREA></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE>";
			break;
		case "11":
			newHTML = "<TABLE ALIGN=\"" + _align + "\" NAME=\"ImageTable\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#C8C8DC\"><TR><TD WIDTH=\"" + _w + "\" VALIGN=\"top\" BGCOLOR=\"White\"><TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\" NAME=\"ImageCell1\"><TR><TD BGCOLOR=\"#C8C8DC\"><TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\" NAME=\"ImageCell2\"><TR><TD BGCOLOR=\"#C8C8DC\"><CENTER><STRONG CLASS=\"Title7\"><I><B></B></I></STRONG></CENTER></TD></TR><TR><TD BGCOLOR=\"White\"><CENTER>Check back later for the answer<BR></CENTER><SPAN CLASS=\"Boards\"></SPAN></TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=5 BGCOLOR=\"White\">&nbsp;</TD></TR></TABLE>";
			break;
	}

	Element.replace(_img, newHTML) // this requires prototype1.6.js
  }
}

