// Javascript include
// Author: Gavin Tooley 
// Last Mod: 2005-04-06 

function checkSampData() {
	theCountry = document.Samples.sampleCountry[document.Samples.sampleCountry.selectedIndex].value;
  if (theCountry.length == 0) {
    alert("Please select your Country");
    document.Samples.sampleCountry.focus();
    return;
  }
  if (document.Samples.sampleFirstName.value.length == 0) {
    alert("Please enter your first name");
    document.Samples.sampleFirstName.focus();
    return;
	}
  if (document.Samples.sampleSurname.value.length == 0) {
    alert("Please enter your surname");
    document.Samples.sampleSurname.focus();
    return;
  }
  if (document.Samples.sampleAddr1.value.length == 0) {
    alert("Please enter your Address");
    document.Samples.sampleAddr1.focus();
    return;
  }
  if (theCountry == 'NZL') {
		theSuburb = document.Samples.sampleSuburb[document.Samples.sampleSuburb.selectedIndex].value;
	  if (theSuburb.length == 0) {
	    alert("Please select your City or Town");
	    document.Samples.sampleSuburb.focus();
	    return;
	  }
	} else {
	  if (document.Samples.sampleSuburb.value.length == 0) {
	    alert("Please enter your Suburb or Area");
	    document.Samples.sampleSuburb.focus();
	    return;
	  }
	}
  if (theCountry == 'AUS' || theCountry == 'USA' || theCountry == 'CAN' || theCountry == 'NZL') {
		theState = document.Samples.sampleState[document.Samples.sampleState.selectedIndex].value;
	  if (theState.length == 0) {
	    alert("Please select your State");
	    document.Samples.sampleState.focus();
	    return;
	  }
		if (document.Samples.samplePostcode.value.length == 0) {
			alert("Please enter your Postcode");
			document.Samples.samplePostcode.focus();
			return;
  	}
  } else {
	  if (document.Samples.sampleState.value.length == 0) {
	    alert("Please enter your State or County");
	    document.Samples.sampleState.focus();
	    return;
	  }
	}
  // now submit the form if everything checked out OK
  document.Samples.submit();
}

function getObj(id) {
	var obj = false;
	if ( document.getElementById ) {
		obj = document.getElementById(id);
	} else if ( document.all ) {
		obj = document.all[id];
	} else if ( document.layers ) {
		obj = document.layers[id];
	}
	return obj;
}

function resetLabels(OpenAction) {
	if ( OpenAction == 'Redo' ) {
		document.Samples.action = "samples.html?function=redo";
		document.Samples.submit();
	} else {
		var theCountry = document.Samples.sampleCountry[document.Samples.sampleCountry.selectedIndex].value;
		suburbSpan = getObj('idSuburb');
		stateSpan = getObj('idState');
		postcodeSpan = getObj('idPostcode');
		if ( suburbSpan.innerText != undefined ) {
		  if (theCountry == 'AUS') {
				suburbSpan.innerText = "Suburb:";
				stateSpan.innerText = "State:";
				postcodeSpan.innerText = "Postcode:";
		  } else if (theCountry == 'GBR') {
				suburbSpan.innerText = "Town:";
				stateSpan.innerText = "County:";
				postcodeSpan.innerText = "Postcode:";
			} else if (theCountry == 'NZL') {
				suburbSpan.innerText = "City/Town:";
				stateSpan.innerText = "Region:";
				postcodeSpan.innerText = "Postcode:";
			} else if (theCountry == 'CAN') {
				suburbSpan.innerText = "City:";
				stateSpan.innerText = "Province:";
				postcodeSpan.innerText = "Postcode:";
			} else if (theCountry == 'USA') {
				suburbSpan.innerText = "City/Town:";
				stateSpan.innerText = "State:";
				postcodeSpan.innerText = "Zip Code:";
			} else {
				suburbSpan.innerText = "City/Town:";
				stateSpan.innerText = "State/Region:";
				postcodeSpan.innerText = "Zip/Postcode:";
			}
		} else {
			// Also works: innerHTML
		  if (theCountry == 'AUS') {
				suburbSpan.textContent = "Suburb:";
				stateSpan.textContent = "State:";
				postcodeSpan.textContent = "Postcode:";
		  } else if (theCountry == 'GBR') {
				suburbSpan.textContent = "Town:";
				stateSpan.textContent = "County:";
				postcodeSpan.textContent = "Postcode:";
			} else if (theCountry == 'NZL') {
				suburbSpan.textContent = "City/Town:";
				stateSpan.textContent = "Region:";
				postcodeSpan.textContent = "Postcode:";
			} else if (theCountry == 'CAN') {
				suburbSpan.textContent = "City:";
				stateSpan.textContent = "Province:";
				postcodeSpan.textContent = "Postcode:";
			} else if (theCountry == 'USA') {
				suburbSpan.textContent = "City/Town:";
				stateSpan.textContent = "State:";
				postcodeSpan.textContent = "Zip Code:";
			} else {
				suburbSpan.textContent = "City/Town:";
				stateSpan.textContent = "State/Region:";
				postcodeSpan.textContent = "Zip/Postcode:";
			}
		}
	}
}
