// Believe Technology Consulting, Inc. and Corporate Event Enterprises -FORM HANDLER- //
function flipPaymentOption() {
	if (document.getElementById('Pay_By_Check').checked==true) {
		// get check pymt info
		var http = false;
		if (navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		submitURL = '/employers/registrationForm/payByCheckInfo.asp';
		
		http.open("GET", submitURL, true);
		http.onreadystatechange=function() {
			if(http.readyState == 4) {
				document.getElementById('paymentForm').innerHTML = http.responseText;
				document.getElementById('formMessages').innerHTML = '';
			}
		}
		http.send(null);
	} else {
		// get cc form
		var http = false;
		if (navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		submitURL = '/employers/registrationForm/ccForm.asp';
		
		http.open("GET", submitURL, true);
		http.onreadystatechange=function() {
			if(http.readyState == 4) {
				document.getElementById('paymentForm').innerHTML = http.responseText;
			}
		}
		http.send(null);
	}
}

function submitForm(inputForm,outputDisplay) {
	var formData = '';
	
	// disable submit button to prevent multiple submissions
	document.getElementById('submitBtn').style.disabled = 'disabled';
    
	// clear output display
	outputDisplay.innerHTML = '';
	
	// determine which form to process and:
	// 1) generate form-specific post urls and
	// 2) do form-specific validation
	var submitURL = '';
	switch (inputForm.id) {
		case 'create_employer_profile' :
			if (document.getElementById('Confirm_Password_req').value!=document.getElementById('Employer_Password_req').value) {
				outputDisplay.innerHTML = 'Passwords do not match.  Please confirm that the passwords you entered match exactly.';
				return false;
			}
			submitURL = '/employers/registrationForm/create_employer_profile/save_employer_profile.asp';
			break;
		case 'additional_contacts' :
			submitURL = '/employers/registrationForm/additional_contacts/save_additional_contacts.asp';
			break;
		case 'interview_room_info' :
			submitURL = '/employers/registrationForm/interview_room_info/save_interview_room_info.asp';
			break;
		case 'hospitality_suite_info' :
			submitURL = '/employers/registrationForm/hospitality_suite_info/save_hospitality_suite_info.asp';
			break;
		case 'addl_sleeping_room_info' :
			submitURL = '/employers/registrationForm/addl_sleeping_room_info/save_addl_sleeping_room_info.asp';
			break;
		case 'candidate_requirements' :
			submitURL = '/employers/registrationForm/candidate_requirements/save_candidate_requirements.asp';
			break;
		case 'payment_info' :
			submitURL = '/employers/registrationForm/payment_info/save_payment_info.asp';
			break;
	}
     
	// gather form data for data submission
	for (i=0;i<inputForm.elements.length;i++) {
		// test for form requirements, if field is blank, display alert and stop processing
		if (inputForm.elements[i].id.indexOf('_req')!=-1 && inputForm.elements[i].value=='') {
			outputDisplay.innerHTML = inputForm.elements[i].id.replace('_req', '').replace('_', ' ').replace('_', ' ') + ' is a required field.';
			inputForm.elements[i].focus();
			return false;
		}
	}
	
//	formData = formData.substring(0,formData.length-1);
	inputForm.submit();
}

/* employer registration form functions start */
function confirmEmployerOrder(regID) {
	// disable button to prevent multiple submissions
	document.getElementById('submitBtn').disabled = 'disabled';
	document.getElementById('editOrderBtn').disabled = 'disabled';
	document.getElementById('submitBtn').value = 'Processing...';
	
	var output_area_id = 'formContainer';
	var submitURL = '/employers/registrationForm/confirm.asp';
	document.getElementById('confirmEmployerOrder').action = submitURL;
	document.getElementById('confirmEmployerOrder').submit();
}

function editEmployerRegistration(regId) {
	// disable button to prevent multiple submissions
	if (document.getElementById('editOrderBtn')) {
		document.getElementById('editOrderBtn').disabled='disabled';
		document.getElementById('editOrderBtn').value='Retrieving Data...';
	}
	
	// submit data
	var http = false;
	if (navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	submitURL = '/employers/registrationForm/edit_order.asp?r=' + regId.toString();
	
	http.open("GET", submitURL, true);
	http.onreadystatechange=function() {
		if(http.readyState == 4) {
			document.getElementById('content').innerHTML = http.responseText;
		}
	}
	http.send(null);
}

function updateInterviewRoomSubtotal() {
	if (document.getElementById('Thursday_Interview_Rooms').value=='') {
		document.getElementById('Thursday_Interview_Rooms').value=0;
	}
	if (document.getElementById('Friday_Interview_Rooms').value=='') {
		document.getElementById('Friday_Interview_Rooms').value=0;
	}

	var totalRooms = 0;

	if (document.getElementById('Thursday_Interview_Rooms').value!='') {
		totalRooms = totalRooms + parseInt(document.getElementById('Thursday_Interview_Rooms').value);
	}
	if (document.getElementById('Friday_Interview_Rooms').value!='') {
		totalRooms = totalRooms + parseInt(document.getElementById('Friday_Interview_Rooms').value);
	}

	document.getElementById('Interview_Room_Subtotal').value=(totalRooms * 700.00).toString() + '.00';
	totalEmployerPurchase();
}

function updateAdditionalRoomSubtotal() {
	if (document.getElementById('Extra_Rooms_Wed').value=='') {
		document.getElementById('Extra_Rooms_Wed').value=0;
	}
	if (document.getElementById('Extra_Rooms_Thu').value=='') {
		document.getElementById('Extra_Rooms_Thu').value=0;
	}
	if (document.getElementById('Extra_Rooms_Fri').value=='') {
		document.getElementById('Extra_Rooms_Fri').value=0;
	}

	var totalRooms = 0;

	if (document.getElementById('Extra_Rooms_Wed').value!='') {
		totalRooms = totalRooms + parseInt(document.getElementById('Extra_Rooms_Wed').value);
	}
	if (document.getElementById('Extra_Rooms_Thu').value!='') {
		totalRooms = totalRooms + parseInt(document.getElementById('Extra_Rooms_Thu').value);
	}
	if (document.getElementById('Extra_Rooms_Fri').value!='') {
		totalRooms = totalRooms + parseInt(document.getElementById('Extra_Rooms_Fri').value);
	}

	document.getElementById('Extra_Room_Subtotal').value=(totalRooms * 300.00).toString() + '.00';
	totalEmployerPurchase();
}

function showContactBoxes() {
	var thursdayContacts = document.getElementById('Thursday_Interview_Rooms').value;
	var fridayContacts = document.getElementById('Friday_Interview_Rooms').value;
	var regId = document.getElementById('employerID').value;
	var singleContact = document.getElementById('Is_Only_Contact_req').value;
	
	var formData = 'r=' + regId.toString() + '&f=' + fridayContacts.toString() + '&t=' + thursdayContacts.toString() + '&s=' + singleContact.toString();
	var submitURL = '/admin/employer_interview_contacts.asp';

	// submit data
	var http = false;
	if (navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}

	http.open("POST", submitURL, true);
	http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	http.setRequestHeader('Content-length', formData.length);
	http.setRequestHeader('Connection', 'close');

	http.onreadystatechange=function() {
		if(http.readyState == 4) {
			document.getElementById('office_Contact_Input').innerHTML = http.responseText;
			document.getElementById('office_Contacts_Area').style.display = '';
/*
			if (document.getElementById('Is_Only_Contact_req').value!='') {
				alert(document.getElementById('Is_Only_Contact_req').value);
			}
*/
			if (singleContact.toString()=='Yes') {
				var inputForm = document.getElementById('lawFirmForm');
				for (i=0;i<inputForm.elements.length;i++) {
					// test for form requirements, if field is blank, display alert and stop processing
					if (inputForm.elements[i].id.indexOf('Room_Contact_')!=-1 && inputForm.elements[i].value=='') {
						if ((inputForm.elements[i].id.indexOf('Thursday_Name')!=-1 || inputForm.elements[i].id.indexOf('Friday_Name')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = document.getElementById('Contact_First_Name_req').value + ' ' + document.getElementById('Contact_Last_Name_req').value;
						}
						if ((inputForm.elements[i].id.indexOf('Thursday_Phone')!=-1 || inputForm.elements[i].id.indexOf('Friday_Phone')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = document.getElementById('Phone_Number_req').value;
						}
						if ((inputForm.elements[i].id.indexOf('Thursday_Email')!=-1 || inputForm.elements[i].id.indexOf('_Friday_Email')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = document.getElementById('Contact_Email_Address_req').value;
						}
						if ((inputForm.elements[i].id.indexOf('Thursday_City')!=-1 || inputForm.elements[i].id.indexOf('Friday_City')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = document.getElementById('City_req').value;
						}
						if ((inputForm.elements[i].id.indexOf('Thursday_Day')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = 'Thursday';
						}
						if ((inputForm.elements[i].id.indexOf('Friday_Day')!=-1) && inputForm.elements[i].value=='') {
							inputForm.elements[i].value = 'Friday';
						}
					}
				}
			}
		}
	}
	http.send(formData);
}

function hideContactBoxes() {
	document.getElementById('office_Contact_Input').innerHTML = '';
	document.getElementById('office_Contacts_Area').style.display = 'none';
}

function updateHospitalitySuitesSubtotal() {
	switch (document.getElementById('Hospitality_Suites').value) {
		case 'Thursday' :
			document.getElementById('Hospitality_Suites_Subtotal').value = '700.00';
			break;
		case 'Friday' :
			document.getElementById('Hospitality_Suites_Subtotal').value = '700.00';
			break;
		case 'Both' :
			document.getElementById('Hospitality_Suites_Subtotal').value = '1400.00';
			break;
		default :
			document.getElementById('Hospitality_Suites_Subtotal').value = '0.00';
			break;
	}
	totalEmployerPurchase();
}

function flipAllCredentials() {
	var inputForm = document.getElementById('lawFirmForm');
	if (document.getElementById('Credentials_All').checked==true) {
		for (i=0;i<inputForm.elements.length;i++) {
			// test for form requirements, if field is blank, display alert and stop processing
			if (inputForm.elements[i].id.indexOf('Credentials_Sought_')!=-1) {
				inputForm.elements[i].checked = true;
			} 
		}
	} else {
		for (i=0;i<inputForm.elements.length;i++) {
			// test for form requirements, if field is blank, display alert and stop processing
			if (inputForm.elements[i].id.indexOf('Credentials_Sought_')!=-1) {
				inputForm.elements[i].checked = false;
			}
		}
	}
}

function totalEmployerPurchase() {
	var totalAmount = 0.00;
	totalAmount = parseInt(document.getElementById('Hospitality_Suites_Subtotal').value) + parseInt(document.getElementById('Extra_Room_Subtotal').value) + parseInt(document.getElementById('Interview_Room_Subtotal').value) + parseInt(document.getElementById('Registration_Fee').value);
	document.getElementById('Amount_Total').value = totalAmount.toFixed(2);
}

/* employer registration form functions end */

