;$(function(){
	var queryString = function (val) {
		var uri = window.location.search;
		var re = new RegExp("" +val+ "=([^&?]*)", "ig");
		return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length+1)):null);
	};
	var derver = queryString('derver');
	var wifiName = queryString('wifiName');
    var type = queryString('type');
    //数据来源
    var source = queryString('source');
	if (wifiName) {
		$('#account').text(decodeURI(wifiName));
	}
	$('#password').on('keyup', function () {
		var password = $('#password').val();
		if (password) {
			$('#tips').hide();
		}
	})
	$('#submitPassword').on('click', function () {
		var password = $('#password').val();
		var exp = /^[\w]{8,}$/;
		if (password == '') {
			$('#tips').show();
			$('#tips').text('请输入wifi密码')
			return
		} else if (!exp.test(password)) {
			$('#tips').show();
			$('#tips').text('wifi密码只能输入字母和数字并且最少八位');
		} else {
			$('#tips').hide();
		}
        //var url = window.location.origin + '/api/parents/parents/V1/connectWifi';
        url = 'https://t.sharingschool.com/sz/api/parents/parents/V1/connectWifi';
        if(source == 'test'){
            var url = 'https://xt.sharingschool.com/sz/api/parents/parents/V1/connectWifi';
        }
        var data = { derver: derver, wifiName: wifiName, password: password,type:type };
		$.ajax({
			type: "post",
			url: url,
			async: true,
            data: JSON.stringify(data),
            contentType: "application/json",
			success: function (res) {
				if (res.code == '999') {
					$('.page1').hide();
					$('.page2').show();
				}
			}
		});
	})
});
