function demarcateStates(countryId,defaultStateId,stateObj,setOptionAll)  {

	if (stateObj) {

		for(i=stateObj.length-1;i>=0;i--)  {

			stateObj.options[i]= null;

		}

		if (setOptionAll)  {

			newState = new Option("alle","");
	 		stateObj.options[stateObj.length] = newState;

		}

		for(i=0;i<states.length;i++)  {

			if (states[i][2]==countryId)  {

				selected=false;

				if (states[i][0]==defaultStateId)  {

					selected=true;

				}

				newState = new Option(states[i][1],states[i][0]);
	 			stateObj.options[stateObj.length] = newState;
	 			stateObj.options[stateObj.length-1].selected=selected;

	 		}

		}

	}

}

function demarcateRegions(countryId,regionIdObj,setOptionAll)  {

	for(i=regionIdObj.length-1;i>=0;i--)  {

		regionIdObj.options[i]= null;

	}

	if (setOptionAll)  {

		newRegion = new Option("alle","");
 		regionIdObj.options[0] = newRegion;

	}

	for(i=0;i<regions.length;i++)  {

		selectedOne=false;

		if (regions[i][2]==countryId)  {

			selected=false;

			newRegion = new Option(regions[i][1],regions[i][0]);
 			regionIdObj.options[regionIdObj.length] = newRegion;
 			regionIdObj.options[regionIdObj.length-1].selected=selected;

 			selectedOne=(selected ? true : selectedOne);

 		}

	}

	if (setOptionAll && !selectedOne)  {

		regionIdObj.options[0].selected=true;

	}

}

function changeCountryCode(countryId,countryCodeObjs)  {

	for(i=0;i<countryCodes.length;i++)  {

		if (countryCodes[i][0]==countryId)  {

			for (j in countryCodeObjs)  {

				countryCodeObjs[j].value = countryCodes[i][1];

			}

			break;

		}

	}

}
