 function DM_defineDOMparts() {
	document.body.insertAdjacentElement = function(where,parsedNode){
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)             
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
		return true;
	}
	document.body.insertAdjacentHTML = function(where,htmlStr){
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
		return true;
	}
	document.body.insertAdjacentText = function(where,txtStr){
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
		return true;
	}
}

function newinnerHTML (obj, str){
	   var r = obj.ownerDocument.createRange();
	   r.selectNodeContents(obj);
	   r.deleteContents();
	   var df = r.createContextualFragment(str);
	   obj.appendChild(df);
	   return str;
	}
	
function newouterHTML (obj, str) {
	   var r = obj.ownerDocument.createRange();
	   r.setStartBefore(obj);
	   var df = r.createContextualFragment(str);
	   obj.parentNode.replaceChild(df, obj);
	   return str;
}

var navVersion = parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
var navName = navigator.appName;
var navAgent = navigator.userAgent;
var isWin = (navAgent.indexOf('Win')!=-1);
var isMac = (navAgent.indexOf('Mac')!=-1);
var isSFR = (navName.indexOf('Konqueror')!=-1&&(navVersion>=5))||(navAgent.indexOf('Safari')!=-1);
var isOP = (navAgent.indexOf('Opera')!=-1&&navVersion>=4);
if (isOP && navName.indexOf('Opera')==-1) {navVersion = (parseFloat(navigator.userAgent.split(") ")[1].split(" ")[1]))}
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var menu_show = new Array();
var menu_gen = new Array();
var menu_id = "";
var popTimer = 0;

// var menu = new Array();

function getRef(id) {
    if (isDOM) return document.getElementById(id);
    if (isIE4) return document.all[id];
    if (isNS4) return document.layers[id];
	return null;
}

function getSty(id) {
    return (isNS4 ? getRef(id) : getRef(id).style);
} 

function getRealLeft(el) {
    var xPos = 0, tempEl = el;
//    if(isIE4 || isDOM) if(tempEl.tagName == "TD") xPos += tempEl.clientLeft;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    var yPos = 0, tempEl = el;
//    if(isIE4 || isDOM) if(tempEl.tagName == "TD") yPos += tempEl.clientTop;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;	
}

function link(link) {
document.location=link;
}

function Item(pid, contbl_id, text, url, img, img_over, width, height, type, ori, div_class, table_class, td_style, td_over_style, td_div_class//, temp1, temp2, ..., tempN
		){
	this.pid			= pid;
	this.contbl_id		= contbl_id;
	this.text			= text;
	this.url			= url;
	this.img			= (img?img:null);
	this.img_over		= (img_over?img_over:null);
	this.h				= (height?height:0);
	this.w				= (width?width:0);
	this.ori			= ori;
	this.type			= type?true:false;
	this.div_class		= (div_class?div_class:"DMdefault");
	this.table_class 	= (table_class?table_class:"DMdefault");
	this.td_style		= (td_style?td_style:DM_td_style);
	this.td_over_style 	= (td_over_style?td_over_style:(DM_td_over_style)?DM_td_over_style:this.td_style);
	this.td_over_style += "  cursor:hand; ";
	this.td_div_class 	= td_div_class?td_div_class:"DMtdDivDefault";
	this.x				= 0;
	this.y				= 0;
	this.child			= false;
	this.active			= false;

// !!! Uncoment for arguments !!!
/*	if(Item.arguments.length>10){
		var a = Item.arguments; 
		for(i=1; (i+9)<a.length; i++)
			eval("this.temp" + i + "= a[i+9]");
	}
*/
}

function DM_check_sys(){
	var temp = new Array();
	var show_temp = new Array();
	var i = "";
	var hide;
	temp[temp.length] = menu_status;
	if (menu_status != 0)
		if(menu[menu_status].pid != '')
		{
			i=menu[menu_status].pid;
			temp[temp.length] = i;
			while (menu[i].pid != ''){
				i=menu[i].pid;
				temp[temp.length] = i;
			}
		}
	for(i=0; i<menu_show.length; i++){
		hide = true;
		for(j=0; hide && j<temp.length; j++)
			if(menu_show[i] == temp[j]){
				hide = false;
				show_temp[show_temp.length] = menu_show[i];
			}
		if(hide == true){
			if (menu[menu_show[i]].child) getSty("DM_div_" + menu_show[i]).visibility = "hidden";
			if (menu[menu_show[i]].img_over) document.images["DM_td_img_"+menu_show[i]].src = menu[menu_show[i]].image.src
			else if (!menu[menu_show[i]].img && !isMac) getSty("DM_td_" + menu_show[i]).cssText = menu[menu_show[i]].td_style;
		}
	}
	menu_show = show_temp;
	return true;
}

function DM_td_over(id){
	clearTimeout(popTimer);
	write_menu_custom(id);
	menu_status = id;
	var add = true;
	for (i=0; i<menu_show.length; i++) if(menu_show[i] == id) add = false;
	if (add == true) menu_show[menu_show.length] = id;
	if (menu[id].img_over) document.images["DM_td_img_"+id].src = menu[id].image_over.src
	else if (!menu[id].img && !isMac) getSty("DM_td_" + id).cssText = menu[id].td_over_style;
	if (menu[id].child && id != ''){
		getSty("DM_div_" + id).visibility = "visible";
	}
	DM_check_sys();
	return true;
}

function DM_td_out(){
	menu_status = 0;
	clearTimeout(popTimer);
	popTimer = setTimeout('DM_check_sys()', 800);
	return true;
}

