/*
 *   (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 (0 < r['valid'])
		{
			var selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipname'; },
				'input'
			);
			var t = selectList[0];
			t.value =  r['con_firstname'] + ' ' + r['con_lastname'];

			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipstreet1'; },
				'input'
			);
			t = selectList[0];
			t.value =  r['con_address1'] == null ? '' : r['con_address1'];

			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipstreet2'; },
				'input'
			);
			t = selectList[0];
			t.value =  r['con_address2'] == null ? '' : r['con_address2'];

			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipcity'; },
				'input'
			);
			t = selectList[0];
			t.value =  r['con_city'] == null ? '' : r['con_city'];

			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipprovince'; },
				'input'
			);
			t = selectList[0];
			t.value =  r['con_province'] == null ? '' : r['con_province'];

			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipzip'; },
				'input'
			);
			t = selectList[0];
			t.value =  r['con_zip'] == null ? '' : r['con_zip'];

			// find the right state in the drop-down
			selectList = YAHOO.util.Dom.getElementsBy(
				function(e) { return e.name == 'shipstate'; },
				'select'
			);
			var stateSelect = selectList[0];
			for (var i = 0; i < stateSelect.options.length; i++)
			{
				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'
			);
			var countrySelect = selectList[0];
			for (var i = 0; i < countrySelect.options.length; i++)
			{
				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.");
		}
	}
}

