function GadgetUtils() {
	if (typeof(gadgets)!=='undefined') {
		this.container = 'iGoogle';
	}
	else if (typeof(_IG_RegisterOnloadHandler)!=='undefined') {
		this.container = 'iGoogleLegacy';
	}
	else if (typeof(widget)!=='undefined') {
		this.container = 'NetVibes';
	}
	else {
		try {
			if (window.parent.document) {
				this.container = 'local';
			}
		}
		catch(e) {
			this.container == null;
		}
	}
}


GadgetUtils.prototype.getDocumentHeight = function() {
	return Math.min(
		Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
		Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
		Math.max(document.body.clientHeight, document.documentElement.clientHeight)
	);
}


/*GadgetUtils.prototype.getDocumentHeight = function() {
	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}*/

GadgetUtils.prototype.resizeGadget = function(height) {
	if (this.container == 'iGoogle') {
		if (height) {
			try {
				gadgets.window.adjustHeight(height);
			}
			catch(e) {
				_IG_AdjustIFrameHeight(height);
			}
		}
		else {
			try {
				gadgets.window.adjustHeight();
			}
			catch(e) {
				_IG_AdjustIFrameHeight();
			}
		}
	}
	if (this.container == 'iGoogleLegacy') {
		if (height) {
			_IG_AdjustIFrameHeight(height);
		}
		else {
			_IG_AdjustIFrameHeight();
		}
	}
	else if (this.container == 'local' && window.parent.document.getElementsByTagName('iframe').length > 0) {
		if (height) {
			window.parent.document.getElementsByTagName('iframe')[0].height = height;
		}
		else {
			window.parent.document.getElementsByTagName('iframe')[0].height = this.getDocumentHeight();
		}
	}
}

/*
future enhancements: signed requests and oauth for igoogle gadgets, more information:
http://code.google.com/apis/gadgets/docs/reference/#gadgets.io
*/
/*
url - required, the url to make the request to
type - required, the type of the request (text, xml, feed, json)
callback - required, the callback function
params - optional, optional parameters for the request, at the moment only used for igoogle feed type (num_entries, get_summaries)

type feed is not supported for 'local' container for now
*/
/*GadgetUtils.prototype.makeRequest = function(url, type, callback, params) {
	var contentType = type.toLowerCase();
	if (this.container == 'iGoogle') {
		var reqParams = {};
		
		if (contentType == 'text') {
			reqParams[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
			gadgets.io.makeRequest(url, function(response){
				callback(response.data);
			}, reqParams);
		}
		else if (contentType == 'xml') {
			reqParams[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			gadgets.io.makeRequest(url, function(response){
				callback(response.data);
			}, reqParams);
		}
		else if (contentType== 'feed') {
			reqParams[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.FEED;
			for (param in params) {
				if (param.toLowerCase() == 'num_entries') {
					reqParams[gadgets.io.RequestParameters.NUM_ENTRIES] = params[param];
				}
				else if (param.toLowerCase() == 'get_summaries') {
					reqParams[gadgets.io.RequestParameters.GET_SUMMARIES] = params[param];
				}
			}
			gadgets.io.makeRequest(url, function(response){
				callback(response.data);
			}, reqParams);
		}
		else if (contentType == 'json') {
			reqParams[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
			gadgets.io.makeRequest(url, function(response){
				callback(response.data);
			}, reqParams);
		}
	}
	else if  (this.container == 'NetVibes') {
		if (contentType== 'text') {
			UWA.Data.getText(url, callback);
		}
		else if (contentType == 'xml') {
			UWA.Data.getXml(url, callback);
		}
		else if (contentType == 'feed') {
			UWA.Data.getFeed(url, callback);
		}
		else if (contentType == 'json') {
			UWA.Data.getJson(url, callback);
		}
	}
	else if  (this.container == 'local') {
		var xmlhttp;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else {
			alert("Your browser does not support XMLHTTP!");
		}
		
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (contentType == 'text') {
					callback(xmlhttp.responseText);
				}
				else if (contentType == 'xml') {
					callback(xmlhttp.responseXML);
				}
				else if (contentType == 'json') {
					callback(evall('('+xmlhttp.responseText+')'));
				}
			}
		}
		
		xmlhttp.open("POST",url,true);
		xmlhttp.send(null);	
	}
}*/