﻿

var expDays = 1; // number of days the cookie should last



var path = "/";
var domain ;
var locapath = document.location.href


org_path_start = locapath.indexOf("://") + 3;

org_path_end = locapath.length;

domain = locapath.substring(org_path_start, org_path_end);

if (domain.toString().search('/')!= -1){

org_path_start = 0;

org_path_end = domain.indexOf("/");

domain = domain.substring(org_path_start, org_path_end);

}





function GetCookie (name) {  

var arg = name + "=";  

var alen = arg.length;  

var clen = document.cookie.length;  

var i = 0;  

while (i < clen) {    

var j = i + alen;    

if (document.cookie.substring(i, j) == arg)      

return getCookieVal (j);    

i = document.cookie.indexOf(" ", i) + 1;    

if (i == 0) break;   

}  

return null;

}

function SetCookie (name, value) {  

var argv = SetCookie.arguments;  

var argc = SetCookie.arguments.length;  

var expires = (argc > 2) ? argv[2] : null;  

var secure = (argc > 5) ? argv[5] : false;  

document.cookie = name + "=" + escape (value) + 

((path == null) ? "" : ("; path=" + path)) +  

((domain == null) ? "" : ("; domain=" + domain)) +    

((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) {  

var exp = new Date();  

exp.setTime (exp.getTime() - 1);  

var cval = GetCookie (name);  

document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();

}

var exp = new Date(); 

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){

var count = GetCookie('sccount')

if(count == null) {

SetCookie('count','1')

return 1

}

else {

var newcount = parseInt(count) + 1;

DeleteCookie('sccount')

SetCookie('sccount',newcount,exp)

return count

   }

}

function getCookieVal(offset) {

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)

endstr = document.cookie.length;

return unescape(document.cookie.substring(offset, endstr));

}



function checkCount() {

var sccount = GetCookie('sccount');

if (sccount == null) {



SetCookie('orgiurl',document.location.href, exp);



window.location.href=page;

}

}


function chglang(dist) {
    dist = (dist=="") ? "tc_chi" : dist;
	loc = location.href.replace("/english",'/' + dist);
	location.href = loc;
}

function txtchglang(dist) {
    dist = (dist=="") ? "tc_chi" : dist;
	loc = location.href.replace("/textonly/english",'/' + dist);
	location.href = loc;
}

function splitString (stringToSplit,separator) {

 var arrayOfStrings = stringToSplit.split(separator);

 return arrayOfStrings[1];

}





/* ==================================================================================================
 * Handling the Font Size Changes
 * ====================================================================================================
 */

// Removes leading and ending whitespaces
// Trim double byte space also
function Trim(str)
{
	return str.replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
}
 
// global
// var for Font Size and Linear Version
var fontarray = new Array("Medium","Large","Extra");
var myfonttitle = "";
var myscreenmode = "";
var displayfonttitle = "";


// var for detect IE VERSION (for IE5.5 )
var userAgent="";
var ie_version=0;
function GetIEVersion() {
	userAgent = navigator.userAgent;
	if (userAgent.indexOf('MSIE') != -1) {
		ie_version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
	}
}

// Cookie Functions:
function createCookie(name,value,days) {
  if (days != null) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  var caLength = ca.length;
  for(var i=0;i < caLength;i++) {
    var c = Trim(ca[i]);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


// Handle the Font
function changeFont(title){
	myfonttitle = title;

	// display font is same for Format Version
	displayfonttitle = myfonttitle;

	// set fonttitle cookie to 2 months
	createCookie("infosecfonttitle", myfonttitle, 60);

	// switch the CSS
	switchCss();

	// swap the Font Image
	swapFontImage();
	/*
	// As requested by User, will refresh the windows
	try{
		window.location.reload();
	}catch(e){
		window.location = locapath;
	}
	*/
}


function switchCss() {
  // CAUTION reminder 20070913:
  // 1) IE7 need a.disabled=true first, no matter how (is this true?)
  // 2) firefox2.04 canNOT use: a.getAttribute("title").indexOf("linear"), else break for-loop
  // 3) firefox can use: var1=a.getAttribute("title"), then compare on var1

	var linkArray = document.getElementsByTagName("link");
	var linkArrayLength = linkArray.length;

	for(i=0; i<linkArrayLength; i++)
	{
		a=linkArray[i];
		// for all "stylesheet" in Link
		if (a.getAttribute("rel").indexOf("stylesheet")!=-1)
		{
			var disable_flag = false;
			// if it is linear mode, assume all css disable first
			//if (myscreenmode==modeLinear) { disable_flag=true; }

			// get the id of css object first
			var id1 = a.getAttribute("id");
			if (id1 != null) {
				if (id1.indexOf("infosecCss")!=-1  ) {
					// For "style.css"
					// handled by default
				} else if (id1.indexOf("mode")!=-1)  {
					// For "modeMedium", "modeLarge", "modeExtra"
					// for normal mode, disable first;
					disable_flag = (id1.indexOf(displayfonttitle) < 0);
				}

			} // end id1!=null

			// 20070917: finally set the enable or disable, set true first for IE7 bug
			a.disabled = true;
			a.disabled = disable_flag;


			// for IE5.5, disable can be set by a.disabled = true;
			// BUT for ENABLE, IE5.5 need to set the alt-stylesheet as "stylesheet"
			// CAUTION: do NOT set "alternate stylesheet" in this way, will hang IE5.5 browser
			if (ie_version>0 && ie_version<6 && disable_flag==false) {
				a.setAttribute("rel","stylesheet");
			}

		} // end if rel stylesheet
	} // end for linkArray
}

function swapFontImage() {
	// display - swap on or off images
	var fontarrayLength = fontarray.length;
	for (i=0;i<fontarrayLength;i++)
	{

		if (displayfonttitle==fontarray[i] ) {
			// seperate to 2 part, avoid change 'gif' to 'htm' when grab the website
			fonttail = '<b><font color="#FF3300">A</font></b>';
		} else {
			fonttail = 'A';
		}

		fontimg = 'txtsize_area_Font_' + fontarray[i];
		var fontImgObj = document.getElementById(fontimg);
		fontImgObj.innerHTML = fonttail;
	}
}

function readAccessCookie() {
	// if FF or IE6+
	if (ie_version==0 || ie_version>=6) {
		myfonttitle = readCookie("infosecfonttitle");
		if (myfonttitle==null) {myfonttitle=fontarray[0]; }

		// for clear old R2 cookie
		if (myfonttitle!=fontarray[0] && myfonttitle!=fontarray[1] && myfonttitle!=fontarray[2] )
		   { myfonttitle = fontarray[0]; }

		displayfonttitle = myfonttitle;
	} else {
		myfonttitle = fontarray[0];
		displayfonttitle = myfonttitle;
	}
}

// on load pages...
// run by default
function loadingFontOnload(){
	GetIEVersion();
	readAccessCookie();
	switchCss();
	// never swap the Font image after the font image is loaded
	//swapFontImage();
}

loadingFontOnload();

/* ==================================================================================================
 * End Handling the Font Size Changes
 * ====================================================================================================
 */