function invadd(func){
	if(func == 'portfolio'){
		$('portfolioAdd').style.display='block';
	}
}

function invaddSubmit(url, invID, func){
	
	//  this is to denote that the function is being called by AJAX
	url = url + '/1';
	
	//  remove any commas they may have entered
	var num_shares;
	num_shares = document.portAdd.share.value;
	num_shares = num_shares.replace(",", "");
	
	switch(func) {
		case 'watchlist':
									
			break;
		case 'portfolio':
			if(isInt(num_shares) == false) {
				$('eres').innerHTML = 'You must enter a positive number of shares.';
				return;
			}
			else {
				if(parseInt(num_shares) <= 0) {
					$('eres').innerHTML = 'You must enter a positive number of shares.';
					return;
				}
			}
			url = url + '/' + num_shares;			
			break;
	}
	new Ajax.Request(url, 
		{
		method: 'get', onCreate:function(){
			},
		onSuccess: function(transport) 
			{response = transport.responseText;
				switch(func){
					case 'watchlist':
						//  only provide ability to recommend if they added successfully
						if(response == 'You have reached the maximum number of items in your watchlist.<br/>') {
							$('addw').innerHTML = response;
						}
						else {
							$('addw').innerHTML = response;
							$('rating_trigger').setStyle({display:'block'});
						}
					break;
					case 'portfolio':
						$('addw').innerHTML = "&nbsp";
						$('addp').innerHTML = response;
						
						//  only redirect if successfully added
						if(response == 'You have reached the maximum number of items in your portfolio.<br/>') {
						}
						else {
							//  redirect in order to get the share prices sorted out
							window.location = "/manageportfolio/";
						}
					break;
					}
			}
		}
		);
}

function isInt(v) {
	var num = parseInt(v);
	
	if (isNaN(num)){
		return false;
	}
	else {
		return true;
	}
}

function invremoveSubmit(url, invID, func){
	
	//  this is to denote that the function is being called by AJAX
	url = url + '/1';
	
	new Ajax.Request(url, 
		{
		method: 'get', onCreate:function(){
			},
		onSuccess: function(transport) 
			{response = transport.responseText;
				switch(func){
					case 'watchlist':
						$('addw').innerHTML = response;
						if ($('rating_trigger')) {
							$('rating_trigger').remove();
						}
						break;
					}
			}
		}
		);
}
