$(function () {
	$(".DateTime").datepicker({
		dateFormat: "dd/mm/yy"
	});

	$(".Int32").keydown(function (e) {
		switch (e.keyCode) {
			case 8:     //backspace
			case 37:    //arrow keys
			case 38:    // |
			case 39:    // |
			case 40:    // |-
			case 46:    //delete
				break;
			default:
				//only allow numeric keypresses
				if (!(e.keyCode >= 48 && e.keyCode <= 57 && !event.shiftKey) && !(e.keyCode >= 96 && e.keyCode <= 105)) {
					e.preventDefault();
				}
				break;
		}
	});

	$("ul.menu").menu();
});


jQuery.fn.menu = function() {
	return this.each(function() {
		//submenu styling
		$(this).find('li a').addClass('ui-widget ui-state-default').css({ 'border': 'none', 'fontSize': '1em' });
		$(this).find('ul li a').css('backgroundImage', 'none');

		//dropdown show/hide events
		// - mouse hover
		$(this).find('li').hover(function() {
			$(this).find('ul').slideDown("fast");
		}, function() {
			$(this).find('ul').slideUp("fast");
		});
		// - keyboard focus
		$('a, input').focus(function() {
			$('ul.menu ul').css('display', 'none');
		});
		$('ul.menu ul li a').unbind('focus');
		$(this).find('> li a').focus(function() {
			$(this).parent().find('ul').css('display', 'inline-block');
		});

		//menu hover events
		// - mouse hover
		$(this).find('li a').hover(function() {
			$(this).removeClass('ui-state-default').addClass('ui-state-hover');
		}, function() {
			$(this).removeClass('ui-state-hover').addClass('ui-state-default');
		})
		// - keyboard focus
		.focus(function() {
			$(this).removeClass('ui-state-default').addClass('ui-state-hover');
		})
		.blur(function() {
			$(this).removeClass('ui-state-hover').addClass('ui-state-default');
		});
	});
};

$(document).ready(function(){
var first = 0;
function removeFirst(strTickerID, speed){
	first = $('ul#'+strTickerID+' li:first').html();
	$('ul#'+strTickerID+' li:first')
	.animate({opacity: 0}, speed)
	.fadeOut('slow', function() {$(this).remove();});
	addLast(strTickerID, first, speed);
}
function addLast(strTickerID, first, speed){
	last = '<li style="display:none">'+first+'</li>';
	$('ul#'+strTickerID).append(last)
	$('ul#'+strTickerID+' li:last')
	.animate({opacity: 1}, speed)
	.fadeIn('slow')
}
function removeFirstHS(){
	removeFirst('headersplashticker',700); }
function removeFirstCS(){
	removeFirst('c2aclientticker',1000);}
	interval = setInterval(removeFirstHS, 10000);
	interval = setInterval(removeFirstCS, 2500);
});

function changecss(theClass,element,value) {
	var cssRules;
	var added = false;
	for (var S = 0; S < document.styleSheets.length; S++){
		if (document.styleSheets[S]['rules']) {
			cssRules = 'rules';
		} else if (document.styleSheets[S]['cssRules']) {
			cssRules = 'cssRules';
		} else {}
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				if(document.styleSheets[S][cssRules][R].style[element]){
					document.styleSheets[S][cssRules][R].style[element] = value;
					added=true;
					break;
				}
			}
		}
		if(!added){
			if(document.styleSheets[S].insertRule){
				document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
		}
	}
}

function csrefresh(nmode) {
	$(".csrb").show('fast');
	$(".csfw").show('fast');
	if (!document.getElementById('FW').checked) { $(".csfw").hide('slow') } else { $(".csfw").show('slow') }
	if (!document.getElementById('RB').checked) { $(".csrb").hide('slow') }else{ $(".csrb").show('slow') }
	if (!document.getElementById('AU').checked) { $(".csau").hide('slow') }
	if (!document.getElementById('GB').checked) { $(".csgb").hide('slow') }
	if (!document.getElementById('IE').checked) { $(".csie").hide('slow') }
	if (!document.getElementById('EU').checked) { $(".cseu").hide('slow') }
	if (!document.getElementById('US').checked) { $(".csus").hide('slow') }
	if (!document.getElementById('ROW').checked) { $(".csrow").hide('slow') }
	if (!document.getElementById('ANON').checked) { $(".csanon").hide('slow') }
}

