function checkdbform(frm) {
	if(frm.jobname.value=="") {
		alert("You need to enter a jobname.");
		frm.jobname.focus();
		return false;
	}
	return true;
}


// User form Check
function checkuserform(frm) {
	if(frm.fname.value=="") {
		alert("You need to enter a first name.");
		frm.fname.focus();
		return false;
	}
	
	if(frm.lname.value=="") {
		alert("You need to enter a last name.");
		frm.lname.focus();
		return false;
	}
	
	if(frm.newusername.value=="") {
		alert("You need to enter a username.");
		frm.newusername.focus();
		return false;
	}
	
	if(frm.newpassword.value=="") {
		alert("You need to enter a password.");
		frm.newpassword.focus();
		return false;
	}
	
	return true;
}


// Email format check
function emailCheck(frm){
	if(frm.email.value=="" || frm.email.value=="Type Email Address Here") { 
		alert('Please enter your email address');
		frm.email.focus()
	   	frm.email.select()
		return false;
	}

	else {
		var goodEmail = frm.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail) {
		} 
		else {
	   		alert('Your email address isn\'t valid.\nPlease try again.')
	   		frm.email.focus()
	   		frm.email.select()
	   		return false;
	   	}
	}
}


// Client Check Script
function checkclient(frm) {
	if(frm.fname.value=="") {
		alert("You need to enter your first name.");
		frm.fname.focus();
		return false;
	}
	
	if(frm.lname.value=="") {
		alert("You need to enter a last name.");
		frm.lname.focus();
		return false;
	}

	if(frm.address1.value=="") {
		alert("You need to enter your address.");
		frm.address1.focus();
		return false;
	}
	
	if(frm.city.value=="") {
		alert("You need to enter your city.");
		frm.city.focus();
		return false;
	}

	if(frm.state.selectedIndex==0) {
		alert("You need to select your state.");
		frm.state.focus();
		return false;
	}
	
	if(frm.zipcode.value=="") {
		alert("You need to enter your zip/postal code.");
		frm.zipcode.focus();
		return false;
	}
	
	if(frm.country.selectedIndex==0) {
		alert("You need to select your country.");
		frm.country.focus();
		return false;
	}
	
	if(frm.clientemail.value!=frm.confirmemail.value) {
		alert('The email addresses you entered do not match');
		frm.confirmemail.focus();
		frm.confirmemail.select();
		return false;
	}
	
	if(frm.clientemail.value=="") { 
		alert('Please enter your email address');
		frm.clientemail.focus()
		return false;
		}
	else {
		var goodEmail = frm.clientemail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail) {
		} 
		else {
  	 		alert('Your email address isn\'t valid.\nPlease try again.')
   			frm.clientemail.focus()
   			frm.clientemail.select()
   			return false;
   		}
	}
	
	if(frm.prefcontact.selectedIndex==0) {
		alert("You need to select your prefered method of contact.");
		frm.prefcontact.focus();
		return false;
	}
	
	if(frm.company.value=="") {
		alert("You need to enter your current company.");
		frm.company.focus();
		return false;
	}
	
	if(frm.title.selectedIndex==0) {
		alert("You need to select your current title.");
		frm.title.focus();
		return false;
	}
	
	if(frm.jobfunction.selectedIndex==0) {
		alert("You need to select your current job function.");
		frm.jobfunction.focus();
		return false;
	}
	
	if(frm.industry.selectedIndex==0) {
		alert("You need to select your current industry.");
		frm.industry.focus();
		return false;
	}
	
	if(frm.education.selectedIndex==0) {
		alert("You need to select your level of education.");
		frm.education.focus();
		return false;
	}
	
	if(frm.relocate.selectedIndex==0) {
		alert("You need to select your willingness to relocate.");
		frm.relocate.focus();
		return false;
	}
	
	if(frm.language.selectedIndex==0) {
		alert("You need to select your second language.");
		frm.language.focus();
		return false;
	}
	
	return true;
}


//Promote Clients from script 
function promoteform(frm) {
	if(frm.dbID.selectedIndex==0) {
		alert("You need to select a database for these candidates.");
		frm.dbID.focus();
		return false;
	}
	
	if(frm.ownerID.selectedIndex==0) {
		alert("You need to select an owner for these candidates.");
		frm.ownerID.focus();
		return false;
	}
}

// Candidate page check 
function candidateformcheck(frm) {
	if(frm.clientemail.value=="") { 
		alert('Please enter your email address.');
		frm.clientemail.focus()
		return false;
		}
	else {
		var goodEmail = frm.clientemail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail) {
		} 
		else {
  	 		alert('Your email address isn\'t valid.\nPlease try again.')
   			frm.clientemail.focus()
   			frm.clientemail.select()
   			return false;
   		}
	}
	
	if(frm.clientpass.value=="") {
		alert('Please enter your password.');
		frm.clientpass.focus();
		return false;
	}
	
	return true;
}

function checkextention(frm) {
	if((frm.resume.value!="") && (frm.resume.value.lastIndexOf(".doc")==-1) && (frm.resume.value.lastIndexOf(".rtf")==-1)) {
		alert("You can only upload .doc, .rtf, or .txt extention files.");
		return false;
	}
	return true;
}


//Popup Opener
function popthiswin(action,width,height) {
	attributes='width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';

	window.open(action,'mypopup',attributes);
}

// Form Submitter
function formsubmitter(action,popup,width,height) {
	if(popup=="yes") {
		attributes='width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
		var w=window.open('','mypopup',attributes);
		document.getElementById("databasetable").action=action;
		document.getElementById("databasetable").target="mypopup";
		document.getElementById("databasetable").submit();
		document.getElementById("databasetable").reset();
		w.focus();
	}
	else {
		document.getElementById("databasetable").action=action;
		document.getElementById("databasetable").target="_self";
		document.getElementById("databasetable").submit();
		document.getElementById("databasetable").reset();
	}
}

// Confirmed Form Submitter
function confirmsubmit(action,width,height) {
	if (confirm('Are you sure you want to delete this candidate?\nDeletion is a permanent process and cannot be reversed.\n\nPlease make sure you have copied all the pertinent information to the other candidate record before continuing.')) {
		document.getElementById("databasetable").action=action;
		document.getElementById("databasetable").target="_self";
		document.getElementById("databasetable").submit();
		document.getElementById("databasetable").reset();
	}
}

// Text box counter
function textCounter(textfield,counterfield,charlimit) {
	if (textfield.value.length > charlimit) 
	textfield.value = textfield.value.substring(0, charlimit);
	
	else 
	counterfield.value = charlimit - textfield.value.length;
}


// Group Checkbox Change
function switchcheckboxes(frm,listfield) {
	var a=document.getElementById(listfield).value.split(",");
	for (var i=0;i<a.length;i++) {
		document.getElementById(a[i]).checked=frm.checked;
	}
}


function checkDate(frm,month,day,year) {
	var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var myDayStr = document.getElementById(day).value;
	
	//Convert month from number to mmm
	var myMonthStr = document.getElementById(month).value
	var myMonthStr = myMonthStr - 1;
	var myMonthStr = montharray[myMonthStr];
	
	var myYearStr = document.getElementById(year).value;	
	var myDateStr = myMonthStr + ' ' + myDayStr + ', ' + myYearStr;

	/* Using form values, create a new date object which looks like "Wed Jan 1 00:00:00 EST 1975". */
	var myDate = new Date(myDateStr);

	// Convert the date to a string so we can parse it.
	var myDate_string = myDate.toGMTString();

	/* Split the string at every space and put the values into an array so, using the previous example, the first element in the array is "Wed", the second element is "Jan", the third element is "1", etc. */
	var myDate_array = myDate_string.split( ' ' );

/* If we entered "Feb 31, 1975" in the form, the "new Date()" function converts the value to "Mar 3, 1975". Therefore, we compare the month in the array with the month we entered into the form. If they match, then the date is valid, otherwise, the date is NOT valid. */
	if ( myDate_array[2] != myMonthStr ) {
		alert(myDateStr + " is not a valid date.");
		return false;
	} 
} 


// Client Check Script
function checkempclient(frm) {
	if(frm.fname.value=="") {
		alert("You need to enter your first name.");
		frm.fname.focus();
		return false;
	}
	
	if(frm.lname.value=="") {
		alert("You need to enter your last name.");
		frm.lname.focus();
		return false;
	}
	return true;
}


// Quicksearch form check
function checkquicksearch(frm) {
	if(frm.qsfname.value=="" && frm.qslname.value=="" && frm.qscompany.value=="") {
		alert("You need to fill in at least 1 field.");
		return false;
	}
}

// Recent Activity Submitter
function RAformsubmitter(action,popup,width,height) {
	if(popup=="yes") {
		attributes='width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
		var w=window.open('','mypopup',attributes);
		document.getElementById("recentactivity").action=action;
		document.getElementById("recentactivity").target="mypopup";
		document.getElementById("recentactivity").submit();
		document.getElementById("recentactivity").reset();
		w.focus();
	}
	else {
		document.getElementById("recentactivity").action=action;
		document.getElementById("recentactivity").target="_self";
		document.getElementById("recentactivity").submit();
		document.getElementById("recentactivity").reset();
	}
}