SOCJUM_FANS_WIDGET = 
{
	society_url : "",
	society_disp: "Widget Socjum",
	fans_count  : 9,
	iframe_url  : '',
	_height  	: 250,
	_init 		: function() 
	{ 
		var html = '<iframe  id="socjum_fans_widget_iframe" name="socjum_fans_widget_iframe"  frameborder="0"  vspace="0"  hspace="0"  marginwidth="0"  marginheight="0" scrolling="no" height='+this._height+' onload="autoIframe(\'socjum_fans_widget_iframe\');"></iframe>';
		document.write(html);
		this._load();
	},
	_config 	: function(society_url, society_disp, fans_count, height, width) 
	{
		this.society_url 	= society_url == undefined || society_url == '' || society_url;
		this.society_disp 	= encodeURIComponent(encodeURI(escape(society_disp)));
		this.fans_count 	= fans_count;	
		this._height 		= height;	
		this._width 		= width;	
		this.iframe_url		= 'http://'+this.society_url+'/fans_widget/display/'+this.society_url+'/'+this.society_disp+'/'+this.fans_count;
		
	},
	_load		: function()
	{	 
		document.getElementById('socjum_fans_widget_iframe').src=this.iframe_url;
		
		var parent = document.getElementById('socjum_fans_widget_iframe').parentNode;
		if(isNaN(this._width) || this._width<180) 
		{
			var width = parent.style.width.replace('px','');
			var width = width.replace('%','');
			document.getElementById('socjum_fans_widget_iframe').width  = width;
		}
		else
			document.getElementById('socjum_fans_widget_iframe').width  = this._width;
		
		var myIFrame = document.getElementById('socjum_fans_widget_iframe');
		var content = myIFrame.contentWindow.document.body.innerHTML;
		//document.getElementById('socjum_fans_widget_iframe').height = height;
	}
};

function autoIframe(frameId)
{
	try
	{
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
	}
	catch(err)
	{
		window.status = err.message;
	}
}


   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            alert(http_request.responseText);
            result = http_request.responseText;
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function check_url(url) {
      var poststr = "myurl=" + escape( encodeURI( url ) );
      makePOSTRequest('http://ckujawa.socjumx.net/check_url.php', poststr);
   }
   
   var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}



