var GlobediaWidget = {
	cols : 1,
	width : 300,
	height : '',
	num : 4,
	country : '0',
	category : 0,
	order : 'votes',
	title : '',
	author : '',
	images : 'true',
	summaries : 'true',
	votes : 'false',
	
	init : function() {
		addCSS();
		printWidgetContent(GLBDWText);
	},
	test : function(prm) 
	{
		for (var n in this) { if (prm[n] && n != 'init' && n != 'test') this[n] = prm[n]; }
		if (this['width'] < 200) this['width'] = 200;
		var params = '';
		for (var p in this) { if (p != 'init' && p != 'test') params = params + p + '=' + this[p] + '&'; }
		params = params.substr(0, (params.length - 1));
		var load = '<div id="glbd-load" class="loading" style="width: '+this['width']+'px;"></div>';
		var link = '<div id="glbd-link" style="text-align:right; font-size:10px; font-family:\'Trebuchet MS\', Arial; margin: 0 auto; width: '+this['width']+'px;"><a href="http://globedia.com" title="Noticias" target="_blank" style="color:#999; text-decoration:none;">globedia.com</a></div>';
		document.getElementById('widget-show').innerHTML = '<div id="glbd-widget">' + load + link + '</div>';
		xmlhttpPost(params, '/widgets/widget.php?test', this);
	}
};

function xmlhttpPost(str, url, obj) {
	var xmlHttpReq = false;
	var self = this;
	var strURL = url;
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try
	    {
	        self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	    }   
	    catch (err)
	    {
	        try
	        {
	            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch (err2)
	        {
	        }
	    }
	}
	
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.send(str);
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			printWidgetContent(self.xmlHttpReq.responseText);
		}
	}
}

function printWidgetContent(content) {
	document.getElementById('glbd-load').style.width = '';
	document.getElementById('glbd-load').style.height = '';
	document.getElementById('glbd-load').style.background = '';
	document.getElementById('glbd-load').innerHTML = content;
}

function addCSS() {
	var css = 'http://globedia.com/css/widget.css';
	
    var Z = document.getElementsByTagName("HEAD")[0];
    var X = document.getElementsByTagName("LINK");
    var W = X.length;
	var Y = 0;
	
    for (; Y < W; Y++) {
        if (X[Y].href == css && X[Y].rel.toLowerCase() == "stylesheet") {
            return;
        }
    }
    W = document.createElement("LINK");
    W.rel = "stylesheet";
    W.type = "text/css";
    W.href = css;
    if (Z) {
        Z.appendChild(W);
    } else {
        document.documentElement.insertBefore(W, document.documentElement.firstChild);
    }
}


