function GetWeekStr()
 {
  var d = new Date();
  var startdate = new Date("Dec 26,2000");
  var days = (d-startdate) / 86400000;
  days = Math.floor(days/7) + 1;
  return ("Score Card for Week " + days);
  }

function GetToken()
 {
  return ("Af830yhq");
  }

function initUpper(InString)  
 {
	if(InString.length==0)
	  return(InString)
//	InString=InString.toLowerCase();
	Space=false;
	var OutString="";
	OutString+=InString.substring(0, 1).toUpperCase();
	for(Count=1; Count<InString.length; Count++)
	  {
		if (InString.substring(Count, Count+1)==" ")
		  {
			Space=true;
			OutString+=InString.substring(Count, Count+1);
			continue;
		  }
		if (Space)
		  {
			OutString+=InString.substring(Count, Count+1).toUpperCase();
			Space=false;
			continue;
		  }
		OutString+=InString.substring(Count, Count+1);
	  }
	return (OutString);
}

function ShooterOK(f)
  {
   if (f.Shooter.value == "")
	 {
	  alert("Please enter your name.");
	  f.Shooter.focus();
	  return (false);
	  }
	 else
	  {
	   f.Shooter.value=initUpper(f.Shooter.value);
	   return (true);
	   }
   }

function emailOK(f)
  {
  var s=f.email.value;
   if (s == "")
	 {
	  alert("Please enter your email address.");
	  f.email.focus();
	  return (false);
	  }
	 else
	  if (s.indexOf("@")==-1)
	   {
		alert("Your email address is not valid.");
		f.email.focus();
		return (false);
		}
		else
		 return (true);
   }

function scoreOK(f)
  {
  var s= new String ();
  s = f.score.value;
   if (s == "")
	 {
	  alert("Please enter your score!");
	  f.score.focus();
	  return (false);
	  }
	 else
	  {
	   if (((f.guntype[0].checked) && (s.substring(3,5)!="90")) ||
	       ((f.guntype[1].checked) && (s.substring(3,5)!="40")) ||
	        (s.indexOf("/")==-1))
	    {
	     if (f.guntype[0].checked)
		    alert("Please enter your score in the form of 'nn/90'.")
		   else
		      alert("Please enter your score in the form of 'nn/40'.");
		 f.score.focus();
	     return (false);
		 }
		else
		 {
    	   return (true);
          }
   	  }
   }

function GunOK(f)
  {
   if (f.Gun.value == "")
	 {
	  alert("Please enter your type of Airgun.");
	  f.Gun.focus();
	  return (false);
	  }
	 else
	  {
	   f.Gun.value=initUpper(f.Gun.value);
	   return (true);
	   }
   }

function ScopeOK(f)
  {
   if (f.Scope.value == "")
	 {
	  alert("Please tell what scope you used, if any.");
	  f.Scope.focus();
	  return (false);
	  }
	 else
	  {
	   f.Scope.value=initUpper(f.Scope.value);
	   return (true);
	   }
   }

function PelletOK(f)
  {
   if (f.Pellet.value == "")
	 {
	  alert("Please enter the pellet used.");
	  f.Pellet.focus();
	  return (false);
	  }
	 else
	  {
	   f.Pellet.value=initUpper(f.Pellet.value);
	   return (true);
	   }
   }

function Authorized(f)
  {
  var s= new String ();
  s = f.Comments.value;

   if ((!(f.token.value == "Af830yhq"))||
       (s.indexOf("http:")>-1))
	 {
	  alert("Authorization not valid.");
	  return (false);
	  }
	 else
	  {
	   return (true);
	   }
   }


function DivisionOK(f)
  {
	for (count=0 ; count<2; count++)
	 {
	   if (f.guntype[count].checked)
		{
		  return (true);
		  break;
		 }
	  }
	alert("Please mark the correct Division.");
	return (false);
   }

function ClassnumOK(f)
  {
	for (count=0 ; count<3; count++)
	 {
	   if (f.classnum[count].checked)
		{
		  return (true);
		  break;
		 }
	  }
	alert("Please mark the correct Class.");
	return (false);
   }

function CheckValues(f)
{
 if (!Authorized(f)) return;
 if (!DivisionOK(f)) return;
 if (!ShooterOK(f)) return;
 if (!ClassnumOK(f)) return;
 if (!emailOK(f)) return;
 if (!scoreOK(f)) return;
 if (!GunOK(f)) return;
 if (!ScopeOK(f)) return;
 if (!PelletOK(f)) return;
 f.submit();
 return;
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)	 // Except on the Mac - ahead of its time
	date.setTime (date.getTime() - skew);
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
	endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	  return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  if (expires!=null) FixCookieDate(expires); //*** Uncomment this line for automatic date correction (see above)
  document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  FixCookieDate (exp); // Correct for Mac bug
  exp.setTime (exp.getTime() - 1);	// This cookie is history
  var cval = GetCookie (name);
  if (cval != null)
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
