// JavaScript Document

if (window.top.location != location) window.top.location.href = window.location.href;

function $id(id){return document.getElementById(id)}

function showcity() {
	var show = document.getElementById("showcity").style.display;
	if( show == "none" ) {
		document.getElementById("showcity").style.display = "";
	} else if( show == "" ) {
		document.getElementById("showcity").style.display = "none";
	}
}

function check_login_left(){
	if($id('username_left').value==''){
		alert('请输入用户名')
		$id('username_left').focus()
		return false
	}
	if($id('userpwd_left').value==''){
		alert('请输入密码')
		$id('userpwd_left').focus()
		return false
	}
	return true
}

window.onerror=function(){return true;}

var default_search_type='company';
function showclose_change_searchtype(w){
	$id("search_type_ol").style.display=w;	
}
var search_type_text=new Array();
search_type_text["company"]="装饰公司";
search_type_text["designer"]="设计师";
search_type_text["cases"]="装修案例";
search_type_text["zhishi"]="装修知识";
search_type_text["wenwen"]="装饰问问";
search_type_text["help"]="帮助中心";
function change_searchtype(w){
	default_search_type=w
	$id("search_type_text").innerHTML=search_type_text[w]
	$id("search_wd").value='请输入 '+search_type_text[w]+' 关键词';
	$id("search_type_ol").style.display='none';
}
function click_wd(w){
	if(w=="请输入 "+search_type_text[default_search_type]+" 关键词") $id("search_wd").value='';
}
function blur_wd(w){
	if(w=="") $id("search_wd").value='请输入 '+search_type_text[default_search_type]+' 关键词';
}

function go_wd(){
	if($id("search_wd").value=="请输入 "+search_type_text[default_search_type]+" 关键词") {
		$id("search_wd").value='';
		$id("search_wd").focus();	
	}
	else {
		switch(default_search_type){
			case "company":window.location.href='/company/?kw='+encodeURI($id("search_wd").value);break;
			case "designer":window.location.href='/designer/?kw='+encodeURI($id("search_wd").value);break;
			case "cases":window.location.href='/cases/?kw='+encodeURI($id("search_wd").value);break;
			case "zhishi":window.location.href='/zhishi/list.php?kw='+encodeURI($id("search_wd").value);break;
			case "wenwen":window.location.href='/wenwen/list.php?kw='+encodeURI($id("search_wd").value);break;
			case "help":window.location.href='/help/kw_'+encodeURI($id("search_wd").value)+"/1.html";break;
			default:alert('非法搜索');break;
		}	
	}
}

var WeekArray=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var timer_changeTimer,BjTime;;

function DoSmallThanTen(dovalue){
	if(dovalue<10) return "0"+dovalue;
	else return dovalue;
}

function GetToday(){
	$id("CnTime").innerHTML="现在时间："+BjTime[3]+"年"+DoSmallThanTen(BjTime[2])+"月"+DoSmallThanTen(BjTime[1])+"日 "+DoSmallThanTen(BjTime[4])+":"+DoSmallThanTen(BjTime[5])+":"+DoSmallThanTen(BjTime[6])+"&nbsp;&nbsp;"+DoSmallThanTen(WeekArray[BjTime[0]]);
	
	BjTime[6]=Math.abs(BjTime[6])+1;
	if(BjTime[6]>59) {
		BjTime[6]=0;
		BjTime[5]=Math.abs(BjTime[5])+1;
		if(BjTime[5]>59) {
			BjTime[5]=0;
			BjTime[4]=Math.abs(BjTime[4])+1;	
			if(BjTime[4]>23) {
				BjTime[4]=0;
				BjTime[0]=Math.abs(BjTime[0])+1;
				BjTime[1]=Math.abs(BjTime[1])+1;
				if(BjTime[0]>5) BjTime[0]=0;
				
				if(BjTime[2]==1 || BjTime[2]==3 || BjTime[2]==5 || BjTime[2]==7 || BjTime[2]==8 || BjTime[2]==10 || BjTime[2]==12) var MonthBigOrSmall=31;
				else if(BjTime[2]==4 || BjTime[2]==6 || BjTime[2]==9 || BjTime[2]==11) var MonthBigOrSmall=30;
				else {
					if(BjTime[3]%4==0) var MonthBigOrSmall=29;
					else if(BjTime[3]%4==0) var MonthBigOrSmall=28;
				}
				
				if(BjTime[1]>MonthBigOrSmall) {
					BjTime[1]=1;	
					BjTime[2]=Math.abs(BjTime[2])+1;	
					if(BjTime[2]>11) {
						BjTime[2]=1;
						BjTime[3]=Math.abs(BjTime[3])+1;	
					}
				}		
			}
		}	
	}
	
	timer_changeTimer=setTimeout("GetToday()",1000)
}

function footer_link_change(w){
	$id("link_nav_"+w).className='onli';
	$id("link_"+w).style.display='block';
	if(w=="parter") {
		$id("link_shangwu").style.display='none';	
		$id("link_nav_shangwu").className='';
	}
	else if(w=="shangwu") {
		$id("link_parter").style.display='none';
		$id("link_nav_parter").className='';	
	}
}

function resizeimg(ImgD,imgwidth,imgheight,needcheck){
	
		var flag=false;  
		var image=new Image(); 
		image.src=ImgD.src; 
		if(image.width>0 && image.height>0){ 
			flag=true; 
			if(image.width/image.height>= imgwidth/imgheight){ 
				if(image.width>imgwidth){
					ImgD.width=imgwidth; 
					ImgD.height=(image.height*imgwidth)/image.width; 
				}else{ 
					ImgD.width=image.width;
					ImgD.height=image.height; 
				} 
			} 
			else{ 
				if(image.height>imgheight){
					ImgD.height=imgheight; 
					ImgD.width=(image.width*imgheight)/image.height; 
				}else{ 
					ImgD.width=image.width;
					ImgD.height=image.height; 
				} 
			} 
		}
	
}

function over(id) {
	document.getElementById("user"+id).className = 'nav_on';
}
function out(id) {
	document.getElementById("user"+id).className = '';
}

function check_city(n){
for(i=1;i<=6;i++){
$id("city_div_"+i).style.display="none"
} 
$id("city_div_"+n).style.display="block" 
}



var Message={
set: function() {//最小化与恢复状态切换
var set=this.minbtn.status == 1?[0,1,'block',this.char[0],'最小化']:[1,0,'none',this.char[1],'恢复'];
this.minbtn.status=set[0];
this.win.style.borderBottomWidth=set[1];
this.content.style.display =set[2];
this.minbtn.innerHTML =set[3]
this.minbtn.title = set[4];
this.win.style.top = this.getY().top;
},
close: function() {//关闭
this.win.style.display = 'none';
window.onscroll = null;
},
setOpacity: function(x) {//设置透明度
var v = x >= 100 ? '': 'Alpha(opacity=' + x + ')';
this.win.style.visibility = x<=0?'hidden':'visible';//IE有绝对或相对定位内容不随父透明度变化的bug
this.win.style.filter = v;
this.win.style.opacity = x / 100;
},
show: function() {//渐显
clearInterval(this.timer2);
var me = this,fx = this.fx(0, 100, 0.1),t = 0;
this.timer2 = setInterval(function() {
t = fx();
me.setOpacity(t[0]);
if (t[1] == 0) {clearInterval(me.timer2) }
},6);//10 to 6
},
fx: function(a, b, c) {//缓冲计算
var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1;
return function() {return [a += cMath((b - a) * c), a - b]}
},
getY: function() {//计算移动坐标
var d = document,b = document.body, e = document.documentElement;
var s = Math.max(b.scrollTop, e.scrollTop);
var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
var h2 = this.win.offsetHeight;
return {foot: s + h + h2 + 2+'px',top: s + h - h2 - 2+'px'}
},
moveTo: function(y) {//移动动画
clearInterval(this.timer);
var me = this,a = parseInt(this.win.style.top)||0;
var fx = this.fx(a, parseInt(y));
var t = 0 ;
this.timer = setInterval(function() {
t = fx();
me.win.style.top = t[0]+'px';
if (t[1] == 0) {
clearInterval(me.timer);
me.bind();
}
},6);//10 to 6
},
bind:function (){//绑定窗口滚动条与大小变化事件
var me=this,st,rt;
window.onscroll = function() {
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st = setTimeout(function() {
me.win.style.top = me.getY().top;
me.show();
},100);//600 mod 100
};
window.onresize = function (){
clearTimeout(rt);
rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
}
},
init: function() {//创建HTML
function $(id) {return document.getElementById(id)};
this.win=$('msg_win');
var set={minbtn: 'msg_min',closebtn: 'msg_close',title: 'msg_title',content: 'msg_content'};
for (var Id in set) {this[Id] = $(set[Id])};
var me = this;
this.minbtn.onclick = function() {me.set();this.blur()};
this.closebtn.onclick = function() {me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];//FF不支持webdings字体
this.minbtn.innerHTML=this.char[0];
this.closebtn.innerHTML=this.char[2];
setTimeout(function() {//初始化最先位置
me.win.style.display = 'block';
me.win.style.top = me.getY().foot;
me.moveTo(me.getY().top);
},0);
return this;
}
};
