window.onload = init;

// Initialize form element properties
function init() {

	var formObj = document.getElementById("jobPostingForm");
	
	if (formObj) {
		// RY add formatting rules here (email, phone, etc.)
		formObj.onsubmit = verifySubmit;
		formObj.contact_Title.optional = true;
		formObj.contact_Address_Line_2.optional = true;
		formObj.contact_Zip.validate = "us_or_can_zipcode";
		formObj.contact_Phone.validate = "phone_number";
		formObj.contact_Fax.optional = true;
		formObj.contact_Fax.validate = "phone_number";
		formObj.contact_Email.validate = "email";
		formObj.billing_Organization.optional = true;
		formObj.billing_Name.optional = true;
		formObj.billing_Title.optional = true;
		formObj.billing_Address_Line_1.optional = true;
		formObj.billing_Address_Line_2.optional = true;
		formObj.billing_City.optional = true;
		formObj.billing_State.optional = true;
		formObj.billing_Zip.optional = true;
		formObj.billing_Zip.validate = "us_or_can_zipcode";
		formObj.billing_Phone.optional = true;
		formObj.billing_Phone.validate = "phone_number";
		formObj.billing_Fax.optional = true;
		formObj.billing_Fax.validate = "phone_number";
		formObj.billing_Email.optional = true;
		formObj.billing_Email.validate = "email";
	}
	
  	return true;
}

function bypassValidation() {
	
	// The onsubmit handler gets reset when the page reloads
    document.getElementById("jobPostingForm").onsubmit = '';

}

// Action to take when user clicks on "Remove this posting" button
function removePosting() {
	
	// Confirm removal
	if (!confirm("Are you sure you want to remove this posting? All information related to this posting will be lost.")) {
		return false;
	}
	
	// Decrement form's posting_Count
	document.getElementById("jobPostingForm").posting_Count.value -= 1;
	bypassValidation();
	return true;
}