function initPersonal(){
	richer.dtp.getData('checkOnline.jsp?'+Math.random(),{
		callback:function(vvv) {
			if(vvv == null || vvv != 'online;'){
				//alert('请重新登陆!');
				window.location = '/login.html';
				return;
			}else{
				//初始化数据
				UserCookie.init();
				var msg = UserCookie.getVisitedInf(0);
				if(msg == null || msg == ''){
					//alert('请重新登陆!');
					window.location = '/login.html';
					return;
				}
				
				Personal.initPersonalTable();
				
				FDBSearchUtil.initDBSearch("searchKeyWord","FDBresultList");//初始化数据搜索
				
				TabContrl.initTab();
				FundProportion.initData();
				
				//登陆欢迎信息
				//alert(msg);
			}
		}
	});
}

var Personal ={
	"initPersonalTable": function(){
		UserID = UserCookie.getVisitedInf(2);
		MyFundCodeArr = new Array();//我持有的基金代码,名
		
		MyFundService.getMyFundDetail(UserID,{
			callback:function(re) {
				var hc = '<li class="bg1"><div class="k1"><h3>基金名称</h3></div><div class="k2">日期</div><div class="k3">净值</div><div class="k4">份额</div><div class="k5">市值</div><div class="k6">投入金额</div><div class="k7">收回金额</div><div class="k8">现金红利</div><div class="k9">当日盈亏</div><div class="k10">当日收益率</div><div class="k11">浮动盈亏</div><div class="k12">收益率</div><div class="k13">操作</div></li>';
				for(var i=0;i<re.length;i++){
					MyFundCodeArr.push(new Array(re[i].fundCode,re[i].fundName));
					hc += Personal.formatHtml(re[i].fundName,re[i].endDate,re[i].unitNV,re[i].share,re[i].value,re[i].investmentSum,re[i].redeemSum,re[i].distributedCash,re[i].dailyProfitAndLoss,re[i].dailyYield,re[i].floatProfitAndLoss,re[i].yield,re[i].fundCode);
				}
				$('MyFundDetailTable').innerHTML = hc;
				
				//清除所有Option
				for(i=$('fundIn').options.length - 1;i>=0;i--){
					$('fundIn').options[i] = null;
				}
				$('fundIn').options.length = 0;
				
				var option_ = document.createElement("option");
				$('fundIn').appendChild(option_);
				option_.text = '请选择需要转换的基金';
				option_.value = -1;
				
				for(var i=0;i<MyFundCodeArr.length;i++){
					var option = document.createElement("option");
					$('fundIn').appendChild(option);
					option.text = MyFundCodeArr[i][1]+'('+MyFundCodeArr[i][0]+')';
					option.value = i;
				}
				
				//清除所有Option
				for(i=$('myselectfund').options.length - 1;i>=0;i--){
					$('myselectfund').options[i] = null;
				}
				$('myselectfund').options.length = 0;
				
				for(var i=0;i<MyFundCodeArr.length;i++){
					var option1 = document.createElement("option");
					$('myselectfund').appendChild(option1);
					option1.text = MyFundCodeArr[i][1]+'('+MyFundCodeArr[i][0]+')';
					option1.value = i;
				}
				
				Personal.sumMyFund();//持仓记录，合计
				Personal.sellRecorde();//交易买卖记录
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
		
		$('fundIn').onchange = function(){
			var fc = MyFundCodeArr[$('fundIn').options[$('fundIn').selectedIndex].value][0];
			var fcomc = 0;
			for(var i=0;i<FDB.length;i++){//通过基金代码匹配基金，找出基金类型
				if(FDB[i][0] == fc){
					fcomc = FDB[i][4]; 
					break;
				}
			}
			
			//清除所有Option
			for(i=$('fundOut').options.length - 1;i>=0;i--){
				$('fundOut').options[i] = null;
			}
			$('fundOut').options.length = 0;
			
			if(fcomc == 0){
				var option = document.createElement("option");
				$('fundOut').appendChild(option);
				option.text = '没有与此基金同公司的其他基金';
				option.value = -1;
			}
			
			for(var i=0;i<FDB.length;i++){
				if(FDB[i][4] == fcomc && FDB[i][0]!= fc){
					var option = document.createElement("option");
					$('fundOut').appendChild(option);
					var ttt = '--';
					if(FDB[i][3] == 1){
						ttt = '股票型';
					}else if(FDB[i][3] == 2){
						ttt = '混合型';
					}else if(FDB[i][3] == 3){
						ttt = '低风险';
					}
					option.text = FDB[i][2]+'('+FDB[i][0]+') ['+ttt+']';
					option.value = FDB[i][0];
				}
			}
		}
	},
	"formatHtml": function(i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,fc){
		return '<li>'
				+'<div class="c1"><h3><a href="fundDetail.html?code='+fc+'">'+i1+'</a></h3></div>'
				+'<div class="c2">'+i2+'</div>'
				+'<div class="c3">'+i3+'</div>'
				+'<div class="c4">'+parseInt(parseFloat(i4)*100)/100+'</div>'
				+'<div class="c5">'+parseInt(parseFloat(i5)*100)/100+'</div>'
				+'<div class="c6">'+parseInt(parseFloat(i6)*100)/100+'</div>'
				+'<div class="c7">'+parseInt(parseFloat(i7)*100)/100+'</div>'
				+'<div class="c8">'+parseInt(parseFloat(i8)*100)/100+'</div>'
				+'<div class="c9">'+parseInt(parseFloat(i9)*100)/100+'</div>'
				+'<div class="c10">'+(parseFloat(i10)*100).toFixed(2)+'%</div>'
				+'<div class="c11">'+parseInt(parseFloat(i11)*100)/100+'</div>'
				+'<div class="c12">'+ (parseInt(parseFloat(i12)*10000))/100+'%</div>'
				+'<div class="c13"><a href="javascript:void(0)" target="_self" onclick=Personal.deleteMyFund("'+fc+'","'+i1+'")>删除</a></div>'
				+'</li>';
	},
	"sumMyFund": function(){
		MyFundService.sumMyFund(UserID,{
			callback:function(re) {
				var arr = re.split('|');
				if(parseFloat(arr[0])<=0){
					for(var k=0;k<re.length;k++){
						if(k!=6 && k!=8){
							arr[k] = 0;
						}
					}
				}
				var hc = '<li class="bg1"><div class="k1"><h3>当前持有总份额</h3></div><div class="k2">当前市值</div><div class="k3">投入总金额</div><div class="k4">已收回总金额</div><div class="k5">现金红利</div><div class="k6">当日总盈亏</div><div class="k7">当日总收益率</div><div class="k8">总浮动盈亏</div><div class="k9">总收益率</div></li>';
				hc += '<li><div class="c1"><h3>';
				hc += parseInt(parseFloat(arr[0])*100)/100;
				hc += '</h3></div><div class="c2">';
				hc += parseInt(parseFloat(arr[1])*100)/100;
				hc += '</div><div class="c3">';
				hc += parseInt(parseFloat(arr[2])*100)/100;
				hc += '</div><div class="c4">';
				hc += parseInt(parseFloat(arr[3])*100)/100;
				hc += '</div><div class="c5">';
				hc += parseInt(parseFloat(arr[4])*100)/100;
				hc += '</div><div class="c6">';
				hc += parseInt(parseFloat(arr[5])*100)/100;
				hc += '</div><div class="c7">';
				hc += parseInt(arr[6]*10000)/100;
				hc += '%</div><div class="c8">';
				hc += parseInt(parseFloat(arr[7])*100)/100;
				hc += '</div><div class="c9">';
				hc += parseInt(arr[8]*10000)/100;
				hc += '%</div></li>';
				$('sumFundDiv').innerHTML = hc;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"sellRecorde": function(){//买卖记录
	//getOperationRecordsGroupByCode
	//getOperationRecords
		MyFundService.getOperationRecordsGroupByCode(UserID,{
			callback:function(re) {
				var hc = '<li class="bg1"><div class="k1"><h3>日期</h3></div><div class="k2">基金名称</div><div class="k3">操作类型</div><div class="k7">生效时间</div><div class="k4">金额</div><div class="k5">份额</div><div class="k6">手续费率</div></li>';
				for(var i=0;i<re.length;i++){
					var arr = re[i].split('|');
					hc += '<li><div class="k1"><h3>';
					hc += arr[0];
					hc += '</h3></div><div class="k2">';
					hc += arr[1];
					hc += '</div><div class="k3">';
					hc += arr[2];
					hc += '</div><div class="k7">';
					hc += arr[6];
					hc += '</div><div class="k4">';
					hc += parseInt(parseFloat(arr[3])*100)/100;
					hc += '</div><div class="k5">';
					hc += parseInt(parseFloat(arr[4])*100)/100;
					hc += '</div><div class="k6">';
					hc += arr[5];
					hc += '</div></li>';
				}
				$('MyFundDetailTable_').innerHTML = hc;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"VolumeProcess": function(){
		var frontOrback = $("fund_p1").checked  ? $("fund_p1").value : $("fund_p1_").value;
		var inOrout = $("fund_p2").checked  ? $("fund_p2").value : $("fund_p2_").value;
		var percentOrNum = $("fund_p3").checked  ? $("fund_p3").value : $("fund_p3_").value;

		var MoneyNum = $('how_much_money1').value;
		if(MoneyNum=='' || MoneyNum<=0){
			alert('金额不正确!');
			//$('how_much_money1').focus();
			return 0;
		}
		
		var rate = $('rate1').value;
		if(rate=='' || rate<0){
			alert('申购费率不正确!');
			//$('rate1').focus();
			return 0;
		}
		
		var unitNV = $("curDateNV1").value;
		if(unitNV=='' || unitNV<=0){
			alert('当时净值不正确!,请选择基金和日期');
			//$('curDateNV1').focus();
			return 0;
		}
		
		if(frontOrback == 1){
			var fee = 0;
			if(percentOrNum == 1){
				fee = MoneyNum*(rate/100);
			}else if(percentOrNum == 2){
				fee = rate;
			}
			if(inOrout == 1){
				$('fundVolume1').value = parseInt(((MoneyNum-fee)/unitNV + 0.005)*100)/100;
			}else if(inOrout == 2){
				$('fundVolume1').value = parseInt(( (MoneyNum/(1+rate/100))/unitNV + 0.005)*100)/100;
				//$('fundVolume1').value = parseInt(( (MoneyNum+fee)/unitNV + 0.005)*100)/100;
			}
		}else if(frontOrback == 2){
			$('fundVolume1').value = parseInt(MoneyNum/unitNV + 0.5);
		}
		return 1;
	},
	"VolumeProcess1": function(){//判断转换份额
		if($('how_much_share1').value == '' || isNaN($('how_much_share1').value)){
			alert('请输入你想转换的份额.');
			//$("how_much_share1").focus();
			return 0;
		}
		var c = parseInt($('how_much_share1').value);
		if(c>parseInt($('curShare').value)){
			alert('你没有这么多份额.');
			//$("how_much_share1").focus();
			return 0;
		}else{
			var m = c*parseFloat($('curUnitValue1').value)*(1-parseFloat($('rate2').value)/100.0);
			$('how_much_money2').value = parseInt(m*100)/100;
			$('how_much_money3').value = $('how_much_money2').value;
			$('how_much_share2').value = parseInt((m/parseFloat($('curUnitValue2').value) + 0.005)*100)/100;
		}
		return 1;
	},
	"VolumeProcess2": function(){//判断份额(赎回)
		if($('how_much_share3').value == '' || isNaN($('how_much_share3').value)){
			alert('请输入你想赎回的份额.');
			//$("how_much_share3").focus();
			return 0;
		}
		var c = parseInt($('how_much_share3').value);
		if(c>parseInt($('curShare1').value)){
			alert('你没有这么多份额.');
			//$("how_much_share3").focus();
			return 0;
		}else{
			$('how_much_money4').value = c*parseFloat($('curUnitValue3').value)*(1-parseFloat($('rate4').value)/100.0);
		}
		return 1;
	},
	"applyMyFund": function(){//申购我的基金
		if(Personal.VolumeProcess() != 1){
			return;
		}
		
		var userName = UserID;
		var applyingMethod = $('fund_p1').value;
		var sum = $('how_much_money1').value;
		var feeType = $('fund_p2').value;
		var share = $('fundVolume1').value;
		var fundCode = $('selFundCode_').value;
		var fundName = $('selFundName1').value;
		var fundType = $('selFundType_').value;//基金类型
		var applyingFeeRatePercent = 1;//申购费率（百分比）
		var applyingFeeRateValue = 0;//申购费率（固定值）
		if($('fund_p3').value == 1){
			applyingFeeRatePercent = $('rate1').value;
		}else{
			applyingFeeRateValue = $('rate1').value;
		}
		var effectiveDate = $("selFundDate1").value;
		var thenUnitNV = $("curDateNV1").value;
		var dividend = $('dividend').value;
		
		/* alert(userName+'\n'+applyingMethod+'\n'+sum+'\n'+feeType+'\n'+share+'\n'+
			fundCode+'\n'+fundName+'\n'+fundType+'\n'+applyingFeeRatePercent+'\n'+applyingFeeRateValue+'\n'+
			effectiveDate+'\n'+thenUnitNV+'\n'+dividend); */
			
		MyFundService.applyMyFund(userName,applyingMethod,sum,feeType,share,
			fundCode,fundName,fundType,applyingFeeRatePercent,applyingFeeRateValue,
			effectiveDate,thenUnitNV,dividend,{
			callback:function(re) {
				if(re == 0){
					alert('数据提交成功!');
					Personal.applyMyFundReset();
					
					Personal.initPersonalTable();
					FundProportion.initData();
					
					TabContrl.showTab(4);
				}else{
					alert('数据提交失败!');
				}
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		})
	},
	"applyMyFundReset": function(){//reset申购我的基金
		$('fundVolume1').value = '';
		$('selFundDate1').value = '';
		$('how_much_money1').value = '';
		$('curDateNV1').value = '';
	},
	"transformMyFund": function(){//转换我持有的基金
		if(Personal.VolumeProcess1() != 1){
			return;
		}
	
		var userName = UserID;
		var outFundCode = MyFundCodeArr[$('fundIn').value][0];
			var ttt = $('fundIn').options[$('fundIn').selectedIndex].text;
		var outFundName = ttt.substr(0,ttt.indexOf('('));
		var effectiveDate = $('selFundDate2').value;
		var outThenUnitNV = $('curUnitValue1').value;
		var outShare = $('how_much_share1').value;
		var outSum = $('how_much_money2').value;
		var outFeeRate = $('rate2').value;
		var outDividend = $('dividend1').value;
		
		var inFundCode = $('fundOut').value;
			var qqq = $('fundOut').options[$('fundOut').selectedIndex].text; 
		var inFundName = qqq.substr(0,qqq.indexOf('('));
			var tttt = qqq.substr(qqq.indexOf('[') + 1,3);
		
		var inFundType = 1; 
		if(tttt == '股票型'){
			inFundType = 1;
		}else if(tttt == '混合型'){
			inFundType = 2;
		}else if(tttt == '低风险'){
			inFundType = 3;
		}
		
		var inThenUnitNV = $('curUnitValue2').value;
		var inShare = $('how_much_share2').value;
		var inSum = $('how_much_money3').value;
		var inFeeRate = $('rate3').value;
		var inDividend = $('dividend2').value;
		
		//alert(userName+'\n'+outFundCode+'\n'+outFundName+'\n'+effectiveDate+'\n'+outThenUnitNV+'\n'+outShare+'\n'+outSum+'\n'+outFeeRate+'\n'+outDividend+'\n'+inFundCode+'\n'+inFundName+'\n'+inFundType+'\n'+inThenUnitNV+'\n'+inShare+'\n'+inSum+'\n'+inFeeRate+'\n'+inDividend);
		
		MyFundService.transformMyFund(userName,outFundCode,outFundName,effectiveDate,outThenUnitNV,outShare,outSum,outFeeRate,outDividend,
			inFundCode,inFundName,inFundType,inThenUnitNV,inShare,inSum,inFeeRate,inDividend,{
			callback:function(re) {
				if(re == 0){
					alert('数据转换提交成功!');
					
					Personal.transformMyFundReset();
					
					Personal.initPersonalTable();
					FundProportion.initData();
					
					TabContrl.showTab(4);
				}else{
					alert('数据转换提交失败!');
				}
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"transformMyFundReset": function(){
		$('selFundDate2').value = '';
		$('curUnitValue1').value = '';
		$('how_much_share1').value = '';
		$('how_much_money2').value = '';
		$('curUnitValue2').value = '';
		$('how_much_share2').value = '';
		$('how_much_money3').value = '';
	},
	"redeemMyFund": function(){//赎回
		if(Personal.VolumeProcess2() != 1){
			return;
		}
		
		var userName = UserID;
		var fundCode = MyFundCodeArr[$('myselectfund').value][0];
			var ttt = $('myselectfund').options[$('myselectfund').selectedIndex].text;
		var fundName = ttt.substr(0,ttt.indexOf('('));
		var effectiveDate = $('selFundDate3').value;
		var thenUnitNV = $('curUnitValue3').value;
		var redeemShare = $('how_much_share3').value;
		var redeemSum = $('how_much_money4').value;
		var redeemFeeRate = $('rate4').value;
		
		//alert(userName+'\n'+fundCode+'\n'+fundName+'\n'+effectiveDate+'\n'+thenUnitNV+'\n'+redeemShare+'\n'+redeemSum+'\n'+redeemFeeRate);
		
		MyFundService.redeemMyFund(userName,fundCode,fundName,effectiveDate,
			thenUnitNV,redeemShare,redeemSum,redeemFeeRate,{
			callback:function(re) {
				if(re == 0){
					alert('数据赎回提交成功!');
					Personal.redeemMyFundReset();
					
					Personal.initPersonalTable();
					FundProportion.initData();
					
					TabContrl.showTab(4);
				}else{
					alert('数据赎回提交失败!');
				}
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"redeemMyFundReset": function(){
		$('selFundDate3').value = '';
		$('curUnitValue3').value = '';
		$('how_much_share3').value = '';
		$('how_much_money4').value = '';
	},
	"deleteMyFund": function(fundCode,fundName){//删除
		var userName = UserID;
		
		MyFundService.deleteMyFund(userName,fundCode,fundName,{
			callback:function(re) {
				if(re == 0){
					alert('成功删除数据!');
					
					Personal.initPersonalTable();
					FundProportion.initData();
					
					TabContrl.showTab(4);
				}else{
					alert('数据删除失败!');
				}
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	}
}

//数据处理函数集
var FDBSearchUtil = {
	"initDBSearch": function(keyWord,result){//初始化数据
		FDB = new Array();//基金数据
		selArr = new Array();//已经选择的数据集,存储FDB索引		
		cmpArr = new Array(8);//对比数据代码
		SearchKeyWords = keyWord;
		SearchResultDIV = result;
		SelectFundIndex = 0;//FDB中的索引
		
		currentElement = null;
		
		//当前在selArr中选中的索引
		SelectIndex = 0;
		MaxListSize = 12;
		
		richer.dtp.getData('http://quotes.fund.163.com//static/data/fund.dat',{
			callback:function(vvv) {
				var re = vvv.split('|');
				for(var i=0;i<re.length - 1;i++){
					var lll = re[i].split(";");
					if(lll[5] != 7){
						FDB.push(lll);
					}
				}
			}
		}); 
		
		//size="13" onChange="FDBSearchUtil.submitData('fund',this.value)"
		var ske = $(keyWord);
		var sdiv = $(result);
		var Sel = $(result+"_select");
		
		ske.value=ske.title;
		
		sdiv.style.display="none";
		Sel.size = MaxListSize;
		
		Sel.onchange = function(){
			if(currentElement == null){
				var cd = new Date();
				FDBSearchUtil.initDefaultDate();
				SelectFundIndex = Sel.options[Sel.selectedIndex].value;
				FDBSearchUtil.submitData(null);
			}
		}
		
		ske.onfocus = function() {
			currentElement = ske;
			
			if (ske.value == ske.title) {
				ske.value = "";
			}
			
			SelectIndex = 0;
			FDBSearchUtil.getSelectArr(ske.value);
		}
		
		ske.onblur = function() {
			currentElement = null;
			
			if (ske.value == "") {
				ske.value = ske.title;
			}

			//sdiv.style.display="none";
		}
		
		ske.onkeyup = function(aEvent) {
		    var myEvent = window.event ? window.event : aEvent;
		    switch (myEvent.keyCode) {
				case 13://回车
					FDBSearchUtil.initDefaultDate();
					SelectFundIndex = selArr[SelectIndex];
					FDBSearchUtil.submitData();
			        break;
			    case 33://pgUP
			    	SelectIndex-=MaxListSize;
			    	FDBSearchUtil.selectOne();
			    	break;
			    case 34://pgDN
			    	SelectIndex+=MaxListSize;
			    	FDBSearchUtil.selectOne();
			    	break;
				case 16://shift
			    	break;
		        case 17://Ctrl
			        break;
			    case 38://向上
			    	--SelectIndex;
			    	FDBSearchUtil.selectOne();
					break;
			    case 40://向下
				    ++SelectIndex;
			    	FDBSearchUtil.selectOne();
					break;
				default:
					SelectIndex = 0;
					FDBSearchUtil.getSelectArr(ske.value);
			}
		}
	},
	"getSelectArr": function(keyWord){//index  0:代码，1：拼音，2：名称
		//判断匹配类型
		if(/^\d{1,6}$/.test(keyWord)){
			index = 0;
		}else if(/^[a-zA-Z]+(\d)*([a-zA-Z])*$/.test(keyWord)){
			index = 1;
		}else{
			index = 2;
		}
		
		//清除所有Option
		for(i=$(SearchResultDIV+"_select").options.length - 1;i>=0;i--){
			$(SearchResultDIV+"_select").options[i] = null;
		}
		$(SearchResultDIV+"_select").options.length = 0;
		
		var reg = new RegExp("^("+keyWord+")");	
		selArr = new Array();
		for(var dbi=0;dbi<FDB.length;dbi++){
			if(reg.test(FDB[dbi][index])){
				selArr.push(dbi);
				
				var option = document.createElement("option");
				$(SearchResultDIV+"_select").appendChild(option);
				option.text = FDB[dbi][0]+'  '+ FDB[dbi][2] + '  ' +FDB[dbi][1];
				option.value = dbi;
			}
		}
		
		FDBSearchUtil.selectOne();
		
		if(selArr.length > 0){
			$(SearchResultDIV).style.display="block";
		}else{
			$(SearchResultDIV).style.display="none";
		}
		
		return selArr.length;
	},
	"selectOne": function(){//选择
		//$(SearchResultDIV+"_table").childNodes;
		if (selArr.length == 0) {//搜索的结果不为0
			return;
		}
		
		if(SelectIndex>selArr.length - 1){
			SelectIndex = selArr.length - 1;
		}else if(SelectIndex<0){
			SelectIndex = 0;
		}

		//$(SearchResultDIV+"_select").options[SelectIndex].selected = true;
		$(SearchResultDIV+"_select").selectedIndex = SelectIndex;
		$(SearchResultDIV+"_inf").innerHTML = '↑ ↓ PgUp PgDn   '+(SelectIndex + 1)+'/'+selArr.length+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" target="_self" onClick="$(SearchResultDIV).style.display=\'none\'"><img src="fundimg/fund06.gif" width="13" height="13" /></a>';
	},
	"initDefaultDate": function(){
		var cd = new Date();
		$("selFundDate1").value = cd.getFullYear()+'-'+(cd.getMonth() + 1)+'-'+cd.getDate();
	},
	"submitData": function(){
		$('selFundName1').value = FDB[SelectFundIndex][2];
		$('selFundCode_').value = FDB[SelectFundIndex][0];
		$('selFundType_').value = FDB[SelectFundIndex][3];
		MyFundService.getUnitNV(FDB[SelectFundIndex][0],$("selFundDate1").value,{
			callback:function(re) {
				$("curDateNV1").value = re;
				//$("how_much_money1").focus();
				
				$(SearchResultDIV).style.display="none";
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"submitData2": function(){//转入，转出
		MyFundService.getUnitNV(MyFundCodeArr[$('fundIn').options[$('fundIn').selectedIndex].value][0],$("selFundDate2").value,{
			callback:function(re) {
				$("curUnitValue1").value = re;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
		
		MyFundService.getUnitNV($('fundOut').options[$('fundOut').selectedIndex].value,$("selFundDate2").value,{
			callback:function(re) {
				$("curUnitValue2").value = re;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
		
		MyFundService.getShare(UserID,MyFundCodeArr[$('fundIn').options[$('fundIn').selectedIndex].value][0],{
			callback:function(re) {
				$("curShare").value = re;
				$("how_much_share1").focus();
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"submitData3": function(){//赎回
		MyFundService.getUnitNV(MyFundCodeArr[$('myselectfund').options[$('myselectfund').selectedIndex].value][0],$("selFundDate3").value,{
			callback:function(re) {
				$("curUnitValue3").value = re;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
		
		MyFundService.getShare(UserID,MyFundCodeArr[$('myselectfund').options[$('myselectfund').selectedIndex].value][0],{
			callback:function(re) {
				$("curShare1").value = re;
				$("how_much_share3").focus();
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	}
}

var FundProportion = {
	"initData": function(){
		pt = new Array(3);
		pt[0] = "InvestmentSum";
		pt[1] = "Share";
		pt[2] = "Value";
		
		flashv = new Array(3);
		
		rateHtml = '';
		
		colorSet =new Array(20);//默认颜色
			colorSet[0] = '006600';
			colorSet[1] = 'CC0000';
			colorSet[2] = '000099';
			colorSet[3] = 'FFFF00';

			colorSet[4] = '00CC00';
			colorSet[5] = '461002';
			colorSet[6] = '0066CC';
			colorSet[7] = 'FFFF99';

			colorSet[8] = 'A4E8BA';
			colorSet[9] = 'F02054';
			colorSet[10] = '3399FF';
			colorSet[11] = '737605';

			colorSet[12] = '466721';
			colorSet[13] = 'FF3399';
			colorSet[14] = '00CCFF';
			colorSet[15] = 'E69A0D';

			colorSet[16] = '7AAB6B';
			colorSet[17] = 'FF66FF';
			colorSet[18] = '7983BB';
			colorSet[19] = '000000';
		
		curPTindex = 2;
		
		//投入本金 0 暂时不处理
		//FundProportion.getHoldingRate(1);
		FundProportion.getHoldingRate(1);
		FundProportion.getHoldingRate(2);
		
		//基金类型比例
		FundProportion.getFundTypeRate();
	},
	"showTab": function(index){
		$('tab_'+pt[curPTindex]).className = '';
		$('tab_'+pt[curPTindex]+'_div').style.display = "none";
		curPTindex = index;
		$('tab_'+pt[curPTindex]+'_div').style.display = "block";
		$('tab_'+pt[curPTindex]).className = 'on';
		$('tab_'+pt[index]+'_div1').innerHTML = rateHtml;
		FlashContrl.updateSwf(flashv[index]);
	},
	"getHoldingRate": function(index){
		MyFundService.getHoldingRate(UserID,pt[index],{
			callback:function(re) {
				var hc = '<li><div class="c1">颜色</div><div class="c2"><h3>基金名称</h3></div><div class="c3">基金代码</div><div class="c4">';
				if(index  == 2){
					hc +='当前市值';
				}else if(index  == 1){
					hc +='持有份额';
				}
				hc += '</div><div class="c5">比例</div><div class="c6">基金类型</div></li>';
				
				var sv = '';//flash数据
				for(var i=0;i<re.length;i++){
					var arr = re[i].split('|');
					hc += '<li><div class="k1" style="background:#'+colorSet[i]+';">　</div><div class="k2"><h3>';
					hc += arr[0];
					hc += '</h3></div><div class="k3">';
					hc += arr[1];
					hc += '</div><div class="k4">';
					hc += arr[2];
					hc += '</div><div class="k5">';
					hc += parseInt(arr[3]*10000)/100.0;
					hc += '%</div><div class="k6">';
					
					if(arr[4] == 1){
						hc += '股票型';
					}else if(arr[4] == 2){
						hc += '混合型';
					}else if(arr[4] == 3){
						hc += '低风险';
					}
					
					hc += '</div></li>';
					
					sv += arr[2];
					sv += '|';
				}
				$('tab_'+pt[index]+'_value').innerHTML = hc;
				flashv[index] = sv.substring(0,sv.length - 1);
				if(re.length<1){
					flashv[index] = '0';
				}
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	},
	"getFundTypeRate": function(){
		MyFundService.getFundTypeRate(UserID,{
			callback:function(re) {
				var hc = '<li><div class="c1"><h3>投资类型</h3></div></li>';
				for(var i=0;i<re.length;i++){
					var arr = re[i].split('|');
					hc += '<li><div class="k1"><h3>';
					if(arr[0] == 1){
						hc += '股票型';
					}else if(arr[0] == 2){
						hc += '混合型';
					}else if(arr[0] == 3){
						hc += '低风险';
					}
					hc += '</h3></div><div class="k2"><h4>';
					hc += parseInt(arr[1]*10000)/100.0;
					hc += '%</h4></div></li>';
				}
				rateHtml = hc;
				
				$('tab_'+pt[2]+'_div1').innerHTML = hc;
			},
			timeout:30000,
			errorHandler:function(message) {
				if(message!=null && message!=""){
					//alert(message);
				}
			}
		});
	}
}

var FlashContrl = {
	"SWF": function(SwfID) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[SwfID];
		} else {
			if(document[SwfID].length != undefined){
	 			return document[SwfID][0];
	 		}
			return document[SwfID];
		}
	},
	"updateSwf": function(v){
		FlashContrl.SWF('pieSwf').setValue(v); 
	}
}

//Flash初始化完毕调用
function callJSInit(){
	FlashContrl.updateSwf(flashv[2]);
}

var TabContrl = {
	"initTab": function(){
		tabName = new Array(6);
		tabName[0] = "tab_buy";
		tabName[1] = "tab_change";
		tabName[2] = "tab_sell";
		tabName[3] = "tab_have";
		tabName[4] = "tab_record";
		tabName[5] = "tab_rate";
		
		curTabIndex = 4;
	},
	"showTab": function(index){
		$(tabName[curTabIndex]).className = '';
		$(tabName[curTabIndex]+'_div').style.display = "none";
		curTabIndex = index;
		$(tabName[curTabIndex]+'_div').style.display = "block";
		$(tabName[curTabIndex]).className = 'on';
	}
}