// AJAXÀà
//--------------------------------------------------------------------
function AJAXRequest() {
	var xmlObj = false;
	var CBfunc,ObjSelf;
	ObjSelf=this;
	try { xmlObj=new XMLHttpRequest; }
	catch(e) {
		try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
		catch(e2) {
			try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e3) { xmlObj=false; }
		}
	}
	if (!xmlObj) return false;
	this.method="POST";
	this.url;
	this.async=true;
	this.content="";
	this.callback=function(cbobj) {return;}
	this.send=function() {
		if(!this.method||!this.url||!this.async) return false;
		xmlObj.open (this.method, this.url, this.async);
		if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlObj.onreadystatechange=function() {
			if(xmlObj.readyState==4) {
				if(xmlObj.status==200) {
					ObjSelf.callback(xmlObj);
				}
			}
		}
		if(this.method=="POST") xmlObj.send(this.content);
		else xmlObj.send(null);
	}
}

//----------------------------------------------------------------------

//user login
var lobd=0;
var lobd1=-26;
var lotim=null;
var lonows=0;
function showlogin(){if(lonows==0){tomax();}else{tomin();}}
function tomin(){try{document.getElementById("username").focus();}catch(e){} lobd--;lobd1--;lonow(lobd,lobd1);if(lobd1==-26){lonows=0;clearTimeout(lotim);return;}else{lotim=setTimeout('tomin()',5);}}
function tomax(){try{document.getElementById("username").focus();}catch(e){} lobd++;lobd1++;lonow(lobd,lobd1);if(lobd1==0){lonows=1;clearTimeout(lotim);return;}else{lotim=setTimeout('tomax()',5);}}
function lonow(lobd,lobd1){document.getElementById("loginbd").style.height=lobd+"px";document.getElementById("thelogin").style.top=lobd1+"px";}


//link img ti huan
img1 =new Image();img1.src ='/img/a1.gif';
img11=new Image();img11.src='/img/a1_1.gif';
img2 =new Image();img2.src ='/img/a2.gif';
img21=new Image();img21.src='/img/a2_1.gif';
img3 =new Image();img3.src ='/img/a3.gif';
img31=new Image();img31.src='/img/a3_1.gif';
img4 =new Image();img4.src ='/img/a4.gif';
img41=new Image();img41.src='/img/a4_1.gif';
img5 =new Image();img5.src ='/img/a9.gif';
img51=new Image();img51.src='/img/a10.gif';
function mover(th,id){eval('th.src=img'+id+'1.src');}
function mout(th,id){eval('th.src=img'+id+'.src');}



//input background color
function zfocus(th){th.value='';th.style.backgroundColor='#fffbbd';}
function zfocus1(th){th.style.backgroundColor='#fffbbd';}
function zblurs(th){th.style.backgroundColor='#fafafa';}


//small page
function tshow(i)
{	
	document.getElementById("pg1").className='no';document.getElementById("pg2").className='no';
	document.getElementById("pg3").className='no';//document.getElementById("pg4").className='no';
	document.getElementById("pg"+i).className='yes';
    document.getElementById("pgs1").style.display='none';document.getElementById("pgs2").style.display='none';
	document.getElementById("pgs3").style.display='none';//document.getElementById("pgs4").style.display='none';
    document.getElementById("pgs"+i).style.display='';
}
function Is_Mail()
{
	if(document.getElementById("email").value.indexOf("@")==-1)	return false;
	if(document.getElementById("email").value.indexOf(".")==-1)	return false;
	if(document.getElementById("email").value.lastIndexOf(".")==document.getElementById("email").value.length-1)	return false;
	if(document.getElementById("email").value.indexOf("@")!=document.getElementById("email").value.lastIndexOf("@"))	return false;
	return true;
}
function senddxx(username,i)
{
	var content,a;
	a	= '';
	content	= document.getElementById("content").value;
	if(content=='')	{document.getElementById("btn").value='Please Enterthe Content!';return false;}
	document.getElementById("btn").value='Sending';
	var ajaxobj=new AJAXRequest;
	url= "/work/senddxx.php";
	p = "username="+username+"&content="+content;
	ajaxobj.method="POST";
	ajaxobj.url=url;
	ajaxobj.content=p;
	ajaxobj.callback=function(xmlobj) {
		a+="<div class=fudong><div class=fudongnr><br><br><b>Your messenge has been sent!</b><br><br></div>";
		a+="<div class=fudongclose><a href=# onclick=return(closepos1("+i+"))><img src=/img/close.gif /></a></div>";
		a+="<div class=clear></div></div>";
		document.getElementById("lis"+i).innerHTML =a;
	}
	ajaxobj.send();

}

//page list to zuo zhe
var divnow=0;
function posts(i,username,userid)
{
	
	divnow=1;
	var a="";
	document.getElementById("lis"+i).innerHTML ="";
	if(userid>0)
	{		
		a+="<div class=fudong><div class=fudongnr><table width=100% cellpadding=0>";
		a+="<tr><td colspan=2 align=left><b>Send Message to Newsposter</b></td></tr>";
		a+="<tr><td>To:</td><td><input type=text id='username' value='"+username+"' class=potexts /></td></tr>";
		a+="<tr><td valign=top>Message:</td><td><textarea id='content' class=potexts1 ></textarea></td></tr>";
		a+="<tr><td valign=top>&nbsp;</td><td><input type=submit id='btn' value=Send class=pobt onclick=senddxx('"+username+"',"+i+");></td></tr>";
		a+="</table></div><div class=fudongclose><a href=# onclick=return(closepos1("+i+"))><img src=/img/close.gif /></a></div><div class=clear></div></div>";
	}
	else
	{
		a+="<div class=fudong><div class=fudongnr>Sorry, <a href=/login.php>Login</a> or <a href=/regist.php>Join 9Down</a> for free.</div>";
		a+="<div class=fudongclose><a href=# onclick=return(closepos1("+i+"))><img src=/img/close.gif /></a></div>";
		a+="<div class=clear></div></div>";
	}
	document.getElementById("lis"+i).innerHTML =a;
	return false;
}
function checkpost(i,id)
{
	if(!Is_Mail())	{document.getElementById("email").value='Invalid E-mail!';return false;}
	var content,a,email,senduser;
	a	= '';
	senduser= document.getElementById("senduser").value;
	email	= document.getElementById("email").value;
	content	= document.getElementById("content").value;
	document.getElementById("btn").value='Sending';
	var ajaxobj=new AJAXRequest;
	url= "/work/sendemail.php";
	p = "id="+id+"&senduser="+senduser+"&email="+email+"&content="+content;
	ajaxobj.method="POST";
	ajaxobj.url=url;
	ajaxobj.content=p;
	ajaxobj.callback=function(xmlobj) {
		//alert(xmlobj.responseText);
		a+="<div class=fudong><div class=fudongnr><br><br><b>Your email has been sent!</b><br><br></div>";
		a+="<div class=fudongclose><a href=# onclick=return(closepos1("+i+"))><img src=/img/close.gif /></a></div>";
		a+="<div class=clear></div></div>";
		document.getElementById("lis"+i).innerHTML =a;
	}
	ajaxobj.send();
	
}
function postemail(i,id)
{
	
	divnow=1;
	var a="";
	document.getElementById("lis"+i).innerHTML ="";
	a+="<div class=fudongv><div class=fudongnrv><table width=100% cellpadding=0>";
	a+="<tr><td colspan=2 align=left><b>Send Message to Newsposter</b></td></tr>";
	a+="<tr><td>Recipient name:</td><td><input type=text id='senduser'  class=potexts /></td></tr>";
	a+="<tr><td>Recipient email:</td><td><input type=text id='email' class=potexts /></td></tr>";
	a+="<tr><td valign=top>Extra info:</td><td><textarea id='content' class=potexts1 ></textarea></td></tr>";
	a+="<tr><td valign=top>&nbsp;</td><td><input type=submit id='btn' value=Send class=pobt onclick=checkpost("+i+","+id+");></td></tr>";
	a+="</table></div><div class=fudongclose><a href=# onclick=return(closepos1("+i+"))><img src=/img/close.gif /></a></div><div class=clear></div></div>";

	document.getElementById("lis"+i).innerHTML =a;
	return false;
}
function closepos(id){if(divnow==0){document.getElementById("lis"+id).innerHTML="";return false;}}
function closepos1(id){if(divnow==1){document.getElementById("lis"+id).innerHTML="";return false;}}
function addli(i,username,userid)
{
	
	divnow=0;
	document.getElementById("lis"+i).innerHTML ="<div class=vs><li><a href=# onclick=return(posts("+i+",'"+username+"',"+userid+"))>Send Messenge</a></li><li><a href=/user-"+username+".htm >View Profile</a></li></div>";
}


//ajax begin


imgt1=new Image();imgt1.src="/img/t2.gif";
imgt2=new Image();imgt2.src="/img/t1.gif";
function zshos(na,id){for (i=1;i<6;i++){document.getElementById(na+i).src=imgt2.src;}for (i=1;i<=id;i++){document.getElementById(na+i).src=imgt1.src;}}
function zhids(na){for (i=1;i<6;i++){document.getElementById(na+i).src=imgt2.src;}}
var k=null;
function jb(){var a=null;try{a=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{a=new ActiveXObject("Microsoft.XMLHTTP")}catch(oc){a=null}}if(!a&&typeof XMLHttpRequest!="undefined"){a=new XMLHttpRequest()}return a;}
//function gopost(na,id){if(k&&k.readyState!=0){k.abort()}k=jb();if(k){k.open("GET","/work/vote.php?id="+na+"&score="+escape(id),true);k.onreadystatechange=function(){if(k.readyState==4&&k.responseText){document.getElementById("ratinged").innerHTML='Thanks for rating!';}};k.send(null);}}
function gopost(id,score)
{
	var ajaxobj=new AJAXRequest;
	url= "/work/vote.php?temp="+Math.random();
	p = "id="+id+"&score="+score;
	ajaxobj.method="POST";
	ajaxobj.url=url;
	ajaxobj.content=p;
	ajaxobj.callback=function(xmlobj) {
		document.getElementById("ratinged").innerHTML='Thanks for rating!';
		document.getElementById("scoreid").innerHTML=parseInt(document.getElementById("scoreid").innerHTML)+1;
		
	}
	ajaxobj.send();
}

function reguser(){var nm=document.getElementById("regusername").value;if(k&&k.readyState!=0){k.abort()}k=jb();if(k){k.open("GET","checkuser.php?username="+nm,true);k.onreadystatechange=function(){if(k.readyState==4&&k.responseText){showuser(k.responseText);}};k.send(null);}}

function showuser(id)
{
	document.getElementById("yacg").innerHTML="<p>" + id + "</p>";
	return false;
}
//tb yong

function bglist(tb)
{
	dom = document.getElementById(tb).getElementsByTagName("tr");
	for(var i =1;i<dom.length;i++)
	{
		dom[i].onmouseover = function(){this.style.backgroundColor='#f8f8f8';};
		dom[i].onmouseout = function(){this.style.backgroundColor='';};
	}
}




//submit
function showadd(id)
{
var a11="Enter the URL of the source website";
var a12="Enter the title of the source webpage";
var a21="Enter the complete URL for the download";
var a22="Enter the name of the file";
var a31="Enter the complete URL for the Screenshot";
var a32="Enter the title of the screenshot";
var a41="Enter the complete URL";
var a42="Enter the name of the link";
var now1="";
var now2="";
	 if(id==1){now1=a11;now2=a12;}
else if(id==2){now1=a21;now2=a22;}
else if(id==3){now1=a31;now2=a32;}
else if(id==4){now1=a41;now2=a42;}
var s ="<table width=100% class=subycc>";
	s+="<tr><td align=right>"+now2+":</td><td><input type=text class=logintexts onfocus='zfocus(this);' onblur='zblurs(this);' id='lss2'></td></tr>";
    s+="<tr><td align=right>"+now1+":</td><td><input type=text class=logintexts onfocus='zfocus(this);' onblur='zblurs(this);' id='lss1'> <input type=submit value=Add onclick='adds("+id+")' class=sub4></td></tr></table>";
	document.getElementById("gnan").innerHTML=s;
}

function adds(id)
{
var a11="News source : "
var a12="Source"
var a21="Download : ";
var a22="Download"
var a31="Screenshot : ";
var a32="Click here"
var a41="Link : ";
var a42="Link"
var now1="";
var now2="";
	 if(id==1){now1=a11;now2=a12;}
else if(id==2){now1=a21;now2=a22;}
else if(id==3){now1=a31;now2=a32;}
else if(id==4){now1=a41;now2=a42;}
if(document.getElementById("lss1").value==""){return;}
if(document.getElementById("lss2").value!=""){now2=document.getElementById("lss2").value;}
document.getElementById("gdlink").value+="<b>"+now1+"</b><a href='"+document.getElementById("lss1").value+"' target='_blank'>"+now2+"</a><br/>\n";
document.getElementById("gnan").innerHTML="";
}

function ys(username)
{
var a ="<div class='liti bj'><a href='#'>"+document.getElementById("title").value+"</a> &nbsp;<img src='/img/b0.gif' align='absmiddle' /></div>";
	a+="<div class='lism bj'>Posted by <b>"+username+"</b> <b>0</b> hours ago  There are <b>0</b> comments</div>";
	a+="<div class='linr bj'>";
//	a+="<div class='linr bj'><a href='#'><img src='/img/r"+document.getElementById("fls").options[document.getElementById("fls").selectedIndex].value+".gif' /></a>";
	//a+=document.getElementById("gdnr").value.substring(1,700); 
	a+=window.mce_editor_0.document.body.innerHTML.substring(1,700);
	a+=" > more</div>";
	a+="<div class=clear></div>";
	a+="<div class='lifls bj'>"+document.getElementById("gdlink").value+"</div>";
	a+="<div class='lidown'><b>...Read More</b> | Last comment was by  | <img src='/img/a18.gif' align='absmiddle' /> comment</span></div>";
	a+="<div class='liti bj'></div>";
document.getElementById("ysbd").innerHTML=a;

}
function mysubmit()
{
	document.getElementById("gdnr").value	= window.mce_editor_0.document.body.innerHTML;
	if(document.getElementById("title").value=='')
	{
		document.getElementById("showtitle").innerHTML	= '* Required ';
		return false;
	}else{
		document.getElementById("showtitle").innerHTML	= '';
	}
	if(document.getElementById("gdnr").value=='')
	{
		document.getElementById("showcontent").innerHTML	= '* Required ';
		return false;
	}else{
		document.getElementById("showcontent").innerHTML	= '';
	}
	if(document.getElementById("fls").value=='0')
	{
		document.getElementById("showtopic").innerHTML	= '* Required ';
		return false;
	}else{
		document.getElementById("showtopic").innerHTML	= '';
	}
	document.getElementById("myform").submit();	
}
function mysearch()
{
	var mykeyword	= document.getElementById("keyword").value;
	alert(mykeyword);
	mykeyword	= mykeyword.replace(/\s+/g,"-")
	alert(mykeyword);
	if(mykeyword!="")	location.href='/search/'+mykeyword+'/';
}
function mypageno(i)
{
	document.getElementById("pageno").value	= i+parseInt(document.getElementById("pageno").value);
	document.getElementById("myform").submit();
}
function comm_re(pid)
{
	document.getElementById("pid").value=pid;
	document.getElementById("subtitle").focus();
}
function comm_qu(url,pid)
{
	location.href=url+pid+'/';
}
function checkcomm()
{
	if(window.mce_editor_0.document.body.innerHTML)
	{
		document.getElementById("subcomm").value	= window.mce_editor_0.document.body.innerHTML;
	}
	return true;
}
function searchsubmit()
{
	document.getElementById("keyword").value	= document.getElementById("keywd").value;
	document.getElementById("myform").submit();
}