// IE 5.5 handling:
var ie_version = 0;
function GetIEVersion() {
	
	// 20070906: find ie_version when it is MSIE
	userAgent = navigator.userAgent;
	if (userAgent.indexOf('MSIE') != -1) {
		ie_version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
	}
	// 20070914: not need to rewrite as "_getElementsByTagName"
}
// Cookie Functions:
function readAccessCookie() {
	// if FF or IE6+
	if (ie_version == 0 || ie_version >= 6) { 
		myfonttitle = readCookie("govhkfonttitle");
		if (myfonttitle==null) {myfonttitle=fontarray[0]; }
		
		myscreenmode = readCookie("govhkscreenmode");
		if (myscreenmode==null) {myscreenmode=modeFormat; } 
		
		// for clear old R2 cookie
		if (myfonttitle!=fontarray[0] && myfonttitle!=fontarray[1] && myfonttitle!=fontarray[2] ) 
		   { myfonttitle = fontarray[0]; }
		if (myscreenmode!=modeFormat && myscreenmode!=modeLinear) { myscreenmode = modeFormat; }
		
		displayfonttitle = myfonttitle;
	} else {
		// ie5.5 or down, provide Linear Version only
		myfonttitle = fontarray[2];
		myscreenmode = modeLinear;
		displayfonttitle = myfonttitle;
	}
}

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 = TrimString(ca[i]);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function TrimString(strIn) {
  return strIn.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function SetDefaultFont()
{
if (readCookie("sdgovfonttitle")!=null)
{

switchCss(TrimString(readCookie("sdgovfonttitle")));
	
}
	
}
function switchCss(FontSize) {
  var floortag = document.getElementsByTagName("*"); 
  createCookie("sdgovfonttitle", FontSize, 60);
  for (i=1;i<=3;i++)
			{
			if(i==FontSize)	
			{
			
			floortag["fontsizeimg"+i].src="http://www.shandong.gov.cn/sdgov/f"+i+".g"+"if";	
			}
			else
			{
			floortag["fontsizeimg"+i].src="http://www.shandong.gov.cn/sdgov/f"+i+"_1.g"+"if";	
			}
			}
	CssObj="fontsize"+FontSize;
	
	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;
		
			var id1 = a.getAttribute("id");
			if (id1 != null) {
				if (id1.indexOf(CssObj)!=-1 ) {
									
					disable_flag = false;	
					
					
				} else if (id1.indexOf("fontsize")!=-1 ) {
					
					disable_flag = true;
					
				} 
			
			} 
			
		
			a.disabled = true;
			a.disabled = disable_flag;
			
				if (ie_version > 0 && ie_version < 6 && disable_flag==false) {
				a.setAttribute("rel","stylesheet");									
			}
		  
		}
	} 
}
function beforeOnload() {
	GetIEVersion();					// (a) - depend on browser
	// (b) - depend on URL
			// (c) - depend on cookie, (a)
	SetDefaultFont();			// (e) - depend on (a), (c)
	// (on HTML: displayTwoLang();  // (f) - depend on (b)
}
beforeOnload();