var $ = function(id) {
	return document.getElementById(id);
}

var MOHA = {};

MOHA['util'] = {};
MOHA['util']['Dom'] = {};

MOHA.util.Dom = {
	setStyle : function (el, property, val) {
		$(el).style[property]=val;
	},

	set : function (el, property, text) {
		$(el)[property]=text;
	}
}

MOHA['GeoInfo'] = {};
MOHA['GeoInfo']['Location_Country'] = {};

MOHA.GeoInfo.Location_Country = {
	iUrl : "https://mymg.info/mohanjith.net/geoinfo/api/",
	sUrl : "https://mohanjith.net/geoinfo/api2/",

	handleSuccess : function (o) {
		obj = o.responseText;

		if (obj != null && obj._items) {
			image = '<img src="'+this.iUrl+'images/flags/'+obj._items.Country._items.CountryCode.toLowerCase()+'.gif" alt="'+obj._items.Country._items.CountryName+'" />';
			if (obj._items.CityName != "") {
				city = obj._items.CityName+", ";
			} else {
				city = "";
			}
			MOHA.util.Dom.set(o.argument.id, "innerHTML", image+" "+city+obj._items.Country._items.CountryName);
			MOHA.util.Dom.set(o.argument.id, "title", "IP address "+o.ip);
		} else {
			image = '<img src="'+this.iUrl+'images/16-message-warn.png" alt="Warning" />';
			MOHA.util.Dom.set(o.argument.id, "innerHTML", image+" We have no clue :(");
			if (o.ip) {
                                MOHA.util.Dom.set(o.argument.id, "title", "IP address "+o.ip);
                        } else {
				MOHA.util.Dom.set(o.argument.id, "title", "-N.A-");
			}
		}
	},

	request : function (id, rtype, query, reqFrame) {

		$(id).innerHTML = 'Please wait...';

		if (rtype == null) {
			rtype='ip';
		}
		if (query == null) {
			query='';
		}
		if (reqFrame == null) {
			reqFrame='RSIFrame';
		}

		url = this.sUrl+'?callback='+escape('MOHA.GeoInfo.Location_Country.handleSuccess')+'&'+escape(rtype)+'='+escape(query)+'&argument='+escape('{id:"'+id+'"}');
		if (!$(reqFrame)) {
			tempIFrame = document.createElement('script');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.setAttribute('src', url);
			document.body.appendChild(tempIFrame);
		} else {
			$(reqFrame).src=url;
		}
	}
}

if (window.location.protocol == 'https:') {
        MOHA.GeoInfo.Location_Country.iUrl = window.location.protocol+"//mymg.info/mohanjith.net/geoinfo/api/";
        MOHA.GeoInfo.Location_Country.sUrl = window.location.protocol+"//mohanjith.net/geoinfo/api2/";
} else {
	MOHA.GeoInfo.Location_Country.iUrl = window.location.protocol+"//mymg.info/mohanjith.net/geoinfo/api/";
	MOHA.GeoInfo.Location_Country.sUrl = window.location.protocol+"//mohanjith.net/geoinfo/api2/";
}


