function enquiryboxsubmit(form, lang, submittype){
	if(enquiryboxcheck(form,lang)){
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4)
			{
				if (xmlHttp.status == 200){
					var result=trim(xmlHttp.responseText);
					
					showresult(result.indexOf('ENQUIRYDONE')>=0?1:0,lang,form);
				}
			}
		}
		xmlHttp.open('GET',getURL(form,submittype),true);
		xmlHttp.send(null);
	}
}

function getURL(form,submittype){
	var url='';
	if(submittype=='email')
		url='/formaction/takedetail_email.jsp';
	else
		url='/formaction/takedetail.jsp';
	url+='?name='+encodeURIComponent(form.name.value);
	url+='&tel='+encodeURIComponent(form.tel.value);
	url+='&email='+encodeURIComponent(form.email.value);
	url+='&loc='+form.loc.value;
	url+='&enquirytype='+form.enquirytype.value;
	url+='&sourcetype='+form.sourcetype.value;

	return url;
}

function enquiryboxcheck(form,lang){
	if(trim(form.name.value)==''){
		alert(lang=='chi'?'請輸入姓名':'Please enter your name.');
		return false;
	}
	if(trim(form.tel.value)==''){
		alert(lang=='chi'?'請輸入電話號碼':'Please enter your phone no.');
		return false;
	}
	if(trim(form.email.value)==''){
		alert(lang=='chi'?'請輸入電郵':'Please enter your E-Mail.');
		return false;
	}
	if(form.email.value.indexOf('@')<=0){
		alert(lang=='chi'?'電郵不正確':'Your E-Mail is incorrect.');
		return false;
	}
	
	return true;
}

function showresult(result,lang,form){
	var sourcetype=form.sourcetype.value;
	form.reset();
	location.href='/'+(lang=='eng' && sourcetype!='TIMETABLE'?'exp':sourcetype=='SCHOOL'?'school':sourcetype=='ADULT'?'adult':'course')+'/tks.jsp?lang='+(lang=='eng'?'ENG':'CHI')+'&success='+result;
}

function contactussubmit(form,lang,submittype){
	if(enquiryboxcheck(form,lang)){
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4)
			{
				if (xmlHttp.status == 200){
					var result=trim(xmlHttp.responseText);
					
					showresult(result.indexOf('ENQUIRYDONE')>=0?1:0,lang,form);
				}
			}
		}
		xmlHttp.open('GET',getURL2(form,submittype),true);
		xmlHttp.send(null);
	}
}

function getURL2(form,submittype){
	var url='';
	if(submittype=='email')
		url='/formaction/takedetail_email.jsp';
	else
		url='/formaction/takedetail.jsp';
	url+='?name='+encodeURIComponent(form.name.value);
	url+='&tel='+encodeURIComponent(form.tel.value);
	url+='&email='+encodeURIComponent(form.email.value);
	url+='&loc='+form.loc.value;
	url+='&enquirytype='+form.enquirytype.value;
	url+='&enquiry='+encodeURIComponent(form.enquiry.value);
	url+='&time='+getSelectedRadioValue(form.time);
	return url;
}

function tailorsubmit(form){
	if(enquiryboxcheck(form,'eng')){
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4)
			{
				if (xmlHttp.status == 200){
					var result=trim(xmlHttp.responseText);
					
					showresult(result.indexOf('ENQUIRYDONE')>=0?1:0,'eng',form);
				}
			}
		}
		xmlHttp.open('GET',getURL3(form),true);
		xmlHttp.send(null);
	}
}

function getURL3(form){
	var url='/formaction/tailor.jsp';
	url+='?name='+encodeURIComponent(form.name.value);
	url+='&tel='+encodeURIComponent(form.tel.value);
	url+='&email='+encodeURIComponent(form.email.value);
	url+='&loc1='+encodeURIComponent(form.loc1.value);
	url+='&loc2='+encodeURIComponent(form.loc2.value);
	url+='&remarks='+encodeURIComponent(form.remarks.value);
	url+='&hrs='+encodeURIComponent(form.hrs.value);
	url+='&min='+encodeURIComponent(form.min.value);
	url+='&period='+encodeURIComponent(form.period.value);
	url+='&courselength='+encodeURIComponent(form.courselength.value);
	url+='&level='+encodeURIComponent(form.level.value);

	var boxes = form.weekday.length;
	var txtvalue="";
	for (i = 0; i < boxes; i++) {
		if (form.weekday[i].checked) {
			txtvalue+=form.weekday[i].value + ","
		}
	}

	url+='&weekday='+encodeURIComponent(txtvalue);
	return url;
}

function checkobject(obj) { 
	if (document.getElementById(obj)) { return true; } else { return false; } 
} 