function Url_in(l){
window.open(l,'_top','');
}

function Url_out(l){
window.open(l,'','');
}

function Url_join(l){
window.open(l,'member_join','');
}

function time_rota() {  //時間自動計算
now = new Date(); 
d="0"+now.getDate();
h="0"+now.getHours();
m="0"+now.getMinutes(); 
s="0"+now.getSeconds(); 
if(d>9){d=now.getDate();} 
if(h>9){h=now.getHours();} 
if(m>9){m=now.getMinutes();} 
if(s>9){s=now.getSeconds();} 
document.Time.CLOCK.value =h+":"+m+":"+s;

if(Number(document.Time.CLOCK_SET_D.value)==d){
	h_l=(Number(document.Time.CLOCK_SET_H.value)-h);
	m_l=(Number(document.Time.CLOCK_SET_I.value)-m-1);
	s_l=(59-s);
	//if(h_l<9){h_l="0"+h_l;} 
	if ( s_l == 60 ){ s_l = 0;}
	if(m_l<0){
		h_show = h_l - Math.ceil(m_l/60) - 1;
		m_show =  60 - Math.abs(m_l);
		s_show = s_l;
	} else {
		h_show = h_l;
		m_show = m_l;
		s_show = s_l;
	}
	
	//if(s_l<9){s_l="0"+s_l;} 
	if(h_show>=0&&m_show>=0&&s_show>=0){
		document.Time.CLOCK_LAST.value ="剩餘"+h_show+"小時"+m_show+"分"+s_show+"秒";
	} else {
		if ( document.Time.CLOCK_LAST.value != "時間已到!" &&  document.Time.CLOCK_LAST.value != "" ){
			//MoveLayer('lyr_fix_clock');
		}
		document.Time.CLOCK_LAST.value ="時間已到!";
		
	}
} else {
	document.Time.CLOCK_LAST.value ="時間已到!";
}
setTimeout( 'time_rota()', 1000);
} 

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 YY_checkform() { //v4.65
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(parseInt(myV))||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){
	  alert('以下必填欄位出現錯誤:\t\t\t\t\t\n\n'+myErr);
	 }else{
		 //nick增加,交流大廳只能按一次
		if(args[0]== 'form_msg'){
			 //alert(args[0]);
			 document.form_msg.Submit.disabled=true;
		}
	}
  document.MM_returnValue = (myErr=='');
}

function LvCounter(field, countfield, maxlimit) {
if (field.value > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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];}
}

function Con_in( l ){
	if( confirm( "是否離開遊戲?\n\n( 提醒您，如果中途離開遊戲，此關分數無法儲存唷! )" ) ){
		window.open(l,'_top','');
	}
}

function Del_in( l ){
	if( confirm( "此動作無法復原!\n\n是否確定執行此動作?" ) ){
		window.open(l,'_top','');
	}
}

function Con_out( l ){
	if( confirm( "是否離開遊戲?\n\n( 提醒您，如果中途離開遊戲，此關分數無法儲存唷! )" ) ){
		window.open( l,'','');
	}
}

function Word_max(l,m,c){
	if ( l.value.length > m ){
		l.value = l.value.substring(0, m);
		alert("超過"+m+"字!");
	} else {
		c.value = m - l.value.length;
	}
}

function Open_line(l){
	if ( l.className=='f_close' ){
		l.className='f_open';
	} else {
		l.className='f_close';
	}
}

function Color_line(l,m){
	if ( l.style.backgroundColor=='' ){
		l.style.backgroundColor=m;
	} else {
		l.style.backgroundColor='';
	}
}

function Close_text(){
	ftext.className='box_close';
}

function Pic_view(){
	pic_view.className='box_open';
}

function Box_com_open(l){
	box_com.className='box_open';
	box_com_pic.src='images/new/bng/com/action_pic_'+l+'.jpg';
	box_com_pic.useMap='#map_'+l;
}

function Box_com_close(){
	box_com.className='box_close';
}

function Box_clock_open(){
	box_clock.className='box_open';
	lyr_bng_pic_room.className='box_close';
}

function Box_clock_close(){
	box_clock.className='box_close';
	lyr_bng_pic_room.className='box_open';
}

function Box_wall_open(){
	box_wall.className='box_open';
}

function Box_wall_close(){
	box_wall.className='box_close';
}

function Box_bed_open(){
	box_bed.className='box_open';
}

function Box_bed_close(){
	box_bed.className='box_close';
}

function Box_pic_open(){
	box_pic.className='box_open';
}

function Box_pic_close(){
	box_pic.className='box_close';
}

function Box_id_open(){
	box_id.className='box_open';
}

function Box_id_close(){
	box_id.className='box_close';
}

function Send_id (l){
	box_id.form_check_id.submit();
}

function Fix_flash(){
	//lyr_fix_clock.style.posTop='20';
	MoveLayer('lyr_fix_clock');
	//index_clock.movieValue='images/swf/html/clock.swf?sec=0';
}

function Login(){
	//lyr_fix_clock.style.posTop='20';
	alert('您已經登入!');
	//index_clock.movieValue='images/swf/html/clock.swf?sec=0';
}

function Vip(){
	//lyr_fix_clock.style.posTop='20';
	alert('此為VIP功能!');
	//index_clock.movieValue='images/swf/html/clock.swf?sec=0';
}

function Buy( l ){
	if( confirm( "請再次確認訂單!\n\n是否進入購物流程?" ) ){
		window.open(l,'_top','');
	}
}

function Worning(l){
	//lyr_fix_clock.style.posTop='20';
	alert(l);
	//index_clock.movieValue='images/swf/html/clock.swf?sec=0';
}

function MoveLayer(layerName) {
　var x = 10;//浮動廣告層固定於瀏覽器的x方向位置
　var y = 480;//浮動廣告層固定於瀏覽器的y方向位置
　var diff = (document.body.scrollTop + y - document.all.lyr_fix_clock.style.posTop)*.40;
　var y = document.body.scrollTop + y - diff;
　eval("document.all." + layerName + ".style.posTop = y");
　eval("document.all." + layerName + ".style.posLeft = x");//移動廣告層
　setTimeout("MoveLayer('lyr_fix_clock');", 20);//設置20毫秒後再調用函數MoveLayer()
}

function showDiv(id, toggle) {
	var div = document.getElementById(id);
	switch(toggle){
		case 'default':
			if(div.style.display == 'block') 
				div.style.display = 'none';
			else 
				div.style.display = 'block';
		break;
		
		case 'show':
			div.style.display = 'block';
		break;
		
		case 'hide':
			div.style.display = 'none';
		break;
	}
}

function syncForm() {
	if($("#sync")[0].checked == true){
		$("#rec_name")[0].value = $("#pay_name").val();
		$("#rec_mobile")[0].value = $("#pay_mobile").val();
		$("#rec_telzip")[0].value = $("#pay_telzip").val();
		$("#rec_telnum")[0].value = $("#pay_telnum").val();
		$("#rec_telext")[0].value = $("#pay_telext").val();
		$("#rec_email")[0].value = $("#pay_email").val();
		$("#rec_address")[0].value = $("#pay_address").val();
	}
	else{
		$("#rec_name")[0].value = '';
		$("#rec_mobile")[0].value = '';
		$("#rec_telzip")[0].value = '';
		$("#rec_telnum")[0].value = '';
		$("#rec_telext")[0].value = '';
		$("#rec_email")[0].value = '';
		$("#rec_address")[0].value = '';
	}
}