/**
 * The RDFa Javascript template.
 *
 * Ben Adida - ben@mit.edu
 * 2006-03-21
 * 2006-05-22 moved to W3C
 *
 * licensed under GPL v2
 */


 // EXPECTING __RDFA_BASE
if (typeof(__RDFA_BASE) == 'undefined')
  __RDFA_BASE = 'http://www.w3.org/2006/07/SWD/RDFa/impl/js/20080817/';

// configuration information
var RDFA = new Object();
RDFA.url = __RDFA_BASE + 'rdfa.js';

RDFA.CALLBACK_DONE_PARSING = function() {
    if (RDFA.warnings && RDFA.warnings.length > 0)
      alert('Warnings:\n\n' + RDFA.warnings.join("\n"));
      
    var N3_TEXT = "";

    // go through all the triples by subject
    RDFA.object_each(RDFA.triplestore.subjectIndex, function(s) {
      N3_TEXT += RDFA.triplestore.subjectIndex[s].join('\n') + '\n\n';
    });
    
    try {
      var n3_encoded = encodeURIComponent(N3_TEXT);
      var n3_uri = 'data:text/plain,' + n3_encoded;
    
      // try opening in a new window
	  var w = window.open(n3_uri);
	
	  if (!w) {
		if (confirm("Couldn't open a new window, want to see the triples in this window?")) {
			// timeout to prevent the browser history from being overwritten for some reason.
        	setTimeout("document.location = '" + n3_uri.replace(/'/g,"\\'") + "'", 250);
		}
      }
    } catch (e) {
      alert('unable to download N3:\n\n' + N3_TEXT);
    }
}

//
// Everything below is used only for loading the RDFa javascript.
// You probably don't need to look at it.
//

// callback when the RDFa parsing is done.
RDFA.CALLBACK_DONE_LOADING = function() {
    RDFA.parse();
}

RDFA.load = function()
{
    var s = document.createElement("script");
    s.type = 'text/javascript';
    s.src = RDFA.url;

    // add it to the document tree, load it up!
    document.getElementsByTagName('head')[0].appendChild(s);
}

RDFA.load();