function pviiClassNew(obj, new_style) 
{obj.className=new_style;}

function preview(file, image, size, width, height)
{
    var predoc = '<img src="'+file+'" alt="'+image+' ('+width+'x'+height+', '+size+')">';
    var w = (width-20) > screen.width ? screen.width-20 : width+20;
    var h = (height-20) > screen.height ? screen.height-20 : height+20;
    var LeftPosition=(screen.width)?(screen.width-w)/2:100;
    var TopPosition=(screen.height)?(screen.height-h)/2:100;
    var win = window.open('','image_preview', 'toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition);

    var doc=win.document.open();

    doc.writeln('<html>\n<head>\n<title>Image Preview - '+image+' ('+width+'x'+height+', '+size+')</title>');
    doc.writeln('</head>\n<body topmargin=2 leftmargin=2>');
    doc.writeln(predoc);
    doc.writeln('</body>\n</html>\n');
    doc=win.document.close();
    win.focus();
    return;
}

function hide_image()
{
var image_div = document.getElementById("image_div");
    image_div.style.display="none";
}

function show_image(url,wtype,w,h)
{
  if(wtype=="1")
  {
     var w_w = eval(w+"+20");
     var w_h = eval(h+"+5");
  	 var LeftPosition=(screen.width)?(screen.width-w_w)/2:100;
 	   var TopPosition=(screen.height)?(screen.height-w_h)/2:100;
     var win = window.open('','Preview','toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width='+w_w+',height='+w_h+',top='+TopPosition+',left='+LeftPosition);
     var doc=win.document.open();
     doc.writeln('<html>\n<head>\n<title>Preview</title>');
     doc.writeln('</head>\n<body style="margin:0">');
     doc.writeln('<img width="'+w+'" height="'+h+'" src="'+url+'" border=0 onClick="window.close()">');
     doc.writeln('</body>\n</html>\n');
     doc=win.document.close();
     win.focus();
  }else if(wtype=="2")
  {
    window.location.href = url;
  }else if(wtype=="3")
  {
    var image_div = document.getElementById("image_div");
    image_div.style.width = eval(w+"+5");
    image_div.style.height = eval(h+"+5");
    image_div.innerHTML = "<table border='3' bgColor='#ffffff'><tr><td><img onClick='hide_image()' src='"+url+"' width='"+w+"' height='"+h+"'/></td></tr></table>";
    centerDiv(image_div);
    image_div.style.display="";
  }  
}

function deleteImage(file)
{
	if(confirm("Delete image \""+file+"\"?"))  return true;
	return false;
}

function showUploadProgressBar()
{
	var divUploadDialog_ = document.getElementById("divUploadDialog");        
	centerDiv(divUploadDialog_);
	divUploadDialog_.style.display = "";
}

function hideUploadProgressBar()
{
	var divUploadDialog_ = document.getElementById("divUploadDialog");
	if(divUploadDialog_) divUploadDialog_.style.display = "none";
}

function centerDiv(myDiv)
{
  var scr_w = screen.width;
  var scr_h = screen.height;

  var browseWidth, browseHeight;

  if (document.layers)
  {
   browseWidth=window.outerWidth;
   browseHeight=window.outerHeight;
  }
  if (document.all)
  {
   browseWidth=document.body.clientWidth;
   browseHeight=document.body.clientHeight;
  }
  //alert("bh:"+browseHeight);
  //alert("bw:"+browseWidth);
  
//  myDiv.style.top  = ((scr_h - parseFloat(myDiv.style.height)) >> 1) - (scr_h-browseHeight)+52;
//  myDiv.style.left = ((scr_w - parseFloat(myDiv.style.width)) >> 1);
  myDiv.style.top  = (((browseHeight - parseInt(myDiv.style.height)) / 2)+50)+"px";
  myDiv.style.left = (((browseWidth - parseInt(myDiv.style.width)) / 2))+"px";
  alert(myDiv.style.top);
//  alert( myDiv.style.left);
}

function previewImage()
{
   var imgRef = document.upload_form.upload.value;
   if(imgRef.length == 0) 
   {
      return false;
   }else
   {
         imgRef = "file:///"+imgRef; 
         var predoc = '<img src="'+imgRef+'">';
	 var w = 500;
	 var h = 500;
	 var LeftPosition=(screen.width)?(screen.width-w)/2:100;
 	 var TopPosition=(screen.height)?(screen.height-h)/2:100;
         var win = window.open('','image_preview', 'toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition);
         var doc=win.document.open();
     
         doc.writeln('<html>\n<head>\n<title>Image Preview</title>');
         doc.writeln('</head>\n<body>');
         doc.writeln(predoc);
         doc.writeln('</body>\n</html>\n');
         doc=win.document.close();
         win.focus();
         return;
   }
}

