// JavaScript Document

		$( function() {
			$( '#gotaquestion' ).ipValidate( {

				required : { //required is a class
					rule : function() {
						return $( this ).val() == '' ? false : true;
					},
					onError : function() {
						if( !$( this ).parent().hasClass( 'element_container' ) ) {
							$( this ).parent().addClass( 'error' );
							showqmessage("* Please fill you information");
						} 
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},				
				
				youremail: { // is a class
					rule : function() {
						//return $( this ).val() == 'Email Address' ? false : true;
						return isValidEmailAddress( $(this).val() );
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						showqmessage("* Please fill you information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},				
								
				submitHandler : function() {						
					//$('.holder').hide();
					//$('#loading').show();
					$.post('getaquestion.php',{qemail:$('#qemail').val() ,question:$('#question').val()},
					function(data){
						if( data.indexOf('success')>=0 ) {
							showqmessage("Thankyou for your message");
							$('#qemail').val("");
							$('#question').val("");
							//$('li.none').append("Thankyou for your message");
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
							}
						} else {
							//$('li.none').append("Sorry but your message could not be sent, try again later");
							showqmessage("Sorry but your message could not be sent, try again later");
						}
					});		
					
					return false;																																		 
				}
			});
		});
		
		function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
	}
	
	function showqmessage(text) {
		//$('li.none').append(" ");
		$('.questionmessage font').replaceWith("<font>"+text+"</font>");
	}
