function refreshPage()
{
	var sURL = unescape(window.location.pathname);
	window.location.href = sURL;
	
}
function ajaxPost(serverUrl, contentParams)
{
   
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("global_ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	//dojo.byId("global_ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
}

function formPost(submitterId, serverUrl, formId, outputId, loaderId)
{
	
	
	
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			//dojo.byId(outputId).value = data;
					   			dojo.eval(data);
					   			dojo.byId(loaderId).style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,
					   form: formId,
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId(loaderId).style.display = "block";
	dojo.xhrPost(postParams);
	
	
}

function refreshBunches(serverUrl)
{

	//var contentParams = { "bunch_id": bunchId};	
	
	
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);	
}
function refreshBunchesFiltered(serverUrl)
{
	var filterTagId;
	filterTagId = dojo.byId('filter_tag_id');
	tagId = filterTagId.value;
	
	var contentParams = { "tag_id": tagId};	
	
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("tag_filter_loader").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	dojo.byId("tag_filter_loader").style.display = "block";
	dojo.xhrPost(postParams);	
}
function refreshBunchesandLoad(serverUrl, bunch_load_id)
{

	var contentParams = { "bunch_load_id": bunch_load_id};	
	
	
	var postParams = { url: serverUrl,
					   content:contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);	
}

function refreshBunchLinks(serverUrl, bunchId)
{

	var contentParams = { "bunch_id": bunchId};	
	
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);	
}
function loadBunch(serverUrl, bunchBoxId, bunchId)
{
	var selectedBoxId;
	var selectedBox;
	
	selectedBox = dojo.byId("selected_bunch_box_id");
	
	selectedBoxId = selectedBox.innerHTML;
	if (selectedBoxId == "")
	{
		selectedBoxId = -1;
	}
	var contentParams = { "bunch_box_id": bunchBoxId,
						  "bunch_id": bunchId,
						  "selected_bunch_box_id":  selectedBoxId };	
	
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId('bunch_links_loader').style.display = "none";
					   			dojo.byId('bunch_links_loadingpane').style.display = "";	
					   			dojo.byId('bunch_unapproved_links_loadingpane').style.display = "";	
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	//dojo.byId("ajax_loader").style.display = "block";
	
	/*highlight
	var highlight = dojo.animateProperty(
				    {
				    node: bunchBoxId,duration: 500,
			        properties: {
			        color:         { start: '#000000', end: '#000000' },
			        backgroundColor:{ start: '#eeee00', end: '#e5e6eb' }
					}
					});
					highlight.play();
	if (selectedBoxId != -1)
	{
		if (dojo.byId(selectedBoxId) != null)
		{
			dojo.byId(selectedBoxId).style.background = "none";	
		}
		

	}*/
	dojo.byId('bunch_links_bg_pane').style.display = "";
	//dojo.byId('bunch_share_pane').style.display = "";
	dojo.byId('bunch_links_loader').style.display = "block";
	dojo.byId('bunch_links_loadingpane').style.display ="none";
	dojo.byId('bunch_unapproved_links_loadingpane').style.display ="none";					
	dojo.xhrPost(postParams);
	
	
}

function loadEditModal(serverUrl, bunchlinkId)
{
	var contentParams = { "bunch_link_id":bunchlinkId  };	
	
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
}
function loadEditAccountModal(serverUrl)
{
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	dojo.byId("edit_account_form").style.display = "none";
	dijit.byId('edit_account_modal').show();
	dojo.byId("edit_account_form_loader").style.display = "block";
	dojo.xhrPost(postParams);
}
function loadAddbunchModal(serverUrl)
{
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("bunch_form").style.display = "none";
	dojo.byId('modal_bunch_form_loader').style.display = "block";
	dijit.byId('bunch_modal').show();
	dojo.xhrPost(postParams);
}

function addbunchModal(serverUrl)
{
//					   content: contentParams,

	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("modal_bunch_loader").style.display = "none";
					   			dojo.byId("addbunch_submit").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   form: "bunch_form",
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("addbunch_submit").style.display = "none";
	dojo.byId("modal_bunch_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
	return false;
}
function loadAddlinkModal(serverUrl, bunchId)
{
    var contentParams = { "bunch_id":bunchId};
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
	
}
function editbunchModal(serverUrl)
{
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("modal_bunch_loader").style.display = "none";
					   			dojo.byId("editbunch_submit").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   form: "bunch_form",
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("editbunch_submit").style.display = "none";
	dojo.byId("modal_bunch_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
	return false;
}
function editlinkModal(serverUrl)
{
	var contentParams = {  };	
	//"bunch_box_id": bunchBoxId
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("editlink_loader").style.display = "none";
					   			dojo.byId("editlink_submit").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   form: "editlink_form",
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("editlink_submit").style.display = "none";
	dojo.byId("editlink_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
	return false;
}

function addlinkModal(serverUrl)
{
	var contentParams = {  };	
	//"bunch_box_id": bunchBoxId
	
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("editlink_loader").style.display = "none";
					   			dojo.byId("addlink_submit").style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   form: "editlink_form",
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("addlink_submit").style.display = "none";
	dojo.byId("editlink_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
	return false;
}


function setRichTextContent(sourceEditorId, targetHiddenId)
{
	dojo.byId(targetHiddenId).value = dijit.byId(sourceEditorId).getValue(); 
}

function showDetails(linkContainerId)
{
	var wipeIn = dojo.fx.wipeIn({node: linkContainerId,duration: 255});
	wipeIn.play();	
}
function hideDetails(linkContainerId)
{
	var wipeOut = dojo.fx.wipeOut({node: linkContainerId,duration: 255});
	wipeOut.play();	
}

function loadEditBunchModal(serverUrl, bunchId)
{
	
	var inlineBunchId;
		inlineBunchId = dojo.byId('inline_bunch_id');
	var bunchId;
	if (bunchId == "") { bunchId = inlineBunchId.innerHTML; }
	
    var contentParams = { "bunch_id":bunchId};
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("bunch_form").style.display = "none";
	dojo.byId('modal_bunch_form_loader').style.display = "block";
	dijit.byId('bunch_modal').show();
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
}
function hideDetails(linkContainerId)
{
	var wipeIn = dojo.fx.wipeOut({node: linkContainerId,duration: 255});
	wipeIn.play();	
}





function ajaxFormPost(destinationUrl, formId, loaderId, submitId)
{
	var useAjaxLoader= true;
	var hideSubmitAction = true;

	if (loaderId===undefined) {     useAjaxLoader = false; }
	if (submitId===undefined) {     hideSubmitAction  = false; }

	var postParams = { url: destinationUrl,
                       load: function(data) {
                       dojo.eval(data);
                       //hide ajax loader
                       if (useAjaxLoader)    {dojo.byId(loaderId).style.display = "none";}
                       if (hideSubmitAction) {dojo.byId(submitId).style.display = "";} //block
                       },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       form:formId,
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };

	//show ajax loader
	if (hideSubmitAction) {dojo.byId(submitId).style.display = "none";}
	if (useAjaxLoader)    {dojo.byId(loaderId).style.display = "block";} //block
	dojo.xhrPost(postParams);
	
	return false;
	
}

function runBasicAjax(destinationUrl)
{
	var ajaxParams = { url: destinationUrl,
                       load: function(data) {
                       dojo.eval(data);
 			           },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };

	dojo.xhrPost(ajaxParams);	
}



function loadShareModal(serverUrl, bunchId)
{
    var contentParams = { "bunch_id":bunchId};
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
}

function updateBunchLinkName(destinationUrl,id, value)
{
	var contentParams = { "bunch_link_id": id,
						  "name": value};	
	//updatebunchlink	
	var ajaxParams = { url: destinationUrl,
					   content: contentParams,
                       load: function(data) {
                       dojo.eval(data);
 			           },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };

	dojo.xhrPost(ajaxParams);	
}

function updateBunchLink(destinationUrl, id, value) 
{
	var contentParams = { "bunch_link_id": id,
						  "link": value};	
	//updatebunchlink	
	var ajaxParams = { url: destinationUrl,
					   content: contentParams,
                       load: function(data) {
                       dojo.eval(data);
 			           },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };

	dojo.xhrPost(ajaxParams);	
}
function editorUpdateLink(destinationUrl, linkId)
{
	var contentParams = { "bunch_link_id": linkId,
						  "link_value": dojo.byId('editlink_'+linkId).value,
						  "link_name": dojo.byId('editname_'+linkId).value };	
	//updatebunchlink	
	var ajaxParams = { url: destinationUrl,
					   content: contentParams,
                       load: function(data) {
	                       dojo.eval(data);
	                       dojo.byId('update_link_loader_'+linkId).style.display = "none";
	                       dojo.byId('link_save_id_'+linkId).style.display = "";
 			           },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };
    dojo.byId('link_save_id_'+linkId).style.display = "none";    
	dojo.byId('update_link_loader_'+linkId).style.display = "block";
	dojo.xhrPost(ajaxParams);		
}
function expandBox(divId,timeDuration)
{
	var wipeIn = dojo.fx.wipeIn({node: divId,duration: timeDuration});
	wipeIn.play();

}
function shrinkBox(divId, timeDuration)
{
	var wipeOut = dojo.fx.wipeOut({node: divId,duration: timeDuration});
	wipeOut.play();
	
}
function slideUpBox(divId, timeDuration)
{
  var makeShorter = dojo.animateProperty(
    {
      node: divId,duration: timeDuration,
      properties: {
        height: {end: 10}
      }
    });
    makeShorter.play();

	
}

function hideElement(divId)
{
	dojo.byId(divId).style.display = "none";
}
function showElement(divId)
{
	dojo.byId(divId).style.display = "";
}

function fadeInBox(divId)
{
	
	dojo.fadeIn({
    node: divId,
    duration: 500,
    beforeBegin: function() {
        var node = dojo.byId(divId);
        dojo.style(node, "opacity", 0);
        dojo.style(node, "display", "block");
    }
	}).play();
}

function fadeOutBox(divId)
{
	var fadeOut = dojo.fadeOut({node: divId,duration: 1000});
	fadeOut.play();

}

function removeLink(serverUrl,linkId)
{	
	var confirmation = confirm("Are you sure you want to delete this link?");
	
	if (confirmation) 
	{
		var contentParams = { "link_id": linkId};
		var postParams = { url: serverUrl,
						   content: contentParams,
						   load: function(data) {
						   			dojo.eval(data);
						   			//dojo.byId("ajax_loader").style.display = "none";
						   },
						   error: function(data) {
						   			console.debug("An error occurred: ", data);
						   },
						   timeout: 200000,					   
						   headers: { "X-Requested-With": "XMLHttpRequest" }
		};
		
		//dojo.byId("ajax_loader").style.display = "block";
		dojo.xhrPost(postParams);
	}	
	
}


function updateBunchTitle(destinationUrl, bunchTitle) 
{
						
	if (bunchTitle != "")
	{
			
		var inlineBunchId;
		inlineBunchId = dojo.byId('inline_bunch_id');
	
		var contentParams = { "bunch_id": inlineBunchId.innerHTML,
							  "bunch_title": bunchTitle };
	
		//updatebunchlink	
		var ajaxParams = { url: destinationUrl,
						   content: contentParams,
	                       load: function(data) {
	                          dojo.eval(data);
	                          if (bunchTitle.length > 20)
	                          {
	                          	bunchTitle = bunchTitle.slice(1,20);
	                          } else {
	                          	dojo.byId('bunch_link_'+inlineBunchId.innerHTML).innerHTML = bunchTitle;	
	                          }
	                          
	 			           },
	                       error: function(data) {
	                       console.debug("An error occurred: ", data);
	                       },
	                       timeout: 200000,
	                       headers: { "X-Requested-With": "XMLHttpRequest" }
	        };
	
		dojo.xhrPost(ajaxParams);	
		
		
	
	}  
	
}
function loadaddLinksPublicModal(serverUrl, bunchId)
{
    var contentParams = { "bunch_id":bunchId};
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId('importlinks').value = '';
	dijit.byId('addlinks_modal').show();
	dojo.byId("importlinks_form_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
}
function loadaddLinksModal(serverUrl, bunchId)
{
    var contentParams = { "bunch_id":bunchId};
    
	var postParams = { url: serverUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId('importlinks').value = '';
	dijit.byId('addlinks_modal').show();
	dojo.byId("importlinks_form_loader").style.display = "block";
	dojo.xhrPost(postParams);
	
}
function generatebunch(serverUrl)
{
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);	
}

function createPublicBunch(serverUrl, loaderId, randId)
{
	var postParams = { url: serverUrl,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("create_bunch_loader").style.display = "none";
					   			//dojo.byId("new_public_bunch").style.display = "block";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	dojo.byId("new_public_bunch_"+randId).style.display = "none";
	dojo.byId(loaderId+"_"+randId).style.display = "block";
	dojo.xhrPost(postParams);	
}

function addComment(destinationUrl, id)
{
	var userName;
	var userComment;
	
	userName = dojo.byId('add_comment_name_'+id);
	userComment = dojo.byId('add_comment_'+id);
	
	var contentParams = { "bunch_link_id": id,
						  "user_comment": userComment.value,
						  "user_name": userName.value};	
	
	var ajaxParams = { url: destinationUrl,
					   content: contentParams,
                       load: function(data) {
                       dojo.eval(data);
                       dojo.byId("loader_add_comment_"+id).style.display = "none";
                       dojo.byId("link_add_comment_"+id).style.display = ""; 
 			           },
                       error: function(data) {
                       console.debug("An error occurred: ", data);
                       },
                       timeout: 200000,
                       headers: { "X-Requested-With": "XMLHttpRequest" }
        };
   
    dojo.byId("link_add_comment_"+id).style.display = "none";    
	dojo.byId("loader_add_comment_"+id).style.display = "block";
	dojo.xhrPost(ajaxParams);		
}

function loadComments(destinationUrl, bunchLinkId)
{
    var contentParams = { "bunch_link_id":bunchLinkId};
    
	var postParams = { url: destinationUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	//dojo.byId("ajax_loader").style.display = "block";
	dojo.xhrPost(postParams);
}

function loadCommentsPane(destinationUrl, bunchLinkId)
{
    var contentParams = { "bunch_link_id":bunchLinkId};
    
	var postParams = { url: destinationUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("curr_comment_loader_"+bunchLinkId).style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("curr_comment_loader_"+bunchLinkId).style.display = "block";
	dojo.xhrPost(postParams);
}


function loadsendtofriend(destinationUrl, bunchLinkId)
{
    var contentParams = { "bunch_link_id":bunchLinkId};
    
	var postParams = { url: destinationUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			//dojo.byId("ajax_loader").style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	dijit.byId('public_sendtofriend_modal').show();
	dojo.byId("public_sendtofriend_form_loader").style.display = "block";
	dojo.byId("public_sendtofriend_form").style.display = "none";
	dojo.xhrPost(postParams);
}

function loadWidget(destinationUrl, bunchId, publicKey)
{
    var contentParams = { "bunchId": bunchId,
                          "publicKey": publicKey};
    
	var postParams = { url: destinationUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dijit.byId('widget_modal').show();
	dojo.byId("widget_form_loader").style.display = "block";
	dojo.byId('widget_form').style.display = "none";
	dojo.xhrPost(postParams);	
}

function deleteBunch(destinationUrl, bunchId, publicKey)
{
	if (confirm('Are you sure you want to delete this bunch?'))
	{
		
	    var contentParams = { "bunchId": bunchId,
	                          "publicKey": publicKey};
	    
		var postParams = { url: destinationUrl,
						   content: contentParams,
						   load: function(data) {
						   			dojo.eval(data);
						   			
						   },
						   error: function(data) {
						   			console.debug("An error occurred: ", data);
						   },
						   timeout: 200000,					   
						   headers: { "X-Requested-With": "XMLHttpRequest" }
		};
		
	
		dojo.xhrPost(postParams);	
	}
		
}

function approveLink(destinationUrl, bunchLinkId)
{
    var contentParams = { "bunch_link_id": bunchLinkId};
	var postParams = { url: destinationUrl,
					   content: contentParams,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId("approve_loader_"+bunchLinkId).style.display = "none";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	
	dojo.byId("approve_loader_"+bunchLinkId).style.display = "block";
	dojo.xhrPost(postParams);
}

function clearDivContents(divId)
{
	dojo.byId(divId).innerHTML = "";	
}

function splashCreateBunch(serverUrl)
{
	
	var buildBunch;
	
	buildBunch = dojo.byId('build_bunch');

	var params = {"build_bunch_values":buildBunch.value};
	
	var postParams = { url: serverUrl,
					   content:params,
					   load: function(data) {
					   			dojo.eval(data);
					   			dojo.byId('splash_loader').style.display = "none";
					   			dojo.byId('button_build_bunch').style.display = "block";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	dojo.byId('button_build_bunch').style.display = "none";
	dojo.byId('splash_loader').style.display = "block";
	dojo.xhrPost(postParams);	
}

function followUser(serverUrl, bunchId, toFollow)
{
	var params = {"bunch_id":bunchId, "to_follow":toFollow};
	var postParams = { url: serverUrl,
					   content:params,
					   load: function(data) {
					   			dojo.eval(data);

					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};

	dojo.xhrPost(postParams);		
}

function loadSiteViewer(siteUrl)
{
	dojo.byId('site_viewer_iframe').src = siteUrl;
	dijit.byId('site_viewer_modal').show();
}

function followAdd(baseUrl, followedId, followerId)
{
	var followLoader;
	var followButton;
	var stopFollowButton;
	
	followLoader = dojo.byId('follow_loader');
	followButton = dojo.byId('button_follow_user');
	stopFollowButton = dojo.byId('button_stopfollow_user');
	
	var params = {"followedId":followedId, "followerId":followerId};
	var postParams = { url: baseUrl+"/follow/add",
					   content:params,
					   load: function(data) {
				   			dojo.eval(data);
				   			followButton.style.display = "none";
							followLoader.style.display = "none";
							stopFollowButton.style.display = "";
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	followButton.style.display = "none";
	followLoader.style.display = "block";
	dojo.xhrPost(postParams);		
}
function followRemove(baseUrl, followedId, followerId)
{
	var followLoader;
	var followButton;
	var stopFollowButton;
	
	followLoader = dojo.byId('follow_loader');
	followButton = dojo.byId('button_follow_user');
	stopFollowButton = dojo.byId('button_stopfollow_user');
	
	var params = {"followedId":followedId, "followerId":followerId};
	var postParams = { url: baseUrl+"/follow/remove",
					   content:params,
					   load: function(data) {
				   			dojo.eval(data);
				   			stopFollowButton.style.display = "none";
				   			followLoader.style.display = "none";
				   			followButton.style.display = "";
							
							
							
					   },
					   error: function(data) {
					   			console.debug("An error occurred: ", data);
					   },
					   timeout: 200000,					   
					   headers: { "X-Requested-With": "XMLHttpRequest" }
	};
	stopFollowButton.style.display = "none";
	followLoader.style.display = "block";
	dojo.xhrPost(postParams);		
}

