///////////////////////////////////////////////////////////////////////////////
// Flash Template
///////////////////////////////////////////////////////////////////////////////
function insert_flash( _url , _width , _height )
{
    var h
	if (_height == 0) h=60;
	else h=_height;
	//alert(h);
	var writeStr =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + _width + '" height="' + h + '" align="middle">'
                  + '<param name="movie" value="' + _url + '">'
                  + '<param name="quality" value="high">'
                  + '<param name="wmode" value="transparent">'
                  + '<embed src="' + _url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + _width + '" height="' + h + '" wmode="transparent"></embed>'
                  + '</object>';

    document.write( writeStr );
}

///////////////////////////////////////////////////////////////////////////////
// ZTransferX Template
///////////////////////////////////////////////////////////////////////////////
function ZTransferX_object( _downloadURL )
{
    var writeStr =  '<OBJECT width = "0" height = "0" ID="ZTransferX" CLASSID="CLSID:C7C7225A-9476-47AC-B0B0-FF3B79D55E67" codebase="' + _downloadURL + '/ZTransferX.cab#version=1,0,3,6" VIEWASTEXT>'
                  + '<PARAM NAME="download.Server" VALUE="'+ _downloadURL + '">'
                  + '<PARAM NAME="download.Port" VALUE="80">'
                  + '<PARAM NAME="download.Instruction" VALUE="OzViewer.idf">'
                  + '<PARAM NAME="install.Base" VALUE="<PROGRAMS>/Forcs">'
                  + '<PARAM NAME="install.Namespace" VALUE="GSCONST">'
                  + '</OBJECT>';

    document.write( writeStr );

}

///////////////////////////////////////////////////////////////////////////////
// OZ Template
///////////////////////////////////////////////////////////////////////////////
function OZView_object( _server , _port , _reportname , _parms )
{
    var writeStr = '';
    
    writeStr = '<OBJECT id="objOZView" CLASSID="CLSID:0FF44578-C130-4A1F-AEE2-E902A7CDC3EC" width="100%" height="100%" border="0" VIEWASTEXT>'
             + '<param name="mayscript" value="true">'
             + '<param name="applet.configmode" value="html">'
             + '<param name="applet.isapplet" value="false">'
             + '<param name="applet.isframe" VALUE="false">'
             + '<param name="applet.smartframesize" value="true">'
             + '<param name="applet.usestatusbar" value="false">'
             + '<param name="language" value="ko/KR">'
             + '<param name="connection.compressedForm" value="true">'
             + '<param name="connection.compresseddatamodule" value="true">'
             + '<param name="FiresScriptEvents" value="true">'
             + '<param name="toolbar.all" value="true">'
             + '<param name="print.command" value="true">';

    // Form Location
    writeStr += '<param name="connection.server" value="' + _server + '">';
    writeStr += '<param name="connection.port" value="' + _port + '">';
    writeStr += '<param name="connection.reportname" value="' + _reportname + '">'

    // Parameters
    writeStr += '<param name="connection.pcount" value="' + _parms.length + '">';
    for( var i=0 ; i < _parms.length ; i++)
    {
        writeStr += '<param name="connection.args' + (i+1) + '" value="' + _parms[i][0] + '=' + _parms[i][1] + '">';    
    }

    writeStr += '</OBJECT> ';
    
    document.write( writeStr );

}
function gmobj(o){
	if(document.getElementById){ m=document.getElementById(o); }
	else if(document.all){ m=document.all[o]; }
	else if(document.layers){ m=document[o]; }
	return m;
}

function ShowGoldPrice(){
	var sHTML = '';	
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" id="rightTable" width="100%">');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="width:30%;"><b>Lo&#7841;i</b></td>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;"><b>Mua</b></td>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;"><b>B&#225;n</b></td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('</table>');
	gmobj('eGold').innerHTML = sHTML;
}

function ShowForexRate(){
	var sHTML = '';
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" width="100%" id="rightTable">');
	for(var i=0;i<vForexs.length;i++){
		sHTML = sHTML.concat('	<tr>');
		sHTML = sHTML.concat('		<td style="text-align:left"><b>').concat(vForexs[i]).concat('</b></td>');
		sHTML = sHTML.concat('		<td>').concat(vCosts[i]).concat('</td>');
		sHTML = sHTML.concat('	</tr>');
	}
	sHTML = sHTML.concat('</table>');
	gmobj('eForex').innerHTML = sHTML;
}
function FormatNumber(str){
	var strTemp = GetNumber(str);
	if(strTemp.length <= 3)
		return strTemp;
	strResult = "";
	for(var i =0; i< strTemp.length; i++)
		strTemp = strTemp.replace(",", "");
	for(var i = strTemp.length; i>=0; i--)
	{
		if(strResult.length >0 && (strTemp.length - i -1) % 3 == 0)
			strResult = "," + strResult;
		strResult = strTemp.substring(i, i + 1) + strResult;
	}	
	return strResult;
}
function GetNumber(str)
{
	for(var i = 0; i < str.length; i++)
	{	
		var temp = str.substring(i, i + 1);		
		if(!(temp == "," || temp == "." || (temp >= 0 && temp <=9)))
		{
			alert("Vui lòng nhập số (0-9)!");
			return str.substring(0, i);
		}
		if(temp == " ")
			return str.substring(0, i);
	}
	return str;
}

 function IsNumberInt(str)
{
	for(var i = 0; i < str.length; i++)
	{	
		var temp = str.substring(i, i + 1);		
		if(!(temp == "," || temp == "." || (temp >= 0 && temp <=9)))
		{
			alert("Vui lòng nhập số (0-9)!");
			return str.substring(0, i);
		}
		if(temp == " " || temp == ",")
			return str.substring(0, i);
	}
	return str;
}

function ConvertPriceText(strTemp)
{
   strTemp        = strTemp.replace(/,/g, "");
   var priceTy    = parseInt(strTemp/1000000000,0)
   var priceTrieu = parseInt((strTemp % 1000000000)/1000000,0)
   var priceNgan  = parseInt(((strTemp % 1000000000))%1000000/1000,0)
   var priceDong  = parseInt(((strTemp % 1000000000))%1000000%1000,0)
   var strTextPrice = ""      
   if(priceTy > 0 && parseInt(strTemp,0) > 900000000)
	strTextPrice = strTextPrice  + "<b>" + priceTy + "</b> tỷ "
   if(priceTrieu > 0)
	strTextPrice = strTextPrice  + "<b>" + priceTrieu + "</b> triệu "
   if(priceNgan > 0)
	strTextPrice = strTextPrice  + "</b>" + priceNgan + "</b> ngàn "
   if(document.getElementById("tiente").value == "vnd1")
   {
		if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
			strTextPrice = strTextPrice  + "<b>VNĐ</b>"
   }
   if(document.getElementById("tiente").value == "sjc")
   {
		 if(priceDong > 0)
			strTextPrice = strTextPrice + priceDong
		 if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
			strTextPrice = FormatNumber(strTemp) + "<b> lượng SJC</b>"
   }
   if(document.getElementById("tiente").value == "usd")
   {
		if(priceDong > 0)
			strTextPrice = strTextPrice + priceDong
		if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
			strTextPrice = FormatNumber(strTemp) + "<b> USD</b>"
   }
   document.getElementById("priceText").innerHTML = strTextPrice
}

function FocusObj(name)
{
   document.getElementById(name).focus()
}

/*
 * Change theme color
 * Type:	function
 * Name:	
 * Date:	2008/12/29
 * @author:	tri do <tridn@von-inc.com>
 */

function getThemeCookie(strname)
{
	var ckval = Get_Cookie(strname);
	if ( ckval )
	{
		return ckval;
	}
	else
	{
		return "yellowtheme";
	}
}
function setThemeCookie(strname,val){
	Set_Cookie( strname, val, 100, '/', '', '' );
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}




function TN_settheme(){
	if(themeName=='') themeName=getThemeCookie('themeName');
	//alert(themeName);
	document.body.className=themeName;
	var curtheme=document.getElementById(themeName);
	curtheme.className=curtheme.className+' active';
}
function TN_changetheme(obj){
	themeName=obj.id;
	for(i=0;i<obj.parentNode.childNodes.length;i++)
	{
		if(obj.parentNode.childNodes[i].nodeType!=3)
			{
				if(obj.parentNode.childNodes[i].className.match('active')) 
				{		
					obj.parentNode.childNodes[i].className=obj.parentNode.childNodes[i].className.replace(' active','');
				}
			}
	}
	setThemeCookie('themeName',themeName);
	TN_settheme();
}


