var popUp; 

function OpenQAS(idname, addressTextboxIds, postBack)
{
	var addressTextBoxId = addressTextboxIds.split(",");
	var selected = "";
	for (var i = 0; i < addressTextBoxId.length; i++) 
	{
		selected += document.getElementById("_" + addressTextBoxId[i]).value + ",";
	}
	
	popUp = window.open('QAS.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + selected + '&postBack=' + postBack + '&ids=' + addressTextBoxId, 
		'popupcal', 
		'width=350,height=150,left=200,top=250');
}

function SetAddress(formName, ids, newAddress, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	//Break the ids into indervidual id
	var id = ids.split(",");
	//Break new Address into address parts 
	var newAddressPart = newAddress.split(",");
	//loop throuh ids putting in address parts
	for (var i = 0; i < id.length -1; i++) 
	{
		//alert("_" + id[i]);
		//alert(newAddressPart[i]);
		if(newAddressPart.length > i + 1)
		{
			document.getElementById("_" + id[i]).value = newAddressPart[i];
		}
		else
		{
			document.getElementById("_" + id[i]).value = "";
		}
	}
	//Postcode
	document.getElementById("_" + id[id.length - 1]).value = newAddressPart[newAddressPart.length - 1];
	
	if (postBack)
		__doPostBack(id,'');
}	

