// JavaScript Document

var mainwindow=window.document;
var count_window;

function count_popup(form_item, count)
{
count_window = window.open('', null, 'width=199,height=38,toolbar=no;');
var body=count_window.document;

//body.innerHTML
body.write('<html><head><![if lt IE 7]><![if gte IE 5.5]><script type="text/javascript"> var blank_gif = "/images/new/spacer.gif"; </script><script type="text/javascript" src="/js/fixpng.js"></script><style type="text/css">img, .png{filter:expression(fixPNG(this));}</style><![endif]><![endif]></head><body><table style="width:199;height:38;background:url('+"'../../../../images/new/item_bg-mini.gif'"+') no-repeat 50%;"><tr><td colspan="2" align="center" valign="middle"><input type="text" id="id_count_item" name="count_item" size="3" value="1" /></td></tr><tr><td class="png" style="width:50%;cursor:pointer;padding-left:35px;padding-top:5px;padding-bottom:5px;background:url(../../../../images/new/btn-login.png) no-repeat 50%;" onmouseover="javascript:this.style.background='+"'url(../../../../images/new/btn-login2.png) no-repeat 50%'"+'" onmouseout="javascript:this.style.background='+"'url(../../../../images/new/btn-login.png) no-repeat 50%'"+'" onClick="window.opener.parent.document.'+form_item+'.count.value=document.getElementById('+"'id_count_item'"+').value;window.opener.parent.document.'+form_item+'.submit();window.close();"><span style="font:11px arial;color:#fff;font-weight:bold;">OK</span></td><td class="png" style="cursor:pointer;padding-left:25px;padding-top:5px;padding-bottom:5px;background:url(../../../../images/new/btn-login.png) no-repeat 50%;" onmouseover="javascript:this.style.background='+"'url(../../../../images/new/btn-login2.png) no-repeat 50%'"+'" onmouseout="javascript:this.style.background='+"'url(../../../../images/new/btn-login.png) no-repeat 50%'"+'" onClick="window.opener.parent.document.'+form_item+'.count.value='+"'0'"+';window.opener.parent.document.'+form_item+'.submit();window.close();"><span style="font:11px arial;color:#fff;font-weight:bold;">Cancel</span></td></tr></table></body></html>');
count_window.focus();
//mainwindow.body.Onfocus="return false";
}

function getCode(n_day,n_month,n_year)
{

	var count=0;
	var cur=false;
	var path="";
	for(var i=0;i<arch_dates.length;i++){
		//alert (arch_dates[i]+"=="+(n_year+"-"+n_month+"-"+n_day)+" - "+(arch_dates[i] == (n_year+"-"+n_month+"-"+n_day)))
		if(arch_dates[i] == (n_year+"-"+n_month+"-"+n_day)){
			count++;
			path='/'+lang+'/news.html?day='+n_day+'&month='+n_month+'&year='+n_year;
			if(news_cur==arch_dates[i])
				cur=true;
		}
	}

	if(count==1)
		return "<b>"+n_day+"</b></a>";
		//return "<a "+(cur?" ":"href='"+path+"'")+">"+n_day+"</a>";
	else if(count>1)
		return "<b>"+n_day+"</b></a>";
		//return "<a "+(cur?" ":"")+" href='news.html?datey="+n_year+"&datem="+n_month+"&dated="+n_day+"'>"+n_day+"</a>";
	return n_day;
}



function leapYear(year) 
{
	if (year % 4 == 0) 
		return true 
	return false
}
function getDays(fmonthf, fyearf){
	var ar = new Array(12);
		ar[0] = "31";
		ar[1] = (leapYear(fyearf))?"29":"28";
		ar[2] = "31";
		ar[3] = "30";
		ar[4] = "31";
		ar[5] = "30";
		ar[6] = "31";
		ar[7] = "31";
		ar[8] = "30";
		ar[9] = "31";
		ar[10] = "30";
		ar[11] = "31";
	return ar[fmonthf];
}
function calendar(){
	var days=1;
	var background="#e2f1fd";
	
	date.setFullYear(year,month,days);
	var cal="<table class='calendar'  cellspacing='0' cellpadding='0'><tbody>";
	var day = date.getDay()==0?6:date.getDay()-1;
	days=getDays(month,year);
	var tmpD=1;
	for(var i=0;i<7;i++)
	{
		cal+="<tr "+(i==0?" class='caHeader'":"")+">";
		for(var j=0;j<7;j++)
		{
			if(i!=0)
			{
				if(1==i && day>j)
					cal+="<td></td>";
				else{
				if(tmpD==nowDate&&(month-1)==nowMonth&&year==nowYear)
				{background="#0683C7";}
				else background="#FFFFFF";
					cal+='<td><a href="/'+lang+'/news.html?day='+tmpD+'&month='+(month+1)+'&year='+year+'" style="text-decoration: none; color:#3950aa; font-weight: normal; background:'+background+'" onmouseout="javascript:this.style.background='+"'"+background+"'"+'" onmouseover="javascript:this.style.background='+"'#0683C7'"+'">'+getCode(tmpD,month+1,year)+'</a></td>';
					tmpD++;
					if(tmpD>days)
						break;
				}
			}
			else
				cal+="<td>"+getweekDay(j)+"</td>";
		}	
		cal+="</tr>";
		if(tmpD>days)
			break;
	}
	return cal+"</table>";
}

/**
  * Выбор года и месяца
  *
  */
function OnChange(move)
{
	if(1==move){
		month--;
		if(month<0){
			year--;
			month=11;
		}
	}
	if(2==move){
		month++;
		if(month>11){
			year++;
			month=0;
		}
	}
	document.getElementById('id_year').innerHTML = year;
	document.getElementById('id_month').innerHTML = getMonthName(month);
	document.getElementById('id_calendar_tb').innerHTML = calendar();
}


