/**
 * @namespace com.thesis.control.SignUpControl
 * @author 钟军锐 August.R@263.net
 */

/** @id SignUpControl */
function SignUpControl(){
	this.mapping = {
		divSignUp:"divSignUp",
		divSetp1:"SignUp_Step1",
		divSetp2:"SignUp_Step2",
		divSetp3:"SignUp_Step3",
		divSetp4:"SignUp_Step4",
		divSetp5:"SignUp_Step5",
		divSetp6:"SignUp_Step6",
		divSetp7:"SignUp_Step7",
		btnNext1:"btnNext_1",
		btnNext2:"btnNext_2",
		btnNext3:"btnNext_3",
		btnNext4:"btnNext_4",
		btnNext5:"btnNext_5",
		btnNext6:"btnNext_6",
		btnSumbit:"btnNext_7",
		btnPrevious2:"btnPrevious_2",
		btnPrevious3:"btnPrevious_3",
		btnPrevious4:"btnPrevious_4",
		btnPrevious5:"btnPrevious_5",
		btnPrevious6:"btnPrevious_6",
		btnPrevious7:"btnPrevious_7",
		btnChangeVC:"btnChangeVC",
		btnReSendVC:"btnReSendVC",
		btnShow:"btnShowSignUpDialog",
		
		txtLoginID:"txtLoginID",
		txtVC:"txtSignUpVC",
		txtEmail:"txtEmail",
		txtEmailVC:"txtEmailVC",
		
		txtPwd:"txtSignInPWD",
		txtRpwd:"txtSignInRPWD",
		
		txtName:"txtName",
		txtShortName:"txtShortName",
		txtWebLink:"txtWebLink",
		txtIntroduce:"txtIntroduce",
		
		txtLicenceID:"txtLicenceID",
		txtTaxNum:"txtTaxNum",
		txtAddress:"txtAddress",
		txtZip:"txtZip",
		txtPhone:"txtPhone",
		txtFax:"txtFax",
		txtEnterpriseCode:"txtEnterpriseCode",
		txtJuridicalPerson:"txtJuridicalPerson",
		txtBank:"txtBank",
		txtBankID:"txtBankID",
		
		txtLinkMan:"txtLinkMan",
		txtLinkPhone:"txtLinkPhone",
		
		selType:"selType",
		imgVC:"imgVC",
		hidVariety:"hidVariety",
		
		chkVariety1:"chkSV1",
		chkVariety2:"chkSV2",
		chkVariety3:"chkSV3",
		chkVariety4:"chkSV4",
		chkVariety5:"chkSV5",
		chkVariety6:"chkSV6",
		chkVariety7:"chkSV7",
		chkVariety8:"chkSV8",
		chkVariety9:"chkSV9",
		chkVarietyA:"chkSVA",
		chkVarietyB:"chkSVB",
		chkVarietyC:"chkSVC",
		chkVarietyD:"chkSVD",
		chkVarietyE:"chkSVE",
		chkVarietyF:"chkSVF"
	};
	
	this.VC = new ValidateCode(this.mapping.imgVC,"/Service/vc.s" , this.mapping.btnChangeVC, false);
	
	M$(this.mapping);
	
	this.CheckBox = {};
	this.CheckBox.chk1 = this.mapping.chkVariety1;
	this.CheckBox.chk2 = this.mapping.chkVariety2;
	this.CheckBox.chk3 = this.mapping.chkVariety3;
	this.CheckBox.chk4 = this.mapping.chkVariety4;
	this.CheckBox.chk5 = this.mapping.chkVariety5;
	this.CheckBox.chk6 = this.mapping.chkVariety6;
	this.CheckBox.chk7 = this.mapping.chkVariety7;
	this.CheckBox.chk8 = this.mapping.chkVariety8;
	this.CheckBox.chk9 = this.mapping.chkVariety9;
	this.CheckBox.chkA = this.mapping.chkVarietyA;
	this.CheckBox.chkB = this.mapping.chkVarietyB;
	this.CheckBox.chkC = this.mapping.chkVarietyC;
	this.CheckBox.chkD = this.mapping.chkVarietyD;
	this.CheckBox.chkE = this.mapping.chkVarietyE;
	this.CheckBox.chkF = this.mapping.chkVarietyF;
	
	this.Dialog = {};
	this.Dialog.Step1={};
	this.Dialog.Step1.Frame = this.mapping.divSetp1;
	this.Dialog.Step1.LoginID = this.mapping.txtLoginID;
	this.Dialog.Step1.VC = this.mapping.txtVC;
	
	this.Dialog.Step2={};
	this.Dialog.Step2.Frame = this.mapping.divSetp2;
	this.Dialog.Step2.Email = this.mapping.txtEmail;
	
	this.Dialog.Step3={};
	this.Dialog.Step3.Frame = this.mapping.divSetp3;
	this.Dialog.Step3.EmailVC = this.mapping.txtEmailVC;
	
	this.Dialog.Step4={};
	this.Dialog.Step4.Frame = this.mapping.divSetp4;
	this.Dialog.Step4.Pwd = this.mapping.txtPwd;
	this.Dialog.Step4.Rpwd = this.mapping.txtRpwd;
	
	this.Dialog.Step5={};
	this.Dialog.Step5.Frame = this.mapping.divSetp5;
	this.Dialog.Step5.Name = this.mapping.txtName;
	this.Dialog.Step5.ShortName = this.mapping.txtShortName;
	this.Dialog.Step5.Introduce = this.mapping.txtIntroduce;
	this.Dialog.Step5.WebLink = this.mapping.txtWebLink;
	this.Dialog.Step5.Type = this.mapping.selType;
	this.Dialog.Step5.Variety = this.mapping.hidVariety;
	
	this.Dialog.Step6={};
	this.Dialog.Step6.Frame = this.mapping.divSetp6;
	this.Dialog.Step6.LicenceID = this.mapping.txtLicenceID;
	this.Dialog.Step6.TaxNum = this.mapping.txtTaxNum;
	this.Dialog.Step6.Fax = this.mapping.txtFax;
	this.Dialog.Step6.Address = this.mapping.txtAddress;
	this.Dialog.Step6.Zip = this.mapping.txtZip;
	this.Dialog.Step6.Phone = this.mapping.txtPhone;
	this.Dialog.Step6.EnterpriseCode = this.mapping.txtEnterpriseCode;
	this.Dialog.Step6.JuridicalPerson = this.mapping.txtJuridicalPerson;
	this.Dialog.Step6.Bank = this.mapping.txtBank;
	this.Dialog.Step6.BankID = this.mapping.txtBankID;
	
	this.Dialog.Step7={};
	this.Dialog.Step7.Frame = this.mapping.divSetp7;
	this.Dialog.Step7.LinkMan = this.mapping.txtLinkMan;
	this.Dialog.Step7.LinkPhone = this.mapping.txtLinkPhone;
	
	this.SignUpDialog = new CommonDialog("注册",this.mapping.divSignUp,true,true);
	this.SignUpDialog.SubHead = C$("span");
	this.SignUpDialog.TitleBar.appendChild(this.SignUpDialog.SubHead);
	
	
	this.Form={};
	
	this.Form.Exist={};
	this.Form.Exist.sURL = "/Service/TMemberService.asmx/isMemberExist";
	this.Form.Exist.oParams = {};
	this.Form.Exist.oParams.name = this.Dialog.Step1.LoginID;
	this.Form.Exist.oParams.vc = this.Dialog.Step1.VC;
	
	this.Form.GetEmailVC={};
	this.Form.GetEmailVC.sURL = "/Service/TMemberService.asmx/getEmailVC";
	this.Form.GetEmailVC.oParams={};
	this.Form.GetEmailVC.oParams.Email = this.Dialog.Step2.Email;
	
	this.Form.ValideEmail={};
	this.Form.ValideEmail.sURL = "/Service/TMemberService.asmx/validateEmail";
	this.Form.ValideEmail.oParams={};
	this.Form.ValideEmail.oParams.vc = this.Dialog.Step3.EmailVC;
	
	this.Form.SetPassWord={};
	this.Form.SetPassWord.sURL ="/Service/TMemberService.asmx/setPassWord";
	this.Form.SetPassWord.oParams={};
	this.Form.SetPassWord.oParams.pwd = this.Dialog.Step4.Pwd;
	this.Form.SetPassWord.oParams.rpwd = this.Dialog.Step4.Rpwd;
	
	this.Form.setCorpInfo={};
	this.Form.setCorpInfo.sURL = "/Service/TMemberService.asmx/setCorpInfo";
	this.Form.setCorpInfo.oParams={};
	this.Form.setCorpInfo.oParams.Name = this.Dialog.Step5.Name;
	this.Form.setCorpInfo.oParams.ShortName = this.Dialog.Step5.ShortName;
	this.Form.setCorpInfo.oParams.WebLink = this.Dialog.Step5.WebLink;
	this.Form.setCorpInfo.oParams.sType = this.Dialog.Step5.Type;
	this.Form.setCorpInfo.oParams.Introduce = this.Dialog.Step5.Introduce;
	this.Form.setCorpInfo.oParams.Variety = this.Dialog.Step5.Variety;
	
	this.Form.setLicenceInfo={};
	this.Form.setLicenceInfo.sURL ="/Service/TMemberService.asmx/setLicenceInfo";
	this.Form.setLicenceInfo.oParams={};
	this.Form.setLicenceInfo.oParams.LicenceID = this.Dialog.Step6.LicenceID;
	this.Form.setLicenceInfo.oParams.TaxNum = this.Dialog.Step6.TaxNum;
	this.Form.setLicenceInfo.oParams.Addr = this.Dialog.Step6.Address;
	this.Form.setLicenceInfo.oParams.Zip = this.Dialog.Step6.Zip;
	this.Form.setLicenceInfo.oParams.Phone = this.Dialog.Step6.Phone;
	this.Form.setLicenceInfo.oParams.Fax = this.Dialog.Step6.Fax;
	this.Form.setLicenceInfo.oParams.EnterpriseCode = this.Dialog.Step6.EnterpriseCode;
	this.Form.setLicenceInfo.oParams.JuridicalPerson = this.Dialog.Step6.JuridicalPerson;
	this.Form.setLicenceInfo.oParams.Bank = this.Dialog.Step6.Bank;
	this.Form.setLicenceInfo.oParams.BankID = this.Dialog.Step6.BankID;
	
	this.Form.SignUp={};
	this.Form.SignUp.sURL="/Service/TMemberService.asmx/signUp";
	this.Form.SignUp.oParams={};
	this.Form.SignUp.oParams.LinkMan = this.Dialog.Step7.LinkMan;
	this.Form.SignUp.oParams.LinkPhone = this.Dialog.Step7.LinkPhone;
	
	
	this.BO = {};
	this.BO.Exist = new BaseBO(SystemMessage, this.Form.Exist);
	this.BO.EmailVC = new BaseBO(SystemMessage, this.Form.GetEmailVC);
	this.BO.ValidateEmailVC = new BaseBO(SystemMessage, this.Form.ValideEmail);
	this.BO.PWD = new BaseBO(SystemMessage, this.Form.SetPassWord);
	this.BO.CorpInfo = new BaseBO(SystemMessage, this.Form.setCorpInfo);
	this.BO.LicenceInfo = new BaseBO(SystemMessage, this.Form.setLicenceInfo);
	this.BO.SignUp = new BaseBO(SystemMessage, this.Form.SignUp);
	
	this.bSignUp = false;
	
	if(typeof SignUpControl._initialized == "undefined"){
		SignUpControl._initialized = true;
		
		/** @id setStep */
		SignUpControl.prototype.setStep = function(iStep){
			var i="";
			var j=0;
			for(i in this.Dialog){
				j++;
				if(j==iStep)
					this.Dialog[i]["Frame"].style.display = "block";
				else
					this.Dialog[i]["Frame"].style.display = "none";
			}
			this.SignUpDialog.SubHead.innerHTML = "　(" + iStep + " / 7)";
		};
		
		/** @id handleException */
		SignUpControl.prototype.handleException = function(ex){
			this.SignUpDialog.exception(ex.toString());
		};
		
		/** @id handleMessage */
		SignUpControl.prototype.handleMessage = function(msg){
			var flag = true;
			var i =0;
			if(msg.code == Configuration.Symbol.SignInIDVacancy){
				i=2;
			}
			else if(msg.code == Configuration.Symbol.TSignUpEmailVCSent){
				i=3;
			}
			else if(msg.code == Configuration.Symbol.TSignUpEmailVCValidated){
				i=4;
			}
			else if(msg.code == Configuration.Symbol.TSignUpPWDSeted){
				i=5;
			}
			else if(msg.code == Configuration.Symbol.TSignUpSetedCorpInfo){
				i=6;
			}
			else if(msg.code == Configuration.Symbol.TSignUpSetedLicenceInfo){
				i=7;
			}
			else{
				this.SignUpDialog.message(msg.toString());
				flag = false;
				if(msg.code == Configuration.Symbol.TSignUpSuccess)
					this.bSignUp = true;
			}
			if(flag){
				this.setStep(i);
				this.SignUpDialog.ask();
			}
		};
		
		/** @id show */
		SignUpControl.prototype.show = function(){
			this.setStep(1);
			this.bSignUp = false;
			this.VC.changeImage();
			this.SignUpDialog.ask();
		};
		
		/** @id setVariety */
		SignUpControl.prototype.setVariety = function(){
			var flag = false;
			var sb = new StringBuffer();
			for(var i in this.CheckBox)
				if(this.CheckBox[i].checked){
					if(flag) sb.append("、");
					sb.append(this.CheckBox[i].value);
					flag = true;
				}
			this.Dialog.Step5.Variety.value = sb.toString();
		};
		
		/** @id initialize */
		SignUpControl.prototype.initialize = function(Root){
			this.setStep(1);
			
			uEvent.addBrowserHandler(this.mapping.btnPrevious2, "click", function(){
				Root.VC.changeImage();
				Root.setStep(1);
			});
			uEvent.addBrowserHandler(this.mapping.btnPrevious3, "click", function(){
				Root.setStep(2);
			});
			uEvent.addBrowserHandler(this.mapping.btnPrevious4, "click", function(){
				Root.setStep(3);
			});
			uEvent.addBrowserHandler(this.mapping.btnPrevious5, "click", function(){
				Root.setStep(4);
			});
			uEvent.addBrowserHandler(this.mapping.btnPrevious6, "click", function(){
				Root.setStep(5);
			});
			uEvent.addBrowserHandler(this.mapping.btnPrevious7, "click", function(){
				Root.setStep(6);
			});
			uEvent.addBrowserHandler(this.mapping.btnShow, "click", function(){
				Root.show();
			});
			
			uEvent.addBrowserHandler(this.mapping.btnNext1, "click", function(){
				Root.SignUpDialog.busy("正在验证登录代号...");
				Root.BO.Exist.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnNext2, "click", function(){
				Root.SignUpDialog.busy("正在发送验证邮件...");
				Root.BO.EmailVC.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnReSendVC, "click", function(){
				Root.SignUpDialog.busy("正在发送验证邮件...");
				Root.BO.EmailVC.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnNext3, "click", function(){
				Root.SignUpDialog.busy("正在验证...");
				Root.BO.ValidateEmailVC.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnNext4, "click", function(){
				Root.SignUpDialog.busy("正在设置密码...");
				Root.BO.PWD.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnNext5, "click", function(){
				Root.setVariety();
				Root.SignUpDialog.busy("正在设置公司信息...");
				Root.BO.CorpInfo.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnNext6, "click", function(){
				Root.SignUpDialog.busy("正在设置注册信息...");
				Root.BO.LicenceInfo.execute();
			});
			uEvent.addBrowserHandler(this.mapping.btnSumbit, "click", function(){
				Root.SignUpDialog.busy("提交注册...");
				Root.BO.SignUp.execute();
			});
			
			uEvent.Listener.add(this.BO.Exist, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.Exist, "Exception", function(ex){
				Root.handleException(ex);
				Root.VC.changeImage();
			});
			uEvent.Listener.add(this.BO.EmailVC, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.EmailVC, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.BO.ValidateEmailVC, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.ValidateEmailVC, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.BO.PWD, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.PWD, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.BO.CorpInfo, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.CorpInfo, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.BO.LicenceInfo, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.LicenceInfo, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.BO.SignUp, "Message", function(msg){
				Root.handleMessage(msg);
			});
			uEvent.Listener.add(this.BO.SignUp, "Exception", function(ex){
				Root.handleException(ex);
			});
			uEvent.Listener.add(this.SignUpDialog, "hide", function(){
				if(Root.bSignUp)
					uEvent.Listener.notify(Root, "SignedUp");
			});
		};
	}
	
	this.initialize(this);
}

