//使用上傳模組
include("../common/swfupload/swfupload.js");
include("../common/swfupload/swfupload.queue.js");
include("../common/swfupload/fileprogress.js");

function show(subjectno)
{ 	
	CallXajaxWithParameterByName('show_subject','mng','f_sno='+subjectno+';','f');
}

function show_result(subjectno) 
{
	var objForm =document.getElementById('mng');
	var error='';
	var pre='';
	
	for (var i=0;i<objForm.length;i++) 
	{ 
		if(objForm[i].name.substr(0,2)=='qu')
		{
			var fieldname=objForm[i].name;
			var num= fieldname.substr(2,fieldname.length);
			if(!isNaN(num))
			{
				if(pre!=fieldname)
				{
					pre=fieldname
					
					if(objForm[i].type=='checkbox')
					{
					}
					else if(objForm[i].type=='radio')
					{
						if(!checkCheckBox(fieldname))
						{
							error+='Q'+num+' ';
						}
						//error+='Q'+num+objForm[i].value+' ';
					}
					else
					{
						if(objForm[i].value=='')
						{
							error+='Q'+num+' ';
						}
					}
				}
				

				
								
			}
		}
	}

	if(error)
	{
		alert(error+lang['FillNull']);
	}
	else
	{
	//document.getElementById('resultbutton').src="./templates/"+tpl_style+"/images/shim.gif";
 		CallXajaxWithParameterByName('show_result','mng','f_sno='+subjectno+';','f');
	}
	return false;
}


function checkCheckBox(fieldname)
{
	var ccount=0; 
	var obj=document.getElementsByName(fieldname);
	
	for (var i=0;i<obj.length;i++) 
	{ 
		if (obj[i].checked) 
			{ 		
			ccount=ccount+1;
			} 
	}
	if (ccount<1) 
	{ 
		return false;
	}	
	return true;

}


function validate_email(field)
{
	with (field)
	{
		apos=field.indexOf("@")
		dotpos=field.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) 
	  	{
	  		return false
	  	}
		else 
		{
			return true
		}
	}
}


function sendemail(obj)
{
	document.getElementById('sendemailbutton').disabled = true;  	
	if(document.getElementById('fillemail').value!="")
	{
		var user_email=document.getElementById('fillemail').value;
		if(validate_email(user_email))
		{ 			
 			CallXajaxWithParameter('validate_email',obj,'s_user_email='+user_email+';');
		}
		else
		{			
			alert(lang['EmailError']);
			document.getElementById('sendemailbutton').disabled = false;
		}
	}
	else
	{
 		document.getElementById('sendemailbutton').disabled = false; 	
	}
			
}
 
function sendemail2()
{
	document.getElementById('ExecResultTemp').value=document.getElementById('Contents').innerHTML;
	document.getElementById('ExecResultTemp').value+=document.getElementById('NotedFD').innerHTML;
	document.getElementById('ExecResultTemp').value+=document.getElementById('NextContents').innerHTML;
	CallXajaxByName('send_email','mng');
}

function choose_province(qid)
{
 	document.getElementById("qu"+qid).value=document.getElementById("province_code").value;	
	document.getElementById("official_code_zone").innerHTML="";	
	document.getElementById("city_code_zone").style.display="";

	CallXajaxWithParameterByName('af_choose_province','mng','f_sno='+qid+';','f');	
	
}
 
function choose_city(qid)
{
	document.getElementById("qu"+qid).value=document.getElementById("city_code").value;
	CallXajaxWithParameterByName('af_choose_city','mng','f_sno='+qid+';','f');	
}

function choose_zone(qid)
{
	document.getElementById("qu"+qid).value=document.getElementById("official_code").value;	
}

 //---- 整理 ---
 
 function changeemail()
 {
	inputform.email.value="";  
	refreshemail();
 }
 
 function refreshemail()
 { 	
 	inputform.action.value='refresh_email';		
	xajax_processForm(xajax.getFormValues("inputform")); 	
 }



 

 

 
 

 
 function CopyToTemp()
 {
	inputform.ExecResultTemp.value=document.getElementById("Contents").innerHTML; 
 }
