var isMSIE = /*@cc_on!@*/false;  // from http://dean.edwards.name/weblog/2007/03/sniff/
var symfony_current_hash;
var history_callback_function;
var observe_form_name;

function change_location(name, value)
{
	observe_form_name = name;
	var newhash = '#' + value;
	location.hash = newhash;
	symfony_current_hash = newhash;
	if(isMSIE)
	{
		updateIframeHash(newhash);
	}
}

function updateIframeHash(value)
{
	var ihistory = $('symfony_ajax_history_iframe');
	var iframe = ihistory.contentWindow.document;
	iframe.open();
	iframe.close();
	iframe.location.hash = value;
}

function history_check_updator()
{
	if(isMSIE)
	{
		var ihistory = $('symfony_ajax_history_iframe');
		var iframe = ihistory.contentWindow.document;
		var current_hash = iframe.location.hash;
		if(current_hash != symfony_current_hash)
		{
			location.hash = current_hash;
			symfony_current_hash = current_hash;
			var value = current_hash.replace(/^#/,'');
			history_callback_function(value);
		}
	}
	else
	{
		var current_hash = location.hash;
		if(current_hash != symfony_current_hash)
		{
			symfony_current_hash = current_hash;
			var value = current_hash.replace(/^#/,'');
			history_callback_function(value);
		}
	}
}

Event.observe(window, "load", function()
{
	symfony_current_hash = location.hash;
	if(isMSIE)
	{
		updateIframeHash(location.hash);
	}
	history_callback_function(location.hash.replace(/^#/,''));
	setInterval(history_check_updator, 100);
});
