﻿/* Moves content between two document elements */
function MoveContent(sourceId, targetId)
{
    sourceElem = document.getElementById(sourceId);
    targetElem = document.getElementById(targetId);
    contentCode = sourceElem.innerHTML;
    sourceElem.innerHTML = '';
    targetElem.innerHTML = contentCode;
}

/* ----------- DIALOGS ---------- */
/* Function to change the time within specified calendar */
function ChangeTime(calendarid, time, timeString)
{
	elem = document.getElementById(calendarid + "_selectedtime");
	if ( elem )
	{
		elem.value = time;
	}
	elem = document.getElementById(calendarid + "_time");
	if ( elem )
	{
		elem.innerHTML = timeString;
	}
}

/* Function to hide specified calendar */
function ShowCalendar(calendarid)
{
	elem = document.getElementById(calendarid + "_seltime");
	if ( elem )
	{
	    elem.src = calendarURLs[calendarid];
		elem.className='VisibleElem';
	}
	elem = document.getElementById(calendarid + "_show");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(calendarid + "_hide");
	if ( elem )
	{
		elem.className='VisibleElem';
	}
}

/* Function to hide specified calendar */
function HideCalendar(calendarid)
{
	elem = document.getElementById(calendarid + "_seltime");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(calendarid + "_hide");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(calendarid + "_show");
	if ( elem )
	{
		elem.className='VisibleElem';
	}
}


/* Function to change the id within specified selector */
function ChangeID(selectorid, id, textValue)
{
	elem = document.getElementById(selectorid + "_selectedid");
	if ( elem )
	{
		elem.value = id;
	}
	elem = document.getElementById(selectorid + "_id");
	if ( elem )
	{
		elem.innerHTML = textValue;
	}
}

/* Function to change the id within specified selector(for external window) */
function FrameChangeID(selectorid, id, textValue)
{
	window.parent.window.ChangeID(selectorid, id, textValue);
}

/* Function to change the id within specified selector(for external window) */
function WindowChangeID(selectorid, id, textValue)
{
    window.opener.window.ChangeID(selectorid, id, textValue);
}


/* Function to show specified dialog */
function ShowDialog(dialogid)
{
	elem = document.getElementById(dialogid + "_dialog");
	if ( elem )
	{
		elem.className='VisibleElem';
		uelem = document.getElementById(dialogid + "_url");
		if ( uelem )
		{
			elem.src = uelem.value;
		}
	}
	elem = document.getElementById(dialogid + "_show");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(dialogid + "_hide");
	if ( elem )
	{
		elem.className='VisibleElem';
	}
}

/* Hides IFRAME dialog */
function FrameHideDialog(dialogid)
{
	window.parent.window.HideDialog(dialogid);
}


/* Function to hide specified dialog */
function HideDialog(dialogid)
{
	elem = document.getElementById(dialogid + "_dialog");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(dialogid + "_hide");
	if ( elem )
	{
		elem.className='HiddenElem';
	}
	elem = document.getElementById(dialogid + "_show");
	if ( elem )
	{
		elem.className='VisibleElem';
	}
}


/* Displays the window */
function ShowModalDialog(dialogid, width, height)
{
    uelem = document.getElementById(dialogid + "_url");
	if ( uelem )
	{
	    window.open(uelem.value, null, 'width=' + width + ';height=' + height + ";modal=yes;menubar=no;resizable=yes;statusbar=yes");
	}	
}


/* ------------ FAVORITES ---------- */
/* Function to process the Add favorite request */
function SetFavorite(itemid, itemtype, selectorid)
{
	try
	{
		chkbox = document.getElementById(selectorid + "_chkFavorite");
		if ( !chkbox.checked )
		{
			FavoriteRequest("?request=delete&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
		else
		{
			FavoriteRequest("?request=add&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
	}	
	catch (exception)
	{
	}
}


/* Function to set the favorite send mails status */
function SetMails(itemid, itemtype, selectorid)
{
	try
	{
		chkbox = document.getElementById(selectorid + "_chkMail");
		if ( chkbox.checked )
		{
			FavoriteRequest("?request=setmail&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
		else
		{
			FavoriteRequest("?request=unsetmail&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
	}	
	catch (exception)
	{
	}
}

/* Function to set favorite send messages status */
function SetMessages(itemid, itemtype, selectorid)
{
	try
	{
		chkbox = document.getElementById(selectorid + "_chkMessage");
		if ( chkbox.checked )
		{
			FavoriteRequest("?request=setmess&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
		else
		{
			FavoriteRequest("?request=unsetmess&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
	}	
	catch (exception)
	{
	}
}

/* Function to set favorite send ICQ status */
function SetICQ(itemid, itemtype, selectorid)
{
	try
	{
		chkbox = document.getElementById(selectorid + "_chkICQ");
		if ( chkbox.checked )
		{
			FavoriteRequest("?request=seticq&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
		else
		{
			FavoriteRequest("?request=unseticq&itemid=" + itemid + "&itemtype=" + itemtype + "&selectorid=" + selectorid, selectorid);
		}
	}	
	catch (exception)
	{
	}
}


/* Function to process the favorite request */
function FavoriteRequest(query, selectorid)
{
	try
	{
		target = document.getElementById(selectorid + "_request");
		url = document.getElementById("favoritesurl").value + query;
		target.src = url;
		target.className = "FavoritesRequest";
	}	
	catch (exception)
	{
	}
}


/* Enables / disables the Mail/Message checkboxes within the favorite selector */
function FavoriteSetControls(selectorid, favexists)
{
	try
	{
		chkmail = document.getElementById(selectorid + "_chkMail");
		if ( chkmail != null )
		{
			if ( favexists )
			{
				chkmail.disabled = false;		
			}
			else
			{
				chkmail.disabled = true;		
				chkmail.checked = false;
			}
		}
		chkmess = document.getElementById(selectorid + "_chkMessage");
		if ( chkmess != null )
		{
			if ( favexists )
			{
				chkmess.disabled = false;		
			}
			else
			{
				chkmess.disabled = true;		
				chkmess.checked = false;
			}
		}
		chkicq = document.getElementById(selectorid + "_chkICQ");
		if ( chkicq != null )
		{
			if ( favexists )
			{
				chkicq.disabled = false;		
			}
			else
			{
				chkicq.disabled = true;		
				chkicq.checked = false;
			}
		}
	}
	catch (exception)
	{
	}	
}


/* ---------------- Menu ---------------- */
var menuElem = null;
var menuStyle = null;
var busy = false;

/* Scrolls the menu to the required location */
function ScrollMenu()
{
    if (busy) return;
    busy = true;
    if (document.all)
    {
        scrollY = document.body.scrollTop - 1;
    }
    else
    {
        scrollY = window.pageYOffset - 1;
    }
    if (scrollY < menuTop)
    {
        scrollY = menuTop;
    }
    menuStyle.top = scrollY + "px";
    busy = false;
}

/* Inits the menu scrolling */
function InitMenu()
{
    menuElem = document.getElementById('jmmenu');
    if ( menuElem.style )
    {
        menuStyle = menuElem.style;
    }
    else   
    {
        menuStyle = menuElem;
    }
    ScrollMenu();
    window.onscroll = ScrollMenu;
}




