/****************************************************
Simple image rollover function. Requires 2 parameters

theImageName = image object name
theFileName = filename of image to rollover/rollout
****************************************************/
function changeImage(theImageName, theFileName) {
	theImageName.src = "images/" + theFileName + ".gif";
}

/****************************************************
Places focus on first textbox or textarea in form.
Will not place focus if forms do not exist
****************************************************/
function formFocus() {
	var theCount;
	var i;

	//alert(document.forms.length);
	//alert(document.forms[0].elements.length);
	if (document.forms.length > 0) {
		theCount = document.forms[0].elements.length;
		if (theCount > 0) {
			if (document.forms[0].elements[0].type == 'text') {
				document.forms[0].elements[0].focus();
			} else {
				for (i = 0; i < theCount; i++) {
					if (document.forms[0].elements[i].type == 'text') {
						document.forms[0].elements[i].focus();
						break;
					}
				}
			}
		}
	} 
}

/****************************************************
Redirection function
****************************************************/
function changeLocation(thePageType) {
	switch (thePageType) {
		case 'js_register':
			window.location.href = 'js_register.asp';
			break;
		
		case 'jsf_pass':
			window.location.href = 'forgot_pwd.asp';
			break;
			
		case 'cancel_reg':
			window.location.href = 'default.asp';
			break;
			
		case 'emp_login':
			window.location.href = 'emp_login.asp';
			break;
		
		case 'js_login':
			window.location.href = 'js_login.asp';
			break;
			
		case 'emp_register':
			window.location.href = 'emp_register.asp';
			break;
		
		case 'empf_pass':
			window.location.href = 'forgot_emp_pwd.asp';
			break;
		
		case 'logout':
			if (confirm("Are you sure you want to log out?")) {
				window.location.href = "do_logout.asp";
			}
			break;
	}
}

/****************************************************
Determine a more user friendly name for any
errors.
****************************************************/
function nameForm(e) {

	var n;
	
	switch (e.name) {
		case "txtFirstName":
			n = "First Name";
			break;
		case "txtLastName":
			n = "Last Name";
			break;
		case "txtAddress1":
			n = "Address";
			break;
		case "txtCity":
			n = "City/Town";
			break;
		case "txtState":
			n = "State/Province";
			break;
		case "txtZip":
			n = "Postal/Zip Code";
			break;
		case "txtEmail1":
			n = "Email Address";
			break;
		case "txtEmail2":
			n = "Confirm Email Address";
			break;
		case "txtUName":
			n = "Username";
			break;
		case "txtCoName":
			n = "Company Name";
			break;
		case "txtName":
			n = "Company Name";
			break;
		case "txtPassword1":
			n = "Password";
			break;
		case "txtPassword2":
			n = "Confirm Password";
			break;
		case "txtAnswer":
			n = "Security Answer";
			break;
		case "lstCountry":
			n = "Country";
			break;
		case "lstDegree":
			n = "Degree Level";
			break;
		case "lstCareer":
			n = "Career Level";
			break;
		case "lstQuestion":
			n = "Security Question";
			break;
		case "txtAnswer1":
			n = "Answer";
			break;
		case "txtPass1":
			n = "New Password";
			break;
		case "txtPass2":
			n = "Retype Password";
			break;
		case "lstAgree":
			n = "Terms of Service Agreement";
			break;
		case "lstSurvey":
			n = "How did you hear about Sourseed.com?";
			break;
		case "txtOther":
			n = "Other";
			break;
		case "lstCitizen":
			n = "Country of Citizenship";
			break;
		case "lstProfile":
			n = "Allow employers to view your profile?";
			break;
		case "txtTitle":
			n = "Job Title";
			break;
		case "lstJobType":
			n = "Job Type";
			break;
		case "lstType":
			n = "Employement Type";
			break;
		case "txtDay":
			n = "Close Date: Day";
			break;
		case "txtYear":
			n = "Close Date: Year";
			break;
		case "txtReq":
			n = "Requirements";
			break;
		case "txtDesc":
			n = "Job Description";
			break;
		case "txtContact":
			n = "Contact Information";
			break;
		case "txtContactPerson":
			n = "Contact Person";
			break;
		case "txtPhone":
			n = "Phone";
			break;
		case "txtFax":
			n = "Fax";
			break;
	}
	return n;	
}

function checkJSEditProfile(theForm) {

	var i;
	var e;
	var msg;
	var theErr = "";
	var intC = theForm.length;
	
	theForm.txtAddress2.optional = true;
	theForm.lstCareer.optional = true;
	theForm.lstCertificate.optional = true;
	
	for (i = 0; i < intC; i++) {
		e = theForm.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} 
		
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} 
	}
		
	for (i = 0; i < intC; i++) {
		e = theForm.elements[i];
		if (e.type == "password") {
			if ((e.value).length < 4) {
				n = nameForm(e);
				e.focus();
				e.select();
				msg = "__________________________________________          \n\n";
				msg += "An error has occurred. The form was not submitted.\n";
				msg += "__________________________________________          \n\n";
				msg += "- This field cannot be less than 4 characters in length.\n";
				msg += "          " + n + "\n\n";
				alert(msg);
				return false;
			}
		}
	}
	
	if (((theForm.txtPassword2.value).toLowerCase() != (theForm.txtPassword1.value).toLowerCase())) {
		theForm.txtPassword2.focus();
		theForm.txtPassword2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your passwords do not match.\n- Please retype your password.\n\n";
		alert(msg);
		return false;
	}
	
	if (((theForm.txtEmail2.value).toLowerCase() != (theForm.txtEmail1.value).toLowerCase())) {
		theForm.txtEmail2.focus();
		theForm.txtEmail2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your emails do not match.\n- Please retype your email.\n\n";
		alert(msg);
		return false;
	}
}


function doRegisterValidate(theForm) {

	var i;
	var e;
	var msg;
	var theErr = "";
	var intC = theForm.length;
	
	theForm.txtAddress2.optional = true;
	theForm.lstCareer.optional = true;
	theForm.lstCertificate.optional = true;
	theForm.txtOther.optional = true;
	
	for (i = 0; i < intC; i++) {
		e = theForm.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} 
		
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} 
	}
	return checkUserInfo(theForm);	
}

function checkUserInfo(f) {
	
	var i;
	var e;
	var n;
	
	for (i = 3; i < 4; i++) {
		e = f.elements[i];
		if ((e.value).length < 4) {
			n = nameForm(e);
			e.focus();
			e.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- This field cannot be less than 4 characters in length.\n";
			msg += "          " + n + "\n\n";
			alert(msg);
			return false;
		}
	}
	if (((f.txtEmail2.value).toLowerCase()) != ((f.txtEmail1.value).toLowerCase())) {
		f.txtEmail2.focus();
		f.txtEmail2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your emails do not match.\n- Please retype your email.\n\n";
		alert(msg);
		return false;
	} else {
		if (((f.txtPassword2.value).toLowerCase()) != ((f.txtPassword1.value).toLowerCase())){
			f.txtPassword2.focus();
			f.txtPassword2.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- Your passwords do not match.\n- Please retype your password.\n\n";
			alert(msg);
			return false;
		}
	}
	
	if (f.lstSurvey.value == "99") {
		if (f.txtOther.value == "") {
			n = nameForm(f.txtOther);
			f.txtOther.focus();
			f.txtOther.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- You have selected \"Other, please specify\".\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + n + "\n\n";
			alert(msg);
			return false;
		}
	}
	
	if ((f.lstAgree.value == "") || (f.lstAgree.value == "N")) {
		f.lstAgree.focus();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- You must agree to the \"Terms of Service\" or you cannot register.\n\n";
		alert(msg);
		return false;
	}
	
}

function checkJobPost(aForm) {
	var i, e;
	var c = aForm.length;
	var msg, theErr;
	
	aForm.lstMonth.optional = true;
	aForm.txtDay.optional = true;
	aForm.txtYear.optional = true;
	
	for (i = 0; i < c; i++) {
		e = aForm.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} 
		
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} 
	}
	
	if (aForm.lstMonth.options[aForm.lstMonth.selectedIndex].value != "") {
		if ((isNaN(aForm.txtDay.value)) || (aForm.txtDay.value == "")) {
			theErr = nameForm(aForm.txtDay);
			aForm.txtDay.focus();
			aForm.txtDay.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following field must be a number.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} else {
			if ((aForm.txtDay.value < 1) || (aForm.txtDay.value > 31)) {
				theErr = nameForm(aForm.txtDay);
				aForm.txtDay.focus();
				aForm.txtDay.select();
				msg = "__________________________________________          \n\n";
				msg += "An error has occurred. The form was not submitted.\n";
				msg += "__________________________________________          \n\n";
				msg += "- The following field cannot be less than 1 or greater than 31.\n";
				msg += "          " + theErr + "\n\n";
				alert(msg);
				return false;
			}
		}
	}
	
	if (aForm.lstMonth.options[aForm.lstMonth.selectedIndex].value != "") {
		if ((isNaN(aForm.txtYear.value)) || (aForm.txtYear.value == "")) {
			theErr = nameForm(aForm.txtYear);
			aForm.txtYear.focus();
			aForm.txtYear.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following field must be a number.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		}
	}
	
	if (aForm.chkConfirm.checked == false) {
		msg = "__________________________________________          \n\n";
		msg += "Confirmation\n";
		msg += "__________________________________________          \n\n";
		msg += "- Please review your listing for errors.\n- Please check the confirmation box when you are\n  complete.\n\n";
		alert(msg);
		return false;
	}
}

function goDel(lID, uID, sType) {
	if (sType == "1A3") {
		if (confirm("Are you sure you want to delete this Listing?\n\nThis is a permanent delete and cannot be recovered.\n")) {
			window.location.href="includes/delete.asp?type=" + sType + "&lid=" + lID  + "&uid=" + uID;
		}
	}
	
	if (sType == "38Z") {
		if (confirm("Are you sure you want to delete this Job?\n\nThis is a permanent delete and cannot be recovered.\n")) {
			window.location.href="includes/delete.asp?type=" + sType + "&lid=" + lID  + "&uid=" + uID;
		}
	}
		
}

function goEdit(aID, sType) {
	if (sType == "1A3") {
		window.location.href="account.asp?view=3&list=2&id=" + aID;
	}
	
	if (sType == "38Z") {
		window.location.href="employer.asp?view=3&a=2&b=" + aID;
	}
}

function goActivate(theID, theType) {
	switch (theType) {
		case 0:
			window.location.href="includes/goactivate.asp?a=" + theID;
			break;
		case 1:
			window.location.href="";
			break;
	}
}

function checkForgotPWD(f) {
	var msg;
	var i;
	var e;
	var msg;
	var theErr = "";
	var intC = f.length;
	
	for (i = 0; i < intC; i++) {
		e = f.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} 
		
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		}
	}
	if (((f.txtPass2.value).toLowerCase()) != ((f.txtPass1.value).toLowerCase())){
		f.txtPass2.focus();
		f.txtPass2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your passwords do not match.\n- Please retype your password.\n\n";
		alert(msg);
		return false;
	}	
}

function searchAll(a) {
	var jLen;
	var eLen;
	var x;
	
	jLen = document.frmSearch.chkJobType.length;
	eLen = document.frmSearch.chkEmpType.length;
	if (a.checked) {
		for (x = 0; x < jLen; x++) {
			document.frmSearch.chkJobType[x].checked = true;
			//document.frmSearch.chkJobType[x].disabled = true;
		}
		for (x = 0; x < eLen; x++) {
			document.frmSearch.chkEmpType[x].checked = true;
			//document.frmSearch.chkEmpType[x].disabled = true;
		}
		document.frmSearch.txtKeyword.value = "";
		document.frmSearch.txtCity.value = "";
		document.frmSearch.selCountry.options[0].selected = true;
		document.frmSearch.txtKeyword.disabled = true;
		document.frmSearch.txtCity.disabled = true;
		document.frmSearch.selCountry.disabled = true;
	} else {
		for (x = 0; x < jLen; x++) {
			//document.frmSearch.chkJobType[x].disabled = false;
			document.frmSearch.chkJobType[x].checked = false;
		}
		for (x = 0; x < eLen; x++) {
			//document.frmSearch.chkEmpType[x].disabled = false;
			document.frmSearch.chkEmpType[x].checked = false;
		}
		document.frmSearch.txtKeyword.disabled = false;
		document.frmSearch.txtCity.disabled = false;
		document.frmSearch.selCountry.disabled = false;
	}
}

function checkAll() {
	var jLen;
	var eLen;
	var totLen
	var x;
	var vCheck = 0;
	
	jLen = document.frmSearch.chkJobType.length;
	eLen = document.frmSearch.chkEmpType.length;
	totLen = (jLen + eLen);
	
	for (x = 0; x < jLen; x++) {
		if (document.frmSearch.chkJobType[x].checked) {
			//alert(x + "-test!")
			vCheck += 1;
		}
	}
	
	for (x = 0; x < eLen; x++) {
		if (document.frmSearch.chkEmpType[x].checked) {
			vCheck += 1;
		}
	}

	if (vCheck == totLen) {
		document.frmSearch.txtKeyword.value = "";
		document.frmSearch.txtCity.value = "";
		document.frmSearch.selCountry.options[0].selected = true;
		document.frmSearch.chkAll.checked = true;
		document.frmSearch.txtKeyword.disabled = true;
		document.frmSearch.txtCity.disabled = true;
		document.frmSearch.selCountry.disabled = true;
	} else {
		document.frmSearch.chkAll.checked = false;
		document.frmSearch.txtKeyword.disabled = false;
		document.frmSearch.txtCity.disabled = false;
		document.frmSearch.selCountry.disabled = false;
	}
}

function viewProfile(id) {
	var features;
	var url;
	
	features = "width=640,height=490,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes";
	url = "emp_viewprof.asp?id=" + id;
	window.open(url,"ViewProf",features);
}

function getResume(id) {
	window.location.href="download.asp?id=" + id;
}

function checkEmpRegister(a) {
	var e;
	var theErr;
	var msg;
	var x = a.length;	
	a.txtCoName.optional = true;
	a.txtFax.optional = true;
	a.txtAddress2.optional = true;
	a.txtOther.optional = true;
	
	for (var i = 0; i < x; i++) {
		e = a.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} else {
			if (e.type == "password") {
				if ((e.value).length < 4) {
					n = nameForm(e);
					e.focus();
					e.select();
					msg = "__________________________________________          \n\n";
					msg += "An error has occurred. The form was not submitted.\n";
					msg += "__________________________________________          \n\n";
					msg += "- This field cannot be less than 4 characters in length.\n";
					msg += "          " + n + "\n\n";
					alert(msg);
					return false;
				}
			}
		}
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} 
	}
	
	if ((a.txtEmail2.value).toLowerCase() != (a.txtEmail1.value).toLowerCase()) {
		a.txtEmail2.focus();
		a.txtEmail2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your emails do not match.\n- Please retype your email.\n\n";
		alert(msg);
		return false;
	}
	
	if ((a.txtPassword2.value).toLowerCase() != (a.txtPassword1.value).toLowerCase()) {
		a.txtPassword2.focus();
		a.txtPassword2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your passwords do not match.\n- Please retype your password.\n\n";
		alert(msg);
		return false;
	}
	
	if (a.lstSurvey.value == "99") {
		if (a.txtOther.value == "") {
			n = nameForm(a.txtOther);
			a.txtOther.focus();
			a.txtOther.select();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- You have selected \"Other, please specify\".\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + n + "\n\n";
			alert(msg);
			return false;
		}
	}
	
	if ((a.lstAgree.value == "") || (a.lstAgree.value == "N")) {
		a.lstAgree.focus();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- You must agree to the \"Terms of Service\" or you cannot register.\n\n";
		alert(msg);
		return false;
	}
}

function checkEmpProfileEdit(a) {
	var e;
	var theErr;
	var msg;
	var x = a.length;	
	a.txtCoName.optional = true;
	a.txtFax.optional = true;
	a.txtAddress2.optional = true;
	
	for (var i = 0; i < x; i++) {
		e = a.elements[i];
		if ((e.value == "") && (!e.optional)) {
			theErr = nameForm(e);
		} else {
			if (e.type == "password") {
				if ((e.value).length < 4) {
					n = nameForm(e);
					e.focus();
					e.select();
					msg = "__________________________________________          \n\n";
					msg += "An error has occurred. The form was not submitted.\n";
					msg += "__________________________________________          \n\n";
					msg += "- This field cannot be less than 4 characters in length.\n";
					msg += "          " + n + "\n\n";
					alert(msg);
					return false;
				}
			}
		}
		if (theErr) {
			e.focus();
			msg = "__________________________________________          \n\n";
			msg += "An error has occurred. The form was not submitted.\n";
			msg += "__________________________________________          \n\n";
			msg += "- The following required field is empty.\n";
			msg += "          " + theErr + "\n\n";
			alert(msg);
			return false;
		} 
	}
	
	if ((a.txtEmail2.value).toLowerCase() != (a.txtEmail1.value).toLowerCase()) {
		a.txtEmail2.focus();
		a.txtEmail2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your emails do not match.\n- Please retype your email.\n\n";
		alert(msg);
		return false;
	}
	
	if ((a.txtPassword2.value).toLowerCase() != (a.txtPassword1.value).toLowerCase()) {
		a.txtPassword2.focus();
		a.txtPassword2.select();
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your passwords do not match.\n- Please retype your password.\n\n";
		alert(msg);
		return false;
	}
}

function checkAppMsg(a) {
	var msg, messlen, x;
	messlen = a.txtMessage.value;
	x = messlen.length;
	if (x > 2000) {
		msg = "__________________________________________          \n\n";
		msg += "An error has occurred. The form was not submitted.\n";
		msg += "__________________________________________          \n\n";
		msg += "- Your message was greater than 2000 characters.\n";
		msg += "- Please shorten your message and try again.\n\n";
		alert(msg);
		return false;
	}
}