$(document).ready
(function(){
	function http_post(url, data, context)
	{
		if(!context) context = document;
		
		var html = DOMBuilder.apply();
		var form = html.FORM
		(
			{
				method: 'post',
				action: url,
				style:  'display: none;'
			}
		);
	
		for(var i in data)
		{
			form.appendChild
			(html.INPUT(
				{
					name:  data[i]['name'],
					value: data[i]['value'],
					type:  'hidden'
				}
			));
		}
		
		context.body.appendChild(form);
		form.submit();
		context.body.removeChild(form);
	}
	
	function open_blank_window(title, params)
	{
		var result = window.open('', title, params);
		
		result.document.open();
		result.document.write
		(
			'<html>'                                      +
			'  <head><title>' + title + '</title></head>' +
			'  <body></body>'                             +
			'</html>'
		);
		result.document.close();
		
		return result;
	}
	
	$("a#environment-agency-lookup").click
	(function(){
		var ea_window = open_blank_window('Environment Agency Register', 'width=780,height=700');
		
		http_post
		(
			'http://www2.environment-agency.gov.uk/epr/detail.asp?subject=1&nopages=7&pagesize=10&table=EAGENCY_ROCAS_C',
			[
				{'name': '1_licence_7_5', 'value': 'CB/GP3479SN'},
			],
			ea_window.document
		);
		
		return false;
	});
});


