is = new BrowserCheck();

function BrowserCheck() {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;
	this.version = navigator.appVersion;
	this.v = parseInt(this.version);
	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 = (this.version.indexOf('MSIE 4')>0);
	this.ie5 = (this.version.indexOf('MSIE 5')>0);
    this.op = (this.b=="Opera");
	this.min = (this.ns||this.ie);
	this.platform = navigator.platform;
}

function getLayerHTML (id, innerHTML, display, top, left, width, height, background, bgimage, zindex) {
    var str = getLayerHTMLTop(id, display, top, left, width, height, background, bgimage, zindex);
    str += innerHTML + getLayerHTMLBottom();
    return str;
}

function getLayerHTMLTop (id, display, top, left, width, height, background, zindex) {
	var str = "";
	if (is.ns4) { 
		str = "<layer "
		if (id !="") str+="id=\"" + id + "\" ";
		if (display != "") {
			if (display == "visible") display = "";
			else display = "none";
			str+="visible=\"" + display + "\" ";
		}		
		if (top != "") str += "top=\"" + top + "\" "
		if (left != "") str+="left=\"" + left + "\" "
		if (width != "") str+="width=\"" + width + "\" "
		if (height != "") str+="height=\"" + height + "\" ";
		if (background != "") str += "background=\"" + background
		str+= "\">";
	}
	else {
		str = "<div ";
        if (id !="") str+="id=\"" + id + "\""; 
        str+=" style=\"position:absolute;";
        if (display != "") {
			if (display == "visible") display = "";
			else display = "none";
			str+="display:" + display + ";";
		}
        if (top != "") str+="top:" + top + ";";
        if (left != "") str+="left:" + left + ";";
        if (width != "") str+="width:" + width + ";";
        if (height != "") str+="height:" + height + ";";
        if (background != "") str+="background-color:" + background + ";";
        if (zindex != "") str+="z-index:" + zindex + ";";
        str+= "\">";
	}
	return str;
}

function getLayerHTMLTopRelative (id, display, top, left, width, height, background, zindex) {
	var str = "";
	if (is.ns4) { 
		str = "<layer "
		if (id !="") str+="id=\"" + id + "\" ";
		if (display != "") {
			if (display == "visible") display = "";
			else display = "none";
			str+="visible=\"" + display + "\" ";
		}		
		if (top != "") str += "top=\"" + top + "\" "
		if (left != "") str+="left=\"" + left + "\" "
		if (width != "") str+="width=\"" + width + "\" "
		if (height != "") str+="height=\"" + height + "\" ";
		if (background != "") str += "background=\"" + background
		str+= "\">";
	}
	else {
		str = "<div ";
        if (id !="") str+="id=\"" + id + "\""; 
        str+=" style=\"position:relative;";
        if (display != "") {
			if (display == "visible") display = "";
			else display = "none";
			str+="display:" + display + ";";
		}
        if (top != "") str+="top:" + top + ";";
        if (left != "") str+="left:" + left + ";";
        if (width != "") str+="width:" + width + ";";
        if (height != "") str+="height:" + height + ";";
        if (background != "") str+="background-color:" + background + ";";
        if (zindex != "") str+="z-index:" + zindex + ";";
        str+= "\">";
	}
	return str;
}

function getLayerHTMLBottom () {
	var str = "";
	if (is.ie) str = "</div>";
	else if (is.ns4) str="</layer>";
	else if (is.ns5) str = "</div>";
	else if (is.ns5) str = "</div>";
	else str = "</div>";
        return str;
}

function resizeLayerRight (doc, id, step, stopWert) {
    if (parseInt(getStyle(doc, id).left) != stopWert) {
        getStyle(doc, id).left = parseInt(getStyle(doc, id).left) + step;
        return 1;
    } else return 0;
}

function resizeLayerLeft (doc, id, step, stopWert) { 
    var left = parseInt(getStyle(doc, id).left) + step;
//	window.status = left;
//	alert(step+":"+left+":"+stopWert);
    if (step < 0) {
        if (left > stopWert) {
            getStyle(doc, id).left = left;
            return 1;
        } else {
            getStyle(doc, id).left = stopWert;
            return 0;
        }
    } else if (step > 0) {
        if (left < stopWert) {
            getStyle(doc, id).left = left;
            return 1;
        } else {
            getStyle(doc, id).left = stopWert;
            return 0;
        }
    }
}

function resizeLayerBottom (doc, id, step, stopWert) {
    if (parseInt(getStyle(id).height) != stopWert) {
        getStyle(doc, id).top = parseInt(getStyle(doc, id).top) - step;
        getStyle(doc, id).height = parseInt(getStyle(doc, id).height) + step;
        return 1;
    } else return 0;
}

function resizeLayerTop (doc, id, step, stopWert) {
    if (parseInt(getStyle(doc, id).height) != stopWert) {
        getStyle(doc, id).height = parseInt(getStyle(doc, id).height) + step;
        return 1;
    } else return 0;
}

function changeLayer (doc, id, name, value) {
//	if (is.ns5 && name == "visibility") {
	if (doc == null) doc = document;
	if (name == "visibility") {
		name = "display";
		if (value == "visible") value="";
		else value ="none";
	}
    eval("getStyle(doc,'"+id+"')."+name+"='"+value+"'");
}

function getStyle (doc,id) {
	if (doc == null) doc = document;
	var elem = getElement(doc,id);
    if (is.ns4) return elem;
    else return elem.style;
}

function getElement (doc, id) {
//	try {
		if (doc == null) doc = document;
		var elm = null;
		if (is.ie) { elm = doc.all[id]; }
		else if (is.ns4) { elm = doc.layers[id]; }
		else if (is.ns5) { elm = doc.getElementById(id); }
		else if (is.op) { elm = doc.getElementById(id); }
	        else { elm = doc.getElementById(id); }
//	} catch (err) {
//		errHandling("getElement", "id = "+id, err);
//	}
	return elm;
}