//  Copyright (2010-2013) Cédric Coussinet (cedric.coussinet@nomoseed.net)
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published
//  by the Free Software Foundation, version 2 of the License.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program. If not, see <http://www.gnu.org/licenses/>

var clickDelay = 250;     // doubleclick time
var eventClick = null;    // handle of click setTimeOut

var serializer = new XMLSerializer();

function nsResolver(prefix) {
  var ns = {
    "share" : "http://www.nomoseed.org/share",
	"model" : "http://www.nomoseed.org/model",
	"svg" : "http://www.w3.org/2000/svg",
	"xlink" : "http://www.w3.org/1999/xlink",
  };
  return ns[prefix] || null;
}

function loadXSLT(dname)
{
	var xsltProcessor = new XSLTProcessor();
	xsltProcessor.importStylesheet(loadXML(dname));
	return xsltProcessor;
}

var xhttp = new XMLHttpRequest();
function loadXML(dname)
{
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;
}

var PI2 = 2 * Math.PI;

var rToD = 180 / Math.PI;
	
var dToR = 1 / rToD;
	
var atan2 = function (y,x)
{
	var r = Math.atan2(y,x);
	if (r<0)
		return -r;
	else
		return PI2 - r;
}

/*	
function sleep(delay)
{
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

function getLocationOnElement(evt, elem) {
   mat = elem.getScreenCTM();
   imat = mat.inverse();   // Go from screen to elem
   var pt = document.rootElement.createSVGPoint();
   pt.x = evt.screenX;
   pt.y = evt.screenY;
   pt = pt.matrixTransform(imat);
   return pt;
}*/