$(document).ready(function(){
	
	if ( $('#subgroups').length > 0 ){
		loadsubgroups( $('select[name=group]').val() );
	}

	$('.tab-content').html( $('ul.toggle-box li.selected').find('div').html() );

	$('ul.toggle-box li').click( function(){
		$('ul.toggle-box li.selected').removeClass('selected');
		$(this).addClass('selected');
		$('.tab-content').html( ( $(this).find('div').html() ) )
	})

	$(".partners img").hover(
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('off','on'));
	  },
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('on','off'));
	  }
	);
	
	$('ul.mainmenu li').hover(function(){
	  $(this).find('.submenu').show(); 
	},function(){
	  $(this).find('.submenu').hide(); 
	});    

	$('.mySelectBoxClass').customStyle();
});

function loadsubgroups( groupstring ){

//	$('#subgroups').html('<img src="/ajrgfx/ajax/ajax-loader.gif" alt="" />')

	$('#subgroups').load('/ajrgfx/ajax/select-subgroups.asp?nodeid='+groupstring.split('|')[0]);

}

function setactionurl( me ){

	me.action = me.group.value.split('|')[1];
	me.group.disabled = true;
	validateform( me );
	me.group.disabled = false;

}

function validateform( me ){

	$(me).find('input.alert').each( function(){
	
		$(this).css('border','none');
		$(this).removeClass('alert')
	
	});
	
	var doSubmit = true;

	$(me).find('.required').each( function(){
	
		if( $(this).attr('type') == 'checkbox' ){
		
			if( ! $(this).attr('checked') ){
			
				alert( $(this).attr('title') );
				
				doSubmit = false;
			
			}
		
		}
		
		if( $(this).attr('class').indexOf('email') > 0 ){
		
			if( !emailCheck( $(this).val() ) ){

				$(this).css('border','1px solid red');
				$(this).addClass('alert')
			
				doSubmit = false;
			
			}
		
		} else {
		
			if ( $(this).val() == '' ){
		
				$(this).css('border','1px solid red');
				$(this).addClass('alert')
				
				doSubmit = false;
		
			}
			
		}
		
	});

	$('.alert').focus( function(){
		$(this).css('border','none');
		$(this).removeClass('alert');
	})
	
	if ( doSubmit ){ me.submit() }

}



