﻿/*
This is for the custom news slider
*/
var curNum = 0;
var maxNum = 5;
var scrollerInterval;
var intervalTime = 5000;
var contentWidth = 234;

$(document).ready(function() {
    $('#moveto div').click(function() {
        var num = parseInt($(this).text());
        moveToNum(num);

        clearInterval(scrollerInterval);
        startInterval();
    });
    $('#scroller').hover(function() {
        clearInterval(scrollerInterval);
    }, function() {
        startInterval();
    });

    $($('#moveto div')[0]).addClass('active');

    startInterval();

    $("input.loginboxusername").autofill();
    $("input.loginboxpassword").autofill();
});
function moveToNum(num) {
    $('#scroller').animate({ scrollLeft: contentWidth * num }, 'slow');
    $('#moveto div').removeClass('active');
    $(($('#moveto div')[num])).addClass('active');
    curNum = num;
}
function nextScrollContent() {
    curNum = curNum < maxNum - 1 ? curNum + 1 : 0;
    moveToNum(curNum);
}
function startInterval() {
    scrollerInterval = setInterval(nextScrollContent, intervalTime);
}

/*
++++
*/

/*
Custom logo slider
*/
var curNumUp = 0;
var maxNumUp = 3;
var scrollerIntervalUp;
var intervalTimeUp = 7000;
var contentWidthUp = 50;

$(document).ready(function() {
    startIntervalUp();
});
function moveToNumUp(numUp) {
    $('#sponsors').animate({ scrollTop: contentWidthUp * numUp }, 'slow');
    curNumUp = numUp;
}
function nextScrollContentUp() {
    curNumUp = curNumUp < maxNumUp - 1 ? curNumUp + 1 : 0;
    moveToNumUp(curNumUp);
}
function startIntervalUp() {
    scrollerIntervalUp = setInterval(nextScrollContentUp, intervalTimeUp);
}

/*
++++
*/

// Move objects between two Listboxes - and save to hidden field for Code Behind to save to database
function MoveItem(ctrlSource, ctrlTarget, hiddenTarget, hiddenSource) {
	var Source = document.getElementById(ctrlSource);
	var Target = document.getElementById(ctrlTarget);
	var hidtar = document.getElementById(hiddenTarget);
	var hidsour = document.getElementById(hiddenSource);
	// function which retrieves the id's of the listboxes and the hidden fields
	// after it saves the data in variables

	if ((Source != null) && (Target != null)) {
		while (Source.options.selectedIndex >= 0) {
			var newOption = new Option(); // Create a new instance of ListItem
			newOption.text = Source.options[Source.options.selectedIndex].text;
			newOption.value = Source.options[Source.options.selectedIndex].value;

			var arrIds = hidsour.value;
			var split = arrIds.split(","); // Split the values into an array
			var temp = "";

			for (i in split) {
				if (newOption.value != split[i]) {
					temp += split[i] + ","; // Add all remaining values to temp
				}
			}
			hidtar.value += newOption.value + ","; // Save to target hidden field
			hidsour.value = temp; // Give back left over values to source hidden field

			Target.options[Target.length] = newOption;    //Save the item in Target
			Source.remove(Source.options.selectedIndex);  //Remove the item from Source
		}
	}
}