﻿	// 頁籤切換效果

	function switchTab(tab_title, pst, tab_cnt)
	{
		for(var i=0 ; i<tab_cnt ; i++)
		{
			if (i == pst)
				document.getElementById(tab_title+'_tab_'+i).className = 'current';
			else
				document.getElementById(tab_title+'_tab_'+i).className = '';
			if (i == pst)
				document.getElementById(tab_title+'_'+i).className = 'disyshow';
			else
				document.getElementById(tab_title+'_'+i).className = 'disyhidn';
		}
	}
	
	function switchBlogsTab(tab_title, pst, tab_cnt)
	{
		for(var i=0 ; i<tab_cnt ; i++)
		{
			if (i == pst)
				document.getElementById(tab_title+'li_'+i).className = 'current';
			else
				document.getElementById(tab_title+'li_'+i).className = '';
			if (i == pst)
				document.getElementById(tab_title+i).className = 'disyshow';
			else
				document.getElementById(tab_title+i).className = 'disyhidn';
		}
	}
	
	function LoadJavaScript(strSrc)
	{
		var objElement = document.createElement("script");

		objElement.language = "javascript";
		objElement.type = "text/javascript";
		objElement.src = strSrc;

		document.body.appendChild(objElement);
	}

	function FormVote(thsForm, sn)
	{
		for (var i=0; i<thsForm.vote.length; i++)
		{
			if (thsForm.vote[i].checked)
			{
			    if (readCookie("vote_gold") == null || readCookie("vote_gold") == "")
                 {
                      alert("請開啟 cookie 功能！");
                      return false;
                 }
                 else
                 {
				    LoadJavaScript("VoteHot.aspx?sn=" + sn + "&vote=" + thsForm.vote[i].value + "&rnd=" + Math.random());
                 }
				return false;
			}
		}

		alert("請選擇投票項目！");

		return false;
	}

	var CurrConversion = function (exn) { }

	function ConversionSubmit(thsElement)
	{
		var thsForm = thsElement.form;
		
		if (thsForm.Money0.value == "" || isNaN(thsForm.Money0.value))
		{
			alert("請輸入數據");

			thsForm.Money0.focus();

			return false;
		}

		thsElement.disabled = true;
		thsForm.Curr0.disabled = true;
		thsForm.Curr1.disabled = true;
		thsForm.Money0.disabled = true;

		var pattern = /^[^,]*,/;
		var aryCurr = new Array();

		aryCurr["gram,ounce"] = 0.03215;
		aryCurr["gram,money"] = 0.26666;
		aryCurr["gram,hktwo"] = 0.02672;
		aryCurr["ounce,gram"] = 31.1035;
		aryCurr["ounce,money"] = 8.294;
		aryCurr["ounce,hktwo"] = 0.8310;
		aryCurr["money,gram"] = 3.749264;
		aryCurr["money,ounce"] = 0.12056;
		aryCurr["money,hktwo"] = 0.10019;
		aryCurr["hktwo,gram"] = 37.42515;
		aryCurr["hktwo,ounce"] = 1.20337;
		aryCurr["hktwo,money"] = 9.981;

		var c0 = thsForm.Curr0.value;
		var c1 = thsForm.Curr1.value;
		var curr = c0.replace(pattern, "") + "," + c1.replace(pattern, "");
		var rt = aryCurr[curr];
		var ex = 1;

		if (!rt)
			rt = 1;

		pattern = /,[a-z]*$/;

		c0 = c0.replace(pattern, "");
		c1 = c1.replace(pattern, "");

		CurrConversion = function (exn) {

			thsElement.disabled = false;
			thsForm.Curr0.disabled = false;
			thsForm.Curr1.disabled = false;
			thsForm.Money0.disabled = false;

			alert( (Math.round(Number(thsForm.Money0.value) * exn / rt * 100) / 100) + " " + c1 );
		}

		if (c0 == c1)
		{
			c1 = thsForm.Curr1.options[thsForm.Curr1.selectedIndex].text;

			CurrConversion(ex);
		}
		else
		{
			c1 = thsForm.Curr1.options[thsForm.Curr1.selectedIndex].text;

			var objElement = document.createElement("SCRIPT");

			objElement.language = "javascript";
			objElement.type = "text/javascript";
			objElement.src = "/gold/Conversion.aspx?Curr0=" + c0 + "&" + "Curr1=" + encodeURIComponent(c1.replace(/\/[^\/]*$/, ""))  + "&rnd=" + Math.floor(Math.random()*10000000000000000) + (new Date()).getTime();

			document.body.appendChild(objElement);
		}

		return false;
	}
