$j.ajaxSetup({ 
	     beforeSend: function(xhr, settings) {
	         function getCookie(name) {
	             var cookieValue = null;
	             if (document.cookie && document.cookie != '') {
	                 var cookies = document.cookie.split(';');
	                 for (var i = 0; i < cookies.length; i++) {
	                     var cookie = jQuery.trim(cookies[i]);
	                     // Does this cookie string begin with the name we want?
	                 if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                     cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                     break;
	                 }
	             }
	         }
	         //alert(cookieValue);
	         return cookieValue;
	         }
	         if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
	             // Only send the token to relative URLs i.e. locally.
	             xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
	         }
	     } 
	});

/*#-----------------------------------------------------------------
# Function: favorite_artist(key_name)
# Created: 
# Last Modified: 2-8-2011
# Purpose:
# 	Send an AJAX request to the server to favorite an artist
#-----------------------------------------------------------------*/

function follow(kind, pk, bval) {

	if (bval == 'true') {
   		 var url = '/follow/' + kind + '/' + pk + '?follow=true';
   		}
   	else if (bval == 'false') {
   		 var url = '/follow/' + kind + '/' + pk + '?follow=false';
   		}	

    //$j("#follow_artist").load(url, {artist_key_name: artist_key_name});
    $j("#follow").load(url);
    
}

/*#-----------------------------------------------------------------
# Function: remove_favorite_div(key_name)
# Created: 
# Last Modified: 11-24-2009
# Purpose:
# 	Send an AJAX request to the server to favorite an artist
#-----------------------------------------------------------------*/

function remove_favorite_div(artist_key_name) {
    var url = '/artist/favorite/' + artist_key_name + '/?value=add';
    $("#favorite_artist").load(url, {artist_key_name: artist_key_name});
    //$("#favorite_artist").load("" + url + " " + artist_key_name  + "");
    
}

/*#-----------------------------------------------------------------
# Function: remove_form_input(key_name)
# Created: 2-22-2010
# Last Modified:  2-24-2010
# Purpose:
# 	Remove an input box from a form
#-----------------------------------------------------------------*/

function remove_form_input(form_id) {
  		// Prevent against JQuery conflict.
		var $j = jQuery.noConflict();
	
 		$j('#' + form_id).fadeTo("fast", 0.01, function(){ //fade
        	$j(this).slideUp("medium", function() { //slide up
            	$j(this).remove(); //then remove from the DOM
             });
         });

		if (form_id == 'artist_div_1') {
			element = document.getElementById('a');			
			new_div = "<div class=\"form-line\" ><a href=\"#\" onClick=\"add_artist(this,1);\" class=\"form\" ";
			new_div += "id=\"artist_add_0\" title=\"Add another artist\">Add Artist</a></div>";
			$j(element).after(new_div);
	
			}

	}
	
/*#-----------------------------------------------------------------
# Function: update_venue_list(obj, web_key, toggle)
# Created: 
# Last Modified: 7-4-2011
# Purpose:
# 	
#-----------------------------------------------------------------*/

function show_modal_box() {

		//transition effect     
		$j('#mask').fadeTo("medium",0.7);  

    	//if mask is clicked
    	$j('#mask').click(function () {
       	 	$j(this).hide();
       	 	$j('#dialog').hide();
    	});  

}
