function ResizeToFit(dlg, picHeight, picWidth) {

 var imgWidth;
 var imgHeight;

 imgWidth = picWidth + 60; 
 imgHeight = picHeight + 110;
 dlg.resizeTo(imgWidth, imgHeight);
}

function mssDisplayImages(img, name, width, height){

 features = 
    "toolbar=no,location=no,directories=no,status=no,menubar=no," +
    "scrollbars=no,resizable=no,width=" + width + ",height=" + height;
 dlg = window.open ("","Details",features);
 dlg.document.write("<html><head><title>" + name + " Zoom</title></head>");


 dlg.document.write("<body bgcolor=white onLoad=\"javascript:opener.ResizeToFit(self,  picImg.height, picImg.width);\"><center>");
 dlg.document.write("<table width=100% height=100%>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<img name=\"picImg\" src=" + img + ">");
 dlg.document.write("</td></tr>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<a href=# onClick=window.close();>");
 dlg.document.write("<font size=1 face=Arial>Click to close</font></a>");
 dlg.document.write("</td></tr>");
 dlg.document.write("</table></body></html>");

 dlg.document.close();
}

function changeImage(newid) {
  var newimg = document.getElementById(newid);
  if (!newimg) return;
  for (i=1; i<=6; i++) {
    var idtext = 'image'+i;
    var oldimg = document.getElementById(idtext);
    if (!oldimg) continue;
    if (newimg!=idtext) oldimg.style.display='none';
  }
  newimg.style.display='block';
}

function findPos(obj, topChange, leftChange) {
   var curTop = 0;
   var curLeft = 0;
   if (obj.offsetParent) {
      do {
         curTop += obj.offsetTop;
         curLeft += obj.offsetLeft;
      }while(obj=obj.offsetParent)
   }
   curTop += topChange;
   curTop += 'px';
   curLeft += leftChange;
   curLeft += 'px';
   return [curTop, curLeft];
}

function createReviewModal(state, div, top, left){
	var clickToClose = true; // set to true to close modalby clicking anywhere
	var modal = document.getElementById('modalOverlay'); // modal div id
	var modalFrame = document.getElementById('modalOverlayFrame'); // modal div id
	var cHeight = findPos(document.getElementById('modalOverlay'), 100, 0)[0];
	var selects = document.getElementsByTagName('select');
	if(div == null){div = '';}
	if(top == null) {top=0;}
	if(left == null) {left=0;}
	function off(){
	   modal.style.height = '1px';
      modal.style.visibility='hidden';
      modalFrame.style.display='none';
      modal.style.top='auto';
      for (i=0;i<selects.length;i++){selects[i].style.visibility='visible';}
   }
  function on(){
      modal.style.height='1000px';
      modal.style.visibility='visible';
      modal.style.top='0px';
      var pos = findPos(document.getElementById('modalOverlay'), top, left);
      modalFrame.style.top= '10%';
      modalFrame.style.left= '34%';
      //modalFrame.style.top= '50%';
      //modalFrame.style.left= '50%';
      modalFrame.style.height='500px';modalFrame.style.display='block';
      for(i=0;i<selects.length;i++){selects[i].style.visibility='hidden';}
   }
	if(!modal||modal=='undefined'){modal=document.createElement('div');modal.id='modalOverlay';document.body.appendChild(modal);}
	if(!modalFrame||modalFrame=='undefined'){modalFrame=document.createElement('div');modalFrame.id='modalOverlayFrame';document.body.appendChild(modalFrame);}
	if (state=="on")on();
	if (state=="off")off();
	if (state="on") {
      modal.onclick=function(){
				if(clickToClose)off();
			}
      }
}

