//================================================
//===	Wildgroup 2001 Oleg Myaskovsky
//===	DHTML utils
//===	ver. 2.0
//================================================

//=============================================================
//===	added by Alexej Spas
//===	Object for checking browser version.
//=============================================================
function BrowserObject() {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns"
	else
		if (b=="Microsoft Internet Explorer") this.b = "ie";
		else this.b = b;
	this.v = parseInt(navigator.appVersion);
	this.ns = (this.b=="ns" && this.v>=4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns5 = (this.b=="ns" && this.v==5);
	this.ie = (this.b=="ie" && this.v>=4);
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	if (this.ie5) this.v = 5;
	this.min = (this.ns||this.ie);
	this.dom = (document.getElementById)? true:false;
	
	var p = navigator.platform.toLowerCase();
	this.win = p.indexOf('win') != -1;
	this.mac = p.indexOf('mac') != -1;
}

var is = new BrowserObject();
//alert(show_props(is));

var debug_mode = false;	// debug feature

//=============================================================
//===	get handle of layer "id" in document "doc"
//=============================================================
function getObject(id, doc) {
	var obj = null;
	var layer = null;

	// get layer object
	if (is.dom) layer = doc.getElementById(id);
	if (is.ie4) layer = doc.all[id];
	if (is.ns4) {
		//alert(id + ' doc=' + doc + ' doc.layers=' +doc.layers + ' doc.layers.length='+doc.layers.length);
		for (var i=0; i<doc.layers.length; i++)
			if (doc.layers[i].name == id) {
				layer = doc.layers[i];
				break;
			}
	}
	if (layer == null && debug_mode)
		alert('DHTML.GetObject: object '+id+' not found in '+document);

	// init extra props
	if (layer != null) {
		obj = (is.ns4)? layer : layer.style;
		obj.layer = layer;
		obj.doc = doc;
		obj.id = id;
	}

	return obj;
}

//=============================================================
//===	show layer "obj"
//=============================================================
function showObject(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.showObject: obj is null');
	
	if (is.ns4) obj.visibility = "show";
	else obj.visibility = "visible";
}

//=============================================================
//===	hide layer "obj"
//=============================================================
function hideObject(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.hideObject: obj is null');
	
	if (is.ns4) obj.visibility = "hide";
	else obj.visibility = "hidden";
}

//=============================================================
//===	move layer "obj" to point("x", "y")
//=============================================================
function moveTo(obj, x, y) {
	if (obj == null && debug_mode) 
		alert('DHTML.moveTo: obj is null');
	
	obj.left = x;
	obj.top = y;
}

//=============================================================
//===	move layer "obj" by vector("x", "y")
//=============================================================  
function moveBy(obj, x, y) {
	if (obj == null && debug_mode) 
		alert('DHTML.moveBy: obj is null');
	
	obj.left = getObjectLeft(obj) + x;
	obj.top = getObjectTop(obj) + y;
}

//=============================================================
//===	get coordinate X of layer "obj"
//=============================================================  
function getObjectLeft(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.getObjectLeft: obj is null');
	
	if (is.ns4) return obj.left;
	else return parseInt(obj.layer.offsetLeft);
}

//=============================================================
//===	get coordinate Y of layer "obj"
//=============================================================  
function getObjectTop(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.getObjectTop: obj is null');
	
	if (is.ns4) return obj.top;
	else return parseInt(obj.layer.offsetTop);
}

//=============================================================
//===	get width of layer "obj"
//=============================================================  
function getObjectWidth(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.getObjectWidth: obj is null');
	
	if (is.ns4) return obj.clip.right
	else return obj.layer.offsetWidth;
}

//=============================================================
//===	get height of layer "obj"
//=============================================================  
function getObjectHeight(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.getObjectHeight: obj is null');
	
	if (is.ns4) return obj.clip.bottom
	else return obj.layer.offsetHeight;
}

//=============================================================
//===	test visibility of layer "obj"
//=============================================================  
function isObjectVisible(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.isObjectVisible: obj is null');
	
	if (is.ns4) {
		if (obj.visibility == "show") return true;
		else return false;
	}
	else {
		if (obj.visibility == "visible") return true;
		else return false;
	}
}

//=============================================================
//===	rewrite content of layer "obj"
//=============================================================  
function writeObject(obj, text) {
	if (obj == null && debug_mode) 
		alert('DHTML.writeObject: obj is null');
	
	if (is.ns4) {
		obj.document.open();
		obj.document.write(text);
		obj.document.close();
	}
	else {
		if(obj!=null && obj.layer!=null)
			obj.layer.innerHTML = text;
	}
}

//=============================================================
//===	get HTML source of layer "id" using "zIndex"
//=============================================================  
function drawLayer(id, zIndex) {
	var source = '';
	if (is.ns4) {
		source += '<LAYER name="' + id + '" visibility="show" z-Index="' + zIndex + '">';
		source += '</LAYER>';
	}
	else {
		source += '<DIV id="' + id + '" style="position:absolute;visibility:visible;z-index:' + zIndex + ';">';
		source += '</DIV>';
	}
	return source;
}

//=============================================================
//===	get zIndex of layer "obj"
//=============================================================  
function getObjectZIndex(obj) {
	if (obj == null && debug_mode) 
		alert('DHTML.getObjectZIndex: obj is null');

	return obj.zIndex;
}

//=============================================================
//===	set zIndex of layer "obj"
//=============================================================  
function setObjectZIndex(obj, zIndex) {
	if (obj == null) 
		if(debug_mode)
			alert('DHTML.setObjectZIndex: obj is null');
		else return;
	obj.zIndex = zIndex;
}

//=============================================================
//===	set background color of layer "obj"
//=============================================================
function setObjectBgColor(obj, color){
	if(obj == null)
		if(debug_mode)
			alert('DHTML.setObjectBgColor: obj is null');
		else return;
	if (is.ns4) {
		obj.bgColor = color;
	}
	else
		obj.backgroundColor = color;
}
