function mydiff(date1,date2,interval) {
    var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
    date1 = new Date(date1);
    date2 = new Date(date2);
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    switch (interval) {
        case "years": return date2.getFullYear() - date1.getFullYear();
        case "months": return (
            ( date2.getFullYear() * 12 + date2.getMonth() )
            -
            ( date1.getFullYear() * 12 + date1.getMonth() )
        );
        case "weeks"  : return Math.floor(timediff / week);
        case "days"   : return Math.floor(timediff / day); 
        case "hours"  : return Math.floor(timediff / hour); 
        case "minutes": return Math.floor(timediff / minute);
        case "seconds": return Math.floor(timediff / second);
        default: return undefined;
    }
}



$(document).ready(function()
{
	date3 = new Date();
    var datediffs =  mydiff('01/01/1980',date3,'days');
	$("#dateofbirth").datepicker({showOn: "both",	buttonImage: "images/calender/calendar.gif", buttonImageOnly: true, yearRange: "-109:-9",defaultDate: '"-'+datediffs+'"' });
	$("#myaccount1").validate({
		rules: {
			
		emailaddress: {
				email: true,
				maxlength: 50
			      },
			firstName: {
				required: true,
				maxlength: 15
			      },
			 lastName: {
				required: true,
				maxlength: 15
			      },
			 city: {
			 //required: true,
			maxlength: 15
			      }, state: {
			 //required: true,
			maxlength: 15
			      },
				   postCode: {
			 //required: true,
			maxlength: 11
			      },
				   country: {
			 //required: true,
			maxlength: 15
			      }
		},
		messages: {	
		
		  emailaddress: {
				email: "Please provide valid email",
				minlength: "Enter more than  15 character"
			},
			firstName: {
				required: "Please provide first name",
				minlength: "Enter more than  15 character"
			},
			lastName: {
				required: "Please provide last name",
				minlength: "Enter more than 15 character"
			},
			city: {
				required: "Please provide city",
				minlength: "Enter more than  15 character"
			},
			state: {
				required: "Please provide state",
				minlength: "Enter more than  15 character"
			},
			postCode: {
				required: "Please provide post code",
				minlength: "Enter more than 10 character"
			},
			country: {
				required: "Please provide country",
				minlength: "Enter more than  15 character"
			}
		}
		

	});	
 
       $("#myaccount2").validate({
		rules: {
			
			phone: {
				required: true,
				maxlength: 15
			      },
			 phoneCarrier: {
				required: true,
				maxlength: 50
			      }
		},
		messages: {			
			phone: {
				required: "Please provide  mobile number",
				maxlength: "Can not Exceed max 15 character"
			},
			phoneCarrier: {
				required: "Please providea phone Carrier",
				maxlength: "Can not Exceed max 50 character"
			}
		}
		

	});	
	    $("#myaccount3").validate({
		rules: {
			
			passwordOld: {
				required: true,
				minlength: 6
			      },
			 passwordNew: {
				required: true,
				minlength: 6
			      },
			 passwordNewConfirm: {
			 required: true,
			 minlength: 6,
			 equalTo: "#passwordNew"
			      }
		},
		messages: {			
			passwordOld: {
				required: "please enter your old password",
				minlength: "password must be at least 6 characters long"
			},
			passwordNew: {
				required: "please enter a new password",
				minlength: "password must be at least 6 characters long"
			},
			passwordNewConfirm: {
				required: "please confirm your new password",
				minlength: "password must be at least 6 characters long"
			}
		}
		

	});	
	
		

						   
$.validator.setDefaults({
	submitHandler: function() { 
	
	
	$("#myaccount1").submit();
	$("#myaccount2").submit();
	$("#myaccount3").submit();
	
}
});
						   

});

