/*
buy.js
2009年10月19日
*/

function Buy()
{
  this.data={
  id:"",
  productname:"",
  productcolor:"",
  productamount:"",
  province:"",
  city:"",
  address:"",
  name:"",
  telphone:"",
  postcode:"",
  comment:""
  };
  
  this.cities = new Object();
  this.cities['北京'] = new Array('北京');
  this.cities['上海'] = new Array('上海');
  this.cities['天津'] = new Array('天津');
  this.cities['重庆'] = new Array('重庆');
  this.cities['河北'] = new Array('石家庄', '张家口', '承德', '秦皇岛', '唐山', '廊坊', '保定', '沧州', '衡水', '邢台', '邯郸');
  this.cities['山西'] = new Array('太原', '大同', '朔州', '阳泉', '长治', '晋城', '忻州', '吕梁', '晋中', '临汾', '运城');
  this.cities['辽宁'] = new Array('沈阳', '朝阳', '阜新', '铁岭', '抚顺', '本溪', '辽阳', '鞍山', '丹东', '大连', '营口', '盘锦', '锦州', '葫芦岛');
  this.cities['吉林'] = new Array('长春', '白城', '松原', '吉林', '四平', '辽源', '通化', '白山', '延边');
  this.cities['黑龙江'] = new Array('哈尔滨', '齐齐哈尔', '黑河', '大庆', '伊春', '鹤岗', '佳木斯', '双鸭山', '七台河', '鸡西', '牡丹江', '绥化', '大兴安岭');
  this.cities['江苏'] = new Array('南京', '徐州', '连云港', '宿迁', '淮阴', '盐城', '扬州', '泰州', '南通', '镇江', '常州', '无锡', '苏州');
  this.cities['浙江'] = new Array('杭州', '湖州', '嘉兴', '舟山', '宁波', '绍兴', '金华', '台州', '温州', '丽水', '衢州');
  this.cities['安徽'] = new Array('合肥', '宿州', '淮北', '阜阳', '蚌埠', '淮南', '滁州', '马鞍山', '芜湖', '铜陵', '安庆', '黄山', '六安', '巢湖', '池州', '宣城');
  this.cities['福建'] = new Array('福州', '南平', '三明', '莆田', '泉州', '厦门', '漳州', '龙岩', '宁德');
  this.cities['江西'] = new Array('南昌', '九江', '景德镇', '鹰潭', '新余', '萍乡', '赣州', '上饶', '抚州', '宜春', '吉安');
  this.cities['山东'] = new Array('济南', '聊城', '德州', '东营', '淄博', '潍坊', '烟台', '威海', '青岛', '日照', '临沂', '枣庄', '济宁', '泰安', '莱芜', '滨州', '菏泽');
  this.cities['河南'] = new Array('郑州', '三门峡', '洛阳', '焦作', '新乡', '鹤壁', '安阳', '濮阳', '开封', '商丘', '许昌', '漯河', '平顶山', '南阳', '信阳', '周口', '驻马店');
  this.cities['湖北'] = new Array('武汉', '十堰', '襄攀', '荆门', '孝感', '黄冈', '鄂州', '黄石', '咸宁', '荆州', '宜昌', '恩施', '襄樊');
  this.cities['湖南'] = new Array('长沙', '张家界', '常德', '益阳', '岳阳', '株洲', '湘潭', '衡阳', '郴州', '永州', '邵阳', '怀化', '娄底', '湘西');
  this.cities['广东'] = new Array('广州', '清远', '韶关', '河源', '梅州', '潮州', '汕头', '揭阳', '汕尾', '惠州', '东莞', '深圳', '珠海', '江门', '佛山', '肇庆', '云浮', '阳江', '茂名', '湛江');
  this.cities['海南'] = new Array('海口', '三亚');
  this.cities['四川'] = new Array('成都', '广元', '绵阳', '德阳', '南充', '广安', '遂宁', '内江', '乐山', '自贡', '泸州', '宜宾', '攀枝花', '巴中', '达川', '资阳', '眉山', '雅安', '阿坝', '甘孜', '凉山');
  this.cities['贵州'] = new Array('贵阳', '六盘水', '遵义', '毕节', '铜仁', '安顺');
  this.cities['云南'] = new Array('昆明', '曲靖', '玉溪', '丽江', '昭通', '思茅', '临沧', '保山', '迪庆', '大理', '楚雄', '西双版纳');
  this.cities['陕西'] = new Array('西安', '延安', '铜川', '渭南', '咸阳', '宝鸡', '汉中', '榆林', '商洛', '安康');
  this.cities['甘肃'] = new Array('兰州', '嘉峪关', '金昌', '白银', '天水', '酒泉', '张掖', '武威', '庆阳', '平凉', '定西', '陇南', '临夏', '甘南');
  this.cities['青海'] = new Array('西宁', '海东', '西宁', '果洛', '玉树', '海西');
  this.cities['内蒙古'] = new Array('呼和浩特', '包头', '乌海', '赤峰', '呼伦贝尔盟', '兴安盟', '哲里木盟', '锡林郭勒盟', '乌兰察布盟', '鄂尔多斯', '巴彦淖尔盟', '阿拉善盟');
  this.cities['广西'] = new Array('南宁', '桂林', '柳州', '梧州', '贵港', '玉林', '钦州', '北海', '防城港', '南宁', '百色', '河池', '柳州', '贺州');
  this.cities['西藏'] = new Array('拉萨', '那曲', '昌都', '林芝', '山南', '日喀则', '阿里');
  this.cities['宁夏'] = new Array('银川', '石嘴山', '吴忠', '固原');
  this.cities['新疆'] = new Array('乌鲁木齐', '克拉玛依', '喀什', '阿克苏', '和田', '吐鲁番', '哈密', '昌吉', '伊犁', '塔城', '阿勒泰');
  this.cities['台湾'] = new Array('台湾');
  this.cities['香港'] = new Array('香港');
  this.cities['澳门'] = new Array('澳门');
  this.cities['海外'] = new Array('海外');
}

Buy.prototype.collect=function()
{
  this.data.productname=$("buy.productname").value;
  this.data.productamount=$("buy.productamount").value;
  this.data.province=$("buy.province").value;
  this.data.city=$("buy.city").value;
  this.data.address=$("buy.address").value;
  this.data.name=$("buy.name").value;
  this.data.telphone=$("buy.telphone").value;
  this.data.postcode=$("buy.postcode").value;
  this.data.comment=$("buy.comment").value;

  if(this.data.productname=="")
  {
    alert("请填写商品名称。");
    $("buy.productname").focus();
    return false;
  }
  if(this.data.province=="")
  {
    alert("请填写收货省份。");
    $("buy.province").focus();
    return false;
  }
  if(this.data.city=="")
  {
    alert("请填写收货城市。");
    $("buy.city").focus();
    return false;
  }
  if(this.data.address=="")
  {
    alert("请填写收货地址。");
    $("buy.address").focus();
    return false;
  }
  if(this.data.name=="")
  {
    alert("请填写收货姓名。");
    $("buy.name").focus();
    return false;
  }
  if(this.data.telphone=="")
  {
    alert("请填写收货电话。");
    $("buy.telphone").focus();
    return false;
  }
  if(this.data.mobile=="")
  {
    alert("请填写收货手机。");
    $("buy.mobile").focus();
    return false;
  }
  if(this.data.postcode=="")
  {
    alert("请填写收货邮编。");
    $("buy.postcode").focus();
    return false;
  }
  if(this.data.comment=="")
  {
    alert("请填写留言。");
    $("buy.comment").focus();
    return false;
  }
  return true;
}

//生成订单
Buy.prototype.add=function()
{ 
    if(this.collect()==false)
      return;
    var obj=new Ajax(this);
    obj.post("/servlet/order/buy.servlet.php",
    "action","add",
    "productname",this.data.productname,
    "productcolor",this.data.productcolor,
    "productamount",this.data.productamount,
    "province",this.data.province,
    "city",this.data.city,
    "address",this.data.address,
    "name",this.data.name,
    "telphone",this.data.telphone,
    "postcode",this.data.postcode,
    "comment",this.data.comment,
    this.addback);
}

Buy.prototype.addback=function(value)
{
  if(value.charAt(0)!="#")
  {
    alert("订单提交成功！");
  }
  else 
  {
    alert(value);
  }
}

Buy.prototype.setprovince=function()
{
  var prov=$("buy.province");
  prov.length=0;
  prov.options[prov.length]=new Option("请选择","");  
	for(i in this.cities)
	  prov.options[prov.length]=new Option(i,i); 
}

Buy.prototype.setcity=function()
{
  var prov=$("buy.province");
  var city=$("buy.city");
  city.length=0;
  city.options[city.length]=new Option("请选择","");
  var provname=prov.options[prov.selectedIndex].value;
  if(provname=="")
    return;
	for(var i=0;i<this.cities[provname].length;i++)
	  city.options[city.length]=new Option(this.cities[provname][i],this.cities[provname][i]);
}

var buy=new Buy();

//End
