var pnum=100;
var spnum=1;

var tWidth='798px';                  // width (in pixels)
var tHeight='25px';                  // height (in pixels)
var tcolour='#000000';               // background colour:
var moStop=true;                     // pause on mouseover (true or false)
var fontfamily = 'georgia,arial,sans-serif'; // font for content
var tSpeed=1;                        // scroll speed (1 = slow, 5 = fast)
var content = new String(); // (use \/ and \' in place of / and 'respectively)
var cps=tSpeed;
var aw, mq;
var fsz = parseInt(tHeight) - 8;


function getTicker(){
var xmlhttp;
var ez = this;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
  {
    ez.xmlhttp=new XMLHttpRequest();
  }
  // code for IE6, IE5
  else if (window.ActiveXObject)
  {
   ez.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else
  {
   alert("Your browser does not support XMLHTTP!");
  }

 ez.xmlhttp.onreadystatechange=function()
 {
  if(ez.xmlhttp.readyState==4)
  {
      content = ez.xmlhttp.responseText;
      content = unescape(content);
      startticker();
  }
 }
  ez.xmlhttp.open("GET","ticker_cre.php",true);
  ez.xmlhttp.send(null);
}  

function startticker(){
	if (document.getElementById) {
		var tick = '<div style="position:relative;width:'+tWidth+';height:'+tHeight+';overflow:hidden;background-color:'+tcolour+'"';
		if (moStop) tick += ' onmouseover="cps=0" onmouseout="cps=tSpeed"'; tick +='><div id="mq" style="position:absolute;left:0px;top:0px;font-family:'+fontfamily+';font-size:'+fsz+'px;white-space:nowrap;"><\/div><\/div>';
		    document.getElementById('ticker').innerHTML = tick;
		    mq = document.getElementById("mq");
		    mq.style.left=(parseInt(tWidth)+10)+"px";
		    mq.innerHTML='<span id="tx">'+content+'<\/span>';
		    aw = document.getElementById("tx").offsetWidth;
		    lefttime=setInterval("scrollticker()",5);
		}
}

function scrollticker(){
	mq.style.left = (parseInt(mq.style.left)>(-10 - aw)) ?parseInt(mq.style.left)-cps+"px" : parseInt(tWidth)+10+"px";
}

function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // code for IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // code for IE6, IE5
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
            //document.getElementById("pnum").value="";
            //setFocus();
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var page=document.getElementById("pnum").value;
    var ch=document.getElementById("ch").value;
    var mode=document.getElementById("mode").value;
    qstr = 'page=' + escape(page) + '&ch=' + escape(ch) + '&mode=' + escape(mode) + '&';  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    document.getElementById("result").innerHTML = str;
}

function setFocus(){
  document.getElementById("pnum").focus();
}

function checkKeycode(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	//alert(keycode);
	
	if(keycode == 39){ //kovetkezo fooldal
	   getNext();
	}
	if(keycode == 37){ //elozo fooldal
	   getPrev();
	}
	if(keycode == 40){ //kovetkezo aloldal
	   getNextSub();
	}
	if(keycode == 38){ //elozo aloldal
	   getPrevSub()
	}
	if(keycode == 33){ //magazin fel
	   jumpMagUp();
	}
	if(keycode == 34){ //magazin le   
	   jumpMagDown();
	}   
}


function jump2link(num){
        document.getElementById("pnum").value=num;
        xmlhttpPost('main.php');
        //document.getElementById('pnum').value='';
	document.getElementById("pnum").value=num.substring(0,3);
        setFocus();
}

function getNext(){
	 //var next = document.frames[0].document.getElementById("next").value; NEM MUKODIK FIREFOXban
	 var next = window.frames[0].document.getElementById("next").value;
	 if (next!=""){
	     document.getElementById("pnum").value=next.substring(0,3);
	     xmlhttpPost('main.php');
	     //document.getElementById('pnum').value='';
	     setFocus();
	 }
}

function getPrev(){
	 var prev = window.frames[0].document.getElementById("prev").value;
	 if (prev!=""){
	     document.getElementById("pnum").value=prev.substring(0,3);
	     xmlhttpPost('main.php');
	     //document.getElementById('pnum').value='';
	     setFocus();
	}     
}

function getNextSub(){
         var nextS = window.frames[0].document.getElementById("nextSub").value;
	 //alert(nextS);
         if (nextS!=""){ 
   	     document.getElementById("pnum").value=nextS;
   	     xmlhttpPost('main.php');
   	     //document.getElementById('pnum').value='';
	     document.getElementById("pnum").value=nextS.substring(0,3);
   	     setFocus();      
   	 }    
}

function getPrevSub(){
         var prevS = window.frames[0].document.getElementById("prevSub").value;
	 //alert(prevS);
         if (prevS!=""){ 
   	     document.getElementById("pnum").value=prevS;
   	     xmlhttpPost('main.php');
   	     //document.getElementById('pnum').value='';
	     document.getElementById("pnum").value=prevS.substring(0,3);
  	     setFocus();
  	 }      

}

function lightMode(obj){
         var path=document.getElementById(obj).src;

	 var endOfpath = path.substring((path.length-17),path.length);
	 var endOfpath2 = path.substring((path.length-17),path.length);
	 
//	 if (obj=='text' && path=='http://www.teletext.hu/images/text_inactive.gif'){
	 if (obj=='text' && endOfpath=='text_inactive.gif'){
	     document.getElementById(obj).src='./images/text_light.gif';
	 }
//	 if (obj=='graf' && path=='http://www.teletext.hu/images/graf_inactive.gif'){
	 if (obj=='graf' && endOfpath2=='graf_inactive.gif'){
	      document.getElementById(obj).src='./images/graf_light.gif';
	 }     
}

function darkMode(obj){
         var path=document.getElementById(obj).src;

	 var endOfpath = path.substring((path.length-14),path.length);
	 var endOfpath2 = path.substring((path.length-14),path.length);

	 if (obj=='text' && endOfpath=='text_light.gif'){
	     document.getElementById(obj).src='./images/text_inactive.gif';
	 }
	 if (obj=='graf' && endOfpath2=='graf_light.gif'){
	      document.getElementById(obj).src='./images/graf_inactive.gif';
	 }     
}

function changeMode(obj){
//	 alert(obj);
	 if (obj=='text'){
	     document.getElementById(obj).src='./images/text_active.gif';
	     document.getElementById('graf').src='./images/graf_inactive.gif';
	     //document.getElementById('ch').value='1';
//	     change2TextMode();
	     document.getElementById('mode').value='text';
//	     setFocus();
	 }
	 if (obj=='graf'){
	      document.getElementById(obj).src='./images/graf_active.gif';
	      document.getElementById('text').src='./images/text_inactive.gif';
	      //document.getElementById('ch').value='2';
//              change2GraphMode();
	      document.getElementById('mode').value='graph';
//	      setFocus();
	 }
	xmlhttpPost('main.php');
}


function lightCh(obj){
         var path=document.getElementById(obj).src;

	 var csat = path.substring((path.length-6),path.length);
 
	 if (obj=='m1' && csat!='m1.jpg'){
	     document.getElementById(obj).src='./images/m1_over.gif';
	 }
	 if (obj=='m2' && csat!='m2.jpg'){
	      document.getElementById(obj).src='./images/m2_over.gif';
	 }     
}

function darkCh(obj){
         var path=document.getElementById(obj).src;

	 var csat = path.substring((path.length-6),path.length);

	 if (obj=='m1' && csat!='m1.jpg'){
	     document.getElementById(obj).src='./images/m1_black.jpg';
	 }
	 if (obj=='m2' && csat!='m2.jpg'){
	      document.getElementById(obj).src='./images/m2_black.jpg';
	 }     
}

function changech(obj){
	 if (obj=='m1'){
	     document.getElementById(obj).src='./images/m1.jpg';
	     document.getElementById('m2').src='./images/m2_black.jpg';
	     document.getElementById('ch').value='1';
	     xmlhttpPost('main.php');
	     setFocus();
	 }
	 if (obj=='m2'){
	      document.getElementById(obj).src='./images/m2.jpg';
	      document.getElementById('m1').src='./images/m1_black.jpg';
	      document.getElementById('ch').value='2';
	      xmlhttpPost('main.php');
	      setFocus();
	 }
}

function lightArrow(obj){
	 if (obj=='elozo'){
	     document.getElementById(obj).src='./images/arrow_left_light.gif';
	 }
	 if (obj=='kovetkezo'){
	      document.getElementById(obj).src='./images/arrow_right_light.gif';
	 }     
}

function darkArrow(obj){
	 if (obj=='elozo'){
	     document.getElementById(obj).src='./images/arrow_left.gif';
	 }
	 if (obj=='kovetkezo'){
	      document.getElementById(obj).src='./images/arrow_right.gif';
	 }     
}

function lightSubArrow(obj){
	 if (obj=='elozoSub'){
	     document.getElementById(obj).src='./images/arrow_leftsub_light.gif';
	 }
	 if (obj=='kovetkezoSub'){
	      document.getElementById(obj).src='./images/arrow_rightsub_light.gif';
	 }     
}

function darkSubArrow(obj){
	 if (obj=='elozoSub'){
	     document.getElementById(obj).src='./images/arrow_leftsub.gif';
	 }
	 if (obj=='kovetkezoSub'){
	      document.getElementById(obj).src='./images/arrow_rightsub.gif';
	 }     
}


function preLoader(){
	document.getElementById("pnum").value='100';
	var1 = new Image();
	var1.src = "./images/m1.jpg";
	var2 = new Image();
	var2.src = "./images/m2.jpg";
	var3 = new Image();
	var3.src = "./images/m1_over.gif";
	var4 = new Image();
	var4.src = "./images/m2_over.gif";
	var5 = new Image();
	var5.src = "./images/m1_black.jpg";
	var6 = new Image();
	var6.src = "./images/m2_black.jpg";	
	var7 = new Image();
	var7.src = "./images/arrow_left.gif";
	var8 = new Image();
	var8.src = "./images/arrow_right.gif";
	var9 = new Image();
	var9.src = "./images/arrow_left_light.gif";
	var10 = new Image();
	var10.src = "./images/arrow_right_light.gif";
	var11 = new Image();
	var11.src = "./images/arrow_leftsub.gif";
	var12 = new Image();
	var12.src = "./images/arrow_leftsub_light.gif";
	var13 = new Image();
	var13.src = "./images/arrow_rightsub.gif";
	var14 = new Image();
	var14.src = "./images/arrow_rightsub_light.gif";
	var15 = new Image();
	var15.src = "./images/graf_active.gif";
	var16 = new Image();
	var16.src = "./images/graf_inactive.gif";
	var17 = new Image();
	var17.src = "./images/text_active.gif";
	var18 = new Image();
	var18.src = "./images/text_inactive.gif";
	var19 = new Image();
	var19.src = "./images/text_light.gif";
	var20 = new Image();
	var20.src = "./images/graf_light.gif";
}

function openAllSub(){
	 //alert('openAllSub');
	 var screenH = screen.height;
	 var screenW = screen.width;
	 var actPage=document.getElementById("pnum").value;
//	 var actPage = window.frames[0].document.getElementById("next").value;
	 var ch=document.getElementById("ch").value;
	 var mode=document.getElementById("mode").value;
	 if (actPage=="") actPage=100;
	 mywindow = window.open("aloldalak.php?ch="+ch+"&actPage="+actPage+"&mode="+mode+"&","_blank","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width="+screenW+",height="+screenH+"");
	 mywindow.moveTo(0,0);
}

function jumpMagUp(){
	 var page=document.getElementById("pnum").value;
	 var actMag=page.substring(0,1);
	 //alert(actMag);
	 if (actMag!='8'){
	     actMag++;
	     actMag=actMag*100;
	     //alert(actMag);
	     document.getElementById("pnum").value=actMag;
	     xmlhttpPost('main.php');
	     setFocus();
	 }
}

function jumpMagDown(){
	 var page=document.getElementById("pnum").value;
	 var actMag=page.substring(0,1);
	 //alert(actMag);
	 if (actMag!='1'){
	     actMag--;
	     actMag=actMag*100;
	     //alert(actMag);
	     document.getElementById("pnum").value=actMag;
	     xmlhttpPost('main.php');
	     setFocus();
	 }
}

function info(){
	 var screenH = screen.height;
//	 screenH = screenH/2;
	 mywindow = window.open("info.html","_blank","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=830,height="+screenH+"");
	 mywindow.moveTo(0,0);
}	

function start(){
         xmlhttpPost('main.php');
	 getTicker();
	 preLoader();
}

function getPage(num){
	 document.getElementById('pnum').value=num;
	 xmlhttpPost('main.php');
         setFocus();
}

function change2TextMode(){
         document.getElementById('mode').value='text';
}

function change2GraphMode(){
         document.getElementById('mode').value='graph';
}

function vote(){
	 var screenH = screen.height;
	 var screenW = screen.width;
	 mywindow = window.open("./vote/index.php","_blank","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width="+screenW+",height="+screenH+"");
	 mywindow.moveTo(0,0);
}

