﻿var style_cookie_name = "style" ;
var style_cookie_duration = 30 ;


function show_nav() {
	if ( document.getElementById('submenuir').getStyle('display') == 'none' ) {
		document.getElementById('submenuir').setStyle('display','block');
	} else {
		document.getElementById('submenuir').setStyle('display','none');
	}
}


// Function to change language
function changelang(frlang, tolang){

	var curUrl = document.location.href;	
	curUrl = curUrl.replace(frlang, tolang);	
	
	document.location=curUrl;	
	
}

function changeFont(fntsize, thelang){
		
	if (fntsize=="small") {
		document.getElementById('generalstyle').href = '/'+thelang+'/css/style.css';
		document.smallChar.src = "/img/textsizebn01b.gif";
		document.normalChar.src = "/img/textsizebn02.gif";
		document.bigChar.src = "/img/textsizebn03.gif";		
	}else if (fntsize=="medium") {
		document.getElementById('generalstyle').href = '/'+thelang+'/css/mid.style.css';
		document.smallChar.src = "/img/textsizebn01.gif";
		document.normalChar.src = "/img/textsizebn02b.gif";
		document.bigChar.src = "/img/textsizebn03.gif";
	}else if (fntsize=="big") {
		document.getElementById('generalstyle').href = '/'+thelang+'/css/big.style.css';
		document.smallChar.src = "/img/textsizebn01.gif";
		document.normalChar.src = "/img/textsizebn02.gif";
		document.bigChar.src = "/img/textsizebn03b.gif";
	}
	set_cookie( style_cookie_name, fntsize, style_cookie_duration );
}

function testForObject(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o)
  {
    if (Tag)
    {
      if (o.tagName.toLowerCase() == Tag.toLowerCase())
      {
        return o;
      }
    }
    else
    {
      return o;
    }
  }
  return null;
}

function bookmark(description)
{
	var url=document.location.href;
	netscape="Firefox/Netscape User's hit CTRL+D to add a bookmark to this page."
	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		alert(netscape);
	}
}

function PrintThisPage(secname) 
{ 
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

   var sWinHTML = document.getElementById('main').innerHTML; 
   var sBtmHTML = document.getElementById('bottom').innerHTML; 
      
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write("<html><LINK href='/eng/css/style.css' rel=Stylesheet>"); 
       winprint.document.write("<LINK href='/eng/css/printonly.css' rel=Stylesheet>"); 
       winprint.document.write("<LINK href='/eng/css/"+secname+".css' rel=Stylesheet><body>"); 
       winprint.document.write(sWinHTML);
       winprint.document.write(sBtmHTML);
       winprint.document.write("<script>document.getElementById('contenttopnav').style.display='none';window.print();</script>");
       winprint.document.write('</body></html>'); 
       winprint.document.close(); 
       winprint.focus(); 
   
}

//Function for top-right search box submission
function goSubmit(theForm, thelang){
	if (theForm.q.value==""){
		if (thelang=="en"){
			alert("Please input a keyword to search.");
		}else{
			alert("請輸入關鍵字搜尋。");
		}
		return false;
	}else{
		return true;
	}
}

function chkSubscribe(theForm, word1, word2, word3, word4, word5){

	if (ValidateForm('T','email',word1,'M|Email', 'T','name',word3 ,'M', 'T','tel',word4 ,'M|N', 'T','org',word5 ,'M', 'T','verifycode',word2,'M')){
		theForm.submit();
	}
}

function chkUnSubscribe(theForm, word1, word2, word3, word4, word5){

	if (ValidateForm('T','email',word1,'M|Email', 'T','verifycode',word2,'M')){
		theForm.submit();
	}
}

function set_cookie ( cookie_name, cookie_value, lifespan_in_days, valid_domain )
{
    var domain_string = valid_domain ?
                       ("; domain=" + valid_domain) : '' ;
    document.cookie = cookie_name +
                       "=" + encodeURIComponent( cookie_value ) +
                       "; max-age=" + 60 * 60 *
                       24 * lifespan_in_days +
                       "; path=/" + domain_string ;
}

function set_style_from_cookie( thelang ){
  var css_title = get_cookie( style_cookie_name );
  if (css_title.length) {
    changeFont(css_title, thelang);
  }else{
    changeFont('small', thelang);	
  }
}

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 '';
	}
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


    
function subOnchange(x) {

  if (x.id == "submit_button")
   {
    		document.getElementById("searchExecute").value="1";
   		
   }
   else if (x.id == "subMenu")
   {
   			document.getElementById("searchExecute").value="0";
   }
	//alert(document.getElementById("searchExecute").value);

}