function share_deal(thread_id){
	document.getElementById('share_deal').innerHTML = "<img id='loading' src='/images/loading.gif'/>";
	toggle_lightbox('lightbox_cover', 'share_deal', false);
	show_loading = false;
	
	url = "/share/info/" + thread_id;
	
	makeRequest(url);
}

function price_check(thread_id){
	document.getElementById('share_deal').innerHTML = "<img id='loading' src='/images/loading.gif'/>";
	toggle_lightbox('lightbox_cover', 'share_deal', false);
	show_loading = false;
	
	url = "/price-check?d=" + thread_id;
	
	makeRequest(url);
}

function share_deal_action(thread_id, type, link, thread_link){
	if(type == 'email'){
		url = "/share/email/" + thread_id;
		
		makeRequest(url);
		link.href = "javascript:void(0)";
	}else if(type == 'facebook'){
		url = "http://www.facebook.com/sharer.php?u=" + thread_link;
		window.open(url,'facebook','height=300,width=600');
		toggle_lightbox('lightbox_cover', 'share_deal', true);
	}
}

function submit_email(thread_id, form, submit_name, submit_value){
	var email = document.getElementById('sender_email_'+thread_id).value;
	if(email.length < 1 || email == 'Sending Email' || email == 'Success: Email Sent' || email == 'Error: Email Not Sent'){
		document.getElementById('sender_email').value = 'Error: Email Not Sent'
		return;
	}
	
	var url = "/share/email/" + thread_id;
	form_fields = form_submit(form, submit_name, submit_value);
	
	makeRequest(url, form_fields);
	callback_function = email_callback;
	document.getElementById('sender_email_'+thread_id).value = 'Sending Email';
	form.action = "javascript:void(0)";
}

function email_callback(response){
	
	thread_id = response.split('*ajax_new_div*share_deal_');
	thread_id = thread_id[1].split('*ajax_div_id*');
	thread_id = thread_id[0];
	
	document.getElementById('sender_email_'+thread_id).value = (response.indexOf('class="success"') != -1?'Success: Email Sent':'Error: Email Not Sent');
	
	callback_function = false;
}

function clear_message(element){
	
	if(element.value == 'Sending Email' || element.value == 'Success: Email Sent' || element.value == 'Error: Email Not Sent'){
		element.value = '';
	}
}