var GLOBALS = new Object();

var src_old = {};

function rollOver(elem, over){
	if(elem && over){
		if(elem.nodeName.toLowerCase() == "img"){
			elem.style.cursor = "pointer";
			var curOut = elem.src;
			elem.src = over;
			elem.onmouseout = function(){
				this.style.cursor = "";
				this.src = curOut;
			}
		}
	}
}

function show_block(id){
	if(id && document.getElementById){
		if(document.getElementById(id + "_block")){
			var block = document.getElementById(id + "_block");

			var all_blocks = document.getElementsByTagName("div");

			for(d = 0; d < all_blocks.length; d ++){
				if(all_blocks.item(d).id == id + "_block"){
					continue;
				}

				if(all_blocks.item(d).id.match(/_block/i)){
					all_blocks.item(d).style.display = "none";
				}
			}

			var all_imgs = document.getElementsByTagName("img");

			for(i = 0; i < all_imgs.length; i ++){
				if(all_imgs.item(i).src.match(/_over/i) && all_imgs.item(i).name != id){
					all_imgs.item(i).src = all_imgs.item(i).src.replace(/_over/i, "_up");
				}
			}

			if(block.getElementsByTagName("a").item(0)){
				block.style.display = (block.style.display == "none")? "" : "none";
	
				if(document.getElementById(id)){
					var node = document.getElementById(id);
	
					if(block.style.display == ""){
						src_old[node.firstChild.name] = node.firstChild.src;
						node.firstChild.src = images_obj[node.firstChild.name + '_o'].src;
						src_old[node.firstChild.name + "_out"] = node.firstChild.onmouseout;
						node.firstChild.onmouseout = null;
					} else {
						if(src_old[node.firstChild.name]){
							node.firstChild.src = src_old[node.firstChild.name].replace(/_over/i, "_up");
							node.firstChild.onmouseout = src_old[node.firstChild.name + "_out"];
						} else {
							node.firstChild.src = node.firstChild.src.replace(/_over/i, "_up");
							node.firstChild.onmouseout = function(){
								if(node.firstChild){
									//node.firstChild.src = node.firstChild.src.replace(/_over/i, "_up");
								}
							}
						}
					}
				}
			}
		}
	}
}

window.onload = function(){
	var nLinks = document.getElementsByTagName("a");

	for(a = 0; a < nLinks.length; a ++){
		if(nLinks.item(a).getElementsByTagName("img").item(0)){
			nLinks.item(a).onfocus = function(){
				if(this.blur){
					this.blur();
				}
			}
		}
	}

	if(location.href.match(/=control/i)){
		var inputs = document.getElementsByTagName("input");

		for(d = 0; d < inputs.length; d ++){
			if(inputs.item(d).className == "button"){
				inputs.item(d).onmouseover = function(){
					this.style.border = "1px solid #fff";
					this.style.cursor = "pointer";
				}

				inputs.item(d).onmouseout = function(){
					this.style.border = "";
					this.style.cursor = "";
				}
			}
		}
	}
}

function aC(color){
	var color = (color)? color : "";	

	ubbc("[color=", "[/color]", color);
}

function aS(size){
	var size = (size)? size : "";	

	ubbc("[size=", "[/size]", size);
}

function ubbc(open, end, c, o){
    var tArea = GLOBALS.area || document.forms["update"].content;

    var open = (open)? open : "";
    var end = (end)? end : "";

    if(typeof document.selection != "undefined"){
       tArea.focus();

       var curSelect = document.selection.createRange();

       if(c){
          curSelect.text = open + c + "]" + curSelect.text + end;
       } else {
          curSelect.text = open + curSelect.text + end;
       }
    } else if(typeof tArea.selectionStart != "undefined"){
       var selStart = tArea.value.substr(0, tArea.selectionStart);
       var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
       var curSelection = tArea.value.replace(selStart, '').replace(selEnd, '');

       if(c){
          tArea.value = selStart + open + c + "]" + curSelection + end + selEnd;
       } else {
          tArea.value = selStart + open + curSelection + end + selEnd;
       }
    } else {
       tArea.value += (c)? open + c + "]" + end : open + end;
    }
}

window.onerror = function(){
	return true;
}