
function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $(input).closest("div.row").find("div.previewrapper > img.uploadpreview").attr('src', e.target.result)
            $(input).closest("div.row").find("div.previewrapper").removeClass("hide");
            $(input).closest("div.row").find("div.previewrapper").fadeIn(1000)
        }
        reader.readAsDataURL(input.files[0]);
    }
}

$(".uploadimg").change(function(){
    readURL(this);
});

$("div.previewrapper > img.removepreview").click(function(){
    $(this).closest("div.row").find("input.uploadimg").val('');
    $(this).closest("div.row").find("input.file-path").val('');
                    $(this).closest("div.previewrapper").fadeOut(1000);
});

function isWeixinBrowser(){
  var ua = navigator.userAgent.toLowerCase();
  return (/micromessenger/.test(ua)) ? true : false ;
}

function closeWechatBrowser(){
	if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
    	WeixinJSBridge.call('closeWindow');
	}     
    $(document).on("WeixinJSBridgeReady", function(){
        WeixinJSBridge.call('closeWindow');
    });
}

$(function() {
    console.log("ready");
    $('.datepicker').pickadate({
    format: 'mm/dd/yyyy',
    selectMonths: true, // Creates a dropdown to control month
    });

    $('.timepicker').pickatime({
        default: 'now', // Set default time
        fromnow: 0,       // set default time to * milliseconds from now (using with default = 'now')
        twelvehour: false, // Use AM/PM or 24-hour format
        donetext: 'OK', // text for done-button
        cleartext: 'Clear', // text for clear-button
        canceltext: 'Cancel', // Text for cancel-button
        autoclose: false, // automatic close timepicker
        ampmclickable: true, // make AM PM clickable
        aftershow: function(){} //Function for after opening timepicker  
    });
    
});

$("form").submit(function(event){
    if ( $(this).find("input.Iagree").is(":checked") == false) {
        alert("发起活动之前，请选择同意主办方须知");
        event.preventDefault();
    }
});  
  
