/*
    Type=CATEGORY,DISCUSSION,ALL;
    ElementID=x (DiscussionID,CategoryID,0)
    Value=1/0 (1=set, 0=unset)
                                  */
function SetNotify(Type,ElementID,Value,Elem,Class,NewText)
{
    var Vanilla = new PathFinder();	
    var ajax = new Ajax.Request(Vanilla.webRoot = Vanilla.getRootPath('script', 'src', 'js/global.js')+'extensions/Notify/ajax.php',    {
        parameters:'PostBackAction=ChangeNotify&Type='+Type+'&ElementID='+ElementID+'&Value='+Value+'&Elem='+Elem,
        onSuccess: function(r)
        {
				var tmp = new Array();
				tmp[0]='PreferenceProgress'; tmp[1]='PreferenceProgress'; tmp[2]='PreferenceProgress';
			if (Elem.substr(0,20)=="NotifyFormDiscussion") {
				tmp[Value]='Progress';
				Element.removeClassName("NotifyFormDiscussion2_"+ElementID,tmp[2]);
				Element.removeClassName("NotifyFormDiscussion1_"+ElementID,tmp[1]);
				Element.removeClassName("NotifyFormDiscussion0_"+ElementID,tmp[0]);
			} else if (Elem.substr(0,18)=="NotifyFormCategory") {
				tmp[Value]='Progress';
				Element.removeClassName("NotifyFormCategory2_"+ElementID,tmp[2]);
				Element.removeClassName("NotifyFormCategory1_"+ElementID,tmp[1]);
				Element.removeClassName("NotifyFormCategory0_"+ElementID,tmp[0]);
			} else {
	            Element.removeClassName(Elem,Class);
			}
            if (NewText != '') 
			{
				Elem.innerHTML = NewText;
            	$(Elem).innerHTML = NewText;
			}
         }
    });
    return true;
}

function NotifyCat(CategoryID)
{
    Element.addClassName('NotifyCatCont_'+CategoryID,'PreferenceProgress');
    if ($('NotifyCat_'+CategoryID).checked == true) Value = 1;
    else Value = 0;
	if (Value==1) {
		try {	
			document.getElementById('NotifyFormCategory22_'+CategoryID).checked=true;
		} catch(err) {};
	}
    SetNotify('CATEGORY',CategoryID,Value,'NotifyCatCont_'+CategoryID,'PreferenceProgress','');
}
function NotifyCategoryMethod(CategoryID,Value2)
{
	var tmp = new Array();
	tmp[0]='PreferenceProgress'; tmp[1]='PreferenceProgress'; tmp[2]='PreferenceProgress';
	tmp[Value2]='Progress';
    Element.addClassName('NotifyFormCategory2_'+CategoryID,tmp[2]);
	Element.addClassName('NotifyFormCategory1_'+CategoryID,tmp[1]);
	Element.addClassName('NotifyFormCategory0_'+CategoryID,tmp[0]);
    SetNotify('CATEGORY',CategoryID,Value2,'NotifyFormCategory2_'+CategoryID,'PreferenceProgress','');
}
function NotifyDiscussion(DiscussionID)
{
    Element.addClassName('NotifyDiscussionCont_'+DiscussionID,'PreferenceProgress');
    if ($('NotifyDiscussion_'+DiscussionID).checked == true) Value = 1;
    else Value = 0;
	if (Value==1) {
		try {	
			document.getElementById('NotifyFormDiscussion22_'+DiscussionID).checked=true;
		} catch(err) {};
	}
    SetNotify('DISCUSSION',DiscussionID,Value,'NotifyDiscussionCont_'+DiscussionID,'PreferenceProgress','');
}
function NotifyDiscussionMethod(DiscussionID,Value2)
{
	var tmp = new Array();
	tmp[0]='PreferenceProgress'; tmp[1]='PreferenceProgress'; tmp[2]='PreferenceProgress';
	tmp[Value2]='Progress';
    Element.addClassName('NotifyFormDiscussion2_'+DiscussionID,tmp[2]);
	Element.addClassName('NotifyFormDiscussion1_'+DiscussionID,tmp[1]);
	Element.addClassName('NotifyFormDiscussion0_'+DiscussionID,tmp[0]);
    SetNotify('DISCUSSION',DiscussionID,Value2,'NotifyFormDiscussion2_'+DiscussionID,'PreferenceProgress','');
}
function PNotifyAll(SetText,UnSetText)
{
    Element.addClassName('SetNotifyAll','Progress');
    if ($('SetNotifyAll').innerHTML == SetText)
    {
        Value = 1;
        NewText = UnSetText;
    }
    else
    {
        Value = 0;
        NewText = SetText;
    }
    SetNotify('ALL',0,Value,'SetNotifyAll','Progress',NewText);
}
function PNotifyCategory(CategoryID,SetText,UnSetText)
{
    Element.addClassName('SetNotifyCategory_'+CategoryID,'Progress');
    if ($('SetNotifyCategory_'+CategoryID).innerHTML == SetText)
    {
        Value = 1;
        NewText = UnSetText;
    }
    else
    {
        Value = 0;
        NewText = SetText;
    }
    SetNotify('CATEGORY',CategoryID,Value,'SetNotifyCategory_'+CategoryID,'Progress',NewText);
}
function PNotifyDiscussion(DiscussionID,SetText,UnSetText)
{
    Element.addClassName('SetNotifyDiscussion_'+DiscussionID,'Progress');
    if ($('SetNotifyDiscussion_'+DiscussionID).innerHTML == SetText)
    {
        Value = 1;
        NewText = UnSetText;
    }
    else
    {
        Value = 0;
        NewText = SetText;
    }
    SetNotify('DISCUSSION',DiscussionID,Value,'SetNotifyDiscussion_'+DiscussionID,'Progress',NewText);
}

function NotifyAll()
{
    Element.addClassName('NotifyAllCont','PreferenceProgress');
    if ($('NotifyAllField').checked == true) Value = 1;
    else Value = 0;
    SetNotify('ALL',0,Value,'NotifyAllCont','PreferenceProgress','');
}

function NotifyOwn()
{
    Element.addClassName('NotifyOwnCont','PreferenceProgress');
    if ($('NotifyOwnField').checked == true) Value = 1;
    else Value = 0;
    SetNotify('OWN',0,Value,'NotifyOwnCont','PreferenceProgress','');
}

function PNCategoryRead(CategoryID,SetText) {
    Element.addClassName('SetNotifyCategoryRead_'+CategoryID,'Progress');
    SetNotify('CATEGORYREAD',CategoryID,0,'SetNotifyCategoryRead_'+CategoryID,'Progress','(hecho) '+SetText);
}

function PNDiscussionRead(DiscussionID,SetText,Value) {
	if (Value>0) {
		Element.addClassName('SetNotifyDiscussionRead_'+DiscussionID,'Progress');
		SetNotify('DISCUSSIONREAD',DiscussionID,Value,'SetNotifyDiscussionRead_'+DiscussionID,'Progress','(hecho) '+SetText);
	} else {
		Element.addClassName('SetNotifyDiscussionNoRead_'+DiscussionID,'Progress');
		SetNotify('DISCUSSIONREAD',DiscussionID,Value,'SetNotifyDiscussionNoRead_'+DiscussionID,'Progress','(hecho) '+SetText);
	}
}