
function show_add_endorsement()
{
	getObj('endorsement_form').style.display = '';
	getObj('add_endorsement_link').style.display = 'none';
}

function hide_add_endorsement(hide_add_endorsement_link)
{
	getObj('endorsement_form').style.display = 'none';
	if(!hide_add_endorsement_link)
		getObj('add_endorsement_link').style.display = '';
}

function addEndorsement()
{
	
	if(!document.add_endorsement["end[RELATIONSHIP]"].value)
	{
		alert("Unable to add endorsement - No relationship");
		return false;
	}
	
	if(!document.add_endorsement["end[FOR_EXCHANGE_PROFILE_ID]"].value)
	{
		alert("Unable to add endorsement - No profile id found");
		return false;
	}
	
	if(!document.add_endorsement["end[ENDORSEMENT]"].value || document.add_endorsement["end[ENDORSEMENT]"].length < 1)
	{
		alert("Unable to add endorsement - Please Provide endorsement text");
		return false;
	}
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 
				'endorsement':true,
				'type':'add',
				'for_profile_id':document.add_endorsement["end[FOR_EXCHANGE_PROFILE_ID]"].value, 
				'relationship':document.add_endorsement["end[RELATIONSHIP]"].value,
				'endorsement':document.add_endorsement["end[ENDORSEMENT]"].value
				 },
			'onSuccess': function(oResponse)
					 {
					 	getObj('endorsement_td').innerHTML = "<BR><BR>Your endorsement has "+
					 		"been submitted and is awaiting approval from this member.";
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to leave an endorsement for this member");
					 }
		} 
	);
	
	
}

function approveEndorsement(ex_endorsement_id)
{
	
	if(!ex_endorsement_id)
	{
		alert("Unable to approve endorsement - No endorsement id");
		return false;
	}
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 
				'endorsement':true,
				'type':'approve',
				'ex_endorsement_id':ex_endorsement_id 
				 },
			'onSuccess': function(oResponse)
					 {
					 	getObj('approve_end_button'+ex_endorsement_id).innerHTML = "<IMG SRC='images/buttons/approved_sm.gif' BORDER=0 VSPACE=3>";
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to approve this endorsement");
					 }
		} 
	);
}

function makeEndorsementPrivate(ex_endorsement_id)
{
	if(!ex_endorsement_id)
	{
		alert("Unable to make endorsement private- No endorsement id");
		return false;
	}
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 
				'endorsement':true,
				'type':'make_private',
				'ex_endorsement_id':ex_endorsement_id 
				 },
			'onSuccess': function(oResponse)
					 {
					 	
					 	getObj('end_pubpriv_button'+ex_endorsement_id).innerHTML = "<A HREF='' "+
					 		"onClick='makeEndorsementPublic("+ex_endorsement_id+"); return false;' onMouseOver='ttWidth=200; "+
					 		"return escape(\"Clicking here will enable other members to see this endorsement on your profile "+
							"At any time in the future you can opt to make it private.\");' CLASS='end_action_links'>"+
							"<IMG src='images/buttons/make_public_sm.gif' hsrc='images/buttons/make_public_sm1.gif' BORDER=0></A>";
							//alert(getObj('end_pubpriv_button'+ex_endorsement_id).innerHTML);
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to make this endorsement private");
					 }
		} 
	);
}

function makeEndorsementPublic(ex_endorsement_id)
{
	if(!ex_endorsement_id)
	{
		alert("Unable to make endorsement public- No endorsement id");
		return false;
	}
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 
				'endorsement':true,
				'type':'make_public',
				'ex_endorsement_id':ex_endorsement_id 
				 },
			'onSuccess': function(oResponse)
					 {
					 	getObj('end_pubpriv_button'+ex_endorsement_id).innerHTML = "<A HREF='' "+
					 		"onClick='makeEndorsementPrivate("+ex_endorsement_id+"); return false;' onMouseOver='ttWidth=200; "+
					 		"return escape(\"Clicking here will enable other members to see this endorsement on your profile "+
							"At any time in the future you can opt to make it private.\");' CLASS='end_action_links'>"+
							"<IMG src='images/buttons/make_private_sm.gif' hsrc='images/buttons/make_private_sm1.gif' BORDER=0></A>";
							//alert(getObj('end_pubpriv_button'+ex_endorsement_id).innerHTML);
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to make this endorsement private");
					 }
		} 
	);
}

function deleteEndorsement(ex_endorsement_id)
{
	if(!ex_endorsement_id)
	{
		alert("Unable to delete endorsement - No endorsement id");
		return false;
	}
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 
				'endorsement':true,
				'type':'delete',
				'ex_endorsement_id':ex_endorsement_id 
				 },
			'onSuccess': function(oResponse)
					 {
					 	getObj('endorsement_row_'+ex_endorsement_id).innerHTML = "";
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to delete this endorsement");
					 }
		} 
	);
}