$(document).ready(function(){global_obj.page_init()});
$(function(){
	$("#memebercompanysubmit").click(function(){
		if(global_obj.check_form($('*[notnull]'))){return false};
		$(this).attr('disabled', true).val('提交中...');
		var x=document.getElementById("memebercompanyform");
		x.action="user.aspx?action=add&m=mobile&from="+window.location.href;	
		x.submit();
	});
	$("#MemberrenzhengSubmit").click(function(){
		if(global_obj.check_form($('*[notnull]'))){return false};
		$(this).attr('disabled', true).val('提交中...');
		var x=document.getElementById("MemberqiyeCertForm");
		x.action="mycompanycert.aspx?action=add&from="+window.location.href;	
		x.submit();
	});
	$("#MemberjobinfoSubmit").click(function(){
		if(global_obj.check_form($('*[notnull]'))){return false};
		var ex = /^\d+$/;
		if (!ex.test($("#txtInfoPeoper").val())) 
		{
			alert("请正确输入招聘人数！");
		}
		else if (!ex.test($("#txtInfoDateNum").val())) 
		{
			alert("请正确输入职位有效期天数！");
		}
		else
		{
			$(this).attr('disabled', true).val('提交中...');
			var x=document.getElementById("MemberJobInfoForm");
			x.action="zpadd.aspx?action=add&from="+window.location.href;	
			x.submit();
		}
	});
	$("#btnPicDelete").click(function(){
		$("#showimage1").show();							  
		$("#showimage2").hide();							  
	});
	/**********************************/
	if( $("#memeberspacesubmit").length>0)
	{
		//修改基本资料
		$("#memeberspacesubmit").on("click",function(){
			if(global_obj.check_form($('*[notnull]'))){return false};
			var chrname=$.trim($("#txtChrTrueName").val()),
				chremail=$.trim($("#txtChrEmail").val()),
				chrqq=$.trim($("#txtChrQQ").val()),
				ChrTel=$.trim($("#txtChrTel").val());
			$.ajax({
				async: false,
				cache: false,
				url: "/public/ajax.aspx",	
				type: "post",
				data: {action:"editspace","chrname":chrname,"chremail":chremail,"chrqq":chrqq,"ChrTel":ChrTel},
				success: function(data){
					if(data=="0")
					{
						alert("个人资料修改成功！");
					}
					else
					{
						alert(data);
					}
				}
			})
		})	
	}
	if($("#memeberpasswordformsubmit").length>0)
	{
		//修改密码
		$("#memeberpasswordformsubmit").on("click",function(){
			if(global_obj.check_form($('*[notnull]'))){return false};
			var oldpassword= $.trim($("#MemberOldPassword").val()),
				newpassword= $.trim($("#MemberNewPassword").val()),
				newpassword_= $.trim($("#MemberNewPassword_").val());
			$.ajax({
				async: false,
				cache: false,
				url: "/public/ajax.aspx",	
				type: "post",
				data: {action:"editpassword","oldpass":oldpassword,"userpass":newpassword,"password":newpassword_},
				success: function(data){
					if(data=="1")
					{
						$("#MemberNewPassword").val("");
						$("#MemberNewPassword_").val("");
						alert("恭喜您，密码修改成功，请牢记！");
					}
					else
					{
						alert(data);
					}
				}
			})
		})	
	}
	if($("#memeberavatarform").length>0)
	{
		$("#addfile").on('change', function () {
            var f = $(this).get(0).files[0];
			$("#memeberavatarsrc").attr("src","/template/ant/wap/n/images/downloading.gif");
			var form = document.getElementById('myform');
			var formData = new FormData(form);
			formData.append('upload_pic', f);
			var xhr = new XMLHttpRequest();
			xhr.addEventListener("load", uploadComplete, false);
			xhr.addEventListener("error", uploadFailed, false);
			xhr.open('POST', form.action);
		　　xhr.send(formData);
        });
		function uploadComplete(evt)
		{
			var data = $.parseJSON(evt.target.responseText);
			if(data.error=="0")
			{
				$("#memeberavatarsrc").attr("src",data.url+data.img_url);
			}
			else
			{
				win_alert(data.errmsg)
			}
		}
		function uploadFailed()
		{
			win_alert("上传失败！请重试！");	
		}
		
	}
});
