﻿//------------- 將傳來的string的 空格拿掉----------------------------------------------------------------------------
function TrimSpace(string) {
  var temp = "";
  string = "" + string;
  splitstring = string.split(" ");
  for(i = 0; i < splitstring.length; i++)
  temp += splitstring[i];  
  return temp;  
}

//------------- 計算傳來的string的長度(以BIT為單位!) ------------------------------------------------------------
function LenBit(Xvalue){  
  var temp=String(Xvalue);
  count=0;
  for (ci=0;ci<temp.length;ci++){
       ascii_value=temp.charCodeAt(ci)           
       if(ascii_value<0 || ascii_value>255){count=count+2}
       else{count=count+1;}                  
  }  
  return count; 
}

//------------- 判斷所需的長度是否超過(x->是form的名稱,y->是否傳送form資料)
//------------- 說明：其中document.forms[x].elements[g].mark...秀出欄位名稱(原本輸入的值,加入mark)
//-------------       maxLength 要一樣 ( 大小寫有差別哦 ! )
function measureLen(x,y){
   for(g=0;g<document.forms[x].length;g++){
      maxll=parseInt(TrimSpace(document.forms[x].elements[g].maxLength));
      if(maxll!="" && Number(maxll) && Number(maxll)>0 && Number(maxll)<100000000){
          if(LenBit(document.forms[x].elements[g].value)>maxll){          
          alert("欄位名稱："+document.forms[x].elements[g].mark+"\n限定長度："+maxll+" \n目前長度："+LenBit(document.forms[x].elements[g].value)+" \n\n\n註：全形字 及 中文字佔2單位　");
          document.forms[x].elements[g].select();
          document.forms[x].elements[g].focus();
          return false;
          }
      }     
   }
   if(y=='submit_Yes'){document.forms[x].submit();}
   return true;
}
//------------- 數值格式化(Fx=>要處理的數字  Fy=>取小數幾位)---------------------------------------------------------
function FormatNumber(Fx,Fy){	
	Fx=String(Fx);
	Fx = Fx.replace(",","");	
	
	Fx = parseFloat(Fx);
	var Fzzz=new String("0000000");
	Fy=parseInt(TrimSpace(Fy));  
	if(Fy<=0 || Fy=="" || !Number(Fy)){Fy=0};  if(Fy>=7){Fy=7};
	Fy="1"+Fzzz.substring(0,Fy);
	  
	  
	round_value=0.5
	if(Fx<0)round_value=-0.5 
	float=parseInt( (Fx * Fy) +round_value)/Fy;    
	if (!Number(float)){float=0}
	return parseFloat(float);
}
//------------- 選擇的螢光棒!    t=>"this"---------------------------------------------------------
	
	
	function HHtr(t){
		t.bgColorMark=t.style.background;
		t.style.background ="#c0c0c0";
	}
	
	function LLtr(t){
		t.style.background =t.bgColorMark;
		t.bgColorMark="";		
	}
	
    
	function highTR(t){
		t.bgColor="gray";
		t.style.color = "white";
	}  
	function lowTR(t){
		t.bgColor="";  
		t.style.color = "black";
	} 
	
	

//----------------------發現資料輸入錯誤時! F->form's 名稱  X->訊息   Y->需停置的欄位!-------------------
function Fback(F,X,Y){
         if(X=="N"){alert("數值資料錯誤! ") }
         if(X=="Z"){alert("資料不可為' 零 '! ")}
         if(X=="D"){alert("日期格式錯誤! ")}         
         if(X=="E"){alert("資料不可留空白! ") }
         eval(F+"."+Y+".focus()");
         eval(F+"."+Y+".select()");
}
//----------------------將傳來的Value值反轉 ----------------------------------------------------------
function textPull(Value){
      Value=""+Value; tempV='';
      for(Ti=0;Ti<=Value.length;Ti++){tempV=Value.charAt(Ti)+tempV;}            
      return tempV;
}
//----------------------將傳來的string值作貨幣格式化 : YN=>if YN="Y" 則加入"$"---------------------------------------
function FormatCurrency(strr,YN){    
      strr=''+strr
      temp_DD=strr.search("-")      
      strr=strr.replace("-","")
      str=strr.split(".");
      if(str.length==1){float=""}else{float="."+str[1]};
      Pstr=textPull(str[0]);      
      tempW="";
      for(Fi=0;Fi<Pstr.length;Fi++){
         if (Fi==0){tempW=tempW+Pstr.charAt(Fi);}
         else if(Fi%3==0){tempW=tempW+","+Pstr.charAt(Fi);}
         else{tempW=tempW+Pstr.charAt(Fi);}
      }      
      tempW=textPull(tempW);
      if(temp_DD!=-1){tempW="-" + tempW}
      tempW=tempW+float;
      if (YN=="Y"){tempW=" $ "+ tempW;}      
      return tempW;
}
//--------打字效果(PS:<span id='neon'> id要取名為neon)--------------------------------------------------------------------
function strNeon2(sT,sC,sF,sL,sS) {//  sT->顯示的文字  sC->文字顏色  sF->文字大小  sL->顯示速度  sS->停滯時間
	//stext=TrimSpace(sT)
	stext=sT                     ; if(stext=="" || stext=="undefined"){return false;}
	sColor=TrimSpace(sC)         ; if(sColor=="" || sColor=="undefined"){sColor='#000080'}
	sFont=TrimSpace(sF)          ; if(isNaN(sFont)){sFont='12'};sFont += "pt"
	sLick=TrimSpace(sL)          ; if(isNaN(sLick)){sLick='100'}
	sStop=TrimSpace(sS)          ; if(isNaN(sStop)){sStop='2000'}
	//alert("stext="+stext+" \nsColor="+sColor+" \nsFont="+sFont+" \nsLick="+sLick+" \nsStop="+sStop)
	num = 0;
	VHvalue="visible";//隱藏 OR 顯示的值
	neon.innerText ="";
	for(i = 0; i != stext.length; i++) {
		neon.innerHTML += "<span id=\"neond\" style=\"color:"+sColor+";visibility:hidden;font-size:"+sFont+";\">"+stext.charAt(i)+"<\/span>"
	}
	//neon.innerHTML="<img src='../images/search.gif' id='id_neon_img'>" + window.neon.innerHTML
	window.neon.mark="visible";  
	neon1();  
}
function neon1(){
	if(window.neon.mark=="hidden"){window.neon.innerHTML="";return false;}
	if(num !=stext.length) {     
		window.neond[num].style.visibility=VHvalue;
		num++;
		setTimeout("neon1()",sLick);
	}
	else {     
		num = 0 ;
		if(VHvalue=='visible'){VHvalue='hidden'}else{VHvalue='visible'}       
		setTimeout("neon1()",sStop);
	} 
}


//--------檢查身份證--------------------------------------------------------------------------------------------------------------
function checkID(str){  
 var idStr="xABCDEFGHJKLMNPQRSTUVXYWZIO";
 var myid="x" + str.toUpperCase();
 var x= idStr.indexOf(myid.charAt(1)) + 9
 var j = new String(x)
 var newnum = (parseInt(j.substr(0,1))*1) + (parseInt(j.substr(1,1))*9)
 var countDown=8
 for(i=2;i<=10;i++) {
  newnum += parseInt(myid.substr(i,1)) * countDown;
  if(countDown>1)
   countDown --;
 }
 if(newnum%10==0)
  return true 
 else 
  return false
} 


//--------檢查統一編號--------------------------------------------------------------------------------------------------------------
function check_invoice(str){
         var InvStr=TrimSpace(str)         
         if ((!Number(InvStr)) || (InvStr.length < 8)){return false}
         else{return true}
         
}
//--------檢查E-MAIL---------------------------------------------------------------------------------------------------------------
function checkEmail(str){
		var err=''
		var errSTR='e-mail 格式不正確!\n';
		if(str.indexOf("@")<0 || str.indexOf("@")==0)
			err += errSTR;
		if(str.indexOf(".")<0 || str.indexOf(".",str.indexOf("@")) < 0 )
			err += errSTR;
		for(i=0;i<str.length;i++){
			if(str.charCodeAt(i) < 48 || str.charCodeAt(i)>122){
				if(str.charCodeAt(i) != 46) //'如果不是字元 "."
					err = errSTR;
			}
		}
		if(err!='')
			return err;
		else
			return true;
}
//--------判斷顯示OR隱藏----------------------------------------------------------------------------------
function floatTH(x,xx_act){	
	if (typeof(xx_act)=='string'){ //......若有指定..則以指定為主!!
		eval("window."+x+".style.display=xx_act")		
	}
	else{
		temp=eval("window."+x+".style.display")
		if(temp=='none'){eval("window."+x+".style.display='block'")}
		else{eval("window."+x+".style.display='none'")}
	}

  //建立一個iframe放到div下方,避免HTML的物件穿透
  //共用處太多 某些地方不適用 先取消
  /*
  try {
        var iFrameUnderDivID = "temp_iframe_"+ x;
        var DivFrontiFrame = $(x);
        var iFrameUnderDiv = $(iFrameUnderDivID);

        if (!$(iFrameUnderDivID)) {
          var newNode = document.createElement("iFrame");
          newNode.setAttribute("id", iFrameUnderDivID);
          //newNode.setAttribute("class", "dpDiv");
          newNode.setAttribute("src", "javascript:false;");
          newNode.setAttribute("scrolling", "no");
          newNode.setAttribute ("frameborder", "0");
          document.body.appendChild(newNode);
        }
        
        
        if (!DivFrontiFrame)
          DivFrontiFrame = $(x);
        if (!iFrameUnderDiv)
          iFrameUnderDiv = $(iFrameUnderDivID);

        try {
          iFrameUnderDiv.style.position = "absolute";
          iFrameUnderDiv.style.width = DivFrontiFrame.offsetWidth;
          iFrameUnderDiv.style.height = DivFrontiFrame.offsetHeight ;
          iFrameUnderDiv.style.top = DivFrontiFrame.style.top;
          iFrameUnderDiv.style.left = DivFrontiFrame.style.left;
          iFrameUnderDiv.style.zIndex = DivFrontiFrame.style.zIndex - 1;
          iFrameUnderDiv.style.visibility = DivFrontiFrame.style.visibility ;
          iFrameUnderDiv.style.display = DivFrontiFrame.style.display;
        } catch(e) {
        }
  } catch (ee) {
  }
  */
}
/*
取消=>jQuery衝突
function $(){
return document.getElementById(arguments[0]);
}
*/

//------回應日期 (xxx->"DD" 表傳回 yy/mm/dd    否則傳回 yy_mm_dd )--------------------------------------------------------------------------------
function JSdate(xxx){
	jj_today=new Date()
	jj_yy=jj_today.getYear()
	jj_mm=jj_today.getMonth()+1
	jj_dd=jj_today.getDate()
	if(xxx=="DD"){jj_date=jj_yy + '/' + jj_mm + '/' + jj_dd}
	else         {jj_date=jj_yy + '_' + jj_mm + '_' + jj_dd}	
	return jj_date
}

//------回應時間 (xxx->"TT" 表傳回 hh:mm:ss    否則傳回hh_mm_ss )------------------------------------------------------------------------------------------------
function JStime(xxx){ 
	jj_today=new Date()
	jj_hh=jj_today.getHours()
	jj_mm=jj_today.getMinutes()
	jj_ss=jj_today.getSeconds()
	if(xxx=="TT"){ jj_time=jj_hh + ':' + jj_mm + ':' + jj_ss}
	else         { jj_time=jj_hh + '_' + jj_mm + '_' + jj_ss}
	return jj_time
}
//------------------------------------------------------------------------------------------------------


//--------------------------------------------------將下拉選單..僅列出一筆所要的值(其餘Remove)
//obj_name--物件名稱 (ex:parent.opener.form1.xx)
//obj_value --所要選的值
//obj_act   --額外的動作
function get_OneSelect(obj_name,obj_value,obj_act){
	var obj_length=eval(obj_name + ".length-1")
	for(count_jj=obj_length;count_jj>=0;count_jj--){
		vv=eval(obj_name + "[" + count_jj + "].value")
		if (obj_value!=vv) eval(obj_name + '.remove('+ count_jj +')')
	}
	//alert(typeof(obj_act))
	if (typeof(obj_act)=='string'){
		eval(obj_act)
	}
}

/*-------------------------------------------------------------------------
	補(零)動作  
	mz_value  - 原字元  
	mz_symbol - 要補的符號
	mz_len    - 所需的的最大長度
------------------------------------------------------------------------*/
function refill_symbol(mz_value,mz_symbol,mz_len){
	mz_value=TrimSpace(mz_value);
	re_str=mz_value;
		
	for (mz_ii=mz_value.length;mz_ii<mz_len;mz_ii++){
		re_str=mz_symbol + re_str
	}
	return re_str;	
}


/*-------------------------------------------------------------------------
	判斷是否為數值狀態 (是.傳回True  否.傳回False)
	xxV 要判的值
------------------------------------------------------------------------*/
function judgeNum(xxV){
	reV=true;
	if(!Number(xxV) & xxV!=0) reV=false;	
	return reV;
}


/*-------------------------------------------------------------------------
@@@@@@主要用來將 ,,, 0007,000981--> 變成 -->7,981
sp_Text  ->要處理的字元
sp_Symbol->分割的符號
sp_Type  ->傳回的類型
------------------------------------------------------------------------*/
function SplitText(sp_Text,sp_Symbol,sp_Type){
	sp_Text=TrimSpace(sp_Text)     ; if (sp_Text=="") return "";
	sp_Symbol=TrimSpace(sp_Symbol) ; if(sp_Symbol=="" || sp_Symbol=="undefined") sp_Symbol="," ;
	sp_Type=TrimSpace(sp_Type)     ; if(sp_Type=="" || sp_Type=="undefined") sp_Type=0 ;
	/*          
	window.document.write (sp_Text + "<br>")
	window.document.write (sp_Symbol + "<br>")
	window.document.write (sp_Type + "<br>")
	window.document.write ("<hr>")
	*/
	sp_ReStr="";
	sp_TempStr="";
	sp_Arr=sp_Text.split(sp_Symbol);	
	for (sp_ii=0;sp_ii<sp_Arr.length;sp_ii++){
		/*....................................數字型態(為預設值)*/
		if (sp_Type==0){			
			sp_TempStr=parseFloat(sp_Arr[sp_ii]);
			if (!judgeNum(sp_TempStr)) sp_TempStr=0;
			
		}
		/*....................................文字型態(加入'單引號 ')*/
		if (sp_Type==1){
			sp_TempStr="'" + sp_Arr[sp_ii] + "'"
		}
				
		sp_ReStr+=sp_TempStr;
		if (sp_ii<sp_Arr.length-1)	sp_ReStr+=sp_Symbol;
	}
	//window.document.write ("<hr>" +sp_ReStr+"<hr>")
	return sp_ReStr;
	
}

/*-------------------------------------------------------------------------
	x_radio->偵測 radio 的狀態,得知其索引(index)值。
	
	說明：
	radio select 這兩者在 javascript 裡都是需要其 index 屬性才能回應數值。
	比較有經驗的網友可以透過 selectedIndex 取得 select 的 index 值，
	但 radio 比 select 還麻煩，因為它沒有 selectedIndex 這個屬性，
	所以需要以跑迴圈的方式處裡逐一偵測每個 radio 的狀態才能得知其索引(index)值。
------------------------------------------------------------------------*/
function checkedIndex(x_radio){
	for(rr=0;rr<eval(x_radio+'.length');rr++){
		if (eval(x_radio+'['+ rr +'].checked'))	return rr
	}
}



/*------------------------------------------------------------------
	★★ 製定日期： p03 (2003.6.26)
	★★ 名    稱： Obj_CheckBox(tag_id,tag_act)
	★★ 功    能： checkBox,勾選動作	 
	★★ 變數說明： tag_id -> 物件
					tag_act-> block 全部顯示  none 全部不顯示  back 反向動作	
	★★ 傳回狀況： 無
	 
	★★ 備　　註： tag_id 為一個物件.且為陣列型態(從1開始判斷)  and tag_id要有"."
----------------------------------------------------------------------*/
function Obj_CheckBox(tag_id,tag_act){ 

	Arr=tag_id.split(".")	
	
	if (!(Judge_Exit(Arr[1]))){
		alert("無勾選物件資料~")
		return false;
	}
	
	

	tag_ll=eval(tag_id + '.length')		
	//-------------------back 反向動作
	if (tag_act=="back"){			
		for (aa=1;aa<tag_ll;aa++){
			if (! (eval(tag_id + '[aa].disabled')) ) {
				if (eval(tag_id + '[aa].checked')){tag_act=''} else{ tag_act='YES'}				
				eval(tag_id + '[aa].checked =tag_act');
			}
		}
		return false;
	}	
	
	//-------------------block 全部顯示  none 全部不顯示
	if (tag_act=='none') tag_act=''
	for (aa=1;aa<tag_ll;aa++){
		if (! (eval(tag_id + '[aa].disabled')) ) eval(tag_id + '[' + aa + '].checked =tag_act')
	}
}

/*------------------------------------------------------------------
	★★ 製定日期： p03 (2003.6.26)
	★★ 名    稱： check_hook(xObj)
	★★ 功    能： checkBox,是否有勾選
	★★ 變數說明： xObj -> 物件		xValue -> 要傳回xObj.那一屬性			
	★★ 傳回狀況： 將有勾選的,組合成一字串,傳回
	 
	★★ 備　　註： xObj 為一個物件.且為陣列型態(從1開始判斷)
----------------------------------------------------------------------*/
function check_hook(xObj,xValue){
	re_str=''
	tag_ll=eval(xObj + '.length')
	for (cc=1;cc<tag_ll;cc++){
		//alert(cc + '= ' + eval(xObj + '[cc].checked'))
		if ( eval(xObj + '[cc].checked') ){
			re_str += eval( xObj + '[cc].' + xValue) + ','
		}
	}		
	re_str=re_str.substring(0,re_str.length-1)	
	return re_str;
}


/*------------------------------------------------------------------
	★★ 製定日期： p03 (2003.6.26)
	★★ 名    稱： Judge_Exit(xName)
	★★ 功    能： 判斷.是否有此物件
	★★ 變數說明： xName -> 物件名稱
	★★ 傳回狀況： 有.傳回->true  沒有.傳回->false
	 
	★★ 備　　註： 
----------------------------------------------------------------------*/
function Judge_Exit(xName){	
	xTag=window.document.all(xName)	
	if (xTag != null){
		return true		
	}	
	return false;	
}



/*------------------------------------------------------------------
	★★ 製定日期： p03 (2003.8.15)
	★★ 名    稱： get_DiffDate(t1,t2)
	★★ 功    能： 2個日期的相差天數
	★★ 變數說明： t1,t2
	★★ 傳回狀況： 傳回天數	 
	★★ 備　　註： 
----------------------------------------------------------------------*/
function get_DiffDate(t1,t2){	
	var now = new Date(t1);
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();

	var date = now.getDate();
	var month = now.getMonth() + 1;
	var year = now.getYear();
	if (year < 1000)
	year+=1900
	        
	var timeValue = "" + ((hours < 10 ) ? "0" : "") + hours
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds    

	if (seconds == 0) {
	window.status = "New minute!";
	}
	
	if (minutes == 0 && seconds == 0) {
	window.status = "New hour!";	        
	}
	
	if (hours == 0 && minutes == 0 && seconds == 0) {
	window.status = "Midnight!";
	}
	else if (seconds > 0) {
	window.status = timeValue + "  The Xact time according to your computer clock!     "  + date + "/" + month + "-" + year;
	}
	 
	nextXmas = new Date(t2)
	nextXmas.setYear(year)
	msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day
	daysLeft = (nextXmas.getTime() - now.getTime()) / msPerDay;
	daysLeft = Math.round(daysLeft);
	
	return daysLeft
}


function getZipCode(t,f_zip,f_add,f_city){
    /*if (f_zip == "")
    	f_zip="form1.add_zip";
    if (f_add == "")
	    f_add="form1.add_waddress";
    if (f_city == "")
	    f_city="form1.add_city";*/
	/*if (t=="869"){
	    window.open("/setup/getZipCode86.asp?Zip="+ f_zip +"&Add="+ f_add +"&City="+ f_city,"winGetZipCode","resizable=0,scrollbars=1,toolbars=0,width=300,height=400,top=0,left=0")	
	}else{*/
	    window.open("/setup/getZipCode.asp?z_country_code="+ t +"&Zip="+ f_zip +"&Add="+ f_add +"&City="+ f_city,"winGetZipCode","resizable=0,scrollbars=1,toolbars=0,width=300,height=400,top=0,left=0")	
    //}
}

