﻿/***********************************************************************************/
/****** page loading ***************************************************************/
/***********************************************************************************/
document.write('<div id="pageLoadingMask"><div id="pageLoadingBox"><div id="pageLoadingImg"></div><div id="pageLoading">網頁載入中, 請稍待 ... </div></div></div>');
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
/***********************************************************************************/
/****** default varient ************************************************************/
/***********************************************************************************/
g5myCompany = "鼎立不動產";
g5myWebName = "林冬利不動產資訊網";
g5myWebUrl = "http://www.g5168.com/";
g5myMobil = "0955-300350";
g5message = "歡迎光臨" + g5myWebName + "\n\n如需服務請來電 : " + g5myMobil + " 謝謝!!";
/***********************************************************************************/
/****** mouse(mvalue) and keyboard(kvalue) event ************************************/
/***********************************************************************************/
function g5nothingEnable() {
	return false;
}
function g5noContextMenu() {
	event.cancelBubble = true;
	event.returnValue = false;
	alert(g5message);
	return false;
}
function g5noRightClick(e) {
	if (window.Event) {
		if (e.which == 2 || e.which == 3) {
			alert(g5message);
			return false;
		}
	} else {
		if (event.button == 2 || event.button == 3) {
			event.cancelBubble = true;
			event.returnValue = false;
			alert(g5message);
			return false;
		}
	}
}
function g5pageLocked(mvalue,kvalue) {
	if (mvalue==true) {
		document.onmousedown = g5noRightClick; // for all others
		document.oncontextmenu = g5noContextMenu; // for IE5+
		if (g5checkBrowser.firefox) { // for firefox
			document.oncontextmenu = new Function("alert(g5message);return false");
		}
		document.onselect = "document.selection.empty()";
		document.onselectstart = g5nothingEnable;
		document.ondragstart = g5nothingEnable;
		document.onmousemove = g5nothingEnable;
		document.onmouseup = g5nothingEnable;
		//if (!g5checkBrowser.chrome&&!g5checkBrowser.firefox) {document.onmousedown = g5nothingEnable;} // if not browser of google
		document.oncopy = g5nothingEnable;
		document.onbeforecopy = g5nothingEnable;
	}
	document.onkeydown = function() {
		if (kvalue==true) {
			if (event.shiftKey||event.altKey||event.ctrlKey) {
				alert(g5message);
			}
			return false;
		} else {
			return true;
		}
	}
	if (g5checkBrowser.firefox) { // for firefox
		if (kvalue==true) {
			document.onkeydown = new Function("alert(g5message);return false;");
		} else {
			document.onkeydown = new Function("return true;");
		}
	}
}
/***********************************************************************************/
/****** Prototype function $ *******************************************************/
/***********************************************************************************/
function $id(){
	var elements = new Array();
		for (var i = 0; i < arguments.length; i++){
			var element = arguments[i];
			if (typeof element == 'string'){
				element = document.getElementById(element);
			}
			if (arguments.length == 1){
				return element;
			}
			elements.push(element);
		}
	return elements;
}
var $name = function(id){
	return "string" == typeof id ? document.getElementsByName(id) : id;
}
var $tag = function(id){
	return "string" == typeof id ? document.getElementsByTagName(id) : id;
}
/***********************************************************************************/
/****** marqueeNews Up *************************************************************/
/***********************************************************************************/
var g5setMarqueeNews = function(container,row,delay,speed) {
	if (typeof container == 'string') container = document.getElementById(container);
	if (typeof container == 'undefined' || !container) return;
	if (typeof row == 'undefined' || row == null) row = 2;
	if (typeof delay == 'undefined' || delay == null) delay = 10000;
	if (typeof speed == 'undefined' || speed == null) speed = 30;
	var ps = container.getElementsByTagName('li');
	var length = ps.length;
	var cheight = length > 0 ? ps[0].offsetHeight : 0;
	var movetime = null;
	var time = null;
	var pause = false;
	var modstop = false;
	container.onmouseover = function(){if ( modstop == true) pause = true;};
	container.onmouseout = function(){pause = false;};
	var show = function(delay,d) {
		clearInterval(movetime);
		clearTimeout(time);
		var top = 0;
		var start = function() {
			movetime = setInterval(move, speed);
		};
		var setNode = function() {
			var plist = container.getElementsByTagName('li');
			var i = 0;
			var t = container.scrollTop;
			while( t >= cheight ) {
				t -= cheight;
				container.appendChild(plist[i++]);
			}
			container.scrollTop = 0;
		};
		var move = function() {
			if (pause) return;
			modstop = false;
			var plist = container.getElementsByTagName('li');
			container.scrollTop += 2;
			var mod = container.scrollTop % cheight;
			if ( mod == 0 || mod == 1 || mod == -1) {
				modstop = true;
				clearInterval(movetime);
				container.appendChild(plist[0]);
				container.scrollTop = 0;
				time = setTimeout(start, delay);
			}
		};
		setNode();
		start();
	};
	show(delay);
}
/***********************************************************************************/
/****** get width & height *********************************************************/
/***********************************************************************************/
// source from - http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
// test page - http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position_test.html
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
/***********************************************************************************/
/****** g5fade('div.id','mode:in,out','speed:fast,slow') ***************************/
/***********************************************************************************/
function g5fade(id,mode,speed,type) {
	var obj = $id(id);
	var finalOpacity, currentOpacity, newOpacity;
	var delay = 5;
	switch (mode) {
		case "in" :
			finalOpacity = 100;
			currentOpacity = 10;
			break;
		case "out" :
			finalOpacity = 0;
			currentOpacity = 100;
			break;
		default :
			finalOpacity = 100;
			currentOpacity = 10;
	}
	switch (speed) {
		case "fast" :
			speed = 1;
			break;
		case "slow" :
			speed = 100;
			break;
		default :
			speed = 10;
	}
	fadeInterval = setInterval(function() {
		if (mode == "out") {
			if (currentOpacity > finalOpacity) {
				newOpacity = currentOpacity - delay;
				g5setOpacity(obj,newOpacity); // set with g5setOpacity function
				currentOpacity = newOpacity;
				alert('Opacity = ' + newOpacity);
			} else {
				clearInterval(fadeInterval);
			}
		} else {
			if (currentOpacity < finalOpacity) {
				newOpacity = currentOpacity + delay;
				g5setOpacity(obj,newOpacity); // set with g5setOpacity function
				currentOpacity = newOpacity;
			} else {
				clearInterval(fadeInterval);
			}
		}
	}, speed);
}
/***********************************************************************************/
/****** zoomIn & zoomOut ************************************************************/
/***********************************************************************************/
/* Example:g5zoom(id,type,wh,minsize,maxsize,speed)
g5zoom('myDiv', 'in', 'width', 25, 300, 'slow')
*/
function g5zoomwh(id,wh,size) {
	switch(wh){
		case 'width':
			$id(id).style.width = size + 'px';
			break;
		case 'height':
			$id(id).style.height = size + 'px';
			break;
		default:
			return false;
	}
}
function g5zoom(id,type,wh,minsize,maxsize,speed) {
	switch(speed){
		case 'fast' :
			speed = 1;
			break;
		case 'slow' :
			speed = 10;
			break;
		default :
			speed = 5;
	}
	if (type=='out') {
		for (var i = 0 ; i <= (maxsize-minsize) ; i++) {
			setTimeout("g5zoomwh('" + id + "','" + wh + "'," + (maxsize-i) + ")", speed * i);
		}
	} else {
		for (var i = minsize ; i <= maxsize ; i++) {
			setTimeout("g5zoomwh('" + id + "','" + wh + "'," + i + ")", speed * i);
		}
	}
}
/***********************************************************************************/
/****** add element ****************************************************************/
/***********************************************************************************/
function g5addElement(inElementType, inElementID, inParentID) {
	newEl = document.createElement(inElementType);
	newEl.setAttribute('id', inElementID);
	$id(inParentID).appendChild(newEl);
	return(newEl);
}
/***********************************************************************************/
/****** remove element *************************************************************/
/***********************************************************************************/
function g5removeElement(inID) {
	oldEl = $id(inID);
	parentEl = oldEl.parentNode;
	return(parentEl.removeChild(oldEl));
}
/***********************************************************************************/
/****** set style css string *******************************************************/
/***********************************************************************************/
/* Example:(id, full css string)
g5setStyle('myDiv', 'color:#ff5900;font-weight:bold;')
*/
function g5setStyle(inID,cssString) {
	if (typeof($id(inID).style.cssText) == 'string' ) {
		$id(inID).style.cssText = cssString;
		$id(inID).setAttribute('style',cssString);
	}
}
/***********************************************************************************/
/****** set style Opacity **********************************************************/
/***********************************************************************************/
function g5setOpacity(inID, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	$id(inID).style.filter = 'alpha(opacity:' + opacity + ')';
	// Safari<1.2, Konqueror
	$id(inID).style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	$id(inID).style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	$id(inID).style.opacity = opacity/100;
}
/***********************************************************************************/
/****** load css & js to <head> ****************************************************/
/***********************************************************************************/
function g5loadJS(url){
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = url;
	document.body.appendChild(script);
}
function g5loadCSS(url){
	var retCSS = document.createElement('link');
	retCSS.setAttribute("rel","stylesheet");
	retCSS.setAttribute("type","text/css");
	retCSS.setAttribute("href",url);
	$name("head")[0].appendChild(retCSS);
}
/***********************************************************************************/
/****** show the presence of msn for topsection_right_msn div in topsection ********/
/***********************************************************************************/
function g5msnPresence(presence) {
	var str;
	switch (presence.statusText) {
		case 'Online' :
			str = '上線中';
			break;
		case 'Busy' :
			str = '忙碌中';
			break;
		case 'Away' :
			str = '暫時離開';
			break;
		case 'Offline' :
			str = '已離線';
			break;
		default :
			str = presence.statusText;
	}
	$id('topsection_right_msn').title = '點選查看 | 傳送線上即時訊息\n狀態：' + str + '\n(免安裝,可直接對談)';
	$id('topsection_right_msn').innerHTML = "<img src='2aImages/msn/msn" + presence.statusText + ".png' style='border: none;' width='114' height='20'" + 
	" alt='點選查看 | 傳送線上即時訊息\n狀態：" + str + "\n(免安裝,可直接對談)' />";
	if (presence.statusText=='Offline') {
		g5setStyle('topsection_right_msn','cursor:default');
	} else {
		g5setStyle('topsection_right_msn','cursor:pointer');
		$id('topsection_right_msn').onclick = function(){g5box('Live Messenger','msn','msn',400,400)};
	}
}
/***********************************************************************************/
/****** Ajax ***********************************************************************/
/***********************************************************************************/
function g5ajaxObjPreview(objID,innerID) {
	if (objID.length==0||innerID.length==0) {
		alert('Error on g5ajaxObjPreview function, objID or innerID is null');
		return false;
	}
	var xmlHttp = g5getXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		/*readyState 所有可能的值如下：
		0 (還沒開始)
		1 (讀取中)
		2 (已讀取)
		3 (資訊交換中)
		4 (一切完成)*/
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				$id(innerID).innerHTML = xmlHttp.responseText;
			} else {
				alert('There was a problem with the request on g5ajaxObjPreview function.');
			}
		}
	};
	var url = '2aAjax/objPreview.asp';
	url = url + '?id=' + objID;
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}
function g5ajaxUrl(url,innerID) {
	if (url.length==0||innerID.length==0) {
		alert('Error on g5ajaxUrl function, url or innerID is null');
		return false;
	}
	$id(innerID).innerHTML = "&nbsp;&nbsp;&nbsp;<img src='2aImages/img/boxLoading.gif'> 資料載入中 ...";
	var xmlHttp = g5getXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				$id(innerID).innerHTML = xmlHttp.responseText;
			} else {
				alert('There was a problem with the request on g5ajaxUrl function.');
			}
		}
	};
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}
function g5ajaxMessage(url,parameters,innerID) {
	if (url.length==0||parameters.length==0||innerID.length==0) {
		alert('Error on g5ajaxMessage function, url or parameters or innerID is null');
		return false;
	}
	$id(innerID).innerHTML = "<img src='2aImages/img/boxLoading.gif'> 留言發送中 ...";
	var xmlHttp = g5getXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				$id(innerID).innerHTML = "您的留言已成功送出";
			} else {
				alert('There was a problem with the request on g5ajaxMessage function.');
			}
		}
	};
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}
function g5getXmlHttpObject() {
	var xmlHttp = false;
	if (window.XMLHttpRequest) { // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		if (xmlHttp.overrideMimeType) {
			xmlHttp.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try { // IE6+
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try { // IE5.5+
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!xmlHttp) {
		alert('您的瀏覽器不支援 Ajax');
		return false;
	}
	return xmlHttp;
}
/***********************************************************************************/
/****** Cookie *********************************************************************/
/***********************************************************************************/
function g5getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function g5setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function g5deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
/***********************************************************************************/
/****** check browser **************************************************************/
/***********************************************************************************/
// 判斷某種流覽器 if(g5checkBrowser.ie)或if(g5checkBrowser.firefox)
// 判斷流覽器版本 if(g5checkBrowser.ie == '8.0')或if(g5checkBrowser.firefox == '3.0')
var g5checkBrowser = {};
var ua = navigator.userAgent.toLowerCase();
var s;
	(s = ua.match(/msie ([\d.]+)/)) ? g5checkBrowser.ie = s[1] :
	(s = ua.match(/firefox\/([\d.]+)/)) ? g5checkBrowser.firefox = s[1] :
	(s = ua.match(/chrome\/([\d.]+)/)) ? g5checkBrowser.chrome = s[1] :
	(s = ua.match(/opera.([\d.]+)/)) ? g5checkBrowser.opera = s[1] :
	(s = ua.match(/version\/([\d.]+).*safari/)) ? g5checkBrowser.safari = s[1] : 0;
/***********************************************************************************/
/****** 獲取 window.location.href 指定查詢字詞的值 ************************************/
/***********************************************************************************/
/* 1 */
function g5getQuyParam(name, url) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&amp;]" + name + "=([^&amp;#]*)";
	var regex = new RegExp(regexS);
	if (typeof (url) == 'undefined') url = window.location.href;
	var results = regex.exec(url);
	if (results == null){
		return "";
	}else{
		return results[1];
	}
}
/* 2 */
function g5getQryStr(qs) {
	s = location.href;
	s = s.replace("?","?&").split("&");
	re = "";
	for (i=1;i<s.length;i++) {
		if (s[i].indexOf(qs+"=")==0) {
			re = s[i].replace(qs+"=","");
		}
	}
	return re;
}
/***********************************************************************************/
/****** add to bookmarks ***********************************************************/
/***********************************************************************************/
function g5createBookmarkLink(){
	if (window.sidebar){
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(g5myWebName, g5myWebUrl,"");
	}else if( window.external){
		// IE Favorite
		window.external.AddFavorite(g5myWebUrl, g5myWebName);
	}else if(window.opera && window.print){
		// Opera Hotlist
		alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
		//return true;
	} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts
		alert('Unfortunately, this browser does not support the requested action, please bookmark this page manually.');
	}
}
/***********************************************************************************/
/****** copyright ******************************************************************/
/***********************************************************************************/
function g5copyrightDate() {
	var cpyrt = $id("footer_getcopyright");
	if (cpyrt) {
		cpyrt.firstChild.nodeValue = (new Date()).getFullYear();
	}
}
/***********************************************************************************/
/****** if error ,refresh the page *************************************************/
/***********************************************************************************/
function g5reloadPage(){
	window.location.reload(); 
}
/***********************************************************************************/
/****** when window onloaded *******************************************************/
/***********************************************************************************/
var gpTime = 6;
function g5pageLoaded() {
	var today = new Date();
	var downyear = today.getFullYear();
	var durringyear = downyear-1999;
	gpTime = gpTime -1;
	if ($id("leftBoxNew")) {
		$id("leftBoxNew").innerHTML = "<div>將於 " + gpTime + " 秒後載入資料</div>";
	}
	if ($id("leftBoxAuc")) {
		$id("leftBoxAuc").innerHTML = "<div>將於 " + gpTime + " 秒後載入資料</div>";
	}
	if ($id("rightBoxContent")) {
		$id("rightBoxContent").innerHTML = "<div class='rightBoxInner'>將於 " + gpTime + " 秒後載入資料</div>";
	}
	if (gpTime > 0) {
		setTimeout("g5pageLoaded();",1000);
	} else {
		$id("topsection_kwords").innerHTML = "<font color='white'>" + g5myWebName + " : " + durringyear + " 年法拍屋操作經驗, 在地深耕經營. 相信專業, 為自己創造一次正確的選擇!</font>";
		$id("footer_kwords").style.display = "none"; // Set foot seokwords5 to hidden
		if ($id("leftBoxNew")) {g5ajaxUrl($id('gfLeftBoxUrlNew').value,'leftBoxNew')};
		if ($id("leftBoxAuc")) {g5ajaxUrl($id('gfLeftBoxUrlAuc').value,'leftBoxAuc')};
		if ($id("rightBoxContent")) {g5ajaxUrl($id('gfRightBoxUrl').value,'rightBoxContent')};
	}
}
/***********************************************************************************/
/****** switch content *************************************************************/
/***********************************************************************************/
function g5switchContent(curobj, cid){
	var imgCollapsed = '../2aImages/img/listCollapsed_1.png';
	var imgExpanded = '../2aImages/img/listExpanded_1.png';
	$id(cid).style.display = ($id(cid).style.display!="block")? "block" : "";
	curobj.src = ($id(cid).style.display=="block")? imgExpanded : imgCollapsed;
}
/*******************************************************/
/****** toggle div *************************************/
/*******************************************************/
var $g ={
	style:function(node){
		return node.currentStyle || document.defaultView.getComputedStyle(node,null) || node.style;
	},
	height:function(node){
		return parseInt($g.style(node).height) || parseInt(node.clientHeight);
	},
	id:function(node){
		return document.getElementById(node);
	},
	name:function(node){
		return document.getElementsByName(node);
	},
	tag:function(node){
		return document.getElementsByTagName(node);
	}
}
function g5toggle(node,speed){
	this.node = node;
	switch(speed){
		case "fast":
			this.speed = 10;
			break;
		case "normal":
			this.speed = 5;
			break;
		case "slow":
			this.speed = 2;
			break;
		default:
			this.speed =5;
	}
	this.run = 1;
	this.max_height = $g.height(this.node);
	this.node.style.height = this.max_height;
	this.display = $g.style(this.node).display;
	this.node.style.overflow = "hidden";
	if(this.max_height <=0 || this.display == "none"){
		this.flag = 1;
	}else{
		this.flag = -1;
	}
}
g5toggle.prototype.up_down = function(){
	if(this.node.style.display == "none"){
		//alert('this is top \n this.node.style.height=' + this.node.style.height);
		this.node.style.display = "block";
		this.node.style.height ="0px";
		$g.id("topsection_middle_down").style.display ="none";
	}
	this.box_height = parseInt($g.style(this.node).height);
	this.box_height -= this.speed * this.flag;
	if(this.box_height > this.max_height){
		//alert('this is bottom \n box_height=' + this.box_height + 'px \n max_height=' + this.max_height + 'px');
		window.clearInterval(this.t);
		this.box_height = this.max_height;
		this.run =1;
		$g.id("topsection_middle_select").style.backgroundImage = "url(2aImages/topsection_middle_select_up.png)";
	}
	if(this.box_height <0){
		//alert('will be changed to top \n box_height=' + this.box_height + 'px \n this.t=' + this.t);
		window.clearInterval(this.t);
		this.box_height = 0;
		this.node.style.display ="none";
		this.run =1;
		$g.id("topsection_middle_select").style.backgroundImage = "url(2aImages/topsection_middle_select_down.png)";
		$g.id("topsection_middle_down").style.display ="block";
		//clearInterval(intervalID);
	}
	this.node.style.height = this.box_height + "px";
	//alert('this.node.style.height=' + this.node.style.height);
}

g5toggle.prototype.toggle = function(){
	var temp = this;
	if(this.run == 1){
		this.flag *= -1;
		this.run =0;
		this.t = window.setInterval(function(){temp.up_down();},10);
	}
}
