		function state(name, regionId)
		{
		    this.name = name;
		    this.regionId = regionId;
		}			
		function country(name, regionId, currencyCode)
		{
		    this.name = name;
		    
		    this.regionId = regionId;
		    this.currencyCode = currencyCode;
		  	this.addState = function(name, regionId){
		  		if(!this.states)
		  			this.states = new Object;
		  		this.states[name] = new state(name,regionId);
		  	}
		}
		var countries = new Object;
		var countryIdToName = new Array;

		var onloadCountryValues = new Object;
		onloadCountryValues['state'] = new Object;
		onloadCountryValues['remitToState'] = new Object;
		YAHOO.util.Event.onDOMReady(function() {
			/* If the page was previously submitted and needs corrections or someone pressed refresh, we should save the values: */
			onloadCountryValues.state.countryId = document.getElementById("countryId").value ;
			onloadCountryValues.state.statePriorValue = document.getElementById("statePriorValue").value ;
	
			/* Load the correct states list: */
			var remitTest = document.getElementById("remitToCountryId");  
			updateStateList(document.getElementById('country'));
			
			if(remitTest != null){		
    			onloadCountryValues.remitToState.countryId = document.getElementById("remitToCountryId").value ;
    			onloadCountryValues.remitToState.statePriorValue = document.getElementById("remitToStatePriorValue").value ;		
    			updateStateList(document.getElementById('remitToCountry'));
            }
		});			
		
		function updateStateList(o){
			var country = countries[o.value];
			if(o.id == "country"){
				var prefixName   = "state";
				var countryIdObj = document.getElementById("countryId");				
			} else {
				var prefixName   = "remitToState";
				var countryIdObj = document.getElementById("remitToCountryId");				
			}
			var selectObj    = document.getElementById(prefixName+"Code");
			var textObj      = document.getElementById(prefixName+"Text");
			countryIdObj.value = country.regionId; 
			if(typeof(country.states) == "undefined"){
				selectObj.name = prefixName+"ListDisabled";
				selectObj.style.display="none";
				textObj.name = prefixName;
				/* if(onloadCountryValues[prefixName].countryId == country.regionId || onloadCountryValues[prefixName].countryId == country.name){
					textObj.value = onloadCountryValues[prefixName].statePriorValue;
				} else {
					textObj.value = "";
				}
				*/
				textObj.value = onloadCountryValues[prefixName].statePriorValue;
				textObj.style.display="";
			} else {
				selectObj.name = prefixName;
				selectObj.style.display="";
				textObj.name = prefixName+"TextDisabled";
				textObj.value = "";
				textObj.style.display="none";
				selectObj.innerHTML = "";
				/* Do not use innerHTML for this, it will not work in IE */
				var blankOption = document.createElement("option");
				blankOption.setAttribute("value",'');				
				selectObj.appendChild(blankOption);
				for ( state in country.states){
					var tmpOption = document.createElement("option");
					tmpOption.setAttribute("value",state);
					//if((onloadCountryValues[prefixName].countryId == country.regionId || onloadCountryValues[prefixName].countryId == country.name) && onloadCountryValues[prefixName].statePriorValue == state){					
					if((onloadCountryValues[prefixName].statePriorValue == state)){					
						tmpOption.setAttribute("selected","selected");
					}
					tmpOption.appendChild(document.createTextNode(state));
					selectObj.appendChild(tmpOption);
				}
			}
			if(prefixName == "remitToState" || (document.getElementById('remitToChkbox') != null && document.getElementById('remitToChkbox').checked == true) || document.getElementById('countryUpdateCurrency') != null){
			    if(document.getElementById("currency") != null){
    				currencyOptions = (document.getElementById("currency").getElementsByTagName("option"));
    				for (var i=0; i<currencyOptions.length; i++) {
    					if(currencyOptions[i].value == country.currencyCode){
    						currencyOptions[i].selected = "selected";
    					}
    				}
			    }	
			}
			
			/*var stateLabel = document.getElementById(prefixName+'Label');
			if(country.name == "United States" || country.name == "Canada" ){
				stateLabel.innerHTML="* State/Province";
				f.stateNotRequired.value = false;					
			} else{
				stateLabel.innerHTML="&nbsp;&nbsp;Address 3:";					
				f.stateNotRequired.value = true;					
			}*/
			
		}		

		function updateMandatoryFlag(o, f, l) {
			var label = document.getElementById(l);
			if (o.value == 'United States' || o.value == 'Canada') {
				label.innerHTML = '* State/Province';
				if (l == 'stateLabel') {
					f.stateNotRequired.value = false;
					if (document.getElementById('remitToChkbox') != null && document.getElementById('remitToChkbox').checked == true) {
						f.remitToStateNotRequired.value = false;
						document.getElementById('remitToStateLabel').innerHTML = '* State/Province';
					}
				}
				else {
					f.remitToStateNotRequired.value = false;
				}
			} else {
				label.innerHTML = '&nbsp;&nbsp;Address 3';
				if (l == 'stateLabel') {
					f.stateNotRequired.value = true;
					if (document.getElementById('remitToChkbox') != null && document.getElementById('remitToChkbox').checked == true) {
						f.remitToStateNotRequired.value = true;
						document.getElementById('remitToStateLabel').innerHTML = '&nbsp;&nbsp;Address 3';
					}
				}
				else {
					f.remitToStateNotRequired.value = true;
				}
			}
			if (l == 'stateLabel' && document.getElementById('remitToChkbox') && document.getElementById('remitToChkbox').checked == true) {
		              updateMandatoryFlag(document.getElementById('remitToCountry'), document.getElementById('remitToCity').form, 'remitToStateLabel');
            			try{
            			     document.getElementById('remitToStateCode').selectedIndex = document.getElementById('stateCode').selectedIndex;
            			} catch(err) {
            			     document.getElementById('remitToStateCode').selectedIndex = 0;
            			     document.getElementById('stateCode').selectedIndex = 0;			        
            			}
            			document.getElementById('remitToStateText').value = document.getElementById('stateText').value;
			}
			
			//alert(l+" "+f.stateNotRequired.value+" "+f.remitToStateNotRequired.value);
		}

