﻿function $(id) {
	return document.getElementById(id);
}
function show(obj)
{
	$(obj).style.display = '';
}
function hide(obj)
{
	$(obj).style.display = 'none';
}
function logbtn(){
	if (getCookie('Account') != null){
		document.getElementById("btnAnonymous").style.display='none';
		document.getElementById("btnLoged").style.display='block';
		document.getElementById("btnJoin").style.display='none';
		document.getElementById("btnMyAcc").style.display='block';
		}
}
function logblk(){
	if (getCookie('Account') != null){
		if (document.getElementById("blkLoged")!=null){document.getElementById("blkLoged").style.display='block';}
		if (document.getElementById("blkAnonymous")!=null){document.getElementById("blkAnonymous").style.display='none';}
		if (document.getElementById("blkLogedLevel")!=null){
		document.getElementById("blkLogedLevel").innerHTML="<img src=http://yimg.twhouses.com.tw/yicon/user" + getCookie("UserLevel") + ".gif align=absbottom>";
		}
		if (document.getElementById("blkLogedUserAcc")!=null){document.getElementById("blkLogedUserAcc").innerText=getCookie('UserAcc');}
		if (document.getElementById("blkLogedJYG")!=null){document.getElementById("blkLogedJYG").innerText=getCookie('JYG');}
		var strImg;
		var str;
		if (getCookie('CustType') != null){
			str = getCookie('CustType');
		}
		else{
			str = getCookie('CustomerType');
		}
		switch(str)
		{
		case "agent":
			strImg = "agent";
			break;
		case "agent35":
			strImg = "agent35";
			break;
		case "agent90":
			strImg = "agent90";
			break;
		case "memberfees":
			strImg = "vip";
			break;
		default:
			strImg = "normal";
		}
		if (document.getElementById("blkLogedCustomerType")!=null){document.getElementById("blkLogedCustomerType").innerHTML="<img src=http://yimg.twhouses.com.tw/yicon/" + strImg + ".gif align=absbottom alt=CustomerType>";}
	}
}
function showtip(current,even,text){
 if (document.all){
   thetitle=text.split('<br>');
  if (thetitle.length>1){
     thetitles='';
     for (w=0;w<thetitle.length;w++)
        thetitles+=thetitle[w];
        current.title=thetitles;
     }
    else
     current.title=text;
    }

  else if (document.layers){

  }
}
function hidetip(){
  	if (document.layers){

	}
}
function historygoback(){
if (window.history.length>0)
	window.history.goback();
else
  	alert("NoPage");
}
function urlgo(s){
	window.location.href='/asp/MainFunctionRefer.asp?act=' + s
}
function init_srolltext_bj(i){
	var obj = document.getElementById("icefable_bj" + i)
	obj.scrollTop = 0;
	setInterval("scrollUp_bj(" + i + ")", 80);
}
function scrollUp_bj(i){
	var obj = document.getElementById("icefable_bj" + i);
	currentTop += 1;
	if(currentTop == 21){
	  	stoptime += 2;
		currentTop -= 1;
		if(stoptime == 110){
	  		currentTop = 0;
	  		stoptime = 0;
		}
	}
	else{   
	    preTop = obj.scrollTop;
		obj.scrollTop += 1;
		if(preTop == obj.scrollTop){
	    	obj.scrollTop = 0;
			currentTop = 20; 
		}
	}
}
function getCookie(name){
	var strCookies = document.cookie;
	var cookieName = name + "="; //Cookie名稱
	var valueBegin, valueEnd, value;
	// 尋找是否有此Cookie名稱
	valueBegin = strCookies.indexOf(cookieName);
	if (valueBegin == -1) return null; //沒有此Cookie
	//取得值的結尾位置
	valueEnd = strCookies.indexOf(";", valueBegin);
	if (valueEnd == -1)
		valueEnd = strCookies.length; //最後一個Cookie
	//取得Cookie值
	value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
	return value;
}
function checkCookieExist(name){
	if (getCookie(name()))
		return true;
	else
		return false;
	}
function validLength(str, minlen, maxlen)
{
    if (str.length < minlen){
        return false;
    }
    if (str.length > maxlen){
        return false;
    }
    return true;
}
function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}
function chkEmail(str)
{
	 var emailRE = /(@\w[-._\w]*\w\.\w{2,3})$/;
   return emailRE.test(str);
}
function isNull(value, contain)
{
	if (("" == value) || (null == value))	{
		return true;
	}	else {
		return false;
	}
}
function getSelOpt(obj)
{
	return obj.options[obj.selectedIndex];
}
function getSelVal(obj)
{
	return obj.options[obj.selectedIndex].value;
}
function getSelText(obj)
{
	return obj.options[obj.selectedIndex].text;
}
function setCurrentVal(obj, val, max)
{
	var len = obj.options.length;
	var index = -1;
	for (var i=0; i<len ; i++) {
		obj.options[i].selected = '';
		if (obj.options[i].value == val) {
			index = i;
		}
	}
	if (index != -1) {
		obj.options[index].selected = "selected";
	} else if (max) {
		obj.options[len].selected = "selected";
	}
}
function setChecked(objname, val)
{
	if ('' == val) return ;
	objs =	document.getElementsByName(objname);
	var len = objs.length;
	var index = -1;
	for (var i=0; i<len; i++) {
		objs[i].checked = '';
		if (objs[i].value == val) 	{
			index = i;
		}
	}
	if (index != -1) {
		objs[index].checked = "checked";
	}
}
function setMulti(objname, val)
{
	if ("" == val) {
		return false;
	}
	var objs =	document.getElementsByName(objname);
	var valArr = val.split(",");	// array
	var len = objs.length;
	for (var i=0; i<len; i++) {
		if (valArr.indexOf(objs[i].value) != -1) {
			objs[i].checked = "checked";
		}
	}
}
function getFileExt(filename)
{
  return filename.replace(/^.*(\.[^\.\?]*)\??.*$/, '$1');
}
function isImage(filename)
{
	var ext;
	ext = getFileExt(filename).toLowerCase();
	switch (ext)
  {
		case '.jpeg':
		case '.jpg':
		case '.gif':
		case '.png': return true;
		default:
			   return false;
	}
	return false;
}
function isNumber(val) 
{
	  var reg = /[\d]+/;
    return reg.test(val);
}
function numbercheckertype2(num,orinum,objText,isallowdot)
{
	//允許開頭是0,小數點可選加,不加千位符
	//適合驗證電話,區域碼,浮點數
  var isErr = 0;
  for (i=0; i<num.length; i++)
  {
    c=num.charAt(i);
	if (isallowdot == "true")
	{if ("0123456789.".indexOf(c,0) < 0) isErr = 1;}
	else
	{if ("0123456789".indexOf(c,0) < 0) isErr = 1;}
  }
  if (isErr == 1)
  {
	 alert("您的" + objText + ":" + num + "有誤\n" + objText + "僅限數字，不可使用中英文字、全形數字、空格或符號!!");
	 return orinum;
  }
  else	
  {
	 return num;
  }
}
function numberchecker(num,str,orinum,nm,stype){	
	//不允許開頭是0,不接受小數點,千位符可選加
	//適合驗證價格類的數字
    num=new String(num);
    num=num.replace(/,/gi,"");
	num = numberConv(num);
    return numbercheckerresult(num,str,orinum,nm,stype);
}
function numbercheckerresult(num,str,orinum,nm,stype){
    var sign="";
    if(isNaN(num)) {
		alert(str+"只可以輸入數字.");
		return orinum;
	}
	else
		$(nm).innerHTML=num;
	if(num==0) {
		return num;
	}
    if(num<0){
        num=num*(-1);
        sign="-";
    }
    else{
        num=num*1;
    }
	var temp="";
	if (stype=="format1")
	{
		num = new String(num)
		var pos=3;
		num_len=num.length;
		while (num_len>0){
			num_len=num_len-pos;
			if(num_len<0) {
				pos=num_len+pos;
				num_len=0;
			}
			temp=","+num.substr(num_len,pos)+temp;
		}
    	return sign+temp.substr(1);
	}
	else
    	return num;
}
function numberConv(val)
{
	if ('' == val)
	{
		return '';
	}
	return val.replace("０","0").replace("１","1").replace("２","2").replace("３","3").replace("４","4").replace("５","5").replace("６","6").replace("７","7").replace("８","8").replace("９","9").replace("．",".").replace("。",".");
}
function Keypress(el,event,type)
{
	var code = window.event ? event.keyCode : event.which;	
	if ((code == 8) || (code == 0)) return true;
	if ((code<48 || code>57))
	{	
		 if (event.preventDefault) return event.preventDefault();
		 else	 event.returnValue = false;
	}
}
function ctlent(event, frmobj) {
	 if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
		 if (frmobj.onsubmit())
		 {
			 frmobj.submit();
		 }
	 }
}
Array.prototype.indexOf = function(substr,start){
	var ta,rt,d='\0';
	if(start!=null){ta=this.slice(start);rt=start;}else{ta=this;rt=0;}
	var str=d+ta.join(d)+d,t=str.indexOf(d+substr+d);
	if(t==-1)return -1;rt+=str.slice(0,t).replace(/[^\0]/g,'').length;
	return rt;
}
//function hide(obj)
//{
//	$(obj).style.display = 'none';
//}
//function show(obj)
//{
//	$(obj).style.display = '';
//}
function DrawImage(ImgD, FitWidth, FitHeight){ 
		var image=new Image(); 
		image.src=ImgD.src; 
		if(image.width>0 && image.height>0){ 
				if(image.width/image.height>= FitWidth/FitHeight){ 
						if(image.width>FitWidth){ 
								ImgD.width=FitWidth; 
								ImgD.height=(image.height*FitWidth)/image.width; 
						}else{ 
								ImgD.width=image.width; 
								ImgD.height=image.height; 
						} 
				} else{ 
						if(image.height>FitHeight){ 
								ImgD.height=FitHeight; 
								ImgD.width=(image.width*FitHeight)/image.height; 
						}else{ 
								ImgD.width=image.width; 
								ImgD.height=image.height; 
						} 
				} 
		} 
}
function AddFavorite(url, title){
	if (window.sidebar) window.sidebar.addPanel(title, url, "");
	else if (window.opera && window.print){
		var mbm = document.createElement('a');
		mbm.setAttribute('rel', 'sidebar');
		mbm.setAttribute('href', url);
		mbm.setAttribute('title', title);
		mbm.click();
	}	else if (document.all) window.external.AddFavorite(url, title);
}
function slideLine(ul, delay, speed, lh) {
			var slideBox = (typeof ul == 'string')?document.getElementById(ul):ul;
			var delay = delay||1000, speed=speed||20, lh = lh||20;
			var tid = null, pause = false;
			var start = function() {
				tid=setInterval(slide, speed);
			}
			var slide = function() {
				if (pause) return;
				slideBox.scrollTop += 2;
				if (slideBox.scrollTop % lh == 0) {
					clearInterval(tid);
					slideBox.appendChild(slideBox.getElementsByTagName('li')[0]);
					slideBox.scrollTop = 0;
					setTimeout(start, delay);
				}
			}
			slideBox.onmouseover=function(){pause=true;}
			slideBox.onmouseout=function(){pause=false;}
			setTimeout(start, delay);
}

function saveCookie(name, value, expires, path, domain, secure) { 
var strCookie = name + "=" + value 
if (expires){ 
// 計算Cookie的期限, 參數為天數 
var curTime = new Date() 
curTime.setTime(curTime.getTime() + expires*24*60*60*1000) 
strCookie += "; expires=" + curTime.toGMTString() 
} 
// Cookie的路徑 
strCookie += (path) ? "; path=" + path : "" 
// Cookie的Domain 
strCookie += (domain) ? "; domain=" + domain : "" 
// 是否需要保密傳送,為一個布林值 
strCookie += (secure) ? "; secure" : "" 
document.cookie = strCookie 
} 
// 使用名稱參數取得Cookie值, null表示Cookie不存在 
function getCookie(name){ 
var strCookies = document.cookie 
var cookieName = name + "=" // Cookie名稱 
var valueBegin, valueEnd, value 
// 尋找是否有此Cookie名稱 
valueBegin = strCookies.indexOf(cookieName) 
if (valueBegin == -1) return null // 沒有此Cookie 
// 取得值的結尾位置 
valueEnd = strCookies.indexOf(";", valueBegin) 
if (valueEnd == -1) 
valueEnd = strCookies.length // 最後一個Cookie 
// 取得Cookie值 
value = strCookies.substring(valueBegin+cookieName.length,valueEnd) 
return value 
} 
