function projectItemChooserStub()
{
	document.write('<div id="project-item-chooser-stub"></div>');
}

function openProjectItemChooser(id)
{	
	var s = 'id=' + id;
    
    var stub = $('project-item-chooser-stub');		
    stub.innerHTML = '<div class="project-item-chooser">Loading...</div>';


    new Ajax.Request('/system/projectItemChooser.php', 
	{
	    parameters:s, 
		method: "post",
		onSuccess:function(response) 
		{
    		var stub = $('project-item-chooser-stub');
			stub.firstChild.innerHTML = response.responseText;   		
    	}, 
		onFailure:function(response)  
		{
		   alert('Error: ' + response.status + ' ' + response.statusText);
		}
	});
}

function closeProjectItemChooser()
{
    var stub = $('project-item-chooser-stub');
	stub.removeChild(stub.firstChild);
}

function chooseProjectItem(n)
{
	var url = window.location.href;
	// var urlPattern = /(.*)[?#].*/;
	var tag;
	var site;
	var index = "" + n;
	
	if (index.match(/^\d+$/) != null)
	{	
    	var urlPattern = /^http:\/\/([^\/]+)\/project\/([^\/]+)(\/.*)?/;
    	var result = urlPattern.exec(url);
    	    
        if (result != null)
        {
        	site = result[1];
        	tag = result[2];
        }
       
    	window.location.href = "http://" + site + "/project/" + tag + "/item/" + n + "/";
    }
}
