
//Fixes a conflict between JQuery and prototype
var $j = jQuery.noConflict();

function newImage(ID,file) {
	document.getElementById(ID).src='/images/'+file;
}

function open_window(URL,name,left,top,width,height,menubar){
	 rp=window.open(URL,name,"top="+top+",left="+left+",height="+height+",width="+width+",menubar="+menubar+",scrollbars=1,resizable=1,status=1");
	 rp.focus();
	 return(false);
}


function openBox(css)
{
    $j(css).toggle();
}

function selectMood(dir)
{
    par = $j('.moodList');
    sObj = par.children('.selected');
    
    if(dir == "n")
    {
        if(sObj.next() && sObj.next().get(0).className == 'hide')
        {
            toggleMoods(sObj.next().get(0), sObj.get(0));
        }
        else
        {
           toggleMoods(par.children()[1], sObj.get(0));
        }
    }
    else
    {
        if(sObj.prev() && sObj.prev().get(0).className == 'hide')
        {
            toggleMoods(sObj.prev().get(0), sObj.get(0));
        }
        else
        {
           chi = par.children();
           toggleMoods(chi[chi.length-2], sObj.get(0));
        }
    }
    
    $j('#moodClicked').get(0).value = "moodClicked";
    $j('.userMood').get(0).value = $j(".moodList li.selected").get(0).id;
    $j('#moodPost').get(0).value = sObj.get(0).textContent;
}

function toggleMoods(obj, obj1)
{
    obj.className = "selected";
    obj1.className = "hide";
}

function logOut()
{
    $j(".logOutClicked").get(0).value = "logOutClicked";
    submitForm();
}

function submitDin()
{
    $j(".dinClicked").get(0).value = "dinClicked";
    submitForm();
}


function debug(o)
{
    t = $j("<textarea class='debug' id='debugBox'></textarea>");
    $j("body").append(t);  
    
    t = $j('#debugBox').get(0);
    
    for(i in o)
    {
        t.value += i + ' = ' +  o[i] + '\n'; 
    }            
}

function getFaq(str)
{
   $j('input#faqCatSelected').get(0).value = str;
   submitForm();
}

function hideShowFaqAnswer(o)
{
    $j(o).next('div').toggle();
}

function submitForm()
{
    document.forms[0].submit();
}

function getPage(num, inp)
{
   $j('input#'+inp).get(0).value = num;
   submitForm();
}

function doSearch()
{
    document.forms[0].action ="/search-results.aspx?keyword=" + $j("#searchField").get(0).value;
    submitForm();
}