// JavaScript Document

function BhUtil() {
	this.build();
}

function bhDebug() {
	return new function() {
		
		this.msg ="";
		
		this.setMsg = function(msg) {
			this.msg = msg;
		}
		
		this.runDebug = function() {
			var msgd = "Debug bh.:";
			if(!bh.Util.isString(this.msg)) {
				for(i in this.msg) {
					msgd+="\n\n - ";
					if(bh.Util.isString(i)) {
						msgd+=i+" : ";
					}
					msgd+=this.msg[i];
				}
			}
			alert(msgd);
		}
	}
}

BhUtil.prototype.build = function() {
	this.getEl = function(id) {
		return document.getElementById(id);
	}
	
	this.getObj = function(el) {
		if(this.isString(el)) {
			return this.getEl(el);
		} else {
			return el;
		}
	}
	
	this.putLower = function(s) {
		return s.toString().toLowerCase();
	}
	
	this.putUpper = function(s) {
		return s.toString().toUpperCase();
	}
	
	this.manipulaEl = function(el,m) {
		
		el = this.getObj(el);

		switch(this.putLower(m)) {
			case "hide" : 
				el.style.display = "none";
				break;
			case "show" : 
				el.style.display = "block";
				break;
			case "clean" : 
				el.innerHTML = "";
				break;
		}
	}
	
	this.isString = function(el) {
		return (typeof el == "string");
	}
	
	this.isObj = function(el) {
		return (typeof el =="object");
	}
	
	this.isUdf = function(el) {
		return (typeof el =="undefined");
	}
	
	this.getRandomId = function() {
		return parseInt(540 * Math.random());
	}
	
	this.isNull = function(el) {
		return (el == null);
	}
}

BhUtil.prototype.Browser = {
	agt : navigator.userAgent.toLowerCase(),
	
	isOpera : function() {
		return (this.agt.indexOf('opera') > -1)
	},
	
	isSafari : function() {
		return (this.agt.indexOf('safari') > -1)
	},

	isIe : function() {
		return (!this.isOpera() && 
				this.agt.indexOf('msie') > -1)
	},

	isGecko : function() {
		return (!this.isOpera() && 
				!this.isSafari() && 
				this.agt.indexOf("gecko") != -1);
	}
}

bh.Util = new BhUtil();

function BhIframe() {
	this.build();
}

BhIframe.prototype.build = function() {
	this.create = function(id,src) {
		var iframe = document.createElement("IFRAME");
			iframe.setAttribute("id",id);
			iframe.setAttribute("name",id);

		if(!bh.Util.isUdf(src) && bh.Util.isNull(src)) {
			iframe.src = src;
		}
		
		return iframe;
	}
	
	this.iframe2Ajax = function(iframe,form,access) {
		
		iframe.setAttribute("width","0");
		iframe.setAttribute("height","0");
		iframe.setAttribute("border","0");
		iframe.setAttribute("style","width: 0; height: 0; border: none;");
		
		form.parentNode.appendChild(iframe);

		if(bh.Util.Browser.isIe()) {
			window.frames[iframe.getAttribute("id")].name = iframe.getAttribute("id");
		}
		
		form.setAttribute("target",iframe.getAttribute("id"));
		form.setAttribute("action",access.url);
		form.setAttribute("method",access.method);
		form.setAttribute("enctype","multipart/form-data");
		
		var iframe = iframe;
		var form = form;
		
		return {
				 getIframe : function() { return iframe},
				 getForm : function() { return  form}
				};
	}
}

bh.Iframe = new BhIframe();

function BhEvent() {
	this.build();
}

BhEvent.prototype.build = function() {
	this.addEvent = function(el,evt,f) {
		if(document.all){
			el.attachEvent('on'+evt,f,false);
		}else{
			el.addEventListener(evt,f,false)
		}
	}
}

bh.Event = new BhEvent();