"use strict";
var lvid = getParameter("lvid");
var toLvid = getParameter("tolvid");
var sign = getParameter("sign");
var tag = getParameter("tag");
var selfHandimg = (lvid == toLvid);
var isfriend = false;
var userOut;
var birthyear, birthmonth, birthday;
var province, city, district, userName, remark;;
var s_countries, s_city, s_county;
var birsDateTime;
var date = new Date();
var Thisyear = date.getFullYear();
var closeWindowHook = false; //关闭窗口hook
var initStatus = false;
var isclose = false;
var signatureT;
var teamName;

function checkUndify(value) {
	if(typeof(value) == "undefined") {
		return "";
	}
	return value;
}
//修改资料 
function updateUser() {
	var params = '{"command":9012,"params":{"lvid":' + lvid + '}}';
	var result = $.parseJSON(sendCommand(params));
	if(result['errorid'] != 0 || result['status'] == 0) {
		return;
	}
	var FNickName = $("#nickedit").val();
	if(!FNickName) {
		var paramStr = "{title:'修改资料',cat:0,content:'请输入昵称！'}";
		var params = "{command:9006,params:" + paramStr + "}";
		sendCommand(params);
		return;
	}
	var FSex = $('#sex').attr('sextype');
	var profession = $("#userprofessionedit").val();
	var company = $("#companyedit").val();
	var signature = $("#signature").val();
	if(signature != signatureT) {
		var params = '{"command":1013,"params":{"lvid":' + lvid + '}}';
		sendCommand(params);
	}
	var params = {
		'lvid': lvid,
		'nickname': FNickName,
		'profession': profession,
		'company': company,
		'sex': FSex,
		'signature': signature,
		'province': checkUndify(s_countries),
		'city': checkUndify(s_city),
		'county': checkUndify(s_county),
		'birthYear': birthyear,
		'birthMonth': birthmonth,
		'birthDay': birthday,
		'sign': sign
	};
	$.getJSON(requestUrlMap['updateUserInfo']['url'], params, function(data) {
		if(data.errorid != 0) {
			var paramStr = "{title:'修改资料',cat:2,content:'修改失败，请重试！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			return;
		}
		if(closeWindowHook) {
			closeDialogWindow();
		}
		$(".datPriMain").show();
		$(".xiuGai-Main").hide();
		loadUserInfo();
	});
}

//年月绑定事件
function TGetDaysInMonth(iMonth, iYear) {
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}
//初始化日
function TUpdateCal(iYear, iMonth) {
	var dDate = new Date(),
		daysInMonth = TGetDaysInMonth(iMonth, iYear),
		str = "";
	$("#dayitem").empty();
	for(var d = 1; d <= parseInt(daysInMonth); d++) {
		str = "<dd> <span class=\"currency_type\">" + d + "日</span> </dd>";
		$("#dayitem").append(str);
	}
	$(".day").find(".currency_type").click(function() {
		var ty = $(this).text();
		if(ty.length == 3) {
			ty = ty.slice(0, 2);
		} else {
			ty = ty.slice(0, 1);
		}
		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		birthday = ty;
		$('#day').html(birthday + '日');
		$("#pBirthday").html(birthyear + "年" + birthmonth + "月" + birthday + '日');

	});
}
$(document).on('click', '#supergroupList dd', function() {
	var upGroupid = $(this).find('span').attr('groupid');
	$('#supergroup').text($(this).find('span').text());
	if($('#supergroup').text() == teamName) {
		return;
	}
	if(upGroupid == -2) {
		var params = '{command:9006,params:{"cat":3,"title":"用户提示", "content":"你确定将(' + toLvid + ')移至黑名单吗？"}}';
		var resultS = $.parseJSON(sendCommand(params));
		if(resultS['errorid'] == 1) {
			var params = '{command:1012,params:{"userid":' + toLvid + ',"teamid": ' + upGroupid + ' }}';
			var result = $.parseJSON(sendCommand(params));
		}
		if(resultS['errorid'] == 2) {
			loadUserInfo();
			return;
		}
		return;
	}
	var params = '{command:1012,params:{"userid":' + toLvid + ',"teamid": ' + upGroupid + ' }}';
	var result = $.parseJSON(sendCommand(params));
	if(result['errorid'] != 0) {
		return;
	}
	loadUserInfo();
})

function loadUserInfo() {
	var params = {
		'lvid': lvid,
		'tolvid': toLvid == lvid ? '' : toLvid,
		'sign': sign
	};
	$.getJSON(requestUrlMap['userInfo']['url'], params, searchUserCallBack);
}
//提交的回调函数

function searchUserCallBack(data) {
	$(".loading-popup").hide();
	$("#supergroupList").html('');
	if(data.errorid != 0) {
		var paramStr = "{title:'修改资料',cat:2,content:'非法请求！'}";
		var params = "{command:9006,params:" + paramStr + "}";
		sendCommand(params);
		return;
	}
	var html = "";
	userOut = data.userinfo;
	var isFriend = data.isfriend;
	if(isFriend) {
		var team = data.userinfo.team;
		if(team.length > 4) {
			$("#supergroupList").css('overflow-y', 'scroll');
		}
		for(var i = 0; i < team.length; i++) {
			if(team[i].id == userOut.FteamId) {
				teamName = team[i].teamName;
			}
			$("#supergroupList").append("<dd> <span class=\"currency_type\" groupid=" + team[i].id + ">" + team[i].teamName + "</span> </dd>");
		}
		$('#supergroup').text(teamName).attr('groupid', userOut.FteamId);
	}else{
		$('.groupL').hide();
		$('.disabledBtn').show();
		$('.markNamebtn').hide();
	}
	birsDateTime = new Date(userOut.systemtime * 1000);
	//如果不是查看自己的资料，隐藏编辑按钮
	var isSelf = true;
	if(userOut.lvid != lvid) {
		$(".editBut").hide();
		$('.img-private-warp').css({
			'cursor': 'default',
			'pointer-events': 'none'
		});
		$('#tabCart li').eq(1).hide();
		if(userOut['companyid'] == 0) {
			$('.remark,.groupL').show();
		}
		isSelf = false;
		printData();
	}else{
		printData();
		myselfInfo();
		$('.datPriInfo ul').css('overflow', 'hidden');
	}
	initStatus = true;
}

function myselfInfo(){
	if(!userOut.remark) {
		remark = '-';
	} else {
		remark = userOut.remark.Trim();
		$('.markNamebtn').text('修改备注');
	}
	$('#age').text(userOut.age);
	$('#remarkN').text(remark);
	var guoindex = dsy.Items["0"].indexOf(userOut.province);
	guoindex = -1 ? 0 : guoindex;
	var guoarrindex = "0_" + guoindex;
	var shengindex = dsy.Items[guoarrindex].indexOf(userOut.city);
	shengindex = -1 ? 0 : shengindex;
	var shengarrindex = guoarrindex + "_" + shengindex;
	//判断是否修改过内容
	setInterval(function() {
		var FSex = $('#sex').attr('sextype');
		var profession = $("#userprofessionedit").val();
		var company = $("#companyedit").val();
		var FNickName = $("#nickedit").val();
		var signature = $("#signature").val();
		var age = $("#age").text();
		if((userOut.sex != FSex || userOut.profession != profession || userOut.company != company || userOut.nickname != FNickName || userOut.birthyear != birthyear || userOut.birthmonth != birthmonth || userOut.birthday != birthday || checkUndify(userOut.province) != s_countries || checkUndify(userOut.city) != s_city || checkUndify(userOut.district) != s_county || userOut.signature != signature || userOut.age != age)) {
			$('.zindeximg').hide();
		} else {
			$('.zindeximg').show();
		}
	}, 100);
	$("#s_city").empty();
	$("#s_county").empty();
	//初始化省
	for(var i = 0; i < dsy.Items[guoarrindex].length; i++) {
		$("#s_city").append("<dd> <span class=\"currency_type\">" + dsy.Items[guoarrindex][i] + "</span> </dd>");
	}
	//初始化国家
	for(var i = 0; i < dsy.Items[shengarrindex].length; i++) {
		$("#s_county").append("<dd> <span class=\"currency_type\">" + dsy.Items[guoarrindex][i] + "</span> </dd>");
	}
	var levelexp = userOut.levelexp;
	var experience = userOut.experience;
	var experienceNeed = parseInt(levelexp) - parseInt(experience);
	var level = userOut.level;
	if(userOut.level > 9) {
		var levelstr = userOut.level + "";
		$(".upgradebar span.nowlevel b:first").html("<img src=\"../images/LVimg/" + levelstr.substring(0, 1) + ".png\"/>");
		$(".upgradebar span.nowlevel b:last").html("<img src=\"../images/LVimg/" + levelstr.substring(1, 2) + ".png\"/>");
	} else {
		$('#lvdengji1').html("<img src=\"../images/LVimg/" + userOut.level + ".png\"/>");
		$(".upgradebar span.nowlevel").html("<img src=\"../images/LVimg/" + userOut.level + ".png\"/>");
		$(".upgradebar dt span:last").html("<img src=\"../images/LVimg/" + Number(userOut.level + 1) + ".png\"/>");
	}
	if(userOut['lvid'] == lvid && userOut['companyid'] != 0) {
		$("#userprofessionedit,#companyedit").attr('readonly', true);
	}
	var updateUrl = "http://www.naycent.com/user/validateuser.action";
	var updateLinkUrl = "http://www.naycent.com/security/to-security.action?type=";
	var phoneUrl = updateUrl+"?lvid=" + lvid + "&sign=" + sign + "&src="+updateLinkUrl+"4";
	var emailUrl = updateUrl+"?lvid=" + lvid + "&sign=" + sign + "&src="+updateLinkUrl+"3";
	if(userOut.phone == '') {
		$("#userphoneedit").html("<span>-</span><a class='numUpdataText' href='#' onclick=\"openTheWindow('" + phoneUrl + "')\" >修改</a>");
	} else {
		$("#userphoneedit").html("<span>" + userOut.phone + "</span><a class='numUpdataText' href='#' onclick=\"openTheWindow('" + phoneUrl + "')\" >修改</a>");
	}
	if(userOut.email == '') {
		$("#useremailedit").html("<span>-</span><a class='mailUpdataText' href='#') onclick=\"openTheWindow('" + emailUrl + "')\">修改</a>");
	} else {
		$("#useremailedit").html("<span>" + userOut.email + "</span><a class='mailUpdataText' href='#') onclick=\"openTheWindow('" + emailUrl + "')\">修改</a>");
	}
	$("#userprofessionedit").val(userOut.profession == "" ? '' : userOut.profession);
	$("#userAddress").val(province + " " + city + " " + district);
	//初始化年月日
	TUpdateCal(userOut.birthyear, userOut.birthmonth);
	s_countries = checkUndify(userOut.province);
	s_city = checkUndify(userOut.city);
	s_county = checkUndify(userOut.district);
	$("#countrieA").html(checkUndify(userOut.province));
	$("#proviceA").html(checkUndify(userOut.city));
	$("#cityA").html(checkUndify(userOut.district));
	$("#pAddress").html(checkUndify(userOut.province) + " " + checkUndify(userOut.city) + " " + checkUndify(userOut.district));
	viewAddressSel(userOut.province, userOut.city);
}
function printData (){
	$("#lvid").html(userOut.lvid);
	$("#nickName").html(userOut.nickname);
	$("#usersex").html(userOut.sex == 0 ? "男" : "女");
	userOut.sex == 0 ? $('.sex dd').eq(0).click() : $('.sex dd').eq(1).click();
	$("#userage").html(userOut.age + '岁'); //年龄 
	$("#userday").html(userOut.birthyear + "年" + userOut.birthmonth + "月" + userOut.birthday + "日"); //生日
	$("#usercompany").text(userOut.company).css('cursor', 'default').attr('title', userOut.company);
	userName = userOut.nickname.replaceAll('<', '&lt').replaceAll('>', '&gt').replaceAll(' ', '&nbsp;');
	$("#usernick").html(userName + "(" + userOut.lvid + ")").css('cursor', 'default').attr('title', userOut.nickname);
	province = userOut['province'] ? userOut['province'] : "";
	city = userOut['city'] ? userOut['city'] : "";
	district = userOut['district'] ? userOut['district'] : "";
	$("#userprovince").html(province + " " + city + " " + district);
	$("#userprofession").text(userOut.profession == "" ? '-' : userOut.profession);
	$("#company").html(!userOut.company ? '-' : userOut.company);
	$("#useremail").html(!userOut.email ? '-' : userOut.email);
	$("#userphone").html(!userOut.phone ? '-' : userOut.phone);
	birthyear = userOut.birthyear;
	birthmonth = userOut.birthmonth;
	birthday = userOut.birthday;
	$("#year").html(birthyear + '年');
	$("#month").html(birthmonth + '月');
	$("#day").html(birthday + '日');
	$("#pBirthday").html(birthyear + "年" + birthmonth + "月" + birthday + "日");
	$("#companyedit").val(userOut.company);
	$("#signature").val(userOut.signature);
	signatureT = userOut.signature;
	$("#nickedit").val(userOut.nickname);
	if(toLvid >= 8000000){
		$('.datPriInfo ul').css('overflow','hidden');
	}
}

function markName() {
	var params = "{command:1010, params: { lvid:" + lvid + ", tolvid:" + toLvid + "}}";
	var result = $.parseJSON(sendCommand(params));
	if(result['errorid'] != 0) {
		return;
	}
	$('#remarkN').text(result['newname'].trim() == '' ? '-' : result['newname']);
	if($('#remarkN').text() == '-') {
		$('.markNamebtn').text('添加备注');
	} else {
		$('.markNamebtn').text('修改备注');
	}
}
//加好友
function addMyFriend() {
	var userStr = $.toJSON(userOut);
	var params = "{command:1001, params:" + userStr + "}";
	var resultS = sendCommand(params);
}

//私聊
function privateChat() {
	var userStr = $.toJSON(userOut);
	var params = "{command:1011, params:" + userStr + "}";
	var resultS = sendCommand(params);
}

//打开一个网页窗口
function openTheWindow(url) {
	var paramStr = "{url:'" + url + "'}";
	var params = "{command:9010, params:" + paramStr + "}";
	sendCommand(params);
}

//点击编辑按钮
function editUser() {
	var params = {
		'lvid': lvid,
		'tolvid': toLvid,
		'sign': sign
	};
	$.getJSON(requestUrlMap['userInfo']['url'], params, searchUserCallBack);
}

function resetbarth(obj) {
	$("#userdayedit").attr("value", $("#year").val() + "年" + $("#month").val() + "月" + $("#day").val() + "日");
	if(obj.id == 'day') {}
}

/**
 * 拉起更换头像对话框
 */
function updateIcon() {
	if(selfHandimg) {
		var params = "{command:9002, params: {headtype:1, lvid:" + lvid + ", groupid:-1}}";
		var resultS = sendCommand(params);
	}
}
//放弃修改
function unUpdateUser() {
	if(closeWindowHook) {
		closeDialogWindow();
	}
	$(".datPriMain").show();
	$(".xiuGai-Main").hide();
	$('.zindeximg').show();
	var data0 = {
		'userinfo': userOut,
		'errorid': 0
	};
	searchUserCallBack(data0);
}
//显示地域选择控件
function viewAddressSel(country, province) {
	var countryIndex = '0',
		provinceIndex = '0_0',
		cityIndex = '0_0_0';
	if(country) {
		for(var i in dsy['Items']['0']) {
			if(dsy['Items']['0'][i] == country) {
				provinceIndex = '0_' + i;
				break;
			}
		}
	}
	if(province) {
		for(var i in dsy['Items'][provinceIndex]) {
			if(dsy['Items'][provinceIndex][i] == province) {
				cityIndex = provinceIndex + '_' + i;
				break;
			}
		}
	}
	//输出国家
	for(var i = 0; i < dsy.Items['0'].length; i++) {
		$("#s_countries").append("<dd> <span txt=" + dsy.Items['0'][i] + " title=" + dsy.Items['0'][i] + " class=\"currency_type\">" + dsy.Items['0'][i] + "</span> </dd>");
	}
	//输出省份
	for(var i = 0; i < dsy.Items[provinceIndex].length; i++) {
		$("#s_provices").append("<dd> <span txt=" + dsy.Items[provinceIndex][i] + " title=" + dsy.Items[provinceIndex][i] + " class=\"currency_type\">" + dsy.Items[provinceIndex][i] + "</span> </dd>");
	}
	//输出城市
	for(var i = 0; i < dsy.Items[cityIndex].length; i++) {
		$("#s_cities").append("<dd> <span class=\"currency_type\" txt=" + dsy.Items[cityIndex][i] + " title=" + dsy.Items[cityIndex][i] + ">" + dsy.Items[cityIndex][i] + "</span> </dd>");
		if($(".cities dd").length <= 3) {
			$('.cities').css('overflow-y', 'hidden');
		} else {
			$('.cities').css('overflow-y', 'scroll');
		}
	}
	//所在地三级联动
	$(".countries").find(".currency_type").click(function() {
		var ty = $(this).attr('txt');
		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		s_countries = ty;
		var guoindex = dsy.Items["0"].indexOf(ty);
		var shengarr = dsy.Items["0_" + guoindex];
		$("#s_provices").empty();
		$("#s_cities").empty();
		shengarr[0] = shengarr[0].length > 5 ? shengarr[0].slice(0, 5) + '...' : shengarr[0];
		var chuCity = dsy.Items["0_" + guoindex + "_0"][0];
		chuCity = chuCity.length > 5 ? chuCity.slice(0, 5) + '...' : chuCity;
		$("#proviceA").html(shengarr[0]);
		$("#cityA").html(chuCity);
		s_city = shengarr[0];
		s_county = dsy.Items["0_" + guoindex + "_0"][0];
		$("#pAddress").html(s_countries + " " + shengarr[0] + " " + s_county);
		for(var i = 0; i < shengarr.length; i++) {
			var shengarrrep = shengarr[i].replace(' ', '');
			//shengarr[i] = shengarr[i].length > 5 ? shengarr[i].slice(0, 5) + '...' : shengarr[i];
			$("#s_provices").append("<dd> <span txt=" + shengarr[i] + " title=" + shengarrrep + " class=\"currency_type\">" + shengarr[i] + "</span> </dd>");
			if($("#s_provices dd").length <= 5) {
				$('#s_provices').css('overflow-y', 'hidden');
			} else {
				$('#s_provices').css('overflow-y', 'scroll');
			}
		}
		var cityarr = dsy.Items["0_" + guoindex + "_" + 0];
		city(cityarr);
		$(".provices").find(".currency_type").click(function() {
			var ty = $(this).attr('txt');
			var op = $(this).closest(".select_box").find(".open_select");
			op.text(ty);
			s_city = ty;
			var shengindex = shengarr.indexOf(ty);
			var cityarr = dsy.Items["0_" + guoindex + "_" + shengindex];
			$("#s_cities").empty();
			$("#cityA").html(cityarr[0]);
			$("#pAddress").html(s_countries + " " + s_city + " " + cityarr[0]);
			s_county = cityarr[0];
			city(cityarr);
		});
	});

	function city(cityarr) {
		for(var i = 0; i < cityarr.length; i++) {
			$("#s_cities").append("<dd> <span class=\"currency_type\" txt=" + cityarr[i] + ">" + cityarr[i] + "</span> </dd>");
			if($(".cities dd").length <= 3) {
				$('.cities').css('overflow-y', 'hidden');
			} else {
				$('.cities').css('overflow-y', 'scroll');
			}
		}
		$(".cities").find(".currency_type").click(function() {
			var ty = $(this).attr('txt');
			var op = $(this).closest(".select_box").find(".open_select");
			op.text(ty);
			s_county = ty;
			$("#pAddress").html(s_countries + " " + s_city + " " + s_county);
		});
	}
	$(".provices").find(".currency_type").click(function() {
		var ty = $(this).attr('txt');
		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		s_city = ty;
		var guoindex = dsy.Items["0"].indexOf(s_countries);
		var shengarr = dsy.Items["0_" + guoindex];
		var shengindex = shengarr.indexOf(ty);
		var cityarr = dsy.Items["0_" + guoindex + "_" + shengindex];
		$("#s_cities").empty();
		$("#cityA").html(cityarr[0]);
		$("#pAddress").html(s_countries + " " + s_city + " " + cityarr[0]);
		s_county = cityarr[0];
		city(cityarr);
		$(".cities").find(".currency_type").click(function() {
			var ty = $(this).attr('txt');
			var op = $(this).closest(".select_box").find(".open_select");
			op.text(ty);
			s_county = ty;
			$("#pAddress").html(s_countries + " " + s_city + " " + s_county);
		});
	});
	$(".cities").find(".currency_type").click(function() {
		var ty = $(this).attr('txt');
		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		s_county = ty;
		$("#pAddress").html(s_countries + " " + s_city + " " + ty);
	});
}
//触发关闭按钮
function modifyUserInfo() {
	if(lvid != toLvid) {
		closeDialogWindow();
		return;
	}
	var FSex = $('#sex').attr('sextype');
	var profession = $("#userprofessionedit").val();
	var company = $("#companyedit").val();
	var FNickName = $("#nickedit").val();
	var signature = $("#signature").val();
	var age = $("#age").text();
	//判断是否修改了数据userOut.province+" "+userOut.city+" "+userOut.district
	if(userOut.sex != FSex || userOut.profession != profession || userOut.company != company || userOut.nickname != FNickName || userOut.birthyear != birthyear || userOut.birthmonth != birthmonth || userOut.birthday != birthday || checkUndify(userOut.province) != s_countries || checkUndify(userOut.city) != s_city || checkUndify(userOut.district) != s_county || userOut.signature != signature || userOut.age != age) {
		var paramStr = "{title:'修改资料',cat:3,content:'您已经对资料进行了修改,是否保存？'}";
		var params = "{command:9006,params:" + paramStr + "}";
		var result = $.parseJSON(sendCommand(params));
		if(result['errorid'] == 1) {
			dataerror();
			return;
		}
		if(result['errorid'] == 2) {
			isclose = true;
			unUpdateUser();
			return;
		}
		var data0 = {
			'userinfo': userOut,
			'errorid': 0
		};
		searchUserCallBack(data0);
		$('.zindeximg').hide();
	}
	$(".datPriMain").show();
	$(".xiuGai-Main").hide();
	$('.zindeximg').show();
	if(closeWindowHook) {
		closeDialogWindow();
	}
}

function closeWindow() {
	closeWindowHook = true;
	try {
		sendCommand('{command:9015, params:{title:"关闭窗口", content:"initStatus: ' + initStatus + ', isClose: ' + isclose + '", iswritefile:1}}');
	} catch(e) {}
	if(!initStatus || isclose) {
		closeDialogWindow();
	} else {
		modifyUserInfo();
	}
}

function dataerror() {
	var day = birsDateTime.getDate();
	var month = birsDateTime.getMonth() + 1;
	var year = birsDateTime.getFullYear();
	var yearText = $('#year').text().match(/\d+/g);
	var monthText = $('#month').text().match(/\d+/g);
	var dayText = $('#day').text().match(/\d+/g);;
	if(yearText == year && monthText > month || yearText == year && monthText == month && dayText > day) {
		var paramStr = "{title:'修改资料',cat:0,content:'日期超过了今天，请重新输入！'}";
		var params = "{command:9006,params:" + paramStr + "}";
		var resultS = sendCommand(params);
	} else {
		updateUser();
	}
}
//回车
document.onkeydown = function(event) {
	//网页内按下回车触发
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode == 27) { // 按 Esc                 //要做的事情         
	}
	if(e && e.keyCode == 113) { // 按 F2                  //要做的事情         
	}
	if(e && e.keyCode == 13) { // enter 键                 //要做的事情      
		if($(".announPopup").is(":hidden") == false) {
			$(".announPopup").hide();
			updateUser();
		}
		if($(".PopupQueding").is(":hidden") == false) {
			$(".PopupQueding").hide();
		}
	}
	if((e.ctrlKey) && (e.keyCode == 65)) {
		e.returnValue = false;
	}
}

$('#priList-li a.inputBox input').focus(function() {
	$(this).parents('a').css('border-color', '#01AAE8');
})
$('#priList-li a.inputBox input').blur(function() {
		$(this).parents('a').css('border-color', '#E8E8E8');
	})
	//关闭对话框
function closeDialogWindow() {
	try {
		sendCommand('{command:9015, params:{title:"关闭窗口", content:"lvid: ' + lvid + '关闭用户资料对话框", iswritefile:1}}');
	} catch(e) {}
	sendCommand("{command:9001, params:{lvid:" + lvid + "}}");
}

$(document).ready(function() {
	var parmes = {
		lvid: lvid,
		sign: sign
	}
	$.ajax({
		type: "get",
		url:requestUrlMap['getUserLevel']['url'],
		data: parmes,
		dataType: 'jsonp',
		success: function(json) {
			var data = json.data;
			$('.upgradebar dt p').css('width', (1 - ((data.needday - data.activityday) / data.currentlevelneedday)) * 100 + '%');
			$('.upgrade span').text(data.activityday);
			$('.upgrade span.data').text(data.todaygrowth + '天');
			$('.upgradebar dd b:first').text(data.needdayforupgrade);
			if(data.needdayforupgrade == data.rateday) {
				$('.upgradebar a.hide').hide();
			}
			$('.upgradebar dd b:last').text(data.rateday);
			if(!data.onlineday) {
				$('.upgradeTask li:first').addClass('error').find('span').text('未完成');
			}
			if(!data.paper) {
				$('.upgradeTask li:nth-child(2)').addClass('error').find('span').text('未完成');
			}
			if(!data.browser) {
				$('.upgradeTask li:last').addClass('error').find('span').text('未完成');
			}
		}
	});
	$('#tabCart li').click(function() {
		if($(this).find('.ziliao-tit').text() == '编辑资料') {
			return;
		}
		$(this).not('.xiuGai-Main li').addClass('tab_on').removeClass('tab_off').siblings().removeClass('tab_on').addClass('tab_off');
		if($('.datPriMain').is(':hidden')) {
			userTab();
		}
		if($('.tabCart li:first').hasClass('tab_off')) {
			$('.datPriInfo').hide();
			$('.gradeInfo').show();
		} else {
			$('.datPriInfo').show();
			$('.gradeInfo').show();
		}
	})
	$(".huiHuaIco").hide();
	$(".addFriendIco").hide();
	var year = (new Date()).getFullYear();
	for(var i = 1970; i <= year; i++) {
		$("#yearitem").append("<dd> <span class=\"currency_type\">" + i + "年</span></dd>");
	}
	$(".year").find(".currency_type").click(function() {
		var ty = $(this).text();
		var ageNum = Number(Thisyear - parseInt(ty));
		$('#age').text(ageNum);

		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		if(ty.length > 4) {
			birthyear = ty.slice(0, 4);
		} else {
			birthyear = ty;
		}
		TUpdateCal(birthyear, birthmonth);
		$("#pBirthday").html(birthyear + "年" + birthmonth + "月" + birthday + "日");
	});
	$(".month").find(".currency_type").click(function() {
		var ty = $(this).text();
		if(ty.length == 3) {
			ty = ty.slice(0, 2);
		} else {
			ty = ty.slice(0, 1)
		}
		var op = $(this).closest(".select_box").find(".open_select");
		op.text(ty);
		birthmonth = ty;
		TUpdateCal(birthyear, ty);
		$('#month').html(birthmonth + '月')
		$("#pBirthday").html(birthyear + "年" + birthmonth + "月" + birthday + "日");
		if(birthmonth == 2 && $('#day').html() > 28) {
			$('#day').html('28');
			$('#pBirthday').html(birthyear + "年" + birthmonth + "月" + 28 + "日");
			birthday = 28;
			return;
		}
	});
	//点击 保存  
	$(".prv-keep").click(function() {
		dataerror();
		$('.zindeximg').show();
	});
	$(".prv-close").click(function() {
		modifyUserInfo();
	});
	loadUserInfo();
});
//点击其它地方隐藏块
$(document).bind("click", function(e) {
	var target = $(e.target);
	/*隐藏生日弹窗*/
	if(target.closest(".birBox").length == 0) {
		$(".pBirPopup").hide();
		$('.birBox a.inputBox').css('border-color', '#E8E8E8');
	}
	//隐藏地址弹窗
	if(target.closest(".paddress").length == 0) {
		$('.dressBox a.inputBox').css('border-color', '#E8E8E8');
		$(".pAddrPopup").hide();
	}
});

function userTab() {
	$('#tabCart li').eq(1).addClass('tab_on').removeClass('tab_off').siblings().removeClass('tab_on').addClass('tab_off');
	$('.datPriMain').show();
	$('.xiuGai-Main').hide();
	$('.datPriInfo').hide();
	$('.gradeInfo').show();
}

$(function() {
	$('#priList-li textarea').blur(function() {
		$(this).css('border', '1px solid #E8E8E8');
	})
	$('#priList-li textarea').focus(function() {
			$(this).css('border', '1px solid #01AAE8');
		})
		//点击 编辑资料
	$(".edit-ziliao").click(function() {
		$(".datPriMain").hide();
		$(".xiuGai-Main").show();
	});
	if(tag == 1) {
		userTab();
	} else if(tag == 2) {
		$(".edit-ziliao").click();
	}
	//生日弹窗
	$("#pBirthday").click(function() {
		if($('.pBirPopup').is(':visible')) {
			$(".pBirPopup").hide();
			$('.birBox a.inputBox').css('border-color', '#E8E8E8');
		} else {
			$(".pBirPopup").show();
			$('.birBox a.inputBox').css('border-color', '#01AAE8');
		}
	});

	$('#priList-li li:even span.type').not(':first,.listmail span').css({
		'width': '59px'
	});
	$('#priList-li li:even').not(':first,.listmail').css({
		'width': '210px'
	});
	$('#priList-li li:last span').css({
		'width': '59px'
	});
	$('#priList-li li:last').css({
		'width': '210px'
	});
	//地址弹窗
	$("#pAddress").click(function() {
		if($('.pAddrPopup').is(':visible')) {
			$(".pAddrPopup").hide();
			$('.dressBox a.inputBox').css('border-color', '#E8E8E8');
		} else {
			$(".pAddrPopup").show();
			$('.dressBox a.inputBox').css('border-color', '#01AAE8');
		}
	});
	//打开或关闭下拉菜单
	$(".open_select").each(function() {
		$(this).click(function(event) {
			event.stopPropagation(); //阻止事件冒泡
			event.cancelBubble = false; //针对ie阻止冒泡
			$(this).parent(".open_select_box").next(".select_list").toggle();
		});
	});
	//离开选择区域后展开的下拉列表关闭
	$(document).click(function(event) {
		var eo = $(event.target);
		if($(".open_select").is(":visible") && eo.attr("class") != "select_list" && !eo.parent(".select_list").length) {
			$(".select_list").hide();
			$('#supergroup').css('border', '1px solid #fff');
			$('.year-open').removeClass('yearact');
			$('.day-open').removeClass('dayact');
			$('.month-open').removeClass('monthact');
			$('.countryBox').removeClass('countriesact');
			$('.provinceBox').removeClass('provicesact');
			$('.cityBox,.UpdataList span').removeClass('citiesact');
			$('.yearBox .open_select_box,.monthBox .open_select_box,.dayBox .open_select_box,.UpdataList .open_select').removeClass('actSelect');
			$('.countryBox .open_select_box,.provinceBox .open_select_box,.cityBox .open_select_box,.UpdataList .open_select').removeClass('actSelect');
			$('.ageList .open_select_box').removeClass('actSelect');
			$('.sexList .open_select_box').removeClass('actSelect');
			$('.ageList .open_select').removeClass('yearact');
			$('.sexList .open_select').removeClass('yearact');
			$('.inputBox').css('border', '1px solid #E8E8E8');

		}
	});
	//分别关闭 年、月、日
	//选择 年select
	$(".year-open").click(function() {
		$(this).addClass('yearact');
		$('.yearBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$('.month-open').removeClass('monthact');
		$('.day-open').removeClass('dayact');
		$('.month').hide();
		$('.day').hide();
	});

	//选择 月select
	$(".month-open").click(function() {
		$(this).addClass('monthact')
		$('.monthBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$('.year-open').removeClass('yearact');
		$('.day-open').removeClass('dayact');
		$('.day').hide();
		$('.year').hide();
	});

	//选择 日select
	$(".day-open").click(function() {
		$(this).addClass('dayact')
		$('.dayBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$('.month-open').removeClass('monthact');
		$('.year-open').removeClass('yearact');
		$('.month').hide();
		$('.year').hide();
	});
	$(".day").on('click', '.currency_type', function() {
			$('.day-open').removeClass('dayact');
			$('.pBirPopup').hide();
			$('.birBox a.inputBox').css('border-color', '#E8E8E8');
		})
		//分别关闭 国家、省份、市
		//选择国家
	$(".countries-open").click(function() {
		$(this).addClass('countriesact')
		$(".provices").hide();
		$(".cities").hide();
		$('.countryBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$(".provices-open").removeClass('provicesact');
		$(".cities-open").removeClass('citiesact');
		$('.birBox a.inputBox').css('border-color', '#E8E8E8');
	});
	//选择省份
	$(".provices-open").click(function() {
		$(this).addClass('provicesact')
		$(".countries").hide();
		$(".cities").hide();
		$('.provinceBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$(".countries-open").removeClass('countriesact');
		$(".cities-open").removeClass('citiesact');
		$('.birBox a.inputBox').css('border-color', '#E8E8E8');
	});
	//选择市
	$(".cities-open").click(function() {
		if($(this).attr('id') == 'supergroup') {
			$('#supergroup').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect');
			$('#supergroup').css({
				'border': '1px solid #ccc',
				'border-radius': '2px'
			});
			return;
		}
		$(this).addClass('citiesact')
		$(".countries").hide();
		$(".provices").hide();
		$('.cityBox .open_select_box').toggleClass('actSelect').parent('.select_box').siblings().find('.open_select_box').removeClass('actSelect')
		$(".countries-open").removeClass('countriesact');
		$(".provices-open").removeClass('provicesact');
		$('.birBox a.inputBox').css('border-color', '#E8E8E8');
	});
	$(".cityBox").on('click', '.currency_type', function() {
		$('.cities-open').removeClass('citiesact');
		$('.pAddrPopup').hide();
		$('.dressBox a.inputBox').css('border-color', '#E8E8E8');
	})
	$("#age").click(function() {
		$(this).addClass('yearact');
		$('.age .open_select_box').addClass('actSelect');
	});
	$("#sex").click(function() {
		$(this).addClass('yearact');
		$('.sex .open_select_box').addClass('actSelect');
	});
	$('.age .open_select').click(function() {
		var ageNum = '';
		for(var i = 0; i < 47; i++) {
			ageNum += '<dd>' + i + '</dd>';
		}
		$('.age .select_list').html(ageNum);
	})
	$(document).on('click', '.age .select_list dd', function() {
		$('#age').text($(this).text());
		$('.select_list').hide();
		$('.age .open_select').removeClass('yearact');
		$('.age .open_select_box').removeClass('actSelect');
	})
	$('.sex .select_list dd').click(function() {
		$('#sex').text($(this).text());
		$('.select_list').hide();
		$('#sex').text() == '女' ? $('#sex').attr('sextype', '1') : $('#sex').attr('sextype', '0');
		$('.sex .open_select').removeClass('yearact');
		$('.sex .open_select_box').removeClass('actSelect');
	})
});