/**
 * Copyright 2003, IMTEAM www.imteam.it
 * QUESTO PROGRAMMA E' COPERTO DA COPYRIGHT E NON PUO' ESSERE COPIATO O
 * MODIFICATO (NEMMENO PARZIALMENTE) SENZA ESPLICITO CONSENSO DEL PROPRIETARIO.
 * NON PUO' ESSERE UTILIZZATO AL DI FUORI DEL PRODOTTO CON CUI E' STATO FORNITO.
 */

var toolDescrizione = 'descrFunz';

// clip layer display to clipleft, cliptip, clipright, clipbottom
// Not working with Mozilla Milestone 12 (Nav5)
function layerClip2(name, clipleft, cliptop, clipright, clipbottom) {
  this.layer = layerGetStyle(name);
  if ( typeof(is)=="undefined" || is == null || this.layer == null) {
    return true;
  }
  if (is.ns4) {
    this.layer.clip.left   = clipleft;
    this.layer.clip.top    = cliptop;
    this.layer.clip.right  = clipright;
    this.layer.clip.bottom = clipbottom;
  } else {
    this.layer.clip = 'rect(' + cliptop + 'px, ' +  clipright + 'px, ' + clipbottom + 'px, ' + clipleft +'px)';
  }
  return true;
}

// ATTENZIONE ! Non e' da cancellare perche' viene utilizzata da mapDrawZoomBox
function layerClip(name, clipleft, cliptop, clipright, clipbottom) {
  this.layer = layerGetStyle(name);
  if ( typeof(is)=="undefined" || is == null || this.layer == null) {
    return true;
  }
  if (is.ns4) {
      this.layer.clip.left   = clipleft;
      this.layer.clip.top    = cliptop;
      this.layer.clip.right  = clipright;
      this.layer.clip.bottom = clipbottom;
  } else {
    var newWidth = clipright - clipleft;
    var newHeight = clipbottom - cliptop;
    this.layer.height = newHeight + "px";
    this.layer.width	= newWidth + "px";
    this.layer.top	= cliptop + "px";
    this.layer.left	= clipleft + "px";
  }
  return true;
}

// nella vecchia implementazione il secondo parametro non c'era,
// quindi per default e' false
function layerGetStyle(name, ignoreError) {
  // se non lo conosci ancora assumi un browser moderno
  if ( typeof(is)=="undefined" || is == null || is.ns6 || is.ie5) {
    if (ignoreError && !(document.getElementById(name))) return null;
    this.style = document.getElementById(name).style;
    return this.style;
  }
  if (is.ns4) {
    return(window.document.layers[name]);
  }
  if (is.ie4) {
    this.style = window.document.all[obj].style;
    return this.style;
  }
  if (is.not) {
    return null;
  }
}

function layerGet(name) {
  if ( typeof(is)=="undefined" || is == null) {
    return null;
  }
  if (is.ns4) {
    return(window.document.layers[name]);
  }
  if (is.ie4) {
    return window.document.all[obj];
  }
  if (is.ns6 || is.ie5) {
    return document.getElementById(name);
  }
  if (is.not) {
    return null;
  }
}

// nella vecchia implementazione il secondo parametro non c'era,
// quindi per default e' false
function layerHide(name, ignoreError) {
  this.layer = layerGetStyle(name, ignoreError);
  if (this.layer == null) {
    //alert("layerHide cannot find ["+name+"]")
    return true;
  }

  // se non lo conosci ancora assumi un browser moderno
  if ( typeof(is)=="undefined" || is == null || is.ns6 || is.ie5 || is.ie4) {
    this.layer.visibility = "hidden";
    this.layer.display="none";
    this.layer.speak="none";
  } else {
    this.layer.visibility = "hide";
  }
  return true;
}

// nella vecchia implementazione il secondo parametro non c'era,
// quindi per default e' false
function layerShow(name, ignoreError) {
  this.layer = layerGetStyle(name, ignoreError);
  if (this.layer == null) {
    //alert("layerShow cannot find ["+name+"]")
    return true;
  }
  if ( typeof(is)=="undefined" || is == null || is.ns6 || is.ie5 || is.ie4) {
    this.layer.display="";
    this.layer.speak="";
    this.layer.visibility = "visible";
  } else {
    this.layer.visibility = "show";
  }
  return true;
}

// move layer to coords
function layerMove(name, x, y) {
  this.layer = layerGetStyle(name);
  if (is.ns4) {
    this.layer.moveTo(x, y);
  } else {
    this.layer.left = x + "px";
    this.layer.top  = y + "px";
  }
}

function layerSwitchVisibility(name) {
  return (layerIsVisibile(name)) ? layerHide(name) : layerShow(name);
}

function layerIsVisibile(name) {
  return ((layerGetStyle(name).visibility == "show") || (layerGetStyle(name).visibility == "visible"));
}

function layerChangeMouseLayout(obj) {
  this.style = layerGetStyle(obj);
  if ( typeof(is)=="undefined" || is == null) {
    return true;
  }
  if (is.ie5) {
    this.style.cursor = "hand";
  } else {
    this.style.cursor = "pointer";
  }
  return true;
}

//var theCursor = "crosshair";
// set the cursor of the specified layer
function setLayerCursor(divLayer, cursor) {
  window.status = cursor;
	var dObj = layerGetStyle(divLayer);
	if (dObj!=null) {
		dObj.cursor = cursor;
		//theCursor = dObj.cursor;
	}
}

