﻿window.remoteURL = '/remote.php?action=';
function submitCareersApplicationForm(fFormID) {
	if (checkResumeUpload()) {
		if (checkForm(fFormID) == true) {
			loader('start');
			fArray = jQuery('#' + fFormID).serializeArray();
			fURL = window.remoteURL + 'careers-application-submit';
			jQuery.post(fURL, fArray, function (data) {
				if (data == 'OK') {
					getCareersThankyou();
				} else {
					alert('Sorry, there was an error submitted the form.  Please try again?');
					loader('stop');
				}
			});
		}
	}
}


function uploadResumeComplete(fData) {
	jQuery('#upload-sid').val(fData);
	if (fData != 'ERROR') {
		jQuery('#upload-sid').val(fData);
		jQuery('#upload-status').html('Your resume has been uploaded.');
		jQuery('#upload-container').fadeOut(300);
	} else {
		alert('Sorry, there was an error uploading.  Please try again.\n\nPossible Causes:\n  - Wrong file type...\n  - Error in transmission...');
	}
	return true;
}

function loader(fAction) {
	switch (fAction) {
		case 'start':
			jQuery('#loader').fadeIn(500);
			break;
		case 'stop':
			jQuery('#loader').fadeOut(500);
			break;
	}
}

function getCareersThankyou(fDomID) {
	location.href = '/careers/application-form/thank-you/';

}

function checkForm(fFormID) {
	fStatus = true;
	jQuery('#'+fFormID+' .input-required').each(function () {
		fVal = jQuery(this).val();
		if (fVal == '' || fVal == '0') {
			jQuery(this).addClass('input-warning');
			fStatus = false;
		} else {
			jQuery(this).removeClass('input-warning');
		}
	});

	return fStatus;
}

function checkResumeUpload() {
	fVal = jQuery('#upload-sid').val();
	if (fVal == '') {
		fStatus = false;
		//alert('You forgot to upload your resume!');
	} else {
		fStatus = true;
	}
	return true;
}
