// ############################################################################
// ##
// ##  STORIES MODULE FUNCTIONS
// ##
// ############################################################################

function SetCountry(strCountry) {
	//alert('Setting country');
	
	if (strCountry) {
		document.getElementById(gstrCountryField).value = strCountry;
	} else {
		document.getElementById(gstrCountryField).value = 'Australia';
	}
	gstrSelectedCountry = document.getElementById(gstrCountryField).value;
	
	SetState(strCountry);

}

function SetState(strCountry) {
	//alert('Setting state');
	//alert(strCountry);
	
	switch (strCountry) {
		case "Australia" :
			//alert('aus');
			strHTML = GetSelectFieldHTML(gstrStateField,'Australian Capital Territory=ACT,New South Wales=NSW,Northern Territory=NT,Queensland=QLD,South Australia=SA,Tasmania=TAS,Victoria=VIC,Western Australia=WA',gstrSelectedState);
			break;
		default :
			//alert('default');
			strHTML = '<input type="text" name="' + gstrStateField + '" id="' + gstrStateField + '" value="' + gstrSelectedState + '" />';
			//break;
	}
	
	SetElementInnerHTML(gstrStateField+'Container',strHTML);
	document.getElementById(gstrStateField).value = gstrSelectedState;
	
	return true;
}

function GetSelectFieldHTML(strFieldID,strOptions,strSelectedOption,strOnchange) {
	arrOptions = strOptions.split(',');
	strHTML = '';
	
	strHTML = '<select name="' + strFieldID + '" id="' + strFieldID + '" onchange="' + strOnchange + '">';
	
	strHTML += '	<option value="">Please select one...</option>';

	if (arrOptions) {
		for (i = 0; i < arrOptions.length; i++) {
			arrThisOption = arrOptions[i].split('=');
			strHTML += '	<option value="' + arrThisOption[1] + '">' + arrThisOption[0] + '</option>';
		}
	}

	strHTML += '</select>';
	//alert(strHTML);
	
	return strHTML;
}

function SetElementInnerHTML(strElementID,strHTML) {
	if (document.getElementById(strElementID)) {
		document.getElementById(strElementID).innerHTML = '';
		document.getElementById(strElementID).innerHTML = strHTML;
	}
}

