var NewWindow=null;
var itemPhotoWindow=null;
function ShowImage(ImgSource,ImgWidth,ImgHeight,ImgAlt) { 
   var divWidth=ImgWidth;
   var divHeight=ImgHeight;
   window.status='Click Here';
   if (NewWindow!=null && !NewWindow.closed) 
   {
      NewWindow.close();
   }
   
   if(ImgWidth>(screen.width-80))
   { 
      divWidth=screen.width - 80;
   }
   if(ImgHeight>(screen.height - 120))
   { 
      divHeight = screen.height - 120;
      if(divWidth<(screen.width - 80)) divWidth+=17;
   }
   else
   {
      if(divWidth==(screen.width - 80)) divHeight+=17;
   }

   var WinLeft=Math.floor((screen.width-divWidth)/2);
   var WinTop=Math.floor((screen.height-divHeight)/2) - 30;
   var WinAppearence;
   
   if(divWidth==(screen.width - 80) || divHeight==(screen.height - 120))
   {
       WinAppearence = 'scrollbars=yes, toolbar=no, resizable=no, menubar=no, status=no, width='+(divWidth)+',height='+(divHeight)+',top='+WinTop+',left='+WinLeft;
   }
   else
   {
       WinAppearence = 'scrollbars=no, toolbar=no, resizable=no, menubar=no, status=no, width='+(divWidth)+',height='+(divHeight)+',top='+WinTop+',left='+WinLeft;
   }
   
   var Hypertext = '<html><head><title>Charysh.info</title></head><body style="background-color:#000000; margin:0;">';
   
   Hypertext += '<table border="0" cellspacing="0" cellpadding="0" style="width:'+(ImgWidth)+'px; height:'+(ImgHeight)+'px;"><tbody><tr><td onContextMenu="window.close(); return false;" onClick="window.close(); return false;"><img src="' + ImgSource + '" width="' + ImgWidth + 'px" height="' + ImgHeight + 'px" alt="' + ImgAlt + '" /></td></tr></tbody></table></body></html>'

   NewWindow=window.open('','NewWindow',WinAppearence);
   NewWindow.document.writeln(Hypertext);
   NewWindow.focus();
}

function openNew(ImgSource)
{

   if (itemPhotoWindow!=null && !itemPhotoWindow.closed) 
     itemPhotoWindow.close();
     
    var WinLeft=Math.floor((screen.width-400)/2);
     var WinTop=Math.floor((screen.height-350)/2) - 30;
     var WinAppearence;
     var  WinAppearence = 'scrollbars=yes, toolbar=no, resizable=no, menubar=no, status=no, width=400,height=350,top='+WinTop+',left='+WinLeft;
    itemPhotoWindow=window.open(ImgSource,'itemPhotoWindow',WinAppearence);
    itemPhotoWindow.focus();
 
   
     
}
function chgImg(photoId,pWidth,pHeigh)
{
     var url="../ViewImage.aspx?big=1&img="+photoId ;
     var imgMain =document.getElementById("imgMain");
     imgMain.src =url;
     var imgLink =document.getElementById("aLink");
     imgLink.href="javascript:ShowImage('"+url + "'," +pWidth +"," + pHeigh +",'');";
      
}
