//-----------------------------------------------------------------------------
// find the first childNode with the given tagname
//-----------------------------------------------------------------------------
function findChildByTagName(el, tn) {
	var i, tmp;
	if (el.childNodes) {
		for (var i = 0; i < el.childNodes.length; i++) {
			tmp = el.childNodes[i];
			if (tmp.tagName == tn) {
				return tmp;
			}
		}
	}
	return null;
}
//-----------------------------------------------------------------------------
// find the number of childNodes with the given tagName
//-----------------------------------------------------------------------------
function findChildCountByTagName(el, tn) {
	var i, tmp, cnt;
	cnt = 0;
	if (el.childNodes) {
		for (var i = 0; i < el.childNodes.length; i++) {
			tmp = el.childNodes[i];
			if (tmp.tagName == tn) {
				cnt++;
			}
		}
	}
	return cnt;
}
//-----------------------------------------------------------------------------
// find the next sibling of the node with the same tagName
//-----------------------------------------------------------------------------
function findNextSiblingByTagName(el) {
	var i, tmp, tn;
	tn = el.tagName;
	while (el.nextSibling) {
		tmp = el.nextSibling;
		if (tmp.tagName == tn) {
			return tmp;
		}
		el = tmp;
	}
	return null;
}
//-----------------------------------------------------------------------------
// find an element by it's class name.
//-----------------------------------------------------------------------------
function findElementByClassName(el, className) {
	var i, tmp;
	if (el.className && el.className.indexOf(className) >= 0) {
		return el;
	}
	for (var i = 0; i < el.childNodes.length; i++) {
		tmp = findElementByClassName(el.childNodes[i], className);
		if (tmp != null) {
			return tmp;
		}
	}
	return null;
}
//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------
function OdinBrowser() {
	var ua, s, i;
	this.isIE = false;  // Internet Explorer
	this.isOpera = false;  // Opera
	this.isMozilla = false;  // Mozilla/Netscape/Firefox etc.
	this.version = null;
	ua = navigator.userAgent;
	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOpera = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isMozilla = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isMozilla = true;
		this.version = 6.1;
		return;
	}
	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
}
var odinbrowser = new OdinBrowser();
function formattedString(strValue, params) {
	var resultstring = strValue;
	for (var count = 0; count < params.length; ++count) {
		var find = "{" + count + "}";
		var pos = resultstring.indexOf(find);
		while (pos > -1) {
			var p1 = resultstring.substring(0, pos);
			var p2 = "";
			if (pos + 3 < resultstring.length) {
				p2 = resultstring.substring(pos + 3, resultstring.length);
			}
			resultstring = p1 + params[count] + p2;
			pos = resultstring.indexOf(find);
		}
	}
	return resultstring;
}
//----------------------------------------------------------------------------
// Validate that a value is numeric
//----------------------------------------------------------------------------
function  validateNumeric( strValue ) {
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	//check for numeric characters
	return objRegExp.test(strValue);
}
//----------------------------------------------------------------------------
// Validate that a value is an integer
//----------------------------------------------------------------------------
function validateInteger( strValue ) {
	var objRegExp  = /(^-?\d\d*$)/;
	//check for integer characters
	return objRegExp.test(strValue);
}
//----------------------------------------------------------------------------
// Validate that a value conforms to the given regular expression pattern
//----------------------------------------------------------------------------
function validateValue( strValue, strMatchPattern ) {
	var objRegExp = new RegExp( strMatchPattern);
	//check if string matches pattern
	return objRegExp.test(strValue);
}
//----------------------------------------------------------------------------
// trim trailing whitespace
//----------------------------------------------------------------------------
function rightTrim( strValue ) {
	var objRegExp = /^([\w\W]*)(\b\s*)$/;
	if(objRegExp.test(strValue)) {
		//remove trailing a whitespace characters
		strValue = strValue.replace(objRegExp, '$1');
	}
	return strValue;
}
//----------------------------------------------------------------------------
// Trim leading whitespace
//----------------------------------------------------------------------------
function leftTrim( strValue ) {
	var objRegExp = /^(\s*)(\b[\w\W]*)$/;
	if(objRegExp.test(strValue)) {
		//remove leading a whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}
//----------------------------------------------------------------------------
// Trim both trailing and leading whitespace
//----------------------------------------------------------------------------
function trimAll( strValue ) {
	var objRegExp = /^(\s*)$/;
	//check for all spaces
	if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0) {
			return strValue;
		}
	}
	//check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}


