/*************** MeAccount.aspx ******************/


function PurchasedFromChanged(needSelectionBox)
{	
	// Clear any error messages
	document.getElementById('ClientMessage').innerHTML = "";

	// cycle through the locations turning them all hidden
	var divs = document.getElementById("PurchasedFromDivs");
	for (i=0; i<divs.childNodes.length; i++)
	{	
		divs.childNodes[i].className = "hide";
	}
	
	var selectedOption = needSelectionBox.options[needSelectionBox.selectedIndex];
	var showDiv = "";
	// get companyName input element
	var companyName = YAHOO.util.Dom.get("companyNameId");
	companyNameElement = YAHOO.util.Dom.get(companyName.value);
	companyNameElement.disabled = false;
	if(companyNameElement.value == "Amazon (USA)")
	{
		companyNameElement.value = "";
	}
							
	document.getElementById('amazonUSAButton').className="hide";
	document.getElementById('amazonUKButton').className="hide";
	var priceAndDescriptionEl = YAHOO.util.Dom.get("priceAndDescription");

	switch(selectedOption.value)
	{
		// On the web
		case "0" :
			openPopup(priceAndDescriptionEl);
			showDiv = "WebProduct";
			break;
		// On the high street
		case "1" :
			openPopup(priceAndDescriptionEl);
			showDiv = "PhysicalLocation";
			break;
		// from Amazon USA
		case "2" :
			closePopup(priceAndDescriptionEl);
			// lock the companyName to Amazon			
			companyNameElement.value = "Amazon (USA)";
			companyNameElement.disabled = true;
			showDiv = "Amazon";
			document.getElementById('amazonUSAButton').className="";
			tmt_DivOnTop('loader');
			break;	
		// from Amazon UK
		case "3" :
			closePopup(priceAndDescriptionEl);
			// lock the companyName to Amazon			
			companyNameElement.value = "Amazon (UK)";
			companyNameElement.disabled = true;
			showDiv = "Amazon";
			document.getElementById('amazonUKButton').className="";			
			tmt_DivOnTop('loader');
			break;	
	}
	if(showDiv != "")
	{
		document.getElementById(showDiv).className="";		
	}
	
}

function resetAmazonDetails()
{
	YAHOO.util.Dom.get("amazonProductImage").src = "";
	YAHOO.util.Dom.get("amazonProductImage").style.display = "none";
	YAHOO.util.Dom.get(amazonProductName).value = "";
	YAHOO.util.Dom.get(amazonProductPrice).value = "";
	YAHOO.util.Dom.get(amazonProductUrl).value = "";;
}

/*********** AddNeed.aspx ****************/

function addNewList()
{
	document.getElementById('EditNeedButton').className = "tabButtonDisabled";
	DisplayTab('NewList');
	ClearTab('NewList'); 
}

function displayViewNeeds()
{
	document.getElementById('EditNeedButton').className = "tabButtonDisabled";
	DisplayTab('ViewNeeds');
}

function closePopup(popup)
{	
	//new YAHOO.util.Anim(popup, { opacity: { to: 0 } }, 1, YAHOO.util.Easing.easeOut).animate;
	YAHOO.util.Dom.get(popup).style.display='none';
}

function openPopup(popup)
{	
	YAHOO.util.Dom.get(popup).style.display='';
}

function amazonProductSelect(name, price, imageUrl, url)
{
	YAHOO.util.Dom.get("amazonProductImage").src = imageUrl;
	YAHOO.util.Dom.get("amazonProductImage").style.display = "";
	YAHOO.util.Dom.get(amazonProductName).value = name;
	if(price=="")
	{
		price=0;
	}
	YAHOO.util.Dom.get(amazonProductPrice).value = price;
	YAHOO.util.Dom.get(amazonProductUrl).value = url;
	closePopup('AmazonDetailsUSA');
	closePopup('AmazonDetailsUK');
}

/* NeedList.ascx */

function openMugShotPopup(positionElement, popup)
{
	var el = YAHOO.util.Dom.get(popup);	
	openPopup(popup);
	
	var xy = YAHOO.util.Dom.getXY(positionElement);
	// move the popup over to the left	
	xy[0] = xy[0] + 500;
	xy[1] = xy[1] + 10;	
	YAHOO.util.Dom.setXY(popup, xy, true);	
}

function openAddressPopup(positionElement, addressDetails)
{
	var el = YAHOO.util.Dom.get("addressDetails");
	el.innerHTML = addressDetails;
	openPopup("AddressPopup");
	
	var xy = YAHOO.util.Dom.getXY(positionElement);
	// move the popup over to the left	
	xy[0] = xy[0] - 290;
	YAHOO.util.Dom.setXY("AddressPopup", xy, true);	
}

function openAddressPopup(positionElement, addressDetails, header)
{
	var el = YAHOO.util.Dom.get("addressDetails");
	el.innerHTML = unescape(addressDetails);
	var cmName = YAHOO.util.Dom.get("header");
	cmName.innerHTML = header;
	openPopup("AddressPopup");
	
	var xy = YAHOO.util.Dom.getXY(positionElement);
	// move the popup over to the left	
	xy[0] = xy[0] - 200;
	YAHOO.util.Dom.setXY("AddressPopup", xy, true);	
}

// used on the needs web control to set the company name of the pop up
function setCompanyName(companyName)
{
	var cmName = YAHOO.util.Dom.get("companyName");
	cmName.innerHTML = companyName;
}

function openWindow(url)
{
	window.open(url, 'NeedLocation', 'status=1, scrollbars=1, resizable=1');
}


/**************** Add Friends ********************************/

/**************** FriendsNeeds ******************************/
function displayTheirProfile()
{
	DisplayTab('theirProfile');	
	document.getElementById('theirListButton').onclick = displayTheirList;
}

function displayTheirList()
{
	DisplayTab('theirList');	
}

function displayFriends()
{
	DisplayTab('friends');
	document.getElementById('theirListButton').onclick = "";
	document.getElementById('theirListButton').className="tabButtonDisabled";
	document.getElementById('theirProfileButton').onclick = "";
	document.getElementById('theirProfileButton').className="tabButtonDisabled";
	document.getElementById('friendMugshot').style.display="none";
}
