
function HPBlogsDisplayChange() {
	switch ($('txtBlogsDisplay').value)
	{
		case 'All':
			$('FilterTag').style.display = 'none';
			$('FilterUser').style.display = 'none';
			$('FilterRole').style.display = 'none';
		break;
		case 'Role':
			$('FilterTag').style.display = 'none';
			$('FilterUser').style.display = 'none';
			$('FilterRole').style.display = 'inherit';
		break;
		case 'User':
			$('FilterTag').style.display = 'none';
			$('FilterUser').style.display = 'inherit';
			$('FilterRole').style.display = 'none';
		break;
		case 'UserTag':
		case 'Tag':
			$('FilterTag').style.display = 'inherit';
			$('FilterUser').style.display = 'none';
			$('FilterRole').style.display = 'none';
		break;

}
}

function setFeaturedDiscussion(EntryID)
{
	Element.addClassName($('ToggleFeatured'),'Progress');
	var myAjax = new Ajax.Request('extensions/HomePage/ajax.php',{
			 parameters:'Method=SetFeaturedDiscussionEntry&EntryID='+EntryID,
			 method:'get',
			 onSuccess: function(r) {
				$('ToggleFeatured').innerHTML = 'This entry is set';
				Element.removeClassName($('ToggleFeatured'),'Progress')	;

}});
return false;
}


function FPLY_Search(BasDir)
{
    new Insertion.Bottom('FPLY_Form','<p class="Progress">Looking for matches...</p>');
    if ($('style').value == $('style').name)
        Style = '';
    else
        Style = $('style').value;
    if ($('location').value == $('location').name)
        Location = '';
    else
        Location = $('location').value;
    if ($('project').value == $('project').name)
        Project = '';
    else
        Project = $('project').value;

    var myAjax = new Ajax.Request(BasDir+'extensions/HomePage/ajax.php',{
    parameters:'Method=RunSearch&Style='+Style+'&Location='+Location+'&Project='+Project,
    method:'post',
    onSuccess: function(r)
    {
     FPLY_Set(r.responseText,Style,Location,Project,BasDir);
    }
    });

}
function FPLY_ReSearch(BasDir)
{
    $('FPLY_Form').innerHTML = '<h3>Find people like you...</h3><form action="#" id="loginForm" method="post"><fieldset><input class="FPLY_Input" type="text" onfocus="if(this.value==this.name) this.value=\'\';" onblur="if (this.value == \'\') this.value=this.name;"  id="style" value="Type your house style (e.g., ranch)" name="Type your house style (e.g., ranch)" /><input class="FPLY_Input" type="text" onfocus="if(this.value==this.name) this.value=\'\';" onblur="if (this.value == \'\') this.value=this.name;"  id="location" value="Type your location (e.g., Chicago)" name="Type your location (e.g., Chicago)" /><input class="FPLY_Input" type="text" onfocus="if(this.value==this.name) this.value=\'\';" onblur="if (this.value == \'\') this.value=this.name;" id="project" value="Type your project name (e.g., kitchen)" name="Type your project name (e.g., kitchen)" /><input class="FPLY_Submit" type="button" id="btlogin" name="FPLY_Submit" onclick="FPLY_Search(\''+BasDir+'\');" value="Search for matches" /></fieldset></form>';

    var WhisperAutoComplete = new AutoComplete('style', true);
    WhisperAutoComplete.TableID = "TagResults";
    WhisperAutoComplete.KeywordSourceUrl = BasDir+ 'extensions/Houseblogs/getUserTags.php?Search=';

    var WhisperAutoComplete2 = new AutoComplete('location', true);
    WhisperAutoComplete2.TableID = "TagResults";
    WhisperAutoComplete2.KeywordSourceUrl = BasDir+ 'extensions/Houseblogs/getUserTags.php?Search=';

    var WhisperAutoComplete3 = new AutoComplete('project', true);
    WhisperAutoComplete3.TableID = "TagResults";
    WhisperAutoComplete3.KeywordSourceUrl = BasDir + 'extensions/Houseblogs/getBlogandDiscussion.php?Search=';
}
function FPLY_Set(Result,Style,Location,Project,BasDir)
{
    var elem = Result.split("|");
    $('FPLY_Form').innerHTML = '<h3>Here\'s what we found</h3><ul>';
    if (Style != '')
        if (elem[0] > 0)
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'extension.php?PostBackAction=Members&Filter_Tag='+Style+'"><b>\''+Style+'\'</b><br />- <span style="color:#f00;">'+elem[0]+'</span> member profile matches</a></li>';
        else
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'extension.php?PostBackAction=Members&Filter_Tag='+Style+'"><b>\''+Style+'\'</b><br />- '+elem[0]+' member profile matches</a></li>';
    if (Location != '')
        if (elem[1] > 0)
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'extension.php?PostBackAction=Members&Filter_Tag='+Location+'"><b>\''+Location+'\'</b><br />- <span style="color:#f00;">'+elem[1]+'</span> member profile matches</a></li>';
        else
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'extension.php?PostBackAction=Members&Filter_Tag='+Location+'"><b>\''+Location+'\'</b><br />- '+elem[1]+' member profile matches</a></li>';
    if (Project != '')
    {
        if (elem[2] > 0)
            $('FPLY_Form').innerHTML += '<li><b>\''+Project+'\'</b><br /><a href="'+BasDir+'extension.php?PostBackAction=Blogs&Filter_Tag='+Project+'">- <span style="color:#f00;">'+elem[2]+'</span> blog entry matches</a></li>';
        else
            $('FPLY_Form').innerHTML += '<li><b>\''+Project+'\'</b><br /><a href="'+BasDir+'extension.php?PostBackAction=Blogs&Filter_Tag='+Project+'">- '+elem[2]+' blog entry matches</a></li>';
        if (elem[3] > 0)
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'index.php?Filter_Tag='+Project+'">- <span style="color:#f00;">'+elem[3]+'</span> discussion matches</a></li>';
        else
            $('FPLY_Form').innerHTML += '<li><a href="'+BasDir+'index.php?Filter_Tag='+Project+'">- '+elem[3]+' discussion matches</a></li>';
    }
    $('FPLY_Form').innerHTML += '</ul><p>&nbsp;</p><form id="loginForm" action="#"><fieldset><input id="btlogin" type="button" name="FPLY_Reset" onclick="FPLY_ReSearch(\''+BasDir+'\');" value="Search Again" /></fieldset></form>';
}
function UpdateModules(side)
{
    Sortable.SERIALIZE_RULE = '/^[^_\-](?:[A-Za-z0-9\-\_]*)';
    element = $('SortModules'+side);
    param = 'Method=SortHomePageModules&side='+side;
    for (i=0;i<element.childNodes.length;i++)
    {
        if (element.childNodes[i].id != '')
        {
            param += '&dat[]='+element.childNodes[i].id;
        }
    }
    new Ajax.Request('extensions/HomePage/ajax.php',{parameters:param});
}
function ModulTypeChanged()
{
    n = $F('txtModuleName');
    elem = $('txtModuleType');
    if (elem.value == 'php' && n != '')
    {
        $('txtSourceCode').innerHTML = '<?php \n/*\nModule Name: '+n+'\nVersion: 0.1\nAuthor: Andreas Hutstein\nAuthor Url: mail@hutstein.de\n*/\n\n\nclass mod_'+n+'t\n{\n    var $Context;\n\n    function mod_'+n+'($Context)\n    {\n        $this->Context = $Context;\n    }\n\n    function Display($side)\n    {\n\n    return \'\';\n    }\n}\n?>';
        $('txtSourceCode').disabled = false;
    }
    else if (elem.value == 'htm')
    {
        $('txtSourceCode').innerHTML = '';
        $('txtSourceCode').disabled = false;
    }
    else
    {
       $('txtSourceCode').innerHTML = 'Insert name and choose file type for this module first';
       $('txtSourceCode').disabled = true;
    }
}