function Trim(str)
   {
     var s = str.replace(/^(\s)*/, '');
     s = s.replace(/(\s)*$/, '');
     return s;
}

function reverseString(str){
  	var revString = ""; 

	for (var i = 0; i <= str.length; i++) {
		revString = str.charAt (i) + revString
	}
	
	return revString;
}


HBI = function(){
	//HBI is a class
}

HBI.removeClass = function(el, className) {
	if (!(el && el.className)) {
		return;
	}
	var cls = el.className.split(" ");
	var ar = new Array();
	for (var i = cls.length; i > 0;) {
		if (cls[--i] != className) {
			ar[ar.length] = cls[i];
		}
	}
	el.className = ar.join(" ");
};

HBI.addClass = function(el, className) {
	HBI.removeClass(el, className);
	el.className += el.className.length?" " + className:className;;
};

HBI.setClass = function(el, className) {
	el.className = className;
};

HBI.hasClass = function(el, className) {
	if (!(el && el.className)) {
		return false;
	}
	var cls = el.className.split(" ");
	for (var i = cls.length; i > 0;) {
		if (cls[--i] == className) {
			return true;
		}
	}
	return false;
};


HBI.createElement = function(type, parent) {
	var el = null;
	if (document.createElementNS) {
		// use the XHTML namespace; IE won't normally get here unless
		// _they_ "fix" the DOM2 implementation.
		el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
	} else {
		el = document.createElement(type);
	}
	if (typeof parent != "undefined") {
		parent.appendChild(el);
	}
	return el;
};


HBI.addEvent = function(el, evname, func) {
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
};

HBI.removeEvent = function(el, evname, func) {
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
};


HBI.getChildNodesByTagName = function(control,tagName){
	if(!control.hasChildNodes()) return;
	ar = new Array();
	for(var i =0; i < control.childNodes.length; i++){
		if(control.childNodes[i].tagName == tagName){
			ar[ar.length] =  control.childNodes[i];
		}
	}
	return ar;
}


HBI.setSiteLocale = function(siteLocale){
	document.cookie = "SITELOCALE=" + siteLocale + ";path=/";
}

HBI.getSiteLocale = function(){
	return HBI.getCookie("SITELOCALE");
}

HBI.getCookie = function(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;

	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
			
	return unescape(dc.substring(begin + prefix.length, end));
}

HBI.emailCheck = function (str) {
	var at					= "@";
	var dot					= ".";
	var lat					= str.indexOf(at);
	var lstr				= str.length;
	var ldot				= str.indexOf(dot);
	
	if (str.indexOf(at) == -1) {
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
	   return false;
	}


	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
	  return false;
	}
	
	if (str.indexOf(at,(lat+1))!=-1) {
		return false;
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
		return false;
	}
	
	if (str.indexOf(dot,(lat+2))==-1) {
		return false;
	}
	
	if (str.indexOf(" ")!=-1) {
		return false;
	}

	return true;
}

/*
 * Remove non-display characters such as &nbsp;
 */
HBI.removeNonDisplayChar = function(sText) {
	var s = sText.replace(/(&nbsp;)/g, '');
	return s;
}


/*
 * Remove non-display characters such as &nbsp;
 */
HBI.removeHTMLTags = function(sText) {
	//var s = sText.replace(/(\s)*/, '');
	//s = s.replace(/(\s)*$/, '');
	//reReplace(arguments.text, "</*[^>]*>", " ", "all")
	
	var s = sText.replace(/(<\/*[^>]*>)/g, '');
	return s;
}