﻿// JScript 文件 author:luobing qq:314941525
    var url=location.search;
    var Request = new Object();
    var program_id;
    if(url.indexOf("?")!=-1)
    {
        var str = url.substr(1)
        strs = str.split("&");
        for(var i=0;i<strs.length;i++)
        {
            Request[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    if(Request["program_id"]!=null)
    {
       if(Request["program_id"].toString()!="")
       {
          program_id = Request["program_id"].toString();
       }
    }

  var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
  function initMPPage()
  {
  		var mapObj = document.getElementsByName('Map2');
		if(mapObj!=null&&mapObj.length>0)
		{
		    try
		    {
		        if(program_timeOut!="ture")
		        {
			        //如果一张票都没售出、购物车中也没有选择位置、也没有已下订单的票 则不向下执行
		   	        if(seatArry.length==0 && selectSeatArry.length==0 && orderSeatArry.length==0)
			        {
			           return;
			        }
			    }
			}catch(error){}			
		   for(var i=0;i<mapObj[0].areas.length;i++)
		   {
		       var areaObj = mapObj[0].areas[i];
		       areaObj.title="点击可订购此位置";
		       try
		       {
		          //此节目过期
		          if(program_timeOut=="ture")
		          { 
		             areaObj.onmouseup="";
		             areaObj.title="";
		          }
		       }
		       catch(error){}
			   try
			   {
			      
			      s = areaObj.id.split(",");
			      if(s[0]!="" && s[1]!="" && s[2]!="")
                   {
                      //已售的票话上标记
                      for(var j=0;j<seatArry.length;j++)
                      {
                         if(seatArry[j][0]==s[0] && seatArry[j][1]==s[1] && seatArry[j][2]==s[2])
                         {
                             //调用画票标记函数
                             PublicDrawDiv(areaObj.coords,areaObj.id,"#17212F","已售出","",null);
                         }
                      }
                      //已选择的票画上标记
                      for(var j=0;j<selectSeatArry.length;j++)
                      {
                         if(selectSeatArry[j][0]==s[0] && selectSeatArry[j][1]==s[1] && selectSeatArry[j][2]==s[2])
                         {
                             //调用画票标记函数
                             PublicDrawDiv(areaObj.coords,areaObj.id,"#08C015","点击可取消选择","hand","SeatConnect_Cancel(this,'"+areaObj.id+"')");
                         }
                      }
                      //已下订单的票画上标记
                      for(var j=0;j<orderSeatArry.length;j++)
                      {
                         if(orderSeatArry[j][0]==s[0] && orderSeatArry[j][1]==s[1] && orderSeatArry[j][2]==s[2])
                         {
                             //调用画票标记函数
                             PublicDrawDiv(areaObj.coords,areaObj.id,"#777777","已下订单","",null);
                         }
                      }
                   }
			   }
			   catch(error){}
		   }
		}
  }

  //订票选择
  function SelectSeat(seatObj)
  {
      //区域ID，排、列
      s = seatObj.id.split(",");
      var area_id=s[0];
      var row_no=s[1];
      var column_no=s[2];
      var webFileUrl = "/Pages/Check_SeatSell.aspx?type=check&program_id="+program_id+"&area_id="+area_id+"&row_no="+row_no+"&column_no="+column_no;
      var result = "";//返回结果
      //开始取值过程
      xmlHttp.open("POST", webFileUrl, false);
      xmlHttp.send("");
      result = xmlHttp.responseText;
      if(result=="selled")
      {
         //已出售此票
         alert("很抱歉，此位置已出售！");
	     return;
      }
      else if(result=="ordered")
      {
         //已下订单
         alert("很抱歉，此位置他人已下订单！");
	     return;
      }
      else if(result=="selected")
      {
         //已被选择
         alert("很抱歉，此位置他人已选择！");
         return;
      }
      else if(result=="seattype_notsell")
      {
         //此类型的票不允许网上出售
         alert("很抱歉，此类型的票不能通过网上购买，请去售票点购买！");
         return;
      }
      else if(result=="seattype_notsell_1")
      {
         alert("很抱歉，学生票只能演出前7天出售！");
         return;
      }
      else if(result=="error")
      {
         //程序异常
         alert("操作失败，请刷新页面后重试！");
         return;
      }
      else
      {
         //未出售、未下订单、且未被选择
         
         //判断是否有无套票关联
         webFileUrl = "/Pages/Get_SeatConnect.aspx?area_id="+area_id+"&row_no="+row_no+"&column_no="+column_no;
         //开始取值过程
         xmlHttp.open("POST", webFileUrl, false);
         xmlHttp.send("");
         result = xmlHttp.responseText;
         if(result=="")
         {
             //无套票
             PublicDrawDiv(seatObj.coords,seatObj.id,"#08C015","点击可取消选择","hand","SeatConnect_Cancel(this,'"+seatObj.id+"')");//调用画票标记函数
             operateSeat(seatObj.id,"insert");
         }
         else if(result=="error")
         {
             //程序异常
             alert("操作失败，请刷新页面后重试！");
             return;
         }
         else
         {
             //有套票
             SeatConnect_Setting(result,"insert");
         }
      }
  }
  
  //对有套票的位置进行关联
  function SeatConnect_Setting(seatList,operType)
  {
      seatListArry = seatList.split("_");
      //读取整个地图，查找ID对应的位置
      var mapObj = document.getElementsByName('Map2');
      if(mapObj!=null&&mapObj.length>0)
      {
             for(var j=0;j<seatListArry.length;j++)
             {
                 if(seatListArry[j]!="")
                 { 
                     var areaObj = document.getElementById(seatListArry[j]);
                     //如果相等，说明这是套票区域
                     if(operType=="insert")
                     {
                        //增加选择区域
                        PublicDrawDiv(areaObj.coords,areaObj.id,"#08C015","点击可取消选择","hand","SeatConnect_Cancel(this,'"+areaObj.id+"')");//调用画票标记函数
                     }
                     else
                     {
                        //移除选择的区域
                        var obj = document.getElementById("seat_"+areaObj.id);
                        obj.parentNode.removeChild(obj);
                     }
                     operateSeat(areaObj.id,operType);
                }
            }
      }
  }
  
  //对有套票的位置如果取消一个时，其他关联的位置也取消
  function SeatConnect_Cancel(obj,seat)
  {
      s = seat.split(",");
      var area_id=s[0];
      var row_no=s[1];
      var column_no=s[2];
     //判断是否有无套票关联
     var webFileUrl = "/Pages/Get_SeatConnect.aspx?area_id="+area_id+"&row_no="+row_no+"&column_no="+column_no;
     //开始取值过程
     xmlHttp.open("POST", webFileUrl, false);
     xmlHttp.send("");
     var result = xmlHttp.responseText;
     if(result=="")
     {
         obj.parentNode.removeChild(obj);
         operateSeat(seat,'delete')
     }
     else if(result=="error")
     {
         //程序异常
         alert("操作失败，请刷新页面后重试！");
         return;
     }
     else
     {
         //有套票
         SeatConnect_Setting(result,"delete");
     }
  }
  
  //通用画位置函数
  function PublicDrawDiv(points,seat,color,title,cursorStyle,funStr)
  {
         //区域ID，排、列
         s = seat.split(",");
	     //左，上,右，下 坐标
	     p = points.split(",");
	     var leftP = p[0];
	     var topP = p[1];
	     var rightP = p[2];
	     var bottomP=p[3];
	     var widthP = rightP-leftP;
	     var heightP = bottomP-topP;
	     //如果热区为矩形，则按划层来处理
	     if(p.length==4)
	     {
             //向DIV中插入子DIV元素
             div=document.createElement("div");
             div.id="seat_"+seat;
             div.style.position="absolute";
             div.style.styleFloat="left";
             div.style.filter = "alpha(opacity=60)";//设置区域内透明度
             div.style.backgroundColor=color;
             div.style.marginLeft=leftP+"px";
             div.style.marginTop=topP+"px";
             div.style.width=widthP+"px";
             div.style.height=heightP+"px";
             div.title=title;
             div.style.cursor=cursorStyle;
             if(funStr!=null)
             {
                div.onmouseup = new Function(funStr);
             }
             document.getElementById("leveldiv1").appendChild(div);
         }
         else
         {		 
             //如果热区为多边形，则按<v:polyline来处理
             polyline=document.createElement("v:polyline");
             polyline.id="seat_"+seat;
             polyline.strokecolor="translpate";//边框线条颜色为透明
             polyline.fillcolor=color;//区域填充颜色
             polyline.points=points;
             polyline.style.position="absolute";
             polyline.style.filter = "alpha(opacity=60)";//设置区域内透明度
             polyline.title=title;
             polyline.style.cursor=cursorStyle;
             if(funStr!=null)
             {
                polyline.onmouseup = new Function(funStr);
             }
             document.getElementById("leveldiv1").appendChild(polyline);
         }
  }
  //记录选择的位置
  function operateSeat(seat,operateType)
  {
      s = seat.split(",");//区域ID，排、列
      var area_id=s[0];
      var row_no=s[1];
      var column_no=s[2];
      var webFileUrl = "/Pages/Check_SeatSell.aspx?type="+operateType+"&program_id="+program_id+"&area_id="+area_id+"&row_no="+row_no+"&column_no="+column_no;
      var result = "";//返回结果
      //开始取值过程
      xmlHttp.open("POST", webFileUrl, false);
      xmlHttp.send("");
      result = xmlHttp.responseText;
      if(result=="uid is null")
      {
         var currentUrl = this.location.href;
         currentUrl = currentUrl.substring(currentUrl.indexOf("http://") + 7);
         currentUrl = currentUrl.substring(currentUrl.indexOf("/"));
         //alert("您未登录或登录超时，请登录后再执行此项操作！");
         //showbgPanel('Login','/member/member_login.aspx?RegRedirectUrl='+currentUrl+'&LoginRedirectUrl='+currentUrl,265,160);
         alert("请选择您的购票方式！");
         showbgPanel('Login','/Pages/buyBill_login.aspx?RegRedirectUrl='+currentUrl+'&LoginRedirectUrl='+currentUrl,264,220);
         return;
      }
      else if(result=="error")
      {
         alert("操作失败，请刷新页面后重试！");
         return;
      }
  }
