
/**
 * JS :: Webusr
 *
 * Webusr.js
 *
 * @version        $1.0$
 * @autor   	   $Peter Benicky$
 * @lastmodified   $06.04.2007$
 */
 
function Webusr(webroot) {
	webThis = this;
	this.server = webroot;
	this.css_images = webroot+'css/user/images/';
	this.axajRequest = null;
	this.initialize();
}

Webusr.prototype.initialize = function() {
	$('#loading').hide();
	$('.disable_user').hide();	
	$('.short_news > li > p').hide();
	$("input[name=search]").bind('click', webThis.search);
	$("input[name=log_in]").bind('click', webThis.login);
	$("input[name=compete]").bind('click', webThis.compete);
	$("input[name=comment]").bind('click', webThis.comment);
	$("input[name=add_party]").bind('click', webThis.addParty);
	$("input[name=file]").bind('change', webThis.change);
	$("input[name=photo]").bind('change', webThis.changePhoto);
	$("input[name=save_artist_setting]").bind('click', webThis.saveArtist);
	$("input[name=registration]").bind('click', webThis.registration);
	$("input[name=forgot_password]").bind('click', webThis.forgot_password);
	$("input[name=save_setting]").bind('click', webThis.saveSetting);
	$("input[name=message]").bind('click', webThis.sendMessage);
	$("input[name=award_send]").bind('click', webThis.award);
	$("a.answer").bind('click', webThis.vote);
 	$(".star-rating > li > a").bind('click', webThis.rate);
	$("a.add_to_freind").bind('click', webThis.addFreind);
	$('a.view_map').toggle(webThis.showMap, webThis.hideMap);
	$("a.join_party").bind('click', webThis.joinParty);
	$('a.view_message').toggle(webThis.viewMessage, webThis.hideMessage);
 	$('a.view_news').toggle(webThis.viewNews, webThis.hideNews);
	$('a.received_message').toggle(webThis.viewMessageReceived, webThis.hideMessage);
	$('a.delete_message').bind('click', webThis.delMessage);
	$('a.not_accepts').bind('click', webThis.delMessage);
	$('a.delete_freind').bind('click', webThis.delFreind);
	$('a.delete_file').bind('click', webThis.delPhoto);
	$('a.mark_event').toggle(webThis.unmarkEvent, webThis.markEvent);
	$('a.unmark_event').toggle(webThis.markEvent, webThis.unmarkEvent);
	$('a.msg_mark').toggle(webThis.markMsg, webThis.unmarkMsg);
	$('a.msg_unmark').toggle(webThis.unmarkMsg, webThis.markMsg);
	$('a.listen').bind('click', webThis.showListen);
	$('a.recommended').bind('click', webThis.showRecommended);
	$('a.delete_visitor').bind('click', webThis.delVisitor);
	$('a.delete_marked').bind('click', webThis.deleteMarked);
	$('li.parent').hover(webThis.showSubmenu, webThis.hideSubmenu);
	$('a.flash_news').toggle(webThis.showFlashnews, webThis.hideFlashnews);
	$('a.help_button').toggle(webThis.showHelp, webThis.hideHelp);
	$('a.recent_button').toggle(webThis.showRecentComments, webThis.hideRecentComments);
	$('a.visited_parties').toggle(webThis.showVisited, webThis.hideVisited);
	$('a.all_freinds').toggle(webThis.showVisited, webThis.hideVisited);
	$('a#back_to_top').bind('click', webThis.toTop);
	$('a#crop_photo').bind('click', webThis.cropPhoto);
	$('a.quote_comment').bind('click', webThis.quoteComment);
	$('a.delete_comment').bind('click', webThis.deleteComment);
	$('a.add_recipient').bind('click', webThis.addRecipient);
	$('a.add_to_top').toggle(webThis.addTop, webThis.removeTop);
	$('a.remove_from_top').toggle(webThis.removeTop, webThis.addTop);
 	$('#status li a').bind('click', webThis.getFriends);
}
Webusr.prototype.addTop = function() {
	var link = this;
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'freinds/add-to-top/'+link.rel,
		success: function(msg){
    		$(link).empty().append('Remove from top');
   		}
	});
	return false;
}
Webusr.prototype.removeTop = function() {
	var link = this;
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'freinds/remove-from-top/'+link.rel,
		success: function(msg){
    		$(link).empty().append('Add to top');
   		}
	});
	return false;
}
Webusr.prototype.search = function() {
	$('#loading').show();
	if($("input.search_input").get(0).value == ''){
		$('div#msg_user').empty().append('<p class="warning">You must enter string for search!</p>').fadeIn("slow");
		$('#loading').hide();
		return false;
	}
}
Webusr.prototype.toTop = function() {
	window.scroll(0,0);
	return false;
}
Webusr.prototype.viewAll = function() {
	$('.disable_user').show();
	return false;
}
Webusr.prototype.showFlashnews = function() {
	var li = $(this).parent();
	$("a", li).css("font-weight", "bold");
	$("a", li).css("color", "#5EB4FF");
	$("p", li).slideDown('fast');
	return false;
}
Webusr.prototype.hideFlashnews = function() {
	var li = $(this).parent();
	$("a", li).css("font-weight", "normal");
	$("a", li).css("color", "");
	$("p", li).slideUp('fast');
	return false;
}
Webusr.prototype.showSubmenu = function() {
	var self = this;
    var ul = $("ul", this);
	ul.show();
	return false;
}

Webusr.prototype.hideSubmenu = function() {
	var self = this;
    var ul = $("ul", this);
	ul.hide();
	return false;
}
Webusr.prototype.showHelp = function() {
	$('#recent_comments').remove();
	$('#visited_parties_div').empty();
	var help = '<h3>BBcode</h3><p>For formating your posts use bbcode. See examples bellow.</p><ul><li>[b]Bold[/b]</li><li>[i]Italic[/i]</li><li>[u]Underline[/u]</li><li>[quote]Some quote[/quote]</li><li>[url=http://www.dnb.sk]dnb[/url]</li></ul><div>';
	var valueT = 0, valueL = 0;
	var element = this;
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	$('form.form').after('<div style="position: absolute; top: '+(valueT + 32)+'px; margin-left: 360px" id="comment_help">' + help);
	return false;
}
Webusr.prototype.showMap = function() {
	var valueT = 0, valueL = 0;
	var element = this;
	var id = this.id.substring(this.id.indexOf('-') + 1);
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	$("#viewmap-"+id).show();
	$("#viewmapview-"+id).show();
	$("#viewmap-"+id).css("top", (valueT + 32)+'px');
	$("#viewmapview-"+id).css("top", (valueT +32)+'px');
	$(this).html("Hide map");
	return false;
}
Webusr.prototype.hideMap = function(){
	var id = this.id.substring(this.id.indexOf('-') + 1);
	$("#viewmap-"+id).hide();
	$("#viewmapview-"+id).hide();
	$(this).html("View map");
	return false;
}
Webusr.prototype.showRecentComments = function() {
	$('#comment_help').remove();
	$('#visited_parties_div').empty();
	$('#loading').show();
	var valueT = 0, valueL = 0;
	var element = this;
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	webThis.ajaxRequest = $.ajax({
		url: this.href,
		success: function(msg){
    		$('form.form').after('<div style="position: absolute; top: '+(valueT + 32)+'px;  margin-left: 338px" id="recent_comments">' + msg + '</div>');
    		$('#loading').hide();
   		}
	});
	return false;
} 
Webusr.prototype.showVisited = function() {
	$('#comment_help').remove();
	$('#recent_comments').remove();
	$('#visited_parties_div').empty();
	$('#loading').show();
	var valueT = 0, valueL = 0;
	var element = this;
	var id = 'visited_parties';
	var href = this.href;
	var margin = '100';
	if ($(this).attr('class') == "all_freinds") {
		var id = 'all_freinds';
		href = this.href + 'all/';
		margin= "0";
	}
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	webThis.ajaxRequest = $.ajax({
		url: href,
		success: function(msg) {
    		$('#visited_parties_div').append('<div style="position: absolute; top: '+(valueT + 15)+'px; margin-left: '+margin+'px" id="'+id+'">' + msg + '</div>');
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.hideVisited = function() {
	$('#comment_help').remove();
	$('#recent_comments').remove();
	$('#visited_parties_div').empty();
	return false;
}
Webusr.prototype.hideHelp = function(){
	$('#comment_help').remove();
	$('#recent_comments').remove();
	$('#visited_parties_div').empty();
	return false;
}
Webusr.prototype.hideRecentComments = function() {
	$('#comment_help').remove();
	$('#recent_comments').remove();
	$('#visited_parties').remove();
	return false;
}
Webusr.prototype.viewMessage = function() {
	var id = this.rel.substring(this.rel.indexOf('-') + 1);
	$(this).empty().append('- Roll in');
	$('p#'+this.rel).slideDown('fast');
	return false;
}

Webusr.prototype.viewNews = function() {
	var id = this.rel.substring(this.rel.indexOf('-') + 1);
	$(this).empty().append('- Roll in');
	$('img#perex_small-'+id).hide();
	$('img#perex-'+id).show();
	$('p#'+this.rel).slideDown('fast');
	return false;
}

Webusr.prototype.hideNews= function() {
	var id = this.rel.substring(this.rel.indexOf('-') + 1);
	$(this).empty().append('+ Roll out');
	$('img#perex-'+id).hide();
	$('img#perex_small-'+id).show();
	$('p#'+this.rel).slideUp('fast');
	return false;
}

Webusr.prototype.viewMessageReceived = function() {
	$(this).empty().append('- Roll in');
	$('p#'+this.rel).slideDown('fast');
	var id = this.rel.substring(this.rel.indexOf('-') + 1);
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'messages/read/'+id+'/'
	});
	return false;
}
Webusr.prototype.cropPhoto = function() {
	$('#loading').show();
	var url = 'users';
	if((this.href.search('artists')) != -1)
		url = 'artists';
	window.location.href = ""+webThis.server+url+'/photo/crop/?x='+$("input[name=x]").val()+'&y='+$("input[name=y]").val()+'&width='+$("input[name=width]").val()+'&height='+$("input[name=height]").val()+"";
	return false;
}
Webusr.prototype.delMessage = function() {
	$('#loading').show();
	var id = this.rel
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('li#'+id).fadeOut('normal');
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.delFreind = function() {
	$('#loading').show();
	var id = this.rel
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('li#'+id).fadeOut('normal');
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.delPhoto = function() {
	$('#loading').show();
	var id = this.rel
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
			$('div#msg_form').empty().append(msg).fadeIn("slow");
    		$('tr#'+id).fadeOut('normal');
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.markEvent = function() {
	$('#loading').show();
	var id = this.id.substring(this.id.indexOf('-') + 1);
	var uniq = this.id;
	var artist_id = this.rel;
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'artist_events/mark/'+artist_id+'/'+id+'/',
		success: function(msg){
    		$('a#'+uniq).css({ background: 'url('+webThis.css_images+'mark_event.gif) no-repeat' });
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.unmarkEvent = function() {
	$('#loading').show();
	var id = this.id.substring(this.id.indexOf('-') + 1);
	var uniq = this.id;
	var artist_id = this.rel;
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'artist_events/unmark/'+artist_id+'/'+id+'/',
		success: function(msg){
    		$('a#'+uniq).css({ background: 'url('+webThis.css_images+'delete_photo.gif) no-repeat' });
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.markMsg = function() {
	$('#loading').show();
	var id = this.id.substring(this.id.indexOf('-') + 1);
	var uniq = this.id;
	var type = this.rel;
	if($('#message-'+id).hasClass("received")) {
		$('#message-'+id).removeClass("received");
		webThis.ajaxRequest = $.ajax({
			url: webThis.server+'messages/read/'+id+'/'
		});
	}
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'messages/mark/'+id+'/'+type+'/true/',
		success: function(msg){
    		$('#message-'+id).addClass("marked");
    		$('a#'+uniq).empty().append("Unmark");
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.unmarkMsg = function() {
	$('#loading').show();
	var id = this.id.substring(this.id.indexOf('-') + 1);
	var uniq = this.id;
	var type = this.rel;
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'messages/unmark/'+id+'/'+type+'/true/',
		success: function(msg){
    		$('#message-'+id).removeClass("marked");
    		$('a#'+uniq).empty().append("Mark");
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.deleteMarked = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: this.href+'true/',
		success: function(msg){
			var del = msg.split(",");
			for (key in del)
			{
				if(del[key] != "")
					$('#message-'+del[key]).fadeOut('normal');
			}
    		$('#loading').hide();
   		}
	});
	$('#loading').hide();
	return false;	
}
Webusr.prototype.showListen = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'news/quick/listen/true/',
		success: function(msg){
    		$('#news_list .parties').empty().append(msg);
    		$('#news_list .listen').addClass('active');
    		$('#news_list .recommended').removeClass('active');
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.showRecommended = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: webThis.server+'news/quick/recommended/true/',
		success: function(msg){
    		$('#news_list .parties').empty().append(msg);
    		$('#news_list .listen').removeClass('active');
    		$('#news_list .recommended').addClass('active');
    		$('#loading').hide();
   		}
	});
	return false;	
}
Webusr.prototype.delVisitor = function() {
	$('#loading').show();
	var id = this.rel
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
			$('div#msg_form').empty().append(msg).fadeIn("slow");
    		$('tr#'+id).fadeOut('normal');
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.hideMessage = function() {
	$(this).empty().append('+ Roll out');
	$('p#'+this.rel).slideUp('fast');
	return false;
}

Webusr.prototype.login = function() {
	$('#loading').show();
	var login = $('input[name=login]').get(0).value;
	var password = webThis.sha1($('input[name=password]').get(0).value);
	$.post(
		webThis.server+'users/login/', 
		{login: login, password: password, ajax: true},
		function(msg){
			if(msg != 'success')
    			$('div#msg_user').empty().append(msg).fadeIn("slow");
    		else
    			location.reload(true);
    	$('#loading').hide();
   		}
	);
	return false;
}
Webusr.prototype.getFriends = function() {
	$('#loading').show();
	var status = $(this).attr('title');
	var link = this;
	$.post(
		webThis.server+'freinds/', 
		{status: status, ajax: link.rel},
		function(msg){
			$('#freind_list > ul').not('#status').empty().append(msg);
			$('#status > li > a').removeClass();
			$(link).addClass('active');
    		$('#loading').hide();
   		}
	);
	return false;
}
Webusr.prototype.saveSetting = function() {
	$('#loading').show();
	if($('input[name=file_fake]').get(0).value == '' && $('input[name=file_fake_photo]').get(0).value == '' ) {
		var sex = $('input[name=sex]:checked').get(0).value;
		var notification = $('input[name=notification]:checked').get(0).value;
		var age = $('input[name=age]').get(0).value;
		var name = $('input[name=name]').get(0).value;
		var location = $('input[name=location]').get(0).value;
		var new_password_retyped = $('input[name=new_password_retyped]').get(0).value;
		var new_password = $('input[name=new_password]').get(0).value;
		if(new_password != '' || new_password_retyped != '') {
			new_password_retyped = webThis.sha1(new_password_retyped);
			new_password = webThis.sha1(new_password); 
		}
		var about = $('textarea[name=about]').get(0).value;
		$.post(
			webThis.server+'users/save_settings/', 
			{sex: sex, age: age, name: name, location: location, new_password_retyped: new_password_retyped, new_password: new_password, about: about, notification: notification, ajax: true},
			function(msg){
		   		$('div#msg_form').empty().append(msg).fadeIn("slow");
		   		$('#loading').hide();
		   		window.scroll(0,0);
	  		}
		);
		return false;
	}
}
Webusr.prototype.award = function() {
	$('#loading').show();
	$('div#msg_form').empty();
	var valueT = 0, valueL = 0;
	var element = document.getElementById('msg_form');
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	var dj_e = $('input[name=dj_e]').get(0).value;
	var mc_e = $('input[name=mc_e]').get(0).value;
	var dj_w = $('input[name=dj_w]').get(0).value;
	var mc_w = $('input[name=mc_w]').get(0).value;
 	var producent_e = $('input[name=producent_e]').get(0).value;
	var track = $('input[name=track]').get(0).value;
	var label = $('input[name=label]').get(0).value;
	var beginer = $('input[name=beginer]').get(0).value;
	var producent_w = $('input[name=producent_w]').get(0).value;
	var track_w = $('input[name=track_w]').get(0).value;
	var source_w = $('input[name=source_w]').get(0).value;
	var album_w = $('input[name=album_w]').get(0).value;
	var source_e = $('input[name=source_e]').get(0).value;
	var festival_e = $('input[name=festival_e]').get(0).value;
	var club_e = $('input[name=club_e]').get(0).value;
	var party_e = $('input[name=party_e]').get(0).value;
	var user_id = $('input[name=user_id]').get(0).value;
	var round = $('input[name=round]').get(0).value;
	if($('input[name=source]:checked').val())
		var source = $('input[name=source]:checked').get(0).value;
	else
	    var source = '';
	if($('select[name=dj] :selected').val())
		var dj = $('select[name=dj] :selected').val();
	else
	    var dj = '';
	if($('input[name=mc]:checked').val())	
		var mc = $('input[name=mc]:checked').get(0).value;
	else
		var mc = '';
	if($('input[name=producent]:checked').val())
		var producent = $('input[name=producent]:checked').get(0).value;
	else
		var producent = '';
	if($('input[name=club]:checked').val())
	    var club = $('input[name=club]:checked').get(0).value;
	else
	    var club = '';
	if($('input[name=party]:checked').val())
	    var party = $('input[name=party]:checked').get(0).value;
	else
	    var party = '';
	if($('input[name=festival]:checked').val())
	    var festival = $('input[name=festival]:checked').get(0).value;
	else
	    var festival = '';
	if((dj == '' && dj_e == 'iný') || (dj == '' && dj_e == ''))
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší slovenský drum and bassový DJ roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
	   	return false;
	}
	if((producent == '' && producent_e == 'iný') || (producent == '' && producent_e == ''))
	{
	    $('div#msg_form').empty().append('<p class="warning_big">Pole najlepší slovenský drum and bassový producent roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
	    return false;
	}
	if(dj_w == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší zahraničný drum and bassový DJ roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
	    return false;
	}
	if(track == "" || track == "Producent - Skladba") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepšia dnb skladba roka 2008 od slovenského producenta je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
	    return false;
	}
  	if((party == '' && party_e == 'iná') || (party == '' && party_e == ''))
  	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole pravidelná klubová noc roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
	  	window.scroll(0, valueT);
		$('#loading').hide();
    	return false;
  	}
  	if((club == '' && club_e == 'iný') || (club == '' && club_e == ''))
  	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole klub roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
	  	window.scroll(0, valueT);
		$('#loading').hide();
    	return false;
  	}
  	if((festival == '' && festival_e == 'iný') || (festival == '' && festival_e == ''))
 	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole festival roka 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
    	return false;
  	}
  	if((source == '' && source_e == 'iný') || (source == '' && source_e == ''))
  	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najobľúbenejší domáci zdroj informacíí o dnb v roku 2008 je povinné. Vyplň ho prosím.</p>').fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
    	return false;
  	}
  $.post(
  	webThis.server+'awards/add/', 
    {round: round, user_id: user_id, beginer: beginer, dj: dj, mc: mc, dj_w: dj_w, mc_w: mc_w, producent: producent, track: track, label: label, producent_w: producent_w, track_w: track_w, source_w: source_w, album_w: album_w, source_e: source_e, festival_e: festival_e, dj_e: dj_e, mc_e: mc_e, producent_e: producent_e, club_e: club_e, party_e: party_e, source: source, club: club, party: party, festival: festival, ajax: true},
	function(msg){
		$('div#msg_form').empty().append(msg).fadeIn("slow");
		window.scroll(0, valueT);
		$('#loading').hide();
		$('input[name=dj]').attr('checked', "");
		$('input[name=mc]').attr('checked', "");
		$('input[name=dj_w]').val('');
		$('input[name=mc_w]').val('');
		$('input[name=track]').val('Producet - Skladba');
		$('input[name=track_w]').val('Producet - Skladba');
		$('input[name=producent]').attr('checked', "");
		$('input[name=album_w]').val('');
		$('input[name=producent_w]').val('');
		$('input[name=label]').val('');
		$('input[name=source_w]').val('');
		$('input[name=source_e]').val('iný');
		$('input[name=party_e]').val('iná');
		$('input[name=club_e]').val('iný');
		$('input[name=dj_e]').val('iný');
		$('input[name=mc_e]').val('iný');
		$('input[name=producent_e]').val('iný');
		$('input[name=festival_e]').val('iný');
		$('input[name=festival]').attr('checked', "");
		$('input[name=party]').attr('checked', "");
		$('input[name=club]').attr('checked', "");
		$('input[name=source]').attr('checked', "");
	}
	);
	return false;
}
Webusr.prototype.award_1 = function() {
	$('#loading').show();
	$('div#msg_form').empty()
	var user_id = $('input[name=user_id]').get(0).value;
	var round = $('input[name=round]').get(0).value;
	if($('input[name=dj]:checked').val())
	    var dj = $('input[name=dj]:checked').get(0).value;
	else
	    var dj = '';
	if($('input[name=dj_w]:checked').val())
	    var dj_w = $('input[name=dj_w]:checked').get(0).value;
	else
	    var dj_w = '';
	if($('input[name=track]:checked').val())
	    var track = $('input[name=track]:checked').get(0).value;
	else
	    var track = '';
	if($('input[name=track_w]:checked').val())
	    var track_w = $('input[name=track_w]:checked').get(0).value;
	else
	    var track_w = '';
	if($('input[name=mc_w]:checked').val())
	    var mc_w = $('input[name=mc_w]:checked').get(0).value;
	else
	    var mc_w = '';
	if($('input[name=mc]:checked').val())
	    var mc = $('input[name=mc]:checked').get(0).value;
	else
	    var mc = '';
	if($('input[name=producent]:checked').val())
	    var producent = $('input[name=producent]:checked').get(0).value;
	else
	    var producent = '';
	if($('input[name=producent_w]:checked').val())
	    var producent_w = $('input[name=producent_w]:checked').get(0).value;
	else
	    var producent_w = '';
	if(dj == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší slovenský drum and bassový DJ roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	   	return false;
	}
	if(producent == "") 
	{
	    $('div#msg_form').empty().append('<p class="warning_big">Pole najlepší slovenský drum and bassový producent roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(mc == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší slovenský drum and bassový MC je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(dj_w == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší zahraničný drum and bassový DJ roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(mc_w == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepší zahraničný drum and bassový MC roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(producent_w == "") 
	{
	    $('div#msg_form').empty().append('<p class="warning_big">Najlepší zahraničný drum and bassový producent roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(track == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepšia dnb skladba roka 2008 od slovenského producenta je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
	if(track_w == "") 
	{
		$('div#msg_form').empty().append('<p class="warning_big">Pole najlepšia zahraničná dnb skladba roka 2008 je povinné. Vyznač ho prosím.</p>').fadeIn("slow");
		window.scroll(0,0);
		$('#loading').hide();
	    return false;
	}
  $.post(
  	webThis.server+'awards/add/2/', 
    {round: round, user_id: user_id, dj: dj, mc: mc, dj_w: dj_w, mc_w: mc_w, producent: producent, track: track, producent_w: producent_w, track_w: track_w, ajax: true},
	function(msg){
		$('div#msg_form').empty().append(msg).fadeIn("slow");
		$('#loading').hide();
		$('input[name=dj]').attr('checked', "");
		$('input[name=mc]').attr('checked', "");
		$('input[name=producent]').attr('checked', "");
		$('input[name=track]').attr('checked', "");
		$('input[name=dj_w]').attr('checked', "");
		$('input[name=mc_w]').attr('checked', "");
		$('input[name=producent_w]').attr('checked', "");
		$('input[name=track_w]').attr('checked', "");
		window.scroll(0,0);
	}
	);
	return false;
}
Webusr.prototype.saveArtist = function() {
	$('#loading').show();
	var name = $('input[name=name]').get(0).value;
	
	if(name == '') {
		$('div#msg_form').empty().append('<p class="warning_big message_margin">Type your name please!</p>').fadeIn("slow");
		$('#loading').hide();
		window.scroll(0,0);
		return false;
	}
	
	if(!$("input:checked").length) {
		$('div#msg_form').empty().append('<p class="warning_big message_margin">Select your country please!</p>').fadeIn("slow");
		$('#loading').hide();
		window.scroll(0,0);
		return false;	
	}
		
	return true;
}

Webusr.prototype.sendMessage = function() {
	$('#loading').show();
	var to = $('input[name=to]').get(0).value;
	var subject = $('input[name=subject]').get(0).value;
	var user_id = $('input[name=user_id]').get(0).value;
	var message = $('textarea[name=message]').get(0).value;
	if(message == '' || subject == '' || to == '')
	{
		$('div#msg_form').empty().append('<p class="warning_big">You left some empty fields, fill it first!</p>').fadeIn("slow");
		return false;
	}
	$.post(
		webThis.server+'messages/send/', 
		{to: to, subject: subject, user_id: user_id, message: message, ajax: true},
		function(msg) {
		   	$('div#msg_form').empty().append(msg).fadeIn("slow");
			$('textarea[name=message]').val("");
			$('input[name=subject]').val("");
		   	$('#loading').hide();
	  	}
		);
	return false;
}

Webusr.prototype.change = function() {
	$('input[name=file_fake]').get(0).value = $('input[name=file]').get(0).value;
	return false;
}

Webusr.prototype.changePhoto = function() {
	$('input[name=file_fake_photo]').get(0).value = $('input[name=photo]').get(0).value;
	return false;
}
Webusr.prototype.compete = function() {
	$('#loading').show();
	var answer = $('textarea[name=answer]').get(0).value;
	if(answer == '') {
		$('div#msg_form').empty().append('<p class="warning_big">You must enter answer to compete!</p>').fadeIn("slow");
		$('#loading').hide();
		return false;
	}
	var name = $('input[name=name]').get(0).value;
	if(name == '') {
		$('div#msg_form').empty().append('<p class="error_big">You must have filled name in your profile to compete!</p>').fadeIn("slow");
		$('#loading').hide();
		return false;
	}
	var user_id = $('input[name=user_id]').get(0).value;
	var competition_id = $('input[name=competition_id]').get(0).value;
	$.post(
		webThis.server+'competition_answers/compete/', 
		{answer: answer, user_id: user_id, competition_id: competition_id, name: name, ajax: true},
		function(msg){
    		$('div#msg_form').empty().append(msg).fadeIn("slow");
    		$('#loading').hide();
   		}
	);
	return false;
}

Webusr.prototype.comment = function() {
	$('#loading').show();
	var comment = $('textarea[name=comment]').get(0).value;
	var subject = $('input[name=subject]').get(0).value;
	if(comment == '' || subject == '') {
		$('div#msg_form').empty().append('<p class="warning_big">You left some empty fields, fill it first!</p>').fadeIn("slow");
		$('#loading').hide();
		return false;
	}
}
Webusr.prototype.quoteComment = function() {
	var body = $('li#comment-'+this.rel + ' .comment_body').text();
	var quote =  $('li#comment-'+this.rel + ' .quote').text();
	body = body.replace(quote,"");
	body = body.replace("\n","");
	$('textarea[name=comment]').val('[quote][b]'+$('li#comment-'+this.rel + ' .comment_user').text()+' said:[/b]\n'+body+'[/quote]');
	var valueT = 0, valueL = 0;
	var element = document.getElementById('msg_form');
	do {
	 	valueT += element.offsetTop  || 0;
	    valueL += element.offsetLeft || 0;
	    element = element.offsetParent;
	} while (element);
	window.scroll(0, valueT);
	return false;
}
Webusr.prototype.addRecipient = function() {
	if($('input[name=to]').val() == '')
		$('input[name=to]').val(this.rel);
	else
		$('input[name=to]').val($('input[name=to]').val() + '; ' + this.rel);
	return false;
}
Webusr.prototype.deleteComment = function() {
	$('#loading').show();
	var id = this.rel;
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
			$('div#msg_form').empty().append(msg).fadeIn("slow");
			if ((msg.search('error')) == -1) 
				$('li#comment-' + id + '').fadeOut("slow");
    		$('#loading').hide();
   		}
	});
	return false;
}
Webusr.prototype.addParty = function() {
	$('#loading').show();
 	var lineup = $('textarea[name=lineup]').get(0).value;
 	var club = $('input[name=club]').get(0).value;
	var city = $('input[name=city]').get(0).value;
	var state = $('input[name=state]').get(0).value;
	var price = $('input[name=price]').get(0).value;
	var link = $('input[name=link]').get(0).value;
	var link_map = $('input[name=link_map]').get(0).value;
	var start = $('input[name=start]').get(0).value;
	var end = $('input[name=end]').get(0).value;
	var date = $('input[name=date]').get(0).value;
	var user_id = $('input[name=user_id]').get(0).value;
	var name = $('input[name=name]').get(0).value;
 	if(lineup == '' || name == '' || club == '' || city == ''  || state == '' || date == '') {
 		$('div#msg_form').empty().append('<p class="warning_big message_margin">You left some empty fields, fill it first!</p>').fadeIn("slow");
 		$('#loading').hide();
 		window.scroll(0,0);
 		return false;
 	}
 	 if($('input[name=file_fake]').get(0).value == '') {
		$.post(
			webThis.server+'parties/add/', 
			{club: club, city: city, name: name, state: state, price: price, link: link, link_map: link_map, start: start, end: end, date: date, user_id: user_id, lineup: lineup, ajax: true},
			function(msg){
		   		$('div#msg_form').empty().append(msg).fadeIn("slow");
		   		$('#loading').hide();
		   		window.scroll(0,0);
	  		}
		);
		return false;
	}	 
}

Webusr.prototype.vote = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('div#msg_inquiry').empty().append(msg).fadeIn("slow");
    		$('#loading').hide();
   		}
	});
	return false;
}

Webusr.prototype.rate = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('div#msg_form').empty().append(msg).fadeIn("slow");
    		$('#loading').hide();
   		}
	});
	return false;
}

Webusr.prototype.addFreind = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('div#msg_form').empty().append(msg).fadeIn("slow");
    		var valueT = 0, valueL = 0;
			var element = document.getElementById('msg_form');
			do {
			 	valueT += element.offsetTop  || 0;
			    valueL += element.offsetLeft || 0;
			    element = element.offsetParent;
			} while (element);
			window.scroll(0, valueT);
    		$('#loading').hide();
   		}
	});
	return false;
}

Webusr.prototype.joinParty = function() {
	$('#loading').show();
	webThis.ajaxRequest = $.ajax({
		url: this.href+Math.random()+'/',
		success: function(msg){
    		$('div#msg_form').empty().append(msg).fadeIn("slow");
    		var valueT = 0, valueL = 0;
			var element = document.getElementById('msg_form');
			do {
			 	valueT += element.offsetTop  || 0;
			    valueL += element.offsetLeft || 0;
			    element = element.offsetParent;
			} while (element);
			window.scroll(0, valueT);
    		$('#loading').hide();
   		}
	});
	return false;
}

Webusr.prototype.forgot_password = function() {
	$('#loading').show();
	var login = $('input[name=username]').get(0).value;
	var email = $('input[name=email]').get(0).value;
	var answer = $('input[name=answer]').get(0).value;
	if(login == '' || email == '' || answer == '') {
    	$('div#msg_form').empty().append('<p class="warning_big message_margin">You left some empty fields, fill it first!</p>').fadeIn("slow");
    	$('#loading').hide();
    	return false;
   	}
}

Webusr.prototype.registration = function() {
	$('#loading').show();
	var login = $('input[name=username]').get(0).value;
	var email = $('input[name=email]').get(0).value;
	var passwd = $('input[name=passwd]').get(0).value;
	var password_retyped = $('input[name=password_retyped]').get(0).value;
	var answer = $('input[name=answer]').get(0).value;
	
	if(passwd == '' || password_retyped == '' || login == '' || email == '' || answer == '') {
    	$('div#msg_form').empty().append('<p class="warning_big message_margin">You left some empty fields, fill it first!</p>').fadeIn("slow");
    	$('#loading').hide();
    	return false;
   	}
   	
	if(!login.match(/^[A-Za-z0-9_-]+$/)) {
		$('div#msg_form').empty().append('<p class="error_big message_margin_info">You entered invalid login! Only A-Z, 0-9, \'_\' chars allowed!</p>').fadeIn("slow");
		$('#loading').hide();
    	return false;;
	}
			
	if(login.length < 3 || login.length > 15) {
		$('div#msg_form').empty().append('<p class="error_big message_margin_info">You entered invalid login! Login length must be betwean 3 and 15!</p>').fadeIn("slow");
		$('#loading').hide();
    	return false;;
	}
   	
   	if(!email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
		$('div#msg_form').empty().append('<p class="error_big message_margin">You entered invalid e-mail address!</p>').fadeIn("slow");
		$('#loading').hide();
    	return false;
	}
			
	if(passwd != password_retyped) {
		$('div#msg_form').empty().append('<p class="error_big message_margin">Passwords does not match!</p>').fadeIn("slow");
		$('#loading').hide();
    	return false;
	}
}

Webusr.prototype.sha1 = function(msg) {

	function rotate_left(n,s) {
		var t4 = ( n<<s ) | (n>>>(32-s));
		return t4;
	};

	function lsb_hex(val) {
		var str="";
		var i;
		var vh;
		var vl;

		for( i=0; i<=6; i+=2 ) {
			vh = (val>>>(i*4+4))&0x0f;
			vl = (val>>>(i*4))&0x0f;
			str += vh.toString(16) + vl.toString(16);
		}
		return str;
	};

	function cvt_hex(val) {
		var str="";
		var i;
		var v;

		for( i=7; i>=0; i-- ) {
			v = (val>>>(i*4))&0x0f;
			str += v.toString(16);
		}
		return str;
	};


	function Utf8Encode(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;
	};

	var blockstart;
	var i, j;
	var W = new Array(80);
	var H0 = 0x67452301;
	var H1 = 0xEFCDAB89;
	var H2 = 0x98BADCFE;
	var H3 = 0x10325476;
	var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;

	msg = Utf8Encode(msg);

	var msg_len = msg.length;

	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}

	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;

		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;

		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}

	word_array.push( i );

	while( (word_array.length % 16) != 14 ) word_array.push( 0 );

	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );


	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {

		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

		A = H0;
		B = H1;
		C = H2;
		D = H3;
		E = H4;

		for( i= 0; i<=19; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=20; i<=39; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=40; i<=59; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=60; i<=79; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		H0 = (H0 + A) & 0x0ffffffff;
		H1 = (H1 + B) & 0x0ffffffff;
		H2 = (H2 + C) & 0x0ffffffff;
		H3 = (H3 + D) & 0x0ffffffff;
		H4 = (H4 + E) & 0x0ffffffff;

	}

	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

	return temp.toLowerCase();
}