function divalert(id, text){
	var el = document.getElementById(id);
	if (el){
		el.parentNode.removeChild(el);
	} else {
		if (text.length !== 0){
			var div = document.createElement('div');
			div.id = id;
			div.style.display = 'inline';
			div.style.top = tempY;
			div.style.left = tempX-100;
			div.className = "divalert noPrint";
			div.appendChild(document.createTextNode(text));
			document.getElementById('layout-doc').appendChild(div);
		}
	}
};

function treeAddNode(fatherId, sonId, node){
	//alert("Node with: " + node.data.pozid + " will be added...");
	//*** Managing the dialog to select object
	//alert(fatherId + " " + sonId + " " + node);
	YAHOO.namespace("example.container");
	if (YAHOO.example.container.panel2==undefined){
		YAHOO.example.container.panel2 = new YAHOO.widget.SimpleDialog("panel2",
		{
			xy:[250,100],
			width: "300px",
			fixedcenter: true,
			visible: false,
			close: true,
			icon: YAHOO.widget.SimpleDialog.ICON_HELP,
			constraintoviewport: true,
			buttons: [ { text:"Yes", handler: function(){addNodeYes(fatherId, sonId, node)}, isDefault:true },
			{ text:"No",  handler:addNodeNo } ]
		} );
		YAHOO.example.container.panel2.setHeader("INPUT OBJECT ID");
		YAHOO.example.container.panel2.setBody('<h3>Search for an existing object id:</h3><br><div id="myAutoComplete"><input id="myInput" type="text"><br><br>Create node on the same level ? :<input type="checkbox" id="checkSameLevel" name="checkSameLevel"><br><div id="myContainer"></div></div>');
		YAHOO.example.container.panel2.setFooter("Please choose the object ID...");
		YAHOO.example.container.panel2.render("layout-doc");
		YAHOO.example.container.panel2.show();
	} else {
		YAHOO.example.container.panel2.show();
	}

	YAHOO.example.BasicRemote = function() {
		// Use an XHRDataSource
		var oDS = new YAHOO.util.XHRDataSource("prog/catalog/addnode_searchproxy.php");
		// Set the responseType
		oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
		// Define the schema of the delimited results
		oDS.responseSchema = {
			recordDelim: "\n",
			fieldDelim: "\t"
		};
		// Enable caching
		oDS.maxCacheEntries = 5;

		// Instantiate the AutoComplete
		var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);

		return {
			oDS: oDS,
			oAC: oAC
		};
	}();

}
function treeDelNode(fatherId, sonId, node){
	var sUrl = "../../prog/catalog/dellnode.php";
	var answer = confirm("Do you really want to delete node: " + sonId + " ?")
	if (answer){
		var ps = node.parent;
		tree.removeNode(node, true);
		var postData = "father=" + encodeURI(fatherId) + "&son=" + encodeURI(sonId);
		var handleSuccess = function(o){
			if(o.responseText !== undefined){
				div = YAHOO.util.Dom.get("center1");
				div.innerHTML = o.responseText;
			}
			if (ps.children.length==0){
				ps.isLeaf = true;
				ps.refresh();
			}
		}
		var handleFailure = function(o){
			if(o.responseText !== undefined){
				div = YAHOO.util.Dom.get("center1");
				div.innerHTML = "<li>Error in Transaction id: " + o.tId + "<\/li>";
				div.innerHTML += "<li>HTTP status: " + o.status + "<\/li>";
				div.innerHTML += "<li>Status code message: " + o.statusText + "<\/li>";
				div.style.height = "";
			}
			alert(o.statusText);
		}
		var callback =
		{
			success:handleSuccess,
			failure: handleFailure,
			argument: ['foo','bar']
		};
		var request = YAHOO.util.Connect.asyncRequest("POST", sUrl, callback, postData);
	}
}
function treeMoveNode(fatherId, sonId, node){
	var answer = confirm("Please try back later ! \nWe are doing our best to implement this new function...")
}

function isDescendant(node, object) {
	while(node.parent != null){
		if(node.parent.data.id == object){
			return true;
		}
		node = node.parent;
	}
	return false;
}
// Define various event handlers for Dialog
function addNodeYes(fatherId, sonId, node) {
	var sUrl = "prog/catalog/addnode.php";
	var object = document.getElementById('myInput').value;
	if (object.length>0){
		var answer = confirm("Do you really want to add node " + object + " ?")
		if (answer){
			var postData = "checksamelevel=" + document.getElementById('checkSameLevel').checked + "&father=" + encodeURI(fatherId) + "&son=" + encodeURI(sonId) + "&object=" + encodeURI(object);
			var handleSuccess = function(o){
				if(o.responseText !== undefined){
					var cnVal  = YAHOO.util.History.getCurrentState("cn");
					node = tree.getNodeByProperty("pozid", cnVal);
					if (o.responseText.substr(0,1)!=="{"){
						div = YAHOO.util.Dom.get("center1");
						div.innerHTML = o.responseText;
					} else {
						div = YAHOO.util.Dom.get("messages");
						div.innerHTML = "Successfully added node "+node.data.id ;
					}

					var oResults = eval("(" + o.responseText + ")");
					if((oResults.ResultSet.Result) && (oResults.ResultSet.Result.length)) {
						if(YAHOO.lang.isArray(oResults.ResultSet.Result)) {
							var i=0;
							var myobj = {label: oResults.ResultSet.nodename[i], editable:true, id: oResults.ResultSet.Result[i], reference: oResults.ResultSet.Reference[i], Language: oResults.ResultSet.Language[i], pozid: node.data.pozid + "-0"};
							//var tempNode = new YAHOO.widget.TaskNode(myobj, node, false);
							if (oResults.ResultSet.IsLeaf[i]==1){
								tempNode.isLeaf = true;
							} else {
								tempNode.isLeaf = false;
							}
						}
					}
					if (node.isLeaf = true){
						node.isLeaf = false;
					}
					if (node.expanded){
						node.collapse();
					}
					node.expand();
					node.parent.refresh();
					//window.location.reload(true);
				}
			}
			var handleFailure = function(o){
				if(o.responseText !== undefined){
					div = YAHOO.util.Dom.get("center1");
					div.innerHTML = "<li>Error in Transaction id: " + o.tId + "<\/li>";
					div.innerHTML += "<li>HTTP status: " + o.status + "<\/li>";
					div.innerHTML += "<li>Status code message: " + o.statusText + "<\/li>";
					div.style.height = "";
				}
				alert(o.statusText);
			}
			var callback =
			{
				success:handleSuccess,
				failure: handleFailure,
				argument: ['foo','bar']
			};
			var request = YAHOO.util.Connect.asyncRequest("POST", sUrl, callback, postData);

			YAHOO.example.container.panel2.hide();
		}

	} else {
		alert("Please type in a object id");
	}
};
var addNodeNo = function() {
	this.hide();
};


function svg(form) {
	var frame = document.getElementById('drawFrame'),
	url  = 'prog/svg/svg_add_template.php';
	//url += '?x=' + form.width.value;
	//url += '&y=' + form.height.value;
	//url += '&r=' + form.radius.value;
	//url += '&color=' + form.color.options[form.color.selectedIndex].value;
	frame.src = url;
}

function RTrim(str){
	var whitespace = String(" \t\n\r"),
	s = String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       // Get length of string

		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) { i--; }

		s = s.substring(0, i+1);
	}
	return s;
}
//
function checkall(el) {
	//chec boxes in a form
	who = document.getElementsByTagName('input');
	for (i=0;i<who.length;i++)
	if (who[i].type == 'checkbox' && who[i].name !== 'checkall'){
		who[i].checked = el.checked;
	}
}

function addrowonmouseover(){
	//this function is it recreating onmouseover events for rows in case FIREFOX browser is surfing cat app
	table = document.getElementById('items');
	rows  = table.getElementsByTagName('tr');
	for (var i = 0; i < rows.length; i++){
		el = rows[i].childNodes[0].childNodes[0];
		if((el.className !== 'undefined' || el.className !== 'null') && rows[i].childNodes[0].childNodes[0].className == 'references'){
			//	rows[i].className = 'even';
			if (el.innerText == undefined){
				spanval = el.textContent;
			} else {
				spanval = el.innerText;
			}
			rows[i].setAttribute("onmouseover","on_mouse_over('"+spanval+"');") ;
			rows[i].setAttribute("onmouseout","on_mouse_out('"+spanval+"');") ;
			rows[i].setAttribute("onclick","on_mouse_click('"+spanval+"');") ;
		}
	}
	//onmouseover=\"on_mouse_over('".$reference."')\" onmouseout=\"on_mouse_out('".$reference."')\" onclick=\"on_mouse_click('".$reference."')\"
}

function readdMissingSvgEvents()
{
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	//svgdoc.getElementById('SVGTest').setAttribute('onload', "fixreferences();");
	var elements = svgdoc.getElementById('SVGTest').getElementsByTagName('g');
	for (var j=0; j<elements.length; j++) {
		if (document.embeds.length>0) {
			if (elements.item(j).getAttribute('id').indexOf('grp_ref_',0)){
				elements.item(j).attachEvent("mouseover",(function() { var j = j; return function() { parent.on_mouse_over(j + 1); };})(), false);
				elements.item(j).attachEvent("mouseout",(function() { var j = j; return function() { parent.on_mouse_out(j + 1); };})(), false);
				elements.item(j).attachEvent("click",(function() { var j = j; return function() { parent.on_mouse_click(j + 1); };})(), false);
			}
		} else {
			if (elements.item(j).getAttribute('id').indexOf('grp_ref_',0)){
				elements.item(j).addEventListener("mouseover",(function() { var j = j; return function() { parent.on_mouse_over(j + 1); };})(), false);
				elements.item(j).addEventListener("mouseout",(function() { var j = j; return function() { parent.on_mouse_out(j + 1); };})(), false);
				elements.item(j).addEventListener("click",(function() { var j = j; return function() { parent.on_mouse_click(j + 1); };})(), false);
			}
		}
	}
}

// zoom si PAN
function setView(newViewBox)
{
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	svgdoc.getElementById('SVGTest').setAttributeNS(null,'viewBox', newViewBox);
}

function toggleAnimation()
{
	var frames = document.Form1.frames.value
	if (frames == 1)
	{
		document.Form1.frames.value = 25
		document.Form1.time.value = 500
	}
	else
	{
		document.Form1.frames.value = 1
		document.Form1.time.value = 0
	}
}

function animatedZoom(startX,startY,startWidth,startHeight,endX,endY,endWidth,endHeight)
{
	var frames = document.Form1.frames.value;
	var time = document.Form1.time.value;
	var framesPerSecond = (time / frames);
	var ratioX = (endX - startX) / frames;
	var ratioY = (endY - startY) / frames;
	var ratioWidth = (endWidth - startWidth) / frames;
	var ratioHeight = (endHeight - startHeight) / frames;
	for(var i = 0; i<frames;i++){
		startX = startX + ratioX;
		startY = startY + ratioY;
		startWidth = startWidth + ratioWidth;
		startHeight = startHeight + ratioHeight;
		setTimeout("setView('" + startX + ' ' + startY + ' ' + startWidth + ' ' + startHeight + "')",i*framesPerSecond);
	}
}

function setOriginalView(){
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var viewBox = svgdoc.getElementById('SVGTest').getAttribute('viewBox'),
	params = viewBox.split(' '),
	startX = parseFloat(params[0]),
	startY = parseFloat(params[1]),
	startWidth = parseFloat(params[2]),
	startHeight = parseFloat(params[3]);
	if (svgdoc.getElementById('SVGTest').getAttribute('height') == "21cm"){
		animatedZoom(startX,startY,startWidth,startHeight,0,0,1052,744)
	} else {
		animatedZoom(startX,startY,startWidth,startHeight,0,0,744,1052)
	}
}


/*****
*
*   zoom_standID
*
*****/
function zoom_standID(standID, margin){
	var
	maxX = 0.0, maxY = 0.0, minX = 0.0, minY = 0.0,
	endWidth = 0.0, endHeight = 0.0, endX = 0.0, endY = 0.0, x, y, coords,
	startView, startParams, startX, startY, startWidth, startHeight;
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		var isie=true;
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		var isie=false;
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	coords = svgdoc.getElementById(standID).getBBox();
	minX = coords.x;
	minY = coords.y;
	maxX = coords.x + coords.width;
	maxY = coords.y + coords.height;
	var idel = standID;
	if (isie) {
		var CTM = svgdoc.getElementById(idel).getCTM();
		idel = svgdoc.getElementById(idel).parentNode.getAttribute('id');
		while(svgdoc.getElementById(idel).getAttribute('id')!=="SVGTest"){
			CTM = svgdoc.getElementById(idel).getCTM().multiply(CTM);
			idel = svgdoc.getElementById(idel).parentNode.getAttribute('id');
		}
	} else {
		idel = svgdoc.getElementById(idel);
		var r = idel.getBBox();
		bb = svgdoc.createElementNS("http://www.w3.org/2000/svg", "rect");
		bb.setAttributeNS(null, "fill", "none");
		bb.setAttributeNS(null, "stroke", "red");
		bb.setAttributeNS(null, "pointer-events", "none");
		svgdoc.documentElement.appendChild(bb);
		bb.x.baseVal.value = r.x - 2;
		bb.y.baseVal.value = r.y - 2;
		bb.width.baseVal.value = r.width + 4;
		bb.height.baseVal.value = r.height + 4;
		bb.transform.baseVal.clear();
		almostctm = idel.getTransformToElement(bb);
		bb.transform.baseVal.appendItem(bb.transform.baseVal.createSVGTransformFromMatrix(almostctm));
		var box = bb.getBBox();
		svgdoc.documentElement.removeChild(bb);
		var CTM  = almostctm;
	}
	if (CTM.a!==0 || CTM.b!==0 || CTM.c!==0 || CTM.d!==0 || CTM.e!==0 || CTM.f!==0){
		var matrix = CTM,
		box = svgdoc.getElementById(standID).getBBox(),
		corners = [],
		point = createPoint(box.x, box.y);
		corners.push( point.matrixTransform(matrix) );
		point.x = box.x + box.width;
		point.y = box.y;
		corners.push( point.matrixTransform(matrix) );
		point.x = box.x + box.width;
		point.y = box.y + box.height;
		corners.push( point.matrixTransform(matrix) );
		point.x = box.x;
		point.y = box.y + box.height;
		corners.push(point.matrixTransform(matrix) );
		var max = createPoint(corners[0].x, corners[0].y),
		min = createPoint(corners[0].x, corners[0].y);
		// identify the new corner coordinates of the
		// fully transformed bounding box
		for (var i = 1; i < corners.length; i++) {
			var x = corners[i].x,
			y = corners[i].y;
			if (x < min.x) {
				min.x = x;
			}
			else if (x > max.x) {
				max.x = x;
			}
			if (y < min.y) {
				min.y = y;
			}
			else if (y > max.y) {
				max.y = y;
			}
		}
		endX = min.x-margin/2; //(minX + translatesX );
		endY = min.y-margin/2; //(minY + translatesY );
		endWidth = (max.x - min.x)+margin; //(maxX - minX);
		endHeight = (max.y - min.y)+margin; //(maxY - minY);
	}
	startView   = svgdoc.getElementById('SVGTest').getAttribute('viewBox');
	startParams = startView.split(' ');
	startX      = parseFloat(startParams[0]);
	startY      = parseFloat(startParams[1]);
	startWidth  = parseFloat(startParams[2]);
	startHeight = parseFloat(startParams[3]);
	animatedZoom(startX,startY,startWidth,startHeight,endX,endY,endWidth,endHeight)
}

function createPoint (x, y) {
	var point = svgdoc.getElementById("SVGTest").createSVGPoint();
	point.x = x;
	point.y = y;
	return point;
}
function DrawBorder(targetElement )
{
	targetElement = svgdoc.getElementById(targetElement);
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var bbox = targetElement.getBBox(),
	svgns = 'http://www.w3.org/2000/svg',
	outline = svgdoc.createElementNS(svgns, 'rect');
	outline.setAttributeNS( null, 'x', bbox.x - 2 );
	outline.setAttributeNS( null, 'y', bbox.y - 2 );
	outline.setAttributeNS( null, 'width',  bbox.width + 4 );
	outline.setAttributeNS( null, 'height', bbox.height + 4 );
	outline.setAttributeNS( null, 'stroke', 'blue' );
	outline.setAttributeNS( null, 'fill', 'none' );
	targetElement.parentNode.insertBefore( outline, targetElement );
}

function zoom_standID_poly(standID)
{
	DrawBorder(standID);
	var margin = 50.0,
	maxX = 0.0, maxY = 0.0, minX = 0.0, minY = 0.0, firstCoord = true,
	endWidth, endHeight, endX, endY, coord, x, y, coords,
	startView, startParams, startX, startY, startWidth, startHeight;

	coords = document.embeds['svgmap'].getSVGDocument().getElementById(standID).getAttribute('points').split(" ");
	for(var i=0;i < coords.length;i++)
	{
		if(coords[i] != "")
		{
			coord = coords[i].split(",");
			x = parseFloat(coord[0]);
			y = parseFloat(coord[1]);
			if(firstCoord)
			{
				maxX = x; maxY = y;
				minX = x; minY = y;
				firstCoord = false;
			}
			else
			{
				if(x > maxX) maxX = x;
				else if(x < minX) minX = x;

				if(y > maxY) maxY = y;
				else if(y < minY) minY = y;
			}
		}
	}
	startView = document.embeds['svgmap'].getSVGDocument().getElementById('SVGTest').getAttribute('viewBox');
	startParams = startView.split(' ');
	startX = parseFloat(startParams[0]);
	startY = parseFloat(startParams[1]);
	startWidth = parseFloat(startParams[2]);
	startHeight = parseFloat(startParams[3]);
	endX = minX - (margin /2);
	endY = minY - (margin /2);
	endWidth = (maxX - minX) + margin;
	endHeight = (maxY - minY)  + margin;
	animatedZoom(startX,startY,startWidth,startHeight,endX,endY,endWidth,endHeight)
}

function zoom(zoomFactor)
{
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var viewBox = svgdoc.getElementById('SVGTest').getAttribute('viewBox'),
	params = viewBox.split(' '),
	startWidth = parseFloat(params[2]),
	startHeight = parseFloat(params[3]);
	if((zoomFactor < 1) & (startWidth == 744) & (startHeight == 1052)) return;
	var startX = parseFloat(params[0]),
	startY = parseFloat(params[1]),
	endWidth = startWidth / zoomFactor,
	endHeight = startHeight / zoomFactor;

	if (svgdoc.getElementById('SVGTest').getAttribute('height') == "21cm"){
		if(endWidth > 1052 )
		endWidth  = 1052;
		if(endHeight > 744 )
		endHeight = 744;
	} else {
		if(endWidth > 744 )
		endWidth  = 744;
		if(endHeight > 1052 )
		endHeight = 1052;
	}
	//if(endWidth > 744 ) endWidth = 744;
	//if(endHeight > 1052) endHeight = 1052;
	var endX = startX + ((startWidth - endWidth) / 2),
	endY = startY + ((startHeight - endHeight) / 2);
	animatedZoom(startX,startY,startWidth,startHeight,endX,endY,endWidth,endHeight)
}

function moveY(amountToMove)
{
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var viewBox = svgdoc.getElementById('SVGTest').getAttribute('viewBox'),
	params = viewBox.split(' '),
	startX = parseFloat(params[0]),
	startY = parseFloat(params[1]),
	startWidth = parseFloat(params[2]),
	startHeight = parseFloat(params[3]),
	endY = startY + amountToMove;
	animatedZoom(startX,startY,startWidth,startHeight,startX,endY,startWidth,startHeight)
}

function moveX(amountToMove)
{
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var viewBox = svgdoc.getElementById('SVGTest').getAttribute('viewBox'),
	params = viewBox.split(' '),
	startX = parseFloat(params[0]),
	startY = parseFloat(params[1]),
	startWidth = parseFloat(params[2]),
	startHeight = parseFloat(params[3]),
	endX = startX + amountToMove
	animatedZoom(startX,startY,startWidth,startHeight,endX,startY,startWidth,startHeight)
}
// zoom si PAN

var item_selected = null,
savedStates=new Array(),
savedP=new Array(),
savedStateCount=0;

//save row style
function saveBackgroundStyle(myElement){
	if (myElement == null)
	return;
	saved = new Object();
	saved.element = myElement;
	saved.className = myElement.className;
	saved.backgroundColor = myElement.style["backgroundColor"];
	return saved;
}
function restoreBackgroundStyle(savedState){
	savedState.element.style["backgroundColor"] = savedState.backgroundColor;
	if (savedState.className)	{
		savedState.element.className = savedState.className;
	}
}
//save path style
function savePathStyle(myElement){
	if (myElement == null)
	return;
	savedP = new Object();
	savedP.element = myElement;
	savedP.className = myElement.className;
	if (document.embeds.length>0) {
		//is in IE
		//alert(myElement.style.cssText);
		savedP.style = myElement.style.cssText;
		alert("saved");
	} else {
		//Firefox
		for (var i=0; i<myElement.style.length; i++) {
			alert(myElement.style[i]);
		}
	}
	return savedP;
}
function restorePathStyle(savedP){
	alert(savedP);
	savedP.element.style.cssText = savedP.style;
	if (savedP.className){
		savedP.element.className = savedState.className;
	}
}

function on_mouse_over (ID){
	var obj_name = "grp_ref_";
	obj_name = RTrim(obj_name.concat(ID));
	svgdoc = document;
	if (svgdoc.embeds.length>0) {
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var svgobj = svgdoc.getElementById(obj_name);
	if (svgobj !== null){
		var ch = svgobj.firstChild;
		while (ch !== null){
			if (ch.nodeType == 1 && ch.nodeName == "path"){
				if (ch.getAttribute("style") !== ""){
					if (!savedP[ID]){
						savedP[ID] = ch.getAttributeNS(null, "style");
					}
					ch.removeAttribute("style");
				}
				ch.setAttributeNS(null,"style", "fill:#00CCFF;fill-opacity:0.25;stroke:#3d0707;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1");
			}
			ch = ch.nextSibling;
		}
	}
	var svgdesc = document.getElementById(obj_name);
	//if (svgdesc !== null){
	//	svgdesc.setAttribute("style", "background-color:white; cursor:hand");
	//}
	var DHTMLobj = document.getElementById(obj_name);
	if (!savedStates[ID]){
		savedStates[ID] = saveBackgroundStyle(DHTMLobj);
	}
	if (DHTMLobj !== null){
		DHTMLobj.style.backgroundColor = "#00CCFF";
	}
}
function on_mouse_out (ID){
	if (ID == item_selected){
		return true;
	}
	var obj_name = "grp_ref_";
	obj_name = RTrim(obj_name.concat(ID));
	svgdoc = document;

	if (svgdoc.embeds.length>0){
		svgdoc = svgdoc.embeds[0].getSVGDocument();
	} else {
		svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
	}
	var svgobj = svgdoc.getElementById(obj_name);
	if (svgobj !== null){
		var ch = svgobj.firstChild;
		while (ch !== null){
			if (ch.nodeType == 1 && ch.nodeName == "path"){
				ch.setAttributeNS(null,"style", savedP[ID]);
			}
			ch = ch.nextSibling;
		}
	}
	//alert (obj_name);
	var svgdesc = document.getElementById(obj_name);
	//if (svgdesc !== null){
	//	svgdesc.setAttribute("style", "background-color:red;");
	//}
	var DHTMLobj = document.getElementById(obj_name);
	if (DHTMLobj !== null){
		restoreBackgroundStyle(savedStates[ID]);
		//DHTMLobj.style.backgroundColor = "transparent";
	}
}
function on_mouse_click_table(ID){
	var obj_name = "grp_ref_";
	//var input_name = "input-";
	obj_name = RTrim(obj_name.concat(ID));
	//input_name = input_name.concat(ID);
	if (item_selected){
		svgdoc = document;
		if (svgdoc.embeds.length>0) {
			svgdoc = svgdoc.embeds[0].getSVGDocument();
		} else {
			svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
		}
		var svgobj = svgdoc.getElementById(obj_name);
		if (svgobj !== null){
			var svgStyle = svgobj.style;
			//svgStyle.setProperty ('fill', 'white');
			svgobj.setAttributeNS(null,"fill","white");
		}
		var DHTMLobj = document.getElementById(obj_name);
		if (DHTMLobj !== null)		{
			//DHTMLobj.style.backgroundColor = "white";
			DHTMLobj.style.fontWeight  = "normal";
			restoreBackgroundStyle(savedStates[ID]);
		}
	} else {
		//document.getElementById(input_name).value++;
	}
	if (item_selected !== ID){
		svgdoc = document;
		if (svgdoc.embeds.length>0) {
			svgdoc = svgdoc.embeds[0].getSVGDocument();
		} else {
			svgdoc = svgdoc.getElementsByTagName('object')[0].contentDocument;
		}
		var svgobj = svgdoc.getElementById(obj_name);
		if (svgobj !== null)	{
			//svgStyle = svgobj.getStyle();
			var svgStyle = svgobj.style;
			//svgStyle.setProperty ('fill', 'white');
			svgobj.setAttributeNS(null,"fill","white");
		}
		var DHTMLobj = document.getElementById(obj_name);
		if (DHTMLobj !== null){
			DHTMLobj.style.backgroundColor = "#66E0FF";
			DHTMLobj.style.fontWeight  = "bold";
		}
		item_selected = ID;
	} else {
		item_selected = null;
	}
}
function waitExpand(node){
	if(!node.dynamicLoadComplete){
		setTimeout(function(){waitExpand(node)}, 200);
	}
}
function on_mouse_click(ID){
	// this function is it used when you click in the SVG drawing
	if (oSelectedNode.expanded === false){
		oSelectedNode.expand();
		if(!oSelectedNode.dynamicLoadComplete){
			waitExpand(oSelectedNode);
			tree.subscribe("expandComplete", function(oSelectedNode) {
				//alert(oSelectedNode.children);
				tree.unsubscribe("expandComplete");
				var el_childs = oSelectedNode.children;
				var el_matches = tree.getNodesByProperty("reference", ID);

				for (var i=0; i<el_childs.length; i++) {
					for (var j=0; j<el_matches.length; j++) {
						if (el_childs[i] == el_matches[j]) {
							el_childs[i].expand();
							if(!el_childs[i].dynamicLoadComplete){
								waitExpand(el_childs[i]);
							}
							//myModuleStateChangeHandler(el_childs[i].data.pozid,"ex")
							YAHOO.util.History.navigate("cn", el_childs[i].data.pozid);
						}
					}
				}
			});
		} else {
			selectCurrentSon(el_childs[i]);
		}
	} else {
		elementClicked = tree.getNodeByProperty("id", ID);
		selectCurrentSon(elementClicked);
	}
}

function changeimagesize(el){
	o1 = document.getElementById(el);
	if (o1.style.height == '400px'){
		o1.style.height = '50px';
		o1.title = 'Click to enlarge';
	} else {
		o1.style.height = '400px';
		o1.title = 'Click to lower back the image';
	}
}
function anchor(ida) {
	window.location.href='#'+ida;
}

function aproove(id) {
	if (document.getElementById(id).value == "1"){
		document.getElementById(id).value == "0";
	} else {
		document.getElementById(id).value == "1";
	}
	alert(document.getElementById(id).value == "1");
}
function alternate(){
	var elements = document.getElementsByTagName('*');
	for (var j=0; j<elements.length; j++) {
		if(elements[j].className == "alternatingtables"){
			var table = elements[j];
			var rows = table.getElementsByTagName("tr");
			for(i = 0; i < rows.length; i++){
				if(i % 2 == 0){
					rows[i].className = "even";
				}else{
					rows[i].className = "odd";
				}
			}
		}
	}
}
function switchvisibility(elem){
	el = document.getElementById(elem);
	if ((el.style.display !== "none") || (el.style.display == 'undefined')){
		el.style.display = "none";
	} else {
		el.style.display = "inline";
	}
}
function hide_class(el_tagname, el_class){
	els  = document.getElementsByTagName(el_tagname);
	//alert(els.length);
	for (var i = 0; i < els.length; i++){
		//alert(els[i].className);
		if((els[i].className !== 'undefined' || els[i].className !== 'null') && (els[i].className == el_class)){
			els[i].style.display = "none";
			//els[i].parentNode.removeChild(els[i]);
		}
	}
}

function pause(millis){
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
}

function switchSVG(){
	p = document.getElementById("preview");
	o1 = document.getElementById("svgmap");
	o1.style.display = "block";
	p.style.display = "none";
}

function textSplitOnRows(el,text,size){
	var rows = Math.ceil(text.length/size);
	if (text.length > size) {
		for (var j=0; j<rows; j++){
			newtext = "";
			newtext = text.substring(eval(j*size),(j+1)*size);
			el.appendChild(document.createTextNode(newtext));
			el.appendChild(document.createElement('br'));
		}
	} else {
		el.appendChild(document.createTextNode(text));
	}
}
function textSplitOnRows_old(el,text,size){
	var foo = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; var parts = []; while (1) { foo = foo.replace(/(\w{1,5})/, ''); parts.push(RegExp.$1); if (!foo) { break; } }; parts;
	alert(parts.length);
	newtext = "123";
	el.appendChild(document.createTextNode(newtext));
	el.appendChild(document.createElement('br'));
}

function onmouseover_catalog(qty, nodename, prop1, prop2, prop3, prop4, prop5, prop6, prop7, prop8, language){
	//Fat.fade_element('details', 25, 500, '#444', '#AAA');
	//Fat.fade_element('details', 25, 500, '#FFCC00', '#F00000');
	mytable     = document.getElementById('onmouseover');
	for ( var i = 1; i < 12; i++ ) {
		myrow       = mytable.getElementsByTagName('tr')[i-1];
		mycel       = myrow.getElementsByTagName('td')[0];
		if (myrow.getElementsByTagName('td')[1].childNodes[0]){
			myceltext   = myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue;
			switch(i){
				case 1:
				while (myrow.getElementsByTagName('td')[1].firstChild) {
					myrow.getElementsByTagName('td')[1].removeChild(myrow.getElementsByTagName('td')[1].firstChild);
				}
				textSplitOnRows(myrow.getElementsByTagName('td')[1],nodename,'20.00');
				break   ;
				case 2:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = language;
				break   ;
				case 3:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop1;
				break   ;
				case 4:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop2;
				break   ;
				case 5:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop3;
				break   ;
				case 6:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop4;
				break   ;
				case 7:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop5;
				break   ;
				case 8:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop6;
				break   ;
				case 9:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop7;
				break   ;
				case 10:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = prop8;
				break   ;
				case 11:
				myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = qty;
				break   ;
			}
		}
	}
}
function onmouseout_catalog(nodename){
	mytable     = document.getElementById('onmouseover');
	for ( var i = 1; i < 12; i++ ) {
		myrow   = mytable.getElementsByTagName('tr')[i-1];
		if (myrow.getElementsByTagName('td')[2].childNodes[0].value){
			myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue = myrow.getElementsByTagName('td')[2].childNodes[0].value;
		}
		switch(i){
			case 2:
			while (myrow.getElementsByTagName('td')[1].firstChild) {
				myrow.getElementsByTagName('td')[1].removeChild(myrow.getElementsByTagName('td')[1].firstChild);
			}
			textSplitOnRows(myrow.getElementsByTagName('td')[1],nodename,'20');
			break   ;
		}
	}
	//Fat.fade_element('details', 25, 500, '#FFCC00', '#E4EAD8');
	return true;
}

//this function sends any div to any z-index if one is passed or the next highest depth if one is not passed.
var zInd = 300;
function upEl(theDiv, zDepth) {
	if( document.layers ) {
		theDiv = document.layers['myDiv6C'].document.layers[theDiv];
	} else {
		theDiv = getRefToDiv(theDiv);
	}
	if( !theDiv ) { window.alert( 'Nothing works in this browser.' ); return; }
	if( theDiv.style ) { theDiv = theDiv.style; }
	if(zDepth){
		theDiv.zIndex = zDepth;
	}else{
		theDiv.zIndex = zInd; zInd++;
	}
}

function editItemScreenTable(){
	var el = document.getElementById('preview');
	if (el){
		switchvisibility('preview');
	}
	mytable     = document.getElementById('itemscreentable');
	Fat.fade_element('itemscreentable', 25, 500, '#FFCC00', '#BBBBBB');
	if (mytable.getAttribute('editing') == 'true') {
	} else {
		mytable.setAttribute('editing','true');

		mytablebody = mytable.getElementsByTagName('tbody')[0];

		for( var i = 0; i < 22; i++ ) {
			myrow       = mytablebody.getElementsByTagName('tr')[i];
			mycel       = myrow.getElementsByTagName('td')[0];

			myceltext   = myrow.getElementsByTagName('td')[1].childNodes[0].nodeValue;

			span        = mycel.childNodes[0];
			//alert(mycel.tagName);

			input       = document.createElement('INPUT');
			input.type  = 'TEXT';
			input.name  = 'input'+(i+1);
			if (myrow.getElementsByTagName('td')[1].childNodes[0].childNodes[0] == undefined){
				input.value = '';
			} else {
				input.value = myrow.getElementsByTagName('td')[1].childNodes[0].childNodes[0].nodeValue;
			}
			input.id    = 'input'+(i+1);
			mycel.appendChild(document.createElement('BR'));
			mycel.appendChild(input);
		}

		newtr = document.createElement('TR');
		newtd = document.createElement('TD');
		newtd.style.textAlign = "left";
		myrow.parentNode.insertBefore(newtr,myrow.nextSibling);
		input       = document.createElement('INPUT');
		input.type  = 'TEXT';
		input.name  = 'dwgref';
		input.value = document.getElementById('drawingref').innerHTML;
		input.id    = 'dwg';
		newtd.appendChild(document.createTextNode('Drawing'));
		newtd.appendChild(document.createElement('BR'));
		newtd.appendChild(input);
		newtd.appendChild(document.createElement('BR'));
		newtd.appendChild(document.createElement('BR'));

		newtr.appendChild(newtd);

		newtd = document.createElement('TD');
		newtd.style.textAlign = "left";
		newtd.appendChild(document.createTextNode(input.value));
		newtr.appendChild(newtd);

		switchvisibility('editvalues');

		//create button to cancel
		input       = document.createElement('INPUT');
		input.type  = 'submit';
		input.name  = 'submit[cancel]';
		input.value = 'Cancel';
		input.onclick = function() { if (getElementById('preview')){ switchvisibility('preview');} };
		input.className = 'forumbuttons';
		mytablebody.getElementsByTagName('tr')[22].getElementsByTagName('td')[0].appendChild(input);
		//create button to save info
		input       = document.createElement('INPUT');
		input.type  = 'submit';
		input.name  = 'submit[edittable]';
		input.value = 'Save data';
		input.className = 'forumbuttons';
		mytablebody.getElementsByTagName('tr')[22].getElementsByTagName('td')[0].appendChild(input);
	}
}

function AddToCart(){
	var element = document.getElementById('addtocartdiv');
	if (element){
		switchvisibility('addtocartdiv');
	} else {
		var ss = document.getElementById('catmain');
		//ss.innerHTML = '';

		brnode = document.createElement('br');
		var basenode    = document.getElementById('maintree');

		addtocartdiv    = document.createElement('div');
		addtocartdiv.style.display = 'inline';
		addtocartdiv.id = 'addtocartdiv';
		basenode.appendChild(addtocartdiv);

		var closeButton = 'javascripts/imageshow/close.gif';

		closeButtonNode = document.createElement('a');
		closeButtonNode.id = 'closeButton';
		closeButtonNode.onclick = function(){ if (document.getElementById('addtocartdiv')){ switchvisibility('addtocartdiv');} };
		closeButtonNode.title   = 'click to close the add to cart operation';

		closeButtonText = document.createTextNode('Click here to close');

		closeButtonNode.appendChild(closeButtonText);
		addtocartdiv.appendChild(closeButtonNode);

		h1Node = document.createElement('h3');
		addtocartdiv.appendChild(h1Node);
		textNode = document.createTextNode('Quantities:');
		h1Node.appendChild(textNode);

		table = document.getElementById('items');
		rows  = table.getElementsByTagName('tr');

		for (var i = 0; i < rows.length; i++){
			el     = rows[i].childNodes[0].childNodes[0];
			elName = rows[i].childNodes[1].childNodes[0];
			if (i !== 0 && (el.className !== 'undefined' || el.className !== 'null') && el.className == 'references'){
				if((el.className !== 'undefined' || el.className !== 'null') && rows[i].childNodes[0].childNodes[0].className == 'references'){
					if (el.innerText == undefined){
						labelNodeText = el.textContent;
					} else {
						labelNodeText = el.innerText;
					}
					if (elName.innerText == undefined){
						labelNodeText1 = elName.textContent;
					} else {
						labelNodeText1 = elName.innerText;
					}
					labelNode = document.createTextNode(labelNodeText+'. '+labelNodeText1+' ');
					addtocartdiv.appendChild(labelNode);

					brnode = document.createElement('br');

					newnode             = document.createElement('INPUT');
					newnode.type        = 'TEXT';
					newnode.className   = 'forum';
					newnode.name  = 'addtocart[' + rows[i].childNodes[0].childNodes[1].value + ',' + rows[i].childNodes[0].childNodes[2].value + ',' +rows[i].childNodes[1].childNodes[0].childNodes[0].getAttribute('href') + ']';
					newnode.id    = 'addtocart[' + rows[i].childNodes[0].childNodes[1].value + ',' + rows[i].childNodes[0].childNodes[2].value + ',' +rows[i].childNodes[1].childNodes[0].childNodes[0].getAttribute('href') + ']';
					newnode.size        = '5';
					newnode.setAttribute('value','0');

					addtocartdiv.appendChild(newnode);

					newnode             = document.createElement('INPUT');
					newnode.type        = 'HIDDEN';
					newnode.className   = 'forum';
					newnode.name  = 'link['+i+']';
					newnode.id    = 'link['+i+']';
					newnode.size        = '5';
					newnode.setAttribute('value',rows[i].childNodes[1].childNodes[0].childNodes[0].getAttribute('href'));

					addtocartdiv.appendChild(newnode);

					//alert(rows[i].childNodes[1].childNodes[0].childNodes[0].getAttribute('href'));

					addtocartdiv.appendChild(brnode);
				}
			}
		}
		// add the submit button


		newnode             = document.createElement('INPUT');
		newnode.id          = 'addtocart';
		newnode.type        = 'submit';
		newnode.className   = 'forumbuttons';
		newnode.size        = '10';
		newnode.name        = 'submit[addtocart]';
		newnode.value       = 'Add to cart';
		addtocartdiv.appendChild(newnode);
	}
}

// instead of e.childNodes[0], you'd use it like get_child(e, 0)
function get_child(parent, n) { for(var i = 0, cn =parent.childNodes, l = cn.length, c = 0; i < l; i++) { if((cn[i].nodeType == 1 && ++c) && c == n + 1) return cn[i]; } return null; }

//function to list all properties of a object
function printProp(obj) {
	var obj;
	var str;
	str='';
	for (property in obj) {
		str += property + ", ";
	}
	alert(str);
}

function LoadUrlInUnitByPosiionUsingDispatcher(cUrl, cUnit) {
	var oUnit=layout.getUnitByPosition(cUnit);
	YAHOO.plugin.Dispatcher.fetch ( oUnit.body, cUrl );
}

//* What I use if I have a large amount of data to output from adebugger in odd environments
function showText(yourText){
	var frame = window.open();
	frame.document.write('');
	frame.document.close();
	var pre = document.createElement('pre');
	pre.appendChild(document.createTextNode(yourText));
	frame.document.body.appendChild(pre);
}

function dumpProps(obj, parent) {
	// Go through all the properties of the passed-in object
	for (var i in obj) {
		// if a parent (2nd parameter) was passed in, then use that to
		// build the message. Message includes i (the object's property name)
		// then the object's property value on a new line
		if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
		// Display the message. If the user clicks "OK", then continue. If they
		// click "CANCEL" then quit this level of recursion
		if (!confirm(msg)) { return; }
		// If this property (i) is an object, then recursively process the object
		if (typeof obj[i] == "object") {
			if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
		}
	}
}