﻿/// <reference path="js/jquery-1.3.2-vsdoc.js" />

$(document).ready(function() {
	
	
	//Ajax loading display
	$(document).ajaxStart(function() {
		$('#loading_display_holder').slideDown("fast");
	});
	$(document).ajaxStop(function() {
		$('#loading_display_holder').slideUp("fast");
	});
	
	
    ////////////// Feedback alert
    var $alert = $('.slide_down_alert');

    if ($alert.length) {
        $alert.slideDown("fast");
    }

    $("#closeMsg").click(function() {
        $alert.slideUp("fast");
    });
    
    ////////////// End Alert
    
   
	////////////// Delete confirm
	
   	$(".deleteBtnConfirm").click(function(f){
		f.preventDefault();
		var theLoc = $(this).attr("href");
		var theItemName = $(this).attr("title");
		jConfirm('Are you sure you want to remove <strong>'+ theItemName +'</strong>.<br/><br/>This cannot be undone!', 'Delete Approval', function(r) {
			if( r == true){
				$.post(theLoc,{confirm_delete:"1"},function(){
				window.location.reload();
				});										
			}
		});
	});
	
	////////////// End Delete confirm	
	
	////////////// Edit confirm

	$(".editBtnConfirm").click(function(f){
		f.preventDefault();
		
		var theLoc = $(this).attr("href");
		var theItemType = $(this).attr("rel");
		var theItemName = $(this).attr("title");
		
		submitEditForm(theItemName);
		
		function submitEditForm(thePopupItemName){
		
		jPrompt('Enter a new '+ theItemType +' name.', thePopupItemName , 'Edit "'+ theItemName + '"', function(r) {
			
			var theEnteredName = r;
			
			if( r.length < 51 ){
				$.post(theLoc,{name:r},function(){
				window.location.reload();

			});										
		}else{
		jAlert("Please enter an "+ theItemType +" title less than 50 characters", 'Error',function(){
		submitEditForm(theEnteredName);
		
		});
		
		}
		});
		
		}
	});
	
	////////////// End edit confirm
	
});

