var infor = (function (API, $) {
	var infor = {};

	var empty = '-';

	var zodiacArr = ["-", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"];

	var constellationArr = ["-", "魔羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座"];

	var bloodtypeArr = ["-", "A型", "B型", "AB型", "O型", "其它"];

	var sexArr = ['-', '男', '女'];

	var educationTypeArr = ['','研究生','本科','大专','中学'];//4中学 3专科 2本科 1研究生


	/**
	 * 展示信息
	 * @param FriendRelations
	 */
	infor.render = function (FriendRelations, info) {

		$('.cake').click(function(){
			return false;
		});

		switch (parseInt(FriendRelations)) {
			case 1://自己
				masterView(info);
				break;
			case 2://好友
				guestView(info,true);
				break;
			case 3://陌生人
				guestView(info);
				break;
		}
	};
	/**
	 * 主态页展示,
	 * 需要特殊处理的字段
	 * 家乡、所在地、就读学校、生日(展示公历还是农历，说是PC端有字段)
	 */
	function masterView(info) {
		initMasterInfo(info);
		$('#masterView').show();
		$('#guestView').hide();
		$('#editView').hide();
		//主态查看绑定编辑按钮事件
		$('#editButton').hover(
				function(){ 
							$(this).addClass('allow-hover');
				},
				function(){
							$(this).removeClass('allow-hover');
										});
		$('#editButton').click(function () {
			$('#editWrap').show();
			API.editClick();
			editView(info);
		});
	};

	function initMasterInfo(info) {

		//点击别的地方所有的下拉菜单隐藏
		$('body').click(function(){
			$('#sexList,#hometownSelectBox,#hometownProList,#hometownCityList,#birthdayContainer,#zodiacList,#yearList,#monthList,#dayList,#bloodTypeList,#constellationList,#locationSelectBox,#locationNationList,#locationProList,#locationCityList,#hometownProList,#hometownCityList,#schoolProList,#searchList').hide();
			return false;
		});

		$('#editWork').attr('maxLength',21);
		$('#wrapUl').width(398);
		
		showFetionId(info);
		showBindPhone(info);
		showBindEmail(info);
		showBloodType(info);

		showBloodTypeSelect();

		showSex(info);
		sexSelect();
		showAge(info);
		showZodiac(info);
		zodiacSelect();
		showConstellation(info);
		constellationSelect();

		//前三个为空，把后面三个隐藏，并把html放到前面来
		if((info.Age=='' || info.Age==0) && (info.Sex =='' || info.Sex ==0) && info.Birthday=='' ){
			$('#masterTR').hide();
			$('#masterInfo').html($('#masterTD').html());
		}
		//后面三个为空，删掉
		if((info.Constellation =='' ||info.Constellation ==0) && (info.Zodiac =='' || info.Zodiac ==0) && (info.BloodType =='' || info.BloodType ==0)){
			$('#masterTR').remove();
		}
		//如果这些信息都不存在 显示一条 -
		if((info.Age=='' || info.Age==0) && (info.Sex =='' || info.Sex ==0) && info.Birthday=='' 
			&& (info.Constellation =='' ||info.Constellation ==0) && (info.Zodiac =='' || info.Zodiac ==0) && (info.BloodType =='' || info.BloodType ==0)
			){
			$('#masterInfo').text('-');
			$('#masterTR').remove();
		}


		initLocation(info);
		//所在地选择
		locationSelectXml();

//        //家乡选择
		hometownSelect();

		showTel(info);
		
		//电话只能输入数字
		$('#editTel').attr('maxLength',32);
		$('#editTel').bind('input propertychange', function () {
			var keyword = $.trim($('#editTel').val());
			 var reg=/^\d{0,32}$/;
			 var reg2=/[^\d]+/g;
			var t=reg.test($(this).val());
			if(!t){
			   var str=$(this).val().replace(reg2,'');
			   if(str)
				$(this).val(str)
			   else
				$(this).val('')
			}
		  
		});

		//邮箱，139邮箱置灰  editEmail
		
		showEmail(info);

		MyShowTongchuangInfo(info.Userid,API.getFriendRelations());

	}
	//截取指定字数字符串，多出来的加‘...’
	function cutString(str,length){
		var len = length || 3;
		if(str.length>len){
			return str.substring(0,len)+'...';
		}else{
			return str;
		}
	}

	//location 为空的话 初始化为中国，北京北京，并且可以下拉选择，不为空的时候要初始化省份和城市的下拉为可选
	function initLocation(info){
		var loc = info.Location;

		if(loc != ''){
			var locArr = loc.split('.');
			var location = '';
				//  PC给过来的数据在城市为空的时候居然为‘-’，这里做下兼容
			info.Nation = (info.Nation == '-') ? '' : info.Nation;
			info.Province = (info.Province == '-') ? '' : info.Province;
			info.City = (info.City == '-') ? '' : info.City;
			if(info.Nation==info.Province){
				location = info.Nation+' '+info.City;
			}else if(info.City==info.Province){
				location = info.Nation+' '+info.City;
			}else{
				location = info.Nation+' '+info.Province+' '+info.City;
			}

			$('#locationInput').val(location);
			$('#masterLocation').text($.trim(location)||empty);

			$('#locationNationContainer').text(cutString(info.Nation));
			$('#locationNationContainer').attr('countryCode',locArr[0]);
			$('#locationProContainer').text(cutString(info.Province));
			$('#locationProContainer').attr('proCode',locArr[1]);
			$('#locationCityContainer').text(cutString(info.City));
			$('#locationCityContainer').attr('cityCode',locArr[2]);
			
			//设置省份
			if(locArr[0] != locArr[1] && locArr[1] !='' ){
				locationProvince(locArr[0]);
			}

			//设置城市
			if(locArr[2] !=''){
				locationCity(locArr[1]);
			}

		}else{
			$('#locationInput').val(empty);
			$('#masterLocation').text(empty);

			//选择框默认为中国，北京 北京

			$('#locationNationContainer').text('中国');
			$('#locationNationContainer').attr('countryCode','CN');
			$('#locationProContainer').text('北京');
			$('#locationProContainer').attr('proCode','bj');
			$('#locationCityContainer').text('北京');
			$('#locationCityContainer').attr('cityCode',10);
			locationProvince('CN');
			locationCity('bj');
		}
	}

	function locationProvince(countryCode){
		var countryName = $('#locationNationContainer').text();
		$.get("js/WorldContryInfo.xml", function (xml) {
			var proHtml = '';
			$("Country[Code='"+countryCode+"'] Province",xml).each(function(){
				proHtml += '<li><a  class="proItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
			});
			$('#locationProList').html(proHtml);
			//点击省之后 ： 1设置编辑框 2：设置当前省的容器，设置省的code，3：选出当前省的城市
			$('.proItem').click(function(){
				$('#locationProContainer').attr('proCode', $(this).attr('Code'));
				$('#locationProContainer').text(cutString($(this).text()));
				$('#locationProList').hide();
				var proCode = $(this).attr('Code')||'';
				var provinceName = $("Country[Code='"+countryCode+"'] Province[Code='"+proCode +"']",xml).attr('Name');
				$('#locationInput').val(countryName+' '+provinceName);
				//设置第一个城市
				$('#locationCityContainer').attr('cityCode', $("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City:first",xml).attr('Code'));
				$('#locationCityContainer').text(cutString($("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City:first",xml).attr('Name')));
				//设置编辑框
				 $('#locationInput').val(countryName + ' ' +provinceName+' '+$('#locationCityContainer').text());
				var cityHtml = '';
				$("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City",xml).each(function(){
					cityHtml += '<li><a  class="cityItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
				});
				$('#locationCityList').html(cityHtml);
				$('.cityItem').click(function(){
					var cityname = $("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City[Code='"+$(this).attr('Code')+"']",xml).attr('Name');
					$('#locationInput').val(countryName+' '+provinceName +' '+ cityname);
					$('#locationCityContainer').attr('cityCode', $(this).attr('Code'));
					$('#locationCityContainer').text(cutString$(this).text());
					$('#locationCityList').hide();
					return false;
				});
				return false;
			});
				
		});

	}
	//设置location 编辑框 设置城市code text
	function locationCity(provinceCode){
		var proCode = provinceCode;
		$.get("js/WorldContryInfo.xml", function (xml) {
			var cityHtml = '';
			$("Province[Code='"+proCode+"'] City",xml).each(function(){
				cityHtml += '<li><a  class="cityItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
			});
			$('#locationCityList').html(cityHtml);
			$('.cityItem').click(function(){
				var cityname = $("Province[Code='"+proCode+"'] City[Code='"+$(this).attr('Code')+"']",xml).attr('Name');
				$('#locationInput').val($('#locationNationContainer').text()+' '+$('#locationProContainer').text() +' '+ cityname);
				$('#locationCityContainer').attr('cityCode', $(this).attr('Code'));
				$('#locationCityContainer').text(cutString($(this).text()));
				$('#locationCityList').hide();
				return false;
			});
		});
	}

	function showFetionId(info){
		$('#masterFetionId').text(info.FetionId || empty);
		$('#editFetionId').text(info.FetionId);
	}

	function locationSelectXml(){
		locationSelect();
		$.get("js/WorldContryInfo.xml", function (xml) {

			var countryHtml = '';
			$('Country',xml).each(function(){
				countryHtml += '<li><a  class="countryItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
			});
			$('#locationNationList').html(countryHtml);
			$('.countryItem').click(function () {
				var countryCode = $(this).attr('code');
				$('#locationNationContainer').attr('countryCode', countryCode);
				$('#locationProContainer').attr('proCode', '');
				$('#locationCityContainer').attr('cityCode','');
				$('#locationNationContainer').text(cutString($(this).text()));
				$('#locationNationList').hide();
				var countryName = $("Country[Code='"+countryCode+"']",xml).attr('Name');
				$('#locationInput').val(countryName);
				//把省和市置空
					$('#locationProList').html('');
					$('#locationCityList').html('');
					$('#locationProContainer').html('');
					$('#locationCityContainer').html('');


				//如果没有省，直接跳过这里，显示市  国家和省的码一致
				if($("Country[Code='"+countryCode+"'] Province",xml).length==0){//没有省且没有城市
					
				}else if($("Country[Code='"+countryCode+"'] Province",xml).length==1){//没有省但是有城市
					
					//这种情况，省和国家的Code是一样的
					// $('#locationProContainer').attr('proCode', $(this).attr('countryCode'));
					//渲染城市
					var cityHtml = '' ;
					//设置第一个城市
					$('#locationCityContainer').attr('cityCode', $("Country[Code='"+countryCode+"'] Province City:first",xml).attr('Code'));
					$('#locationCityContainer').text(cutString($("Country[Code='"+countryCode+"'] Province City:first",xml).attr('Name')));
					//设置编辑框
					$('#locationInput').val(countryName + ' ' +$("Country[Code='"+countryCode+"'] Province City:first",xml).attr('Name') );
					$("Country[Code='"+countryCode+"'] Province City",xml).each(function(){
						cityHtml += '<li><a  class="cityItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
					});
					$('#locationCityList').html(cityHtml);
					$('.cityItem').click(function(){
						var cityName = $("Country[Code='"+countryCode+"'] Province City[Code='"+ $(this).attr('Code')+"']",xml).attr('Name');
						$('#locationInput').val(countryName+' '+cityName);
						$('#locationCityContainer').attr('cityCode', $(this).attr('Code'));
						$('#locationCityContainer').text(cutString($(this).text()));
						$('#locationCityList').hide();
						return false;
					});
				}else{//有省有城市
					var proHtml = '';
					$("Country[Code='"+countryCode+"'] Province",xml).each(function(){
						proHtml += '<li><a  class="proItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
					});
					$('#locationProList').html(proHtml);
					//先设置第一个省
					$('#locationProContainer').attr('proCode',$("Country[Code='"+countryCode+"'] Province:first",xml).attr('Code'));
					$('#locationProContainer').text(cutString($("Country[Code='"+countryCode+"'] Province:first",xml).attr('Name')));
					//设置编辑框
					$('#locationInput').val(countryName + ' ' +$("Country[Code='"+countryCode+"'] Province:first",xml).attr('Name'));
					$('.proItem').click(function(){
						$('#locationProContainer').attr('proCode', $(this).attr('Code'));
						$('#locationProContainer').text(cutString($(this).text()));
						$('#locationProList').hide();
						var proCode = $(this).attr('Code')||'';
						var provinceName = $("Country[Code='"+countryCode+"'] Province[Code='"+proCode +"']",xml).attr('Name');
						$('#locationInput').val(countryName+' '+provinceName);
						//设置第一个城市
						$('#locationCityContainer').attr('cityCode', $("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City:first",xml).attr('Code'));
						$('#locationCityContainer').text(cutString($("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City:first",xml).attr('Name')));
						//设置编辑框
						 $('#locationInput').val(countryName + ' ' +provinceName+' '+$("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City:first",xml).attr('Name'));
						var cityHtml = '';
						$("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City",xml).each(function(){
							cityHtml += '<li><a  class="cityItem" code="' +$(this).attr('Code')+ '" href="javascript:;">' +cutString($(this).attr('Name')) + '</a></li>';
						});
						$('#locationCityList').html(cityHtml);
						$('.cityItem').click(function(){
							var cityname = $("Country[Code='"+countryCode+"'] Province[Code='"+proCode+"'] City[Code='"+$(this).attr('Code')+"']",xml).attr('Name');
							$('#locationInput').val(countryName+' '+provinceName +' '+ cityname);
							$('#locationCityContainer').attr('cityCode', $(this).attr('Code'));
							$('#locationCityContainer').text(cutString($(this).text()));
							$('#locationCityList').hide();
							return false;
						});
						return false;
					});
				}
				return false;
			});
		
		},'xml');
	}    

	function showTel(info) {
		var tel = info.Tel || empty;
		$('#masterTel').text(tel);
		$('#editTel').val(info.Tel || '');
	}

	function showEmail(info) {
		var email = info.Email || empty;
		$('#masterEmail').text(email.substr(0,30));
		$('#editEmail').val((info.Email).substr(0,30) || '');
		if(email.search('@139.com') !=-1){
			$('#editEmail').addClass('gray').attr('disabled','disabled');
		}
		$('#editEmail').attr('maxLength',30);
	}

	function showAge(info) {
		var birth = info.Birthday || empty;
		if (birth == empty) {
			$('#masterBirthday').text(birth);
			var age = info.Age == '' ? '':info.Age + '岁';
			$('#masterAge').text(age || $('#masterAge').remove());
			$('#editAge').text('');
			$('.cake').text(birth);
			$('#masterZodiac').text('');
			$('#masterConstellation').text('');
			$('#masterBirthday').remove();
			$('#masterCake').remove();
		} else {
			var birthArr = info.Birthday.split('-');
			var age ;
			//如果生日不为空年龄为空，
			if(info.Age == ''){
				$('#masterAge').remove();
			}else{
				age = info.Age;
				$('#masterAge').text(age + '岁');
				$('#editAge').text(age);
			}
			$.setCurrentYear(birthArr[0]);
			$.setCurrentMonth(birthArr[1]);
			$.setCurrentDay(birthArr[2]);
			
			//生日
			if (info.BirthLunar=='1') {
				var lunar = CalendarConvert.GetLunarDay(birthArr[0], birthArr[1], birthArr[2]);
				var birthday = lunar[2].name + lunar[3].name + '（农历生日）';
				$('#masterBirthday').text(birthday);
			} else {
				$('#masterBirthday').text(birthArr[1] + '月' + birthArr[2] + '日（公历生日）');
			}
		}
	}

	function showBindPhone(info) {
		var phone ;
		//IsCM==2  邮箱注册用户
		if(info.IsCM==2 && info.BindPhone == ''){//未绑定
			phone = '<p class="fl phone" regid="411934" style=""></p><a href="javascript:;" class="btn_edit p" title="绑定手机号" regid="411933" onClick="API.bindPhone();">绑定</a>';
		}else{
			phone = '<p class="fl phone okay" >'+info.BindPhone+'</p>'+'<a href="javascript:;" title="更换手机号" class="btn_edit p okay" onClick="API.bindPhone();" ></a>';
		}
		$('#masterBindPhone').html(phone);
		$('#editBindPhone').html(phone);
	}

	function showBindEmail(info) {
		var email;
		if(info.BindEmail==''){
			email = '<p class="fl mail" regid="411936" style=""></p><a href="javascript:;" class="btn_edit m" title="绑定邮箱账号" regid="411935" onClick="API.bindEmail();">绑定</a>';
		}else{
			email = '<p class="fl mail okay" >'+info.BindEmail+'</p>'+'<a href="javascript:;" title="更换邮箱账号"  class="btn_edit m okay" onClick="API.bindEmail();"></a>';
		}
		$('#masterBindEmail').html(email);
		$('#editBindEmail').html(email);
	}

	function showBloodType(info) {
		$('#masterBloodType').text(bloodtypeArr[info['BloodType']]);
		$('#editBloodType').text(bloodtypeArr[info['BloodType']]);
		$('#editBloodType').attr('value', info.BloodType);
		if(info.BloodType=='' || info.BloodType==0){
			$('#masterBloodType').remove();
		}
	}

	function showSex(info) {
		$('#masterSex').text(sexArr[info.Sex] || '');
		$('#editSex').text(sexArr[info.Sex] || '');
		$('#editSex').attr('value', info.Sex);
		if(info.Sex=='' || info.Sex == 0){
			$('#masterSex').remove();
		}
	}

	function sexSelect() {
		$('#editSexSpan').click(function () {
			hideOtherList('sexList');
			if ('none' == $('#sexList').css('display')) {
				var html = '';
				for (var i in sexArr) {
					if(i==0){//不显示-
						continue;
					}
					html += '<li><a class="sexItem" value="' + i + '" href="javascript:;">' + sexArr[i] + '</a></li>';
				}
				$('#sexList').html(html);
				$('.sexItem').click(function () {
					$('#editSex').attr('value', $(this).attr('value'));
					$('#editSex').text($(this).text());
					$('#sexList').hide();
					return false;
				});
				$('#sexList').show();
			} else {
				$('#sexList').hide();
			}
			$.rollingMatch('#editSex','#sexList','hover');
			return false;
		});
	}


	/**
	 * 主态编辑页面展示
	 * todo 图标链接
	 */
	function editView(info) {
		$('#masterView').hide();
		$('#guestView').hide();
		$('#editView').show();
		
		//取消按钮、保存按钮鼠标移上去的效果
		$('#editView div').first().find('a').hover(
							function(){
								$(this).addClass('allow-hover');
										 },
							function(){
								$(this).removeClass('allow-hover');
							});
		//取消保存
		
		$('#editCancelButton').click(function () {
			//console.log('点击取消');
			//发起消息，监听pc事件
			var flag = $.isModify(info);
			//console.log('点击取消给pc传的flag：：：'+flag);
			if(flag == '1'){
				var json = $.getPCModifyInfo(info);
				json.flag = flag;
				API.editCancel(json,function(status, outTxt, outJson){
				});
			}else{
				var json = $.getPCModifyInfo(info);
				json.flag = flag;
				API.editCancel(json,function(status, outTxt, outJson){
				});
				location.reload();
			}
			
		});
		//保存
		$('#editOkButton').click(function () {
			//PC接口保存
			API.saveContactInfo(getPCModifyInfo(info));
			$.saveTongchuangUserInfo();
		});

		//添加学校
		addSchoolView();
	   
		$("#addSchool").click(function (event) {
			hideOtherList();
			$('#schoolView').show();
			$('#wrapUl').width(796);
			$("#wrapUl").animate({ left: "-398px"}, { duration: 500, easing: "easeOutExpo" });
		}); //sq
		$("#closeSchoolButton").click(function (event) {
			// event.target
			$("#wrapUl").animate({ left: "0" }, { duration: 500, easing: "easeOutExpo" });
			$('#schoolView').hide();
			$('#wrapUl').width(398);
		}); //sq

		$.focus();
	}

	function zodiacSelect() {
		$('#editZodiacSpan').click(function () {
			hideOtherList('zodiacList');
			if ('none' == $('#zodiacList').css('display')) {
				var html = '';
				for (var i in zodiacArr) {
					if(i==0){//不显示-
						continue;
					}
					html += '<li><a class="zodiacItem" value="' + i + '" href="javascript:;">' + zodiacArr[i] + '</a></li>';
				}
				$('#zodiacList').html(html);
				$('.zodiacItem').click(function () {
					$('#editZodiacContainer').attr('value', $(this).attr('value'));
					$('#editZodiacContainer').text($(this).text());
					$('#zodiacList').hide();
					return false;
				});
				$('#zodiacList').show();
			} else {
				$('#zodiacList').hide();
			}
			$.rollingMatch('#editZodiacContainer','#zodiacList','hover');
			return false;
		});

	}

	function showZodiac(info) {
		//生肖
		var Zodiac = info.Zodiac || 0;
		var text = (zodiacArr[Zodiac]=='-')?empty:'属' + zodiacArr[Zodiac];
		$('#masterZodiac').text(text);
		$('#editZodiacContainer').text(Zodiac == 0 ? '' :zodiacArr[Zodiac]);
		$('#editZodiacContainer').attr('value', Zodiac);
		if(info.Zodiac=='' || info.Zodiac == 0){
			$('#masterZodiac').remove();
		}
	}

	function getZodiacValue() {
		return String($('#editZodiacContainer').attr('value'));
	}

	function showConstellation(info) {
		var constellation = info.Constellation || 0;
		$('#masterConstellation').text(constellationArr[constellation]);
		$('#editConstellationContainer').text(constellation == 0 ? '' :constellationArr[constellation]);
		$('#editConstellationContainer').attr('value', constellation);
		if(info.Constellation=='' || info.Constellation == 0){
			$('#masterConstellation').remove();
		}
	}

	function getConstellationValue() {
		return String($('#editConstellationContainer').attr('value'));
	}

	function constellationSelect() {
		$('#editConstellationSpan').click(function () {
			hideOtherList('constellationList');
			if ('none' == $('#constellationList').css('display')) {
				var html = '';
				for (var i in constellationArr) {
					if(i==0){//不显示-
						continue;
					}
					html += '<li><a class="constellationItem" value="' + i + '" href="javascript:;">' + constellationArr[i] + '</a></li>';
				}
				$('#constellationList').html(html);
				$('.constellationItem').click(function () {
					$('#editConstellationContainer').attr('value', $(this).attr('value'));
					$('#editConstellationContainer').text($(this).text());
					$('#constellationList').hide();
					return false;
				});
				$('#constellationList').show();
			} else {
				$('#constellationList').hide();
			}
			$.rollingMatch('#editConstellationContainer','#constellationList','hover');
			return false;
		});
	}


	function locationSelect() {
		$('.locationPoint').click(function(){
			return false;
		});
		$('#locationInput').click(function () {
			hideOtherList();
			$('#hometownSelectBox').hide();
			if ('none' == $('#locationSelectBox').css('display')) {
				$('#locationSelectBox').show();
			} else {
				$('#locationSelectBox').hide();
			}
			return false;
		});

		//所在地下拉点击收起
		$('#locationNationContainer,#locationNationA').click(function(){
			if ('none' == $('#locationNationList').css('display')) {
				$('#locationNationList').show();
				$('#locationProList').hide();
				$('#locationCityList').hide();
			} else {
				$('#locationNationList').hide();
			}
			$.rollingMatch('#locationNationContainer','#locationNationList','hover');
			return false;
		});

		$('#locationProContainer,#locationProA').click(function () {
			if ('none' == $('#locationProList').css('display')) {
				$('#locationProList').show();
				$('#locationNationList').hide();
				$('#locationCityList').hide();
			} else {
				$('#locationProList').hide();
			}
			$.rollingMatch('#locationProContainer','#locationProList','hover');
			return false;
		});
		$('#locationCityContainer,#locationCityA').click(function () {
			if ('none' == $('#locationCityList').css('display')) {
				$('#locationCityList').show();
				$('#locationProList').hide();
				$('#locationNationList').hide();
			} else {
				$('#locationCityList').hide();
			}
			$.rollingMatch('#locationCityContainer','#locationCityList','hover');
			return false;
		});
	}


	$.getLocationCode = function () {
		var obj = {};
		obj.country = $('#locationNationContainer').attr('countryCode');
		obj.province = $('#locationProContainer').attr('proCode');
		obj.city = $('#locationCityContainer').attr('cityCode');
		return obj;
	}
	/**
	 * 添加学校视图
	 */
	function addSchoolView() {
		schoolProsSelect();

		searchSchool();
	}

	function schoolProsSelect() {
		$('#schoolProSpan').click(function () {
			hideOtherList();
			 $.getJSON(domain+'feedclient/profile/getSchoolProvinceList?callback=?',function(data){
				var schoolProvinces = data;
				if ('none' == $('#schoolProList').css('display')) {
					var html = '';
					for (var i in schoolProvinces) {
						html += '<li><a class="schoolCityItem" value="' + schoolProvinces[i].Code + '" title="'+schoolProvinces[i].Name +'" href="javascript:;">' + schoolProvinces[i].Name.substring(0,9) + '</a></li>';
					}   
					$('#schoolProList').html(html);
					$('#schoolProList').show();

					$('.schoolCityItem').click(function () {
						$('#schoolProContainer').text($(this).text());
						$('#schoolProContainer').attr('value', $(this).attr('value'));
						$('#schoolProList').hide();
						$('#provinceSearch').text($(this).text());
						$('#provinceSearch').attr('areaCode', $(this).attr('value'));
						showSchoolByProvinceCode($(this).attr('value'));
						return false;
					});
					$.rollingMatch('#schoolProContainer', '#schoolProList', 'hover');
				} else {
					$('#schoolProList').hide();
				}
			});
		});
	}

	function showSchoolByProvinceCode(areaCode) {
		$.getJSON(domain + 'feedclient/profile/getSchoolByNameAndProvinceCode?callback=?'
			, {'areaCode': areaCode}
			, function (data) {
				var html = '';
				for (var i in data) {
					html += '<li><a  Code="' + data[i].Code + '" AreaCode="' + data[i].AreaCode + '" class="schoolItem" href="javascript:;">' + data[i].Name + '</a></li>';
				}
				$('#schoolContainer').html(html);
				$('.schoolItem').click(function () {
					selectSchool($(this).attr('Code'), $(this).attr('AreaCode'), $(this).text());
				});
			});
	}

	function selectSchool(SchoolCode, AreaCode, SchoolName) {
		//滑动回编辑页面
		$("#wrapUl").animate({ left: "0" }, { duration: 500, easing: "easeOutExpo" });
		//选中学校之后设置  schoolCode 和areaCode 到学校的input
		$('#searchInput').val(SchoolName);
		$('#addSchool').attr('SchoolCode', SchoolCode);
		$('#addSchool').attr('AreaCode', AreaCode);
		var educationType = $('.educationType.selected').attr('value') || 2;//没有就默认本科
		$('#addSchool').attr('eType', educationType);
		$('#addSchool').val(SchoolName + ' ' + educationTypeArr[educationType]);
	}

	function searchSchool() {
		$('#searchInput').bind('input propertychange', function () {
			var keyword = $.trim($('#searchInput').val());
			if (/^[\u4e00-\u9fa5]+$/.test(keyword))//匹配汉字
			{
				showSchoolByName(keyword, $('#schoolProContainer').attr('value'));
			}
		});
	}

	function showSchoolByName(name,areaCode) {
		$.getJSON(domain + 'feedclient/profile/getSchoolByNameAndProvinceCode?callback=?'
			, {
				'areaCode': areaCode,
				'name': name,
				'pageSize': 10
			}
			, function (data) {
				if (data == null) {
					return false;
				}
				var html = '';
				for (var i in data) {
					html += '<li><a  Code="' + data[i].Code + '" AreaCode="' + data[i].AreaCode + '" class="searchItem" href="javascript:;">' + data[i].Name + '</a></li>';
				}
				$('#searchList').html(html);
				$('#searchList').show();
				$('.searchItem').click(function () {
					$('#searchList').hide();
					selectSchool($(this).attr('Code'), $(this).attr('AreaCode'), $(this).text());
				});
			}
		);
	}

	function showEducationType(info) {
		$('.eductionType').removeClass('selected');
		$(".eductionType[value='" + info.EducationType + "']").addClass('selected');
		$('.eductionType').click(function () {
			$('.eductionType').removeClass('selected');
			$(this).addClass('selected');
		});
	}

	function showPro(pros, pro) {
		var html = '';
		for (var i = 0; i < pros.length; i++) {
			html += '<li><a class="proItem" value="' + pros[i].Id + '" href="javascript:;">' + pros[i].Name + '</a></li>';
		}

		$('#proList').html(html);
		showCity($("li:contains('" + pro + "')").find('a').attr('value'));
		$('.proItem').click(function () {
			$('#proList').hide();
			$('#editPro').text($(this).text());
			$('#editPro').attr('value', $(this).attr('value'));
			showCity($(this).attr('value'));
			return false;
		});

		$('#editProSpan').click(function () {
			if ('none' == $('#proList').css('display')) {
				$('#proList').show();
			} else {
				$('#proList').hide();
			}
		});
		$('#editCitySpan').click(function () {
			if ('none' == $('#cityList').css('display')) {
				$('#cityList').show();
			} else {
				$('#cityList').hide();
			}
		});

	}

	function hometownSelect() {
		$('#hometownInput').click(function () {
			$('#locationSelectBox').hide();
			if ('none' == $('#hometownSelectBox').css('display')) {
				$('#hometownSelectBox').show();
			} else {
				$('#hometownSelectBox').hide();
			}
			return false;
		});

		$('#hometownProSpan').click(function () {
			if ('none' == $('#hometownProList').css('display')) {
				showHometownProvinces();
				$('#hometownProList').show();
				$('#hometownCityList').hide();
			} else {
				$('#hometownProList').hide();
			}
			$.rollingMatch('#hometownProSpan','#hometownProList','hover');
			return false;
		});

		$('#hometownCitySpan').click(function () {
			if ('none' == $('#hometownCityList').css('display')) {
				$('#hometownCityList').show();
				$('#hometownProList').hide();
			} else {
				$('#hometownCityList').hide();
			}
			showHometownCity();
			$.rollingMatch('#hometownCitySpan','#hometownCityList','hover');
			return false;
		});
	}

	function showHometownProvinces() {
		$.getJSON(domain + 'feedclient/profile/getProvinceByNationId?callback=?', function (hometownProvinces) {
			var html = '';
			//getProvinceByNationId
			for (var i in hometownProvinces) {
				html += '<li><a class="hometownProvinceItem" proId="' + hometownProvinces[i].Id + '" href="javascript:;">' + hometownProvinces[i].Name + '</a></li>';
			}
			;
			$('#hometownProList').html(html);

			$('.hometownProvinceItem').click(function () {
				$('#hometownProContainer').text($(this).text());
				$('#hometownProContainer').attr('value', $(this).attr('proId'));
				$('#hometownProList').hide();
				$('#hometownInput').val($(this).text());
				$('#hometownInput').attr('hometownPro',$(this).text());
				showHometownCity();
				return false;
			});
		});
	}

	function showHometownCity() {
		$.getJSON(domain + 'feedclient/profile/getCityByProvinceId?callback=?', {'provinceId': $('#hometownProContainer').attr('value')}, function (result) {
			var html = '';
			for (var i = 0; i < result.length; i++) {
				html += '<li><a class="cityItem" value="' + result[i].Id + '" href="javascript:;">' + result[i].Name + '</a></li>';
			}
			$('#hometownCityList').html(html);
			$('#hometownCityContainer').text(result[0].Name);
			$('#hometownCityContainer').attr('value', result[0].Id);
			$('#hometownInput').val($('#hometownProContainer').text() + ' ' +result[0].Name );
			$('.cityItem').click(function () {
				$('#hometownCityList').hide();
				$('#hometownCityContainer').text($(this).text());
				$('#hometownCityContainer').attr('value', $(this).attr('value'));
				$('#hometownInput').val($('#hometownProContainer').text() + ' ' +$(this).text() );
				$('#hometownInput').attr('hometownCity',$(this).text());
				return false;
			});
		});
	}

	function getHometownCode() {
		var obj = {};
		obj.nationId = 1;
		obj.provinceId = $('#hometownProContainer').attr('value');
		obj.cityId = $('#hometownCityContainer').attr('value');
		return obj;
	}

	function showBloodTypeSelect() {
		$('#editBloodTypeSpan').click(function () {
			hideOtherList('bloodTypeList');
			if ('none' == $('#bloodTypeList').css('display')) {
				var html = '';
				for (var i in bloodtypeArr) {
					if(i==0){//不显示-
						continue;
					}
					html += '<li><a class="bloodTypeItem" value="' + i + '" href="javascript:;">' + bloodtypeArr[i] + '</a></li>';
				}
				$('#bloodTypeList').html(html);
				$('.bloodTypeItem').click(function () {
					$('#editBloodType').text($(this).text());
					$('#editBloodType').attr('value', $(this).attr('value'));
					$('#bloodTypeList').hide();
					return false;
				});
				$('#bloodTypeList').show();
			} else {
				$('#bloodTypeList').hide();
			}
			$.rollingMatch('#editBloodType','#bloodTypeList','hover');

			return false;
		});


	}


	/**
	 * 客态页展示
	 */
	function guestView(info,isFriend) {
		initGuestinfo(info,isFriend);

		$('#masterView').hide();
		$('#guestView').show();
		$('#editView').hide();
		$('#guestRemarksName').show();
		$('#guestEditRemarksNameSpan').hide();
		if(parseInt(API.getFriendRelations())==3){
			$('#guestRemarksName').css('cursor','default');
		}
		//绑定好友备注
		$('#guestRemarksName').click(function () {
			if(parseInt(API.getFriendRelations())==3){
				return false;
			}
			$('#guestRemarksName').hide();
			$('#guestEditRemarksNameSpan').show();
			$('#guestEditRemarksNameInput').focus();
			//回车 修改备注 
			$('#guestEditRemarksNameInput').keydown(function(e){
				if(e.keyCode==13){
					API.modifyRemarksName({'name':$(this).val()});
					var name = $(this).val();
					if(name == ''){
						name = empty;
					}
					$('#guestRemarksName').text(name);
					$('#guestEditRemarksNameSpan').hide();
					$('#guestRemarksName').show();
				}
			});
			//失去焦点，修改备注 

			$('#guestEditRemarksNameInput').blur(function(){
				API.modifyRemarksName({'name':$(this).val()});
				var name = $(this).val();
				if(name == ''){
					name = empty;
				}
				$('#guestRemarksName').text(name);
				$('#guestEditRemarksNameSpan').hide();
				$('#guestRemarksName').show();

			});
		});
		$('#guestEditRemarksNameInput').attr('maxLength',20);
		//前三个为空，把后面三个隐藏，并把html放到前面来
		if((info.Age=='' || info.Age==0) && (info.Sex =='' || info.Sex ==0) && info.Birthday=='' ){
			$('#guestTR').hide();
			$('#guestInfo').html($('#guestTD').html());
		}
		//后面三个为空，删掉
		if((info.Constellation =='' ||info.Constellation ==0) && (info.Zodiac =='' || info.Zodiac ==0) && (info.BloodType =='' || info.BloodType ==0)){
			$('#guestTR').remove();
		}

		//如果这些信息都不存在 显示一条 -
		if((info.Age=='' || info.Age==0) && (info.Sex =='' || info.Sex ==0) && info.Birthday=='' 
			&& (info.Constellation =='' ||info.Constellation ==0) && (info.Zodiac =='' || info.Zodiac ==0) && (info.BloodType =='' || info.BloodType ==0)
			){
			$('#guestInfo').text('-');
			$('#guestTR').remove();
		}

	};
	//初始化客态页信息
	function initGuestinfo(info,isFriend) {
		$('#guestFetionId').text(info.FetionId || empty);
		var phone =info.BindPhone;

		if(info.BindPhone == '' && info.IsCM ==2){
			phone = '未绑定手机';
		}

		if(info.BindPhone == '' && info.IsCM ==1){
			phone = '未公开';
			if (isFriend && info.PhoneFlag == 1) {
				$('#guestBindPhone').parent().append("&nbsp;<a id='applymobileno'>(申请公开手机号)</a>");
				$('#applymobileno').bind("click",function(){
				API.applymobileno(info.Userid);
			});
			}
		}

		
		$('#guestBindPhone').text(phone);
		$('#guestBindEmail').text(info.BindEmail || '未绑定邮箱');
		//备注名
		$('#guestRemarksName').text(info.RemarksName || empty);
		$('#guestEditRemarksNameInput').val(info.RemarksName);
		$('#guestSex').text(sexArr[info.Sex] || empty);
		//年龄、生日
		var birth = info.Birthday || empty;
		if (birth == empty) {
			var age = ((info.Age|| '')=='')? '' : info.Age + '岁';
			$('#guestAge').text(age);
			$('#guestBirthday').text('');
			$('#guestBirthCake').remove();
		} else {
			var birthArr = info.Birthday.split('-');
			var age = ((info.Age|| '') =='')? '' : info.Age + '岁';
			$('#guestAge').text(age);
			//生日
			if (parseInt(info.BirthLunar)==1) {
				var lunar = CalendarConvert.GetLunarDay(birthArr[0], birthArr[1], birthArr[2]);
				var birthday = lunar[2].name + lunar[3].name + '（农历生日）';
				$('#guestBirthday').text(birthday);
			} else {
				$('#guestBirthday').text(birthArr[1] + '月' + birthArr[2] + '日（公历生日）');
			}
		}
		//生肖
		var zodiac = info.Zodiac || 0;
		if (zodiac == 0) {
			$('#guestZodiac').remove();
		} else {
			$('#guestZodiac').text('属' + zodiacArr[zodiac]);
		}
		var constellation = info.Constellation || 0;
		$('#guestConstellation').text(constellationArr[constellation]);
		if(constellation==0){
			$('#guestConstellation').remove();
		}

		var bloodType = info.BloodType || 0;
		$('#guestBloodType').text(bloodtypeArr[bloodType]);
		if(bloodType==0){
			$('#guestBloodType').remove();
		}
		var location;
		if(info.Province == info.City){
			location = info.Nation + ' '+info.Province; 
		}else{
			location = info.Nation + ' '+ info.Province + ' '+ info.City;
		}

		$('#guestLocation').text($.trim(location)||empty);

		$('#guestTel').text(info.Tel || empty);
		$('#guestEmail').text((info.Email).substr(0,30) || empty);
		//备注
		var html = '';
		html += (info.AddrName) ? info.AddrName + '<br>' : '';
		html += (info.OtherPhone) ? info.OtherPhone + '<br>' : '';
		html += (info.CompanyTel) ? info.CompanyTel + '<br>' : '';
		html += (info.szhomeTel) ? info.szhomeTel + '<br>' : '';
		html += (info.OtherEmail) ? info.OtherEmail + '<br>' : '';
		html += (info.Address) ? info.Address + '<br>' : '';
		html = ('' == html) ? empty : html;
		$('#remarkInfo').html(html);
		MyShowTongchuangInfo(info.Userid,2);
	}

	//focus效果

	$.focus = function () {
		$('span').mouseenter(function () {
			$(this).addClass('on');
		});
		$('span').mouseleave(function () {
			$(this).removeClass('on');
		});
	}

	function getSexValue() {
		return String($('#editSex').attr('value'));
	}

	function getTongchuangModifyInfo() {
		var data ={};
		if(!$.TongchuangInfo){
			return data;
		}
		data.c = API.getLoginCertificate();
		if($('#hometownInput').val() != ''){
			var homePro = $('#hometownProContainer').text()||'';
			if(($.TongchuangInfo.homePro != homePro)){
				data.homePro = homePro;
			}

			var homeCity = $('#hometownCityContainer').text()||'';

			if(homeCity != $.TongchuangInfo.homeCity){
				data.homeCity = homeCity;
				//只要修改城市，省份也要传
				data.homePro = homePro;
			}
		}
		
		var company = $.trim($('#editWork').val());
		if(company != $.TongchuangInfo.work ){

			if (''==company && $.TongchuangInfo.work != empty) {
				company = empty;
			};
			data.company = company;
		}

		var workIndex = $('#editWork').attr('workId');
		if(workIndex){
			data.workIndex = workIndex;
		}

		//这些属性选择学校之后才会有，不选不会有
		var schoolCode = $('#addSchool').attr('schoolCode');
		var areaCode = $('#addSchool').attr('areaCode');
		var eType = $('#addSchool').attr('eType');//这里不选要为默认的学历

		var schoolId = $('#addSchool').attr('schoolId');//之前学校的schoolid
		if(schoolCode != $.TongchuangInfo.schoolCode || areaCode != $.TongchuangInfo.areaCode|| eType != $.TongchuangInfo.educationType){
			data.schoolCode = schoolCode;
			data.areaCode = areaCode;
			data.eType = eType;
			data.schoolId = schoolId;
		}
		return data;
	}

	//获取改动后的信息，pc侧用, 所有给pc传的字段的值都必须是字符串 String(0)

	function getPCModifyInfo(info) {
		var obj = {};
		if (info.Sex != getSexValue()) {
			obj.Sex = getSexValue();
		}
		//只处理大于1900的农历转换
        if(info.Birthday.substring(0,4)>1899){
		        if (info.Birthday != $.getBirth()) {
			        obj.Birthday = $.getBirth();
		        }
        }
		if (info.BirthLunar != String($.getCalendar()) ){
			obj.BirthLunar = String($.getCalendar());
		}

		//生肖  

		if (info.Zodiac != getZodiacValue() && getZodiacValue() != 0) {
			obj.Zodiac = String($('#editZodiacContainer').attr('value'));
		}

		// //星座  

		if (info.Constellation != getConstellationValue() && getConstellationValue() !=0) {
			obj.Constellation = String(getConstellationValue());
		}

		// //血型

		if (info.BloodType != $('#editBloodType').attr('value')) {
			obj.BloodType = String($('#editBloodType').attr('value'));
		}

		//所在地  ??
		var locationArr = info.Location.split('.');
		var countrycode = $('#locationNationContainer').attr('countryCode') ||  '';
		var procode = $('#locationProContainer').attr('proCode') ||  '';
		var citycode = $('#locationCityContainer').attr('cityCode') ||  '';
		var newLocation = '';

		if(countrycode != ''){
			newLocation += countrycode+'.';
		}

		if(procode != ''){
			newLocation += procode +'.';
		}else{
			if(citycode != ''){
				newLocation += countrycode+'.';
			}
		}

		if(citycode != ''){
			newLocation += citycode +'.';
		}
		if (newLocation != info.Location) {
			obj.Location = newLocation;
		}

		//办公电话
		if (info.Tel != $('#editTel').val()) {
			obj.Tel = String($('#editTel').val());
		}

		// //邮件
		if (info.Email != $('#editEmail').val()) {
			obj.Email = String($('#editEmail').val());
		}
		return obj;
	};

// 	function log(obj){
// 		console.log('$$$$$$$$$$$$$$$$$$$$$$$$$');
// 
// 		for (var i in obj) {
// 			console.log(i+'>>>>>>>>'+obj[i]);
// 		};
// 
// 		console.log('$$$$$$$$$$$$$$$$$$$$$$$$$');
// 	}

	$.getPCModifyInfo = getPCModifyInfo;
	$.isModify = isModify;

	$.MyShowTongchuangInfo = MyShowTongchuangInfo;

	//显示同窗客态页信息
	function MyShowTongchuangInfo(userId,FriendRelations){
		$.getJSON(domain+'feedclient/feedclient/profile/getInfo?callback=?',{'userId':userId,'c':API.getLoginCertificate()},function(data){
			$.TongchuangInfo = data;

			switch (parseInt(FriendRelations)) {
				case 1://自己
					showSelfTongchuangInfo(data);
					break;
				case 2://好友
					//console.log('showFriendTongchuangInfo');
					showFriendTongchuangInfo(data);
					break;
				case 3://陌生人
					showFriendTongchuangInfo(data);
					break;
			}
			
		});
	}

	function showFriendTongchuangInfo(data){
		var hometown = '';
		if(data.homePro){
			hometown += (data.homePro=='省份')? '' : data.homePro;

		}
		if(data.homeCity){
			hometown  += ' '+(('城市'==data.homeCity)?'':data.homeCity);
		}
		hometown = ($.trim(hometown)=='') ? empty :hometown;

		$('#guestHometown').text(hometown);

		//guestSchool

		var schoolName = data.schoolName || empty;
		if(schoolName == empty){
			$('#guestSchool').text(empty);
		}else{
			if(educationTypeArr[data.educationType]){
				$('#guestSchool').text(schoolName + ' '+educationTypeArr[data.educationType]);
			}else{
				$('#guestSchool').text(schoolName);
			}
		}
	  
		//work
		var work = (data.work||'').substr(0,42) || empty;
		$('#guestCompany').text(work);

	}

	$.saveTongchuangUserInfo = saveTongchuangUserInfo;

	function saveTongchuangUserInfo(callback){
		if(parseInt(isTongchuangModify())=='0'){
			if(callback){
				callback();
			}
			location.reload();
		}
		var data = getTongchuangModifyInfo();

		$.ajax({  
			type: "GET",  
			async: false,  
			url:domain+'feedclient/feedclient/profile/saveUserInfo?callback=?',
			data:data,  
			dataType: "jsonp",  
			success: function(json){  
				if(callback){
					callback();
				}
				location.reload();
				
			},  
			error: function(){  
				if(callback){
					callback();
				}
				location.reload();
			}  
		});  
	}
	//点击下拉 ，隐藏其余的下拉框
	$.hideOtherList = hideOtherList;
	function hideOtherList(id){
		$('.dropdown:not(#'+id+')').hide();
	}

	function showSelfTongchuangInfo(data){
		infor.userInfo = data.userInfo;
		var hometown = '';
		if(data.homePro){
			hometown += data.homePro;
			$('#hometownProContainer').text(data.homePro);
			//获取当前省份的code，为了获取当前数省份城市
			if(data.homePro != '' && data.homePro != '省份'){
				$.getJSON(domain + 'feedclient/profile/getProvinceByNationId?callback=?', function (hometownProvinces) {
					var proCode = '';
					//getProvinceByNationId
					for (var i in hometownProvinces) {
						if(hometownProvinces[i].Name == data.homePro){
							proCode = hometownProvinces[i].Id;
						}
					}
					if(proCode != ''){
						$('#hometownProContainer').attr('value',proCode);
					}
				});
			}
		}
		if(data.homeCity){
			hometown  += ' '+data.homeCity;
			$('#hometownCityContainer').text(data.homeCity);
		}
		hometown = ($.trim(hometown)=='') || ( hometown.indexOf('省份') !=-1) ? empty :hometown;
		if(hometown.length>1){
			if(hometown.indexOf('省份') !=-1){
				$('#masterHometown').text(empty);
			}else{
				$('#masterHometown').text(data.homePro+' '+data.homeCity);
			}
		}else{
			$('#masterHometown').text(hometown);
		}
		
		$('#hometownInput').val((hometown==empty)?'':hometown);

		var schoolName = data.schoolName || empty;
		schoolName = (schoolName != empty) ? schoolName +' '+((educationTypeArr[data.educationType])? '| '+educationTypeArr[data.educationType]:'' || '') : '';

		$('#addSchool').attr('eType',(data.educationType==0)?2:data.educationType);//为零的话默认为本科
		$('#addSchool').attr('areaCode',data.areaCode);
		$('#addSchool').attr('schoolCode',data.schoolCode);
		$('#addSchool').attr('schoolId',data.schoolId);
		$('#masterSchool').text(schoolName || empty);
		$('#addSchool').val(schoolName);

		//显示学历
		$(".educationType[value='"+data.educationType+"']").addClass('selected');
		//如果没有学历默认为本科
		if(!data.educationType){
			$(".educationType[value='2']").addClass('selected');
		}

		$(".educationType").click(function(){
			$('.educationType').removeClass('selected');
			$(this).addClass('selected');
			$('#addSchool').attr('eType',$(this).attr('value'));

			//更改学校编辑框的学历
			var sn = $('#addSchool').val();
			if(sn!=''){
				var s = '';
				if(sn.indexOf('|') != -1){
					s = sn.substring(0,sn.indexOf('|')+2);
					s += educationTypeArr[$('#addSchool').attr('eType')];
					$('#addSchool').val(s);
				}else{
					//
				}
			}
		});

		//显示学校省份
		$('#schoolProContainer').text(data.schoolProvince || '北京');
		$('#schoolProContainer').attr('value',data.areaCode || '001');
		$('#provinceSearch').text(data.schoolProvince || '北京');
		showSchoolByProvinceCode(data.areaCode ||'001');

		//work

		var work = data.work || empty;

		$('#editWork').val((data.work==empty)?'':data.work);
		$('#masterCompany').text(work);

		if(data.workId){
			$('#editWork').attr('workId',data.workId);
		}

	}

	function isTongchuangModify(){
		var tongchuangModifyInfo = getTongchuangModifyInfo();
		for(var i in tongchuangModifyInfo){

			if(i=='c' || i == 'workIndex' || i == 'schoolId'){
				continue;
			}
			if(tongchuangModifyInfo[i]!=0){
				return '1';
			}
		}
		return '0';
	}


	/**
	 * 判断各字段是否有变动
	 * 
	 */
	function isModify(info) {
		var obj = getPCModifyInfo(info);
		var isFull = false;
		for(var i in obj ){
			if(obj[i]){
				isFull = true;
			}
		}
		if (!isFull && parseInt(isTongchuangModify())==0) {
			return '0';
		} else {
			return '1';
		}
	}

	return infor;
}(API, jQuery));

var loadFlag = false;
function AfterSMCompleted(){
	if (!loadFlag) {
		loadFlag = true;
		var relation = API.getFriendRelations();
		var info = API.getContactInfo();

		infor.render(relation, info);
		$.birthdaySelect(info);
		//监听关闭窗体事件
		API.startlisten(function(status, outTxt, outJson) {
		    var flag = (typeof outJson[0]['flag'] == 'undefined') ? '' : parseInt(outJson[0]['flag']);

			if (1 == flag) {//关闭
				API.closeEdit($.isModify(info), $.getPCModifyInfo(info));
			}
			if (2 == flag) {//用户需要保存信息
				//这里只需要保存同窗的字段就行
				$.saveTongchuangUserInfo(function(){
					API.completeSave();
				});
			}
			//点取消之后的关闭
			if(3==parseInt(flag)){
				location.reload();
			}
			if (flag == 4) 
			{
				var divMain = document.getElementById("divMain");
				divMain.style.backgroundColor = outJson[0]['bgColor'];
        divMain.style.background = (outJson[0].layout&&outJson[0].layout==1)?("url(" + outJson[0].themeSrc + ") repeat top left"):("url(" + outJson[0].themeSrc + ")no-repeat top left");					
				if(outJson[0].posX)
				{
					divMain.style.backgroundPositionX = outJson[0].posX+"px";
				}
				if(outJson[0].posY)
				{								
					divMain.style.backgroundPositionY = outJson[0].posY+"px";
				}			
					
			}

			if (flag == 5) {
				location.reload();
			}
		});
	}

}


//--------------------------------------------------------------

jQuery.easing['jswing'] = jQuery.easing['swing'];

			jQuery.extend(jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c * (t /= d) * t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c * (t /= d) * (t - 2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t + b;
		return -c / 2 * ((--t) * (t - 2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c * (t /= d) * t * t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c * ((t = t / d - 1) * t * t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
		return c / 2 * ((t -= 2) * t * t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c * (t /= d) * t * t * t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
		return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c * (t /= d) * t * t * t * t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
		return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t / d * (Math.PI / 2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t == 0) return b;
		if (t == d) return b + c;
		if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
		return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
		return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
		return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c * (t /= d) * t * ((s + 1) * t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
		return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t /= d) < (1 / 2.75)) {
			return c * (7.5625 * t * t) + b;
		} else if (t < (2 / 2.75)) {
			return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
		} else if (t < (2.5 / 2.75)) {
			return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
		} else {
			return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
	}
});
