var _showPriceBack=function(ret){
	var nPrice=parseInt($("#newform1 #select option:selected").html().split("元")[0])||0;
	//var nPrice=parseInt($("#newform1 #select").val().split("元")[0])||0;
	if(ret=="-1"){
		$("#selectinfo").html("<span style='color:#FF0000'>没有查询到帐号信息，请重新登录</span>");
		}else if((parseInt(ret)||0)<nPrice){
			$("#selectinfo").html("<span style='color:#FF0000'>您的当前余额"+ret+"元，无法购买"+nPrice+"元的产品，请先充值</span>");
			}else{
				$("#selectinfo").html("当前余额"+ret+"，可以购买");
				}
	}
var _showPrice=function(){
	getPost("/api/llsapi.asp?apiAction=api_userMoney","","_showPriceBack");
	}
var _buy=function(ret){
		$("#newbutton").val("提交");
		$("#newbutton").prop("disabled",false);	
		if(ret.indexOf("[ok]")!=-1){alert("订单生成成功，点确定进入付款页");
		window.location.href='/renew_Pay.asp?id='+ret.replace("[ok]","");
		}else{alert(ret);}
	}
var _buySubmit=function(){
	$("#newbutton").prop("disabled",false);
	$("#newform1").unbind("submit");
		$("#newform1").submit(function(){
				var obj=$(this);
				var isRun=true;
				var PostStr="1=1";
				obj.find("input,select").each(function(){
						var name=$(this).attr("name");
						var Val=$(this).val()||"";
						var spry=$(this).attr("spry:content")||"";
						if(spry!=""){
							var _sp=spry.split(";");
							if(eval("Val.length"+_sp[1])){
								var errText="不得少于"+_sp[1].replace(/[\<|\!\=]/ig,"")+"字符";
								if(_sp[1].indexOf("=")!=-1) errText="必须是"+_sp[1].replace(/[\<|\!\=]/ig,"")+"字符";
								alert(_sp[0]+errText);
								isRun=false;
								$(this).focus();
								return false;
								}
							}
							
						if(Val!="") Val=escape(Val);
						PostStr+="&"+name+"="+Val;
						});
				if(!isRun) return false;
				$("#newbutton").val("提交中，请不要刷新当前页面，以防提交失败");
				$("#newbutton").prop("disabled",false);
				getPost("/user/api_reNewPay.asp",PostStr,"_buy")
				return false;
									   });	
	}


$(function(){
		

				_showPrice();
				$("#newform1 #select").change(function(){
					_showPrice();									
														});
				_buySubmit();
		   })