/*
jQuery(document).ready(function(){
	
	
	jQuery('#btnsubmit').click(function() {
	
		var name = jQuery("input#field_1").val();
		var email = jQuery("input#signup_email").val();
		var user = jQuery("input#signup_username").val();
		var pass = jQuery("input#signup_password").val();
		
		var dataString = 'field_1='+ name + '&signup_email=' + email + '&signup_username=' + user + '&signup_password=' + pass;
		console.log(dataString);
		
		jQuery.ajax({
      	  type: "POST",
	      url: "/php/request.php",
	      data: dataString,
	      success: function(response) {
			console.log(response);
	      }
	     });
	    return false;
		
	});
	
})
*/


var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)jQuery/i;			
				
jQuery(document).ready(function(){
	
	var options = { 
		//target:        '#output2',   // target element(s) to be updated with server response 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse,  // post-submit callback 
		clearForm: false,        // clear all form fields after successful submit 
		resetForm: false        // reset the form after successful submit 
	}; 

	// bind to the form's submit event 
	jQuery('#frm').submit(function() { 
		// inside event callbacks 'this' is the DOM element so we first 
		// wrap it in a jQuery object and then invoke ajaxSubmit 
		jQuery(".err_msg").remove();
		jQuery(this).ajaxSubmit(options); 
		// !!! Important !!! 
		// always return false to prevent standard browser submit and page navigation 
		return false; 
	}); 
	
		// pre-submit callback 
	function showRequest(formData, jqForm, options) {
		// formData is an array; here we use jQuery.param to convert it to a string to display it 
		// but the form plugin does this for you automatically when it submits the data 
		var queryString = jQuery.param(formData); 
		
	/*	if (jQuery("#field_1").val().replace(/^\s*|\s*jQuery/g,"")==""){
			alert ("Please enter your full name.");
			jQuery("#field_1").focus();
			return false;
		}
		if (jQuery("#signup_username").val().replace(/^\s*|\s*jQuery/g,"")==""){
			alert ("Please enter your user name.");
			jQuery("#signup_username").focus();
			return false;
		}
							
		if (emailfilter.test(jQuery("#signup_email").val())==false){
			alert ("Please enter valid Email ID.");
			jQuery("#signup_email").focus();
			return false;
		}
		
		if (jQuery("#signup_password").val().replace(/^\s*|\s*jQuery/g,"")==""){
			alert ("Please enter password.");
			jQuery("#signup_password").focus();
			return false;
		}*/
 
		// jqForm is a jQuery object encapsulating the form element.  To access the 
		// DOM element for the form do this: 
		// var formElement = jqForm[0]; 
 
		//alert('About to submit: \n\n' + queryString); 
 
		// here we could return false to prevent the form from being submitted; 
		// returning anything other than false will allow the form submit to continue 
		return true; 
	} 
	 
	// post-submit callback 
	function showResponse(responseText, statusText, xhr, jQueryform)  { 
		// for normal html responses, the first argument to the success callback 
		// is the XMLHttpRequest object's responseText property 
 
		// if the ajaxSubmit method was passed an Options Object with the dataType 
		// property set to 'xml' then the first argument to the success callback 
		// is the XMLHttpRequest object's responseXML property 
 
		// if the ajaxSubmit method was passed an Options Object with the dataType 
		// property set to 'json' then the first argument to the success callback 
		// is the json data object returned by the server 
		
		//jQuery("#frm_addyourown_wrapper").hide();
		//wedidthis_visible=false;
		
		//jQuery("#confirmation_wrapper").show();
		//jQuery("#confirmation_wrapper").css({top: '100px', left: '180px'});
	
		//alert(responseText);
		
 
		var data=eval('(' + responseText + ')'); 
		var datamsg=data.msg;
						
		if(data.status=="error"){							
			if(!datamsg.field_1==""){
				jQuery("<span class='err_msg'>Please enter your full name</span>").insertAfter("td.field_1 input");
			} 
			if(!datamsg.signup_username==""){
				jQuery("<span class='err_msg'>" + datamsg.signup_username +"</span>").insertAfter("td.signup_username input");
			} 
			if(!datamsg.signup_email==""){
				jQuery("<span class='err_msg'>"+ datamsg.signup_email +"</span>").insertAfter("td.signup_email input");
			}
			if(!datamsg.signup_password==""){
				jQuery("<span class='err_msg'>Please enter your password</span>").insertAfter("td.signup_password input");
			}	
		} else{
			jQuery("#msg").append(datamsg.success_msg).css("color","green");
		}					
	}	
});
