// Home video
function goDetail1(){
	if(document.f_archive_e.media[3].checked){
		document.f_archive_e.home_video_detail[0].focus();
	}
	else {
		for (i = 0; i < document.f_archive_e.home_video_detail.length; i++) {
			document.f_archive_e.home_video_detail[i].checked = false;
		}
	}
}
// Non-theatrical 
function goDetail2(){
	if(document.f_archive_e.media[4].checked){
		document.f_archive_e.non_theatrical_detail[0].focus();
	}
	else {
		for (i = 0; i < document.f_archive_e.non_theatrical_detail.length; i++) {
			document.f_archive_e.non_theatrical_detail[i].checked = false;
		}
	}
}

function chkDetail(){
	if((document.f_archive_e.territory[4].checked)||
		(document.f_archive_e.territory[5].checked)){
		document.f_archive_e.territory_free.focus();
	}
	if((!document.f_archive_e.territory[4].checked)&&
		(!document.f_archive_e.territory[5].checked)){
		document.f_archive_e.territory_free.value = "";
	}
}

function validation_e(){
	// Company
	document.f_archive_e.company.value = Trim(document.f_archive_e.company.value);
	if(document.f_archive_e.company.value == ""){
		alert("Please input your company name.");
		document.f_archive_e.company.focus();
		return false;
	}
	// Person in charge
	document.f_archive_e.prsn_in_chrg.value = Trim(document.f_archive_e.prsn_in_chrg.value);
	if(document.f_archive_e.prsn_in_chrg.value == ""){
		alert("Please input a person-in-charge name.");
		document.f_archive_e.prsn_in_chrg.focus();
		return false;
	}
	// Address
	document.f_archive_e.address.value = Trim(document.f_archive_e.address.value);
	if (document.f_archive_e.address.value == ""){
		alert("Please input the address of your company.");
		document.f_archive_e.address.focus();
		return false;
	}
	// Telephone
	document.f_archive_e.tel_no.value = Trim(document.f_archive_e.tel_no.value);
	if (document.f_archive_e.tel_no.value == ""){
		alert("Please input the telephone number of your company.");
		document.f_archive_e.tel_no.focus();
		return false;
	}
	if (document.f_archive_e.tel_no.value.search(/[^0-9|+|-]/i) != -1){
		alert("Please check the filled-in telephone number.");
		document.f_archive_e.tel_no.focus();
		return false;
	}
	// FAX
	document.f_archive_e.fax_no.value = Trim(document.f_archive_e.fax_no.value);
	if(document.f_archive_e.fax_no.value == ""){
		alert("Please input the facsimile number of your company.");
		document.f_archive_e.fax_no.focus();
		return false;
	}
	if (document.f_archive_e.fax_no.value.search(/[^0-9|+|-]/i) != -1){
		alert("Please check the filled-in facsimile number.");
		document.f_archive_e.fax_no.focus();
		return false;
	}
	// E-mail Address
	document.f_archive_e.mail_addr.value = Trim(document.f_archive_e.mail_addr.value);
	if(document.f_archive_e.mail_addr.value == ""){
		alert("Please input your mail address.");
		document.f_archive_e.mail_addr.focus();
		return false;
	}
	if(!MailString(document.f_archive_e.mail_addr.value)){
		alert("Please check the filled-in mail address.");
		document.f_archive_e.mail_addr.focus();
		return false;
	}
	// Home video detail
	if ((document.f_archive_e.media[3].checked)&&
		(!document.f_archive_e.home_video_detail[0].checked)&&
		(!document.f_archive_e.home_video_detail[1].checked)&&
		(!document.f_archive_e.home_video_detail[2].checked)&&
		(!document.f_archive_e.home_video_detail[3].checked)){

		alert("Please select detail.");
		document.f_archive_e.home_video_detail[0].focus();
		return false;
	}
	// Non-theatrical detail
	if ((document.f_archive_e.media[4].checked)&&
		(!document.f_archive_e.non_theatrical_detail[0].checked)&&
		(!document.f_archive_e.non_theatrical_detail[1].checked)&&
		(!document.f_archive_e.non_theatrical_detail[2].checked)&&
		(!document.f_archive_e.non_theatrical_detail[3].checked)){

		alert("Please select detail.");
		document.f_archive_e.non_theatrical_detail[0].focus();
		return false;
	}
	// Territory detail
	if (((document.f_archive_e.territory[4].checked)||
		(document.f_archive_e.territory[5].checked))&&
		(document.f_archive_e.territory_free.value=="")){

		alert("Please input detail.");
		document.f_archive_e.territory_free.focus();
		return false;
	}

	return true;
}
function Trim(str)
{
	var buf = "";
	var start_pos = -1;
	var end_pos = -1;
	
	for(i=0;i<str.length;i++){
		if( str.charAt(i) != ' ' ) {
			start_pos = i;
			break;
		};
	};

	for(i=str.length-1;i>=0;i--){
		if( str.charAt(i) != ' ' ) {
			end_pos = i;
			break;
		};
	};

	if ( end_pos == -1 ) {
		buf = "";
	}
	else {
		buf = str.substr( start_pos, end_pos - start_pos + 1 );
	}

	return buf;
}
function MailString( pStr )
{
	nFlg = true;
	var checkOK = "0123456789.-@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_&";
	var checkStr = pStr;
	var allValid = true;
	var alpha = 0;
	var point = 0;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j))
				break;
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		if (ch == '@')
			alpha++;
		if (ch == ".")
			point ++;
		if (i==(checkStr.length-1) && ch == ".")
			return false;
	}
	if (!allValid){
		return false;
	}
	if (alpha !=1){
		return false;
	}
	if (point <1){
		return false;
	}
	return true;
}

