function isEmail(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(str) == false) {
		return false;
	}
	return true;
}

$(document).ready(function(){
	
	if ($('div#agenda').length) {
	
		$('div#agenda h2').click(function() {
		
			var _class = $(this).attr('class').split('-');

			if (_class[1] == 'off') {
				
				$('div#agenda h2').each(function () {
					var _class = $(this).attr('class').split('-');
						$(this).attr('class', _class[0]+'-off');
				});
				
				$('div#agenda div').each(function () {
					var _class = $(this).attr('class').split('-');
						$(this).attr('class', _class[0]+'-off');
				});
				
				$(this).attr('class', _class[0]+'-on');
				$('div#agenda div.'+_class[0]+'-off').attr('class', _class[0]+'-on');
			}
			
			return false;
		
		});
	
	}
    
    if ($('div#sponsor-bank').length) {
    	var _html = $('div#sponsor-bank').html();
    				$('div#sponsor-bank').html('');
    	
    	$('div#sponsors').append(_html);
    	
		$('div.slideshows').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			timeout:  4000	
		});
	
    }
    
    if ($('img#content-single-big-image').length) {
    	$('img#content-single-big-image').appendTo($('div#bigimage'));
    	$('div#bigimage img#content-single-big-image').attr('style', '');
    }


	if ($('form.generic-form').length) {
		
		
		$('form.generic-form .req').change(function(e) {
			if (($(this).val().length > 0 || ($(this).is('SELECT') && $(this).val() == '--')) && $(this).hasClass('error-form')) {
				$(this).removeClass('error-form');
			} else {
				if (($(this).val().length == 0 || ($(this).is('SELECT') && $(this).val() == '--')) && !$(this).hasClass('error-form')) {
					$(this).addClass('error-form');
				}
			}
		});
		
		$('input#register-now').click(function(){
		
			$('form.generic-form .req').each(function(u, e){
			
				if ($(e).hasClass('error-form')) {
					$(e).removeClass('error-form');
				}
				
				if ($(e).is('SELECT')) {
					if ($(e).find(':selected').val() == '--') {
						$(e).addClass('error-form');
					}
				}
				
				if ($(e).is('INPUT')) {
					if ($(e).val().length == 0) {
						$(e).addClass('error-form');
						console.log("ERROR");
					}
				}
			});
			
			if ($('form.generic-form .error-form').length > 0) {
				alert("Please fill out all the required information");
				return false;
			}
			
			if (isEmail($('input#email').val()) == false) {
				$('input#email').addClass('error-form');
				alert('Invalid email address');
				return false;
			}
						
			return true;
		});
	
	}
	
});
