function confirmUserDelete()
{
    var bRet = confirm("Are you sure you want to delete this user?");
    if (bRet) {
        document.frmUser.del.value = '1';
        document.frmUser.submit();
    }
}

function confirmNewsDelete()
{
    var bRet = confirm("Are you sure you want to delete this news article? This can not be undone.");
    if (bRet) {
        document.frmNews.del.value = '1';
        document.frmNews.submit();
    }
}

function confirmDownloadDelete()
{
    var bRet = confirm("Are you sure you want to delete this download file? This can not be undone.");
    if (bRet) {
        document.frmDownload.del.value = '1';
        document.frmDownload.submit();
    }
}

function replaceFile()
{
    document.getElementById('hiddenUploader').style.display = '';
    document.getElementById('existingFileUploadBox').style.display = 'none';
    document.frmDownload.existing_fileup.value = '';
}

function showCalendar()
{
    document.getElementById('calendarMonthNav').style.display = '';
    if (document.getElementById('mainCalendar').style.display != '')
    {
        document.getElementById('mainCalendar').style.display = '';
        document.getElementById('mainAgenda').style.display = 'none';

        for (var x=0; x < document.getElementById('calendar_viewToggleButton1').childNodes.length; x++)
        {
            document.getElementById('calendar_viewToggleButton1').childNodes[x].className = document.getElementById('calendar_viewToggleButton1').childNodes[x].className.replace('_off', '');
        }
        for (var x=0; x < document.getElementById('calendar_viewToggleButton2').childNodes.length; x++)
        {
            document.getElementById('calendar_viewToggleButton2').childNodes[x].className = document.getElementById('calendar_viewToggleButton2').childNodes[x].className + '_off';
        }
    }
}

function showAgenda()
{
    document.getElementById('calendarMonthNav').style.display = 'none';
    if (document.getElementById('mainAgenda').style.display != '')
    {
        document.getElementById('mainCalendar').style.display = 'none';
        document.getElementById('mainAgenda').style.display = '';

        for (var x=0; x < document.getElementById('calendar_viewToggleButton1').childNodes.length; x++)
        {
            document.getElementById('calendar_viewToggleButton1').childNodes[x].className = document.getElementById('calendar_viewToggleButton1').childNodes[x].className + '_off';
        }
        for (var x=0; x < document.getElementById('calendar_viewToggleButton2').childNodes.length; x++)
        {
            document.getElementById('calendar_viewToggleButton2').childNodes[x].className = document.getElementById('calendar_viewToggleButton2').childNodes[x].className.replace('\_off', '');
        }
    }
}

function addStyleClass(obj, className)
{
    obj.className += ' ' + className;
}

function removeStyleClass(obj, className)
{
    obj.className = obj.className.replace(' ' + className,'');
}

function addAppointment(addy, admfg)
{
    if (currentCalendarUid != null)
    {
        document.getElementById('calendar_mainTable').style.display = "none";
        document.getElementById('calendar_mainInfo').style.display = "";
        showPopWin('calendar_appointment_popup.php?dt=' + addy + '&auid=' + currentCalendarUid + '&admfg=' + admfg, 600, 400, null, true);
    }
    else
    {
        if (admfg == 'y')
        {
            document.getElementById('calendar_mainTable').style.display = "none";
            document.getElementById('calendar_mainInfo').style.display = "";
            showPopWin('calendar_appointment_popup.php?dt=' + addy + '&auid=-1&admfg=' + admfg, 600, 400, null, true);
        }
    }
}

function forgottenPassword()
{
    window.location.href = '/members/password_forget.php';
}

var currentCaptchaObj = "";
var previousCommentObj = null;
var currentCalendarUid = null;

function toggleComments(obj, objID)
{
    if (obj.style.display == '')
    {
        obj.style.display = 'none';
    }
    else
    {
        if (previousCommentObj != null)
        {
            previousCommentObj.style.display = 'none';
        }

        if (currentCaptchaObj != "")
        {
            document.getElementById('magicRecaptcha').innerHTML = document.getElementById('commentrecaptcha_' + currentCaptchaObj).innerHTML;
            document.getElementById('commentrecaptcha_' + currentCaptchaObj).innerHTML = "";
        }
        obj.style.display = "";
        currentCaptchaObj = objID;

        document.getElementById('commentrecaptcha_' + currentCaptchaObj).innerHTML = document.getElementById('magicRecaptcha').innerHTML;
        document.getElementById('magicRecaptcha').innerHTML = "";

        previousCommentObj = obj;

    }
}

var currentCalExtraObj = null;

function getMousePos(e)
{
    var cursor = {x:0, y:0};
    if (document.layers) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
        //xMousePosMax = window.innerWidth+window.pageXOffset;
        //yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        cursor.x = window.event.x+document.body.scrollLeft;
        cursor.y = window.event.y+document.body.scrollTop;
        //xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        //yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        cursor.x = e.pageX;
        cursor.y = e.pageY;
        //xMousePosMax = window.innerWidth+window.pageXOffset;
        //yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    if (currentCalExtraObj != null)
    {
        window.parent.document.getElementById('extraHelper').innerHTML = currentCalExtraObj.innerHTML;
        window.parent.document.getElementById('extraHelper').style.top = (cursor.y + 20) + 'px';
        window.parent.document.getElementById('extraHelper').style.left = (cursor.x + 40) + 'px';
        window.parent.document.getElementById('extraHelper').style.display = '';

        //currentCalExtraObj.style.top = (cursor.y + 20) + 'px';
        //currentCalExtraObj.style.left = (cursor.x + 20) + 'px';
        //currentCalExtraObj.style.display = '';
    }
}

function showAppointmentExtra(e, obj, uid)
{
    currentCalExtraObj = obj;
    currentCalendarUid = uid;
}

function hideAppointmentExtra(obj)
{
    window.parent.document.getElementById('extraHelper').style.display = 'none';

    //currentCalExtraObj.style.display = 'none';
    currentCalExtraObj = null;
    currentCalendarUid = null;
}

function startTrackingMousePositionForCalendar()
{

    if (document.layers) { // Netscape
        document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = getMousePos;
    } else if (document.all) { // Internet Explorer
        document.onmousemove = getMousePos;
    } else if (document.getElementById) { // Netcsape 6
        document.onmousemove = getMousePos;
    }
}

function showWishlist()
{
    document.getElementById('wishlistDiv').style.display = '';
}


function deleteAppt(aptuid)
{
    var bRet = confirm("Are you sure you want to delete this appointment? It can not be reversed.");
    if (bRet)
    {
        document.frmAppointment.monkey.value = aptuid;
        document.frmAppointment.submit();
    }
}


// jQ stuff

jQuery.fn.Scroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
				var containerWidth = $strip.parent().parent().width();
				$strip.find("li").each(function(i){
					stripWidth += jQuery(this, i).outerWidth(true);
				});
				$strip.width(stripWidth);
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;
				function scrollnews(offSetLeft, tempo){
					$strip.animate({left: '-='+ offSetLeft}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);
				$strip.hover(function(){
					$strip.stop();
				},
				function(){
					var totalTravel = stripWidth+containerWidth;
					var defTiming = totalTravel/settings.travelocity;
					scrollnews(totalTravel, defTiming);
				});
		});
};
