// JavaScript Document
window.onerror = new Function("return true");var obj = [];
var scr,spa,img,W,Wi,Hi,wi,hi,Sx,Sy,M,xm,ym,xb=0,yb=0,ob =  - 1,cl = false;px = function(x){return Math.round(x) + "px";}
/* center image  - do not resize for perf. reason */
img_center = function(o){with(img[o]){style.left = px( - (width - Wi) / 2);style.top = px( - (height - Hi) / 2);}}
//////////////////////////////////////////////////////////
var Nx = 4; //size grid x
var Ny = 3; //size grid y
var Tx = 3; // image width
var Ty = 3; // image height
var Mg = 60; // margin
var SP = 1; // speed
//////////////////////////////////////////////////////////
function Cobj(o, x, y){
	this.o = o;this.ix = Math.min(Nx - Tx, Math.max(0, Math.round(x - (Tx / 2))));this.iy = Math.min(Ny - Ty, Math.max(0, Math.round(y - (Ty / 2))));
	this.li = ((this.ix * M + this.ix * Sx) - (x * M + x * Sx)) / SP;this.ti = ((this.iy * M + this.iy * Sy) - (y * M + y * Sy)) / SP;
	this.l = 0;this.t = 0;this.w = 0;this.h = 0;this.s = 0;this.mv = false;this.spa = spa[o].style;this.img = img[o];this.txt = img[o].alt;img[o].alt = "";
	/* zooming loop */
	this.zoom = function(){
		with(this){l += li * s;t += ti * s;w += wi * s;h += hi * s;
			if ((s > 0 && w < Wi) || (s < 0 && w > Sx)){window.focus();setTimeout("obj[" + o + "].zoom()", 16);
			}else{mv = false;if (s > 0){l = ix * M + ix * Sx;t = iy * M + iy * Sy;w = Wi;h = Hi;}else{l = x * M + x * Sx;t = y * M + y * Sy;w = Sx;h = Sy;}}
			/* html animation */
			with(spa){left = px(l);top = px(t);width = px(w);height = px(h);zIndex = Math.round(w);}
		}
	}
	this.click = function(){
		with(this){img_center(o);
			if ( ! mv || cl){if (s > 0){if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4){s =  - 2;mv = true;zoom();cap.innerHTML = txt;}
				}else{if (cl || ob != o){if (ob >= 0){with(obj[ob]){s =  - 2;mv = true;zoom();}}ob = o;s = 1;xb = xm;yb = ym;mv = true;zoom();cap.innerHTML = txt;}}}
		}
	}
	img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
	img[o].onclick = new Function("cl=true;obj[" + o + "].click()");img[o].onload = new Function("img_center(" + o + ")");
	this.zoom();
}
document.onmousemove = function(e){if ( ! e){e = window.event;}xm = (e.x || e.clientX);ym = (e.y || e.clientY);}
function load(atx)
{
	if(atx==4){Tx=4;}else{Tx=3;}
	scr = document.getElementById("screen");spa = scr.getElementsByTagName("span");img = scr.getElementsByTagName("img");cap = document.getElementById("caption");
	document.getElementById("border").onmouseover = function(){cl = true;if(ob >= 0 && obj[ob].s > 0) obj[ob].click();ob = -1;}
	W = parseInt(scr.style.width);H = parseInt(scr.style.height);M = W / Mg;Sx = (W - (Nx - 1) * M) / Nx;Sy = (H - (Ny - 1) * M) / Ny;
	Wi = Tx * Sx + (Tx - 1) * M;Hi = Ty * Sy + (Ty - 1) * M;SP = M * Tx * SP;wi = (Wi - Sx) / SP;hi = (Hi - Sy) / SP;
	for (k = 0, i = 0; i < Nx; i ++){for (j = 0; j < Ny; j ++){obj[k] = new Cobj(k ++, i, j);}}
}
function Calrate(){
	var cash=document.house.cash.value;var yrate=document.house.yrate.value;var year=document.house.year.value;var rate=yrate/12;document.house.cash.value=cash;
    document.house.yrate.value = yrate;document.house.year.value  = year;var t_time = year * 12;var rate_100 = rate / 100;var t_ok = 1 ;
    for (i = 0; i < t_time; i++){t_ok *= (1 + rate_100);}var t_rate = ( rate_100 * t_ok ) / ( t_ok - 1 );var rtn_mon = cash * t_rate;
    document.house.rtn_Mon.value = Math.round(rtn_mon+0.49);
}
function Clear(){document.house.cash.value = "";document.house.yrate.value = "";document.house.year.value = "";document.house.rtn_Mon.value = "";}
function member_onclick()	{document.member.flg.value = 'login';document.member.submit();}
function omoPicture(a){document.getElementById("bigHousePhoto").src=a;}
function action_onclick(){
	var	cemail,cyy,cmm,cdd;
	if (!(checkempty(document.qa.name.value))){document.qa.name.focus();alert ('請輸入姓名!');return false;}
	if (checkempty(document.qa.email.value)){cemail=document.qa.email.value;
		if (cemail.indexOf('@')==-1|| cemail.indexOf('.')==-1){alert('EMail格式有誤請確認');document.qa.email.focus();return false;}
	}else{alert('請輸入EMail');document.qa.email.focus();return false;}
	if (!(checkempty(document.qa.comment.value))){alert ('請輸入問題與建議!');document.qa.comment.focus();return false;
	}else{var ccomment = document.qa.comment.value;nLen=ccomment.length;N=0;for (i=0; i < nLen ; i++){if(ccomment.charAt(i) > unescape('%80'))N = N+2;else N = N+1;}
		if	( N > 1000){alert("對不起!您的意見已經超過500個字,共超過 "+(N-1000)+" bytes,請簡短一些,謝謝您");document.qa.comment.focus();	return false;}
	}if (!(checkempty(document.qa.validcode.value))){document.qa.validcode.focus();alert ('請輸入驗證碼!');return false;}return true;
}
function checkempty(txtval){if (txtval.length==0) return false;var i=0;while (i < txtval.length) {if (txtval.substring(i,i+1) != ' ') return true;i=i+1;}return false;}
function errimg(im,ch){if(ch=='M'){im.src='/images/wvj.gif'}else{im.src='/images/web/notyet.jpg'}}
	
