#!/usr/bin/perl

use URI::Escape;

print <<EOT;
<html>
 <head>
  <title>Graph</title>


<script>
function setParam(url,name,value)
{
  var urla = url.split("?");
  var search = urla[1];
  var args = search.split("&");

  for (var i = 0 ; i < args.length ; i++) {
     var couple = args[i].split("=");
     if (couple[0] == name) args[i] = name + "=" + value;
  }


  return (urla[0] + "?" + args.join("&"));
}

function getParam0(search,name)
{
  var args = search.split("&");
  var value = "???";

  for (var i = 0 ; i < args.length ; i++) {
     var couple = args[i].split("=");
     if (couple[0] == name) value = couple[1];
  }

  if (value == "???") value = getDefaultParam(name);

  return value;
}

function getParam(name)
{
  return getParam0(location.search.slice(1),name);
}

function getParam3(from,name)
{
  //var url = unescape(getParam('xmluri'));
  //var tmp = url.split("?");
  var tmp = from.split("?");

  if (tmp.length > 1)
     return getParam0(tmp[1],name);
  else
     return getDefaultParam(name);
}
</script>


 </head>
 <body bgcolor="white" onLoad="window.focus()">
  <script>
   var draw_graph_url =
    location.protocol + '//' + location.host;
   document.write('<img border="false" src="' + draw_graph_url + '/get_gif?pid=$ARGV[0]" usemap="#graphe">');
  </script>
  <map name="graphe">
EOT

while (<STDIN>) {
 my (undef,$point1,$point2,$uri) = split;
 my ($point1x,$point1y) = split /,/,$point1;
 my ($point2x,$point2y) = split /,/,$point2;
 $point1y = substr($point1y,0,-1);
 $point2y = substr($point2y,0,-1);
 $point1x = substr($point1x,1);
 $point2x = substr($point2x,1);

# Linea corretta se c'e' il menu
# print <<EOT;
#   <area shape="rect" href="$url" coords="$point1x,$point2y,$point2x,$point1y">
#EOT

# In assenza di menu
 my $point_1_5_x = $point1x +   ($point2x - $point1x)/5;
 my $point_2_5_x = $point1x + 2*($point2x - $point1x)/5;
 my $point_3_5_x = $point1x + 3*($point2x - $point1x)/5;
 my $point_4_5_x = $point1x + 4*($point2x - $point1x)/5;
 print <<EOT;
  <script>
   var iurl = unescape(getParam("url"));
   var getterURL = getParam3(iurl,"param.getterURL");
   var interfaceURL = unescape(getParam3(iurl,"param.interfaceURL"));
   var url = setParam(iurl,"keys","MDG");
   url = setParam(url,"xmluri", getterURL + "getxml%3Furi%3D$uri");
   url = setParam(url,"param.CICURI","$uri");
   url = setParam(url,"param.RDFURI","helm:rdf:www.cs.unibo.it/helm/rdf/rdfprova//$uri");
   var draw_graph_url =
    location.protocol + '//' + location.host + location.pathname;
   url = draw_graph_url + "?url=" + escape(url);
   document.write('<area shape="rect" href="' + url + '" coords="$point1x,$point2y,$point_1_5_x,$point1y">');
  </script>
EOT
 print <<EOT;
  <script>
   var iurl = unescape(getParam("url"));
   var getterURL = getParam3(iurl,"param.getterURL");
   var interfaceURL = unescape(getParam3(iurl,"param.interfaceURL"));
   var url = setParam(iurl,"keys","d_c%2CC1%2CHC2%2CL");
   url = setParam(url,"xmluri", getterURL + "getxml%3Furi%3D$uri");
   url = setParam(url,"param.CICURI","$uri");
   url = setParam(url,"param.RDFURI","helm:rdf:www.cs.unibo.it/helm/rdf/rdfprova//$uri");
   url = interfaceURL + "?url=" + escape(url);
   document.write('<area shape="rect" href="' + url + '" coords="$point_2_5_x,$point2y,$point_3_5_x,$point1y" target="cic">');
  </script>
EOT
 print <<EOT;
  <script>
   var iurl = unescape(getParam("url"));
   var getterURL = getParam3(iurl,"param.getterURL");
   var interfaceURL = unescape(getParam3(iurl,"param.interfaceURL"));
   var url = setParam(iurl,"keys","MMG");
   url = setParam(url,"xmluri", getterURL + "getxml%3Furi%3Dhelm:rdf:www.cs.unibo.it/helm/rdf/rdfprova//$uri");
   url = setParam(url,"param.CICURI","$uri");
   url = setParam(url,"param.RDFURI","helm:rdf:www.cs.unibo.it/helm/rdf/rdfprova//$uri");
   var draw_graph_url =
    location.protocol + '//' + location.host + location.pathname;
   url = draw_graph_url + "?url=" + escape(url);
   document.write('<area shape="rect" href="' + url + '" coords="$point_4_5_x,$point2y,$point2x,$point1y">');
  </script>
EOT
}

print <<EOT;
   </map>
  </img>
 </body>
</html>
EOT
