function currencyConverter(){
var amount = document.converterform.amount.value;
var currency = document.converterform.currency_type.value;
var livecurrency = document.converterform.livecurrency.value;
var curr_result = document.getElementById("curr_result");

if(amount==""){
	alert("請輸入銀碼");
	document.converterform.amount.focus();
	return false;
}else{
	if(currency=="HKD"){
		curr_result.value = ("$ "+ Math.round(amount / livecurrency)+" 円");
		return false;
	}else{
		curr_result.value = ("HKD$ "+ Math.round(amount * livecurrency));
		return false;
	}
}
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
   
function quoteCost(){
var weight_kg = document.shippingcostform.weight_kg.value;
var size_d = document.shippingcostform.size_d.value;
var size_w = document.shippingcostform.size_w.value;
var size_h = document.shippingcostform.size_h.value;

var goodsprice = document.shippingcostform.goodsprice.value;
var jpshipcost = document.shippingcostform.jpshipcost.value;
var shipping = document.shippingcostform.shipping.value;
var totally = document.shippingcostform.totally.value;

	if(weight_kg=="" && size_d=="" && size_w=="" && size_h==""){
		alert("請輸入重量或尺寸任何一種方式");
		return false;
	}
	//	 if (size_d=="" && size_w=="" && size_h==""){
	//		alert("請輸入完整尺寸, 單位為CM");
	//		document.shippingcostform.size_d.focus();
	//	}else
		if (weight_kg !="" && IsNumeric(weight_kg) == false){
				alert("請輸入數字");
				document.shippingcostform.weight_kg.focus();
				return false;
		}
		if (size_d !="" && size_w !="" && size_h !="" && IsNumeric(size_d) == false && IsNumeric(size_w) == false && IsNumeric(size_h) == false){
				alert("請輸入數字");
				document.shippingcostform.size_d.focus();
				return false;
		}
}

function selChange(theSel,baseURL,targetWin)
{
  var currSel=theSel.selectedIndex;

  if(currSel==0)
        return;
     var currURL=theSel.options[currSel].value;
  baseURL=baseURL.substring(0,baseURL.lastIndexOf("/")+1);
  targetWin.location.href=baseURL+currURL;

  theSel.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function winResizeTo(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
   window.resizeTo(myWidth,myHeight);
   alert(myWidth + " " +myHeight );
}

function bidSite(theURL,winName) { //v2.0
  window.open(theURL,winName,'toolbar=yes,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes');
}


function SetCurrentSelectedNode(ContainerName, nodeID )
{
	var Container = document.getElementById(ContainerName);
	
	if (Container)
	{
		Container.value = nodeID;
	}
	HightLight(nodeID)	;
}

function HightLight( id )
{	
	var tree = document.getElementById(TreeControlID);
	var Nodelist = tree.getElementsByTagName('table');
	
	for (i=0; i < Nodelist.length; i++)
	{
		Nodelist[i].style.backgroundColor = '';
	}

	var SelectedNode = document.getElementById(TreeControlID + "_NodeSet_" + id);
	if (SelectedNode){
		SelectedNode.style.backgroundColor = '#F3F3F3';
	}
}

function getCat(page){
	var cattype = document.form1.cattype.value; 
	document.location.href=page + '.php?cat='+ cattype ;
}

function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setGoogleTrans(mode){
	if(mode == "on"){
		setCookie('jpbuygoogletrans', 'true', 99);
	}else{
		setCookie('jpbuygoogletrans', 'false', 99);
	}
}

function setJPBuyDisplayMode(mode){
	if(mode == "thumb"){
		setCookie('jpbuydisplay', 'true', 99);
	}else{
		setCookie('jpbuydisplay', 'false', 99);
	}
}


function paymentType(dropdown){
	var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
	if(SelValue == "other"){
		document.getElementById("otherfield").style.display = 'block';
	}else{
		document.getElementById("otherfield").style.display = 'none';
	}
	return false;
}
function validate_required(field,alerttxt){
with (field){
  if (value==null||value==""){
    alert(alerttxt);return false;
    }else{
    	return true;
    }
  }
}
function validate_email(field,alerttxt){
with (field){
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}
function validate_phone(field,alerttxt) {
    var stripped = field.value.replace(/[\(\)\.\-\ ]/g, '');     
	 if (isNaN(parseInt(stripped))) {
        alert(alerttxt);return false;
    }else {return true;}
}

function validate_form(thisform){
with (thisform){
	if (validate_required(name,"請填上姓名")==false){
		name.focus();return false;
	}
	if (validate_required(email,"請填上確認電郵")==false){
		email.focus();return false;
	}
	if (validate_email(email,"請填上正確電郵")==false){
		email.focus();return false;
	}
	if (validate_required(phone,"請填上聯絡電話")==false){
		phone.focus();return false;
	}
	if (validate_phone(phone,"請填上正確聯絡電話")==false){
		phone.focus();return false;
	}
	if (validate_required(type,"請選擇付款類型")==false){
		type.focus();return false;
	}
	if (validate_required(totalamount,"請填上付款金額")==false){
		totalamount.focus();return false;
	}
	if (validate_phone(totalamount,"請填上正確金額，不用填上$")==false){
		totalamount.focus();return false;
	}

  }
  
}

function translateNow(){
	var yKeyWord = $('#ySearch').val();

	if ( $("#isTranslate").attr('checked') ) {
		$.translate(yKeyWord, 'ja', {
		complete:	function(translation){
		translation = Url.encode(translation);
		//	$('#ySearch').val(translation);
			window.open("http://auctions.search.yahoo.co.jp/search?p="+translation+"&auccat=0&tab_ex=commerce", "mywindow","width=900,height=740,scrollbars=yes"); 
		}
		}); 
	}else{
		yKeyWord = Url.encode(yKeyWord);
		window.open("http://auctions.search.yahoo.co.jp/search?p="+yKeyWord+"&auccat=0&tab_ex=commerce", "mywindow","width=900,height=740,scrollbars=yes"); 
	}

}


function disableBtn(){
	document.getElementById("prev").disabled = true;
	document.getElementById("next").disabled = true;
	document.payFormCcard.submit();
}
