var $x = jQuery.noConflict();
$x(document).ready(function(){

	$x('.loader').hide();
	$x('.error').hide();
	$x("#quote").validationEngine();	
		
	$x('#quote').submit(function(){
		
		var name = $x('#name').attr("value");
		var email = $x('#email').attr("value");
		var mensahe = $x('#mensahe').attr("value");
		var datastring = "name="+name+"&email="+email+"&mensahe="+mensahe + '&key=true';
		
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
		
		if(name == "" || email == "" || mensahe == ""){
			//alert("emty");
		}
		else{
		
			if(name.length < 2){
			//alert("min of 5");
			}
			else{
				if(!(emailReg.test(email)) ){
					//alert("di mao");
				}
				else{
					
					
				$x.ajax({
				// the URL for the request
				//url: 'admin_quote.php?'+datastring,
				
				url:'http://www.advanzmarketing.com/wp-content/themes/advanzmarketing/quote/admin_quote.php?'+datastring,
				//url:'http://www.advanzweb.com/wp-content/themes/advanzweb/contact/admin_contact.php?'+datastring,
				// (will be converted to a query string)
				// the data to send

				data: {}, 
				//data: {name:"name", email:"email", mensahe:"mensahe", key:"true"},
			
				// whether this is a POST or GET request
				 type : 'POST',
				 
				 beforeSend: function(){
				  // Handle the beforeSend event
				  $x('.loader').show();
				 },
				 
				  success: function(data){
				  // Handle the success event
				  //alert(datastring);
					 $x('.loader').fadeOut(3000,function(){
						$x('.error').fadeIn(500).delay(4000).fadeOut(500);
					 });
					 
					},
				 
				  complete: function(){
				// Handle the complete event
					$x('#name').val('');
					$x('#email').val('');

					$x('#mensahe').val('');
					} 
				});
				
				return false;
					
				}
			}
		}
		
	
		
	});

});


