﻿/**
 * 選單收合
 * @author JASON WANG, LANECHANG HONG
 * @class 
 */
var MenuList = {

    _mm: null,

    _sm: null,

    currUnit: null,

    smNum: 0,

    isclick: false,

    box_title_in: function(_element) {
        _element.getElementsByTagName('div')[0].className = 'box_title_over';
        _element.getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';
    },

    box_title_out: function(_element) {
        if (_element.parentNode.id != this.currUnit) {
            _element.getElementsByTagName('div')[0].className = 'box_title';
            _element.getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = '';
        }
    },

    docGetElementsByClassName: function(_className) {
        var _resultArr = new Array();
        var _allArr = document.getElementsByTagName('*');

        try {
            for (var i = 0; i < _allArr.length; i++) {
                if (_allArr[i].className == _className) {
                    _resultArr[_resultArr.length] = _allArr[i];
                }
            }
            return _resultArr;
        }
        catch (e) {
            return null;
        }
        finally {
            _resultArr = null;
            _allArr = null;
            delete _resultArr;
            delete _allArr;
        }
    },

    click2focus: function(_element, _evt) {
        _element.focus();
        (_evt.type == 'click') ? this.isclick = true : this.isclick = false;
    },

    box_toggle_expand: function(_element) {
        var _elmt = _element;
        var i = 1;
        var collection = document.getElementsByTagName('div');
        var tmpId = '';
        try {
            if (_element.href.indexOf('#') == -1 && this.isclick == true) {
                document.location = _element.href;
                 throw new Error();
            }

            this.isclick = false;
            this.currUnit = _elmt.parentNode.id;
            if (_elmt.parentNode.className == 'box') {

                for (i = 1; i <= collection.length; i++) {
                    if (collection[i - 1].id.substring(0, 4) == 'box_' || collection[i - 1].id.substring(0, 3) != 'box') continue;
                    tmpId = collection[i - 1].id.replace('box', '');
                    if (collection[i - 1].id == this.currUnit) {
                        collection[i - 1].className = 'box_expand';
                        collection[i - 1].getElementsByTagName('div')[0].className = 'box_title_over';
                        collection[i - 1].getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';

                        if (document.getElementById('box_content' + tmpId) != null) document.getElementById('box_content' + tmpId).style.display = 'block';

                    }
                    else {
                        collection[i - 1].className = 'box';
                        collection[i - 1].getElementsByTagName('div')[0].className = 'box_title';
                        collection[i - 1].getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = '';
                        if (document.getElementById('box_content' + tmpId) != null) document.getElementById('box_content' + tmpId).style.display = 'none';
                    }
                    tmpId = null;
                }
            }
            else {
                _elmt.parentNode.className = 'box';

                if (document.getElementById('box_content' + _elmt.parentNode.id.substr(_elmt.parentNode.id.length - 1, 1)) != null)
                    document.getElementById('box_content' + _elmt.parentNode.id.substr(_elmt.parentNode.id.length - 1, 1)).style.display = 'none';
            }
        }
        catch (e) {
            return;
        }
        finally {
            _elmt = null;
            i = null;
            collection = null;
            tmpId = null;
            delete collection;
            delete tmpId;
            delete i;
            delete _elmt;
        }
    },

    getParam: function(_paramStr) {
        var v = {
            _href: document.location.href,
            _qStr: null,
            _obj: null,
            _valueParamArr: null,
            i: 0
        }

        try {
            v._qStr = v._href.split('?')[1];
            if (v._qStr == null) throw new Error();
            v._obj = new Object();
            v._valueParamArr = v._qStr.split('&');
            for (v.i = 0; v.i < v._valueParamArr.length; v.i++) {
                v._obj[v._valueParamArr[v.i].split('=')[0]] = v._valueParamArr[v.i].split('=')[1];
            }

            if (v._obj[_paramStr] == null || v._obj[_paramStr] == undefined) throw new Error();
            return v._obj[_paramStr];
        }
        catch (e) {
            return ''
        }
        finally {
            v = null;
            delete v;
        }
    },

    highlightCurrUnit: function() {
        this.smNum = this.docGetElementsByClassName('box').length;
        this._mm = this.getParam('mm');
        this._sm = this.getParam('sm');

        try {
            if (this._mm != '') {
                this.currUnit = 'box' + this._mm;
                document.getElementById(this.currUnit).className = 'box_expand';
                if (document.getElementById('box_content' + this._mm) != null) document.getElementById('box_content' + this._mm).style.display = 'block';
                document.getElementById(this.currUnit).getElementsByTagName('div')[0].className = 'box_title_over';
                document.getElementById(this.currUnit).getElementsByTagName('div')[0].getElementsByTagName('div')[0].className = 'box_title_txt_over';

                if (this._sm != '') {             
                   document.getElementById(this.currUnit).getElementsByTagName('a')[this._sm].style.color = '#ffffff';
                   document.getElementById(this.currUnit).getElementsByTagName('a')[this._sm].style.backgroundColor = '#34a7b7';
                }
            }
        }
        catch (e) {
            return;
        }
    }
};


/**
 * 最新消息圖片外框變色
 * @param el -外框div元素
 * @param color -變換色碼
 */
function newsImgborderColor(el, color) {
    var altEl = null;
    try{
        el.style.borderColor = color;
        altEl = document.getElementById(el.id + '_ALT');
        if (altEl != undefined && altEl != null) altEl.style.color = color;
    }
    catch(e) {
        return;
    }
    finally {
        altEl = null;
    }
}


var ChangeFontSize = {
	
	/**
	 * 是否使用Cookie儲存字型設定資料
	 * @type Boolean
	 */
	isUseCookie: true,
	
	/**
	 * Cookie索引名稱
	 * @type String
	 */
	cookieName: 'CurrFontSize',
	
	/**
	 * 是否改變圖片狀態
	 * @type Boolean
	 */
	isChangeImage: true,
	
	/**
	 * 文字大小尺寸陣列
	 * @type Array
	 */
	fontSize: ['90%', '100%', '125%', '135%'],	
	
	/**
	 * 圖片id陣列
	 * @type Array
	 */
	imgID: ['fontSize1', 'fontSize2', 'fontSize3', 'fontSize4'],
	
	/**
	 * 普通狀態圖片CSS陣列
	 * @type Array
	 */
	normalCSS: ['FuncBar_Font1', 'FuncBar_Font2', 'FuncBar_Font3', 'FuncBar_Font4'],
	
	/**
	 * 滑鼠覆蓋狀態圖片CSS陣列
	 * @type Array
	 */
	overCSS: ['FuncBar_Font1_ov', 'FuncBar_Font2_ov', 'FuncBar_Font3_ov', 'FuncBar_Font4_ov'],
	
	/**
	 * 網頁載入完畢初始讀取
	 */
	OnLoad: function() {
		var index = this.ReadCookie(this.cookieName) || 1;
		try {
			//查詢Cookie是否使用Cookie
			if (this.isUseCookie) {			
				document.body.style.fontSize = this.fontSize[parseInt(index)] || this.fontSize[1];			
			}
			
			this.Update(index);
		}
		catch(e) {
			return;
		}
		finally {
			index = null;
		}
	},
	
	/**
	 * 立即改變字型大小
	 */
	Immediate: function() {
		var i, currSize;
		
		try {
			//檢查陣列資料
			if (this.fontSize == null || this.fontSize.length == 0) throw new Error('大小索引錯誤。');
			
			//讀取目前尺寸或預設值
			currSize = document.body.style.fontSize || '100%';
			
			for (i=1; i<=this.fontSize.length; i++) {
				if (this.fontSize[i-1] == currSize) {
					document.body.style.fontSize = (i==4? this.fontSize[0]: this.fontSize[i]);
					
					//假如啟用圖片轉換
					if (this.isChangeImage) {
						//重製圖片並且更改選取字型的圖片顏色
						this.ResetImg();
						this.ImgClick((i==4? 0: i));
					}
					//假如有使用Cookie則寫入Cookie
					if (this.isUseCookie) this.CreateCookie(this.cookieName, (i==4? 0: i), 1);
				}
			}		
		}
		catch(e) {
			alert(e.Message);
			return;
		}
		finally {
			i = null;
			currSize = null;
		}
	},
	
	/**
	 * 依照索引改變文字大小
	 * @param {number} fontIndex -陣列索引
	 */
	Update: function(fontIndex) {
		var index;
		try {
			index = parseInt(fontIndex);
			if (this.fontSize == null || this.fontSize.length < (index+1)) throw new Error('大小索引錯誤。');
			document.body.style.fontSize = this.fontSize[index];	
			
			if (this.isChangeImage) this.ImgClick(fontIndex);			
			if (this.isUseCookie) this.CreateCookie(this.cookieName, (fontIndex), 1);
		}
		catch(e) {
			alert(e.Message);
			return;
		}
		finally {
			index = null;
		}
	},
	
	/**
	 * 選擇字型按下改變圖片樣式
	 * @param {number} idIndex -陣列索引
	 */
	ImgClick: function(idIndex) {
		var el, index;
		
		try {
			index = parseInt(idIndex);
			if (this.imgID == null || this.imgID.length < (index+1)) throw new Error('圖片id索引錯誤。');
			if (this.normalCSS == null || this.normalCSS.length < (index+1)) throw new Error('CSS索引錯誤。');
			if (this.overCSS == null || this.overCSS.length < (index+1)) throw new Error('CSS索引錯誤。');
			
			this.ResetImg();
			el = document.getElementById(this.imgID[idIndex]);
			el.className = this.overCSS[idIndex];
		}
		catch(e) {
			return;
		}
		finally {
			el = null;
			index = null;
		}	
	},
	
	/**
	 * 重置圖片
	 */
	ResetImg: function() {
		var i, el;
		try {
			if (this.isChangeImage) {
				for(i=1; i<=this.imgID.length; i++) {
					el = document.getElementById(this.imgID[i-1]);
					if (el == null) continue;				
					el.className = this.normalCSS[i-1];
				}
			}
		}
		catch(e) {
			return;
		}
		finally {
			i = null;
			el = null;
		}
	},
	
	/**
	 * 建立Cookie
	 * @param {string} name -索引名稱
	 * @param {string} value -值
	 * @param {number} days	-天數
	 */
	CreateCookie: function(name, value, days) {
		var date, expires;
		try {
			if (days) {
	    		date = new Date();
	    		date.setTime(date.getTime()+(days*24*60*60*1000));
	    		expires = '; expires='.concat(date.toGMTString());
			}
	 		else expires = '';
	  		document.cookie = name.concat('=', value, expires, '; path=/');			
		}
		catch(e) {
			alert('Cooke建立失敗：'.concat(e.Message));
		}
		finally {
			date = null;
			expires = null;
		}
	},
	
	/**
	 * 讀取Cookie的值
	 * @param {string} name -索引名稱
	 * @return {string}
	 */
	ReadCookie: function(name) {
		var nameEQ, ca;
	    
	    try {	    	
			nameEQ = name.concat('=');
	    	ca = document.cookie.split(';');
			for(var i=0; i<ca.length; i++) {
				var c = ca[i];
		    	while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
		  	return null;
		}
		catch(e) {
			alert('Cookie讀取失敗：'.concat(e.Message));
			return null;
		}
		finally {
			nameEQ = null;
			ca = null;
		}
	}
};



function doResize() {
	//alert(document.body.clientWidth);
	
	if (document.body.clientWidth<1064) {
		//alert('<994');
		document.getElementById('menu').className='menu_scroll';
		document.getElementById('nav_top').className='nav_top_scroll';
	}else {
		//alert('>=994');
		document.getElementById('menu').className='menu';
		document.getElementById('nav_top').className='nav_top';
	}
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}


/**
 * 預載圖片陣列
 * @type Array
 */
var loadImg = [
	'/images/zhTW/images/content_06_3ov.gif',
	'/images/zhTW/images/content_06_4ov.gif',
	'/images/zhTW/images/content_06_2ov.gif',
	'/images/zhTW/images/btn_Trailov.gif',
	'/images/zhTW/images/btn_gsov.gif',
	'/images/zhTW/images/qm_mapov.jpg',
	'/images/zhTW/images/ta02ov_37.jpg',
	'/images/zhTW/images/ta02ov_38.jpg',
	'/images/zhTW/images/ta02ov_40.jpg',
	'/images/zhTW/images/pic-shoot2.jpg',
	'/images/zhTW/images/bt_rov_06.jpg',
	'/images/zhTW/images/bt_rov_07.jpg',
	'/images/zhTW/images/bt_rov_10.jpg',
	'/images/zhTW/images/bt_rov_11.jpg',
	'/images/zhTW/images/bt_wov.gif',
	'/images/zhTW/images/r_bannerov_17.gif',
	'/images/zhTW/images/r_bannerov_20.gif',
	'/images/zhTW/images/r_bannerov_23.gif',
	'/images/zhTW/images/r_bannerov_26.gif',
	'/images/zhTW/images/r_bannerov_29.gif',
	'/images/zhTW/images/r_bannerov_32.gif'
];

/**
 *頁面載入
 */
function pageLoad() {
	MM_preloadImages(loadImg[0],  loadImg[1],  loadImg[2],  loadImg[3],  loadImg[4],  loadImg[5],
	                 loadImg[6],  loadImg[7],  loadImg[8],  loadImg[9],  loadImg[10], loadImg[11],
	                 loadImg[12], loadImg[13], loadImg[14], loadImg[15], loadImg[16], loadImg[17],
	                 loadImg[18], loadImg[19], loadImg[20]);
	MenuList.highlightCurrUnit();
	doResize();
}


var loadMask = {
    msg: ['申請資料傳送中，請稍候‧‧‧', '重置表單‧‧‧', '資料傳送中，請稍候‧‧‧',
          '查詢中，請稍候‧‧‧'],
    maskID: ['loadingMask', 'loadingFont'],

    show: function(index) {
        var i;
        var elTemp;
        try {
            for (i = 1; i <= this.maskID.length; i++) {
                elTemp = document.getElementById(this.maskID[i - 1]);
                if (elTemp != undefined && elTemp != null) {
                    elTemp.innerHTML = elTemp.innerHTML.replace('{$MSG}', this.msg[index]);
                    elTemp.style.visibility = 'visible';
                    elTemp.style.display = 'block';
                }
            }
        }
        catch (e) {
            return;
        }
        finally {
            i = null;
            elTemp = null;
        }
    },

    hide: function() {
        var i;
        var elTemp;
        try {
            for (i = 1; i <= this.maskID.length; i++) {
                elTemp = document.getElementById(maskID[i - 1]);
                if (elTemp != undefined && elTemp != null) {
                    elTemp.style.visibility = 'hidden';
                    elTemp.style.display = 'none';
                }
            }
        }
        catch (e) {
            return;
        }
        finally {
            i = null;
            elTemp = null;
        }
    }
};
