// JavaScript Document
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='/Pay.asp?id='+ret.replace("[ok]","");
		}else{alert(ret);}
	}

var getUserInfosBack=function(ret){
	$(".uinfos").html(ret);
	if(ret.indexOf("所有人资料")!=-1){
		_buySubmit();
	}
	
	}	
var getUserInfos=function(id){
	getPost("/api/api_MyInfos.asp?id="+id,"","getUserInfosBack");
	}	
var _buySubmit=function(){
	$("#newform1").unbind("submit");
	$("#newbutton").prop("disabled",false);
		$("#newform1").submit(function(){
				var obj=$(this);
				var isRun=true;
				var sDomain=obj.find("#sDomain").val();
				if(sDomain.replace(/([(a-zA-Z0-9)+]|[:\/\/]|\.)/ig,"")!=""||sDomain==""){
					obj.find("#sDomain").focus();
					alert("请输入标准的域名");
					isRun=false;
					return false;
					}
	
				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_buy.asp",PostStr,"_buy")
				return false;
									   });
	}

$(function(){
				_showPrice();
				$("#newform1 #select").change(function(){
					_showPrice();									
														});
		   var id=0;
		   if($(".myinfos a").size()>0){
			   id=$(".myinfos a:eq(0)").attr("id").replace("tid","");
			   }
			   getUserInfos(id);	
			   $(".myinfos a").click(function(){
					var idz=$(this).attr("id").replace("tid","");
					getUserInfos(idz);	
						return false;					  
											  });
			   
						
				
		   })