﻿
/// <summary>
/// Use for registration form.
/// </summary>
var RegistrationForm = new Class({

	Implements: [Options, Events],
		options: {
		},
	
	
	/*********************************************BCS Comments*********************************************/	
	/// <name>initialize</name>
	/// <summary>
	/// 1.Register validate of input.
	/// 2.Add Event to elements
	/// </summary>
	/// <param name="ele">current form object</param>
	/*****************************************************************************************************/
	initialize: function(ele){
	
		this.form = ele;
		this.contactImask = null;
		this.exValidator = new fValidator(ele.get('id'), { onValid: this.OnValidCheck.bind(this) });
		this.exValidator.register($("lbOpName"),{type: "lbOpName", re: /.*[^ ].*/, msg: "Please enter your Operating Name." });
		this.exValidator.register($("lbLicenseeNum"), {type: "licenseeNum", re: /^[0-9]{3,6}$/, msg: "Please check your Licensee Number. Your Licensee Number must be a number between 3 to 6 digits." }); 
		this.exValidator.register($("ctl00_LeftContent_dplLicenseeType"), {type: "ctl00_LeftContent_dplLicenseeType", re: /.*[^ ].*/, msg: "Please select your Licensee Type." })
		this.exValidator.register($("lbPhone"), {type:"lbPhone",re: /^[\(]\d{3}[\)][ ]\d{3}[-]\d{4}$/ , msg: "Please enter a Phone Number." });	
		//this.exValidator.register($("lbPhoneWithoutMask"), {type:"lbPhoneWithoutMask",re: /.*[^ ].*/, msg: "Please enter a Phone Number." });	
		this.exValidator.register($("lbPSTNum"),{type: "lbPSTNum", re: /.*[^ ].*/, msg: "Please enter your PST Number." });
		this.exValidator.register($("lbAddress"),{type: "lbAddress", re: /.*[^ ].*/, msg: "Please enter your Address." });
		this.exValidator.register($("lbPostalCode"),{type: "lbPostalCode", re: /^[a-zA-Z][0-9][a-zA-Z][ ]?[0-9][a-zA-Z][0-9]$/, msg: "Please enter a valid Postal Code. " });
		this.exValidator.register($("lbCntFirstName"),{type: "lbCntFirstName", re: /.*[^ ].*/, msg: "Please enter your First Name. " });
		this.exValidator.register($("lbCntLastName"),{type: "lbCntLastName", re: /.*[^ ].*/, msg: "Please enter your Last Name." });
		this.exValidator.register($("lbCntPhone"),{type: "lbCntPhone", re: /^[\(]\d{3}[\)][ ]\d{3}[-]\d{4}$/, msg: "Please enter a Phone Number." });
		//this.exValidator.register($("lbCntPhoneWithoutMask"),{type: "lbCntPhoneWithoutMask", re: /.*[^ ].*/, msg: "Please enter a Phone Number." });
		
		this.exValidator.register($("lbCntEAddress"), {type: "emailAddress",re: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, msg: "Please check your email address. Your email addresses should look like 'myname@yahoo.com'."});
		
		this.exValidator.register($("ctl00_LeftContent_cityDropDownList"),{type: "ctl00_LeftContent_cityDropDownList", re: /.*[^ ].*/, msg: "" });
		this.exValidator.register($("ctl00_LeftContent_countryDropDownList"),{type: "ctl00_LeftContent_countryDropDownList", re: /.*[^ ].*/, msg: "" });
		this.exValidator.register($("ctl00_LeftContent_chainDrop"),{type: "ctl00_LeftContent_chainDrop", re: /.*[^ ].*/, msg: "" });
		this.exValidator.register($("ctl00_LeftContent_provinceDropDownList"),{type: "ctl00_LeftContent_provinceDropDownList", re: /.*[^ ].*/, msg: "" });
		
		document.getElementById("lbOpName").focus();

		$("btnAddContact").addEvent('click', function(e){
		
			new Event(e).stop();
			var divContact = document.getElementById("divContact");
			var tabIndex = divContact.getElementsByTagName("table").length * 3;
			var tbHtml = this.CreateDomHtml(tabIndex);
			divContact.appendChild(tbHtml);
			var time = $time();

			var aryInput = tbHtml.getElementsByTagName("input");
			 
			for(var i = 0 ; i < aryInput.length ; i++)
			{
				
				var item = aryInput[i];
				switch(aryInput[i].id)
				{
					case "lbCntFirstName":
						this.exValidator.register( item, {type: item.id + time, re: /.*[^ ].*/, msg: "Please enter your First Name." } ); 
					break;
					case "lbCntPhone":
						this.exValidator.register(item,{type: item.id + time, re: /^[\(]\d{3}[\)][ ]\d{3}[-]\d{4}$/, msg: "Please enter your telephone."});
					break;
					case "lbCntLastName":
						this.exValidator.register(item,{type: item.id  + time, re: /.*[^ ].*/, msg: "Please enter your Last Name."});
					break;
					case "lbCntEAddress":
						this.exValidator.register(item,{type: item.id  + time, re: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, msg: "Please check your email address. Your email addresses should look like 'myname@yahoo.com'."});
					break;
				}
			}
			//this.contactImask = new iMask();
			if(parseInt($('ctl00_LeftContent_countryDropDownList').get('value')) == 37 || parseInt($('ctl00_LeftContent_countryDropDownList').get('value')) == 235)
			{
				//imaskObj.addRestrict();
				imaskObj.removeRestrict();
				imaskObj = new iMask();
			}
			else
			{
				imaskObj = new iMask();
				imaskObj.removeRestrict();
				//
			}
			//var btnDel = tbHtml.getElement("a");
			var btnDel = new Element('a');
			var btnDels = $$('tbcontact').each(function(element,index){
				
				if(tbHtml == element)
				{
					btnDel = element.getElement('a');
				}
			});
			btnDel.addEvent('click', function(e){
				new Event(e).stop();
				var aryInput = tbHtml.getElements("input");
				for(var i = 0 ; i < aryInput.length ; i++)
				{
					var item = aryInput[i];
					switch(aryInput[i].id)
					{
						case "lbCntFirstName":
							this.exValidator.registerRemove(item); 
						break;
						case "lbCntPhone":
							this.exValidator.registerRemove(item);
						break;
						case "lbCntLastName":
							this.exValidator.registerRemove(item);
						break;
						case "lbCntEAddress":
							this.exValidator.registerRemove(item);
						break;
					}
				}
			
				
				this.DeleteTable(btnDel);
			}.bind(this));
			
		}.bind(this));
		
		this.PostCodeValidation();
		
		$("lbLicenseeNum").addEvent('keydown',function(e){
			var keynum = e.code;
			var blValidate = ((keynum > 36) && (keynum < 41)) || ((keynum > 47) && (keynum < 58)) || ((keynum > 95) && (keynum < 106)) || (keynum == 8) || (keynum==46) || (keynum==110) || (keynum==9) || (keynum==13)
			
			if(window.event)
			{
				if(blValidate)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else // Netscape/Firefox/Opera   
			{   
				if(blValidate)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}.bind(this));
		
		$("lbnClearAll").addEvent('click', function(e){
			new Event(e).stop();
			this.form.reset();
		}.bind(this));
		
		
		/*********************************************BCS Comments*********************************************/
		/// <name>
		/// Descript : Logic of submit button click.
		/// Date	 : May 2nd 2009
		/// Logic	 : If Terms and Condition checked == true
		///				  If form validate == true
		///					 Get form data
		///					 call logicControl
		///			   Else
		///				  Set Term and condition text red
		/// </name>
		/// <summary>
		/// Delete current table
		/// </summary>
		/// <param name="btnCurrent">current table</param>
		/******************************************************************************************************/
		$("lbnMainSubmit").addEvent('click', function(e){
			new Event(e).stop();
			
			var notRepeat = this.LicenseeAndContactRepeat();
			if($('chkTermsCondition').checked == true && notRepeat == true)
			{
			    var blValidate = this.exValidator._onSubmit(e);
			    var blRegister = this.LicenseeNumAndEmailCheck();
			    if(blValidate == true && blRegister == true)
			    {
				    //get the submit data
				    var ary = this.DealQueryString(ele.toQueryString());
				    this.aryParameter = ary;

				    this.LogicControlSubmit();
			    }
			    else
			    {
				    return false;
			    }
			}
			else if($('chkTermsCondition').checked == true && notRepeat == false)
			{
			    return false;
			}
			else
			{
				//Set the Terms and conditions to read.
				var divContainer = $('divConditionTitle');
				var checkBoxTable = divContainer.getElement('table').getNext('table').getElement('td');
				checkBoxTable.setStyle('color','#F00000');
				checkBoxTable.setStyle('font-weight','bold');
				
				return false;
			}
		}.bind(this));
		
		$("lbnNotExistsYes").addEvent('click', function(e){
			new Event(e).stop();
			
			var ary = this.DealQueryString(ele.toQueryString());
			this.aryParameter = ary;
			
			document.getElementById("spRegisterResult").innerHTML = "Once your licensee information is validated, all the users you have just added will receive an email with their account activation.<br/><br/>"
			
			this.SetTheActiveStatus("false");
			this.LogicSubmitResult();
		}.bind(this));
		
		$("lbnNotExistsNo").addEvent('click', function(e){
			new Event(e).stop();
			this.WapDivElement("divLicenseeRegist");
		}.bind(this));
		
		
		$("chkTermsCondition").addEvent('click', function(e){
			//new Event(e).stop();
			var divContainer = $('divConditionTitle');
			var checkBoxTable = divContainer.getElement('table').getNext('table').getElement('td');
			checkBoxTable.setStyle('color','');
			checkBoxTable.setStyle('font-weight','');
		}.bind(this));
		
		$("lbnNotUniqueBack").addEvent('click', function(e){
			new Event(e).stop();
			this.WapDivElement("divLicenseeRegist");
		}.bind(this));
		
		$("lbnNotUniqueOK").addEvent('click', function(e){
			new Event(e).stop();
			
			var ary = this.DealQueryString(ele.toQueryString());
			this.aryParameter = ary;
			
			this.LogicControlNotUniqueSubmit();
		}.bind(this));
		
		$("lbnRegistOk").addEvent('click', function(e){
			new Event(e).stop();
			this.LicenseeRegisterOk();
		}.bind(this));

//		$("btnLicEmailqq").addEvent("click", function(e){
//			new Event(e).stop();
//			encodeURIComponent()
//			
//			var licenseeNum = $('lbLicenseeNum').get('value');
//			var licenseeName = $('lbOpName').get('value');
//			var bodycontent = 'Dear onlineorderdesk.com,%0A%0C%0A%0CI am trying to register on onlineorderdesk using my licensee number ('+licenseeNum+'), but the system tells me that this number has already been registered by someone else. Please contact me to resolve this issue.%0A%0C%0A%0COperating Name:'+licenseeName+' %0A%0C%0A%0C%0A%0C%0A%0CThanks.';
//			window.location.href = "mailto:webmaster@onlineorderdesk.com?subject=" + "Licensee Number Check" + "&body=" +bodycontent;
//		});
		
		$("ctl00_LeftContent_countryDropDownList").addEvent('change', function(e){
			new Event(e).stop();
			var selectCountryEle=	$("ctl00_LeftContent_countryDropDownList");
			this.CountryID = selectCountryEle.get('value');
			var selectCityEle = $("ctl00_LeftContent_cityDropDownList");
			var selectProvinceEle = $("ctl00_LeftContent_provinceDropDownList");
			var reqURL = 'GetCityAndProvinceByCountry.aspx?CountryID='+ this.CountryID;
			var opeReq = new Request.JSON({url: reqURL,
										onComplete:function(Data){
										var num = parseInt(Data.numOfItems);
										selectProvinceEle.options.length=0;
										var stateTdEle = selectProvinceEle.getParent('td').getPrevious('td');
										var selectSentence = 'Select a Province/State';
										if(parseInt(this.CountryID) == 37)
										{
											stateTdEle.set('text','Province:');
											selectSentence= 'Select a Province';
//											this.phoneTypeEnable();
//											this.phoneTypeContactEnable();
											imaskObj.removeRestrict();
											imaskObj.addRestrict();
											this.exValidator._msgInject( $('lbPostalCode'), {type: $('lbPostalCode').id, msg: "" }, true);
											$("lbPostalCode").removeEvents();
											this.exValidator.registerRemove($('lbPostalCode')); 
											this.exValidator.register($("lbPostalCode"),{type: "lbPostalCode", re: /^[a-zA-Z][0-9][a-zA-Z][ ]?[0-9][a-zA-Z][0-9]$/, msg: "Please enter a valid Postal Code. " });
											this.PostCodeValidation();
										
										}
										else if(parseInt(this.CountryID) == 235)
										{
											stateTdEle.set('text','State:');
											selectSentence= 'Select a State';
//											this.phoneTypeEnable();
//											this.phoneTypeContactEnable();
											imaskObj.removeRestrict();
											imaskObj.addRestrict();
											this.exValidator._msgInject( $('lbPostalCode'), {type: $('lbPostalCode').id, msg: "" }, true);
											$("lbPostalCode").removeEvents();
											this.exValidator.registerRemove($('lbPostalCode')); 
											this.exValidator.register($('lbPostalCode'),{type: "lbPostalCode", re: /.*[^ ].*/, msg: "Please enter your Postal Code." });
											this.PostCodeValidation();
//											this.contactImask.removeRestrict();
//											if(this.contactImask != null)
//											{
//												this.contactImask.addRestrict();
//											}
										}
										else 
										{
											stateTdEle.set('text','Province/State:');
//											this.phoneTypeDisable();
//											this.phoneTypeContactDisable();
											//alert(imaskObj+"1111111111111111")
											//imaskObj=null ;
											//alert(imaskObj+"2222222222222")
											imaskObj.removeRestrict();
											
											this.exValidator._msgInject( $('lbPostalCode'), {type: $('lbPostalCode').id, msg: "" }, true);
											$("lbPostalCode").removeEvents();
											this.exValidator.registerRemove($('lbPostalCode')); 
											this.exValidator.register($('lbPostalCode'),{type: "lbPostalCode", re: /.*[^ ].*/, msg: "Please enter your Postal Code." });
											this.PostCodeValidation();
//											if(this.contactImask != null)
//											{
//												this.contactImask.removeRestrict();
//											}
										}
										var defaultobjOption1 = new Option(selectSentence, '0');
										selectProvinceEle.options.add(defaultobjOption1);
										selectCityEle.options.length=0;
										var defaultobjOption2 = new Option('Select a City', '0');
										selectCityEle.options.add(defaultobjOption2);
										var textBoxCity = selectCityEle.getNext('input');
										var textBoxProvince = selectProvinceEle.getNext('input');
										if( num>0 )
										{
											selectProvinceEle.setStyle('display','');
											selectCityEle.setStyle('display','none');
											textBoxCity.setStyle('display','');
											textBoxProvince.setStyle('display','none');
											
											//remove register
											this.exValidator._msgInject( textBoxCity, {type: textBoxCity.id, msg: "" }, true);
											this.exValidator._msgInject( textBoxProvince, {type: textBoxProvince.id, msg: "" }, true);
											this.exValidator.registerRemove(textBoxCity); 
											this.exValidator.registerRemove(textBoxProvince); 
//											this.exValidator.registerRemove(lbPostalCode);
											var i = 0;
											for(;i<num;i++)
											{
												 var objOption = new Option(eval("Data.returnValue" + i),eval("Data.returnIDValue" + i));
												 selectProvinceEle.options.add(objOption);
											}
										}
										else
										{
											selectProvinceEle.setStyle('display','none');
											
											textBoxProvince.setStyle('display','');
											selectCityEle.setStyle('display','none');
											textBoxCity.setStyle('display','');
											
											//register textBoxCity,textBoxProvince input
											this.exValidator.register( textBoxCity, {type: textBoxCity.id, re: /.*[^ ].*/, msg: "Please enter your city." } ); 
											this.exValidator.register( textBoxProvince, {type: textBoxProvince.id, re: /.*[^ ].*/, msg: "Please enter your province." } ); 
										}
										
										
									}.bind(this)
								}).get();
		    
		}.bind(this));
		
		
		$("ctl00_LeftContent_provinceDropDownList").addEvent('change', function(e){
			new Event(e).stop();
			var selectCityEle = $("ctl00_LeftContent_cityDropDownList");
			var selectProvinceEle=	$("ctl00_LeftContent_provinceDropDownList");
			this.ProvinceID = selectProvinceEle.get('value');
			var reqURL = 'GetCityAndProvinceByCountry.aspx?ProvinceID='+ this.ProvinceID ;
			var opeReq = new Request.JSON({url: reqURL,
										onComplete:function(Data){
										var num = parseInt(Data.numOfItems);
										selectCityEle.options.length=0;
										var defaultobjOption = new Option('Select a City', '0');
										selectCityEle.options.add(defaultobjOption);
										var textBoxCity = selectCityEle.getNext('input');
										if( num>0 )
										{	
											selectCityEle.setStyle('display','');
											textBoxCity.setStyle('display','none');
											
											//remove register
											this.exValidator._msgInject( textBoxCity, {type: textBoxCity.id, msg: "" }, true);
											this.exValidator.registerRemove(textBoxCity);
											
											var i = 0;
											for(;i<num;i++)
											{
												 var objOption = new Option(eval("Data.returnValue" + i),eval("Data.returnIDValue" + i));
												 selectCityEle.options.add(objOption);
											}
										}
										else
										{
											selectCityEle.setStyle('display','none');
											textBoxCity.setStyle('display','');
											
											//register textBoxCity input
											this.exValidator.register( textBoxCity, {type: textBoxCity.id, re: /.*[^ ].*/, msg: "Please enter your city." } ); 
										}
										
										
									}.bind(this)
								}).get();
		}.bind(this));
		
		$("ctl00_LeftContent_cityDropDownList").addEvent('blur', function(e){
			new Event(e).stop();
			$("ctl00_LeftContent_provinceDropDownList").setStyle('background-color','#CCFFCC');
			$("ctl00_LeftContent_provinceDropDownList").setStyle('border-color','#00CC00');
			$("ctl00_LeftContent_countryDropDownList").setStyle('background-color','#CCFFCC');
			$("ctl00_LeftContent_countryDropDownList").setStyle('border-color','#00CC00');
		}.bind(this));
		
		$("ctl00_LeftContent_provinceDropDownList").addEvent('blur', function(e){			
		new Event(e).stop();						
		$("ctl00_LeftContent_countryDropDownList").setStyle('background-color','#CCFFCC');			
		$("ctl00_LeftContent_countryDropDownList").setStyle('border-color','#00CC00');		
		}.bind(this));				
		
		$("UploadImg").addEvent('click',function(e){
			new Event(e).stop();
			
			var strFileName = $("ctl00_LeftContent_uploadfile").get('value');
			var strExtend = strFileName.substring(strFileName.lastIndexOf("."));
			var strLower = strExtend.toLowerCase();
			
			if(strFileName == "")
			{
				return false;
			}
			
			if( strLower == ".jpg" || strLower == ".jpeg" || strLower == ".png" || strLower == ".gif")
			{
				var imgUpload = $("imgUpload");
				imgUpload.setAttribute("src","../Images/Uploading.gif");
				
				imgUpload.style.width = '16px';
				imgUpload.style.height = '16px';
				
//				imgUpload.setProperty("width","16px");
//				imgUpload.setProperty("height","16px");
//				imgUpload.setAttribute('width','16px');
//				imgUpload.setAttribute('height','16px');
				imgUpload.setStyle('padding-left','60px');
				
				
				imgUpload.style.display = "";
				$("uploadSpan").style.display = "none";
				
				var form1 = $("aspnetForm");
				form1.action = "RegisterLicensee.aspx?type=saveas";
				form1.submit();

//				var strFrame = document.getElementById('iframe1');
//				window.alert(strFrame.id);
//				strFileName.onload 

				
//				while(true)
//				{
//					
//				}
				
//				while(true)
//				{
//					
//				}

//				setTimeout("var a = 0;",3000);
				
			}
			else
			{
				window.alert("For best results logos should be a JPEG(.jpg) or  PNG (.png) or GIF (.gif) format.");
//				new ConfirmWindow("Invalidate image","For best results logos should be between 2 to 4 megapixels in the JPEG (.jpg) format and less than 2MB in size.", 
//										{
//											ConfirmText: 'Yes',
//											CancelText:'No'
//										});
			}
		}.bind(this));
		
		$("iframe1").addEvent('load', function(e){
			var strFileName = $("ctl00_LeftContent_uploadfile").get('value');
			var fullName = this.LogoNameSet(strFileName);
			var strPath = "../Images/Logos/" + fullName;
			var imgUpload = $("imgUpload");
			imgUpload.setAttribute("src", strPath);
			var notFinished = imgUpload.src.indexOf("Images/Uploading.gif") == -1;
			
			
			imgUpload.style.width = '150px';
			imgUpload.style.height = '120px';
			imgUpload.setStyle('padding-left','0px');
//			imgUpload.setAttribute('width','150px');
//			imgUpload.setAttribute('height','120px');

		}.bind(this));
		
		$("rbChainYes").addEvent('click', function(e){
			$("ctl00_LeftContent_chainDrop").setStyle('display','');
		}.bind(this));
		
		$("rbChainNo").addEvent('click', function(e){
			$("ctl00_LeftContent_chainDrop").setStyle('display','none');
		}.bind(this));
		
//		$("rblPendingYes").addEvent('click', function(e){
//			$('trLicenseeNum').setStyle('display','');
//			this.exValidator.registerRemove($('lbLicenseeNum'));
//			this.exValidator.register($("lbLicenseeNum"), {type: "licenseeNum", re: /^[0-9]{3,8}$/, msg: "Please check your Licensee Number. Your Licensee Number must be a number between 3 to 8 digits." }); 
//			//$('lbLicenseeNum').set('text', '');
//		}.bind(this));
//		
//		$("rblPendingNo").addEvent('click', function(e){
//			$('trLicenseeNum').setStyle('display','none');
//			this.exValidator.registerRemove($('lbLicenseeNum'));
//			//this.exValidator.register($("lbLicenseeNum"), {type: "licenseeNum", re: /^[P][e][n][d][i][n][g]$/, msg: "Please enter Pending." });
//			//$('lbLicenseeNum').set('text', 'Pending');
//		}.bind(this));

		$("chkPending").addEvent('click',function(e){
			if($("chkPending").checked == true)
			{
				this.exValidator._msgInject( $('lbLicenseeNum'), {type: "licenseeNum", msg: "" }, true);
				this.exValidator.registerRemove($('lbLicenseeNum'));
				$('lbLicenseeNum').value = "Pending";
				$('lbLicenseeNum').setAttribute("disabled", true);
				this.exValidator.register($("lbLicenseeNum"), {type: "licenseeNum", re: /^[P][e][n][d][i][n][g]$/, msg: "Please enter Pending." });
				this.exValidator._validate($("lbLicenseeNum"),{type: "licenseeNum", re: /^[P][e][n][d][i][n][g]$/, msg: "Please enter Pending." });
			}
			else
			{
				$('lbLicenseeNum').value = "";
				$('lbLicenseeNum').removeAttribute("disabled");
				this.exValidator.registerRemove($('lbLicenseeNum'));
				this.exValidator.register($("lbLicenseeNum"), {type: "licenseeNum", re: /^[0-9]{3,6}$/, msg: "Please check your Licensee Number. Your Licensee Number must be a number between 3 to 6 digits." }); 
			}
			
		}.bind(this));
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeAndContactRepeat</name>
	/// <date>May 10th 2009<date>
	/// <summary>
	/// Use for judge the contact or licensee number has duplicate
	/// </summary>
	/// <return>true : not repeat ; false : repeat</return>
	/******************************************************************************************************/
	LicenseeAndContactRepeat:function()
	{
		
		//judge the if the contact have same email address
		var aryContact = document.getElementsByName('lbCntEAddress');
		var aryConValue = new Array();
		for(var i = 0 ; i < aryContact.length ; i++)
		{
			aryConValue.include(aryContact[i].value);
		}

		if(aryContact.length == aryConValue.length)
		{
			return true;
		}
		else
		{
			return false;
		}
	},
	
	LogoNameSet:function(strFileName)
	{
		var today = new Date();
		var intYear = today.getUTCFullYear();
		var intMonth = today.getUTCMonth() + 1;
		var intDay = today.getUTCDate();
		
		var newName = strFileName.substring(strFileName.lastIndexOf("\\") + 1);
		var fullName = intMonth + '-' + intDay + '-' + intYear + newName;
		return fullName;
	},
	
	PostCodeValidation : function()
	{
			$("lbPostalCode").addEvent('keydown',function(e){
			$('lbPostalCode').value = $('lbPostalCode').value.toUpperCase();
			}.bind(this));
			
			$("lbPostalCode").addEvent('keyup',function(e){
				$('lbPostalCode').value = $('lbPostalCode').value.toUpperCase();
			}.bind(this));
	},
	
	phoneTypeDisable : function()
	{
			$('lbFax').setStyle('display','none');
			$('lbFaxWithoutMask').setStyle('display','');
			$('lbPhone').setStyle('display','none');
			$('lbPhoneWithoutMask').setStyle('display','');
			$('lbTollFree').setStyle('display','none');
			$('lbTollFreeWithoutMask').setStyle('display','');	
	
	},
	
	phoneTypeEnable : function()
	{
			$('lbFax').setStyle('display','');
			$('lbFaxWithoutMask').setStyle('display','none');
			$('lbPhone').setStyle('display','');
			$('lbPhoneWithoutMask').setStyle('display','none');
			$('lbTollFree').setStyle('display','');
			$('lbTollFreeWithoutMask').setStyle('display','none');	
	
	},
	
	phoneTypeContactDisable : function()
	{
		var phones = document.getElementsByName("lbCntPhone");
		for (var i=0;i<phones.length;i++)
			{
				phones[i].setStyle('display','none');
				phones[i].getNext('input').setStyle('display','');
				this.exValidator.register(phones[i].getNext('input'),{type: phones[i].getNext('input').get('text'), re: /.*[^ ].*/, msg: "Please enter a Phone Number." });
			}
			
		var Faxes = document.getElementsByName("lbCntFax");
		for (var i=0;i<Faxes.length;i++)
			{
				Faxes[i].setStyle('display','none');
				Faxes[i].getNext('input').setStyle('display','');
					} 
		var CellPhones = document.getElementsByName("lbCntCellPhone");
		for (var i=0;i<CellPhones.length;i++)
			{
				CellPhones[i].setStyle('display','none');
				CellPhones[i].getNext('input').setStyle('display','');
						} 
	
	},
	
	phoneTypeContactEnable : function()
	{
			var phones = document.getElementsByName("lbCntPhone");
			for (var i=0;i<phones.length;i++)
				{
					phones[i].setStyle('display','');
					phones[i].getNext('input').setStyle('display','none');
				} 
			var Faxes = document.getElementsByName("lbCntFax");
			for (var i=0;i<Faxes.length;i++)
				{
					Faxes[i].setStyle('display','');
					Faxes[i].getNext('input').setStyle('display','none');
				} 
			var CellPhones = document.getElementsByName("lbCntCellPhone");
			for (var i=0;i<phones.length;i++)
				{
					CellPhones[i].setStyle('display','');
					CellPhones[i].getNext('input').setStyle('display','none');
				} 
	
	},
	
	
	
	/*********************************************BCS Comments*********************************************/
	/// <name>DeleteTable</name>
	/// <summary>
	/// Delete current table
	/// </summary>
	/// <param name="btnCurrent">current table</param>
	/******************************************************************************************************/
	DeleteTable:function(btnCurrent){
		var tbCurrent = btnCurrent.parentNode.parentNode.parentNode;
		var divCurrent = tbCurrent.parentNode;
		
        var aryInput = tbCurrent.getElementsByTagName('input');
        var blHasInput = false;
        for(var i = 0 ; i < aryInput.length ; i++)
        {
			if( i==7 || i ==10)
			{
				continue;
			}
			else if(aryInput[i].type == "text" && aryInput[i].value != "" && aryInput[i].value != "(___) ___-____")
			{
				
				
				blHasInput = true;
				break;
			}
        }
        
        if(blHasInput == true )
        {
			new ConfirmWindow("Delete contact","Are you sure you want to delete this contact?", 
										{ConfirmText: 'Yes',
										CancelText:'No',
										onConfirm: function(){
											divCurrent.removeChild(tbCurrent);
										}.bind(this)
								});
        }
        else
        {
			divCurrent.removeChild(tbCurrent);
        }
   },
	
	/*********************************************BCS Comments*********************************************/
	/// <name>CreateDomHtml</name>
	/// <summary>
    /// create contact form table
    /// </summary>
    /// <param name="tabIndex">tabindex value</param>
    /// <returns>one table element</returns>
    /******************************************************************************************************/
   CreateDomHtml:function(tabIndex)
   {
		var oneColumnIndex = (tabIndex + 1).toString();
		var twoColumnIndex = (tabIndex + 2).toString();
		var threeColumnIndex = (tabIndex + 3).toString();

		var tbDom = document.createElement("tbContact");
        var tbContact = '<table width="100%" border="0" id="tbContact"style="BORDER-RIGHT: silver thin solid; PADDING-RIGHT: 1pt; BORDER-TOP: silver thin solid; PADDING-LEFT: 1pt; MARGIN: 1pt; BORDER-LEFT: silver thin solid; PADDING-TOP: 1pt;">';
            tbContact +=    '<tr>';
            tbContact +=        '<td align="right" width="10%">First Name:</td>';
            tbContact +=        '<td width="30%"><input type="text" id="lbCntFirstName" name="lbCntFirstName" tabindex = ' + oneColumnIndex + '/>&nbsp;<span id="Label1" style="color: rgb(255, 51, 0);">*</span></td>';
            tbContact +=        '<td align="right" width="10%">Phone:</td>';
            tbContact +=        '<td width="30%"><input type="text" id="lbCntPhone" name="lbCntPhone"  class="iMask" alt="{type: \'fixed\',mask: \'(999) 999-9999\',stripMask: false}" value="(___) ___-____" tabindex = ' + twoColumnIndex + '/><input type="text" id="lbCntPhoneWithoutMask" name="lbCntPhoneWithoutMask" tabindex = ' + twoColumnIndex + ' value="" style="display:none"/>&nbsp;<span id="Label1" style="color: rgb(255, 51, 0);">*</span></td>';            tbContact +=		'<td rowspan="3" width="20%">'
            tbContact +=			'<table border="0">'
            tbContact +=				'<tr>'
            tbContact +=					'<td>System access rights:</td>'
            tbContact +=				'</tr>'
			tbContact +=				'<tr>'
            tbContact +=					'<td><input id="chkEditCompany" type="checkbox" name="chkEditCompany" tabindex = ' + threeColumnIndex + '/> Edit Company information </td>';
            tbContact +=				'</tr>'
            tbContact +=				'<tr>'
            tbContact +=					'<td><input id="chkMaintainContact" type="checkbox" name="chkMaintainContact" tabindex = ' + threeColumnIndex + '/> Maintain other contacts </td>';
            tbContact +=				'</tr>'
            tbContact +=				'<tr>'
            tbContact +=					'<td><input id="chkPoWinery" type="checkbox" name="chkPoWinery" tabindex = ' + threeColumnIndex + '/> Authorized to send PO to winery </td>';
            tbContact +=				'</tr>'
            tbContact +=			'</table>'
            tbContact +=		'</td>'
            tbContact +=    '</tr>';  
            tbContact +=    '<tr>';
            tbContact +=        '<td align=right>Last Name: </td>';
            tbContact +=        '<td><input type="text" id="lbCntLastName" name="lbCntLastName" tabindex = ' + oneColumnIndex + '"/>&nbsp;<span id="Label1" style="color: rgb(255, 51, 0);">*</span></td>';
            tbContact +=        '<td align=right>Fax:</td>';
            tbContact +=        '<td><input type="text" id="lbCntFax" name="lbCntFax" tabindex = ' + twoColumnIndex + ' class="iMask" alt="{type: \'fixed\',mask: \'(999) 999-9999\',stripMask: false}" value="(___) ___-____" /><input type="text" id="lbCntFaxWithoutMask" name="lbCntFaxWithoutMask" tabindex = ' + twoColumnIndex + ' style="display:none" /></td>';            tbContact +=    '</tr>';
            tbContact +=    '<tr>';
            tbContact +=        '<td align="right">Email address: </td>';
            tbContact +=        '<td><input type="text" id="lbCntEAddress" url="EmailAddressChange.aspx" name="lbCntEAddress" style="width: 198px" tabindex = ' + oneColumnIndex + '/>&nbsp;<span id="Label1" style="color: rgb(255, 51, 0);">*</span></td>';
            tbContact +=        '<td align=right>Cell Phone: </td>';
            tbContact +=        '<td><input type="text" id="lbCntCellPhone" name="lbCntCellPhone" tabindex = ' + twoColumnIndex + ' class="iMask" alt="{type: \'fixed\',mask: \'(999) 999-9999\',stripMask: false}" value="(___) ___-____"/> <input type="text" id="lbCntCellPhoneWithoutMask" name="lbCntCellPhoneWithoutMask" tabindex = ' + twoColumnIndex + ' style="display:none" /></td>';            tbContact +=    '</tr>';
            tbContact +=    '<tr>';
            tbContact +=        '<td align="right" colspan="5"><a id="btnRemove" class="A_DelUser"/>Don\'t Add this User</a>&nbsp;&nbsp;</td>';
            tbContact +=    '</tr>';
            tbContact += '</table>';
        tbDom.innerHTML = tbContact;
        return tbDom;
   },
   
	ConditionCheckConfirm:function(){
		$("chkTermsCondition").checked = true;
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>OnValidCheck</name>
	/// <summary>
    /// logic when pass the validate
    /// </summary>
    /// <param name="field">current element</param>
    /// <param name="options">options</param>
    /*****************************************************************************************************/
	OnValidCheck: function(field, options){
		if(field.id == "lbLicenseeNum")
		{
			this.LicenseeNumRealCheck(field);
		}
		else if(field.id == "lbCntEAddress")
		{
			var addressEles = document.getElementsByName("lbCntEAddress");
			var count = 0;
			for (var i=0;i<addressEles.length;i++)
			{
				if(addressEles[i].value == field.value)
				{
					count = count + 1;
				}
			} 
			if(count > 1)
			{
				this.exValidator._msgInject( field, {type: options.type, msg: "The contact email can't be same as others!" }, true);
				return;
			}
			//judge has the unique entAddress
			//if unique
			//{
			//	this.exValidator._msgInject( ele, {type: strType.toString(), msg: "You can't input a unique emailAddress." }, true);
			//	return;
			//}
			//else
			//{
				this.EmailRealCheck(field,options.type);
			//}
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeNumRealCheck</name>
	/// <summary>
    /// Check the licensee number is registed
    /// </summary>
    /// <param name="ele">licensee number input element</param>
    /*****************************************************************************************************/
	LicenseeNumRealCheck:function(ele){ 
		//Get value from input
		//this.element.get('value');
		//Send AJAX request to Backend
		var jsonRequest = new Request({
			url: ele.getProperty("url") + "?type=1&licenseeNum=" + this.AddLeadingZerosToLicenseeNumber(ele.value) + "&contact=false",
			onComplete: function(responseText){
				this.LicenseeResult(responseText,ele);
			}.bind(this)
		}).get();
		
//		this.exValidator._msgInject( ele, {type: "licenseeNum", msg: "Validating, please wait..." }, true);
	},
	
	
	LicenseeResult:function(responseText,ele){
		if(responseText.toString() == "true")
		{
			var lbLic = ele.nextSibling.nextSibling; 
			this.exValidator._msgInject( ele, {type: "licenseeNum", msg: "This Licensee Number has already been registered on onlineorderdesk.com. <a id='btnLicEmailqq' onclick='javascript: sendEmailBtottun();'>Contact Us for more information.</a> " }, true);
			
			//$("btnLicEmail").style.display = "";
		}
		else if(responseText.toString() == "false")
		{
			var lbLic = ele.nextSibling.nextSibling;
//			this.exValidator._msgInject( ele, {type: "licenseeNum", msg: "" }, true);
			lbLic.style.color = "#FF3300"
			//lbLic.innerHTML = "*";
			$(lbLic.id).set('text','*');
			//$("btnLicEmail").style.display = "none";
		}
		else if(responseText.toString() == "no")
		{
			var lbLic = ele.nextSibling.nextSibling;
//			this.exValidator._msgInject( ele, {type: "licenseeNum", msg: "" }, true);
			lbLic.style.color = "#FF3300"
			//lbLic.innerHTML = "*";
			$(lbLic.id).set('text','*');
			//$("btnLicEmail").style.display = "none";
		}
		else
		{
			//window.alert(responseText);
		}
	},
	
	
	EmailRealCheck:function(ele,strType){ 
		//Get value from input
		//this.element.get('value');
		//Send AJAX request to Backend
		
		var jsonRequest = new Request({
			url: ele.getProperty("url") + "?eAddress=" + ele.value,
			onComplete: function(responseText){
				this.EmailResult(responseText,ele,strType);
			}.bind(this)
		}).get();


		//Show information for checking
		//this.inforEle.set('html','*span>Validating, please wait...</span>');
	},
	
	
	EmailResult:function(responseText,ele,strType){ 
		if(responseText.toString() == "true")
		{
			var lbLic = ele.nextSibling.nextSibling;
			this.exValidator._msgInject( ele, {type: strType.toString(), msg: "This Email Address has been registed." }, true);
		}
		else if(responseText.toString() == "false")
		{
			var lbLic = ele.nextSibling.nextSibling;
			lbLic.style.color = "#FF3300"
			lbLic.innerHTML = "*";
		}
		else if(responseText.toString() == "no")
		{
			var lbLic = ele.nextSibling.nextSibling;
			lbLic.style.color = "#FF3300"
			lbLic.innerHTML = "*";
		}
		else
		{
			//window.alert(responseText)
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>DealQueryString</name>
	/// <summary>
	/// Get all parameter from current from
	/// </summary>
	/// <returns>the parameter array</returns>
	/*****************************************************************************************************/
	DealQueryString:function(strQuery)
	{
		var aryParam = new Array();
	
		var aryQuery = strQuery.split("&");
		aryQuery.each(function(item,index){
			if(item.indexOf("__VIEWSTATE") == -1 && item.indexOf("__EVENTVALIDATION") && item.indexOf("__EVENTTARGET") == -1)
				{
					var nvKeyName = item.split("=");
					if(nvKeyName[0].toString().toLowerCase() == "lbLicenseeNum".toLowerCase())
					{
						var licNum = this.AddLeadingZerosToLicenseeNumber(nvKeyName[1]);
						aryParam.push([ nvKeyName[0].replace("ctl00$LeftContent$","") , licNum ]);
					}
					else
					{
						aryParam.push([ nvKeyName[0].replace("ctl00$LeftContent$","") , nvKeyName[1] ]);
					}
				}
			}.bind(this));	
			
//		BaseOperator.AlertNameValueArray(aryParam);
		return aryParam;
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LogicControlSubmit</name>
	/// <summary>
	/// function : logic control
	/// descript : 
	///		if pending licensee
	///		begin
	///			show the confirm window, information is pending licensee.
	///		end
	///		else
	///		begin
	///			judge the licensee number is exists in government
	///			if exists
	///			begin 
	///				judge the licensee address information is right
	///				if all right
	///					submit the information
	///				else if part right
	///					check the right information by user
	///				else if not right
	///					show the confirm window, information is address not unique.
	///				else
	///					throw a error
	///			end
	///			else
	///			begin
	///				show the confirm window, information is not exists licensee.
	///			end
	///		end
	/// </summary>
	/*****************************************************************************************************/
	LogicControlSubmit:function()
	{
		if($('chkPending').checked == true)
		{
			//Is a pending licensee
			/*
			this.SetTheActiveStatus("false");
			var strHtml = "Are you sure that you want to register as a Pending Licensee? <br>As a Pending Licensee you will not be able to submit POs to a Winery.<br>";
				strHtml = strHtml + "Click 'No' to enter your Licensee Number now.<br><br> Newly issued licensee numbers may take up to 31 days to show in our records<br><br><br>";

			$('spNotExistsLicensee').set('html', strHtml);
			this.WapDivElement("tbLicNotExists");
			*/
			
			this.PendingNotExistsRegister();
		}
		else
		{
			var licNum = this.SearchFromParamter("lbLicenseeNum");
			var blExists = this.LicenseeExistsInGov(licNum);
			if(blExists == "true")
			{
				//get parameter for address information compare
				var licOpName = this.SearchFromParamter("lbOpName");
				var lbAddress = this.SearchFromParamter("lbAddress");
				var lbCity = this.SearchFromParamter("city");
				var dplLicenseeType = this.SearchFromParamter("dplLicenseeType");
				var lbProvince = this.SearchFromParamter("province");
				var lbPostalCode = this.SearchFromParamter("lbPostalCode");
				var lbCountry = this.SearchFromParamter("countryDropDownList");
				
				//compare the address information and return it to array
				var strCompareInfo = this.LicenseeInfoCompare(licNum,licOpName,lbAddress,lbCity,dplLicenseeType,lbProvince,lbPostalCode,lbCountry);
				var aryCompare = this.DealCompareInfo(strCompareInfo);
				var strResult = aryCompare[0][0];
				//work by compare results
				if(strResult == "allright")
				{
					this.SetTheActiveStatus("true");
					document.getElementById("spRegisterResult").innerHTML = "We have sent emails individually with account activation to all the users you just added.<br/><br/>"
					this.LogicSubmitResult();
				}
				else if(strResult == 'partright')
				{
					var blInfoUnique = this.CreateAddressChkOption(aryCompare);
					this.WapDivElement("tbNotUnique");
				}
				else if(strResult == "notright")
				{
					this.SetTheActiveStatus("false");
					$('spNotExistsLicensee').set('html', 'The licensee number you entered '+licNum+' is in our records, but the licensee information is different.<br />Are you sure it is correct?<br><br>Newly updated licensee information may take up to 31 days to show in our records.<br /><br />');
					
					this.WapDivElement("tbLicNotExists");
				}
				else
				{
					throw new Error('A unkonw state when compare the address informations');
				}
			}
			else
			{
				//Is a licensee number that not exists in gov database.
				/*
				this.SetTheActiveStatus("false");
				$('spNotExistsLicensee').set('html', 'The licensee number you entered '+licNum+' is not in our records.<br />Are you sure it is correct?<br><br>Newly issued licensee numbers may take up to 31 days to show in our records<br /><br />');
				
				this.WapDivElement("tbLicNotExists");
				*/
				this.PendingNotExistsRegister();
			}
		}
	},
	
	DealCompareInfo:function(strCompareInfo)
	{
		//stuff result to array
		var aryInfo = strCompareInfo.split("&");
		var aryParam = new Array();
		for(var i = 0 ; i< aryInfo.length ; i++)
		{
			var nvNameKey = aryInfo[i].split("=");
			aryParam.push([ nvNameKey[0],nvNameKey[1] ]);
		}
		return aryParam;
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LogicControlNotUniqueSubmit</name>
	/// <summary>
	/// function : submit modify information
	/// descript : licensee number exists in database , but the licensee information did't unique with the gov database.
	/// </summary>
	/*****************************************************************************************************/
	LogicControlNotUniqueSubmit:function()
	{
//		BaseOperator.AlertNameValueArray(this.aryParameter);
		
		if(document.getElementById("rbUniqueOur").checked == true)
		{
			document.getElementById("spRegisterResult").innerHTML = "We have sent emails individually with account activation to all the users you just added.<br/><br/>"
			this.SetTheActiveStatus("true");
			for(var i = 0 ; i < this.aryParameter.length ; i ++)
			{
				if(this.aryParameter[i][0] == "lbOpName")
				{
					if($("lbOpNameOur") != null )
					{
						var strOpName = $("lbOpNameOur").get('text');
						this.aryParameter[i][1] = strOpName;
					}
				}
				if(this.aryParameter[i][0] == "lbAddress")
				{
					if($("lbAddressOur")  != null )
					{
						var strAddress = $("lbAddressOur").get('text');
						this.aryParameter[i][1] = strAddress;
					}
				}
			}
		}
		else
		{
			document.getElementById("spRegisterResult").innerHTML = "Once your licensee information is validated, all the users you just added will receive an email with account activation.<br/><br/>"
			this.SetTheActiveStatus("false");
			
			for(var i = 0 ; i < this.aryParameter.length ; i++)
			{
				if(this.aryParameter[i][0] == "lbOpName")
				{
					if( $("lbOpNameYou") != null )
					{
						var strOpName = $("lbOpNameYou").get('text');
						this.aryParameter[i][1] = strOpName;
					}
				}
				if(this.aryParameter[i][0] == "lbAddress")
				{
					if( $("lbAddressYou") != null )
					{
						var strAddress = $("lbAddressYou").get('text');
						this.aryParameter[i][1] = strAddress;
					}
				}
			}
		}
		
//		BaseOperator.AlertNameValueArray(this.aryParameter);
		
		this.LogicSubmitResult();
		
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LogicSubmitResult</name>
	/// <summary>
	/// submit success. show the confirm div. else continue to register.
	/// </summary>
	/*****************************************************************************************************/
	LogicSubmitResult:function()
	{
		var blSuccess = this.LicenseeInfoSubmit(this.aryParameter);
		if(blSuccess == "true")
		{
			this.WapDivElement("tbLicConfirm");
		}
		else
		{
			this.WapDivElement("divLicenseeRegist");
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>SearchFromParamter</name>
	/// <summary>
	/// Get the value from current form
	/// </summary>
	/// <param name="strParam">element name</param>
	/*****************************************************************************************************/
	SearchFromParamter:function(strParam)
	{
		//Set the search type of the query string parameter.
		var reType = strParam;
		switch(strParam)
		{
			case "province":
				var objProvince = $("ctl00_LeftContent_provinceDropDownList");
				if(objProvince.style.display == "")
				{
					reType = "provinceDropDownList";
				}
				else
				{
					reType = "textForProvince";
				}
			break;
			case "city":
				var objCity = $("ctl00_LeftContent_cityDropDownList");
				if(objCity.style.display == "")
				{
					reType = "cityDropDownList";
				}
				else
				{
					reType = "textForCity";
				}
			break;
		}
		
		//Search the value from current form
		var strValue = undefined;
		for(var i = 0 ; i < this.aryParameter.length ; i++)
		{
			if(this.aryParameter[i][0].toLowerCase() == reType.toLowerCase())
			{
				strValue = this.aryParameter[i][1];
				break;
			}
		}
		if(strValue == undefined)
		{
			throw new Error("search parameter failed");
		}
		else
		{
			return strValue;
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>AddLeadingZerosToLicenseeNumber</name>
	/// <summary>
	/// Add by BrightCreek - Robin
	/// Add date: Aug 31th 2009
	/// Version: v3.90
	/// Use for: Add leading zeros for licensee number
	/// </summary>
	/// <param name="strParam">licensee number</param>
	/*****************************************************************************************************/
	AddLeadingZerosToLicenseeNumber:function(licNumber)
	{
		if( 0 < licNumber.length && licNumber.length <= 6 )
		{
			var tempLic = "000000";
			return tempLic.substr(0, 6 - licNumber.length) + licNumber;
		}
		else if(6 < licNumber.length && licNumber.length <= 8)
		{
			return licNumber;
		}
		else
		{
			throw new Error('Please check your Licensee Number. Your Licensee Number must be a number between 3 to 8 digits');
		}
	},
	
	PendingNotExistsRegister:function()
	{
		var ary = this.DealQueryString(this.form.toQueryString());
		this.aryParameter = ary;
		
		strInfo = "<br>Once your licensee information is validated, all the users you have just added will receive an email with their account activation.<br/><br/>"
		
		document.getElementById("spRegisterResult").innerHTML = strInfo;
		
		this.SetTheActiveStatus("false");
		this.LogicSubmitResult();
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeExistsInGov</name>
	/// <summary>
	/// Judge the licensee number has been exists in govment database
	/// </summary>
	/// <param name="strParam">element name</param>
	/*****************************************************************************************************/
	LicenseeExistsInGov:function(licNumber)
	{
		var strPage = "LicenseeNumCharge.aspx";
		var aryUrl = new Array();
		aryUrl.push([ ["type"],["2"] ]);
		aryUrl.push([ ["lbLicenseeNum"],[licNumber] ]);
		var cParam = new CombinePageAndParam(strPage,aryUrl);
		var strUrl = cParam.CombineUrl();
		
		var blExists = AjaxServer.TransToAjaxServer(strUrl);
		return blExists.toString();
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeInfoCompare</name>
	/// <summary>
	/// Combine the parameter of licensee information
	/// </summary>
	/// <param name="licNumber">licensee number element name</param>
	/// <param name="opName">opName element name</param>
	/// <param name="address">address element name</param>
	/// <param name="city">address element name</param>
	/// <param name="province">address element name</param>
	/// <param name="postalCode">address element name</param>
	/// <param name="country">address element name</param>
	/// <return>the parameter query string</return>
	/*****************************************************************************************************/
	LicenseeInfoCompare:function(licNumber,opName,address,city,licenseeType,province,postalCode,country)
	{
		var strPage = "LicenseeNumCharge.aspx";
		var aryUrl = new Array();
		aryUrl.push([ "type","3" ]);
		aryUrl.push([ "lbLicenseeNum",licNumber ]);
		aryUrl.push([ "lbOpName",opName ]);
		aryUrl.push([ "lbAddress",address ]);
		aryUrl.push([ "city",city ]);
		aryUrl.push([ "licenseeType", licenseeType ]);
		aryUrl.push([ "province",province ]);
		aryUrl.push([ "lbPostalCode",postalCode ]);
		aryUrl.push([ "lbcountry",country ]);
		
		var cParam = new CombinePageAndParam(strPage,aryUrl);
		
		var strUrl = cParam.CombineUrl();
		var responseText = AjaxServer.TransToAjaxServer(strUrl);
		return responseText;
		
//		var request = new Request({
//				url: strUrl,
//				onComplete: function(responseText){
//					this.LicenseeInfoResult(responseText);
//				}.bind(this)
//			}).get();
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>CreateAddressChkOption</name>
	/// <summary>
	/// Exchange the display of div and create the table
	/// </summary>
	/// <param name="responseText">The result after the licensee information compare</param>
	/// <return>true: information of licensee all right. false : others</return>
	/*****************************************************************************************************/
	CreateAddressChkOption:function(aryInfo)
	{
		aryInfo.shift();
		
		//licensee information not unique that should create cheack table.
		var tbYou = $("tbUniqueYou");
		this.ClearTables(tbYou,"<tr><td align='center' colspan='2'><input id='rbUniqueYou' name='rblUniqueCheck' tabindex='1' value='1' type='radio'>You entered</td></tr>",1);
		
		var tbOur = $("tbUniqueOur");
		this.ClearTables(tbOur,"<tr><td align='center' colspan='2'><input id='rbUniqueOur' name='rblUniqueCheck' checked='checked' tabindex='1' value='2' type='radio'>Our records</td></tr>",2);

		for(var i = 0 ; i < aryInfo.length ; i ++)
		{
			this.LicenseeNotUniqueDomOp(aryInfo[i]);
		}
		
//		document.getElementById("rbUniqueYou").setAttribute('name','rblUniqueCheck');
//		document.getElementById("rbUniqueOur").setAttribute('name','rblUniqueCheck');
//		document.getElementById("rbUniqueOur").setAttribute('checked','checked');
		
//		$("rbUniqueYou").setProperty('name','rblUniqueCheck');
//		$("rbUniqueOur").setProperty('name','rblUniqueCheck');
//		$("rbUniqueOur").setProperty('checked','checked');
	},
	
	ClearTables:function(pNode, strHtml, type)
	{
		if(Browser.Engine.trident)
		{
			if(type == 1)
			{
				var tempTbody = pNode.getElement('tbody');
				if(tempTbody != undefined)
				{
					tempTbody.destroy();
				}

				var tbody = new Element('tbody');

				var trEle = new Element('tr');

				var tdEle = new Element('td');
				tdEle.setProperty('align','center');
				tdEle.setProperty('colspan','2');

				//			var inputEle = new Element('input');
				//			inputEle.setProperty('id','rbUniqueYou');
				//			//inputEle.setProperty('name','rblUniqueCheck');
				//			
				//			inputEle.setProperty('tabindex','1');
				//			inputEle.setProperty('value','1');
				//			inputEle.setProperty('type','radio');

				var inputEle = document.createElement("<input id='rbUniqueYou' name='rblUniqueCheck' type='radio' tabindex='1' value='1'/>");

				var spanEle = new Element('span');
				spanEle.set('text','You entered');

				tdEle.appendChild(inputEle);
				tdEle.appendChild(spanEle);
				trEle.appendChild(tdEle);
				tbody.appendChild(trEle);
				pNode.appendChild(tbody);

			}
			else
			{
				var tempTbody = pNode.getElement('tbody');
				if(tempTbody != undefined)
				{
					tempTbody.destroy();
				}

				var tbody = new Element('tbody');

				var trEle = new Element('tr');

				var tdEle = new Element('td');
				tdEle.setProperty('align','center');
				tdEle.setProperty('colspan','2');

				//			var inputEle = new Element('input');
				//			inputEle.setProperty('id','rbUniqueOur');
				//			//inputEle.setProperty('name','rblUniqueCheck');
				//			inputEle.setProperty('tabindex','1');
				//			inputEle.setProperty('value','2');
				//			inputEle.setProperty('type','radio');


				var inputEle = document.createElement("<input id='rbUniqueOur' name='rblUniqueCheck' type='radio' checked tabindex='1' value='2'/>");

				var spanEle = new Element('span');
				spanEle.set('text','Our records');

				tdEle.appendChild(inputEle);
				tdEle.appendChild(spanEle);
				trEle.appendChild(tdEle);
				tbody.appendChild(trEle);
				pNode.appendChild(tbody);
			}
	  }
		else
		{
			 pNode.set('html', strHtml);
		}
		
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeNotUniqueDomOp</name>
	/// <summary>
	/// create DOM element when licensee information not unique
	/// </summary>
	/// <param name="item"></param>
	/*****************************************************************************************************/
	LicenseeNotUniqueDomOp:function(item)
	{
		switch(item[0])
		{
			case "lbOpNameYou":
				var tbYou = $("tbUniqueYou").getElement('tbody');
				
				var trDom = document.createElement("tr");
					var tdName = document.createElement("td");
					tdName.setAttribute("align","right");
					tdName.appendChild(document.createTextNode("Operating Name:"));

					var tdNameContent = document.createElement("td");
					tdNameContent.setAttribute("align","left");
					var tdNameSpan = document.createElement("span")
					tdNameSpan.setAttribute("id",item[0]);
					tdNameSpan.appendChild(document.createTextNode(item[1]));
					tdNameContent.appendChild(tdNameSpan);

					trDom.appendChild(tdName);
					trDom.appendChild(tdNameContent);

				tbYou.appendChild(trDom);
				
			break;
			case "lbOpNameOur":
				var tbOur = $("tbUniqueOur").getElement('tbody');
				
				var trDom = document.createElement("tr");
					var tdName = document.createElement("td");
					tdName.setAttribute("align","right");
					tdName.appendChild(document.createTextNode("Operating Name:"));
					
					var tdNameContent = document.createElement("td");
					tdNameContent.setAttribute("align","left");
					var tdNameSpan = document.createElement("span")
					tdNameSpan.setAttribute("id",item[0]);
					tdNameSpan.appendChild(document.createTextNode(item[1]));
					tdNameContent.appendChild(tdNameSpan);
					
				trDom.appendChild(tdName);
				trDom.appendChild(tdNameContent);
								
				tbOur.appendChild(trDom);
			break;
			case "lbAddressYou":
				var tbYou = $("tbUniqueYou").getElement('tbody');
				
				var trDom = document.createElement("tr");
					var tdName = document.createElement("td");
					tdName.setAttribute("align","right");
					tdName.appendChild(document.createTextNode("Address:"));
					
					var tdNameContent = document.createElement("td");
					tdNameContent.setAttribute("align","left");
					var tdNameSpan = document.createElement("span")
					tdNameSpan.setAttribute("id",item[0]);
					tdNameSpan.appendChild(document.createTextNode(item[1]));
					tdNameContent.appendChild(tdNameSpan);
					
				trDom.appendChild(tdName);
				trDom.appendChild(tdNameContent);
								
				tbYou.appendChild(trDom);
			break;
			case "lbAddressOur":
			
				var tbOur = $("tbUniqueOur").getElement('tbody');
				
				var trDom = document.createElement("tr");
					var tdName = document.createElement("td");
					tdName.setAttribute("align","right");
					tdName.appendChild(document.createTextNode("Address:"));
					
					var tdNameContent = document.createElement("td");
					tdNameContent.setAttribute("align","left");
					var tdNameSpan = document.createElement("span")
					tdNameSpan.setAttribute("id",item[0]);
					tdNameSpan.appendChild(document.createTextNode(item[1]));
					tdNameContent.appendChild(tdNameSpan);
					
				trDom.appendChild(tdName);
				trDom.appendChild(tdNameContent);

				tbOur.appendChild(trDom);
			break;
		}
	},
	
	
//	ParamterSetWhenCheck:function()
//	{
//		if(document.getElementById("rbUniqueOur").checked == false)
//		{
//			var tdOur = document.getElementById("rbUniqueYou").parentNode;
//			var arySpan = tdOur.getElementsByTagName("span");
//			arySpan.each(function(item,index){
//				this.aryParamter.push(tdOur.nextSibling)
//			});
//		}
//	},

/*********************************************BCS Comments*********************************************/
	/// <name>LicenseeNumAndEmailCheck</name>
	/// <summary>
	/// Add by brightcreek - Robin
    /// Version: v3.90
    /// Use for: Check the licensee number and email address are registed
    /// </summary>
    /// <return> 
	///			 true: licensee number and all email address not registed;
    ///			 false: licensee number or one email address of them been registed 
    /// </return>
    /*****************************************************************************************************/
	LicenseeNumAndEmailCheck:function(){
		var strLicNumber = $("lbLicenseeNum").value;
		strLicNumber = this.AddLeadingZerosToLicenseeNumber(strLicNumber);
		var strEmailAddress = "";
		var aryAddress = document.getElementsByName("lbCntEAddress");
		for(var i = 0; i < aryAddress.length; i++)
		{
			if(i < aryAddress.length - 1)
			{
				strEmailAddress += aryAddress[i].value + ","
			}
			else
			{
				strEmailAddress += aryAddress[i].value
			}
		}
			
		var responseText = AjaxServer.TransToAjaxServer($("lbLicenseeNum").getProperty("url") + "?type=5&licenseeNum=" + strLicNumber + "&eAddress=" + strEmailAddress);
		if(responseText.toString() == "true")
		{
			return true;
		}
		else if(responseText.toString() == "false")
		{
			return false;
		}
		else
		{
			window.alert('failed to real check the licensee number.');
		}
	},
	
	
	LicenseeInfoSubmit:function(aryInfo)
	{
		
		var strPage = "LicenseeNumCharge.aspx";
		var aryUrl = this.DealTheSubmitInfo(aryInfo);
		aryUrl.push(["type","4"]);
		var cParam = new CombinePageAndParam(strPage,aryUrl);
		var strUrl = cParam.CombineUrl();
		
		var responseText = AjaxServer.TransToAjaxServer(strUrl);
		return responseText;
		
//		window.location.replace("../Login.aspx");
//		var strPage = "LicenseeNumCharge.aspx";
//		var aryUrl = aryInfo;
//		aryUrl.push(["type","4"]);
//		var strUrl = CombinePageAndParam.CombineUrl(strPage,aryUrl);
//		
//		var request = new Request({
//				url: strUrl,
//				onComplete: function(responseText){
//					window.alert(responseText);
//				}.bind(this)
//			}).get();
	},
	
	
	/*********************************************BCS Comments*********************************************/
	/// <name>DealTheSubmitInfo</name>
	/// <summary>
	/// Split the parameter to two array.
	/// Array Licensee : licensee information.
	/// Array Contact : contact information.
	/// </summary>
	/// <param name="aryInfo">the form parameter</param>
	/*****************************************************************************************************/
	DealTheSubmitInfo:function(aryInfo)
	{
		try
		{
			var aryLicensee = new Array();
			for(var i = 0 ; i < aryInfo.length ; i++)
			{
				if( !this.IsContactElement(aryInfo[i][0]) )
				{
					aryLicensee.push( [ aryInfo[i][0], aryInfo[i][1] ] );
				}
			}
			
			var strContact = this.CombineContactData();
			
			aryLicensee.push( ["aryContact", strContact] );
			
			return aryLicensee;
		}
		catch(ex)
		{
			throw new Error('A error occur when get the licensee and contact data');
		}
	},
	
	
	/*********************************************BCS Comments*********************************************/
	/// <name>CombineContactData</name>
	/// <summary>
	/// push data to aryContact
	/// </summary>
	/// <param name="aryContactEle">Element name</param>
	/*****************************************************************************************************/
	CombineContactData:function()
	{
		try
		{
			var aryContact = new Array();
			
			var aryFirstName = document.getElementsByName("lbCntFirstName");
			var aryLastName = document.getElementsByName("lbCntLastName");
			var aryAddress = document.getElementsByName("lbCntEAddress");
			var aryPhone = document.getElementsByName("lbCntPhone");
			var aryFax = document.getElementsByName("lbCntFax");
			var aryCellPhone = document.getElementsByName("lbCntCellPhone");
			var aryEditCompany = document.getElementsByName("chkEditCompany");
			var aryMaintainContact = document.getElementsByName("chkMaintainContact"); 
			var aryPoWinery = document.getElementsByName("chkPoWinery"); 
			
			var strInfo = "";
			for(var i = 0 ; i < aryFirstName.length ; i++)
			{
				strInfo = strInfo + aryFirstName[i].value + "|";
				strInfo = strInfo + aryLastName[i].value + "|"; 
				strInfo = strInfo + aryAddress[i].value + "|"; 
				strInfo = strInfo + aryPhone[i].value + "|";
				strInfo = strInfo + aryFax[i].value + "|";
				strInfo = strInfo + aryCellPhone[i].value + "|"; 
				strInfo = strInfo + aryEditCompany[i].checked + "|"; 
				strInfo = strInfo + aryMaintainContact[i].checked + "|"; 
				strInfo = strInfo + aryPoWinery[i].checked;
				strInfo = strInfo + "$";
			}
			var strResult = strInfo.substring(0,strInfo.length - 1 );
			return strResult;
		}
		catch(ex)
		{
			throw new Error('a error accur when get contact informations');
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>SetTheActiveStatus</name>
	/// <summary>
	/// Update the active status
	/// </summary>
	/// <param name="strTrue">true active; false inactive</param>
	/*****************************************************************************************************/
	SetTheActiveStatus:function(strActive)
	{
		var exists = false;
		for(var i = 0 ; i < this.aryParameter.length ; i++)
		{
			if(this.aryParameter[i][0] == "strActive")
			{
				this.aryParameter[i][1] = strActive;
				exists = true;
				break;
			}
		}
		if(exists == false)
		{
			this.aryParameter.push(["strActive",strActive]);
		}
	},
	
	/*********************************************BCS Comments*********************************************/
	/// <name>IsContactElement</name>
	/// <summary>
	/// Judge is a contact element
	/// </summary>
	/// <param name="strEleName">element name</param>
	/// <return>true is a contact element; false licensee element</return>
	/*****************************************************************************************************/
	IsContactElement:function(strEleName)
	{
		var strElementName = "lbCntFirstName,lbCntLastName,lbCntEAddress,lbCntPhone,lbCntFax,lbCntCellPhone,chkEditCompany,chkMaintainContact,chkPoWinery";
		if(strElementName.indexOf(strEleName) != -1)
		{
			return true;
		}
		else
		{
			return false;
		}
	},

	
	LicenseeRegisterOk:function()
	{
		window.location.replace("../Default.aspx");
	},
	
	
//	LicenseeInfoConfirm:function()
//	{
//		var request = new Request({
//				url: this.url + "?eAddress=" + this.element.value,
//				onComplete: function(responseText){
//					this.LicenseeInfoConfirmResult(responseText);
//				}.bind(this)
//			}).get();
//	},
//	
//	LicenseeInfoConfirmResult:function()
//	{
//		if(responseText == "true")
//		{
//			this.WapDivElement("tbLicConfirm");
//		}
//	},
	
	WapDivElement:function(elementName)
	{
		var divLicenseeRegist = document.getElementById("divLicenseeRegist");
		var tbLicNotExists = document.getElementById("tbLicNotExists");
		var tbNotUnique = document.getElementById("tbNotUnique");
		var tbLicConfirm = document.getElementById("tbLicConfirm");
		divLicenseeRegist.style.display = "none";
		tbLicNotExists.style.display = "none";
		tbNotUnique.style.display = "none";
		tbLicConfirm.style.display = "none";
		
		document.getElementById(elementName).style.display = "";
		
	}
})

