
function utils() {
	return this;
}

utils.prototype.get_cookie = function( 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 ) );
}

utils.prototype.set_cookie = function( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

utils.prototype.del_cookie = function( name, path, domain ) {
	if ( get_cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

utils.prototype.get_window_height = function() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientHeight;
	}
	return null;
}

utils.prototype.get_window_width = function() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientWidth;
	}
	return null;
}

utils.prototype.in_array = function(needle, haystack) {
	for (var i=0; i<haystack.length; ++i) {
		if (haystack[i] == needle) {
			return true;
		}
	}
	return false;
}

utils.prototype.check_all = function(checked, names) {
	var nameArr = names.split('|');
	var inputs = document.getElementsByTagName("input");
	for (var i=0; inputs && i<inputs.length; ++i) {
		if (this.in_array(inputs[i].name, nameArr) && !inputs[i].disabled) {
			inputs[i].checked = checked;
		}
	}
}

utils.prototype.is_empty = function (name) {
	var coll = document.forms[0].elements[name];
	if (coll.checked) {
		return false;
	}
	for (var i=0; coll && i<coll.length; ++i) {
		if (coll[i].checked) {
			return false;
		}
	}
	return true;
}

utils.prototype.get_obj_top = function (obj) {
	var returnValue = obj.offsetTop;
	while((obj = obj.offsetParent) != null){
		if(obj.tagName!='HTML')returnValue += obj.offsetTop;
	}
	return returnValue;
}

utils.prototype.get_obj_left = function (obj) {
	var returnValue = obj.offsetLeft;
	while((obj = obj.offsetParent) != null){
		if(obj.tagName!='HTML')returnValue += obj.offsetLeft;
	}
	return returnValue;
}

utils.prototype.cancel_bubble = function (evt) {
	if (!evt) { evt = window.event; }
	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();
}

utils.prototype.install_doc_onclick = function (handler, replace) {
	if (replace || !document.onclick) {
		if (document.addEventListener) {
			document.addEventListener("click", handler, false);
		}
		document.onclick = handler;
		//if (document.captureEvents) { document.captureEvents(Event.CLICK); }
	}
}

utils.prototype.submit = function (action, retval) {
	if (retval == undefined) { retval = false; }
	var act = document.getElementById('act');
	act.value = action;
	document.forms[0].submit();
	return retval;
}

utils.prototype.set_focus = function (id) {
	var obj = document.getElementById(id);
	if (obj) { obj.focus(); }
}

utils.prototype.popup = function (url, w, h) {
	var win = window.open(url, "_blank", "resizable=1,scrollbars=1,location=no,menubar=no,toolbar=no,width=" + w + ",height=" + h);
	if (!win) { alert("Please allow popups on this page."); }
	return win;
}

utils.prototype.popup2 = function (url, w, h) {
	var win = window.open(url, "_blank", "resizable=0,scrollbars=0,location=no,menubar=no,toolbar=no,width=" + w + ",height=" + h);
	if (!win) { alert("Please allow popups on this page."); }
	return win;
}

utils.prototype.go = function (url) {
	window.location = url;
	return false;
}

//the one and only utils
var g_utils = new utils();

