/*
Author: WISE MONKS
Visit us at: http://www.wisemonks.com/
*/

$(function(){
	//1#form inputs default values
	$(".card_form input.text, .card_form textarea").each(function(){
		
		$(this).val($(this).attr('rel'));
		
		$(this).focus(function(){
			if($(this).val() == $(this).attr('rel')){
				$(this).val("");
			}	
		});
		
		$(this).blur(function(){
			if(!$(this).val().length){
				$(this).val($(this).attr('rel'));
			}
		});
	});//1#end
	
	//2#email validation function
	var email_test = function(str) {
	     var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$";
	     var regex = new RegExp(emailReg);
	     return regex.test(str);
	}//2#end
	
	
	//3#post card form validation
	$('.card_form .submit').click(function(){
		
		$('#card_error').hide();
		
		var error_log = [];
		
		$(".card_form input.text, .card_form textarea").each(function(){
			
				if($(this).hasClass('email')){
					if(!email_test($(this).val())){
						error_log.push($(this).attr('title'));
					}
				}
				else{
					if(!$(this).val().length || $(this).val() == $(this).attr('rel')){
						error_log.push($(this).attr('title'));
					}
				}
		});
		
		if(error_log.length){
			$('#card_error').html(error_log.join('<br />')).fadeIn('slow').focus();
			return false;
		}
		else{
			return true;
		}
		
	});//3#end
	
	 $(document).pngFix(); 
	
});