// JavaScript Document

		$( function() {
			$( '#needaquotation' ).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' );
							needamessage("* Please fill you information");
						} 
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				yname: { //fname is a class
					rule : function() {
						return $( this ).val() == 'Please type your name...' ? false : true;
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						needamessage("* Please fill you information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},			
				
				yemail: { // is a class
					rule : function() {
						//return $( this ).val() == 'Email Address' ? false : true;
						return isValidEmailAddress( $(this).val() );
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						needamessage("* Please fill you information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				pnumber: { //fname is a class
					rule : function() {
						return $( this ).val() == 'Phone Number' ? false : true;
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						needamessage("*select one");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				ncategory: { //fname is a class
					rule : function() {
						return $( this ).val() == 'Select One' ? false : true;
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						needamessage("* Please fill you information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				submitHandler : function() {						
					//$('.holder').hide();
					//$('#loading').show();
					$.post('needaquotation.php',{yourname:$('#yourname').val(), youremail:$('#youremail').val(), phonenumber:$('#phonenumber').val(), category:$('#category').val()},
					function(data){
						if( data.indexOf('success')>=0 ) {
							needamessage("Thankyou for your message");
							$('#yourname').val("");
							$('#youremail').val("");
							$('#phonenumber').val("");
							$('#category').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");
							needamessage("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 needamessage(text) {
		//$('li.none').append(" ");
		$('.needmessage font').replaceWith("<font>"+text+"</font>");
	}
