var theForm = "";
function checkForm(myForm, lang) {
	theForm = myForm
	text = "*のついた項目は必須入力項目です。";
	if (lang == 'en') {
		text = "The fields marked with * are compulsory.";
	}
	if (!checkTextValue('realname')) {
		alert(text);
		theForm['realname'].focus()
		return false;
	}
	if (!checkTextValue('firstname')) {
		alert(text);
		theForm['firstname'].focus()
		return false;
	}
	if (!checkMail('email')) {
		alert(text);
		theForm['email'].focus()
		return false;
	}
	if (!checkTextValue('phone')) {
		alert(text);
		theForm['phone'].focus()
		return false;
	}
	if (!checkTextValue('address')) {
		alert(text);
		theForm['address'].focus()
		return false;
	}
	if (!checkSelectValue('age')) {
		alert(text);
		theForm['age'].focus()
		return false;
	}
	if (!checkSelectValue('preferred_of_contact')) {
		alert(text);
		theForm['preferred_of_contact'].focus()
		return false;
	}
	return true;
}

function checkQuickForm(myForm, lang) {
	theForm = myForm
	text = "*のついた項目は必須入力項目です。";
	if (lang == 'en') {
		text = "The fields marked with * are compulsory.";
	}
	if (!checkTextValue('name')) {
		alert(text);
		theForm['name'].focus()
		return false;
	}
	if (!checkMail('email')) {
		alert(text);
		theForm['email'].focus()
		return false;
	}
	if (!checkTextValue('phone')) {
		alert(text);
		theForm['phone'].focus()
		return false;
	}
	if (!checkSelectValue('preferred_of_contact')) {
		alert(text);
		theForm['preferred_of_contact'].focus()
		return false;
	}
	return true;
}

function checkMail(inVar) {
	var x = theForm[inVar].value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) {
		return true;
	} else {
		return false;
	}
}

function checkRadioValue(inVar) {
	var radio_choice = false;
	for (counter = 0; counter < theForm[inVar].length; counter++) {
		if (theForm[inVar][counter].checked) {
			radio_choice = true;
		}
	}
	return radio_choice;
}

function checkSelectValue(inVar, inVar2) {
	if (theForm[inVar].selectedIndex < inVar2) {
		return false;
	}
	return true;
}

function checkTextValue(inVar) {
	if (theForm[inVar].value == "") {
		return false;
	}
	return true;
}

function togglePrefer(my_form, lang) {
	text = "(お電話の場合)ご都合のよい時間帯";
	if (lang == "en") {
		text = "Preferred time";
	}
	if (my_form.preferred_of_contact.selectedIndex == 0) {
		//my_form.preferred_time.disabled = false;
		document.getElementById('preferred_time_text').innerHTML = text;
		document.getElementById('preferred_time_textfield').innerHTML = '<input type="text" name="preferred_time" size="35" />';
	} else {
		//my_form.preferred_time.disabled = true;
		document.getElementById('preferred_time_text').innerHTML = '';
		document.getElementById('preferred_time_textfield').innerHTML = '';
	}
}
