function Countries(){this.Add=function(country){var c=new Country();c.Add(country.GetName(),country.GetID(),country.GetStates());this.countries[this.countries.length]=c};this.GetCountry=function(index){if(index<this.countries.length){var country=new Country();country.Add(this.countries[index].GetName(),this.countries[index].GetID(),this.countries[index].GetStates());return country}else return null};this.GetCountryByID=function(id){for(i=0;i<this.countries.length;i++){if(this.countries[i].GetID()==id){var country=new Country();country.Add(this.countries[i].GetName(),this.countries[i].GetID(),this.countries[i].GetStates());return country}}return null};this.Length=function(){return this.countries.length};this.countries=[]}function Country(){this.Add=function(name,id,states){this.id=id;this.name=name;for(i=0;i<states.Length();i++)this.states.Add(states.GetState(i));};this.Destroy=function(){this.id='';this.name='';this.states.Destroy();};this.GetID=function(){return this.id};this.GetName=function(){return this.name};this.GetStates=function(){var states=new States();for(i=0;i<this.states.Length();i++)states.Add(this.states.GetState(i));return states};this.id=new Number();this.name=new String();this.states=new States();}function States(){this.Add=function(state){var s=new State();s.Add(state.GetName(),state.GetID());this.states[this.states.length]=s};this.Destroy=function(){while(this.states.length>0)this.states.pop();};this.GetState=function(index){if(index<this.states.length){var state=new State();state.Add(this.states[index].GetName(),this.states[index].GetID());return state}else return null};this.GetStates=function(){var state=new State();var states=new States();for(i=0;i<this.states.length;i++){state.Add(this.states[i].GetName(),this.states[i].GetID());states.Add(state);}return states};this.Length=function(){return this.states.length};this.states=[]}function State(){this.Add=function(name,id){this.id=id;this.name=name};this.GetID=function(){return this.id};this.GetName=function(){return this.name};this.id=new Number();this.name=new String();}function CountryGetList(elCountries,elStates){var el=document.getElementById(elCountries);var newdiv=document.createElement('select');var txtNode;for(var i=el.childNodes.length-1;i>=0;i-=1)el.removeChild(el.childNodes[i]);newdiv.className='selectwidth';newdiv.setAttribute('name','Bcountry');newdiv.setAttribute('id','CountryID');addEvent(newdiv,'change',function(){StateGetList(this(this.selectedIndex).value,elStates)});el.appendChild(newdiv);childEl=el.firstChild;for(i=0;i<countries.Length();i++){newdiv=document.createElement('option');newdiv.setAttribute('value',countries.GetCountry(i).GetID());txtNode=document.createTextNode(countries.GetCountry(i).GetName());newdiv.appendChild(txtNode);childEl.appendChild(newdiv);}}function StateGetList(countryID,elStates){var elCountryID=document.getElementById('CountryID');var countryID=elCountryID[elCountryID.selectedIndex].value;var el=document.getElementById(elStates);var newdiv=document.createElement('select');for(var i=el.childNodes.length-1;i>=0;i-=1)el.removeChild(el.childNodes[i]);newdiv.className='selectwidth';newdiv.setAttribute('name','Bprovince');newdiv.setAttribute('id','StateID');el.appendChild(newdiv);childEl=el.firstChild;if(countryID>2){newdiv=document.createElement('option');newdiv.setAttribute('value',0);txtNode=document.createTextNode("N/A");newdiv.appendChild(txtNode);childEl.appendChild(newdiv);}country=countries.GetCountryByID(countryID);states=country.GetStates();for(i=0;i<states.Length();i++){newdiv=document.createElement('option');newdiv.setAttribute('value',states.GetState(i).GetID());txtNode=document.createTextNode(states.GetState(i).GetName());newdiv.appendChild(txtNode);childEl.appendChild(newdiv);}}function addEvent(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false);EventCache.add(obj,type,fn);}else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event);};obj.attachEvent("on"+type,obj[type+fn]);EventCache.add(obj,type,fn);}else{obj["on"+type]=obj["e"+type+fn]}}EventCache=function(){var listEvents=[];return{listEvents:listEvents,add:function(node,sEventName,fHandler){listEvents.push(arguments);},flush:function(){var i,item;for(i=listEvents.length-1;i>=0;i-=1){item=listEvents[i];if(item[0].removeEventListener){item[0].removeEventListener(item[1],item[2],item[3]);};if(item[1].substring(0,2)!="on"){item[1]="on"+item[1]};if(item[0].detachEvent){item[0].detachEvent(item[1],item[2]);};item[0][item[1]]=null}}}}();addEvent(window,'unload',EventCache.flush);
