function checkID(id) {
	if (!id.value) {
		alert("Please input an ID.");
		id.focus();
		id.select();
		return false;
	}
	if (id.value.length < 4 || id.value.length > 15) {
		alert("An ID must be between 4 and 15 letters.");
		id.focus();
		id.select();
		return false;
	}
	if (checkSpace(id.value)) {
		alert("An ID should not contain an space.");
		id.focus();
		id.select();
		return false;
	}
	if (checkLetter(id.value)) {
		alert("An ID should only consist of English and numeric letters.");
		id.focus();
		id.select();
		return false;
	}
	return true;
}

function checkCode(code) {
	if (!code.value) {
		alert("Please input a code.");
		code.focus();
		code.select();
		return false;
	}
	if (code.value.length < 4 || code.value.length > 15) {
		alert("A code must be between 4 and 15 letters.");
		code.focus();
		code.select();
		return false;
	}
	if (checkSpace(code.value)) {
		alert("A code should not contain an space.");
		code.focus();
		code.select();
		return false;
	}
	if (checkLetter(code.value)) {
		alert("A code should only consist of English and numeric letters.");
		code.focus();
		code.select();
		return false;
	}
	return true;
}

function checkName(name) {
	if (!name.value) {
		alert("Please input a name.");
		name.focus();
		return false;
	}
	return true;
}

function checkPassword(pw, repw) {
	if (!pw.value) {
		alert("Please input a password.");
		pw.focus();
		pw.select();
		return false;
	}
	if (pw.value.length < 4 || pw.value.length > 15) {
		alert("A password must be between 4 and 15 letters.");
		pw.focus();
		pw.select();
		return false;
	}
	if (checkSpace(pw.value)) {
		alert("A password should not contain an space.");
		pw.focus();
		pw.select();
		return false;
	}
	if (checkSpace(repw.value)) {
		alert("A password should not contain an space.");
		repw.focus();
		repw.select();
		return false;
	}
	if (pw.value != repw.value) {
		alert("A password you input does not match.");
		pw.value = repw.value = "";
		pw.focus();
		pw.select();
		return false;
	}
	return true;
}

function checkEmail(email) {
	if (!email.value) {
		alert("Please input an email address.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf(" ") != -1) {
		alert("An email format does not allow an space.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf("+") > -1) {
		alert("An email format does not allow a '+' sign.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf("/") > -1) {
		alert("An email format does not allow a '/' sign.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf(":") > -1) {
		alert("An email format does not allow a ':' sign."); 
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf("@") < 1) {
		alert("An email format should have a '@' sign.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf(".") == -1) {
		alert("An email format should have a '.' sign.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.indexOf(".") - email.value.indexOf("@") == 1) {
		alert("An email format does not allow a '.' sign next to a '@' sign.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.charAt(email.value.length-1) == '.') {
		alert("An email format does not allow a '.' sign at the end of an email address.");
		email.focus();
		email.select();
		return false;
	}
	if (email.value.toLowerCase().match("hanmail.net") || email.value.toLowerCase().match("daum.net")) {
		alert("Please input an email address except that an email address is from 'hanmail.net' or 'daum.net'.");
		email.focus();
		email.select();
		return false;
	}
	return true;
}

function checkPhone(ph1, ph2, ph3) {
	if (!ph1.value || !ph2.value || !ph3.value) {
		alert("Please input a phone number.");
		ph1.focus();
		ph1.select();
		return false;
	}
	if (!checkNumber(ph1.value)) {
		alert("A phone number should only have a numeric letters.");
		ph1.focus();
		ph1.select();
		return false;
	}
	if (!checkNumber(ph2.value)) {
		alert("A phone number should only have a numeric letters.");
		ph2.focus();
		ph2.select();
		return false;
	}
	if (!checkNumber(ph3.value)) {
		alert("A phone number should only have a numeric letters.");
		ph3.focus();
		ph3.select();
		return false;
	}
	return true;
}

function checkMobile(mobile1, mobile2, mobile3) {
	if (!mobile1.value || !mobile2.value || !mobile3.value) {
		alert("Please input a cellular number.");
		mobile1.focus();
		mobile1.select();
		return false;
	}
	if (!checkNumber(mobile1.value)) {
		alert("A cellular number should only have a numeric letters.");
		mobile1.focus();
		mobile1.select();
		return false;
	}
	if (!checkNumber(mobile2.value)) {
		alert("A cellular number should only have a numeric letters.");
		mobile2.focus();
		mobile2.select();
		return false;
	}
	if (!checkNumber(mobile3.value)) {
		alert("A cellular number should only have a numeric letters.");
		mobile3.focus();
		mobile3.select();
		return false;
	}
	return true;
}

function checkFax(fax1, fax2, fax3) {
	if (!fax1.value || !fax2.value || !fax3.value) {
		alert("Please input a fax number.");
		fax1.focus();
		fax1.select();
		return false;
	}
	if (!checkNumber(fax1.value)) {
		alert("A fax number should only have a numeric letters.");
		fax1.focus();
		fax1.select();
		return false;
	}
	if (!checkNumber(fax2.value)) {
		alert("A fax number should only have a numeric letters.");
		fax2.focus();
		fax2.select();
		return false;
	}
	if (!checkNumber(fax3.value)) {
		alert("A fax number should only have a numeric letters.");
		fax3.focus();
		fax3.select();
		return false;
	}
	return true;
}

function checkSSN(ssn1, ssn2) {
	if (!ssn1.value) {
		alert("Please input a SSN number.");
		ssn1.focus();
		ssn1.select();
		return false;
	}
	if (!ssn2.value) {
		alert("Please input a SSN number.");
		ssn2.focus();
		ssn2.select();
		return false;
	}
	if (!checkNumber(ssn1.value)) {
		alert("A SSN number should only have a numeric letters.");
		ssn1.focus();
		ssn1.select();
		return false; 
	}
	if (!checkNumber(ssn2.value)) {
		alert("A SSN number should only have a numeric letters.");
		ssn2.focus();
		ssn2.select();
		return false;
	}
	if (ssn1.value.length > 0 && ssn1.value.length != 6) {
		alert("A SSN number is not correct.");
		ssn1.focus();
		ssn1.select();
		return false;
	}
	if (ssn2.value.length > 0 && ssn2.value.length != 7) {
		alert("A SSN number is not correct.");
		ssn1.focus();
		ssn1.select();
		return false;
	}
	if (ssn1.value.length == 6 && ssn2.value.length == 7) {
		var temp = "" + ssn1.value + ssn2.value;
		if (!checkJuminNumber(temp) && !checkForeignNumber(temp)) {
			alert("A SSN number is not correct.");
			ssn1.focus();
			ssn1.select();
			return false;
		}
	}
	return true;
}

function checkDate(yy, mm, dd) {
	if (!yy.value) {
		alert("Please select a year.");
		yy.focus();
		return false;
	}
	if (!mm.value) {
		alert("Please select a month.");
		mm.focus();
		return false;
	}
	if (!dd.value) {
		alert("Please select a day.");
		dd.focus();
		return false;
	}
	return true;
}

function checkToday(sdate_yy, sdate_mm, sdate_dd) {
	var sdate = sdate_yy.value + "-" + sdate_mm.value + "-" + sdate_dd.value;
	var cur_date, temp = new Date();
	cur_date = temp.getYear();
	if (temp.getMonth() + 1 < 10) cur_date += "-0" + (temp.getMonth() + 1);
	else cur_date += "-" + (temp.getMonth() + 1);
	if (temp.getDate() < 10) cur_date += "-0" + temp.getDate();
	else cur_date += "-" + temp.getDate();
	if (cur_date > sdate) {
		alert("A date you select must be after today.");
		sdate_yy.focus();
		return false;
	}
	return true;
}

function checkAttachment(attach) {
	if (!attach.value) {
		alert("Please select an attached file.");
		attach.focus();
		return false;
	} else {
		if (attach.value.toLowerCase().match("\.exe") || attach.value.toLowerCase().match("\.php") || attach.value.toLowerCase().match("\.cgi") || attach.value.toLowerCase().match("\.htm") || attach.value.toLowerCase().match("\.html")) {
			alert("The file should not be an executable file or a script file.\n\nPlease select an attached file again.");
			attach.focus();
			return false;
		}
	}
	return true;
}

function checkPhoto(attach) {
	if (!attach.value) {
		alert("Please select an image file.");
		attach.focus();
		return false;
	} else {
		if (!(attach.value.toLowerCase().match("\.jpg"))) {
			alert("The file is not proper image format.\n\nOnly JPG files are allowed.");
			attach.focus();
			return false;
		}
	}
	return true;
}

function checkPhotoGIF(attach) {
	if (!attach.value) {
		alert("Please select an image file.");
		attach.focus();
		return false;
	} else {
		if (!(attach.value.toLowerCase().match("\.jpg") || attach.value.toLowerCase().match("\.gif"))) {
			alert("The file is not proper image format.\n\nOnly JPG and GIF files are allowed.");
			attach.focus();
			return false;
		}
	}
	return true;
}

function checkUpload(attach) {
	if (!attach.value) {
		alert("Please select a uploaded file.");
		attach.focus();
		return false;
	} else {
		if (!(attach.value.toLowerCase().match("\.csv"))) {
			alert("The file is not a CSV format.\n\nOnly CSV files are allowed.");
			attach.focus();
			return false;
		}
	}
	return true;
}

function checkResume(attach) {
	if (!attach.value) {
		alert("Please select a resume file.");
		attach.focus();
		return false;
	} else {
		if (!(attach.value.toLowerCase().match("\.doc") || attach.value.toLowerCase().match("\.ppt"))) {
			alert("The file is not proper resume format.\n\nOnly DOC and PPT files are allowed.");
			attach.focus();
			return false;
		}
	}
	return true;
}
