function countRemaining(textForm, maxLength, divid) {
	var pid = divid;
	//alert(pid);
	var remainCharacter = maxLength - textForm.value.length;

	if(textForm.value.length<=maxLength) $(pid).innerHTML = remainCharacter;
	else {
		alert('enable input '+maxLength+' Word');
		textForm.value = textForm.value.substr(0,maxLength);
	}
}

function chkInputForm() {
	var rform = document.applicationForm;

	// chk Title of Presentation
	if(chkLength(rform.presentationTitle, 'Title of Presentation')==0) { rform.presentationTitle.focus(); return false; }
	if(chkLength(rform.presenterName, 'Name of Presentater1')==0) { rform.presenterName.focus(); return false; }
	if(chkLength(rform.affiliation, 'Affiliation')==0) { rform.affiliation.focus(); return false; }
	if(chkRadioButton(rform.targetArea, 'Target Area')==0) { rform.targetArea[0].focus(); return false; }
	if(chkRadioButton(rform.position, 'Position')==0) { rform.position[0].focus(); return false; }
	if(chkRadioButton(rform.title, 'Title')==0) { rform.title[0].focus(); return false; }
	if(chkEmailForm(rform.mailingPresenter1, 'Presenter1')==0) { rform.mailingPresenter1.focus(); return false; }
	/*
	if(chkLength(rform.mailingPresenter1, 'Mailing List Presenter1')==0) { 
		rform.mailingPresenter1.focus(); 
		return false; 
	} else {
		if(rform.mailingPresenter1.value.indexOf(' ') != -1) { // eMail 공백포함여부 검사
			alert("Checkd Email (Presenter1)");
			rform.mailingPresenter1.focus(); 
			return 0;
		}
		if(rform.mailingPresenter1.value.search(/^\w.*\@\w+.*\.\w{2,3}$/) == -1) { // eMail  유효성 검사
			alert("Checkd Email (Presenter1)");
			rform.mailingPresenter1.focus(); 
			return 0;
		}
	}
	*/
		
	// Presenter3 Email Validation
	if(chkLengthNotAlert(rform.presenterName3, 'Name of Presentater3')>0) {
		// Presenter2에 대한 사항이 입력되있는지 확인
		if(chkLength(rform.presenterName2, 'Name of Presentater2')==0) { rform.presenterName2.focus();  return false; }
		if(chkLength(rform.affiliationPresenter2, 'Affiliation Presenter2')==0) { rform.affiliationPresenter2.focus(); return false; }
		if(chkEmailForm(rform.mailingPresenter2, 'Presenter2')==0) { rform.mailingPresenter2.focus(); return false; }
		// Presenter3에 대한 사항이 입력되있는지 확인
		if(chkLength(rform.affiliationPresenter3, 'Affiliation Presenter3')==0) { rform.affiliationPresenter3.focus(); return false; }
		if(chkEmailForm(rform.mailingPresenter3, 'Presenter3')==0) { rform.mailingPresenter3.focus(); return false; }
	} else if (chkLengthNotAlert(rform.presenterName2, 'Name of Presentater2')>0) {
		// Presenter2에 대한 사항이 입력되있는지 확인
		if(chkLength(rform.affiliationPresenter2, 'Affiliation Presenter2')==0) { rform.affiliationPresenter2.focus(); return false; }
		if(chkEmailForm(rform.mailingPresenter2, 'Presenter2')==0) { rform.mailingPresenter2.focus(); return false; }
	}

	if(rform.country.options[rform.country.selectedIndex].value.length==0) {alert('select country'); rform.country.focus(); return false;}
	if(chkLength(rform.address, 'Address')==0) { rform.address.focus(); return false; }
	if(chkLength(rform.phoneWork, 'Phone Work')==0) { rform.phoneWork.focus(); return false; }
	/*
	if(chkLength(rform.phoneHome, 'Phone Home')==0) { rform.phoneHome.focus(); return false; }
	if(chkLength(rform.phoneCell, 'Phone Cell Phone')==0) { rform.phoneCell.focus(); return false; }
	*/
	if(chkRadioButton(rform.topicArea, 'Topic Area')==0) { rform.topicArea[0].focus(); return false; }
	if(chkRadioButton(rform.typeOfPresentation, 'Type of Presentation')==0) { rform.typeOfPresentation[0].focus(); return false; }
	if(chkRadioButton(rform.equimentRequired, 'Equiment Required')==0) { rform.equimentRequired[0].focus(); return false; }
	if(chkLength(rform.abstractPresentation, 'Abstract of your presentation')==0) { rform.abstractPresentation.focus(); return false; }

	if(countBlank(rform.abstractPresentation)>260) { alert('A 250-word Abstract of your presentation'); rform.abstractPresentation.focus(); return false;}

	if(chkLength(rform.biographicalData, 'Biographical data')==0) { rform.biographicalData.focus(); return false; }
	if(countBlank(rform.biographicalData)>61) { alert('An 60-word Biographical data'); rform.biographicalData.focus(); return false;}

	rform.titleStr.value = makeCheckStr(rform.title);
	rform.equimentRequiredStr.value = makeCheckStr(rform.equimentRequired);
	
	if(rform.submitType.value=='modify') {
		rform.action="./applicationRegist_Modify.php";
	} else {
		rform.action="./applicationRegist.php";
	}
	
	//alert('Run submit()');
	rform.submit();

}

function makeCheckStr(inputForm) {
	var titleLength = inputForm.length;
	var chkStr="";
	var chkStart=0;

	for(i=0; i<titleLength; i++) {
		if(inputForm[i].checked==true) {
			if(chkStart>0) chkStr += "|";
			chkStr += inputForm[i].value;
			chkStart++;
			//alert(inputForm[i].value);
		}
	}

	return chkStr
}
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/gi,"");
}
function chkLength(inputForm, fieldName) {
	inputForm.value = inputForm.value.trim();
	if(inputForm.value.length==0) {
		alert('Input '+fieldName);
		return 0;
	} else {
		return 1;
	}
}

function chkLengthNotAlert(inputForm, fieldName) {
	inputForm.value = inputForm.value.trim();
	if(inputForm.value.length==0) {
		//alert('Input '+fieldName);
		return 0;
	} else {
		return 1;
	}
}
function chkEmailForm(emailForm, fieldName) {
	if(chkLength(emailForm, 'Mailing List '+fieldName)==0) { 
		emailForm.focus(); 
		return false; 
	} else {
		if(emailForm.value.indexOf(' ') != -1) { // eMail 공백포함여부 검사
			alert("Checkd Email ("+fieldName+")");
			emailForm.focus(); 
			return 0;
		}
		if(emailForm.value.search(/^\w.*\@\w+.*\.\w{2,3}$/) == -1) { // eMail  유효성 검사
			alert("Checkd Email ("+fieldName+")");
			emailForm.focus(); 
			return 0;
		}
	}
}
function chkRadioButton(inputForm, fieldName) {
	var formLength = inputForm.length;
	for(i=0; i<formLength; i++) {
		if(inputForm[i].checked==true) return 1;
	}
	alert('Check '+fieldName);
	return 0;
}

function countBlank(inputForm) {
	// blank를 체크 하기는 한데 여러개의 blank가 연속으로 있는것 까지 체크를 하니 문제다.
	var str=inputForm.value;

	str=str.replace(/,/g, " ");
	str=str.replace(/\./g, " ");
	str=str.replace(/\!/g, " ");
	str=str.replace(/\?/g, " ");
	str=str.replace(/\n/g, " ");
	str=str.replace(/\r/g, " ");
	str=str.replace(/\'/g, " ");
	str=str.replace(/\"/g, " ");
	str=str.replace(/\:/g, " ");
	str=str.replace(/\;/g, " ");
	str=str.replace(/-/g, " ");
	str=str.replace(/_/g, " ");
	str=str.replace(/\[/g, " ");
	str=str.replace(/\]/g, " ");
	str=str.replace(/\(/g, " ");
	str=str.replace(/\)/g, " ");
	str=str.replace(/\</g, " ");
	str=str.replace(/\>/g, " ");
	str=str.replace(/\~/g, " ");
	str=str.replace(/\\/g, " ");
	str=str.replace(/\//g, " ");

	str=str.replace(/     /g, " ");
	str=str.replace(/    /g, " ");
	str=str.replace(/   /g, " ");
	str=str.replace(/  /g, " ");
	str=str.replace(/  /g, " ");
	str=str.replace(/  /g, " ");
	str=str.replace(/  /g, " ");
	str=str.replace(/  /g, " ");	// 공란 두개를 한개로 변환

	//var formLength = inputForm.value.length;
	//var arrStr = inputForm.value;
	var formLength = str.length;
	var arrStr = str;
	var blankCount=0;

	for(i=0; i<formLength; i++) {
		if(arrStr[i]==' ') blankCount++;
	}
	//alert(blankCount);
	return blankCount;
}