var phoneLookUp = {
	handleSuccess:function(o) {
		var tdcResult = eval('(' + o.responseText + ')');
		document.getElementById(o.argument.name).value = tdcResult.name != null ? tdcResult.name : '';
		if (document.getElementById(o.argument.company) != null) {
			document.getElementById(o.argument.company).value = tdcResult.company != null ? tdcResult.company : '';
		}
		else if (document.getElementById('bestillerfirma') != null) {
			// HaX: For bedrift er o.argument.company = m_bestillerfirma og for private blot bestillerfirma. Hvis privat aendres til
			// m_bestillerfirma goeres feltet desvaerre obligatorisk. Derfor dette felt.
			document.getElementById('bestillerfirma').value = tdcResult.company != null ? tdcResult.company : '';
		}
		document.getElementById(o.argument.zip).value = tdcResult.zipcode != null ? tdcResult.zipcode : '';
		document.getElementById(o.argument.city).value = tdcResult.city != null ? tdcResult.city : '';
		document.getElementById(o.argument.address).value = tdcResult.address != null ? tdcResult.address : '';
		//if(tdcResult.zipcode != '') {
		if(o.argument.get_sectors === true && tdcResult.zipcode != '') {
			sectorAreasObject.getSectorAreas(tdcResult.zipcode, tdcResult.city, 'zip');
		}
	},

	handleFailure:function(o) {
		//alert("Failure: "+o.getAllResponseHeaders);
	},

	startRequest:function(number) {
		YAHOO.util.Connect.asyncRequest('GET', '/bestil/rpc_phone_lookup.php?number='+number, phoneLookUpCallback, null);
	},

	init:function(elmId) {
		if(document.getElementById(elmId) && document.getElementById(elmId).value != '') {
			this.startRequest(document.getElementById(elmId).value);
		}
	}
};

function phone_lookup_listener(e, elmId) {
	if (!e) {
		var e = window.event;
	}
	if (e.keyCode) {
		code = e.keyCode;
	} else if (e.which) {
		code = e.which;
	}
	if(code == 13) 	{
		phoneLookUp.init(elmId)
		return (false);
	}
}

/*var tdcLookUpCallback = {
		success:tdcLookUp.handleSuccess,
		failure:tdcLookUp.handleFailure,
		scope:tdcLookUp,
		argument: { 'name':"addon_block" }
};*/