function  LargeWebPageImage(id)
{
 id = parseInt(id);
  var XMLWebPageImageRequest = new XMLRequestf();
  XMLWebPageImageRequest.openxmlurl = "/publishing/webpageimagexml.php?id=" + id;  
  XMLWebPageImageRequest.loadedcallback =  "CreateLargeWebPageImage();";
  XMLWebPageImageRequest.loaderrorcallback =  "DialogBox(\"webpageimage\",\"\",\"Image not found!\",400,300);";
  XMLWebPageImageRequest.LoadRequest();
}

function  OriginalWebPageImage(id)
{
 id = parseInt(id);
  var XMLWebPageImageRequest = new XMLRequestf();
  XMLWebPageImageRequest.openxmlurl = "/publishing/webpageimagexml.php?id=" + id;
  XMLWebPageImageRequest.loadedcallback =  "CreateOriginalWebPageImage();";
  XMLWebPageImageRequest.loaderrorcallback =  "DialogBox(\"webpageimage\",\"\",\"Image not found!\",400,300);";
  XMLWebPageImageRequest.LoadRequest();
}

function CreateLargeWebPageImage()
{
 var image = "\n";
 var id = 0;
 var title = " ";
 var description = "";   
 var width = 0;
 var height = 0;
 var owidth = 0;
 var oheight = 0;
 var xmlwebpageimages = XMLRequest.responseXML.getElementsByTagName("webpageimage");
 xmlwebpageimage = xmlwebpageimages.item(0).childNodes;
 for (i=0;i<xmlwebpageimage.length;i++)
 {
  if (xmlwebpageimage.item(i).nodeType==1)
  {
   name =  xmlwebpageimage.item(i).nodeName;
   value =  xmlwebpageimage.item(i).childNodes[0].nodeValue;
   switch (name)
   {
    case "id":
     id = parseInt(value);
    break   
    case "title":
     title = value;
    break         
    case "description":
     description = value;
    break   
    case "widthlarge":
     width = parseInt(value);
    break
    case "heightlarge":
     height = parseInt(value);
    break 
    case "linklarge":
     image = value;
    break
    case "widthoriginal":
     owidth = parseInt(value);
    break
    case "heightoriginal":
     oheight = parseInt(value);
    break  
   } 
  }
 }
 image =  "<img src=\"" + image + "\" width=\"" + width + "\" height=\"" + height + "\" border=\"0\" />";
 if (owidth > width)
 {
   image = "<a onClick=\"OriginalWebPageImage(" + id + ")\">" + image + "</a>"; 
 }
 if (description != "")
 {
  image = "<div>" + image + "</div><div style=\"text-align:left; max-width:"+width+"px;  width:"+width+"px; \">" + description + "</div>";
 }
 image = "<div class=\"imagemargin\">" +  image +  "</div>"; 
 DialogBox("webpageimage",title,image,width,height);
}

function CreateOriginalWebPageImage()
{
 var image = "\n";
 var description = "";
 var id = 0; 
 var title = " ";   
 var width = 0;
 var height = 0;
 wwidth = document.documentElement.clientWidth - 40;
 hheight = document.documentElement.clientHeight - 70;
 
 var xmlwebpageimages = XMLRequest.responseXML.getElementsByTagName("webpageimage");
 xmlwebpageimage = xmlwebpageimages.item(0).childNodes;
 for (i=0;i<xmlwebpageimage.length;i++)
 {
  if (xmlwebpageimage.item(i).nodeType==1)
  {
   name =  xmlwebpageimage.item(i).nodeName;
   value =  xmlwebpageimage.item(i).childNodes[0].nodeValue;
   switch (name)
   {
    case "id":
     id = parseInt(value);
    break        
    case "title":
     title = value;
    break 
    case "description":
     description = value;
    break                
    case "widthoriginal":
     width = parseInt(value);
    break
    case "heightoriginal":
     height = parseInt(value);
    break 
    case "linkoriginal":
     image = value;
    break             
   } 
  }
 }		
 lwidth = width;
 lheight = height;  
 if (width > wwidth)
 {
  lwidth = wwidth;
  lheight = height - (Math.round(((width - lwidth) / width) * height));
 }
 if (lheight > hheight)
 {
 llheight = lheight;
  lheight = hheight;
  lwidth = lwidth - (Math.round(((llheight - lheight) / llheight) * lwidth));
 } 
 
 image =  "<img src=\"" + image + "\" width=\"" + lwidth + "\" height=\"" + lheight + "\" border=\"0\" />"; 
 image = "<a onClick=\"LargeWebPageImage(" + id + ")\">" + image + "</a>"; 
 if (description != "")
 {
  image = "<div>" + image + "</div><div style=\"text-align:left; max-width:"+lwidth+"px;  width:"+lwidth+"px; \">" + description + "</div>";  
 }  
 image = "<div class=\"imagemargin\">" +  image +  "</div>";
 DialogBox("webpageimage",title,image,lwidth,lheight);
}

