var timerMulti = window.setInterval("runMultiple();", 500); 


var pinpong;


var posX = 0;
var movetimeout = 12;
var rottime = null;
var step = 5;
var wl = null;
var wp = null;
var stop = false;

function archive_sort(year){
  fobj=document.getElementById('archive_sort');
  fobj.innerHTML='<table><tr><td>Выбрать новости в '+year+' году:</td><td><a href="?year='+year+'">за все месяцы</a>  <a href="?month=1&year='+year+'">за январь</a>  <a href="?month=2&year='+year+'">за февраль</a>  <a href="?month=3&year='+year+'">за март</a>  <a href="?month=4&year='+year+'">за апрель</a>  <a href="?month=5&year='+year+'">за май</a></td></tr><tr><td></td><td><a href="?month=6&year='+year+'">за июнь</a>  <a href="?month=7&year='+year+'">за июль</a>  <a href="?month=8&year='+year+'">за август</a>  <a href="?month=9&year='+year+'">за сентябрь</a>  <a href="?month=10&year='+year+'">за октябрь</a>  <a href="?month=11&year='+year+'">за ноябрь</a>  <a href="?month=12&year='+year+'">за декабрь</a></td></tr></table>';
  
  return false;
}

function runMultiple(){
  var timedot;

  if (pinpong!=1) {
    timedot=":";
    pinpong=1;    
  } else { timedot="&nbsp;"; pinpong=0; }
  
  var now_date = new Date();
  
  var hours = now_date.getHours();
  if (hours<10) { hours='0'+hours; }
  var minutes = now_date.getMinutes();
  if (minutes<10) { minutes='0'+minutes; }
  var month = new Array(13);
month[0] = "января";
month[1] = "февраля";
month[2] = "марта";
month[3] = "апреля";
month[4] = "мая";
month[5] = "июня";
month[6] = "июля";
month[7] = "августа";
month[8] = "сентября";
month[9] = "октября";
month[10] = "ноября";
month[11] = "декабря";

var day= now_date.getDate();

// if (day<10) { day='0'+day; }

var cmonth=now_date.getMonth();
var cyear=now_date.getFullYear();

var fobj=document.getElementById('timeline');
fobj.innerHTML='Сегодня '+day+' '+month[cmonth]+' '+cyear+' года '+hours+timedot+minutes;


}

function moveready() {
	wp = document.getElementById('workplace');
	wl = document.getElementById('workline');

  if(wp && wl) {
    posX = 0;
    wl.style.left = 0; 
    clearTimeout(movetimeout);

    var elems = wl.getElementsByTagName('div');
    var plcwidth = wp.clientWidth;
    var divwidth = 145; // elems[0].clientWidth;
    var numdiv = plcwidth/divwidth;
    var delta = numdiv-parseInt(numdiv);
    var newwidth = divwidth; 
    
    if(delta || divwidth == plcwidth){
      // newwidth = parseInt(plcwidth / (parseInt(numdiv))); 
  	newwidth=divwidth;
      wl.style.width = (newwidth+35)*elems.length+"px";
  
      for(var i = 0; i < elems.length; i++) {
        elems[i].style.width = newwidth + "px";
      }               
    }
  }
	return false;
}

function movestop() {
  stop = true;
  clearTimeout(movetimeout);

	return false;
}

function moveleft() {
  if(wp && wl && stop==false) {
		posX -= step;
				
    if((wl.clientWidth+posX+step) > wp.clientWidth) {
		  wl.style.left = posX + 'px';
      rottime = setTimeout('moveleft()', movetimeout);
	   } else {
      clearTimeout(movetimeout);
    }
  }
  if(stop==true) {
    stop = false;
  }
  
  return false;
}

function moveright() {
  if(wp && wl && stop==false) {
		posX += step;
			
  if(posX-step <= 0) {
      wl.style.left = posX + 'px';    
      rottime = setTimeout('moveright()', movetimeout);
	 } else {
    clearTimeout(movetimeout);
    }
	}
  
  if(stop==true) {
    stop = false;
  }
  
  return false;
}

var colors = ["#000000", ,"100F0E", "#252222", "#494444", "#585151", "#6B6464", "#8B8484", "#A7A4A3", "#BFBEBD", "#E6E6E6", "#F8F9F8", "#FFFFFF"];
var ii = 0;
var kk = colors.length - 1;
var bb = 1;
var maxbb = 21;
var timeslow = 150;

function hide(bname) {
  var b = document.getElementById(bname);

  if(b) {
    b.style.cssText = "color: " + colors[ii];
    b.style.display = "block";
    ++ii;
    if (ii <= kk) {
      setTimeout('hide("'+bname+'")', timeslow);
    }
    else {
       b.style.display = "none";
       ++bb;
       if(bb > maxbb) {
          bb = 1;
       }
       ii = 0;
       kk = colors.length - 1;

       setTimeout('show("b'+bb+'")', timeslow);
    }
  }
} 

function show(bname) {
  var b = document.getElementById(bname);

  if(b) {
    b.style.cssText = "color: " + colors[kk];
    b.style.display = "block";

    --kk;
    if (kk >= ii) {
      setTimeout('show("'+bname+'")', timeslow);
    }
    else {
        ii = 0;
        kk = colors.length - 1;
        
        setTimeout('hide("'+bname+'")', timeslow);
    }
  }
} 

function changetxt() {
  show("b1");
}

addLoadHandler(moveready);
addLoadHandler(changetxt);

function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
		    oldHandler();
		    handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}

function showmenu (){
return true;
}






function del_input(obj){

obj.value="";
}




function show_World(obj){
obj.className="tab_selected";
var obj2=document.getElementById('nrussia_link'); 
obj2.className="tab";
var obj3=document.getElementById('novosti_rus'); 
obj3.style.display="none"; 
var obj4=document.getElementById('novosti_mir'); 
obj4.style.display="inline"; 
return false;
}

function show_Russia(obj){
obj.className="tab_selected";
var obj2=document.getElementById('nworld_link'); 
obj2.className="tab";
var obj3=document.getElementById('novosti_rus'); 
obj3.style.display="inline"; 
var obj4=document.getElementById('novosti_mir'); 
obj4.style.display="none"; 
return false;
}

function getCurrSelection() {
	if(document.selection)
		return document.selection;
	else
		return window.getSelection();
}

function getRange(sel) {
	if(!sel)
		sel = getSelection();

	if(typeof sel != "undefined") {
		return sel.getRangeAt(0);
	} else {
		return window.document.createRange();
	}
}

function hasParent(obj, par_id) {
	if(!obj) {
		return false;
	}

	if(obj.id == par_id) {
//		alert(obj.id);
		return true;
	} else {
		if(obj.parentNode) {
			return hasParent(obj.parentNode, par_id);
		} else {
			return false;
		}
	}
}

function trim(str) {
	var res = str.replace(/^\s+/, '');
	return res.replace(/\s+$/, '');

}


function gen_popup(src, width, height, page_header) {
	if(!page_header)
		page_header = "";

	win = window.open("", "_blank", "width=" + (width) + ",height=" + (height) + ",titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");

	win.document.write("<html><head><title>" + page_header + "</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table style='height: 100%' cellspacing='0' cellpadding='0' border='0'><tr><td valgin='middle'>");
	win.document.write("<" + "script" + ">document.title = \"" + page_header + "\";\r\nfunction _CloseOnEsc(e) {if(e){ event = e;} if (event.keyCode == 27) { window.close(); return; }} document.onkeydown = _CloseOnEsc;<" + "/script>");
	win.document.write("<img src=\"" + src +  "\" onclick=\"javascript: window.close();\" style=\"cursor: pointer;\" />");
	win.document.write("</td></tr></table></body></html>");
	win.document.close();
	return false;
}

function getPageSizes(){
	
	var iScrollX, iScrollY;
	
	if (window.innerHeight && window.scrollMaxY) {
		iScrollX = document.body.scrollWidth;
		iScrollY = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		iScrollX = document.body.scrollWidth;
		iScrollY = document.body.scrollHeight;
	} else {
		iScrollX = document.body.offsetWidth;
		iScrollY = document.body.offsetHeight;
	}
	
	var iWinWidth, iWinHeight;
	if (self.innerHeight) {
		iWinWidth = self.innerWidth;
		iWinHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		iWinWidth = document.documentElement.clientWidth;
		iWinHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		iWinWidth = document.body.clientWidth;
		iWinHeight = document.body.clientHeight;
	}	
	
	if(iScrollY < iWinHeight){
		iPageHeight = iWinHeight;
	} else { 
		iPageHeight = iScrollY;
	}

	if(iScrollX < iWinWidth){	
		iPageWidth = iWinWidth;
	} else {
		iPageWidth = iScrollX;
	}

	var arrSizes = new Array(iPageWidth,iPageHeight,iWinWidth,iWinHeight) 
	return arrSizes;
}
