
function externalLinks() {
	$('a.external').click(function() {
		window.open(this.href);
		return false;
	});
}

var DateTime = {
	insertData : function(date) {
		var input = $("input.selectedInput").val(date);
		input.removeClass("selectedInput");
		$("#cal").hide();
	},
	removeCal : function(e) {
		$("#cal").hide();
		$("body").unbind("click");
	},
	showCal : function(e) {	
		$("body").unbind("click");
		$("input.calendar").each(function(index) {
			$(this).removeClass("selectedInput");
		});

		$("#cal").show();
		$(this).addClass("selectedInput");
		var obj = $(this).offset();

		$("#cal").css("left",obj.left);
		$("#cal").css("top",obj.top+25);

		var p = $(this).val().split(".");

		if(p==""){
			var mesic=2;
			var rok=2012;
		}
		else{
			var mesic=p[1];
			var rok=p[2];
		}		

		$.ajax({
			url: "/klub/updater/index$2299-showMonth.html?m=inputCalendar&amp;async=true",
			data: "month="+mesic+"&year="+rok,
			cache: false,
			success: function(html){
				$("#cal").html(html);
				$("body").bind("click",DateTime.removeCal);
			}
		});	
	},

	init : function() {
		$("body").append("<div id=\"cal\"></div>");
		$("input.calendar").each(function(index) {
			input=$(this);
			$(this).bind("click",DateTime.showCal);
		});
	}
}

function ajax(place, url) {
	$("body").unbind("click");
	$.ajax({
		url: url,
		cache: true,
		type: "POST",
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		success: function(html){
			$("#"+place).html(html);
			$("body").bind("click",DateTime.removeCal);
		}
	});
}

var LightBox = {
	init : function() {
		// lightbox init
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.55, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
		});
	}
}

var Efekty = {
	Filter: function(e) {	
		if($(this).hasClass("on")){			
			$(this).removeClass("on");
			$("#filter1").hide();
			//$("body").unbind("click");	
		}
		else{			
			$(this).addClass("on");		
			var obj = $(this).offset();
			if($("#filter1").hasClass('mini')){
				$("#filter1").css("left",obj.left-165);
			}
			else{
				$("#filter1").css("left",obj.left-295);
			}
			$("#filter1").css("top",obj.top+32);
			$("#filter1").show();	
			$("body").bind("click",Efekty.FilterOff);			
			$("#filter1").bind("click",Efekty.FilterOff);	
			$("#filter1 :image").unbind("click",function(){return true;});
			$("#filter1 :image").bind("click",function(){this.form.submit();});				
		}	
		return false;	
	},	
	FilterOff: function(e) {		
		if($(this).get(0).id=="filter1"){ return false; }
		else {
			$("#filter1").hide();	
			$("#filterLink").removeClass("on");
		}						
	},
		
	PostToogle: function(e) {
		 $(this).toggleClass("opened");
		 $("#postContentHolder").slideToggle("normal");
	},

	SearchVal : function(e) {
		if($(this).val() == "Vyhledávání"){ $(this).val(""); }
		else{ if($(this).val()==""){ $(this).val("Vyhledávání"); }}			
	},
		
	init : function() {
	
		// filter 
		$("#filterLink").bind("click", Efekty.Filter);
		// search hover			
		// $("#search").hover(	function() {$("#advance").show();},	function() {$("#advance").hide();});		
		
		//light on-off items
		$("#items div.item").each(function(index) {
			$(this).hover( function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});	
		$("#hpNews div.newsItem").each(function(index) {
			$(this).hover( function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});	

		$("#itemsGallery div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});			
		$("#itemsRelated div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});			
		$("#topAction div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		
		$("#domobiluContent div.row").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#mp3 tr").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#finishedContests tr").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#venues table tr").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#topDiscussion div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#contests div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#benefit div.item").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#fulltext div.r").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		$("#tickets div.leftItem, #tickets div.item, #tickets div.rightItem").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});
		
		
		//fix menu ie6
		$("#menu a").each(function(index) {
			$(this).hover(function() {$(this).addClass("hover");}, function() {$(this).removeClass("hover");});
		});		

		// discussion postComment	
		$("#postContent h3").bind("click", Efekty.PostToogle);		
		var openedHolder = gParam('parent_id');	
		if(openedHolder){ $("#postContentHolder").show(); }else{ $("#postContentHolder").hide(); }		

		//external links
		externalLinks();		
	
		//searchbox
		$("#searchInputText").bind("click", Efekty.SearchVal);
		$("#searchInputText").bind("blur", Efekty.SearchVal);

		var options = {
			//script:"http://o2extra2-edit.etnetera.o2/autocomplete/?language=cz&",			
			script:"/autocomplete/?language=cz&",
			varname:"prefix",
			json:true,
			shownoresults:false,
			timeout:10000,
			delay:500,
			maxresults:5
			//callback: function (obj) { document.getElementById('searchInputText').value = obj.id; }
		};
		var as_json = new bsn.AutoSuggest('searchInputText', options);
		
		$("div.section h2").each(function(e) {		 
			var id = $(this).attr('id');
			if(id){
			if ($(this).hasClass('open')){
				$("#"+id+"_content").show();
			}else {	$("#"+id+"_content").hide(); }

			$(this).bind("click",function(){ 
				if ($(this).hasClass('open')){					
					$(this).removeClass('open'); 
					$(this).addClass('close'); 
					$("#"+id+"_content").slideUp();			
				}
				else {					
					$(this).removeClass('close'); 
					$(this).addClass('open'); 
					$("#"+id+"_content").slideDown();
				}				
			});
			} //id			
		});

		$("div.section div.more").each(function(e) {		 
			var id = $(this).attr('id');
			if(id){
			if ($(this).hasClass('open')){
				$("#"+id+"_content").show();
			}else {	$("#"+id+"_content").hide(); }

			$(this).bind("click",function(){ 
				if ($(this).hasClass('open')){					
					$(this).removeClass('open'); 
					$(this).addClass('close'); 
					$("#"+id+"_content").slideUp();			
				}
				else {					
					$(this).removeClass('close'); 
					$(this).addClass('open'); 
					$("#"+id+"_content").slideDown();
				}				
			});
			} //id			
		});

		$("div.head a.main_button_container").each(function(e) {		 
			var id = $(this).attr('id');
			if(id){
			if ($(this).hasClass('open')){
				$("#"+id+"_content").show();
			}else {	$("#"+id+"_content").hide(); }

			$(this).bind("click",function(){ 
				if ($(this).hasClass('open')){					
					$(this).removeClass('open'); 
					$(this).addClass('close'); 
					$("#"+id+"_content").slideUp();			
				}
				else {					
					$(this).removeClass('close'); 
					$(this).addClass('open'); 
					$("#"+id+"_content").slideDown();
				}				
			});
			} //id			
		});	
	}
}


tooltipText="";
h =	$("#bubbleBig").height();
stT="";
var Tooltips = {	
	ShowTooltip : function(e) {
		var obj = $(this).offset();
		var h = $("#tooltip").height();	
		$("#tooltip").css("left",obj.left-83);
		$("#tooltip").css("top",obj.top-h-10);
		
		if ($(this).get(0).title) {
			$("#tooltipData").html($(this).get(0).title);
			tooltipText = $(this).attr("title");
			$(this).get(0).title="";
		}
		else {		
			$("#tooltipData").html($(this).parent().get(0).title);
			tooltipText = $(this).parent().attr("title");
			$(this).parent().get(0).title="";
		}		
		$("#tooltip").show();		
	},
	
	ShowTooltipMove : function(e) {
		var obj = $(this).offset();
		var h = $("#tooltip").height();	
		$("#tooltip").css("left",e.pageX-83);
		$("#tooltip").css("top",e.pageY-h-10);
	}, 
	
	HideTooltip : function(e) {	
		$(this).get(0).title = tooltipText;
		$("#tooltip").hide();		
	},

	// -- gal HP

	ShowTooltipGal : function(e) {
		var obj = $(this).offset();
		$("#tooltipGal").css("left",obj.left-73);
		$("#tooltipGal").css("top",obj.top-70);
		
		if ($(this).get(0).title) {
			$("#tooltipDataGal").html($(this).get(0).title);
			tooltipText = $(this).attr("title");
			$(this).get(0).title="";
		}
		else {		
			$("#tooltipDataGal").html($(this).parent().get(0).title);
			tooltipText = $(this).parent().attr("title");
			$(this).parent().get(0).title="";
		}		
		$("#tooltipGal").show();		
	},
	
	ShowTooltipMoveGal : function(e) {
		var obj = $(this).offset();
		$("#tooltipGal").css("left",e.pageX-73);
		$("#tooltipGal").css("top",e.pageY-85);
	}, 
	
	HideTooltipGal : function(e) {	
		$(this).get(0).title = tooltipText;
		$("#tooltipGal").hide();		
	},	

	// -- mini

	ShowTooltipMini : function(e) {
		var obj = $(this).offset();
		$("#tooltipMini").css("left",obj.left-50);
		$("#tooltipMini").css("top",obj.top-35);
		$("#tMC").html($(this).html());		
		$("#tooltipMini").show();		
	},
	
	ShowTooltipMoveMini : function(e) {
		var obj = $(this).offset();
		$("#tooltipMini").css("left",e.pageX-50);
		$("#tooltipMini").css("top",e.pageY-35);
	}, 
	
	HideTooltipMini : function(e) {	$("#tooltipMini").hide(); },

	
	// -- big tooltips /span .i
	
	ShowTooltipBig : function(e) {
		 $("body").unbind("click");

		var obj = $(this).offset();		
		if ($(this).get(0).title) {
			$("#bubbleContentHolder").html($(this).get(0).title);
			tooltipText = $(this).attr("title");
			h = $("#bubbleBig").height();
			$("#bubbleBig").css("left",obj.left-102);
			$("#bubbleBig").css("top",obj.top-h-12);
			$("#bubbleBig").show();				
		}	
		$(this).bind("mouseout", function(){$("body").bind("mouseup", Tooltips.HideTooltipBig);});
		return false;
	},	
		
	HideTooltipBig : function(e) { $("#bubbleBig").hide(); },	
	
	init : function() {
		var tool = document.createElement("div");
		tool.id = "tooltip";
		var p = document.createElement("p");
		p.id = "tooltipData";
		tool.appendChild(p);
		$("body")[0].appendChild(tool);

		$("body").append("<div id=\"tooltipGal\"><p id=\"tooltipDataGal\"></p>");
		$("body").append("<div id=\"bubbleBig\"><div id=\"bubbleContent\"><div id=\"bubbleContentHolder\"></div></div></div>");
		$("body").append("<div id=\"tooltipMini\"><div id=\"tMC\"></div></div>");

		$(".tooltip").each(function(index) {
			$(this).bind("mouseover", Tooltips.ShowTooltip);
			$(this).bind("mousemove", Tooltips.ShowTooltipMove);
			$(this).bind("mouseout", Tooltips.HideTooltip);
		});

		$(".tooltipGal").each(function(index) {
			$(this).bind("mouseover", Tooltips.ShowTooltipGal);
			$(this).bind("mousemove", Tooltips.ShowTooltipMoveGal);
			$(this).bind("mouseout", Tooltips.HideTooltipGal);
		});

		$(".tooltipMini").each(function(index) {
			$(this).bind("mouseover", Tooltips.ShowTooltipMini);
			$(this).bind("mousemove", Tooltips.ShowTooltipMoveMini);
			$(this).bind("mouseout", Tooltips.HideTooltipMini);
		});

		// .i span na vypisu galerii
		$("a.i").each(function(index) {
			$(this).bind("click", Tooltips.ShowTooltipBig);
		});
		$("body").bind("click", Tooltips.HideTooltipBig);	
	}	
}


var PrettySelect = {
	
	createUl : function(id, name, value, parent) {
		
		var hiddenInput = document.createElement("input");
		hiddenInput.id = name;	
		hiddenInput.name = name;
		hiddenInput.value = value;
		hiddenInput.type = "hidden";
		
		var ul = document.createElement("ul");	
		ul.id = "ul_"+id;
		$(ul).addClass("pretty");
		var i = 0;				
		var lastItem = $("#"+id+" option").length;			
		
		$("#"+id+" option").each(function(){
			var li = document.createElement("li");
			li.alt = $(this).attr("value");
			
			if($(this).attr('selected')){
				$(li).addClass('selected');	
			}			
			//li.innerHTML = $(this).html();				
			$(li).html($(this).html());				
			$(li).hide();					
			
			if(i==0){ 
				$(li).addClass('first');
				$(li).bind("click",function(){
				if($(this).hasClass('open')){						
				$(this).removeClass('open');
				PrettySelect.hideLi(id);	
					}
					else{
						$(this).addClass('open');
						$("#ul_"+id+" li").each(function(){
							$(this).show();	
						});							
					}		
				})
				$(li).show();	
			}
			else{
				$(li).bind("click",function(){
					$("#ul_"+id+" li.first").html($(this).html());
					$("#ul_"+id+" li.first").removeClass('open');
					hiddenInput.value =  $(this).attr('alt');//naplneni novou hodnotou
					PrettySelect.deselect(id);//odznaceni selectovane css
					$(this).addClass('selected');	//oznaceni zvolene
					PrettySelect.hideLi(id);//skryti vsech li		
				});					
			}
			if(i+1==lastItem){ $(li).addClass('last'); }
			
			ul.appendChild(li);
			i++;
				
		});			
		var prettyHolder = $(parent); 
		prettyHolder.append($(ul));
		prettyHolder.append($(hiddenInput));
	},		
		
	hideLi : function(id){		
		$("#ul_"+id+" li").each(function(){
			if(!$(this).hasClass('first')){
				$(this).hide();
			}								
		});
	},
		
	deselect : function(id){
		$("#ul_"+id+" li").each(function(){
			if(!$(this).hasClass('first')){
				$(this).removeClass('selected');
			}								
		});		
	},		
		
	init : function() {		
		$("select.pretty").each(function(){		
			var name = $(this).attr("name");
			var value = $(this).attr("value");
			var parent = $(this).parent();
			$(parent).css('position','relative');	
			PrettySelect.createUl($(this).attr("id"), name, value, parent);	
			$(this).remove();			
		});		
		$('input[type=radio]').prettyCheckboxes();		
	}	
}


function gParam(param) {
  param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+param+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return results[1];
}


	var myNews = new Array();
	var myLink = new Array();

	function fc() {
		var myId = $("#nL");
		myId.fadeOut("slow");		
		st2 = setTimeout("changeNews()",1000)
	}
	
	var num = 0;
	function changeNews() {
		var myId = $("#nL");
		myId.fadeIn("slow");

		var myCount = myNews.length;			
		num++; if (num > myCount-1) {num = 0}
		
		myId.html('<a href="'+myLink[num]+'">'+ myNews[num] + '</a>');
		var st1 = setTimeout("fc()",5000);	
	}



function newWindow(src,x,y) { 
	return window.open(src,'_blank','width='+x+',height='+y+',resizable=yes,scrollbars=yes');
}
function newPopup(src,x,y) {
	return window.open(src,'_blank','width='+x+',height='+y+',top=300,left=400,resizable=no,scrollbars=no,statusbar=yes');
}

function openWallpaper(v) { if(v!=""){ window.open(v); return false; } }


(function($) {
	/**
	 * attaches a character counter to each textarea element in the jQuery object
	 * usage: $("#myTextArea").charCounter(max, settings);
	 */
	
	$.fn.charCounter = function (max, settings) {
		max = max || 100;
		settings = $.extend({
			container: "<span></span>",
			classname: "charcounter",
			format: "Zbýva %1 znaků.",
			pulse: true,
			delay: 0
		}, settings);
		var p, timeout;
		
		function count(el, container) {
			el = $(el);
			if (el.val().length > max) {
			    el.val(el.val().substring(0, max));
			    if (settings.pulse && !p) {
			    	pulse(container, true);
			    };
			};
			if (settings.delay > 0) {
				if (timeout) {
					window.clearTimeout(timeout);
				}
				timeout = window.setTimeout(function () {
					container.html(settings.format.replace(/%1/, (max - el.val().length)));
				}, settings.delay);
			} else {
				container.html(settings.format.replace(/%1/, (max - el.val().length)));
			}
		};
		
		function pulse(el, again) {
			if (p) {
				window.clearTimeout(p);
				p = null;
			};
			el.animate({ opacity: 0.1 }, 100, function () {
				$(this).animate({ opacity: 1.0 }, 100);
			});
			if (again) {
				p = window.setTimeout(function () { pulse(el) }, 200);
			};
		};
		
		return this.each(function () {
			var container = (!settings.container.match(/^<.+>$/)) 
				? $(settings.container) 
				: $(settings.container)
					.insertAfter(this)
					.addClass(settings.classname);
			$(this)
				.bind("keydown", function () { count(this, container); })
				.bind("keypress", function () { count(this, container); })
				.bind("keyup", function () { count(this, container); })
				.bind("focus", function () { count(this, container); })
				.bind("mouseover", function () { count(this, container); })
				.bind("mouseout", function () { count(this, container); })
				.bind("paste", function () { 
					var me = this;
					setTimeout(function () { count(me, container); }, 10);
				});
			if (this.addEventListener) {
				this.addEventListener('input', function () { count(this, container); }, false);
			};
			count(this, container);
		});
	};
})(jQuery);


var AsyncCalendar = function(calEl) {
    var calendar = $(calEl);
    var loadSuccess = function(data, textStatus) {
	calendar.replaceWith(data);
	new AsyncCalendar(document.getElementById("calendar"));
    };
    var updateCalendar = function(href) {
	var url = "/klub/updater/index$2293-showMonth.html"
	url += "?m=calendar&";
	url += href.replace(/^.*\?/,'');
	$.ajax({
	    url : url,
	    success : loadSuccess
	});
    };
    calendar.find("#previousMonth a , #nextMonth a").click(function(){
	updateCalendar(this.href);
	return false;
    });
};


jQuery.fn.ajaxSubmit = function(foo, conf) {
        var config = {
                method: false,  // request method (get/post) defaults to form's
                action: false,  // action (url) defaults to form's
                loading: 'Loading...'
        };
        config = jQuery.extend(config, conf);

        var callback = (typeof(foo) === 'string') ? function(data) {jQuery(foo).html(data);} : (typeof(foo) === 'function') ? foo : false;

        return this.each(function() {
                var form = jQuery(this);

                if(form.is('form')) {
                        var method = config.method || form.attr('method');
                        var action = config.action || form.attr('action');
                        var submit = jQuery('input[type="submit"]', form);
                        var data = {};

                        form.submit(function() {
                                jQuery('*[name]', form).each(function() {
                                        var t = jQuery(this);
                                        var val = (t.attr('type') == 'checkbox') ? (t.attr('checked') == true) ? 1 : 0 : t.val();
                                        data[t.attr('name')] = val;
                                });
                                submit.val(config.loading);
                                jQuery[method](action, data, function(data) {
                                        callback(data);
                                });

                                return false;
                        });
                }
        });
};


/* ------------------------------------------------------------------------
	prettyCheckboxes	
	Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
	Inspired By: All the non user friendly custom checkboxes solutions ;)
	Version: 1.0.1	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */
	
	jQuery.fn.prettyCheckboxes = function(settings) {
		settings = jQuery.extend({
					checkboxWidth: 16,
					checkboxHeight: 16,
					className : 'prettyCheckbox',
					display: 'list'
				}, settings);

		$(this).each(function(){
			// Find the label
			$label = $('label[for="'+$(this).attr('id')+'"]');
			// Add the checkbox holder to the label
			$label.prepend("<span class='holderWrap'><span class='holder'></span></span>");
			// If the checkbox is checked, display it as checked
			if($(this).is(':checked')) { $label.addClass('checked'); };
			// Assign the class on the label
			$label.addClass(settings.className).addClass($(this).attr('type')).addClass(settings.display);
			// Assign the dimensions to the checkbox display
			$label.find('span.holderWrap').width(settings.checkboxWidth).height(settings.checkboxHeight);
			$label.find('span.holder').width(settings.checkboxWidth);
			// Hide the checkbox
			$(this).addClass('hiddenCheckbox');
			// Associate the click event
			$label.bind('click',function(){
				$('input#' + $(this).attr('for')).triggerHandler('click');
				
				if($('input#' + $(this).attr('for')).is(':checkbox')){
					$(this).toggleClass('checked');
					$('input#' + $(this).attr('for')).checked = true;
				}else{
					$toCheck = $('input#' + $(this).attr('for'));

					// Uncheck all radio
					$('input[name="'+$toCheck.attr('name')+'"]').each(function(){
						$('label[for="' + $(this).attr('id')+'"]').removeClass('checked');	
					});

					$(this).addClass('checked');
					$toCheck.checked = true;
				};
			});
			
			$('input#' + $label.attr('for')).bind('keypress',function(e){
				if(e.keyCode == 32){
					if($.browser.msie){
						$('label[for="'+$(this).attr('id')+'"]').toggleClass("checked");
					}else{
						$(this).trigger('click');
					}
					return false;
				};
			});
		});
	};


function createMarker(point, html) {
	bounds.extend(point);
	var o2Icon = new GIcon(G_DEFAULT_ICON);
   // 	o2Icon.image = "";
   //   o2Icon.iconSize = new GSize(25, 25);

	// Set up our GMarkerOptions object
	markerOptions = { icon:o2Icon };
	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	GEvent.addListener(marker,"mouseover", function() {
		marker.openInfoWindowHtml(html);
	});
	map.addOverlay(marker);
	map.setZoom(map.getBoundsZoomLevel(bounds) - 1);
	map.setCenter(bounds.getCenter());
}


function fbs_click(url) {u=url;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
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;
	}
}



