/* onload attacher */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// ========================================
function checkSelected(frmSelectObj,frmAction) {

	if (frmAction == "Edit") {
		if (frmSelectObj.selectedIndex == -1) {
			alert("You must select an item from the list first.")
			return false;
		}
	}
	else if (frmAction == "Delete") {
		if (frmSelectObj.selectedIndex == -1) {
			alert("You must select an item from the list first.")
			return false;
		}
		else {
			if (confirm("Are you sure you wish to delete this item?"))
				return true;
			else
				return false;
		}
	}
	else
		return true;
}


// ========================================
function validateRequired() {
	var funcArgs = validateRequired.arguments;
	var alertMsg = "";

	for (i=0; i<funcArgs.length; i++) {
		varTestVal = document.getElementById(funcArgs[i]).value
		if (varTestVal == "") {
			alertMsg += "Please ensure the \"" + funcArgs[i] + "\" field is completed."
		}
	}

	if (alertMsg != "") {
		alert(alertMsg);
		return false;
	}
	else
		return true;
}


// #####################################
function convertCheckboxs(theForm){

	for(i=0; i<theForm.elements.length; i++){
		if(theForm.elements[i].type == "checkbox"){
			elName = theForm.elements[i].name;
			var chkID = "txt_" + elName
			chkBox = document.getElementById(chkID)
			if (chkBox != null) {
				bChecked = theForm.elements[i].checked;
				if (bChecked)
					chkBox.value = "1";
				else
					chkBox.value = "0";
				//alert(chkBox.value)
			}
		}
	}
}


// ############################################
function copyAddress() {

	if (confirm("This will copy the physical address fields into your postal fields. Are you sure?")) {
		document.getElementById('postaladdress').value = document.getElementById('address').value;
		document.getElementById('postalsuburb').value = document.getElementById('suburb').value;
		document.getElementById('postalstateid').value = document.getElementById('stateid').value;
		document.getElementById('postalstatenotaust').value = document.getElementById('statenotaust').value;
		document.getElementById('postalcountryid').value = document.getElementById('countryid').value;
		document.getElementById('postalpostcode').value = document.getElementById('postcode').value;
	}
}


// ############################################
function showOtherField(objField, sOther) {

	if (gebid(objField).value == sOther) {
		if (navigator.appName.indexOf('Microsoft') >= 0) {
			gebid(objField + 'Row').style.display = 'block'; // IE ignore table-row
		}
		else {
			gebid(objField + 'Row').style.display = 'table-row';
		}
	}
	else
		gebid(objField + 'Row').style.display = 'none';
}



function chooseMembership() {
	var bFound = false;
	
		if (document.frmMemType.hdnSlelctedValue.value != "") bFound = true;
	
	if (!bFound) {
		alert("You must select a membership type.")
		return false;
	}
	else return true;
}

// ========================================
function confirmCancel(cancelLoc) {
	if (confirm('Are you sure you want to cancel? Changes will be lost.'))
		document.location.href = cancelLoc;
	else
		return false
}