/* it's soapdesigned.com */
$(document).ready(function() {
	$('a.j_expand').live('click', function() {
		var target = $('#'+$(this).data('target')); 
		if(target.hasClass('active'))
			target.slideUp(150).removeClass('active');
		else	target.slideDown(150).addClass('active');
		return false;
	});
	$('a.j_close').live('click', function() {
		$('#'+$(this).data('target')).slideUp(150).removeClass('active');
		return false;
	});
	$('form').submit(function() {
		var 	error = false,
			errfields = [];		
		$('.required', $(this)).each(function() {
			val = $.trim($(this).val());
			if(val == '') {
				error = true;
				errfields.push($(this));
			} else if($(this).hasClass('email') && !val.match(/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/)) {
				error = true;
				errfields.push($(this));
			} else if($(this).hasClass('phone')) {
				ph = val.replace(/[^0-9]/g,'');
				if(ph.length < 10) {
					error = true;
					errfields.push($(this));
				} else	$(this).removeAttr('style');				
			} else	$(this).removeAttr('style');
		});		
		if(error) {
			/*$('html, body').animate({
				scrollTop: $(this).offset().top-100
			}, 400);*/
			$('.errmessage').slideDown(200, function() {
				if(errfields.length >= 1)
					var t = 1;
					for(i=0; i <= errfields.length; i++) {
						$(errfields[i]).delay(t).animate({borderWidth:5},100);
						t = t+100;
					}
			});
			
		} else	return true;		
		return false;
	});
});

