function displayTags(id) {
	if(id == "default")
		$('#popular_tags').text("");
	else {
		$('#popular_tags').load('helpers/display_sector_tags.php?id=' + id);
		$('#product_tags').val("");
	}
}

function addTag(anchor) {
	var tag = $(anchor).text();
	var products = $('#product_tags').val();
	
	if($(anchor).hasClass('off')) {
		if(products == "") {
			$('#product_tags').val(tag);
		} else {
				$('#product_tags').val(products + ", " + tag);
		}
		$(anchor).removeClass('off');
		$(anchor).addClass('on');
	} else {
			var new_products = "";
			var product_split = products.split(", ");
			
			for(var index = 0; index < product_split.length; index++) {
				if(product_split[index] != jQuery.trim(tag)) {
					
					if(index == (product_split.length - 1))
						new_products = new_products + product_split[index];
					else 
						new_products = new_products + product_split[index] + ", ";
				}
			}
			
			$('#product_tags').val(new_products);
			
			$(anchor).removeClass('on');
			$(anchor).addClass('off');	
	}
}

function open_window(url) {
	newwindow=window.open(url,'name','height=510,width=485');
	if (window.focus) {newwindow.focus()}
	return false;
}

function tellAFriend_validation(form){
  var email = document.getElementById('email-address');
	var name = document.getElementById('name');
	if (email.value == "" || name.value == "") {
   alert("Please complete the form before submitting.");
	 return false;
	}
	form.submit();
	return true;
}

function make_contact(form) {
	var message = document.getElementById('message');
	if(message.value == "") {
		alert('Please type a message before submitting');
		return false;
	}

	form.submit();
	return true;
}

function comment_form(form) {
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var comment = document.getElementById('comment');
	
	if(name.value == "" || email.value == "" || comment.vale == "") {
		alert('Please complete the form before submitting');
		return false;
	}
	
	form.submit();
}

function enableSubmit() {
		var checkbox = document.getElementById('terms');
		var submit = document.getElementById('registration_submit');
		
		if(checkbox.checked)
			submit.disabled = false;
		else
			submit.disabled = true;	
}

function show_hide(show, hide) {
	$(show).show();
	$(hide).hide();
}

function initiate_contact(opportunity) {
	$('#contact_details').load('helpers/initiate_contact.php?id=' + opportunity);
}