/******************************************************************************
* U_script.js                                                                 *
*                                                                             *
* Copyright 2006 by Transcend Online Store                                    *
* 線上購物網網址: http://shop.transcend.com.tw                                *
* 最後更新日期: Sep 27, 2006.                                                 *
*                                                                             *
******************************************************************************/
var widthcheck = false;	 //定義版面寬窄的變數為窄:false,寬:true

var main_width = ec_getcookie('main_width'); //讀取Cookie於變數中

if(main_width == 'wide'){ 
	document.createStyleSheet('U_css_wide.css');
	//document.write('<link rel="stylesheet" type="text/css" href="U_css_wide.css">');
	widthcheck = true;	
}

//判定顯示圖片
function show_width_icon(webpath){	
	if(main_width == 'wide'){ 
		document.write('<img src="'+webpath+'top3_screen_narrow.gif" border="0" id="width_icon" align="absmiddle"')
	}
	else{
		document.write('<img src="'+webpath+'top3_screen_wide.gif" border="0" id="width_icon" align="absmiddle"')	
	}	
}

//動態改變網頁的寬度
function changewidth(webpath){
	if (widthcheck){
		document.getElementById('main_table').style.width = '1000px';
		document.getElementById('width_icon').src = webpath + 'top3_screen_wide.gif';
		widthcheck = false;
		ec_main_width('narrow');		
	}
	else{
		document.getElementById('main_table').style.width = '100%';
		document.getElementById('width_icon').src = webpath + 'top3_screen_narrow.gif';		
		widthcheck = true;
		ec_main_width('wide');
	}	
}

//寫入Cookie記錄
function ec_setcookie(theName,theValue,theDay){
	if ((theName!= null) && (theValue!= null))
	{
		setDay = new Date();
		setDay.setTime(setDay.getTime()+(10*1000*60*60*24));
		expDay = setDay.toGMTString();
		document.cookie = theName + "="+escape(theValue)+";expires="+expDay;
		return true;
	}
	return false;
}

//讀取Cookie記錄
function ec_getcookie(theName){
	theName += "=";
	theCookie =document.cookie+";";
	start = theCookie.indexOf(theName);
	if (start != -1)
	{
		end = theCookie.indexOf(";",start);
		return unescape(theCookie.substring(start+theName.length,end));
	}
	return false;
}	

//清除Cookie
function ec_deletecookie(theName){
	document.cookie = theName + "=;expires= Thu, 01 Jan 2000 00:00:01 GMT"; 
}

//記錄此使用者的版面寬度於Cookie中
function ec_main_width(wvalue){
	OS_name   = 'main_width';
	OS_Value  = wvalue;
	OS_exp    = '';
	ec_deletecookie(OS_name);		
	ec_setcookie(OS_name,OS_Value,OS_exp);
}

