function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=640,height=600,scrollbars=yes');
return false;
}


function swapImages(img1,img2,img3)
{
 if (document.images)
 {
     button1 = new Image
     button2 = new Image
     button3 = new Image
     button1.src = img1
     button2.src = img2
     button3.src = img3

     document.write('<div align="center">')
     document.write('  <span onmouseover="document.rollover.src=button2.src" ')
     document.write('	 onmouseout="document.rollover.src=button1.src"')
     document.write('	onmousedown="document.rollover.src=button3.src"')
     document.write('	  onmouseup="document.rollover.src=button2.src">')
     document.write('	<img src="'+img1+'" border=0 name="rollover"></span>')
     document.write('</div>')
 }
}

function setemail(who,name,domain)
{
document.write("<a href=" + "mail" + "to:" + name + "@" + domain + ">" + who + "</a>");
}

function thisemail(name,who)
{
document.write("<a href=" + "mail" + "to:" + name + "@kleinforestband.org>" + who + "</a>");
}

function kisdemail(name,who)
{
document.write("<a href=" + "mailto:" + name + "@kleinisd.net?subject=KISD: >" + who + "</a>");
}

function montharray(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
   this[0] = m0;
   this[1] = m1;
   this[2] = m2;
   this[3] = m3;
   this[4] = m4;
   this[5] = m5;
   this[6] = m6;
   this[7] = m7;
   this[8] = m8;
   this[9] = m9;
   this[10] = m10;
   this[11] = m11;
}

function MakeArray(n) {this.length = n; return this;}
  var Days = new MakeArray(7);
  var Months = new MakeArray(12);
  Days[1]="Sunday"; Days[2]="Monday"; Days[3]="Tuesday";   Days[4]="Wednesday";
  Days[5]="Thursday"; Days[6]="Friday"; Days[7]="Saturday";
  Months[1]="January"; Months[2]="February"; Months[3]="March";   Months[4]="April"; 
  Months[5]="May"; Months[6]="June"; Months[7]="July";   Months[8]="August"; 
  Months[9]="September"; Months[10]="October"; Months[11]="November"; 
  Months[12]="December";

function getNiceDate(theDate)
 {
  return Months[theDate.getMonth()+1] + " &nbsp; " + theDate.getFullYear();
 }

function getNiceTimez()
 {
  var lastMod = new Date();
  var Hours;
  var Mins;
  var Time;
  Hours = lastMod.getHours();
  if (Hours >= 12)
   { Time = " P.M."; }
  else
   { Time = " A.M."; }
  if (Hours > 12)
   { Hours -= 12; }
  if (Hours == 0)
   { Hours = 12; }

  Mins = lastMod.getMinutes();
  if (Mins < 10)
    {  Mins = "0" + Mins; }

  document.write(Days[lastMod.getDay()+1] + ", " + Months[lastMod.getMonth()+1] +  
        " " + lastMod.getDate() + " " + lastMod.getFullYear() + 
        " &nbsp; "  + Hours + ":" + Mins + Time );
 }


function getNiceTime()
 {
  var lastMod = new Date();
  var Hours;
  var Mins;
  var Time;
  Hours = lastMod.getHours();
  if (Hours >= 12)
   { Time = " P.M."; }
  else
   { Time = " A.M."; }
  if (Hours > 12)
   { Hours -= 12; }
  if (Hours == 0)
   { Hours = 12; }

  Mins = lastMod.getMinutes();
  if (Mins < 10)
    {  Mins = "0" + Mins; }

  document.write(Days[lastMod.getDay()+1] + " " + Months[lastMod.getMonth()+1] +  
        ", " + lastMod.getDate() + " " + lastMod.getFullYear()  );
 }


function calendar()
{
   today = new Date();
   var thisDay;
   var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
   var monthNames2 = " 1 2 3 4 5 6 7 8 9101112";
   var monthDays = new montharray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   year = today.getFullYear();
   if(year<2000)year+=1900;
   thisDay = today.getDate();
   if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
      monthDays[1] = 29;
   nDays = monthDays[today.getMonth()];
   firstDay = today;
   firstDay.setDate(1);
   var lastMod = new Date();
   startDay = firstDay.getDay();
   document.write("<table class='mycalTitle' width='100%' border='0' bordercolor=silver cellspacing=0 cellpadding=1  BGCOLOR=\"#333333\">");
   document.write("<TR BGCOLOR=\"#660099\"><TH COLSPAN=7>");
   document.write(getNiceDate(lastMod));
   document.write("<TR BGCOLOR=\"#006600\"><TH width=14%>Sun<TH width=15%>Mon<TH width=14%>Tue<TH width=14%>Wed<TH width=14%>Thu<TH width=14%>Fri<TH width=15%>Sat");
   document.write("<TR>");
   column = 0;
   for (i=0; i<startDay; i++)
   {
      document.write("<TD>");
      document.write("<CENTER>");
      document.write("&nbsp");
      column++;
   }
   for (i=1; i<=nDays; i++)
   {
      document.write("<TD");
      if (i == thisDay)
       {  document.write(" BGCOLOR=\"#eeeeee\"><FONT COLOR=\"#000000\" size=2><b>"); }
      else
       {
       switch (column)
          {
          case 0  : 
           document.write("><FONT COLOR=\"#99ff99\">");
           break;
          case 6  : 
           document.write("><FONT COLOR=\"#9999FF\">");               
           break;
          default : 
           document.write(">");               
           break;
           }
        }
      document.write(i);
      if (i == thisDay)
         document.write("</b>")
      if (column == 7||column == 0||i == thisDay) 
         document.write("</FONT>")
      column++;
      if (column == 7)
      {
         document.write("<TR>");
         column = 0;
      }
   }
   document.write("</TABLE>");
}


function addbookmark(url,title)
{
 bookmarkurl=url;
 bookmarktitle=title;
 if (document.all)
   window.external.AddFavorite(bookmarkurl,bookmarktitle);
}

function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}


function checkCR(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}


function checkDecimals(fieldName, fieldValue) {

decallowed = 2;  // how many decimals are allowed?

if (isNaN(fieldValue) || fieldValue == "") 
{
	alert("The amount does not appear to be a valid number.");
	fieldName.select();
	fieldName.focus();
	return false;
}
else 
{
	if (fieldValue.indexOf('.') == -1) fieldValue += ".";
	dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

	if (dectext.length > decallowed)
	{
		alert ("Please enter a number with up to " + decallowed + " decimal places.");
		fieldName.select();
		fieldName.focus();
		return false;
	}
	else
	{
		if (document.PayPal.custom.value=="") 
		{
			alert ("Please enter student name(s).");
			return false;
		}
	}
	document.PayPal.item_name.value = "Band Fee Payment - " + document.PayPal.custom.value;
	return true;
}

}
