// JavaScript Document

function reset_val(){
	document.getElementById('prev').value='1';
	document.getElementById('pic_gallery').value='1';
}

function startTime(j){
	var today=new Date();
	var h=today.getHours();
	h=h%12;
	var m=today.getMinutes();
	var s=today.getSeconds();
	go_(j);
	var cc=0;
	
	j++;
	if(j==5)
		j=1;
	
	m=checkTime(m);
	s=checkTime(s);
	t=setTimeout('startTime('+j+')',10000);
}

function checkTime(i){
	if (i<10){
	  i="0" + i;
	}
	return i;
}
 
function go_(x){

	xmlHttp=GetXmlHttpObject();
	 if (xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    } 
	xmlHttp.open("POST","other_topnews.php?counter="+x, true);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.send(null);
	
}

function stateChanged(){ 
    if (xmlHttp.readyState==4){ 
		var val=xmlHttp.responseText;
		//alert(val);
		var news=val.split("*****");
		//////////////Changing image and news////////////////////////
		document.getElementById('lead_image').src="http://174.120.4.66/~theqc/newsImage/"+news[2];
		var x=parseInt(news[3]);
		document.getElementById('search'+x).src="image/"+"tab"+x+"_s.gif";
		/////////////////////////////////////////////////////
		//alert("x= "+x);
		//alert('1');
		for(xy=1;xy<=4;xy++){
			if(xy!=x){
				//alert("xy= "+xy);
				//document.getElementById('search'+xy).src="image/"+"tab"+xy+".gif";	
				document.getElementById('search'+xy).style.backgroundImage="none";
			}
			
		}
		//document.getElementById('search'+x).src="image/"+"tab"+x+"_s.gif";
		document.getElementById('search'+x).style.backgroundImage="url(images/slide-num-bg-hover.gif)";
		
		document.getElementById('search'+x).style.backgroundRepeat="no-repeat";
		//alert('2');
		document.getElementById('lead_news_heading').innerHTML="<a class=t_main target=_BLANK href=details.php?cat="+x+">"+news[0]+"</a>";
		//alert('3');
		document.getElementById('lead_news').innerHTML="<a class=t1 target=_BLANK href=details.php?cat="+x+">"+news[1]+"</a>";
		//alert('4');
		var prev=document.getElementById('prev').value;
		//alert('5');
		
			
		document.getElementById('prev').value=x;			
	
	 next();
		
    }
}

function stateChanged2(){ 
    if (xmlHttp.readyState==4){ 
		var val=xmlHttp.responseText;
		//alert(val);
		var news=val.split("*****");
		var x=parseInt(news[0]);
		document.getElementById('gallery_image').src="../picture_div/picgallery_ban/"+x+".jpg";
		document.getElementById('gallery_caption').innerHTML=news[1];	
		
    }
}

function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
     }

    catch (e){
        // Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }

        catch (e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
} 



function previous(){
	xmlHttp=GetXmlHttpObject();
	var x=parseInt(document.getElementById("pic_gallery").value)-1;
	if(x==0)
		x=8;
	if (xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    } 
	xmlHttp.open("POST","img_gallery.php?img="+x, true);
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.send(null);
	
	document.getElementById("pic_gallery").value=x;
	
}

function next(){
	xmlHttp=GetXmlHttpObject();
	var x=parseInt(document.getElementById("pic_gallery").value)+1;
	
	
	if(x==9)
		x=1;
	if (xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    } 
	xmlHttp.open("POST","img_gallery.php?img="+x, true);
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.send(null);
	
	document.getElementById("pic_gallery").value=x;
	
}




function go_english(){
	window.location="../english/";	
}