//class list
if("document" in self&&!("classList" in document.createElement("_"))){(function(j){"use strict";if(!("Element" in j)){return}var a="classList",f="prototype",m=j.Element[f],b=Object,k=String[f].trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array[f].indexOf||function(q){var p=0,o=this.length;for(;p<o;p++){if(p in this&&this[p]===q){return p}}return -1},n=function(o,p){this.name=o;this.code=DOMException[o];this.message=p},g=function(p,o){if(o===""){throw new n("SYNTAX_ERR","An invalid or illegal string was specified")}if(/\s/.test(o)){throw new n("INVALID_CHARACTER_ERR","String contains an invalid character")}return c.call(p,o)},d=function(s){var r=k.call(s.getAttribute("class")||""),q=r?r.split(/\s+/):[],p=0,o=q.length;for(;p<o;p++){this.push(q[p])}this._updateClassName=function(){s.setAttribute("class",this.toString())}},e=d[f]=[],i=function(){return new d(this)};n[f]=Error[f];e.item=function(o){return this[o]||null};e.contains=function(o){o+="";return g(this,o)!==-1};e.add=function(){var s=arguments,r=0,p=s.length,q,o=false;do{q=s[r]+"";if(g(this,q)===-1){this.push(q);o=true}}while(++r<p);if(o){this._updateClassName()}};e.remove=function(){var t=arguments,s=0,p=t.length,r,o=false;do{r=t[s]+"";var q=g(this,r);if(q!==-1){this.splice(q,1);o=true}}while(++s<p);if(o){this._updateClassName()}};e.toggle=function(p,q){p+="";var o=this.contains(p),r=o?q!==true&&"remove":q!==false&&"add";if(r){this[r](p)}return !o};e.toString=function(){return this.join(" ")};if(b.defineProperty){var l={get:i,enumerable:true,configurable:true};try{b.defineProperty(m,a,l)}catch(h){if(h.number===-2146823252){l.enumerable=false;b.defineProperty(m,a,l)}}}else{if(b[f].__defineGetter__){m.__defineGetter__(a,i)}}}(self))};

//inject jh plugin
if (!window.jh) {

	window.jh = {

		dom: function(id) {
			return document.getElementById(id) || {};
		},

		_visibility: function(el, visible, method) {
			if (el && el.style) {
				if (visible) {
					el.style.display = method || 'block';
				} else {
					el.style.display = 'none';
				}
			}
		},

		_dom: function(el) {
			return typeof el === "string" ? this.dom(el) : el;
		},

		enable: function(el) {
			var el = this._dom(el);
			if (el) {
				el.disabled = false;//!enabled;
			}
		},

		disable: function(el) {
			console.log(el);
			var el = this._dom(el);
			if (el) {
				console.log("disabling", el);
				el.disabled = true;//!enabled;
			}
		},

		show: function(el, method) {
			this._visibility(this._dom(el), true, method);
		},

		hide: function(el) {
			this._visibility(this._dom(el), false);
		},

		html: function(el, html) {
			el = this._dom(el);
			if (el) {
				el.innerHTML = html;
			}
		},

		value: function(el) {
			el = this._dom(el);
			if (el) {
				return el.value;
			}
			return;
		},

		addClass: function(el, clazz) {
			el = this._dom(el);
			if (el && el.classList) {
				el.classList.add(clazz);
			}
		},

		removeClass: function(el, clazz) {
			el = this._dom(el);
			if (el && el.classList) {
				el.classList.remove(clazz);
			}
		},

		toggleClass: function(el, clazz) {
			el = this._dom(el);
			if (el && el.classList) {
				el.classList.toggle(clazz);
			}
		},

		debounce: function(func, wait, immediate) {
			var timeout;
			return function() {
				var context = this, args = arguments;
				var later = function() {
					timeout = null;
					if (!immediate) func.apply(context, args);
				};
				var callNow = immediate && !timeout;
				clearTimeout(timeout);
				timeout = setTimeout(later, wait || 100);
				if (callNow) func.apply(context, args);
			};
		},

		post: function(url, body, callback) {
			var xhttp = new XMLHttpRequest();
			
			xhttp.onreadystatechange = function() {
				if (xhttp.readyState == 4) {
				  typeof callback === "function" && callback(xhttp.status, xhttp.response ? JSON.parse(xhttp.response) : null);
				}
			};
			
			xhttp.open("POST", url, true);
			xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
			xhttp.send(JSON.stringify(body));
		}


	};

}



