function AddFavority(title, url){ 
	if (document.all) 
		window.external.AddFavorite(url, title); 
	else if (window.sidebar) 
		window.sidebar.addPanel(title, url, "") 
} 

function AddBrowerIndexPage(url, obj){
	if( isIE ){
		obj.style.behavior = "url(#default#homepage)";
		obj.setHomePage(url);
	}else{
		var txt = "1. 將滑鼠移至網址列後，拖曳網址列上的圖片至瀏覽器\"房屋\"圖示上.\n";
		txt += "2. 從彈跳的視窗中，選擇 \"是\"\n";
		txt += "3. 恭喜，你已完成設定！";
		alert(txt);
	}
}  

/* 登入 */
function CheckLogin(x){
	if( x.LoginName.value == '請輸入帳號' || x.LoginName.value == '' ){
		alert('請輸入帳號！');
		x.LoginName.value = '';
		x.LoginName.focus();
		return false;
	}
	if( x.LoginPass.value == '' ){
		alert('請輸入密碼！');
		x.LoginPass.style.display = '';
		x.tmp.style.display = 'none';
		x.LoginPass.focus();
		return false;
	}
	return true;
}

/* 檢查身份證字號 */
/* 來源：http://blog.phptw.idv.tw/read-136.html */
function firstlettererr(id){    
	var fl=id.substr(0,1);
	var T="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //*24個*//
	var smp=id.substr(0,1)
	if (T.indexOf(smp) == -1) { return false; } else { return true; }    
}    
  
function checkid(id) {    
	if(id.length==10){ return true; } else { return false; }    
}    
  
function chfastid(id) {    
	var c = id.charAt(0);    
	if(c<"A" || c> "Z"){ return false; } else { return true; }    
}    
  
function ch12fastid(id) {    
	var c = id.charAt(1);    
	if(c!="1" && c!="2") { return false; } else { return true; }    
}    
  
function idmanber(id) { //=====後九碼為數字//    
	var bmp;    
	var d="0123456789";    
	var bab=id.length-1;    
	for (var i=1;i<=bab;i++){    
		bmp=id.substr(i,1)    
		if (d.indexOf(bmp) == -1) { return false; }    
	}    
	if(id != "0"){ return true; } else { return false; }    
}    
  
function idchackok(id) { //規則//    
	var alph = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","X","Y","W","Z","I","O");    
	var num = new Array("10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35");    
	var n=0;
	for(i=0;i<alph.length;i++)
		if(id.charAt(0)==alph[i])
			n=i;
	var tot1 = parseFloat(num[n].charAt(0)) + (parseFloat(num[n].charAt(1)) * 9);

	var tot2 = 0;
	for(i=1;i<id.length-1;i++)    
		tot2 = tot2 + parseFloat(id.charAt(i))*(9-i);    
	var tot3 = parseFloat(id.charAt(9));    
	var tot4 = tot1 + tot2 + tot3;    
	if((tot4 % 10)!=0){ return false; } else { return true; }    
}    

function idChech(id){
	var txt;
	if(checkid(id) == false){
		txt = "您的身份證字號位數不對";
		return txt;
	}

	if(chfastid(id) == false){
		txt = "您的身分證字號第一碼必須是大寫的英文字母";
		return txt;
	}

	if(ch12fastid(id) == false){
		txt = "您的身分證字號第二碼有問題";
		return txt;
	}

	if(firstlettererr(id) == false){ 
		txt = "您的身份證字號錯誤";
		return txt;
	}


	if(idmanber(id) == false){
		txt = "您的身份證字號後9碼應為數字";
		return txt;
	}

	if(idchackok(id) == false){
		txt = "您的身分證字號有問題";
		return txt;
	}
	return true;
}

function ShowChildLevel(id){
	var i=1;
	var iw = 146;
	var maxW = $(".bk_button .url").width();

	while( true ){
		var button = document.getElementById("button" + i);
		var level = document.getElementById("level" + i);

		if( button && level ){
			var src = button.src.substring( (button.src.length - 6), (button.src.length) );
			if( src == "_1.jpg" ){
				src = button.src.substring(0, (button.src.length - 6));
			}else{
				src = button.src.substring(0, (button.src.length - 4));
			}

			if( i == id ){
				button.src = src + "_1.jpg";
				level.style.display = "block";

				var ow = (iw * (parseInt(id) - 1) ) + (iw / 2);
				var nw = ow - (level.offsetWidth / 2);

				if( (nw + level.offsetWidth) > maxW ){
					nw = (maxW - 10) - level.offsetWidth;
				}
				if( nw < 0 ){
					nw = 10;
				}
				level.style.left = nw + "px";

			}else{
				button.src = src + ".jpg";
				level.style.display = "none";
			}

		}else{
			break;
		}
		i++;
	}
}



// * 廣告輪播 * //
$(function()
{
	actionCount = $(actionSelector).length;

	if(actionCount !=0)
	{
		cntActionIdx = 0;
		$(actionSelector + ":eq("+ cntActionIdx + ")").show();
	}

	if( typeof(M_BNR) != "undefined" )
		var time = (M_BNR[cntActionIdx])? M_BNR[cntActionIdx] : actionInterval;
	else
		var time = actionInterval;

	setTimeout("ShowAction();", time);

});

var cntActionIdx = -1;
var actionCount = 0;
var actionInterval = 6000;
var actionSelector = "#action_bnr span";

function ShowAction()
{
	if(actionCount < 2) return;

	if(cntActionIdx != -1)
	{
		$(actionSelector + ":eq("+ cntActionIdx + ")").fadeOut("slow",function()
		{
			if(cntActionIdx +1 < actionCount )
			{
				cntActionIdx++;
			}
			else
			{
				cntActionIdx = 0;
			}

			$(actionSelector + ":eq("+ cntActionIdx + ")").fadeIn("slow",function()
			{
				var time = (M_BNR[cntActionIdx])? M_BNR[cntActionIdx] : actionInterval;
				setTimeout("ShowAction();", time);
			});
			
		});
	}
}

// * 跑馬燈產品 * //
$(function(){
		$("#MarqueeArea").bind("mouseenter", StopMoveDIV );
		$("#MarqueeArea").bind("mouseleave", StartMoveDIV );

		var def_height = 20;
		var hH = $("#FirstSilder").height();

		if( hH < def_height ){
			hH = def_height;
			$("#FirstSilder").height( def_height );
		}

		$("#SecondSilder").html( $("#FirstSilder").html() );

		var nowY = parseInt( $("#FirstSilder").css("top") );

		SetPosition("#FirstSilder", "#SecondSilder");

		hFlag = window.setTimeout("StartMoveDIV()", 2000);

	//}
});

function SetPosition(first, second ){

	var nowH = $(first).height();
	var nowY = parseInt( $(first).css("top") );

	$(second).css("top", (nowH + nowY) + "px" );
}

var hFlag = 0;
var Htmp = 0;
function StartMoveDIV(){
	var move = ( isIE )? 2 : 1;
	var first = "#FirstSilder";
	var second = "#SecondSilder";
	var item_height = $("#item:eq(0)").height();
	var timer = 20;

	var nowH = 0 - $(first).height();

	$(first).css("top", (parseInt( $(first).css("top") ) - move) + "px" );
	$(second).css("top", (parseInt( $(second).css("top") ) - move) + "px" );

	var fm = parseInt( $(first).css("top") );
	var sm = parseInt( $(second).css("top") );

	if( fm <= nowH ){
		$(first).css("top", $(first).height() + "px" );
	}
	if( sm <= nowH ){
		$(second).css("top", $(second).height() + "px" );
	}

	Htmp ++;

	if( (move * Htmp) >= item_height ){
		timer = 2000;
		Htmp = 0;
	}

	hFlag = window.setTimeout("StartMoveDIV()", timer);
}

function StopMoveDIV(){
	window.clearTimeout(hFlag);
}
