function donate(link, ddlname)
{		
	var n = document.getElementById(ddlname); 
	var ind = n.selectedIndex; 
	
	if (ind != 0 && n.options[ind].value != '0') 
	{ 
		var str = n.options[ind].value + ''; 
		
		window.open(link.replace("@PRICE@", str));
	} 
	else 
	{ 
		if (ind == 0) 
			alert('Please select a donation amount'); 
		else  
		{
			var str = 'NYP';
			window.open(link.replace("@PRICE@", str));
		} 
	}
}

function donateRadio(link, form)
{	
	var i; 
	var price; 
	
	//alert(form.elements.length);
	
	for(i = 0; i < form.elements.length; i++)
	{
		if(form.elements[i].checked == true)
		{
			//alert(i);
			price = form.elements[i].value; 
			break;
		}
	}
	
	if (price != '0') 
	{ 
		window.open(link.replace("@PRICE@", price));
	} 
	else 
	{
		var str = 'NYP';
		window.open(link.replace("@PRICE@", str));
	}
}

function searchStore(url)
{
	//alert(url);
	var n = document.getElementById('searchBox'); 
	
	if(!n.value || n.value.length == 0)
	{
		alert ('You haven\'t input any key words!');
		return;
	}
	
	var str = n.value.replace(/ /g, "_");
	
	window.open(url + 'search.php/?' + str, '_self');
}

function searchEvent(url, e)
{
	var key; 
	
	if(window.event)
		key = window.event.keyCode; //IE
	else
	    key = e.which; //firefox  
	
	//alert(key);	
	if(key == 13)
	{
		searchStore(url);
	}
}

function NoGiftButtonClick(list, addition)
{
	var amount = document.getElementById(list).value; 
	
	//var str = "https://www.paypal.com/cart/add=1&business=donations@ihcenter.org&item_number=$" + amount + " Donation&item_name=Palast Investigative Fund " + addition + "&amount=" + amount + "&currency_code=USD";
	var str = "https://www.paypal.com/cart/add=1&business=jayhalfon@mac.com&item_number=$" + amount + " Donation&item_name=Palast Investigative Fund " + addition + "&amount=" + amount + "&currency_code=USD";
	
	window.open(str,'cart','height=350,width=600,screenX=10,screenY=10,top=10,left=10,scrollbars=yes');
}

function AltDonButtonClick(list, addition, boxID, min, address)
{
		if(!address) 
		{
			var address = "jayhalfon@mac.com";
		}
				
		var link_part1 = "https://www.paypal.com/cart/add=1&business=";
		var link_part2 = "&item_number=Palast Investigative Fund&item_name=Palast Investigative Fund ";
		var link_part3 = "&amount=";
		var link_part4 = "&currency_code=USD";
				
		var n = document.getElementById(list); 
		var ind = n.selectedIndex; 
		
		if (ind != 0 && n.options[ind].value != '0') 
		{ 
			var str = n.options[ind].value + '';
			window.open(link_part1 + address + link_part2 + addition + link_part3 + str + link_part4); 
		} 
		else 
		{ 
			//if (ind == 0) alert('Please select a donation amount!'); 
			//else  
			//	{					
					var amountBox = document.getElementById(boxID); 
										
					var price = parseInt(amountBox.value);
					//alert(price);
					if(!price || price < 0) 
					{
						alert('You must input a valid amount.');
						return;
					}
					
					if(price < min) 
					{
						alert('Because of high production costs, we ask for a minimum $' + min + ' donation!');
					}
					else 
					{
						window.open(link_part1 + address + link_part2 + addition + link_part3 + price.toString() + link_part4);
					}						
					
			//	}
		}
}
	
function AltDonDDLChanged(list, usambox)
{
		var n = document.getElementById(list); 
		var ind = n.selectedIndex; 
		
		var amountBox = document.getElementById(usambox); 
		
		//if(ind != 0)
		//{
			if (n.options[ind].value != '0') 
			{
				if(!amountBox.disabled) 
				{
					amountBox.disabled = true; 
				}		
				
				amountBox.value = n.options[ind].value;
			}
			else
			{		
				if(amountBox.disabled) 
				{
					amountBox.disabled = false; 
					amountBox.focus();
				}
			}
		//}
		/*else 
		{
			amountBox.disabled = true; 
		}*/
		
}
