//轉換匯率
function currency_translate(){
//	alert('currency_translate.........');
	
  var currency=document.getElementById('currency_convert');
  if(currency.value!="no"){
      currency_value=currency.value;
      //取得匯率的code
      var code=currency_value.substring(currency_value.length-3,currency_value.length);
      //取得匯率
      var currency=currency_value.substring(0,currency_value.length-4);
      var price_now=document.getElementById('newPrice_label');
      var price_before=document.getElementById('originalPrice_label');
      var price_save=document.getElementById('savedAmount');
      var HK_price=document.getElementById('HK_price');
      var final_price=currency*HK_price.value;
      var before=document.getElementById('HK_price2');
      var before_price=currency*before.value;
      var save_price=before_price-final_price;
      price_now.innerHTML=code+'$'+final_price.toFixed(2);//優惠價
      price_before.innerHTML=code+'$'+before_price.toFixed(2);//原價格
      price_save.innerHTML=code+'$'+save_price.toFixed(2);//節省
  }
  }
function currency_translate2(){
//	alert('currency_translate2.........');
  var currency=document.getElementById('currency_convert2');
  
//  alert(currency);
  if(currency.value!="no"){
      currency_value=currency.value;
      //取得匯率的code
      var code=currency_value.substring(currency_value.length-3,currency_value.length);
      //取得匯率
      var currency=currency_value.substring(0,currency_value.length-4);
      var price_now=document.getElementById('newPrice_label');
      var HK_price=document.getElementById('HK_price');
      var final_price=currency*HK_price.value;
      price_now.innerHTML=code+'$'+final_price.toFixed(2);//優惠價
  }
  }
function categories_redirect_list(categories_code){
  window.location.href="product_listing.php?categories_code="+categories_code;
}
function categories_redirect_pic(categories_code){
  window.location.href="product_pic.php?categories_code="+categories_code;
}
function next_page(url){
  window.location.href=url;
}
function set_number_per_page(url){
  window.location.href=url;
}

function pic_sort_by(url){
 window.location.href=url;
}
function list_sort_by(url){
	
	if(url !='') window.location.href=url;
}
function checkSearch(){
var kwords=document.getElementById("kwords");
 if(kwords.value==''||kwords.value=='請輸入關鍵字'){
   alert('請輸入搜尋條件');
   return false;
 }
}
function checkSearch_cpStore(){
var kwords=document.getElementById("cpStore");
 if(kwords.value==''){
   alert('請輸入搜尋條件');
   return false;
 }
}
function checkAdvancdSearch(){

var price_from=document.getElementById('price_from'); 
var price_to=document.getElementById('price_to');
var publishYear_From=document.getElementById('publishYear_From'); 
var publishYear_To=document.getElementById('publishYear_To');
var patrn1 = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;//浮點數正則 
var patrn2 = /^[0-9]*[1-9][0-9]*$/;//正整數正則 

 if(price_from.value!=''&&!isDigit(price_from.value,patrn1)){
  alert('請輸入正確的價格格式！');
  price_from.focus();
  price_from.select();
    return false;
 }
 if(price_to.value!=''&&!isDigit(price_to.value,patrn1)){
   alert('請輸入正確的價格格式！');
   price_to.focus();
   price_to.select();
   return false;
 }
  if(publishYear_From.value!=''&&!isDigit(publishYear_From.value,patrn2)){
   alert('請輸入正確的日期格式！');
   publishYear_From.focus();
   publishYear_From.select();
   return false;
 }
  if(publishYear_To.value!=''&&!isDigit(publishYear_To.value,patrn2)){
   alert('請輸入正確的日期格式！');
   publishYear_To.focus();
   publishYear_To.select();
   return false;
 }

}
function isDigit(string,patrn) 
 {    
    var result; 
    if (!patrn.exec(string)) 
      result = false; 
    else 
       result = true; 
     return result; 
 }
