function dialog(url, _width, _height) {
	if (IE) window.event.cancelBubble = true; //Kad neeitu i ta linka kuri paspaudeme
	if (IE) window.event.returnValue = false; //paspaudej - ir nieko negrazino tau!!!
	var pav;
	nr_temp=Math.floor(Math.random()*1000);
	if (arguments[3]) pav=arguments[3];
		else pav=nr_temp;
	if (arguments[4]) scrollbar="yes";
		else scrollbar="no";
	window.open(url, pav, "top=100, left=100, width="+_width+", height="+_height+", menubar=no, resizeable=yes, scrollbars="+scrollbar+", staus=1, toolbar=no, location=no, directories=no");
}

function zoomas(url, w, h) {
	window.open("http://www.manopasaulis.eu/scripts/dialog.php?file="+url, "Picture", "top=200, left=200, width="+w+", height="+h+", menubar=no, resizeable=yes, scrollbars=no, staus=1, toolbar=no, location=no, directories=no");
}

function change_main_image(url) {
	document.images['main_image'].src=url;
}



function strpad(val)
{
  return (!isNaN(val) && val.toString().length==1) ? "0"+val : val;
}

function generateCalendar( lang, none )
{
  var f = document.calendar_form;
	if (!none)
	{
	  eval ( "var selected_month = f.m.options[f.m.selectedIndex].value;");
	  eval ( "var selected_year = f.y.options[f.y.selectedIndex].value;");
		var js_month = selected_month - 1;
	}
	else 
	{
	  var today = new Date();
	  var selected_month = today.getMonth() + 1;
		selected_month = strpad(selected_month);
		var js_month = selected_month - 1;
		var selected_year = today.getFullYear();
	}
	var thistime = new Date();
	var thisyear = thistime.getFullYear();
	var thismonth =thistime.getMonth() + 1;
	var js_thismonth = thismonth - 1;
	thismonth = strpad(thismonth);
	var thisday = thistime.getDate();
	var years = new Array( thisyear, thisyear+1 );
	
	var calendar = "<table width=\"160\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"27\"><table width=\"160\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
	calendar += "<td width=\"50\"><select name=\"y\" onchange=\"generateCalendar('"+lang+"', 0)\">";
	for ( var i =0; i<years.length; i++ )
	{
	  calendar += "<option value=\""+years[i]+"\" ";;
	  if (years[i] == selected_year) calendar += "selected";
		calendar += ">"+years[i]+"</option>";
	}
	calendar += "</select></td>";
	
	var months_lt = new Array( "Sausis", "Vasaris", "Kovas", "Balandis", "Gegužė", "Birželis", "Liepa", "Rugpjūtis", "Rugsėjis", "Spalis", "Lapkritis", "Gruodis" );
	var months_en = new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );
  eval(	"var this_months = months_"+lang+";");
	
	calendar += "<td width=\"70\" align=\"right\"><select name=\"m\" onchange=\"generateCalendar('"+lang+"', 0)\">";
	for ( var j=0; j<this_months.length; j++)
	{
	  calendar += "<option value=\"";
		op_val = strpad(j+1);
		calendar += op_val+"\"";
		if (selected_month == op_val) calendar += " selected ";
		calendar += ">"+this_months[j]+"</option>"
	}
	calendar += "</select></td>";
	
	var week_days_lt = new Array( "P", "A", "T", "K", "P", "Š", "S" );
	var week_days_en = new Array( "M", "T", "W", "T", "F", "S", "S" );
  eval(	"var this_week = week_days_"+lang+";");
	
	calendar += "</tr></table></td></tr><tr><td><table width=\"160\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\"><tr>";
	
  var thetime_ = new Date( selected_year, js_month );
	var nexttime = thetime_.getTime() + (60 * 60 * 24 * 32 * 1000);
	
	var next_ = new Date( nexttime );
	var next_year = next_.getFullYear();
	var next_month = next_.getMonth();
	var nexttime_ = new Date( next_year, next_month );
	
	var weekday_ = thetime_.getDay();
	//pirmoji savaites diena menesyje
	if (weekday_ == 0) weekday_ = 7; 

	var days_num = (nexttime_ - thetime_) / 24 / 60 / 60 / 1000;
	days_num = Math.round(days_num);
	
	calendar += "<tr bgcolor=\"#d9d3aa\">";
	for ( var i =0; i<this_week.length; i++ )
	{
	  calendar += "	<td width=\"14%\" align=\"center\" valign=\"middle\" height=\"16\"><strong>"+this_week[i]+"</strong></td>";
	}
	calendar += "</tr>";
	
  if (weekday_ > 1)
  {
    var colspan = weekday_ - 1;
    calendar += "<td colspan=\""+colspan+"\"></td>";
  }

	for ( var i = 1; i <= days_num; i++ )
	{
	  if ( weekday_ == 8 )
		{
		  calendar += "</tr><tr>";
			weekday_ = 1;
		}
		calendar += "<td style=\"background: #eeead1; color: #d8d1a4; \" width=\"20\" align=\"center\"";
		if (selected_year == thisyear && js_month == js_thismonth && i == thisday)
		  calendar += "bgcolor=#FF0000";
		calendar += " >";
		if (selected_year > thisyear || (selected_year == thisyear && (js_month > js_thismonth) || (js_month == js_thismonth && i >= thisday)))
		{
		  var curDate = new Date( selected_year, js_month, i );
		  ii = i;
		  if (i < 10) ii = "0"+i;
		  link = selected_year+"-"+selected_month+"-"+ii;
		  calendar += "<a href=\"http://www.eb.lt/lt.php3?vid=75&date_from="+link+"&date_to="+link+"\">";
		}
		if (selected_year == thisyear && js_month == js_thismonth && i == thisday)
		  calendar += "<span style=\"font-weight: bold; color: red\">";
		calendar +=i;
		if (selected_year == thisyear && js_month == js_thismonth && i == thisday)
		  calendar += "</span>";
		if (selected_year > thisyear || (selected_year == thisyear && (js_month > js_thismonth) || (js_month == js_thismonth && i >= thisday)))
		  calendar += "</a>";
		calendar += "</td>";
		weekday_++;
	}
	
	if ( weekday_ < 7 )
	{
	  colspan = 7 - weekday_;
		calendar += "<td colspan=\""+colspan+"\"></td>";
	}

	calendar += "</tr></table>";  
  document.getElementById('calendar').innerHTML = calendar ;		
}

