// JavaScript Document


function ajaxcopy(file,target){
	ajax(file,"fill",target);
}

function fill(str,target){
	obj(target).innerHTML=unescape(str)
}

function alertfill(str,target){
	fill(str,target);
}

function ajax(file,action,args,post){
		if(args=="topage"){
			location=file
			return
			}
		var xmlObj = false;
		if (window.XMLHttpRequest) {
			xmlObj = new XMLHttpRequest();
			if (xmlObj.overrideMimeType) {
				xmlObj.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) {
			try {
				xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {}
			}
		}
		if (!xmlObj) {
			alert('Error: Cannot create an XMLHTTP instance');
			return false;
		}
		xmlObj.onreadystatechange = function(){
			loading(1)
			if(xmlObj.readyState == 4){
				if (xmlObj.status == 200) {
					if(action=="fill" ){ 
							resultstr=escape(unbom(xmlObj.responseText))
					}else if(action=="geturl"){
							window.location=args;
					}else if(action=="clickobj"){
							eval("obj('"+args+"').onclick()")				
					}else if(action=="alertfill"){
							resultarr = unbom(xmlObj.responseText).split('|');
							resultstr=escape(resultarr[0]);
							if(resultarr[2]!=undefined && resultarr[2]!="" && resultarr[1]!=undefined && resultarr[1]!="") {
								if(resultarr[2]=='geturl' && resultarr[3]!=undefined && resultarr[3]!=""){
									alert(resultarr[1]);
									window.location=resultarr[3];
								}else if(resultarr[2]=='function'){
									eval(resultarr[1]+"("+resultarr[3]+")");
								}else{
									if(confirm(resultarr[1])) { 
										eval(resultarr[2]+"()");
									}else{
										eval(resultarr[3]+"()");
									}
								}
							} else if (resultarr[1]!=undefined && resultarr[1]!="") {
								alert(resultarr[1]);
							}

					}else{
							resultstr=unbom(xmlObj.responseText)
					}
					
			
			if(file.indexOf("read.php")>-1){
				
				}
				try{
					if(args){
						resultstr=resultstr.replace(/'/g, "");
						eval(action+"('"+resultstr+"','"+args+"')")
					}else{
						resultstr=resultstr.replace(/'/g, "");
						eval(action+"('"+resultstr+"')")
					}
					loading(0)
				}catch(e){}
				}
				
			}
		}
		//alert(1+"---"+file);
		if(post){
			xmlObj.open ('POST', file, true);
			xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
			xmlObj.send (post);
		}else{
			xmlObj.open ('GET', file, true);
			xmlObj.send (null);
		}
		//alert(2+"---"+file);
}


function obj(name){ 
	return document.getElementById(name);
}

function val(name){ 
	return document.getElementById(name).value;
}

function setval(id,v){ 
	document.getElementById(id).value = v;
}


function psit(target,top,left){
top=parseInt(top)
left=parseInt(left)
	if(document.all){
		obj(target).style.pixelTop=top
		obj(target).style.pixelLeft=left
	}else{
		obj(target).style.top=top+"px"
		obj(target).style.left=left+"px"
	}
}

function gettop(target){
	if(document.all){
		return obj(target).style.pixelTop
	}else{
		return obj(target).style.top
	}
}

function getleft(target){
	if(document.all){
		return obj(target).style.pixelLeft
	}else{
		return obj(target).style.left
	}
}

function insert(target,insertstr){
	if(document.all){
obj(target).insertAdjacentHTML("afterEnd",insertstr)
}else{
	op=obj(target).parentNode
	var range=op.ownerDocument.createRange();
	range.setStartBefore(op);
	var fragment = range.createContextualFragment(insertstr);
		op.appendChild(fragment);  
}
	}
	
function intxt(target,content){
		obj(target).innerHTML=content
	}
	
function poscenter(targetid){
	var sw=screen.availWidth
	var sh=screen.availHeight
	var st=window.screenTop?window.screenTop:130
	var sc=(document.documentElement && document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;
	target=obj(targetid)
	var tw=parseInt(target.style.width)
	var th=parseInt(target.style.height)
	if(isNaN(th)){
		th=100
	}
	otop=sh/2-th/2-st/2+sc-50
	oleft=sw/2-tw/2
	psit(targetid,otop,oleft)
	//alert(otop)
	}
	
function poscorner(targetid){//?????????
	psit(targetid,0,0)
	}
	
function swclass(target,class1,class2){//???????????
	if(obj(target).className==class1){
		obj(target).className=class2
		}else{
			obj(target).className=class1
			}
	}

function dragobj(e,td){ //??????
	var evtobj=window.event? window.event : e
	ofx=evtobj.clientX-parseInt(td.style.left)
	ofy=evtobj.clientY-parseInt(td.style.top)
	 document.body.onselectstart=function(){return false} 
	//alert(evtobj.clientX)
	document.onmousemove=function(){
		td.style.left=evtobj.clientX-ofx+"px"
		td.style.top=evtobj.clientY-ofy+"px"
		}
	document.onmouseup=function(){
		document.onmousemove=""
	 document.body.onselectstart=""; 
		if(window.event){
			document.releaseCapture()
		}else{
			window.releaseEvents(event.mousemove);
		}
		}
}
function stopdragobj(e){
		if(window.event){
			document.releaseCapture()
		}else{
			window.releaseEvents(event.mousemove);
		}
		document.onmousemove=null
	}
	
function hide(targetDiv){ //????
	try{
		td=obj(targetDiv)
		td.style.display='none'
	}catch(e){
	}
}
function show(targetDiv){ //????
	try{
		td=obj(targetDiv)
	//td.style.display='block'
	}catch(e){}
}


function selectbox(name,num){ //??
	for(var i=0;i<num;i++){
		obj(name+i).checked=obj(name+"all").checked
		}
	}
function geturl(str,url){
	location=url
	}
function getallbox(name,num){ //??????????","??
	valarr=new Array()
	for(var i=0;i<num;i++){
			if(obj(name+i).checked==true){
				valarr.push(obj(name+i).value)
			}
		}
	valstr=valarr.join(",")
	return valstr
	}
	
function invertbox(name,num){ 
	for(var i=0;i<num;i++){
		obj(name+i).checked=!obj(name+i).checked
		}
	}



function showmsg(a,name,title){ 
	ajax("message.php?a="+a+"&d="+name+"&t="+title,"fill","msgbox");
	poscenter('messagebox');
	show("messagebox");
	}
	
function sendmsg(){ 
	poststr="mt="+val("msgtitle")+"&mc="+val("msgcontent")+"&sd="+val("sender")+"&ds="+val("dest")
	ajax("message.php?a=send","fill","msgbox",poststr)
	}
	
function msgalert(str){
	str='<div style="padding:25px 5px">'+str+'</div><div style="padding:5px"><input id="msgokbtn" class="minibtn" type="button" value="OK" onclick="hide(\'messagebox\')"/></div>';
	//alert(str);
	obj('msgbox').innerHTML=str;
	poscenter('messagebox');
	show("messagebox");
	}
function msgrefresh(str){
	str='<div style="padding:25px 5px">'+str+'</div><div style="padding:5px"><input id="msgokbtn" class="minibtn" type="button" value="OK" onclick="hide(\'messagebox\');location=location"/></div>';
	//alert(str);
	obj('msgbox').innerHTML=str;
	poscenter('messagebox');
	show("messagebox");
	}
function msgurl(str,url){
	str='<div style="padding:25px 5px">'+str+'</div><div style="padding:5px"><input id="msgokbtn" class="minibtn" type="button" value="OK" onclick="hide(\'messagebox\');location=\''+url+'\'"/></div>';
	//alert(str);
	obj('msgbox').innerHTML=str;
	poscenter('messagebox');
	show("messagebox");
	}
function msgback(str){
	str='<div style="padding:25px 5px">'+str+'</div><div style="padding:5px"><input id="msgokbtn" class="minibtn" type="button" value="OK" onclick="history.back(1)"/></div>';
	//alert(str);
	obj('msgbox').innerHTML=str;
	poscenter('messagebox');
	show("messagebox");
	}
function msgrun(url){ //???????
	ajax(url,'fill',"msgbox");
	show("messagebox");
	}

function msgchkuserback(str){ //msgchkusr????????
	if(str==1){
		sendmsg()
	}else{
		alert("No such user!")
		return false
	}
	}

function msgchkusr(target){ //?????????????
	if(target.value==obj("sender").value){
		alert("Can't send to yourself!")
		return false;
	}else{
		return true;
		}
}



function logboxclick(){ 
	poststr="username="+val("username")+"&password="+val("password")+"&vercode="+val("vercode")
	ajax('logbox.php','fill','logbox',poststr)
	}
function logboxclick2(){ 
	poststr="username="+val("username")+"&password="+val("password")+"&vercode="+val("vercode")
	ajax('logbox.php','fill','logbox',poststr)
	location="logbox2.php";
	}

function getgender(n){ 
	if(n==1){
		return "Boy"
		}else{
		return "Girl"	
			}
	}

function postcomm(target){ 
	  poststr="content="+val("content");
	  poststr+="&user="+val("user");
	  poststr+="&id="+val("id");
	  poststr+="&work=blog";
	  ajax("comment.php","fill",target,poststr);
  	}

function flash(url,width,height){//??FLASH???
	var flashstr="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+width+"\" height=\""+height+"\"><param name=\"wmode\" value=\"transparent\"/><param name=\"allowscriptaccess\" value=\"always\"/><param name=\"movie\" value=\""+url+".swf\"/><param name=\"quality\" value=\"high\"/><embed src=\""+url+".swf\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" wmode=\"transparent\" allowscriptaccess=\"always\"></embed></object>"
	return flashstr
	}
	
function loading(n){ 
	if(n==1){
		//poscenter("loading")
		show("loading")
		}else{
			hide("loading")
			}
		//setTimeout("hide(\"loading\")",5000)
	}
		
function setablist(aburl){
	document.write("<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"><tr>")
	var mya="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	for(i=0;i<26;i++){
	document.write("<td width=\"20\" height=\"20\" class=\"ab ha\" id=\"ab"+i+"\" onmouseover=\"this.style.border='1px solid #666666';this.className='abh ha'\" onmouseout=\"this.style.border='1px solid #cccccc';this.className='ab ha'\" onclick=\"clearab();this.className='ab ha';ajax('"+aburl+"&key="+mya.substr(i,1)+"','fill','topage')\" style=\"cursor:pointer\">"+mya.substr(i,1)+"</td>")
	}
	document.write("<td width=\"20\" height=\"20\" class=\"ab ha\" id=\"ab"+i+"\" onmouseover=\"this.style.border='1px solid #666666';this.className='abh ha'\" onmouseout=\"this.style.border='1px solid #cccccc';this.className='ab ha'\" onclick=\"clearab();this.className='ab ha';ajax('"+aburl+"','fill','topage')\" style=\"cursor:pointer\">ALL</td>")
	document.write("</tr></table>")
}

function clearab(){
	for(j=0;j<26;j++){
		document.getElementById("ab"+j).className="ab"
	}
}

function unbom(ret){
 if ('\uFEFF' == ret.charAt(0)) {
        ret = ret.substring(1); //UTF-8???????'\uFEFF'????????
    }
	 if (unescape("%0D") == ret.charAt(0)) {
        ret = ret.substring(1); //UTF-8???????'\uFEFF'????????
    }
	 if (unescape("%0A") == ret.charAt(0)) {
        ret = ret.substring(1); //UTF-8???????'\uFEFF'????????
    }
	return(ret);
}

function getage(str){//????
	datearr=str.split("-")
	nowdate=new Date()
	age=nowdate.getFullYear()-datearr[0];
	if(nowdate.getMonth()>datearr[1]){
		age--
	}else if(nowdate.getMonth()==datearr[1]){
		if(nowdate.getDate()>datearr[2]){
			age--
			}		
	}else{}
	return age;
}

function fref(id){
	ajax("friend.php?a=refuse&u="+id,"msgalert");
	}
function fapp(id){
	ajax("friend.php?a=app&i="+id,"msgalert");
	}
function showitem(target,url){
	if(url.indexOf("diy-show.swf")==-1){
		url="showswf.swf?url="+url;
	}else{
		url=url.split("diy-show").join("showdiy")
	}
	wid=target.width;
	hei=target.height;
	if(document.all){
		target.outerHTML=flash(url,wid,hei)
	}else{
		target.innerHTML=flash(url,wid,hei)
	}
}
function tags(tag){
	tmparr=tag.split(',');
	tagarr=new Array();
	for(var i in tmparr){
		tagarr.push("<a href='avatar.php?a=tag&t="+tmparr[i]+"'>"+tmparr[i]+"</a>")
	}
	tagstr=tagarr.join(',');
	document.write(tagstr);
	}


function cloud(str,target){
result=""
tmparr=str.split('|');

tagarr=new Array();
cont=new Array()
for(var i=0;i<tmparr.length-1;i++){
	tagarr[i]=tmparr[i].split(',')
	tagarr[i].push(i)
	cont[i]=tagarr[i][1];
}
sorarr=tagarr.slice()
sorarr.sort(function(a,b){return b[1]-a[1]})
myc=5
for(var i in sorarr){
	tagarr[sorarr[i][2]][3]=myc;
	if(i%5==0){
	myc--;
	}
}
tagarr.sort()
for(var i in tagarr){
	result+="<div style=\"line-height:20px;padding-left:10px;border-bottom:1px dashed #cccccc\" onclick=\"location='avatar.php?a=tag&t="+tagarr[i][0]+"'\" title=\"[ "+tagarr[i][1]+" ]\" class=\"ha tags"+tagarr[i][3]+"\" onmouseover=\"this.className='ha yk2 tags"+tagarr[i][3]+"'\" onmouseout=\"this.className='ha tags"+tagarr[i][3]+"'\">"+tagarr[i][0]+"</div> "
}
fill(result,target)
}