/*
 *   (c) Copyright 2007-2008 Hen's Teeth Network, Inc. All rights reserved.
 *   Redistribution without prior written permission is strictly prohibited.
 *   Contact Art Zemon www.hens-teeth.net
 *
 */

function htnRedirectToRegistry(oForm)
{
	oForm.setAttribute("action", "/HTN/registry/index.php");
}

function htnValidRegistryResponse(o)
{
	if ('' != o.responseText)
	{
		var r = YAHOO.lang.JSON.parse(o.responseText);
		if (r['valid'])
		{
			YAHOO.util.Dom.get('shipname').value = r['con_firstname'] + ' ' + r['con_lastname'];
			YAHOO.util.Dom.get('shipstreet1').value = r['con_address1'];
			YAHOO.util.Dom.get('shipstreet2').value = r['con_address2'];
			YAHOO.util.Dom.get('shipcity').value = r['con_city'];
			YAHOO.util.Dom.get('shipprovince').value = r['con_province'];
			YAHOO.util.Dom.get('shipzip').value = r['con_zip'];
			// find the right state in the drop-down
			var selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipstate'; },
				'select',
				'my_form'
			);
			var stateSelect = selectList[0];
			for (var i in stateSelect.options)
			{
				if (stateSelect.options[i].value == r['con_state'])
					stateSelect.selectedIndex = i;
			}
			// find the right country in the drop-down
			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipcountry'; },
				'select',
				'my_form'
			);
			var countrySelect = selectList[0];
			for (var i in countrySelect.options)
			{
				if (countrySelect.options[i].value == r['con_country'])
					countrySelect.selectedIndex = i;
			}
			alert("Since you have purchased items from a gift registry, the shipping address for this order has been set to the registrant's preferred address.");
		}
	}
}
