//+=========================Dreamweaver js函數====================================================
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-=========================Dreamweaver js函數====================================================
//=========================刪除確認====================================================
function del_confirm(){
	return confirm('您確定要刪除該筆資料嗎!!');
}
//=========================刪除確認====================================================
//=========================月曆===========================================================================
//textbox-> onclick="calendar()"
function calendar(){
	showModalDialog("../include/calendar.htm?dd=1",window,"dialogHeight:250Px;dialogWidth:220px;status:no;help:no");
}
//=========================月曆===========================================================================
//=========================開特殊新視窗====================================================
function open_fit_window(url,w,h){
	var width, height, args;							//宣告變數
	width=(w<window.screen.availWidth-50)?w+50:window.screen.availWidth-50;
	height=(h<window.screen.availHeight-50)?h+50:window.screen.availHeight-50;
	args="width="+width+",height="+height+",resizable=yes,scrollbars=yes,status=no,top=0,left=0";			
	window.open(url,"", args);
	return false;
}
//=========================開特殊新視窗====================================================
//=========================回應表格縮放====================================================
function reply_show(){
	var show, obj_img, obj_tab;
	obj_img=event.srcElement;
	obj_tab=event.srcElement.nextSibling.nextSibling;
	if (obj_img.alt=="展開回覆"){
		obj_img.alt="隱藏回覆"
		obj_img.src="../images/reply_close.jpg"
		obj_tab.style.display="block";
	}else{
		obj_img.alt="展開回覆"
		obj_img.src="../images/reply_open.jpg"
		obj_tab.style.display="none";
	}
}
//=========================回應表格縮放====================================================
//=========================計數器用Cookie=================================================
function setCookie(){
	 var str_time=new Date();
	 str_time.setTime(str_time.getTime()+24*60*60*1000);
	 document.cookie = 'visitor=yunlin-travel; expires='+str_time.toGMTString();
}
//=========================計數器用Cookie=================================================
//============================去掉Flash框==========================
function show_flash(str_flash){
	var obj_flash=document.all(str_flash);
	document.write(obj_flash.outerHTML);
	obj_flash.style.display="none";
}
//============================去掉Flash框==========================
//=========================表單欄位說明文字處理====================================================
//網頁初始,載入無障礙提示文字
function LoadAlt(){
	for (var i=0;obj_input=form1.all[i];i++){
		if (((obj_input.tagName=="INPUT") && (obj_input.type=="text"))||(obj_input.tagName=="TEXTAREA")){
			var obj_attribute=(obj_input.value)?"value":"innerText";
			obj_input.setAttribute(obj_attribute,obj_input.alt);
			obj_input.onfocus=ClearAlt;
			obj_input.onblur=ShowAlt;
		}
	}
}
//表單上傳,清除無障礙提示文字
function EraseAlt(){
	for (var i=0;obj_input=form1.all[i];i++){
		if (((obj_input.tagName=="INPUT") && (obj_input.type=="text"))||(obj_input.tagName=="TEXTAREA")){
			var obj_attribute=(obj_input.value)?"value":"innerText";
			var obj_value=obj_input.getAttribute(obj_attribute).replace(/(^\s+)|(\s+$)/g,"");
			if (obj_value==obj_input.alt) obj_input.setAttribute(obj_attribute,"");
		}
	}
}
//移入欄位,清空無障礙提示文字
function ClearAlt(){
	obj=event.srcElement;
	if (obj.value==obj.alt) obj.value='';
}
//移出欄位,顯示無障礙提示文字
function ShowAlt(){
	obj=event.srcElement;
	if (obj.value=='') obj.value=obj.alt;
}
//=========================表單欄位說明文字處理====================================================
//=========================欄位格式檢核====================================================
function check_basic_field(){
	obj_form=event.srcElement; //document.all("form1");
	for (var i=0;obj_input=obj_form.all[i];i++){
		if (obj_input.validate){
			var validate=obj_input.validate.split(",")			
			var obj_value=((obj_input.value)?obj_input.value:obj_input.innerText).replace(/(^\s+)|(\s+$)/g,"");
			var obj_name=obj_input.alt.substring(5,obj_input.alt.length-2);
			for (var j=0;j<validate.length;j++){					
				switch (validate[j]){
				case "row":
					obj_name+=(obj_input.parentElement.parentElement.rowIndex+1);
					break;		
				case "null":					
					if (((obj_value=="")||(obj_value==obj_input.alt))&&(!obj_input.vdnullold)){						
						alert("["+obj_name+"]請勿空白");return false;	
					}
					break;
				case "len":
					if (obj_value.length>obj_input.vdlength){		
						alert("["+obj_name+"]請勿超過"+obj_input.vdlength+"個字");return false;		
					}
					break;
				case "num":
					if ((obj_value=="")||(obj_value==obj_input.alt)) break;
					var range=obj_input.vdrange.split(",");
					if ((obj_value<parseInt(range[0]))||(obj_value>parseInt(range[1]))||(obj_value!=parseInt(obj_value))){
						alert("["+obj_name+"]請輸入"+range[0]+"~"+range[1]+"的整數");return false;
					}	
					break;				
				case "reg":	
					if ((obj_value=="")||(obj_value==obj_input.alt)) break;
					if (obj_value.match(new RegExp("^"+obj_input.vdregular+"$","i"))==null){
						alert("["+obj_name+"]請使用正確格式");return false;
					}
					break;
				case "ext":	  
					if ((obj_value=="")||(obj_value==obj_input.alt)) break;
					if (obj_value.match(new RegExp("[\.]("+obj_input.vdregular+")","i"))==null){
						alert("["+obj_name+"]請勿上傳不合法的檔案");return false;
					}
					break;       //?!asp$|php$ 不能為程式檔  //jpg$|gif$|bmp   必須為圖片檔
				} 
			}			
		}		
	}
	EraseAlt();	//清除無障礙提示文字
	return true;
}

//=========================欄位格式檢核====================================================

//=========================問卷格式檢核====================================================
function check_inquire_field(){
	obj_form=event.srcElement;
	for (var i=0;obj_input=obj_form.all[i];i++){
		if (obj_input.validate){
			var validate=obj_input.validate.split(",")			
			var obj_value=((obj_input.value)?obj_input.value:obj_input.innerText).replace(/(^\s+)|(\s+$)/g,"");
			var obj_name=obj_input.alt.substring(5,obj_input.alt.length-2);
			for (var j=0;j<validate.length;j++){					
				switch (validate[j]){
				case "null":					
					if (((obj_value=="")||(obj_value==obj_input.alt))&&(!obj_input.vdnullold)){						
						alert("["+obj_name+"]請勿空白");return false;	
					}
					break;			
				case "len":
					if (obj_value.length>obj_input.vdlength){		
						alert("["+obj_name+"]請勿超過"+obj_input.vdlength+"個字");return false;		
					}
					break;
				case "one":		
					temp_name=obj_input.name.replace(/(^inq_rad)|(^inq_chk)/g,"");
					temp_check="";
					for (var k=0;obj_choose=obj_form.all.tags("INPUT")[k];k++){
						if (((obj_choose.name=="inq_rad"+temp_name) || (obj_choose.name=="inq_chk"+temp_name)) && (obj_choose.checked)) temp_check="checked";
					}
					if (temp_check==""){
						alert("["+obj_name+"]請至少勾選一個");return false;
					}
					break;	
				case "note":
					temp_id=obj_input.id.replace(/^txt/g,"");
					for (var k=0;obj_choose=obj_form.all.tags("INPUT")[k];k++)
						if ((obj_choose.id=="hid"+temp_id) || (((obj_choose.id=="rad"+temp_id) || (obj_choose.id=="chk"+temp_id)) && (obj_choose.checked)))
							if (((obj_value=="")||(obj_value==obj_input.alt))&&(!obj_input.vdnullold)){						
								alert("["+obj_name+"]請勿空白");return false;	
							}							
					break;
				}
			}			
		}		
	}
	EraseAlt();	//清除無障礙提示文字
	return true;
}
//=========================問卷欄位格式檢核====================================================
//============================動態產生輸入附檔欄位==========================
//更換多筆的資料欄位型態
function changeField(){
	obj_file=event.srcElement.parentElement.children(1);
	obj_data=event.srcElement.parentElement.children(2);
	if (event.srcElement.value=="file"){
		obj_file.style.display="inline";
		obj_data.style.display="none";
	}else if (event.srcElement.value=="link"){
		obj_file.style.display="none";
		obj_data.style.display="inline";
	}	
	obj_file.outerHTML=obj_file.outerHTML;	obj_data.value="";	
}


//新增多欄資料列
function InsertRow(){
	obj=document.getElementById('txt_fieldnum')
	obj_value=obj.value.replace(/(^\s+)|(\s+$)/g,"").replace(/[,]+/g,"");
	if (obj_value.length==0){
		alert("附檔數量請勿空白!!");return false;
	}else if ((obj_value<0)||(obj_value>100)||(obj_value!=parseInt(obj_value))){			
		alert("附檔數量請輸入0~100的正整數");return false;
	}else{
		rownum=obj_value;
	}	

	var tab_field=document.all("tab_field");
	var	row_exist=tab_field.innerHTML;	
	var row_new,cell_del,cell_title,cell_data,cell_order;
	for (i=0;i<rownum;i++){
	new_row=tab_field.insertRow();
	cell_del=new_row.insertCell();	cell_title=new_row.insertCell();
	cell_data=new_row.insertCell();	cell_order=new_row.insertCell();
	cell_del.innerHTML="<input name='btn_fielddel' type='button' id='btn_fielddel' onclick='js:DeleteRow()' value='刪除'>";
	cell_title.innerHTML="標題:<input name='txt_fieldtitle[]' type='text' size='20' alt='--請輸入多欄資料-標題--' validate='row,null,len' vdlength='100'>";	
	cell_data.innerHTML="<select name='ddl_fieldtype[]' onchange='js:changeField()'><option value='file' selected>檔案</option><option value='link'>連結</option></select>"
					   +"<input name='txt_fieldfile[]' type='file' size='15' onchange='js:this.nextSibling.value=this.value;'>"
					   +"<input name='txt_fielddata[]' type='text' size='23' alt='--請輸入多欄資料-資料--' validate='row,null,len' vdlength='100' style='display=none'>"			   			
	cell_order.innerHTML="順序:<input name='txt_fieldorders[]' type='text' size='5' alt='--請輸入多欄資料-順序--' validate='row,num' vdrange='-100,100'>";	
	}
}

//刪除多欄資料列
function DeleteRow(){
	var obj_table=event.srcElement.parentElement.parentElement.parentElement;
	var del_index=event.srcElement.parentElement.parentElement.rowIndex;
	obj_table.deleteRow(del_index);
}

//建立已存在多欄資料表格
function ExistRow(num, title, path, format){
	//判斷物件型態
	var obj_format,tab_exist,last_row,cell_del,cell_file;
	if (format=='link'){
		obj_format='連結：<a href="'+ path +'" target="_blank" title="'+ title +'">'+ title +'</a>';
	}else if (format.substr(0,6)=='image/'){
		obj_format='圖檔：<img border="0" src="'+ path +'" width="50" height="50" alt="'+ title +'" align="middle">';
	}else{
		obj_format='附檔：<a href="'+ path +'" target="_blank" title="'+ title +'">'+ title +'</a>';
	}
	//判斷放置位置
	tab_exist=document.getElementById('tab_exist');
	last_row=tab_exist.rows[tab_exist.rows.length-1];
	if ((!last_row) || (last_row.cells.length==6))
		last_row=tab_exist.insertRow();
	//放入格子中
	cell_del=last_row.insertCell();
	cell_file=last_row.insertCell();
	cell_del.width="10%"
	cell_file.width="20%"
	cell_del.innerHTML='<input type="checkbox" name="chk_fielddel[]" value="'+ num +'"><label for="chk_del">刪除</label>';
	cell_file.innerHTML=obj_format;
}
//============================動態產生輸入附檔欄位==========================
//=========================CheckBox全選====================================================
function SetAllCheck(obj_check, obj_table){
	var obj_label=document.all(obj_check.value);
	obj_label.innerText=(obj_check.checked)?"全清":"全選";
	for (var i=0;obj_input=obj_table.all.tags("input")[i];i++){
		if (obj_input.type=="checkbox")	obj_input.checked=obj_check.checked;				   
	}
}
//=========================CheckBox全選====================================================
