﻿// JavaScript Document
var uScore;
var Gift;
var Score;
var Smallpic;
var goto_type;
var next_url;
var next_form;
var next_id;
var PID;
var vGift;
//	$("form").serialize(), 

function getUser(){
	$.post(
	"Ajax_Login.asp",
	{
	username: $("#username").val(),
	password: $("#password").val()
	},
	function (msg) {
		var login_value = msg;
		switch (login_value)
		{
		case "1": //alert("用户名为空");
		//$("msg").html("用户名为空");
		document.getElementById("msg").innerHTML="用户名为空";
		break;
		case "2": 
		//alert("密码为空");
		//$("msg").html("密码为空");
		document.getElementById("msg").innerHTML="密码为空";

		break;
		case "3": 
		//alert("用户名或是密码错误");
		//$("msg").html("用户名或是密码错误");
		document.getElementById("msg").innerHTML="用户名或是密码错误";

		break;
		case "9": 
			
			if (goto_type=="1") //链接
			{
				window.location.href=next_url
			}
			if (goto_type=="2") //提交表单
			{
				$.weeboxs.open('#infoBox',{width:400,timeout:30,title:'礼品兑换',onclose:function(){window.location.reload();}
							   });
				
			$.weeboxs.close();	
				//document.myform.submit();
				/*
				$(next_form).submit( function () {
				  alert("1");
				  return false;
				} ); 
				*/
			}
		break;
		}
	}
	);
}

//检查是否登录
function order_goto_next(_next_url,_next_form,_goto_type,uScore,Gift,Score,Smallpic,P_ID)
{
    this.uScore = uScore;
	this.Score = Score;
	this.Gift = Gift;
	this.PID = P_ID;
	this.Smallpic = Smallpic;
	next_url  = _next_url;
	next_form = _next_form;
	goto_type = _goto_type;
	
	
	var url;
	var r_value;

	$.post(
	'Ajax_Check_IsLogin.asp',
	function (msg) {
		r_value = msg;
		if (r_value=="0")
		{	
			$.weeboxs.open('#formBox',{width:360,timeout:30,title:'会员登录'});
			document.getElementById("username").focus();
		}
		else if(r_value=="1")
		{   
			
			document.getElementById("infoBox").innerHTML='<form id="form1" name="form1" method="post" action='+ next_url +'><div class="details"><h6>您当前的积分为：<em>'+uScore+'</em>分</h6><ul><ol class="giftname"><span>您选择的礼品为：</span><strong>'+Gift+'</strong><span>所需<em>'+Score+'</em>积分</span></ol><ol class="smallpic"><img src="'+Smallpic+'" heigh=100 width=100/></ol><ol class="add"><li><span>收货人：</span><input name="Order_Send_Name" type="text" id="Order_Send_Name" /></li><li><span>收货地址：</span><input name="Order_Send_Addr" type="text" id="Order_Send_Addr" /></li><li><span>邮政编码：</span><input name="Order_Send_Zip" type="text" id="Order_Send_Zip"  /></li></ol><ol class="goto"><button class="submit" type="submit" >确定兑换</button><button class="dialog-cancel concel" >取消返回</button></ol></ul></div></form>';
			$.weeboxs.open('#infoBox',{width:600,timeout:30,title:'礼品兑换'});		//kimi 2009/2/20   添加录入收货人信息
			
		}		
		else
		{
			if (goto_type=="1") //链接
			{
				window.location.href=next_url
			}
			if (goto_type=="2") //提交表单
			{
				document.getElementById(next_form).submit();
			}
		}
	}
	);

			
}
function isbuy(uScore,Score)
{    
	if (uScore < Score)
	    {
			alert("对不起，您的积分不足兑换！");
		}
		else
		{
		
		if (Order_Send_Name_Check()==false)
		{
			return false;
		}

		if (Order_Send_Addr_Check()==false)
		{
			return false;
		}

		if (Order_Send_Zip_Check()==false)
		{
			return false;
		}
		
		$.post(
		"saveaction.asp",
		{
			pro: PID,
			Product_ID:PID,
			Order_Send_Name:$("#Order_Send_Name").val(),
			Order_Send_Addr:$("#Order_Send_Addr").val(),
			Order_Send_Zip:$("#Order_Send_Zip").val()
		},
		function (orderstate) {
			var state=orderstate.split("|");
			var status = state[0];
			switch (status)
			{
			case "14893888839841": 
			alert("对不起，兑换失败，请检查网络状态~！");
			break;
			case "1": 
			alert('兑换成功！您的订单号为：'+state[1]+'!');
			window.location.reload();
			break;
			case "9": 
			alert('你的积分不够!');
			break;
			}
		}
		);

	}
}

function Order_Send_Name_Check()
{
	var Order_Send_Name;
    Order_Send_Name=document.getElementById("Order_Send_Name").value;

	if(trim(Order_Send_Name)==""){
		alert("请填写完整的收货信息，以便我们及时发货，谢谢！！");
		document.getElementById("Order_Send_Name").focus();
       	return false;		
	}
	if(Order_Send_Name.length>20){
		alert("收货人名称过长，请减少字数谢谢！！");
		document.getElementById("Order_Send_Name").focus();
       	return false;	
	}
}

function Order_Send_Addr_Check()
{
	var Order_Send_Addr;
	Order_Send_Addr=document.getElementById("Order_Send_Addr").value;
	if(trim(Order_Send_Addr)==""){
		alert("请填写完整的收货信息，以便我们及时发货，谢谢！！");
		document.getElementById("Order_Send_Addr").focus();
       	return false;		
	}
	if(Order_Send_Addr.length>200){
		alert("收货地址过长，请减少字谢！！");
		document.getElementById("Order_Send_Addr").focus();
       	return false;	
	}
}

function Order_Send_Zip_Check()
{
	var Order_Send_Zip;
	Order_Send_Zip=document.getElementById("Order_Send_Zip").value;
	if(trim(Order_Send_Zip)==""){
		alert("请填写完整的收货信息，以便我们及时发货，谢谢！！");
		document.getElementById("Order_Send_Zip").focus();
       	return false;
	}
	if(Order_Send_Zip.length>10){
		alert("邮编过长，请减少字谢谢！！");
		document.getElementById("Order_Send_Zip").focus();
       	return false;	
	}
}

function trim(s)
{   
  	if(s.length>0){   
  		if(s.charAt(0)==" ")  s=s.substring(1,s.length);   
  		if(s.charAt(s.length-1)==" ")  s=s.substring(0,s.length-1);   
  		if(s.charAt(0)==" "||s.charAt(s.length-1)==" ")   return   trim(s);   	
  	}   
  	return   s;   
 }