// JavaScript Document
// copyright(C)2009 ZSTYLE. All rights reserved.
var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
var $=function(){return document.getElementById(arguments[0]);}
var _http=function(){return window.ActiveXObject ? new ActiveXObject("Msxml2.XMLHTTP") :  new XMLHttpRequest();}
function send_request(rt){
	var http = _http();
	var url = "sendrequest.php";
	url += "?rt=" + rt;
	if(rt==0){
		var rs = document.getElementById("requestspan");
		rs.innerHTML = 'Sending request....<img src="/common/images/loading.gif" align="absmiddle" />';
		//$("requestspan").innerHTML = 'Sending request....<img src="/common/images/loading.gif" align="absmiddle" />';
	}		
	else{
		var rs = document.getElementById("requestspan2");
		rs.innerHTML = 'Sending request....<img src="/common/images/loading.gif" align="absmiddle" />';
	}
	http.open("GET", url,false);
	http.send(null);
	http.onreadystatechange=function(){
		if(http.readyState == 4){
			$("requestspan").innerHTML = http.responseText;
		}
	}
}
function setUserFlag(o, id, flg){
	var http = _http();
	var url = "setuserflag.php";
	url += "?id=" + id + "&f=" + flg;
	http.open("GET", url, false);
	http.send(null);
	if(http.responseText != "1"){
		alert(http.responseText);
	}else{
		switch(flg){
			case undefined || null:
				break;
			case 0:
				o.className = 'btKeepTop_InAct';
				break;
			case 1:
				o.className = 'btKeepTop_Act';
		}
	}
}
function setStatus(o, i, tbl, id, flg, op){
	var http = _http();
	var url = "setstatus.php";
	url += "?tbl=" + tbl + "&id=" + id + "&i=" + i + "&f=" + flg + "&op=" + op;
	http.open("GET", url, false);
	http.send(null);
	if(http.responseText != "1"){
		alert(http.responseText);
	}else{
		switch(i){
			case 0:
				o.className = 'btPub_InAct';
				break;
			case 1:
				o.className = 'btPub_Act';
				break;
			case -1:
				break;
		}
		switch(flg){
			case undefined || null:
				break;
			case 0:
				o.className = 'btKeepTop_InAct';
				break;
			case 1:
				o.className = 'btKeepTop_Act';
		}
	}
}
function attch_eve(o, ars){
	var id = o.id;
	var clds = o.getElementsByTagName("li");
	for(var i=0; i < clds.length; i++){
		clds[i].onmouseover=totabclick;
		clds[i].setAttribute("for-show", ars[i]);
	}
}
function totabclick(e){
	var e = e || event;
	var o = e.srcElement || e.target;
	/*if(o.tagName == "li"){o = o.parentNode;}*/
	var ulo = o.parentNode;
	var clds = ulo.getElementsByTagName("li");
	for(var i=0; i < clds.length; i++){
		var diso = clds[i].getAttribute("for-show");
		T$(diso).style.display = "none";
		clds[i].className="";
	}
	var str = o.getAttribute("for-show");
	T$(str).style.display = "block";
	o.className="act";
}
function goto(url){
	window.location.href= url;
}
function show_layer(d,o){
	var x = getLeft(d);
	var y = getTop(d);
	o.style.left = x + 'px';
	o.style.top  = y + 18 + 'px';
	o.style.visibility = 'visible';
}
function getTop(e)
{ 
	var offset=e.offsetTop; 
	while(e = e.offsetParent)offset+=e.offsetTop; 
	return (isIE||isOpera ? offset : offset + 'px'); 
}
function getLeft(e)
{ 
	var offset=e.offsetLeft; 
	while(e = e.offsetParent)offset+=e.offsetLeft;
	return (isIE||isOpera ? offset : offset + 'px'); 
}
function share(t){
	var arcurl = escape(window.location.href);
	var url = "";
	var atitle =  window.document.title;
	switch(t){
		case "facebook":
			url = "http://www.facebook.com/share.php?u=" + arcurl;
			break;
		case "twitter":
			url = "http://twitter.com/home?status=" + escape(atitle + ":") + arcurl;
			break;
		case "kaixin":
			url = "http://www.kaixin001.com/repaste/share.php?rtitle=" + escape(atitle) + "&rurl=" + arcurl + "&rcontent=" + arcurl;
			break;
		case "email":
			s = "Your friend recommend a article <" + atitle + "> from " + window.location.href;
			b = "it's so intesting.";
			url = "mailto:?subject=" + escape(s) + "&body=" + b;
			break;
	}
	//window.location.href = url;
	window.open(url);
	return false;
}
/*
<script type="text/javascript">
	T$('click_test1').onclick = function(){TINY.box.show('word-mix-widh-auto-btn.html',1,300,150,1)}
	var content2 = "<img width='600' height='480' src='http://aaa.com/1.jpg' border='0' />";
	T$('click_test2').onclick = function(){TINY.box.show(content2,0,0,0,1)}
	var content3 = "this will hidden after 3 seconds";
	T$('click_test3').onclick = function(){TINY.box.show(content3,0,0,0,0,3)}
</script>
*/
var TINY={};
function T$(i){return document.getElementById(i);}
TINY.box=function(){
	var p,m,b,fn,ic,iu,iw,ih,ia,f=0;
	var execstr = '';
	return{
		show:function(c,u,w,h,a,t){
			if(!f){
				p=document.createElement('div'); p.id='tinybox';
				m=document.createElement('div'); m.id='tinymask';
				b=document.createElement('div'); b.id='tinycontent';
				document.body.appendChild(m); document.body.appendChild(p); p.appendChild(b);
				/*m.onclick=TINY.box.hide;*/ window.onresize=TINY.box.resize; f=1
			}
			if(!a&&!u){
				p.style.width=w?w+'px':'auto'; p.style.height=h?h+'px':'auto';
				p.style.backgroundImage='none'; b.innerHTML=c
			}else{
				b.style.display='none'; p.style.width=p.style.height='100px'
			}
			this.mask();
			ic=c; iu=u; iw=w; ih=h; ia=a; this.alpha(m,1,80,3);
			if(t){setTimeout(function(){TINY.box.hide()},1000*t)}
		},
		fill:function(c,u,w,h,a){
			if(u){
				p.style.backgroundImage='';
				var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
				x.onreadystatechange=function(){
					if(x.readyState==4&&x.status==200){TINY.box.psh(x.responseText,w,h,a)}
				};
				x.open('GET',c,1); x.send(null)
			}else{
				this.psh(c,w,h,a)
			}
		},
		psh:function(c,w,h,a){
			if(a){
				if(!w||!h){
					var x=p.style.width, y=p.style.height; b.innerHTML=c;
					p.style.width=w?w+'px':''; p.style.height=h?h+'px':'';
					b.style.display='';
					w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight);
					b.style.display='none'; p.style.width=x; p.style.height=y;
				}else{
					b.innerHTML=c
				}
				this.size(p,w,h,4)
			}else{
				p.style.backgroundImage='none'
			}
		},
		hide:function(){
			TINY.box.alpha(p,-1,0,5)
		},
		resize:function(){
			TINY.box.pos(); TINY.box.mask()
		},
		mask:function(){
			m.style.height=TINY.page.theight()+'px';
			m.style.width=''; m.style.width=TINY.page.twidth()+'px'
		},
		pos:function(){
			var t=(TINY.page.height()/2)-(p.offsetHeight/2); t=t<10?10:t;
			p.style.top=(t+TINY.page.top())+'px';
			p.style.left=(TINY.page.width()/2)-(p.offsetWidth/2)+'px'
		},
		setexec:function(s){
			execstr = s;
		},
		alpha:function(e,d,a,s){
			clearInterval(e.ai);
			if(d==1){
				e.style.opacity=0; e.style.filter='alpha(opacity=0)';
				e.style.display='block'; this.pos()
			}
			e.ai=setInterval(function(){TINY.box.twalpha(e,a,d,s)},20)
		},
		twalpha:function(e,a,d,s){
			var o=Math.round(e.style.opacity*100);
			if(o==a){
				clearInterval(e.ai);
				if(d==-1){
					e.style.display='none';
					e==p?TINY.box.alpha(m,-1,0,3):b.innerHTML=p.style.backgroundImage='';
					if(execstr != ""){
						eval(execstr);
					}
				}else{
					e==m?this.alpha(p,1,100,5):TINY.box.fill(ic,iu,iw,ih,ia)
				}
			}else{
				var n=o+Math.ceil(Math.abs(a-o)/s)*d;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		size:function(e,w,h,s){
			e=typeof e=='object'?e:T$(e); clearInterval(e.si);
			var ow=e.offsetWidth, oh=e.offsetHeight,
			wo=ow-parseInt(e.style.width), ho=oh-parseInt(e.style.height);
			var wd=ow-wo>w?-1:1, hd=(oh-ho>h)?-1:1;
			e.si=setInterval(function(){TINY.box.twsize(e,w,wo,wd,h,ho,hd,s)},20)
		},
		twsize:function(e,w,wo,wd,h,ho,hd,s){
			var ow=e.offsetWidth-wo, oh=e.offsetHeight-ho;
			if(ow==w&&oh==h){
				clearInterval(e.si); p.style.backgroundImage='none'; b.style.display='block'
			}else{
				if(ow!=w){e.style.width=ow+(Math.ceil(Math.abs(w-ow)/s)*wd)+'px'}
				if(oh!=h){e.style.height=oh+(Math.ceil(Math.abs(h-oh)/s)*hd)+'px'}
				this.pos()
			}
		}
	}
}();
TINY.page=function(){
	return{
		top:function(){return document.body.scrollTop||document.documentElement.scrollTop},
		width:function(){return self.innerWidth||document.documentElement.clientWidth},
		height:function(){return self.innerHeight||document.documentElement.clientHeight},
		theight:function(){
			var d=document, b=d.body, e=d.documentElement;
			return Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight))
		},
		twidth:function(){
			var d=document, b=d.body, e=d.documentElement;
			return Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		}
	}
}();
var VCS={};
VCS.Scroll=function(){
	var sp=20,st=1;
	var ofl = 0;
	return {
		to:function(s, l, o){
			ofl = l;
			if(s == 1 && o.canleft == 0)return o.cp;
			if(s == 0 && o.canright == 0)return o.cp;
			if(o.l && o.l > 0){return o.cp;}
			o.l  = l;
			if(!o.cp)o.cp = 0;
			o.cp += 1*((s == 1 || s == 3) ? -1 : 1);
			o.it = setInterval("VCS.Scroll.scroll(" + s + ",'" + o.id + "')", st);
			return o.cp;
		},
		scroll:function(s, id){
			var o = $(id);
			if(o.l <= 0){
				o.l = 0;
				clearInterval(o.it);
				if(o.scrollLeft == 0){
					o.canleft = 0;
					o.canright = 1;
				}else if(o.scrollLeft < o.scrollWidth - ofl){
					o.canleft = 1;
					o.canright= 1;
				}else{
					o.canleft = 1;
					o.canright = 0;
				}
				return;
			}
			var p = 1; //default is right, bottom.
			//left,top
			if(s==1 || s==3){p = -1;}
			var ck = o.l - sp;
			if(ck >= 0){
				o.scrollLeft += p*sp;
			}else{
				o.scrollLeft += p*(sp + ck);
			}
			o.l-=sp;
		}
	};
}();
VCS.Util=function(){
	return {
		resize:function(o,w,h,t,dc){
			var e = o.getElementsByTagName(t);
			var l = dc || e.length;
			o.style.width = (w * l) + 'px';
		},
		tips:function(o, dist, cp){
			var e = o.getElementsByTagName("img");
			dist.innerHTML = e[cp].alt;
		}
	};
}();
VCS.Alpha=function(){
	return {
		fadeIn: function(o, t){
			var id = o.id;
			if(!o.st){
				var ut = t/100;
				o.st = setInterval("VCS.Alpha.setOpacity('" + id + "',-1)", ut);
			}
		},
		fadeOut: function(o, t){
			var id = o.id;
			if(!o.st){
				var ut = t/100;
				o.st = setInterval("VCS.Alpha.setOpacity('" + id + "',1)", ut);
			}
		},
		setOpacity:function(id,v){
			var o = $(id);
			var p = o.style.opacity;
			if(p == 1 || p==0){
				clearInterval(o.st);
				return;
			}
			try{
				o.style.opacity += v*(0.1);
				o.style.filter = "alpha(Opacity=" + (p*10 + v) + ")";
				o.style.mozOpacity="0.5";
			}catch(e){};
		}
	};
}();
