var xmlHttpCounter
function next(int)
{
	document.getElementById("comment_left").innerHTML = '';
	document.getElementById("comment_right").innerHTML = '';

	if(document.getElementById("next_q_id").value == document.getElementById("id").value || document.getElementById("next_q_id").value=="" ){
		document.getElementById("right_loading_stat").innerHTML='<img src="/images/loading.gif" alt="" />'
		document.getElementById("left_loading_stat").innerHTML=''

		xmlHttpCounter=GetXmlHttpObject()
		if (xmlHttpCounter==null)
		 {
		 alert ("Browser does not support HTTP Request")
		 return
		 } 
		var url="next.php"
		url=url+"?sid="+Math.random()
		xmlHttpCounter.onreadystatechange=stateChangedNext2 
		xmlHttpCounter.open("GET",url,true)
		xmlHttpCounter.send(null)
		
	}else{	
var old_id = document.getElementById("next_q_id").value
		document.getElementById("right_loading_stat").innerHTML='<img src="/images/loading.gif" alt="" /> &#1583;&#1585; &#1581;&#1575;&#1604; &#1576;&#1575;&#1585;&#1711;&#1584;&#1575;&#1585;&#1740; &#1576;&#1593;&#1583;&#1740;'
		document.getElementById("left_loading_stat").innerHTML=''
		
		document.getElementById("id").value=document.getElementById("next_q_id").value
		//document.getElementById("left_pic").style.backgroundImage="url(choice/"+document.getElementById("next_q_left_pic").value+")"

		document.getElementById("left").innerHTML=document.getElementById("next_q_left").value
		document.getElementById("right").innerHTML=document.getElementById("next_q_right").value
		
document.getElementById("vote_buttom_right").style.display = 'block'
document.getElementById("vote_buttom_left").style.display = 'block'
document.getElementById("rank_box_right").style.display = 'none'
document.getElementById("rank_box_left").style.display = 'none'		
		
		document.getElementById("left_rank").innerHTML=document.getElementById("next_q_left_rank").value
		document.getElementById("left_pic").style.backgroundImage="url(choice/"+document.getElementById("next_q_left_pic").value+")"

		document.getElementById("right_rank").innerHTML=document.getElementById("next_q_right_rank").value
		document.getElementById("right_pic").style.backgroundImage="url(choice/"+document.getElementById("next_q_right_pic").value+")"
		
		document.getElementById("right_percent").innerHTML=document.getElementById("next_q_right_percent").value
		document.getElementById("left_percent").innerHTML=document.getElementById("next_q_left_percent").value
		
		document.getElementById("right_percent_bar").style.width=Math.round(document.getElementById("next_q_right_percent").value*2)+"px"
		document.getElementById("left_percent_bar").style.width=Math.round(document.getElementById("next_q_left_percent").value*2)+"px"
		
 document.getElementById("right_selection").className='normal'
 document.getElementById("left_selection").className='normal'
		document.getElementById("site").href=document.getElementById("next_q_site").value
		
		
		document.getElementById("right_loading_stat").innerHTML=''
		document.title='راست یا چپ؟ انتخاب کنید و لبخند بزنید :: '+document.getElementById("next_q_right").value+' یا '+document.getElementById("next_q_left").value
		
		xmlHttpCounter=GetXmlHttpObject()
		if (xmlHttpCounter==null)
		 {
		 alert ("Browser does not support HTTP Request")
		 return
		 } 
		var url="next.php"
		url=url+"?sid="+Math.random()
		url=url+"&old_id="+old_id
		xmlHttpCounter.onreadystatechange=stateChangedNext 
		xmlHttpCounter.open("GET",url,true)
		xmlHttpCounter.send(null)
	}
} 

function stateChangedNext() 
{ 
 if (xmlHttpCounter.readyState==4 || xmlHttpCounter.readyState=="complete")
 {

var xmlDoc=xmlHttpCounter.responseXML

document.getElementById("next_q_id").value = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue

document.getElementById("next_q_title_fa").value = xmlDoc.getElementsByTagName("title_fa")[0].childNodes[0].nodeValue
document.getElementById("next_q_title_en").value = xmlDoc.getElementsByTagName("title_en")[0].childNodes[0].nodeValue
document.getElementById("next_q_left").value = xmlDoc.getElementsByTagName("left")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_rank").value = xmlDoc.getElementsByTagName("left_rank")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_pic").value = xmlDoc.getElementsByTagName("left_pic")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_desc").value = xmlDoc.getElementsByTagName("left_desc")[0].childNodes[0].nodeValue
document.getElementById("next_q_right").value = xmlDoc.getElementsByTagName("right")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_rank").value = xmlDoc.getElementsByTagName("right_rank")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_pic").value = xmlDoc.getElementsByTagName("right_pic")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_desc").value = xmlDoc.getElementsByTagName("right_desc")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_percent").value = xmlDoc.getElementsByTagName("right_percent")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_percent").value = xmlDoc.getElementsByTagName("left_percent")[0].childNodes[0].nodeValue
document.getElementById("next_q_site").value = xmlDoc.getElementsByTagName("site")[0].childNodes[0].nodeValue

commnet_left();
commnet_right();
	
	simplePreload( 'choice/'+xmlDoc.getElementsByTagName("right_pic")[0].childNodes[0].nodeValue, 
		'choice/'+xmlDoc.getElementsByTagName("left_pic")[0].childNodes[0].nodeValue );

 } 
} 


function stateChangedNext2() 
{ 
 if (xmlHttpCounter.readyState==4 || xmlHttpCounter.readyState=="complete")
 {
var xmlDoc=xmlHttpCounter.responseXML

document.getElementById("next_q_id").value = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue

document.getElementById("next_q_title_fa").value = xmlDoc.getElementsByTagName("title_fa")[0].childNodes[0].nodeValue
document.getElementById("next_q_title_en").value = xmlDoc.getElementsByTagName("title_en")[0].childNodes[0].nodeValue
document.getElementById("next_q_left").value = xmlDoc.getElementsByTagName("left")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_rank").value = xmlDoc.getElementsByTagName("left_rank")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_pic").value = xmlDoc.getElementsByTagName("left_pic")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_desc").value = xmlDoc.getElementsByTagName("left_desc")[0].childNodes[0].nodeValue
document.getElementById("next_q_right").value = xmlDoc.getElementsByTagName("right")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_rank").value = xmlDoc.getElementsByTagName("right_rank")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_pic").value = xmlDoc.getElementsByTagName("right_pic")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_desc").value = xmlDoc.getElementsByTagName("right_desc")[0].childNodes[0].nodeValue
document.getElementById("next_q_right_percent").value = xmlDoc.getElementsByTagName("right_percent")[0].childNodes[0].nodeValue
document.getElementById("next_q_left_percent").value = xmlDoc.getElementsByTagName("left_percent")[0].childNodes[0].nodeValue
document.getElementById("next_q_site").value = xmlDoc.getElementsByTagName("site")[0].childNodes[0].nodeValue

	simplePreload( 'choice/'+xmlDoc.getElementsByTagName("right_pic")[0].childNodes[0].nodeValue, 
		'choice/'+xmlDoc.getElementsByTagName("left_pic")[0].childNodes[0].nodeValue );
		
	next();
 } 
} 

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
 {
 objXMLHttp=new XMLHttpRequest()
 }
else if (window.ActiveXObject)
 {
 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
 }
return objXMLHttp
}

function simplePreload()

{ 

  var args = simplePreload.arguments;

  document.imageArray = new Array(args.length);

  for(var i=0; i<args.length; i++)

  {

    document.imageArray[i] = new Image;

    document.imageArray[i].src = args[i];

  }

}