function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function getElementByIdLike(stringtxt,typeelement) {
    if(!typeelement) typeelement = '*';
    var elements = document.getElementsByTagName(typeelement);
    var retElements = new Array();

    for(var tElement in elements) {
        if(elements[tElement].id && typeof(elements[tElement].id) == 'string') {
            if(elements[tElement].id.indexOf(stringtxt) != -1) {
                retElements.push(elements[tElement]);
            }
        }
    }

    return retElements;
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function getMax(aItems){
	var nMax = 0;
	for(var i = 0; i < aItems.length; i++){
		if(aItems[i] > nMax)
		nMax = aItems[i];
	}
	return nMax;
}

/**
 *	AJAXObject Function
 *	@description	Create the XMLHttpRequest according to the browser
 *	@return			XMLHttpRequest
 */
function AJAXObject() {
	var httpobj = null;
	if(window.ActiveXObject) {
		httpobj = new window.ActiveXObject('Microsoft.XMLHTTP');
	} else if(window.XMLHttpRequest) {
		httpobj = new XMLHttpRequest();
	}
	return httpobj;
}

/* getElementsByClass */

if(!window._getElementsByClass) {
	function _getElementsByClass(classNameStr, parentObj) {
		var returnItems = new Array();
		if(parentObj) {
			if(parentObj.length) {
				alert('classNameStr : ' + classNameStr + '\nparentObj : [parentObj : Error : Must be concret object]');
				return returnItems;
			}
		}
		
		var everyTags = ((parentObj)?parentObj:document).getElementsByTagName('*');
				
		var i = 0;
		while(everyTags[i]) {
		
			var strClasses = everyTags[i].className;
			
			if(strClasses != '') {
				var objClasses = strClasses.split(' ');
				
				for(var indx in objClasses) {
					if(objClasses[indx] == classNameStr) {
						returnItems.push(everyTags[i]);
					}
				}
			}
			i++;
		}
		return returnItems;	
	}
}

var customElements = 0;

document.sc_createElement = function(eType, eClasses, eId, eContainer) {
	customElements++;
	var customElement;
	
	if(!document.getElementById(((eId)?eId:'custElement__' + customElements))) {
		customElement = document.createElement(eType);
		if(eClasses) {
			if(document.all) customElement.setAttribute('className',eClasses);
			else customElement.setAttribute('class',eClasses);
		}
		
		customElement.setAttribute('id',((eId)?eId:'custElement__' + customElements));
		
		if(eContainer) eContainer.appendChild(customElement);
	} else {
		customElement = document.getElementById(((eId)?eId:'custElement__' + customElements));
	}
	
	return customElement;
}

document.sc_clearElement = function(currentElement) {
	if(currentElement) {
		while(currentElement.hasChildNodes()) {
			currentElement.removeChild(currentElement.firstChild);
		}
	} else return;
}

//////////////////////////////////////
// CUSTOM PAGE OBJECT
//////////////////////////////////////
var c_page = {
	width : null,
	height : null,
	sTop : null,
	sLeft : null,
	getSize : function(element) {
		var element = (element)?element:(window.clientHeight)?window:document.body;
		
		this.height = element.clientHeight;
		this.width = element.clientWidth;

		var size = {};
		size.h = this.height;
		size.w = this.width;

		return size;
	},
	getScrollPosition : function(element) {
		var element = (element)?element:document.body;
		
		this.sTop = element.scrollTop;
		this.sLeft = element.scrollLeft;

		var position = {};
		position.t = this.sTop;
		position.l = this.sLeft;

		return position;
	}		
}
//////////////////////////////////////

// Cross-Browser Split 1.0
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
// Consistent cross-browser, ECMA-262 v3 compliant split


// avoid running twice, which would break the reference to the native `split`
if (!window.cbSplit) {

	var cbSplit = function (str, separator, limit) {
		// if `separator` is not a regex, use the native `split`
		if (Object.prototype.toString.call(separator) !== "[object RegExp]")
			return cbSplit._nativeSplit.call(str, separator, limit);

		var	output = [],
			lastLastIndex = 0,
			flags = (separator.ignoreCase ? "i" : "") +
				(separator.multiline  ? "m" : "") +
				(separator.sticky     ? "y" : ""),
			separator = RegExp(separator.source, flags + "g"), // make `global` and avoid `lastIndex` issues
			separator2, match, lastIndex, lastLength;

		str = str + ""; // type conversion
		if (!cbSplit._compliantExecNpcg)
			separator2 = RegExp("^" + separator.source + "$(?!\\s)", flags); // doesn't need /g or /y, but they don't hurt

		// behavior for `limit`: if it's...
		// - `undefined`: no limit.
		// - `NaN` or zero: return an empty array.
		// - a positive number: use `Math.floor(limit)`.
		// - a negative number: no limit.
		// - other: type-convert, then use the above rules.
		if (limit === undefined || +limit < 0) {
			limit = Infinity;
		} else {
			limit = Math.floor(+limit);
			if (!limit)
				return [];
		}

		while (match = separator.exec(str)) {
			lastIndex = match.index + match[0].length; // `separator.lastIndex` is not reliable cross-browser

			if (lastIndex > lastLastIndex) {
				output.push(str.slice(lastLastIndex, match.index));

				// fix browsers whose `exec` methods don't consistently return `undefined` for nonparticipating capturing groups
				if (!cbSplit._compliantExecNpcg && match.length > 1) {
					match[0].replace(separator2, function () {
						for (var i = 1; i < arguments.length - 2; i++) {
							if (arguments[i] === undefined)
								match[i] = undefined;
						}
					});
				}

				if (match.length > 1 && match.index < str.length)
					Array.prototype.push.apply(output, match.slice(1));

				lastLength = match[0].length;
				lastLastIndex = lastIndex;

				if (output.length >= limit)
					break;
			}

			if (separator.lastIndex === match.index)
				separator.lastIndex++; // avoid an infinite loop
		}

		if (lastLastIndex === str.length) {
			if (!separator.test("") || lastLength)
				output.push("");
		} else {
			output.push(str.slice(lastLastIndex));
		}

		return output.length > limit ? output.slice(0, limit) : output;
	};

	cbSplit._compliantExecNpcg = /()??/.exec("")[1] === undefined; // "NPCG": nonparticipating capturing group
	cbSplit._nativeSplit = String.prototype.split;

}


// for convenience...
String.prototype.split = function (separator, limit) {
	return cbSplit(this, separator, limit);
};