var ie=document.all
var ns6=document.getElementById&&!document.all
var n=document.layers
var currdate = "";

if (ie||ns6)    {fShow="visible";fHide="hidden";}
if (n) {fShow="show"; fHide="hide";}

var MonthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var nCurrentYear = 0;
var nCurrentMonth = 0;

var nWidth  = 20;
var nHeight = 20;

var leftX;
var rightX
var topY;
var bottomY;


function Calendar()
{

var HTMLstr = "";

HTMLstr += "<table width='80%' height='15px' bgcolor='#4682B4' cellspacing='0' cellpadding='0' border='1' bordercolor='#000000'>\n";
HTMLstr += "<tr><td bgcolor='#4682B4'>\n";
HTMLstr += "\n";
HTMLstr += "<table border='0' cols='0' width='100%' height='15px'>\n";
HTMLstr += "<tr>\n";
//HTMLstr += "<td><b> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'>Year:</font></b></td>\n";
HTMLstr += "\n";
if (n)
{
	//HTMLstr += "<td align='center' width='50%'>\n";
	//HTMLstr += "<a href=\"javascript:prevYear();\"><font color='white' size=-2> <img src= prev.gif border='0'> </font></a>\n";
	//HTMLstr += "<a href=\"javascript:nextYear();\"><font color='white' size=-2> <img src= next.gif border='0'> </font></a>\n";
}
if (ie||ns6)
{
	//HTMLstr += "<td align='center' width='50%'>\n";
//HTMLstr += "<a href=\"javascript:prevYear();\" style='text-decoration: none;'><font color='white' size=-2> <img src= prev.gif border='0'> </font></a>\n";
//HTMLstr += "<a href=\"javascript:nextYear();\" style='text-decoration: none;'><font color='white' size=-2> <img src= next.gif border='0'> </font></a>\n";
}
//HTMLstr += "</td>\n";
//HTMLstr += "\n";
/*HTMLstr += "<td align='left'>";

if (n) HTMLstr += "<ilayer id='main'><layer id='idYear' top='0' left='0'>\n";
if (ie||ns6)HTMLstr += "<div id='main' style='position: relative'>\n";
HTMLstr += "<font color='#99ffff'><b>1999</b></font>\n";
if (n) HTMLstr += "</layer></ilayer>\n";
if (ie||ns6)HTMLstr += "</div>\n";
HTMLstr += "</td>\n";
*/
HTMLstr += "</tr>\n";
HTMLstr += "<tr align= 'center' width='50%'>\n";
//HTMLstr += "<td><b> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> Month:</font></b></td>\n";
HTMLstr += "\n";
HTMLstr += "<td align='left'>\n";
if (n)
{
	HTMLstr += "<a href=\"javascript:prevMonth();\"> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <img src= prev.gif border='0'> </font></a>\n";
	HTMLstr += "<a href=\"javascript:nextMonth();\"> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <img src= next.gif border='0'> </font></a>\n";
}
if (ie||ns6)
{
	
	HTMLstr += "<a href=\"javascript:prevMonth();\" style='text-decoration: none;'> <img src= prev.gif border='0'> </a> </td>\n";
//HTMLstr += "<a href=\"javascript:nextMonth();\" style='text-decoration: none;'> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <img src= next.gif border='0'> </font></a>\n";
}
//HTMLstr += "</td>\n";
//HTMLstr += "\n";
HTMLstr += "<td align='right'>\n";
if (n) HTMLstr += "<ilayer id='main2'><layer id='idMonth' top='0' left='0'>\n";
if (ie||ns6)HTMLstr += "<div id='main2'  style='position: relative'>\n";
HTMLstr += "<font color='#4682B4' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'><b>December</b></font>\n";
if (ie||ns6)HTMLstr += "<div>\n";
if (n) HTMLstr += "</layer></ilayer>\n";
HTMLstr += "</td>\n";
HTMLstr += "\n";
//
//HTMLstr += "</td>\n";
//HTMLstr += "\n";
HTMLstr += "<td  align='left'>\n";
if (n) HTMLstr += "<ilayer id='main'><layer id='idYear' top='0' left='0'>\n";
if (ie||ns6)HTMLstr += "<div id='main' style='position: relative'>\n";
HTMLstr += "<font color='#4682B4' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'><b>1999</b></font>\n";
if (n) HTMLstr += "</layer></ilayer>\n";
if (ie||ns6)HTMLstr += "</div>\n";
HTMLstr += "</td>\n";
HTMLstr += "<td align='right'> <a href=\"javascript:nextMonth();\" style='text-decoration: none;'> <img src= next.gif border='0'> </td></a>\n";
//
HTMLstr += "</tr>\n";
HTMLstr += "</table>\n";
HTMLstr += "\n";
HTMLstr += "</td></tr>\n";
HTMLstr += "\n";
HTMLstr += "<tr height='160px'><td valign=\"top\">\n";
HTMLstr += "\n";
HTMLstr += "<table bgColor='#87cefa' width='100%' height='0%' border=0 cols='7'>\n";
HTMLstr += "<tr>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Mon </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Tue </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Wed </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Thu </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Fri </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Sat </b> </font> </td>\n";
HTMLstr += "<td  width='20'> <font color='#000066' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b> Sun </b> </font> </td>\n";
HTMLstr += "</tr>\n";
HTMLstr += "<tr>\n";
HTMLstr += "<td colspan=7 >\n";
if (ie||ns6)HTMLstr += "<div style='position: relative;'>";
if (n) HTMLstr += "<ilayer id='idMenuContainer' height='100px' width='50%'>\n";
currdate = new Date().getDate();

for (var date=1; date <= 31; date++)
{
	if (n)
	{
		HTMLstr += "  <layer id=\"idDate"+date+"\" val="+date+" visibility=\"hide\">\n";
		HTMLstr += "    <layer><font bgcolor='#4682B4' style='font-size:7pt'> "+date+"</font> </layer>\n";
		HTMLstr += "  </layer>\n";
	}
	if (ie||ns6)
	{
		
		if(date == currdate)
		{
			HTMLstr += "  <div id=\"idDate"+date+"\" val="+date+" style=\"position: absolute; visibility: hidden;\">\n";
			HTMLstr += "  <A href='javascript:openpopup()'> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'><b>"+date+"</b></A></font>\n";
			HTMLstr += "  </div>\n";
		}
		else
		{

			HTMLstr += "  <div id=\"idDate"+date+"\" val="+date+" style=\"position: absolute; visibility: hidden\">\n";
			// HTMLstr += "    <b>"+date+"</b>\n";
			HTMLstr += " <A href='javascript:openpopup1()'> <font color='#000000' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'>"+date+"</A></font>\n";
			HTMLstr += "  </div>\n";
		}
	}
  }

if (ie||ns6)HTMLstr += "</div>";
if (n) HTMLstr += "</ilayer>\n";
HTMLstr += "</td></tr>\n";
HTMLstr += "</table>\n";
HTMLstr += "\n";
HTMLstr += "</td></tr>\n";
HTMLstr += "</table>\n";
document.writeln(HTMLstr);
buildMonthMenu(HTMLstr);
}

function setCurrentMonth()
{
  date = new Date();
  currentyear=date.getYear()
  if (currentyear < 1000)
  currentyear+=1900
  setYearMonth(currentyear, date.getMonth()+1);
}

function setMonth(nMonth)
{
	setYearMonth(nCurrentYear, nMonth);
}

function setYearMonth(nYear, nMonth)
{
  if (ie||ns6)
{
  nCurrentYear = nYear;
  nCurrentMonth = nMonth;
  var cross_obj=ns6? document.getElementById("main"): document.all["main"]
  var cross_obj2=ns6? document.getElementById("main2"): document.all["main2"]
  cross_obj.innerHTML  = "<font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif' ><b>"+nCurrentYear+"</b></font>";
  cross_obj2.innerHTML = "<a href=\"javascript:showMonthMenu()\" style=\"text-decoration:none\"> <font color='#FFFFFF' font style='font-size:7pt' face='Verdana, Arial, Helvetica, sans-serif'> <b>"+MonthNames[nCurrentMonth-1]+"</b></font></a>\n";

  var date   = new Date(nCurrentYear, nCurrentMonth-1, 1);
  var nWeek  = 1;
  var nDate;
 
  currdate = new Date().getDate();

  while (date.getMonth() == nCurrentMonth-1)
  {
	nDate = date.getDate();
	nLastDate = nDate;
	var posDay = date.getDay()-1;
	if (posDay == -1) posDay=6;
	var posLeft = posDay*(nWidth+5)+5;
	var posTop  = (nWeek-1)*nHeight;
        var cross_obj3=ns6? document.getElementById("idDate"+nDate).style : document.all["idDate"+nDate].style
	cross_obj3.left = posLeft;
	cross_obj3.top  = posTop;
	cross_obj3.color  = "black";
	cross_obj3.visibility = "visible";
	// original:
	// date = new Date(currentyear, date.getMonth(), date.getDate()+1);
	// johan:
	var currdate =  date.getDate()+1;
	date = new Date(nCurrentYear, date.getMonth(), date.getDate()+1);
	
	if (posDay == 6) nWeek++;
  }
  for (++nDate; nDate <= 31; nDate++){
        cross_obj3=ns6? document.getElementById("idDate"+nDate).style : document.all["idDate"+nDate].style
	cross_obj3.visibility = "hidden";
      }
}
  if (n)
{
  // Verify parameters
  if (nMonth < 1 || nMonth > 12) {alert("Function: setYearMonth()\nERROR: Incorrect month "+nMomth);}

  nCurrentYear = nYear;
  nCurrentMonth = nMonth;

  document.main.document.idYear.document.open();
  document.main.document.idYear.document.write("<font color=\"#99ffff\"><b>"+nCurrentYear+"</b></font>");
  document.main.document.idYear.document.close();

  document.main2.document.idMonth.document.open();
  document.main2.document.idMonth.document.write("<a href=\"javascript:showMonthMenu()\" style=\"text-decoration:none\"><font color=\"#99ffff\"><b>"+MonthNames[nCurrentMonth-1]+"</b></font></a>");
  document.main2.document.idMonth.document.close();

  var date   = new Date(nYear, nMonth-1, 1);
  var nWeek  = 1;
  var nDate;

  while (date.getMonth() == nMonth-1)
  {
	nDate = date.getDate();
	nLastDate = nDate;

	var posDay = date.getDay()-1;
	if (posDay == -1) posDay=6;
	var posLeft = posDay*(nWidth+5)+5;
	var posTop  = (nWeek-1)*nHeight;

	document.layers["idMenuContainer"].document.layers["idDate"+nDate].left = posLeft;
	document.layers["idMenuContainer"].document.layers["idDate"+nDate].top  = posTop;
	if (date.getDay() == 0 || date.getDay() == 6)
		document.layers["idMenuContainer"].document.layers["idDate"+nDate].color  = "red";
	else
		document.layers["idMenuContainer"].document.layers["idDate"+nDate].color  = "black";
	document.layers["idMenuContainer"].document.layers["idDate"+nDate].visibility = "visible";
	date = new Date(nCurrentYear, date.getMonth(), date.getDate()+1);
	if (posDay == 6) nWeek++;
  }
  for (++nDate; nDate <= 31; nDate++)
	document.layers["idMenuContainer"].document.layers["idDate"+nDate].visibility = "hidden";
}
}

function nextMonth()
{
  nCurrentMonth++;
  if (nCurrentMonth > 12)
  {
	nCurrentMonth -= 12;
	nextYear();
  }
  
  setYearMonth(nCurrentYear, nCurrentMonth);
}


function prevMonth()
{
  nCurrentMonth--;
  if (nCurrentMonth <1)
  {
	nCurrentMonth += 12;
	prevYear();
  }
  setYearMonth(nCurrentYear, nCurrentMonth);

}

function prevYear()
{
  nCurrentYear--;
  setYearMonth(nCurrentYear, nCurrentMonth);
}

function nextYear()
{
  nCurrentYear++;
  setYearMonth(nCurrentYear, nCurrentMonth);
}

////////////////////////////////////////////////////

function updateIt(e)
{
//  var x = e.pageX;
//  var y = e.pageY;

//  if (x > rightX || x < leftX) hideMonthMenu();
//  else if (y > bottomY || y < topY) hideMonthMenu();
}

function hideMonthMenu()
{
  document.layers["idMonthMenu"].visibility="hide";
}

function showMonthMenu()
{
if (!n) return;
  topY    = document.layers["main2"].pageY-50;
  bottomY = document.layers["main2"].pageY + document.layers["idMonthMenu"].clip.height+50;
  leftX   = document.layers["main2"].pageX-50;
  rightX  = document.layers["main2"].pageX + document.layers["idMonthMenu"].clip.width+50;

  document.layers["idMonthMenu"].top = document.layers["main2"].pageY+document.layers["main2"].clip.height;
  document.layers["idMonthMenu"].left = document.layers["main2"].pageX;
  document.layers["idMonthMenu"].visibility="show";
}

function buildMonthMenu()
{
if (!n) return;
  var HTML = "";
  HTML += "<layer id=\"idMonthMenu\" visibility=\"hide\" width=\"120\" bgcolor=\"darkblue\">\n";
  HTML += "<table border=\"1\" cellspacing=\"0\" cellpading=\"0\">\n";
  for (var month=0; month<12;)
  {
	HTML += "<tr>\n";
	for (var i = 0; i < 3; i++)
	{
		var nMonth = month+1;
		HTML += "<td><a href=\"javascript:hideMonthMenu();setMonth("+nMonth+");\"><font color=\"white\" size=-1><b>"+MonthNames[month]+"</b></font></a></td>\n";
		month++;
	}
	HTML += "</tr>\n";
  }
  HTML += "</table>";
  HTML += "</layer>";
  document.writeln(HTML);
}

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts

function openpopup(){
var popurl="country.htm"
winpops=window.open(popurl,"","width=438,height=200,top=250,left=250")
}
function openpopup1(){
var popurl="country1.htm"
winpops=window.open(popurl,"","width=438,height=200,top=250,left=250")
}
