function fakTrans(){
	var mForm=window.document.forms[0];
	var cForm=window.frames[0].document.forms[0];
	mForm.tm1.value=cForm.tm1.value;
	mForm.tm2.value=cForm.tm2.value;
	mForm.tm3.value=cForm.tm3.value;
	mForm.tm4.value=cForm.tm4.value;
	mForm.tm5.value=cForm.tm5.value;
	mForm.tm6.value=cForm.tm6.value;
	mForm.tm7.value=cForm.tm7.value;
	mForm.tm8.value=cForm.tm8.value;
	mForm.tm9.value=cForm.tm9.value;
	mForm.tm10.value=cForm.tm10.value;
}
function chCondition(){
	var form=window.document.forms[0];
	if(form.activities.value=="operating"){
		form.soperator.style.display="none";
		form.ioperator.style.visibility="hidden";
		form.operator.style.display="inline";
	}else{
		form.soperator.style.display="inline";
		form.ioperator.style.visibility="visible";
		form.operator.style.display="none";
	}
}
function calFak(val,result,resource){
	if(val.value.length==0) val.value=0;
	result.value=eval(resource.value)+eval(val.value);
}
function chkFormReport(){
	var form=window.document.forms[0];
	if(form.name.value.length==0){
		alert('กรุณากรอกชื่อของท่าน');
		form.name.focus();
		return false;
	}else if(form.tel.value.length==0){
		alert('กรุณากรอกโทรศัพท์ที่สามารถติดต่อได้');
		form.tel.focus();
		return false;
	}else if(form.province.value.length==0){
		alert('กรุณาเลือกจังหวัดที่ดำเนินการ');
		return false;
	}else if(form.amphor.value.length==0){
		alert('กรุณาเลือกอำเภอที่ดำเนินการ');
		return false;
	}else if(form.district.value.length==0){
		alert('กรุณาเลือกตำบลที่ดำเนินการ');
		return false;
	}else if(form.village.value.length==0){
		alert('กรุณาเลือกหมู่บ้านที่ดำเนินการ');
		return false;
	}
	form.submit();
}
function clearBox(){
	var form=opener.document.forms[0];
	//form.province.value='';
	//form.amphor.value='';
	//form.district.value='';
	//form.village.value='';
}
function fillArea(area){
		var pro=window.document.forms[0].province;
		var am=window.document.forms[0].amphor;
		var dis=window.document.forms[0].district;
		var vill=window.document.forms[0].village;
		switch (area){
		case 'province': 
			opener.document.forms[0].province.value= pro.options[pro.selectedIndex].text;
			opener.document.forms[0].pro_id.value=pro.options[pro.selectedIndex].value;	
			break;
		case 'amphor': 
			opener.document.forms[0].amphor.value= am.options[am.selectedIndex].text;
			opener.document.forms[0].am_id.value=am.options[am.selectedIndex].value;
			break;
		case 'district':
			opener.document.forms[0].district.value= dis.options[dis.selectedIndex].text;
			opener.document.forms[0].dis_id.value=dis.options[dis.selectedIndex].value;
			break;
		case 'village':
			opener.document.forms[0].village.value= vill.options[vill.selectedIndex].text;
			opener.document.forms[0].vill_id.value=vill.options[vill.selectedIndex].value;
			window.close();
			break;
		};
}
function openBrWindow(theURL,winName,w,h) {
	var top=(screen.height-h)/2;
	var left=(screen.width-w)/2;
	var features='scrollbars=no,status=yes,width='+w+',height='+h+',top='+top+',left='+left;
	window.open(theURL,winName,features);
}
function openFull(theURL,winName,w,h) {
	var top=(screen.height-h)/2;
	var left=(screen.width-w)/2;
	var features='scrollbars=no,status=yes,width='+w+',height='+h+',top='+top+',left='+left;;
	window.open(theURL,winName,features);
}
function chk_register(form,lang){
	var error='';
	var eflag=false;
	
	if(form.fname.value.length==0){
		if(lang=='th')error+=" - ชื่อ \n";
		else error+= " - First Name \n";
		eflag=true;
	}
	
	if(form.lname.value.length==0){
		if(lang=='th')error+=" - นามสกุล \n";
		else error+=" - Last Name \n";
		eflag=true;
	}

	if(form.lname.value.length==0)form.lname.focus();
	if(form.fname.value.length==0)form.fname.focus();
	if(eflag){
		if(lang=='th')
			alert("กรุณากรอก \n"+error+" \nให้สมบูรณ์.");
		else alert("Please make sure  \n"+error+" \n was properly completed.");
		return false;
	}
}
function swapMenu_in(menu){menu.style.backgroundColor='#0000FF';}
function swapMenu_out(menu){menu.style.backgroundColor='#0099FF';}

var timerID = null
var timerRunning = false
function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
function startclock(){
    stopclock()
    showtime()
}
function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue  += (hours >= 12) ? "PM." : "AM."
    document.report.dtime.value = "เวลา "+timeValue 
    timerID = setTimeout("showtime()",1000)
    timerRunning = true
}
function LimitAttach(form, file) {
	if (!file) return;
	extArray = new Array(".gif", ".jpg", ".png");
	allowSubmit = false;
	form.file2.src=file;
	form.file2.width=240;
	form.file2.title=file;
	while (file.indexOf("\\") != -1)
		file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit) 
		fileerror="ไฟล์ภาพประกอบต้องเป็นไฟล์ประเภท gif ,jpg หรือ png เท่านั้น";

	if(!allowSubmit ){
		alert(fileerror);
		form.file2.src="images/contents/nofileimg.jpg";
	}
}
function picshow(form,file) {
	if (!file) return;
	extArray = new Array(".gif", ".jpg", ".png");
	allowSubmit = false;
	form.pic.src=file;
	form.pic.height=82;
	form.pic.title=file;
	while (file.indexOf("\\") != -1)
		file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit) 
		fileerror="ไฟล์ภาพประกอบต้องเป็นไฟล์ประเภท gif ,jpg หรือ png เท่านั้น";

	if(!allowSubmit ){
		alert(fileerror);
		form.pic.src="../images/contents/noimage.jpg";
	}
}
function picshowlink(form,file) {
	if (!file) return;
	extArray = new Array(".gif", ".jpg", ".png");
	allowSubmit = false;
	form.pic.src=file;
	form.pic.height=36;
	form.pic.title=file;
	while (file.indexOf("\\") != -1)
		file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit) 
		fileerror="ไฟล์ภาพประกอบต้องเป็นไฟล์ประเภท gif ,jpg หรือ png เท่านั้น";

	if(!allowSubmit ){
		alert(fileerror);
		form.pic.src="../images/contents/nofileimglink.jpg";
	}
}
function FileAttach(form, file) {
	if (!file) return;
	fileext=null;
	docFile="images/docfile.gif";
	xlsFile="images/xlsfile.gif";
	pptFile="images/pptfile.gif";
	zipFile="images/zipfile.gif";
	pdfFile="images/pdffile.gif";
	unknowFile="images/unknowfile.gif";
	
	while (file.indexOf("\\") != -1)
		file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	switch(ext){
		case '.doc':	 fileext=docFile;break;
		case '.xls':	 fileext=xlsFile;break;
		case '.ppt':  fileext=pptFile;break;
		case '.zip':  fileext=zipFile;break;
		case '.pdf':  fileext=pdfFile;break;
		default:  fileext=unknowFile;
	};
	form.filename.value=file;
	form.file1.src=fileext;
}
function resetReport(form){
	defaultFile="images/note.gif";
	noImg="images/contents/nofileimg.jpg";
	form.file1.src=defaultFile;
	form.file2.src=noImg;
}
function checkReportForm(form){
	flagTopic=form.topic.value.length<=0;
	flagContent=form.content.value.length<=0;
	flagName=form.name.value.length<=0;
	flagOrg=form.org.value.length<=0;
	flagOrgPhone=form.tel.value.length<=0;
	flagRec=true;
	err="";
	for(i=0;i<form.checkbox.length;i++){
		if(form.checkbox[i].checked==true){
			flagRec=false;
		}
	}
	
	if(flagTopic) err+="- หัวข้อ/ชื่อเรื่องที่จะรายงาน\n";
	if(flagContent) err+="- รายละเอียด\n";
	if(flagName) err+="- ยศชื่อ-นามสกุล\n";
	if(flagOrg) err+="- หน่วยงาน\n";
	if(flagOrgPhone) err+="- เบอร์โทรศัพท์หน่วยงาน\n";
	if(flagRec) err+="- เลือกผู้รับรายงาน";

	if(err!=""){
		fullError="เกิดข้อผิดพลาดกรุณาตรวจสอบ :\n"+err;
		alert(fullError);
		if(flagOrg) form.org.focus();
		if(flagName) form.name.focus();
		if(flagContent) form.content.focus();
		if(flagTopic) form.topic.focus();
		return false;
	}else form.submit();
}
function selectAll(formName) {
	if(formName.checkAll.checked==true){
		for (var i = 0; i < formName.elements.length; i++) {
			var e = formName.elements[i];
			if(e.type=="checkbox") e.checked=true;
		}
	}else {
		for (var i = 0; i < formName.elements.length; i++) {
			var e = formName.elements[i];
			if(e.type=="checkbox") e.checked=false;
		}
	}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=200,left = 412,top = 284');");
}

function selectChoice(list,box,hidden){
	box.value=list.text;
	hidden.value=list.value;
}

function confirmDel(){
	if(document.forms[0].topic.value!='' && document.forms[0].title_id.value!='')
		return true;
	return false;
}
function jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function check_number(){
	e_k=event.keyCode;
	if(e_k!=13&&e_k!=44&&e_k!=46&&(e_k<48)||(e_k>57)){
		event.returnValue=false;
		alert("ต้องเป็นตัวเลขเท่านั้น...");
	}
}
function count_chr(str,num){
	if(str.value.length!=num){
		alert("ควรกรอกให้ครบ "+num+" ตัวอักษร");
		str.select();
	}
}