//funcions_plafo.js



//----------------------- begin CODE BY TAG --------------------------------------------------

//-- Copyright/Copyleft 2003 by TAG. Code is published under the terms of GNU GPL

//-- http://www.enlloc.org/wikipool


var act = false
var nav
var primreg
var total = 20
var matriu = new Array(total)
for(i=0;i<total;i++){
	matriu[i]= new Array(2)
	for(i2=0;i2<3;i2++){
		matriu[i][i2] = -1
	}
}

function comprovaNav(){
	if(document.layers){nav = "ns4"}
	else{ 
		if(document.all){nav = "mie"}
		else{
			if(document.getElementById){ nav = "ns6"}
		}
	}
}

comprovaNav();


function actualitza(reg){
	//aquest control hauria d'estar a l'altre frame, sino s'actualitza la pągina cada cop i es perd la variable
	if(act){
		act = false
		alert("act es posa en false")
	}
	else{
		act = true
		alert("act es posa en true")
		actualitzaAra(reg)
	}
}

function actualitzaAra(reg){
	//alert(reg)
	for(i=0;i<total;i++){
		if(nav=="ns4"){ //netscape 4 o 4.x
			//document.layers["Layer1"]
		}
		if(nav=="mie"){ //explorer
			var x = document.all["Layer"+i].style.left
			x = parseInt( x.substring( 0, x.length - 2 ) )
			var y = document.all["Layer"+i].style.top
			y = parseInt( y.substring( 0, y.length - 2 ) )
		}
		if(nav=="ns6"){ //standard -> netscape 6 o >, mozilla
			var x = document.getElementById("Layer"+i).style.left
			x = parseInt( x.substring( 0, x.length - 2 ) ) 
			var y = document.getElementById("Layer"+i).style.top
			y = parseInt( y.substring( 0, y.length - 2 ) ) 
		}
		matriu[i][0] = x
	    matriu[i][1] = y
		//alert("posició Layer" + i + ": " + x + ", " + y)
	}
	cadena = matriuAcadena()

	document.location = "actualitza.php?primreg="+reg+"&cadena="+cadena

	if(act){
		//setTimeout(actualitzaAra(reg),30000) //no queda clar la sintaxi
	}
}


function matriuAcadena(){
	cadena = ""
	for(i=0;i < matriu.length; i++){
		for(i2=0;i2 < 2; i2++){
			if(i2==0){cadena = cadena + matriu[i][0]}
			else{
				if(i2 != 1){cadena = cadena + "," + matriu[i][i2]}
				else{cadena = cadena + "," + matriu[i][i2] + ":"}
			}
		}	
	}	
	return cadena;
}

//----------------------- finalize CODE BY TAG --------------------------------------------------


//----------------------- begin CODE BY Mike Hall for dragging layers ---------------------------

//-- Copyright 2001 by Mike Hall. Code is published under the terms of GNU GPL
//-- Please see http://www.brainjar.com/terms.asp for terms of use.

//-- Ver http://kusor.net// para mas informacion.


// Determine browser and version.


function Browser() {

  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";

  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";

  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";

  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}



var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();

dragObj.zIndex = 0;




function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)

    dragObj.elNode = document.getElementById(id);

  else {

    if (browser.isIE)

      dragObj.elNode = window.event.srcElement;

    if (browser.isNS)

      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)

      dragObj.elNode = dragObj.elNode.parentNode;

  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {


    x = window.event.clientX + document.documentElement.scrollLeft

      + document.body.scrollLeft;

    y = window.event.clientY + document.documentElement.scrollTop

      + document.body.scrollTop;

  }


  if (browser.isNS) {

    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;

  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;

  }

  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }

}



function dragGo(event) {
  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {

    x = window.event.clientX + document.documentElement.scrollLeft

      + document.body.scrollLeft;

    y = window.event.clientY + document.documentElement.scrollTop

      + document.body.scrollTop;

  }


  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }

  if (browser.isNS)
    event.preventDefault();
}



function dragStop(event) {

  // Clear the drag element global.

  dragObj.elNode = null;

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }

  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }

}

//----------------------- finalize CODE BY Mike Hall for dragging layers ---------------------------------
