


var theRdf;

function rdf_popwin1() 
{
   var dc =  evdb_poppedwin.document;
   dc.open();
  dc.writeln("<html><head><title>RDF</title></head><body><pre>\r\n");
  dc.writeln(theRdf);
  dc.writeln("</pre></body></html>");
   dc.close();
   evdb_poppedwin.focus();
}


function rdf_popwin(i)
{
	 evdb_poppedwin = window.open("empty.html","evdb_poppedwin");//,evdb_winprops);
     theRdf = ttlrdf(events[i]);
	 setTimeout('rdf_popwin1()',100);
}



function TTLEncode(plaintext)
{
    var en0 = "\\"; // always encoded
	var en1 = "\\\"";
	var ln = plaintext.length;
	var ch,rs;
    if (plaintext.indexOf("\n") >= 0)
	   {
	   rs = "\"\"\"";
	   if (plaintext.indexOf("\"\"\"") >= 0)
	       {
           var i;
	       for (i = 0; i < ln; i++ ) 
	          {
		      ch = plaintext.charCodeAt(i);
		      if (ch == 92) rs += "\\\\"; else
			  if (ch == 34) rs += "\\\""; else
			  rs += String.fromCharCode(ch);
			  }
		   rs += "\"\"\"";
		   return rs;
		   }
	   for (i = 0; i < ln; i++ ) 
	       {
		   ch = plaintext.charCodeAt(i);
		   if (ch == 92) rs += "\\\\"; else
		   rs += String.fromCharCode(ch);
		   }
	   rs += "\"\"\"";
	   return rs;
	   }
  else // just use a normal string
      {
	  rs = "\"";
	  for (var i = 0; i < plaintext.length; i++ ) 
	      {
		  var ch = plaintext.charCodeAt(i);
		  if (ch == 13) rs += "\\r"; else
		  if (ch == 9) rs += "\\t"; else
		  if (ch == 34) rs += "\\\""; else
		  if (ch == 92) rs += "\\\\"; else
		  rs += String.fromCharCode(ch);
		  }
	  rs += "\"";
	  return rs;
	  }
}




function ttlrdf(ev)
{
   var rs;
   rs = "# RDF in <a href='http://www.ilrt.bris.ac.uk/discovery/2004/01/turtle/'>Turtle syntax</a>\n\n";
   rs += "@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .\n";
   rs += "@prefix geo: &lt;http://www.w3.org/2003/01/geo/wgs84_pos#&gt; .\n";
   rs += "@prefix ical: &lt;http://www.w3.org/2002/12/cal/ical/&gt; .\n";
   rs += "@prefix vcard: &lt;http://www.w3.org/2001/vcard-rdf/3.0#&gt; .\n";
   rs += "@prefix event: &lt;http://fabl.net/vocabularies/evdb_event/&gt; .\n";
   rs += "\n\n";
   rs += "event:"+ev.event_id+"\n";
   rs += " dc:title ";
   rs += TTLEncode(URLDecode(ev.title));
   rs += " ;\n"

   rs += " dc:description ";
   rs += TTLEncode(URLDecode(ev.description));
   rs += " ;\n"

   rs += " ical:dtstart \"";
     
   rs += ev.icalDate;
   rs += "\" ;\n"

   var gi = ev.group;
   var lat = latitudes[gi];
   var lon = longitudes[gi];

   if (lat < 100)
   {
   rs += " geo:lat ";
   rs += lat;
   rs += " ;\n"

   rs += " geo:long ";
   rs += lon;
   rs += " ;\n"
   }



   rs += " vcard:Region \"";
   rs += ev.region;
   rs += "\" ;\n"

   rs += " vcard:Locality \"";
   rs += ev.locality;
   rs += "\" .\n\n"

   

  return rs;
}


