function isEmpty(textField) {
	if ((textField.length==0) ||(textField==null)) {
		return true;
	} else { 
		return false; 
	}
}

function isCreditCard(cardnumber) {
	var sum = 0; 
	var mul = 1; 
	var l = cardnumber.length;
	var digit;
	var tproduct;
	if (cardnumber.length < 14)  
		return false;
	if (cardnumber.length > 19)
		return false;
	for (i = 0; i < l; i++) {
		digit = cardnumber.substring(l-i-1,l-i);
		tproduct = parseInt(digit ,10)* mul;
		if (tproduct >= 10)
			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	if ((sum % 10) == 0)
		return true;
	else
		return false;
}

function validateDate( strValue ) {
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	// Check to see if in correct format
	if(!objRegExp.test(strValue)) {
		return false; // doesn't match pattern, bad date
	} else {
		for (i=0; i <strValue.length; i++) {
			if ((strValue.charAt(i)>'9') || (strValue.charAt(i)<'0')) {
				break;
			}
		}
		var strSeparator=strValue.charAt(i);
		var arrayDate = strValue.split(strSeparator); //split date into month, day, year
		// Create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,
		                    '03' : 31, 
		                    '04' : 30,
		                    '05' : 31,
		                    '06' : 30,
		                    '07' : 31,
		                    '08' : 31,  
		                    '09' : 30,
		                    '10' : 31,
		                    '11' : 30,
		                    '12' : 31 }
		var intDay = parseInt(arrayDate[1]);
		// Check if month value and day value agree
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
				return true; //found in lookup table, good date
		} else {
			alert("Invalid date" + " | " + arrayDate[0] + " | " + strSeparator);
			return false; 
		}
		// Check for February (bugfix 20050322)
		var intMonth = parseInt(arrayDate[0]);
		if (intMonth == 2) { 
			var intYear = parseInt(arrayDate[2]);
			if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0) {
				return true; //Feb. had valid number of days
			} else {
				alert("Invalid leap date");
				return false;
			}
		}
	}
	return false; //any other values, bad date
}

function validateEmail(strValue) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(strValue);
}

function validatePhone( strValue ) {
	var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
	// Check for valid us phone with or without space between area code
	return objRegExp.test(strValue);
}

function verifyFields()	{
	if (isEmpty(document.formSendMail.company.value)) {
		alert('Error on company field: Please enter your COMPANY here!');
		document.formSendMail.company.focus();
		document.formSendMail.company.select();
		return false;
	}
	if (isEmpty(document.formSendMail.phone.value) ||(document.formSendMail.phone.value == '(include area code)')) {
		alert('Error on phone field: Please enter your PHONE here!');
		document.formSendMail.phone.focus();
		document.formSendMail.phone.select();
		return false;
	}
	if (isEmpty(document.formSendMail.contact.value)) {
		alert('Error on contact person field: Please enter the CONTACT PERSON here!');
		document.formSendMail.contact.focus();
		document.formSendMail.contact.select();
		return false;
	}
	if ((isEmpty(document.formSendMail.submit_by.value)) || (!validateEmail(document.formSendMail.submit_by.value))) {
		alert('Error on email field: Please enter the EMAIL here!');
		document.formSendMail.submit_by.focus();
		document.formSendMail.submit_by.select();
		return false;
	}
	if (isEmpty(document.formSendMail.position.value)) {
		alert('Error on position field: Please enter the POSITION here!');
		document.formSendMail.position.focus();
		document.formSendMail.position.select();
		return false;
	}
	if (isEmpty(document.formSendMail.category.value)) {
		alert('Error on job category field: Please select one JOB CATEGORY below!');
		document.formSendMail.category.focus();
		return false;
	}
	if (isEmpty(document.formSendMail.report.value)) {
		alert('Error on report to field: Please enter the REPORT TO here!');
		document.formSendMail.report.focus();
		document.formSendMail.report.select();
		return false;
	}
	if (!validateDate(document.formSendMail.start_date.value)) {
		alert('Error on start date field: Please enter the START DATE here!');
		document.formSendMail.start_date.focus();
		document.formSendMail.start_date.select();
		return false;
	}
	if (isEmpty(document.formSendMail.duties.value)) {
		alert('Error on duties and requirements field: Please enter the DUTIES AND REQUIREMENTS here!');
		document.formSendMail.duties.focus();
		document.formSendMail.duties.select();
		return false;
	}
	return true;
}
