// JavaScript Document

//檢查同意條款chekBox
function chkAgree(obj)
{
  alert(obj);
}

//系統設定之網站資料
function isSystemSet1()
{
	f=document.systemset1;
	if( !checkf(f.webname,2,"網站名稱")) return false
	if( !checkf(f.webaddress,2,"網站網址")) return false	
}

//系統設定之公司資料
function isSystemSet2()
{
	f=document.systemset2;
	if( !checkf(f.service_tel,9,"客服專線")) return false	
	if( !checkf(f.fax,9,"傳真電話")) return false
	if( !checkfemail(f.order_mail,"訂單信箱")) return false
	if( !checkfemail(f.service_mail,"客服信箱")) return false		
}

//檢查系統設定之公司資料之郵局戶名
function chkPostAgree()
{
	f=document.systemset2;
	if(f.agree_count.checked)
	{
		f.post_countname.value=f.bank_countname.value;
	}
	else
	{
		f.post_countname.value="";
	}
}

//同銀行戶名
function AgreeDisabled()
{
	f=document.systemset2;
	f.agree_count.checked=false;
}


//系統設定之運費／折扣
function isSystemSet3()
{
	f=document.systemset3;
	if( !checkf(f.shoppingcash,1,"最低消費金額")) return false
	if( !checkValue(f.shoppingpoint,"最低消費金額")) return false
	if( !checkf(f.shoppingpoint,1,"最低消費抵用點數")) return false
	if( !checkValue(f.shoppingpoint,"最低消費抵用點數")) return false	
	if( !checkf(f.freight_limit,1,"消費金額")) return false
	if( !checkValue(f.freight_limit,"消費金額")) return false	
	if( !checkf(f.freight,1,"運費金額")) return false
	if( !checkValue(f.freight,"運費金額")) return false			
}

//系統設定之付款方式
function isSystemSet4()
{
	f=document.systemset4;
	if( !checkf(f.pay_type1,1,"付款方式")) return false	
}

//系統設定之儲值點數
function isSystemSet5()
{
	f=document.systemset5;
	if( !checkf(f.p_cash,1,"回饋現金")) return false	
	if( !checkValue(f.p_cash,"回饋現金")) return false		
	if(f.p_cash.value<1)
	{
		alert("回饋現金,最少1元");
		f.p_cash.focus();
		f.p_cash.select();  
		return false;
	}
	
	
	if( !checkf(f.c_point,1,"折抵點數")) return false	
	if( !checkValue(f.c_point,"折抵點數")) return false		
	if(f.c_point.value<1)
	{
		alert("折抵點數,最少1點");
		f.c_point.focus();
		f.c_point.select();  
		return false;
	}
	
}

//註冊單驗證
function isJoinEmpty()
{
	f=document.joins;
	if( !checkApwd(f.a_cert,f.incert,"輸入驗證碼","圖片驗證碼")) return false	
	if( !checkf(f.user,6,"帳號")) return false
	if( !checkf(f.password,6,"密碼")) return false
	if( !checkApwd(f.password,f.ag_password,"密碼","確認密碼")) return false
	if( !checkf(f.name,2,"姓名")) return false
	if( !checkf(f.ho_address,5,"地址")) return false
	if( !checkf(f.ho_tel_1,2,"電話區域碼")) return false
	if( !checkf(f.ho_tel_2,7,"電話主碼")) return false
	if( !checkfemail(f.email,"電子信箱")) return false
} 

//會員新增驗證
function isMembeAdd()
{
	f=document.memberadd;
	if( !checkf(f.name,2,"姓名")) return false
	if( !checkf(f.ho_address,5,"地址")) return false
	if( !checkf(f.ho_tel_1,2,"電話區域碼")) return false
	if( !checkf(f.ho_tel_2,7,"電話主碼")) return false
	if( !checkfemail(f.email,"電子信箱")) return false
}


//會員修改驗證
function isMembeUpdate()
{
	f=document.memberupdate;
	if( !checkf(f.name,2,"姓名")) return false
	if( !checkf(f.ho_address,5,"地址")) return false
	if( !checkf(f.ho_tel,10,"電話碼號")) return false
	if( !checkfemail(f.email,"電子信箱")) return false
}

//會員登入驗證
function isMemberLogin()
{
	f=document.memberlgoin;
	if( !checkf(f.user,6,"會員帳號")) return false
	if( !checkf(f.password,6,"會員密碼")) return false
} 

//忘記密碼驗證
function isForGetCode()
{
	f=document.forgetcode;
	if( !checkf(f.user,6,"帳號")) return false
	if( !checkfemail(f.email,"電子信箱")) return false
} 

//會員資料驗證
function isEdits()
{
	f=document.profile_update;
	if( !checkf(f.name,2,"姓名")) return false
	if( !checkf(f.ho_address,5,"地址")) return false
	if( !checkf(f.ho_tel,10,"電話碼號")) return false
	if( !checkfemail(f.email,"電子信箱")) return false
}

//會員密碼修改驗證
function isPassworUpdate()
{
	f=document.password_update;
	if( !checkf(f.password,6,"密碼")) return false
	if( !checkApwd(f.password,f.ag_password,"密碼","確認密碼")) return false
}


//網站管理員登入驗證
function isAdminLogin()
{
	f=document.adminlogin;
	if( !checkf(f.user,6,"管理員帳號")) return false
	if( !checkf(f.password,6,"管理員密碼")) return false
} 


//網站管理員新增資料驗證
function isAdminAdd()
{
	f=document.adminadd;
	if( !checkf(f.admin_user,6,"帳號")) return false
	if( !checkf(f.admin_password,6,"密碼")) return false
	if( !checkApwd(f.admin_password,f.admin_apassword,"密碼","確認密碼")) return false
	if( !checkf(f.admin_name,2,"姓名")) return false
	if( !checkfemail(f.admin_email,"電子信箱")) return false
}

//網站管理員更新資料驗證
function isAdminUpdate()
{
	f=document.adminupdate;
	if( !checkf(f.admin_password,6,"密碼")) return false
	if( !checkApwd(f.admin_password,f.admin_apassword,"密碼","確認密碼")) return false
	if( !checkf(f.admin_name,2,"姓名")) return false
	if( !checkfemail(f.admin_email,"電子信箱")) return false
}

//商品新增類別驗證
function isGoodsAddType()
{
	f=document.goodstypeadd;
	if( !checkf(f.g_t_name,1,"類別名稱")) return false
}


//商品編輯類別驗證
function isGoodsUpdateType()
{
	f=document.goodstypeaupdate;
	if( !checkf(f.g_t_name,1,"類別名稱")) return false
}

//資料搜尋驗證
function chkSerach()
{
	f=document.serachData;
	if( !checkSelect(f.serach_item,"-1","搜尋項目")) return false
	if( !checkKeyWord(f.keyword,"請輸入關鍵字"))return false
}


//新増商品資料驗證
function isGoodsAdd()
{
	f=document.goodsadd
	if( !checkf(f.goods_no,1,"商品編號")) return false
	if( !checkf(f.goods_name,2,"商品名稱")) return false
	if( !checkf(f.goods_sales,1,"商品售價")) return false
	if( !checkValue(f.goods_sales,"商品售價")) return false	
	if( !checkf(f.goods_nsales,1,"商品網路價")) return false
	if( !checkValue(f.goods_nsales,"商品網路價"))return false
	if( !checkf(f.goods_storage,1,"商品庫存量")) return false
	if( !checkValue(f.goods_storage,"商品庫存量"))return false
	if( !checkSelect(f.g_t_id,"0","商品類別")) return false	
	if( !checkf(f.goods_img,1,"商品圖片")) return false
	f.save.disabled=true;	
}

//檢查商品選項
function chkOptions(formName,v)
{
	if((v==1) || (v==-1))
	{
		formName.value='';
		formName.disabled=true;		
	}
	else
		formName.disabled=false;
}

//修改商品資料驗證
function isGoodsUpdate()
{
	f=document.goodsupdate
	if( !checkf(f.goods_no,1,"商品編號")) return false
	if( !checkf(f.goods_name,2,"商品名稱")) return false
	if( !checkf(f.goods_sales,1,"商品售價")) return false
	if( !checkValue(f.goods_sales,"商品售價")) return false	
	if( !checkf(f.goods_nsales,1,"商品網路價")) return false
	if( !checkValue(f.goods_nsales,"商品網路價"))return false
	if( !checkf(f.goods_storage,1,"商品庫存量")) return false
	if( !checkValue(f.goods_storage,"商品庫存量"))return false
	if( !checkSelect(f.g_t_id,"0","商品類別")) return false
	f.save.disabled=true;	
}


//最新消息新增驗證
function isNewsAdd()
{
	f=document.newsadd;
	if( !checkf(f.news_topic,1,"主題")) return false
}

//最新消息更新驗證
function isNewsUpdate()
{
	f=document.newsupdate;
	if( !checkf(f.news_topic,1,"主題")) return false
}

////商品放入購物車驗證
function isCart(obj,obj2)
{
	f=document.obj;
	if( !checkValue(obj2,"數量")) return false
	if( !checkZero(obj2,"數量")	) return false
}


//商品搜尋驗證
function chkGoodsSerach()
{
	f=document.serachData;
	if( !checkSelect(f.goods_type_item,"-1","請選商品分類")) return false
	if( !checkSelect(f.price_item,"-1","請選商品價格")) return false
}

//訂單資資驗證
function isOrders(v)
{
	f=document.order_info;
	var p=f.order_pay_type.options[f.order_pay_type.selectedIndex].text;
	
	if( !checkf(f.order_name,2,"姓名")) return false
	if( !checkf(f.order_tel,9,"電話")) return false
	if( !checkfemail(f.order_email,"電子信箱")) return false		
	if( !checkf(f.order_address,5,"地址")) return false
	if( !checkSelect(f.order_pay_type,"-1","請選付款方式")) return false	
	
	if(p=="儲值點數" && parseInt(v) < parseInt(f.order_point.value))
	{
		alert("會員的儲值點數不足無法使用！");
		return false;
	}
	
	f.order_ok.disabled=true;
}

//訂單處理狀態
function isOrderSuatus()
{
	f=document.orderupdate;
	if( !checkSelect(f.order_status,"-1","請選擇處理狀態")) return false	
}


//好站推薦新增驗證
function isWebsiteAdd()
{
	f=document.websiteadd;
	if( !checkf(f.website_name,1,"網站名稱")) return false
	if( !checkf(f.website_address,1,"網址")) return false	
}

//好站推薦更新驗證
function isWebsiteUpdate()
{
	f=document.websiteupdate;
	if( !checkf(f.website_name,1,"網站名稱")) return false
	if( !checkf(f.website_address,1,"網址")) return false	
}


//常見問題新增驗證
function isHelpAdd()
{
	f=document.helpadd;
	if( !checkf(f.help_topic,1,"主題")) return false
}

//常見問題更新驗證
function isHelpUpdate()
{
	f=document.helpupdate;
	if( !checkf(f.help_topic,1,"主題")) return false
}

//連絡我們驗證
function isContact()
{
	f=document.contactme;
	if( !checkf(f.incert,6,"驗證碼")) return false
	if( !checkf(f.user_name,3,"會員姓名")) return false
	if( !checkfemail(f.user_email,"電子信箱")) return false
	if( !checkf(f.topic,3,"主題")) return false	
	if( !checkf(f.main,1,"內容")) return false			
}


//銷售統計驗證
function isSales()
{
	f=document.serachData;
	if( !checkf(f.sdate,10,"起始日期")) return false
	if( !checkf(f.edate,10,"終止日期")) return false
	if(f.sdate.value>f.edate.value)
	{
		alert("[起始日期]不可大於[終止日期]");
		return false;
	}
}

//儲值點數驗證
function isPoints()
{
	f=document.addpoint;
	if( !checkf(f.salespoint,1,"儲值點數")) return false
	if( !checkValue(f.salespoint,"儲值點數")) return false
	if( !checkZero(f.salespoint,"儲值點數")) return false
	if( !checkSelect(f.order_pay_type,"-1","請選付款方式")) return false	
}


//新增語系管理
function isLangAdd()
{
	f=document.langadd;
	if( !checkf(f.lang_code,2,"語系代碼")) return false
	if( !checkf(f.lang_name,2,"語系名稱")) return false
}

//更新語系管理
function isLangUpdate()
{
	f=document.langupdate;
	if( !checkf(f.lang_name,2,"語系名稱")) return false
}


//新増投票資料
function isPollAdd()
{
	f=document.polladd
	fidles=0;//計算欄位
	if( !checkf(f.poll_name,1,"主題")) return false
	
	for(i=1;i<=5;i++)
	{
		if(document.getElementById("poll_question_name"+i).value!="")
			fidles++;
	}
	
	if(fidles==0)
	{
		alert("至少填一個選項");
		f.poll_question_name1.focus();
		f.poll_question_name1.select();	
		return false;
	}
	
	
	if((f.poll_effect.value=="" || f.poll_effect.value<=0) && (f.poll_forever.checked==false))
	{
		if( !checkf(f.poll_effect,2,"有效天數")) return false;
	}

}

//修改投票資料
function isPollUpdate(v)
{
	f=document.pollupdate
	fidles=0;//計算欄位
	if( !checkf(f.poll_name,1,"主題")) return false
	
	for(i=1;i<=v;i++)
	{
		if(document.getElementById("poll_question_name"+i).value!="")
			fidles++;
	}

	if(fidles==0)
	{
		alert("至少填一個選項");
		f.poll_question_name1.focus();
		f.poll_question_name1.select();	
		return false;
	}
		
	if((f.poll_effect.value=="" || f.poll_effect.value<=0) && (f.poll_forever.checked==false))
	{
		if( !checkf(f.poll_effect,2,"有效天數")) return false;
	}
}


//新增投票選項
function isPollQuestionsAdd()
{

	count=0;
	for(i=1;i<=5;i++)
	{
		if(document.getElementById("poll_question_name"+i).value!="")
			count++;
	}
	
	if(count==0)
	{
		alert("至少填一個選項");
		document.poll_questions_add.poll_question_name1.focus();
		document.poll_questions_add.poll_question_name1.select();	
		return false;
	}
}

//投票驗證
function isVoting()
{
	f=document.voting;
	count=0;
	for(i=0;i<f.poll_question_id.length;i++)
	{
		if(f.poll_question_id[i].checked)
			count++;
	}
	
	if(count==0)
	{
		alert("您未選擇投票項目");
		return false;
	}
	
}

//變投票長條圖
function ChangeBar(v,src,ind)
{
	document.getElementById("bar"+ind).src=src+v+'.gif';
}

//宅配公司新增資料驗證
function isfreightAdd()
{
	f=document.freightadd
	fidles=0;//計算欄位
	if( !checkf(f.freight_company,2,"宅配公司名稱")) return false
	if( !checkf(f.freight_liaison,2,"宅配公司連絡人")) return false
	if( !checkf(f.freight_tel,2,"宅配公司電話")) return false	
}

//宅配公司更新資料驗證
function isfreightUpdate()
{
	f=document.freightupdate
	fidles=0;//計算欄位
	if( !checkf(f.freight_company,2,"宅配公司名稱")) return false
	if( !checkf(f.freight_liaison,2,"宅配公司連絡人")) return false
	if( !checkf(f.freight_tel,2,"宅配公司電話")) return false	
}

//發票檢查
function chkInvoice()
{
	f=document.order_info;
	f.invoicetitle.value='';
	f.invoicesn.value='';	
	if(f.invoicechk[0].checked)
	{
		f.invoicetype.disabled=false;
		f.invoicetitle.disabled=true;
		f.invoicesn.disabled=true;		
		f.invoicetype.selectedIndex=0;
	}
	else
	{
		f.invoicetype.disabled=true;
		f.invoicetitle.disabled=true;
		f.invoicesn.disabled=true;		
		f.invoicetype.selectedIndex=0;		
	}
}

//發票種別檢查
function chkInvoiceType()
{
	f=document.order_info;
	f.invoicetitle.value='';
	f.invoicesn.value='';	
	if(f.invoicetype.options[f.invoicetype.selectedIndex].value==3)
	{
		f.invoicetitle.disabled=false;
		f.invoicesn.disabled=false;
	}
	else
	{
		f.invoicetitle.disabled=true;
		f.invoicesn.disabled=true;
	}
	

}

//DM新增驗證
function isDmAdd()
{
	f=document.dmadd;
	if( !checkf(f.dm_img,1,"圖片")) return false	
}

//DM編輯驗證
function isDmUpdate()
{
	f=document.dmupdate;
	if( !checkf(f.dm_img,1,"圖片")) return false	
}


function OnLoadFous(obj)
{
	obj.focus();
	obj.select();
}

function Del_Data(urls,id,response)
{
	YN=confirm(response);
	if(YN)
	{
		location.href=urls+'?id='+id;
	}
}

function DelDataArg(urls,response,arg)
{
	YN=confirm(response);
	if(YN)
	{
		location.href=urls+arg;
	}
}

var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) 
{
  XMLHttpRequestObject = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");
}

function getData(dataSource, divID)
{
  if(XMLHttpRequestObject)
  {
    XMLHttpRequestObject.open("GET", dataSource);
    XMLHttpRequestObject.onreadystatechange = function()
    {
      if (XMLHttpRequestObject.readyState == 4 &&
          XMLHttpRequestObject.status == 200)
      {
        var objDiv = document.getElementById(divID);
        objDiv.innerHTML = XMLHttpRequestObject.responseText;
      }
    }
    XMLHttpRequestObject.send(null);
  }
}


//動態檢查資料
//---------------------------------------------------------------------------
function checkData(obj1,obj2,divID,urls,obj3)
{
	if(obj1.value!="")
	{
	   getData(urls+"?qry="+obj1.value+"&types="+obj2+"&lang="+obj3,divID);
	}
}
//----------------------------------------------------------------------------------------

function checkfemail(field,prompt)
{
   var len = field.value.length;
   if(len==0) {
      alert(prompt+"格式不對");
	  field.focus();
	  field.select();	  
      return (false);
   }
   for(var i=0;i<len;i++)
   {  var c= field.value.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
      {alert("您的電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !");
	   field.focus();
   	   field.select();
       return (false);
	   }
   }
   if((field.value.indexOf("@")==-1)||(field.value.indexOf("@")==0)||(field.value.indexOf("@")==(len-1)))
   {alert("您的電子郵件地址不合法 !");
   	field.focus();
	field.select();
    return (false);}
   if((field.value.indexOf("@")!=-1)&&(field.value.substring(field.value.indexOf("@")+1,len).indexOf("@")!=-1))
   {alert("您的電子郵件地址不合法 !");
	field.focus();
	field.select();   
    return (false);}
   if((field.value.indexOf(".")==-1)||(field.value.indexOf(".")==0)||(field.value.lastIndexOf(".")==(len-1)))
   {alert("您的電子郵件地址不完全 !");
	field.focus();
	field.select();   
    return (false);}

   return(true);
}

function checkf(field,len,prompt) {
  if (field.value.length < len) {
    alert("『"+prompt+"』輸入不正確");
	field.focus();
	field.select();
    return(false);
  }
  return(true);
}   


//確定密碼驗證
function checkApwd(field1,field2,message1,message2)
{
 if(field1.value!=field2.value)
 {
  alert("『"+message1+"』和『"+message2+"』不一致!");
  field2.focus();
  field2.select();
  return(false);
 }
 return(true);
}

function getFocus(obj)
{
	obj.focus();
	obj.select();
	return false;
}

function checkSelect(field,prompt,message)
{
 if(field.value==prompt)
 {
  alert("請選擇一個『"+message+"』");
  field.focus();
  return(false);
 }
 return(true);
}

function checkKeyWord(field,keyword)
{
	if(field.value==keyword)
	{
		alert(keyword);
		field.focus();
		field.select();
		return (false);
	}
	return (true);
}

function checkValue(field,prompt)
{
 if(isNaN(field.value))
 {
  alert("『"+prompt+"』輸入應該是數字");
  field.focus();
  field.select();  
  return(false);
 }
 return(true);
}


function checkZero(field,prompt)
{
 if(field.value<=0)
 {
  alert("『"+prompt+"』應該大於0");
  field.focus();
  field.select();  
  return(false);
 }
 return(true);
}

function txthidden(obj2,counts)
{
	for(i=1;i<=counts;i++)
	{
		document.getElementById(obj2+i).style.display='none';
	}
}

function txtShow(obj1,obj2,counts)
{
	txthidden(obj2,counts);
	document.getElementById(obj1).style.display='';
}

//顯示商品圖片陰影
function overImg(obj,urls)
{
	document.getElementById(obj).style.backgroundImage="url("+urls+")";	
}

//顯示商品圖片陰影
function OutImg(obj)
{
	document.getElementById(obj).style.backgroundImage="none";	
}

function chkImgUrls(v)
{
	f=document.systemset6;
	if(f.all("adv_img"+v).value!="")
	{
		f.all("adv_del"+v).disabled=true;
	}
	else
	{
		f.all("adv_del"+v).disabled=false;	
	}
}	

function imgUrlsDisabled(v)
{
	f=document.systemset6;
	f.all("adv_img"+v).value="";	
	if(f.all("adv_del"+v).checked==true)
		f.all("adv_img"+v).disabled=true
	else
		f.all("adv_img"+v).disabled=false
}

//開啟至中視窗
function NewWindow(mypage,myname,w,h,scroll)
{
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=0'
	win = window.open(mypage,myname,settings);
}

//狀態列顯示
function showStatus(v)
{
	window.status=v;
}

//顯示商品圖片
function ChangGoodsImg(ImgSrc)
{
	f=document.goods_show;
	f.GoodsBImg.src=ImgSrc;
}

//變更語系
function change_lang(obj)
{
	location.href='lib/changlang.php?lang='+obj;
}

//新增留言
function isMegAdd()
{
	f=document.message_add;
	if( !checkf(f.message_name,2,"您的姓名")) return false	
	if( !checkf(f.message_topic,3,"主題")) return false		
	if( !checkf(f.message_main,10,"留言內容")) return false
	if( !checkf(f.incert,6,"驗證碼")) return false	
}

//留言版表情圖示
function cgface(field,filename,path)
{
	document.getElementById(field).src=path+filename+'.gif';
}

//可訂購時通知我
function sendme(obj,v)
{
	location.href='index.php?html=27&lang='+obj+'&code='+v;
}