// USER REGISTRATION JavaScript

$(document).ready(function (){
								
	/* USER REGISTRATION */
	//Below code is commented to disable ajax version of Signup
	//$("#frmRegistration").ajaxSubmit();
	
	/* DO RESET*/
	$("input").filter("#btnCancel").click(function(){	
		$("#formErrors").hide("slow");
		return false;
	})
	.end()	
								
	//Call function to Copy/Remove Shipping address. 
	$("#copyAddress").copyAddressfn();	
});


/**************
 * Desc: Process user Registration on form Submit. 
 * Author: antony@vtc
 * Date: 18-Sept-2007
 */	
$.fn.ajaxSubmit = function(e) { 
	/* Change a form's submission type to ajax */ 		
	this.submit(function(){ 
		var params = {}; 
		$(this) .find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
		.filter(":enabled").each(function() { 
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});	
		$("body").addClass("curWait"); 
		$.post(appUrl+"/app/modules/member/signup.ajax.php", params, function(json){ 
			$("body").removeClass("curWait"); 
			respObj = eval("(" + json + ")");
			alert( respObj['redirect']); 	
			if( respObj['redirect']){
				window.location = appUrl+"/app/modules/shopping/payment.php"; 
			}else{
				alert("erreur : des champs requis ne  sont pas correctement remplis");	
			}
		}); 
		return false; 
	}); 
	return this;
}

/**************
 * Desc: Copy/Remove Shipping address. 
 * Author: sujith@vtc
 * Date: 18-Sept-2007
 */		 
$.fn.copyAddressfn = function(){
	this.click(function(){
		if(this.checked){
			$("#shipFirstName").val($("#firstName").val());
			$("#shipLastName").val($("#lastName").val());
			$("#shipCompany").val($("#company").val());
			$("#deliveryAddress").val($("#addressDetails").val());
			$("#shipPostCode").val($("#postalCode").val());
			$("#shipCity").val($("#city").val());
			$("#shipCountry").val($("#country").val()); 
			
		}else{
			$("#shipFirstName").val('');
			$("#shipLastName").val('');
			$("#shipCompany").val('');
			$("#deliveryAddress").val('');
			$("#shipPostCode").val(' ');
			$("#shipCity").val(' ');	
			$("#shipCountry").val('');
		}		
	});	
}

