//顯示子選單
function trans_menu( key, is_show, is_det, is_det_show ){
	if( !document.getElementById(key).className ){
		document.getElementById(key).style.backgroundPosition = is_show ? '0 -45px' : '0 0px';
	}
	//有子選單
	if( is_det )
		document.getElementById(key+'_det').style.display = is_det_show ? 'block' : 'none';
}
function trim( str ){
	re = /^[ ]+|[ ]+$/g;
	return str.replace(re,"");
}
function cancelEsc(e){
	var e = window.event;
	if( e.keyCode==27 )event.returnValue = false;
	return false;
}

function openWin( url, set, name ){
    var winID = window.open('blank.htm',name, "top=10,width=780,height=650,left=10,scrollbars=1,resizable=yes," + set );
    winID.location.href=url;
    if( winID.opener==null )
        winID.opener = window;
    winID.opener.name = 'opener';
}

function download_link(e){
	if( !e ){
		var e = window.event; // ?? e 這時候有 scope 的問題嗎?
    }
	alert( "請按滑鼠右鍵 -> 選另存目標下載" );
	e.returnValue = false;
	return false;
}

function parseInt2(s){
   var num = (s+'').replace( ',', '' );
   var patrn=/^[-,+]{0,1}[0-9|\.]{0,}$/;   
   if (!patrn.exec(num))return 0;
   //去掉第一個零
   num = num.replace( /^0/, '' );
   if( num=='' )num = 0;
   return parseInt(num);
}

//更換縣市下拉
function reset_addr2( prefix, city_code ){
	var obj = document.getElementById('ADDR2'+prefix);	
	var now = new Date();
	var tt = now.getTime();
	new Ajax.Request( 'ajax.php?time=' + tt, { method:'get',
		parameters:{ 'item':'select_addr', 'city_code':city_code },
		onSuccess: function(transport){						
			var rs = transport.responseText.evalJSON();
			obj.options.length = 1;			
			var list = rs.list;
			if( list.length > 0 ){
				obj.options[0].text = '請選擇鄉鎮別';
			}else{
				obj.options[0].text = '';
			}
			for( var i=0; i<list.length; i++ ){
				obj.options.add( new Option( list[i][1], list[i][0] ) );
			}
		}
	});
}

//將輸入值存入SESSION
function save_temp_input( name, value ){	
	var now = new Date();
	var tt = now.getTime();
	new Ajax.Request( 'ajax.php?time=' + tt, { method:'get',
		parameters:{ 'item':'save_session_value', 'name':name, 'value':value },
		onSuccess: function(transport){
			var rs = transport.responseText;
		}
	});
}
//==============================================================================
function setCookie(name, value, expires, path, domain, secure){
	var now = new Date( );
　  now.setTime( now.getTime( ) + 1000*expires );
    document.cookie= name + "=" + escape(CodeCookie(value)) +
        ((expires) ? "; expires=" + now.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name){ 　 
	var strArg=name+"="; 
	var nArgLen=strArg.length; 
	var nCookieLen=document.cookie.length; 
	var nEnd; 
	var i=0; 
	var j; 

	while( i<nCookieLen ){ 
		j=i+nArgLen; 
		if (document.cookie.substring(i,j)==strArg){ 
			nEnd=document.cookie.indexOf (";",j); 
			if (nEnd==-1) nEnd=document.cookie.length; 
			return DecodeCookie(unescape(document.cookie.substring(j,nEnd))); 
		} 
		i=document.cookie.indexOf(" ",i)+1; 　 
		if (i==0) break; 
	} 
	return null; 
} 



function deleteCookie(name, path, domain){
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//COOKIE中文編碼
function CodeCookie(str) { 
　 var strRtn=""; 

　for (var i=str.length-1;i>=0;i--) 
　 { 
　　 strRtn+=str.charCodeAt(i); 
　　 if (i) strRtn+="a"; //用a作分隔符 
　 } 
　 return strRtn; 
} 


function DecodeCookie(str){ 
　 var strArr; 
　 var strRtn=""; 

　strArr=str.split("a"); 

　for (var i=strArr.length-1;i>=0;i--) 
　 strRtn+=String.fromCharCode(eval(strArr[i])); 

　return strRtn; 
} 

function freight_desc(){
	openWin( '?pid=freight_desc', 'top=150,left=250,width=350px,height=500px' );
}