/*
c http://www.elfin.tw
All Rights Reserved.
*/
function end_msg(tmpvalue){
	result = "";
	switch(tmpvalue){
		case "success_add":
		result = "新增成功";
		break;
		
		case "success_edit":
		result = "修改成功";
		break;
		
		case "success_del":
		result = "刪除成功";
		break;
		
	}
	if(result!=""){	alert(result);}
}

function openwin2(url,win_name,toolbar,directories,menubar,status,resizable,scrollbars,top,left,width,height){
	chk_win = window.open(url,win_name,'toolbar='+toolbar+',directories='+directories+',menubar='+menubar+',status='+status+',resizable='+resizable+',scrollbars='+scrollbars+',top='+top+',left='+left+',width='+width+',height='+height+'');
	chk_win.focus();
	return false;
}

function openwin(url,width,height){
	var newopen = showModalDialog(url,false,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:0;edge: Raised; center: Yes; help: No;");
}

function opendlwin(url,win_name,toolbar,directories,menubar,status,resizable,scrollbars,top,left,width,height){
	chk_win = window.open('ftp://wsguest:edcrfv654@wenshu.org.tw/'+url,win_name,'toolbar='+toolbar+',directories='+directories+',menubar='+menubar+',status='+status+',resizable='+resizable+',scrollbars='+scrollbars+',top='+top+',left='+left+',width='+width+',height='+height+'');
	chk_win.focus();
	return false;
}

/*日曆*/
function cal_location(){
	//span_cal.style.left = window.event.clientX;	
}

/*上線日期*/
function cal_chg(tmpyear,tmpmon,tmpdate,tmpname){
	tmpvalue= tmpyear + "-" + tmpmon + "-" + tmpdate;
	cal(tmpvalue,tmpname);
}

function cal_click(tmpyear,tmpmon,tmpdate,tmpname){
	tmpmon = cut_r(("0"+tmpmon),2);
	tmpdate = cut_r(("0"+tmpdate),2);
	tmpvalue= tmpyear + "-" + tmpmon + "-" + tmpdate;
	document.all(tmpname).value=tmpvalue
	span_cal.innerHTML="";
}

function cal(tmpdate,tmpname){
	now_day = new Date();
	now_year = now_day.getFullYear() ;

	var show_cal = "";
	if(tmpdate!=""){
		var chgdate = new RegExp("-","g");
		tmpdate = tmpdate.replace(chgdate,"/");
		new_date = new Date(tmpdate);
	}
	else{
		new_date = new Date();
	}
	//day.setDate(1); 
	getdate = new_date.getDate();
	//getweek = new_date.getDay();
	getmon = new_date.getMonth();
	getyear=new_date.getFullYear() ;
        getweek = new Date(getyear,getmon,1).getDay();
	check = (getyear-1911)%4;	//閏月
	
	numdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31) 
	if(check == 0){ numdays[1] = 29 }

	show_cal+="<table border=0 cellspacing = 0 cellpadding=3 class=cal>";
	show_cal+="<tr><td colspan = \"7\" align = center><table border=0>";
	show_cal+="<td><select name=\"selyear\" onchange=\"cal_chg(this.value,(getmon+1),getdate,'"+tmpname+"')\">";
	show_cal+="<option value=\""+(now_year-1)+"\""+">"+(now_year-1)+"</option>";
	for(tmpcnt=now_year;tmpcnt<now_year+5;tmpcnt++){
		chk_sel = "";
		if(tmpcnt==getyear){
			chk_sel = " selected";
		}
		show_cal+="<option value=\""+tmpcnt+"\""+chk_sel+">"+tmpcnt+"</option>";
	}
	show_cal+="</select></td><td>年</td>"
	
	show_cal+="<td><select name=\"selmon\" onchange=\"cal_chg(getyear,this.value,getdate,'"+tmpname+"')\">";
	for(tmpcnt=1;tmpcnt<=12;tmpcnt++){
		chk_sel = "";
		if(tmpcnt==getmon+1){
			chk_sel = " selected";
		}
		show_cal+="<option value=\""+tmpcnt+"\""+chk_sel+">"+tmpcnt+"</option>";
	}
	show_cal+="</select></td><td>月</td>"
	
	show_cal+="</table></tr>";
	show_cal+="<tr><td style=\"color:#FF0000\" align = center width = 25>日</td><td align = center width = 25>一</td><td align = center width = 25>二</td><td align = center width = 25>三</td><td align = center width = 25>四</td><td align = center width = 25>五</td><td style=\"color:#006600\" align = center width = 25>六</td></tr>";
	
	for(tmpcnt_s=1-getweek;tmpcnt_s<=31;tmpcnt_s+=7){
		show_cal+="<tr align = center>";
		for(tmpcnt_e=tmpcnt_s;tmpcnt_e<tmpcnt_s+7;tmpcnt_e++){
			chk_sel = "";
			if(tmpcnt_e==getdate){
				chk_sel = " bgcolor=\"#FFFFCC\"";
			}
			show_onclick = " onclick = \"cal_click(getyear,(getmon+1),"+tmpcnt_e+",'"+tmpname+"')\" style=\"cursor:hand\""
			show_mouse = " onmouseover=\"this.className='cal_over'\" onmouseout=\"this.className=''\"";
			if((tmpcnt_e>0)&&(tmpcnt_e<=numdays[getmon])){
				show_cal+="<td align = center height = 25"+chk_sel+show_onclick+show_mouse+">"+tmpcnt_e+"</td>";
			}
			else{
				show_cal+="<td align = center>&nbsp;</td>";
			}
		}
		show_cal+="</tr>";
	}
	show_cal+="<tr><td colspan = 7 align = center><input type = button name = bu_cls value = 關閉 onclick=\"span_cal.innerHTML='';\"></td></tr>";
	show_cal+="</table>";
	
	span_cal.innerHTML = show_cal;
}

/*出生日期*/
function cal_birth_chg(tmpyear,tmpmon,tmpdate,tmpname){
	tmpvalue= tmpyear + "-" + tmpmon + "-" + tmpdate;
	cal_birth(tmpvalue,tmpname);
}

function cal_birth_click(tmpyear,tmpmon,tmpdate,tmpname){
	tmpmon = cut_r(("0"+tmpmon),2);
	tmpdate = cut_r(("0"+tmpdate),2);
	tmpvalue= tmpyear + "-" + tmpmon + "-" + tmpdate;
	document.all(tmpname).value=tmpvalue
	span_cal.innerHTML="";
}

function cal_birth(tmpdate,tmpname){
	now_day = new Date();
	now_year = now_day.getYear() ;

	var show_cal = "";
	if(tmpdate!=""){
		var chgdate = new RegExp("-","g");
		tmpdate = tmpdate.replace(chgdate,"/");
		new_date = new Date(tmpdate);
	}
	else{
		new_date = new Date();
	}
	
	//day.setDate(1); 
	getdate = new_date.getDate();
	getweek = new_date.getDay();
	getmon = new_date.getMonth();
	//getyear = new_date.getYear();
	getyear = new_date.getFullYear() ;
	check = (getyear-1911)%4;	//閏月
	
	numdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31) 
	if(check == 0){ numdays[1] = 29 }

	show_cal+="<table border=0 cellspacing = 0 cellpadding=3 class=cal>";
	show_cal+="<tr><td colspan = \"7\" align = center><table border=0>";
	show_cal+="<td><select name=\"selyear\" onchange=\"cal_birth_chg(this.value,(getmon+1),getdate,'"+tmpname+"')\">";
	for(tmpcnt=1937;tmpcnt<=now_year;tmpcnt++){
		chk_sel = "";
		if(tmpcnt==getyear){
			chk_sel = " selected";
		}
		show_cal+="<option value=\""+tmpcnt+"\""+chk_sel+">"+tmpcnt+"</option>";
	}
	show_cal+="</select></td><td>年</td>"
	
	show_cal+="<td><select name=\"selmon\" onchange=\"cal_birth_chg(getyear,this.value,getdate,'"+tmpname+"')\">";
	for(tmpcnt=1;tmpcnt<=12;tmpcnt++){
		chk_sel = "";
		if(tmpcnt==getmon+1){
			chk_sel = " selected";
		}
		show_cal+="<option value=\""+tmpcnt+"\""+chk_sel+">"+tmpcnt+"</option>";
	}
	show_cal+="</select></td><td>月</td>"
	
	show_cal+="</table></tr>";
	show_cal+="<tr><td style=\"color:#FF0000\" align = center width = 25>日</td><td align = center width = 25>一</td><td align = center width = 25>二</td><td align = center width = 25>三</td><td align = center width = 25>四</td><td align = center width = 25>五</td><td style=\"color:#006600\" align = center width = 25>六</td></tr>";
	
	for(tmpcnt_s=1-getweek;tmpcnt_s<=31;tmpcnt_s+=7){
		show_cal+="<tr align = center>";
		for(tmpcnt_e=tmpcnt_s;tmpcnt_e<tmpcnt_s+7;tmpcnt_e++){
			chk_sel = "";
			if(tmpcnt_e==getdate){
				chk_sel = " bgcolor=\"#FFFFCC\"";
			}
			show_onclick = " onclick = \"cal_birth_click(getyear,(getmon+1),"+tmpcnt_e+",'"+tmpname+"');showDiv('span_cal', false);\" style=\"cursor:hand\""
			show_mouse = " onmouseover=\"this.className='cal_over'\" onmouseout=\"this.className=''\"";
			if((tmpcnt_e>0)&&(tmpcnt_e<=numdays[getmon])){
				show_cal+="<td align = center height = 25"+chk_sel+show_onclick+show_mouse+">"+tmpcnt_e+"</td>";
			}
			else{
				show_cal+="<td align = center>&nbsp;</td>";
			}
		}
		show_cal+="</tr>";
	}
	show_cal+="<tr><td colspan = 7 align = center><input type = \"button\" name = \"bu_cls\" value = \"關閉\" onclick=\"span_cal.innerHTML='';showDiv('span_cal', false);\"></td></tr>";
	show_cal+="</table>";
	
	span_cal.innerHTML = show_cal;
}


function showDiv(sDivID, bState) {
    var oDiv = document.getElementById(sDivID);
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        var oIframe = document.getElementById('HelpFrame');
        oIframe.scrolling = 'no';
    }
    catch (e) {
        var oIframe = document.createElement('iframe');
        var oParent = oDiv.parentNode;
        oIframe.id = 'HelpFrame';
        oParent.appendChild(oIframe);
    }
    oIframe.frameborder = 0;
    oIframe.style.position = 'absolute';
    oIframe.style.top = 0;
    oIframe.style.left = 0;
    oIframe.style.display = 'none';
    @end @*/
    if (bState) {
        oDiv.style.display = 'block';
        /*@cc_on
        @if (@_jscript_version >= 5)
        oIframe.style.top = oDiv.style.top;
        oIframe.style.left = oDiv.style.left;
        oIframe.style.zIndex = oDiv.style.zIndex - 1;
        oIframe.style.width = parseInt(oDiv.offsetWidth);
        oIframe.style.height = parseInt(oDiv.offsetHeight);
        oIframe.style.display = 'block';
        @end @*/
    }
    else {
        /*@cc_on
        @if (@_jscript_version >= 5)
        oIframe.style.display = 'none';
        @end @*/
        oDiv.style.display = 'none';
    }
}

function cut_r(tmpvalue, cutlen){
	if (cutlen <= 0)
		return "";
	else if (cutlen > String(tmpvalue).length)
		return tmpvalue;
	else {
		var iLen = String(tmpvalue).length;
		return String(tmpvalue).substring(iLen, iLen - cutlen);
	}
}

function fun_num(tmp_value,err_msg){	//數字
	var re = /[^0-9]{1,}/;
	if(re.test(tmp_value)){
		return (err_msg+"　格式錯誤(請填寫數字)!!\n");
	}
	return "";
}

function fun_alpha_num(tmp_value,err_msg){	//小寫字母或數字
	var re = /[^a-z0-9]{1,}/;
	if(re.test(tmp_value)){
		return (err_msg+"　格式錯誤(請填寫小寫字母或數字)!!\n");
	}
	return "";
}

function fun_tel_num(tmp_value,err_msg){	//數字
	var re = /[^0-9\-]{1,}/;
	if(re.test(tmp_value)){
		return (err_msg+"　格式錯誤(請填寫數字 或 - 符號)!!\n");
	}
	return "";
}

function fun_lenone(tmp_value,tmp_len,err_msg){	//長度(<len)
	if(tmp_value.length < tmp_len){
		return(err_msg+"　長度錯誤(最少需輸入"+ tmp_len + "個字)!!\n")
	}
	return "";
}

function fun_email(tmp_value){
	if(!(tmp_value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)){
		return("E-Mail　格式錯誤!!\n");
	}
　　return "";
}

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_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_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];}
}
