/*
 * Borrowed from the AED system
 * This is a add-on for the standard contact form
 * Some form elements are not included here, they will be hidden fields
 */

// Submit button pressed
function send_contact() {
	var gData = '?action=4&index=0';
	var addData = new Array();
	addData[0] = "subject";
	addData[1] = "firstname";
	addData[2] = "lastname";
	addData[3] = "email";
	addData[4] = "phone";
	addData[5] = "mobile";
	addData[6] = "message";	
	
	var postData = '';
	for (i = 0; i < addData.length; i++) {
		postData += '&' + addData[i] + "=";
		x = document.contactForm.elements['edit-'+addData[i]];
		if (!x) continue;	// headings
		if (x.length) {
			// Check for a radio item
			for (cn = 0; cn < x.length; cn++) {
				if (x[cn].checked || x[cn].selected) {
					postData += escape(x[cn].value).replace(/\+/g, '%2B');
					break;
				}
			}
		} else if (x.type == "checkbox") {
			// Checkbox
			postData += x.checked ? '1' : '0';
		} else {
			// Anything else
			postData += escape(x.value).replace(/\+/g, '%2B');
		}
	}
	
	ajaxCall('/contact'+gData, 'contact_callback', postData);
	var btn = document.getElementById('btnSend');
	btn.value = "Sending..";
	btn.disabled = true;
}

// Callback
function contact_callback(txt) {
	if (txt.substr(0, 7) == 'REDIR: ') {
		frmSave();
		window.location = txt.substr(7);
	} else {
		document.getElementById('btnSend').value = "Error Sending";
		alert(txt);
	}
}


