<!--
//**************************************************************************************************
//*	function included:
//*		validate_login(theform)
//*		validate_download_form(dl_form, mode)
//*		validate_news_form(news_form, mode)
//*		validate_contact_form(contact_form, language)
//*			contactFormErrEN()
//*			contactFormErrTC()
//*		validate_gallery_form(gallery_form, mode)
//*		validate_gallery_photo_form(gallery_photo_form, mode)
//*		validate_exhibition_form(exhibition_form)
//*		validate_company_form(company_form)
//*		validate_newsletter(newsletter)
//*		validate_delete_newsletter_form(newsletter_list)
//**************************************************************************************************

function validate_login(loginform){
	if (loginform.username.value.isEmpty()){
		alert("Please enter your username");
		return;
	}

	if (loginform.password.value.isEmpty()){
		alert("Please enter your password");
		return;
	}

	loginform.submit();
}

//--------------------------------------------------------------------------------------------------
function validate_download_form(dl_form, mode){
	var start, end, extension = "";

	if (mode == "update"){
		if (dl_form.resource_id.value.isEmpty()){
			alert("Please provided the resource's identity first.");
			return false;
		}
	}

	if (dl_form.name_en.value.isEmpty()){
		alert("Please enter the resource's name [English version]");
		return false;
	} else if (dl_form.name_en.value.getLength() > 255){
		alert("The length of resource's name [English version] should not more than 255 characters");
		return false;
	}

	if (dl_form.name_tc.value.isEmpty()){
		alert("Please enter the resource's name [Chinese version]");
		return false;
	} else if (dl_form.name_tc.value.getLength() > 120){
		alert("The length of resource's name [Chinese version] should not more than 120 Chinese words");
		return false;
	}

	if (dl_form.description_en.value.isEmpty()){
		alert("Please enter the resource's description [English version]");
		return false;
	} else if (dl_form.description_en.value.getLength() > 1000){
		alert("The length of resource's description [English version] should not more than 1000 characters");
		return false;
	}

	if (dl_form.description_tc.value.isEmpty()){
		alert("Please enter the resource's description [Chinese version]");
		return false;
	} else if (dl_form.description_tc.value.getLength() > 500){
		alert("The length of resource's description [Chinese version] should not more than 500 words");
		return false;
	}

	if (mode == "add"){
		if (dl_form.filename.value.isEmpty()){
			alert("Please attach the file");
			return false;
		}
	}
	
	if (dl_form.filename.value.getLength() > 0){
		start = -1;
		end = -1;

		start = dl_form.filename.value.lastIndexOf(".") + 1;
		end = dl_form.filename.value.getLength();

		extension = dl_form.filename.value.substring(start, end).toLowerCase();
		if (extension != "pdf" && extension != "doc" && extension != "xls"){
			alert("We only allow the file, which extension is \"PDF\", \"DOC\" and \"XLS\"");
			return false;
		}
	}

	if (dl_form.post_date.value.isEmpty()){
		alert("Please select the post date");
		return false;
	}

	return true;
}

//--------------------------------------------------------------------------------------------------
function validate_news_form(news_form, mode){
	var start, end, extension = "";
	
	if (mode == "update"){
		if (news_form.news_id.value.isEmpty()){
			alert("Please provided the news's identity first.");
			return false;
		}
	}

	if (news_form.description_en.value.isEmpty()){
		alert("Please enter the news's description [English version]");
		return false;
	} else if (news_form.description_en.value.getLength() > 255){
		alert("The length of news's description [English version] should not more than 255 characters");
		return false;
	}

	if (news_form.description_tc.value.isEmpty()){
		alert("Please enter the news's description [Chinese version]");
		return false;
	} else if (news_form.description_tc.value.getLength() > 120){
		alert("The length of news's description [Chinese version] should not more than 120 words");
		return false;
	}

	if (news_form.filename.value.getLength() > 0){
		start = -1;
		end = -1;

		start = news_form.filename.value.lastIndexOf(".") + 1;
		end = news_form.filename.value.getLength();

		extension = news_form.filename.value.substring(start, end).toLowerCase();
		if (extension != "pdf" && extension != "doc" && extension != "xls"){
			alert("We only allow the file, which extension is \"PDF\", \"DOC\" and \"XLS\"");
			return false;
		}
	}

	if (news_form.content_en.value.isEmpty()){
		alert("Please enter the content[English version] of the news");
		return false;
	}

	if (news_form.content_tc.value.isEmpty()){
		alert("Please enter the content[Chinese version] of the news");
		return false;
	}

	if (news_form.news_date.value.isEmpty()){
		alert("Please select the news date");
		return false;
	}

	return true;
}

//--------------------------------------------------------------------------------------------------
function contactFormErrEN(){
	this.companyExceptionMsg	= "Please enter your company name.";
	this.lastNameExceptionMsg	= "Please enter your last name.";
	this.firstNameExceptionMsg	= "Please enter your first name.";
	this.telExceptionMsg		= "Please provide your telephone.";
	this.emailExceptionMsg		= "Please provide your email.";

	return (this);
}

function contactFormErrTC(){
	this.companyExceptionMsg	= "請輸入公司名稱.";
	this.lastNameExceptionMsg	= "請輸入閣下的姓氏.";
	this.firstNameExceptionMsg	= "請輸入閣下的名字.";
	this.telExceptionMsg		= "請提供閣下的聯絡電話.";
	this.emailExceptionMsg		= "請提供閣下的電郵地址.";

	return (this);
}

function validate_contact_form(contact_form, language){
	var errMsg;
	if (language == "en"){
		errMsg = new contactFormErrEN();
	} else{
		errMsg = new contactFormErrTC();
	}

	if (contact_form.company_name.value.isEmpty()){
		alert(errMsg.companyExceptionMsg);
		return false;
	}

	if (contact_form.last_name.value.isEmpty()){
		alert(errMsg.lastNameExceptionMsg);
		return false;
	}

	if (contact_form.first_name.value.isEmpty()){
		alert(errMsg.firstNameExceptionMsg);
		return false;
	}

	if (contact_form.tel.value.isEmpty()){
		alert(errMsg.telExceptionMsg);
		return false;
	}

	if (contact_form.email1.value.isEmpty()){
		alert(errMsg.emailExceptionMsg);
		return false;
	}

	return true;
}

//--------------------------------------------------------------------------------------------------
function validate_gallery_form(gallery_form, mode){
	var start, end;
	var extension;

	if (mode == "update"){
		if (gallery_form.gallery_id.value.isEmpty()){
			alert("Please provided the gallery's identity first.");
			return false;
		}
	}

	if (gallery_form.subject_en.value.isEmpty()){
		alert("Please enter the gallery's subject [English version]");
		return false;
	} else if (gallery_form.subject_en.value.getLength() > 255){
		alert("The length of gallery's subject [English version] should not more than 255 characters");
		return false;
	}

	if (gallery_form.subject_tc.value.isEmpty()){
		alert("Please enter the gallery's subject [Chinese version]");
		return false;
	} else if (gallery_form.subject_tc.value.getLength() > 120){
		alert("The length of gallery's subject [Chinese version] should not more than 120 words");
		return false;
	}

	if (gallery_form.content_en.value.isEmpty()){
		alert("Please enter the description[English version] of the gallery");
		return false;
	}

	if (gallery_form.content_tc.value.isEmpty()){
		alert("Please enter the description[Chinese version] of the gallery");
		return false;
	}


	if (mode == "add"){
		if (gallery_form.main_image.value.isEmpty()){
			alert("Please select an image for the gallery.");
			return false;
		}
	} 

	if (gallery_form.main_image.value.getLength() > 0){
		start = -1;
		end = -1;

		start = gallery_form.main_image.value.lastIndexOf(".") + 1;
		end = gallery_form.main_image.value.getLength();

		extension = gallery_form.main_image.value.substring(start, end).toLowerCase();
		if (extension != "jpg" && extension != "jpeg" && extension != "gif" && extension != "png"
				&& extension != "bmp"){
			alert("We only allow the file, which extension is \"JPG\", \"JPEG\", \"GIF\", \"BMP\" and \"PNG\"");
			return false;
		}
	}

	if (gallery_form.post_date.value.isEmpty()){
		alert("Please select the post date");
		return false;
	}

	return true;
}

//--------------------------------------------------------------------------------------------------
function validate_gallery_photo_form(gallery_photo_form, mode){
	var start, end;
	var extension;

	if (gallery_photo_form.gallery_id.value.isEmpty()){
		alert("Please provided the gallery's identity first.");
		return false;
	}

	if (gallery_photo_form.description_en.value.isEmpty()){
		alert("Please enter the description[English version] of the photo");
		return false;
	} else if (gallery_photo_form.description_en.value.getLength() > 500){
		alert("The description [English version] cannot be more than 500 characters.");
		return false;
	}

	if (gallery_photo_form.description_tc.value.isEmpty()){
		alert("Please enter the description[Chinese version] of the photo");
		return false;
	} else if (gallery_photo_form.description_tc.value.getLength() > 1000){
		alert("The description [Chinese version] cannot be more than 500 characters.");
		return false;
	}

	if (mode == "add"){
		if (gallery_photo_form.photo_name.value.isEmpty()){
			alert("Please select an image for the gallery.");
			return false;
		}
	} 
	
	if (gallery_photo_form.photo_name.value.getLength() > 0){
		start = -1;
		end = -1;

		start = gallery_photo_form.photo_name.value.lastIndexOf(".") + 1;
		end = gallery_photo_form.photo_name.value.getLength();

		extension = gallery_photo_form.photo_name.value.substring(start, end).toLowerCase();
		if (extension != "jpg" && extension != "jpeg" && extension != "gif" && extension != "png"
				&& extension != "bmp"){
			alert("We only allow the file, which extension is \"JPG\", \"JPEG\", \"GIF\", \"BMP\" and \"PNG\"");
			return false;
		}
	}

	return true;
}

//--------------------------------------------------------------------------------------------------
function validate_exhibition_form(exhibition_form) {

	var contact_person_en;
	var contact_person_tc;
	var tel;
	
	if (exhibition_form.name_en.value.isEmpty()) {
		alert("Please enter the English name of the exhibition.");
		return false;
	} else if (exhibition_form.name_en.value.getLength() > 100) {
		alert("The length of the exhibition's English name cannot be more than 100 characters.");
		return false;
	}
	
	if (exhibition_form.name_tc.value.isEmpty()) {
		alert("Please enter the Chinese name of the exhibition.");
		return false;
	} else if (exhibition_form.name_tc.value.getLength() > 100) {
		alert("The length of the exhibition's Chinese name cannot be more than 100 characters.");
		return false;
	}
	
	if (exhibition_form.fax.value.getLength() > 30) {
		alert("The length of fax cannot be more than 30 characters");
		return false;
	}
	
	if (exhibition_form.email.value.getLength() > 100) {
		alert("The length of email cannot be more than 30 characters");
		return false;
	}
	
	if (exhibition_form.show_date_en.value.isEmpty()) {
		alert("Please enter the show date of the exhibition.");
		return false;
	} else if (exhibition_form.show_date_en.value.getLength() > 10) {
		alert("The length of the show date cannot be more than 10 characters.");
		return false;
	}

	if (exhibition_form.end_date_en.value.isEmpty()) {
		alert("Please enter the end date of the exhibition.");
		return false;
	} else if (exhibition_form.end_date_en.value.getLength() > 10) {
		alert("The length of the end date cannot be more than 10 characters.");
		return false;
	} else {
		var sArray = exhibition_form.show_date_en.value.split("-");
		var eArray = exhibition_form.end_date_en.value.split("-");

		if (sArray.length == 3 && eArray.length == 3) {
			if (parseInt(eArray[2],10) < parseInt(sArray[2],10)) {
				alert("End date must be later than start date" + " 2 " + sArray[2] );
				return false;
			} else {
				if (parseInt(eArray[2],10) = parseInt(sArray[2],10)) {
					if (parseInt(eArray[1],10) < parseInt(sArray[1],10)) {
						alert("End date must be later than start date" + " 1 " + sArray[1]);
						return false;
					} else {
						if (parseInt(eArray[1],10) = parseInt(sArray[1],10)) {
							if (parseInt(eArray[0],10) < parseInt(sArray[0],10)) {
								alert("End date must be later than start date" + " 0 " + parseInt(sArray[0],10) + parseInt(eArray[0],10));
							return false;
							}
						}
					}
				}
			}
		}
	}

	if (exhibition_form.venue_en.value.isEmpty()) {
		alert("Please enter the venue (English) of the exhibition.");
		return false;
	} else if (exhibition_form.venue_en.value.getLength() > 500) {
		alert("The length of the venue (English) cannot be more than 500 characters.");
		return false;
	}
	
	if (exhibition_form.venue_tc.value.isEmpty()) {
		alert("Please enter the venue (Chinese) of the exhibition.");
		return false;
	} else if (exhibition_form.venue_tc.value.getLength() > 500) {
		alert("The length of the venue (Chinese) cannot be more than 500 characters.");
		return false;
	}
	
	if (exhibition_form.description_en.value.getLength() > 500) {
		alert("The length of the description (English) cannot be more than 500 characters");
		return false;
	}
	
	if (exhibition_form.description_tc.value.getLength() > 500) {
		alert("The length of the description (Chinese) cannot be more than 500 characters");
		return false;
	}
	
	for (var index = 1; index <= 5; index++) {
		eval("contact_person_en = exhibition_form.contact_person_en" + index + ".value;");
		eval("contact_person_tc = exhibition_form.contact_person_tc" + index + ".value;");
		eval("tel = exhibition_form.contact_tel" + index + ".value;");
		
		if (contact_person_en.getLength() > 100) {
			alert("The English name of contact person, which with index " + index + " cannot be more than 100 characters");
			return false;
		}
		if (contact_person_tc.getLength() > 100) {
			alert("The Chinese name of contact person, which with index " + index + " cannot be more than 100 characters");
			return false;
		}
		if (tel.getLength() > 30) {
			alert("The tel of contact person, which with index " + index + " cannot be more than 30 characters");
			return false;
		}
	}
}


//--------------------------------------------------------------------------------------------------
function validate_company_form(company_form) {

	with (company_form) {
		if (company_name_en.value.isEmpty()) {
			alert("Please enter the company name (English)");
			return false;
		} else if (company_name_en.value.getLength() > 250) {
			alert("The company name (English) cannot be more than 250 characters");
			return false;
		}
	
		if (company_name_tc.value.isEmpty()) {
			alert("Please enter the company name (Chinese)");
			return false;
		} else if (company_name_tc.value.getLength() > 250) {
			alert("The company name (Chinese) cannot be more than 250 characters");
			return false;
		}

		if (address_en.value.isEmpty()) {
			alert("Please enter your company address (English)");
			return false;
		} else if (address_en.value.getLength() > 250) {
			alert("The address (English) cannot be more than 250 characters")
			return false;
		}	
		
		if (address_tc.value.isEmpty()) {
			alert("Please enter your company address (Chinese)");
			return false;
		} else if (address_tc.value.getLength() > 250) {
			alert("The address (Chinese) cannot be more than 250 characters");
			return false;
		}
		
		if (tel.value.getLength() > 30) {
			alert("The tel cannot be more than 30 characters");
			return false;
		}
		
		if (fax.value.getLength() > 30) {
			alert("The fax cannot be more than 30 characters");
			return false;
		}
		
		if (website.value.getLength() > 100) {
			alert("The website cannot be more than 100 characters");
			return false;
		}
		
		if (email.value.getLength() > 100) {
			alert("The email cannot be more than 100 characters");
			return false;
		}
		
		if (br_no.value.getLength() > 50) {
			alert("The BR No. cannot be more than 50 characters");
			return false;
		}
		
		if (ci_no.value.getLength() > 50) {
			alert("The CI No. cannot be more than 50 characters");
			return false;
		}
		
		if (!hk_num_of_employee.value.isEmpty()){
			if (isNaN(parseInt(hk_num_of_employee.value,10))) {
				alert("The number of employee (HK) should be a number");
				return false;
			}
		}
		
		if (!prc_num_of_employee.value.isEmpty()){
			if (isNaN(parseInt(prc_num_of_employee.value,10))) {
				alert("The number of employee (PRC) should be a number");
				return false;
			}
		}
		
		if (!oversea_num_of_employee.value.isEmpty()){
			if (isNaN(parseInt(oversea_num_of_employee.value,10))) {
				alert("The number of employee (Oversea) should be a number");
				return false;
			}
		}	
			
		if (factory_en.value.getLength() > 250) {
			alert("The factory (English) cannot be more than 250 characters");
			return false;
		}
		
		if (factory_tc.value.getLength() > 250) {
			alert("The factory (Chinese) cannot be more than 250 characters");
			return false;
		}
		
		if (hk_factory_en.value.getLength() > 250) {
			alert("The HK factory (English) cannot be more than 250 characters");
			return false;
		}
		
		if (hk_factory_tc.value.getLength() > 250) {
			alert("The HK factory (Chinese) cannot be more than 250 characters");
			return false;
		}
		
		if (prc_factory_en.value.getLength() > 250) {
			alert("The PRC factory (English) cannot be more than 250 characters");
			return false;
		}
		
		if (prc_factory_tc.value.getLength() > 250) {
			alert("The PRC factory (Chinese) cannot be more than 250 characters");
			return false;
		}
		
		if (oversea_factory_en.value.getLength() > 250) {
			alert("The oversea factory (English) cannot be more than 250 characters");
			return false;
		}
		
		if (oversea_factory_tc.value.getLength() > 250) {
			alert("The oversea factory (Chinese) cannot be more than 250 characters");
			return false;
		}	
		if (branch_en.value.getLength() > 255) {
			alert("The branch (English) cannot be more than 250 characters");
			return false;
		}
		
		if (branch_tc.value.getLength() > 250) {
			alert("The branch (Chinese) cannot be more than 250 characters");
			return false;
		}
		
		if (contact_person_en.value.getLength() > 50) {
			alert("The contact person (English) cannot be more than 50 characters");
			return false;
		}
		
		if (contact_person_tc.value.getLength() > 50) {
			alert("The contact person (Chinese) cannot be more than 50 characters");
			return false;
		}
		
		if (contact_person_position.value.getLength() > 100) {
			alert("The position of contact person cannot be more than 100 characters");
			return false;
		}
		
		if (contact_person_position_en.value.getLength() > 100) {
			alert("The position of contact person (English) cannot be more than 100 characters");
			return false;
		}
		
		if (contact_person_position_tc.value.getLength() > 100) {
			alert("The position of contact person (Chinese) cannot be more than 100 characters");
			return false;
		}	
		if (contact_person_email.value.getLength() > 100) {
			alert("The email of contact person cannot be more than 100 characters");
			return false;
		}
	
		if (major_product.value.getLength() > 500) {
			alert("The major product cannot be more than 500 characters");
			return false;
		}
		
		if (principal_market.value.getLength() > 500) {
			alert("The principal market cannot be more than 500 characters");
			return false;
		}
		
		if (trade_mark.value.getLength() > 500) {
			alert("The trade mark cannot be more than 500 characters");
			return false;
		}
		
		if (outstanding_achievements.value.getLength() > 500) {
			alert("The outstanding achievements cannot be more than 500 characters");
			return false;
		}
		
		return true;
	}

}

//--------------------------------------------------------------------------------------------------
function validate_newsletter(newsletter){
	var subContentCount = parseInt(newsletter.num_of_sub_topic.value,10);
	var subtopic, content, image;
	var pass = false;

	if (newsletter.topic.value.isEmpty()){
		alert("Please enter the topic of newsletter");
		return false;
	} else if (newsletter.topic.value.getLength() > 255){
		alert("The topic of newsletter cannot be more than 255 characters or 120 chinese word");
		return false;
	}

	if (subContentCount == 1){
		if (newsletter.sub_topic1.value.isEmpty()){
			alert("Please at least enter one sub-topic");
			return false;
		} else if (newsletter.sub_topic1.value.getLength() > 255){
			alert("The lenght of sub-topic cannot be more than 255 characters or 20 chinese word");
			return false;
		}

		if (newsletter.content1.value.isEmpty()){
			alert("Please at least enter one sub-topic's content");
			return false;
		} else if (newsletter.content1.value.getLength() > 4000){
			alert("The length of the content of sub-topic cannot be more than 4000 characters or more than 2000 chinese word");
			return false;
		}
	} else{
		for (var i = 1; i <= subContentCount; i++){

			eval("subtopic = newsletter.sub_topic" + i + ";");
			eval("content = newsletter.content" + i + ";");

			if (pass){
				if (subtopic.value.isEmpty()){
					alert("Please at least enter one sub-topic");
					return false;
				} else if (subtopic.value.getLength() > 255){
					alert("The lenght of sub-topic cannot be more than 255 characters or 20 chinese word");
					return false;
				}

				if (content.value.isEmpty()){
					alert("Please at least enter one sub-topic's content");
					return false;
				} else if (content.value.getLength() > 4000){
						alert("The length of the content of sub-topic cannot be more than 4000 characters or more than 2000 chinese word");
					return false;
				}

				pass = true;
			} else{
				if (subtopic.value.getLength() > 255){
					alert("The length of sub-topic cannot be more than 255 characters or 120 chinese word");
					return false;
				}

				if (content.value.getLength() > 4000){
					alert("The length of the content of sub-topic cannot be more than 4000 characters or 2000 chinese word");
					return false;
				}
			}
		}
	} 

	return true;
}

//--------------------------------------------------------------------------------------------------
function validate_delete_newsletter_form(newsletter_list){
	var checkboxCount = (newsletter_list.newsletterId.length == undefined ? 1 : newsletter_list.newsletterId.length);
	var pass = false;

	if (checkboxCount == 1){
		if (newsletter_list.newsletterId.checked){
			pass = true;
		}
	} else{
		for (var i = 0; i < checkboxCount; i++){
			if (newsletter_list.newsletterId[i].checked){
				pass = true;
				break;
			}
		}
	}

	if (pass){
		if (confirm("Do you really want to delete selected newsletter?")){
			return true;
		} else{
			return false;
		}
	} else{
		return false;
	}
}

//-->