/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var baseURL = 'http://smakpracy.pl/';

function showAuthWindow(name){
    if(name == null) {
        $("div.auth_window").slideDown();
    }
    else {
        $("div#"+name).slideDown();
    }
}
function hideAuthWindow() {
    $("div.auth_window").hide();
}
/**
 *Otwiera dialog boxa
 */
function open_dialog() {
    $('div#dialog').dialog("open");
}
/**
 * Użytkownicy do zaznaczenia
 */
function change_users_for_remove(){
    $("input[name='users_for_remove']").val('');
    $("input[name='user_operation']:checked").each(function(){
        $("input[name='users_for_remove']").val($("input[name='users_for_remove']").val()+$(this).val()+"|");
    });
}
/**
 * Select all
 */
function toggle_all() {
    if($("input[name='select_all']").is(":checked")) {
        //zaznaczenie wszystkich
        $("input[name='user_operation']").each(function(){
            $(this).attr("checked", true);
        });
        change_users_for_remove();
    }
    else {
        //odznaczenie wszystkich
        $("input[name='user_operation']").each(function(){
            $(this).attr("checked", false);
        });
        change_users_for_remove();
    }
}



function rvote(vote, id)  {
	$('#cvote_' + id).html("Chwila");
	$.ajax({
      type: "POST",
      url: baseURL + 'glosuj_komentarz',
      data: 'vote=' + vote + '&id=' + id, 
      complete: function (XMLHttpRequest, textStatus) {
    	  $('#cvote_' + id).html(XMLHttpRequest.responseText);
		}
    });		
}


function newsletter_post () {
	$('#newsletter_info').show().html("Przesyłam zgłoszenie...");
	$("#newsletter_submit").hide();
	
	$.ajax({
      type: "POST",
      url:  baseURL + 'newslettera/subscribe_popup',
      data: 'newsletter_email=' + $("#newsletter_email").val() + '&newsletter_accept_rules=' + $("#newsletter_accept_rules:checked").val(), 
      complete: function (XMLHttpRequest, textStatus) {
			var response = XMLHttpRequest.responseText.split("||");
			if(response[0] == "0") {
				$("#newsletter_submit").show();
			}
			$('#newsletter_info').html(response[1]);
		}
    });	
}

function append_comment_form(post, comment) {
	
	if (!$('#comment_new_' + comment).length) {
		var divinput = $("<div>").addClass('comment_content_input')
			.append($("<label>").html("Dodaj wypowiedź do tego wątku"))
			.append($("<textarea>").addClass('comment_content').attr('id', 'comment_content_' + comment).attr('name', 'comment_content'));
	
		var divsubmit = $("<div>").addClass('comment_submit_button')
			.append($("<input>").attr('type', 'submit').attr('id', 'comment_submit_' + comment).attr('name', 'comment_submit').attr('value', 'Odpowiedz'));
	
		var div = $("<div>").addClass('comment_new').attr('id', 'comment_new_' + comment).css('display', 'none')
			.append($("<form>").addClass('add_comment_form').attr('action', baseURL + 'home/save_comment/' + post + '/' + comment).attr('method','post').append(divinput).append(divsubmit)
		)
		
		$('#comment_form_' + comment) . append(div);
	    

		
		div.show('slow', function () {$("#comment_content_" + comment).textareaCount({'originalStyle': 'originalDisplayInfo', 'maxCharacterSize': 500});});
		
	}
	
	$.scrollTo('#comment_new_' + comment, {duration: 300, offset: -100});
}

