$(document).ready(function(){
	//Show password
    $('#new_password_admin').hide();
    $('#new_password_admin_repeat').hide();
	$('#show_password').click(function() {
    	$('#new_password_admin').toggle('fast');
    	$('#new_password_admin_repeat').toggle('fast');
  	});

    //var my_tabs = $('#stat_page').tabs({ remote:true });
    //Choose tab in statistics..
    //my_tabs.tabs('select', parseInt($("#tabToChoose").html()));
    //$('#').MultiFile();
    
    //Mark all not closed questions..
    $('#mark_all_not_closed_questions').click(function() {
    	$("#all_not_closed_questions input:checkbox").each(function() {
    		this.checked = true;
    	});
  	});
    
    //Close questions..
    $('#close_marked_channels').click(function() {
    	$("not_closed_questions_ids").val("");
    	var current_value = "";
    	var i = 0;

    	$("#all_not_closed_questions input:checkbox").each(function() {
    		if(this.checked==true) { 
    			current_value = current_value + "," + this.id;
    			i++;
    		}
    	});
    	
    	//Are any checkboxes checked?
    	if(i>0) {
    		var dataString = 'postedFrom=not_closed_form&not_closed_questions_ids='+ current_value.substring(1);
    		//alert (dataString);return false;
    		$.ajax({
    			type: "POST",
    			url: "index.php",
    			data: dataString,
    			success: function() {
    				console.log(dataString);
    				$("#all_not_closed_questions_content").load("ajax_page.php?mode=all_not_closed_questions_content&page=1");
    			}
    		});
    	} else {
    		//do nothing..
    	}
    });
    
    //Sortable videos..
    $(".sortable_videos_and_screenshoots").sortable({
    	opacity:'0.6',
    	placeholder: 'liHover',
    	revert: 'true',
    	update: function(e,ui) { 
    		//Update list..
    		var list=$(this).sortable('toArray');
    		list=list.join(',');
    		$('#order_list_videos_images').val(list);

    		//Show save button..
    		$('#save_video_screenshot_order').show();
    	}
    });
    
    //Save changes in the order of news elements..
    $("#save_video_screenshot_order").click(function() {
    	$.get("ajax_page.php?mode=save_screenshot_video_order&list="+$("#order_list_videos_images").val()+"&question_id="+$("#question_id").html(), function(data){
    		$('#save_video_screenshot_order').hide();
    	});
    });
    
    //No enter in search form..
    $("#search").bind("keypress", function(e) {
    	if (e.keyCode == 13) return false;
    });
    
    /*
     * Confirm before delete
     */
    $('.delete').click(function(){
    	var answer = confirm($("#confirm_delete").html());
    	
    	if(!answer) {
    		$("#hidden_action").val("save");
    	}
    	return answer;
    }); 
});
