/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function () {
    var countryID = $('#countryID').val();
    var state = $('#statehidValue').val();
    listStates(countryID, state);

    //validate date of birth
    if ($("#dobMonth").val() != '' && $("#dobYear").val() != '' && $("#dobDay").val() != '') {
        validateDOB()
    }

    $('.div_upload_sub_userProfilePicture_edit').addClass('edit_image');
    $('.div_upload_sub_userProfilePicture_edit a').html('Edit');
   
    $(document).on('change',".dob-valid", function () {
        if ($("#dobMonth").val() != '' && $("#dobYear").val() != '' && $("#dobDay").val() != '') {
            validateDOB();
        }
    })
});
//ajax state populating
function listStates(countryID, stateID)
{
    $('#statehidValue').val(stateID);
	if(countryID!=''){
		var data={
			"countryID" : countryID ,
			"stateID" : stateID
		};
		$.ajax({
			type: "POST",
			url: GLOBAL_BASE_PATH + "/ajax/ajaxState/",
			data: data,
			beforeSend:function(){
				$("#loadProcessImage").append('<img src="' + GLOBAL_ROOT_PATH + '/public/default/manage/standard/images/ajax-loader.gif" id="loading_gif2" height="16" width="16" alt="loader" />');
			},
			success: function (msg) {
				$("#loadProcessImage").empty();
				if (msg != '') {
					$("#stateInput").show();
					$('#stateID').empty();
					$("#stateProvinceInput").hide();
					$("#stateID").append('<option value="">' + lblSelect + '</option>' + msg);
					$("#stateSelectedType").val("state");
					$("#userProvince").val('');
					$("#div_err_frmBusiness_provincehidden").css("display", "none");
				} else {
					$("#stateInput").hide();
					$("#stateProvinceInput").show();
					$("#stateSelectedType").val("province");
					$("#stateID").val('');
					$("#div_err_frmBusiness_statehidden").css("display", "none");
				}
			}
		});
	}
}
function getStateHiddenValue(val)
{
    $('#statehidValue').val(val);
}
function validateDOB() {
    var month = $("#dobMonth").val();
    var year = $("#dobYear").val();
    var days = Math.round(((new Date(year, month)) - (new Date(year, month - 1))) / 86400000);
    var dobDay = $("#dobDay").val();
    if (dobDay > days) {
        $("#hiddenDob").val(1);
    } else {
        $("#hiddenDob").val(0);
    }
}