CookieDomain=".chinaventure.com.cn";
var isLoadUserInfo=false;

var Ticket=new function (){
	this.ChangePaytype=function(){
		if($("Paytype_2").checked){
			//Element.hide($("userinfo_tbl"));
			Element.show($("userfrom"));
			Ticket.Start();
		}else{
			Element.show($("userinfo_tbl"));
			Element.hide($("userfrom"));
		}
	}
	this.Nothing=function(){
		Cookies.Set("cv_UserName","",-1, "/", CookieDomain);Cookies.Set("cv_Password","",-1, "/", CookieDomain)	;Users.isLogind=false;
		isLoadUserInfo=false;
		Element.hide($("userinfo_tbl"));
		this.ShowLoginForm(null);
	}
    this.Start=function(){
	  if(Users.BoolCheckUserState()){
		 this.ShowLogind(Users.GetUserName());
	  }else{   
		 this.ShowLoginForm(ChinaVentureUser);
	  }
	}
	this.ShowLoginForm=function(user){
	   $("TicketUsers").innerHTML="<span id=GuestName >用户名： <input name='TicketUser' type='text' id='TicketUser' size='15' maxlength='20' value='' \/></td><td> 密　码： <input name='TicketPwd' type='password' id='TicketPwd' size='15' maxlength='20' value='' />&nbsp;&nbsp;<input type=\"button\" name=\"CommentButton\"   onclick='Ticket.Login();'  value=\"登陆\">&nbsp;<a href='http://m.chinaventure.com.cn/reg/' target='_blank'>注册新用户</a><span id=TicketLoading></span></span>";
	}
	this.ShowLogind=function(user){
	    $("TicketUsers").innerHTML="欢迎您：<font color=blue> " + user +"</font>【<a href=http://m.chinaventure.com.cn/?10000 target='_blank'>我的订票</a>】【<a href=http://m.chinaventure.com.cn/ target='_blank'>会员中心</a>】【<a onclick=\"Ticket.Nothing();return false;\" href=\"javascript:void(0)\">注销登录</a>】";
		this.LoadUserInfo(user);
	}
	this.LoadUserInfo=function(user){
		if(!isLoadUserInfo){
			var url="/ticket/getuserinfo.aspx?u="+user+"&temp="+Math.random();
			var pars="";
			var myAjax = new Ajax.Request(url,{
				method: 'post',
				parameters: pars,
				onComplete: this.BindUserInfo
			 });
		}else{
			Element.show($("userinfo_tbl"));
		}
	}
	this.BindUserInfo=function(obj){
	   var nodes = obj.responseXml.documentElement.childNodes;
	   if(nodes){
		   $("truename").value=nodes.item(0).text;
		   $("address").value=nodes.item(1).text;
		   $("phone").value=nodes.item(2).text;
		   $("mobile").value=nodes.item(3).text;
		   $("zip").value=nodes.item(4).text;
		   $("company").value=nodes.item(5).text;
		   $("mail").value=nodes.item(6).text;
		   $("title").value=nodes.item(7).text;
		   Element.show($("userinfo_tbl"));
		   isLoadUserInfo=true;
	   }else{
		  isLoadUserInfo=false;
	   }
	}
	this.Login=function(){
       ChinaVentureUser=$("TicketUser").value;
	   if(!Users.CheckUsername(ChinaVentureUser)){
	      $("TicketUser").focus();
		  return ; 
       }
       var password;
       if($("TicketPwd").value==""){        
          alert("请输入密码！");
	      $("TicketPwd").focus();
	      return ; 
       }else{
	      password=$("TicketPwd").value;
	   }
       $("GuestName").innerHTML="&nbsp;&nbsp;<img src=http://new.chinaventure.com.cn/Common/images/loading.gif  align='top'>  登陆中…";
       Users.AjaxLogin(ChinaVentureUser,password,Ticket.CheckUser);
    }
	this.CheckUser=function(originalRequest)
    {
        var arrobj=Common.ArrayValue(originalRequest.responseXML);
		if (arrobj){
		    switch (arrobj[1]){
		    case '0':
		        alert("用户名或密码错误!");
				Ticket.ShowLoginForm(ChinaVentureUser);		
			    break;
		    case '1':
		        Ticket.ShowLogind(ChinaVentureUser);
			    Cookies.Set("cv_UserName", Cookies.Code(ChinaVentureUser),1, "/", CookieDomain)
			    Cookies.Set("cv_Password", Cookies.Code(arrobj[0]),1, "/", CookieDomain)		
                Users.isLogind=true;
				break;
		    default:
		        alert("用户名或密码错误!");
				Ticket.ShowLoginForm(ChinaVentureUser);		
			    break;
			}
	    }
    } 
	this.Events=function(){
	}
}


function pageLoad(){
   show_o();
}
function CheckSubumit(){
		$("HiddenUser").value="guest";
   if($F("truename")==""){
       alert("姓名不能为空!");
       $("truename").focus();
	   return false;
   }
   if($F("company")==""){
       alert("公司名称不能为空!");
	   $("company").focus();
	   return false;
   }
   if($F("mail")==""){
       alert("邮箱不能为空!");
	   $("mail").focus();
	   return false;
   }
   if($F("mobile")==""){
       alert("电话不能为空!");
	   $("mobile").focus();
	   return false;
   }
   if($F("phone")==""){
       alert("电话不能为空!");
	   $("phone").focus();
	   return false;
   }
   if($F("zip")==""){
       alert("邮政编码不能为空!");
	   $("zip").focus();
	   return false;
   }
   if($F("address")==""){
       alert("地址不能为空!");
	   $("address").focus();
	   return false;
   }
   if($F('UserNumSelect')>0){
      for(var i=1;i<=$F('UserNumSelect');i++){
		   if($F("o_UserName_"+i+"")==""){
			   alert("姓名不能为空!");
			   $("o_UserName_"+i+"").focus();
			   return false;
		   }
		   if($F("o_Jobtitle_"+i+"")==""){
			   alert("职位不能为空!");
			   $("o_Jobtitle_"+i+"").focus();
			   return false;
		   }
		   if($F("o_Phone_"+i+"")==""){
			   alert("电话不能为空!");
			   $("o_Phone_"+i+"").focus();
			   return false;
		   }
		   if($F("o_Email_"+i+"")==""){
			   alert("Email不能为空!");
			   $("o_Email_"+i+"").focus();
			   return false;
		   }
	  }
   }
   $("UserCount").disabled=false;
   $("Money").disabled=false;
   return true;
}
function show_o(){
   if($F('UserNumSelect')==0){
       Element.hide($("o_tbl"));
   }else{
      Element.show($("o_tbl"));
      for(var i=1;i<=$F('UserNumSelect');i++){
	     Element.show($("o_"+i+""));
	  }
      for(var i=parseInt($F('UserNumSelect'))+1;i<=10;i++){
	     Element.hide($("o_"+i+""));
	  }
   }
   getprice();
}
function getprice(){
   var n=parseInt($F('UserNumSelect'))+1;
   $("UserCount").value=n;
   
   var price=0;
   var type=$F('TicketType');
   if(type=="GP"){
		price=10000
   }else if (type=="GP(Senior member and above)"){
		price=7000
   }else if (type=="LP"){
		price=7000
   }else if (type=="LP(Senior member and above)"){
		price=4900
   }
     $("Money").value=price*n;
   
   
}