// JScriptsLetChek.js

var submitcount=0  // "Submit Once" Script

function Inputchecker(q)
{
var checkOK = " 10ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ.\'- ";
var Pre0 = "HO!!  HO!!  HO!! \n\n";
var Pre2= Pre0 + "Did you forget to tell Santa ";
var Pre3= Pre0 + "You wouldn\'t be fibbing to Santa about ";
var Aft0= " now would you? ";
var Aft3= "you live in?\nSelect your ";
var Aft4= "from the drop-down list.";
var AgeM = "Make sure to enter your age as a number (e.g. 10) instead of as a word (e.g. ten).\n\nEnter infant\'s ages as decimals (e.g. 0.5).";
var Prez= Pre2 + "what you\'d like for Christmas?\n\nPlease type 3 wishes (in case the elves can\'t make enough presents for everyone).";

  if (q.firstname.value == "")
  {
    alert(Pre2 + "your first name?");
    q.firstname.focus();
    q.firstname.select();
    return (false);
  }

  var checkStr = q.firstname.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

  if ((!allValid) || (checkStr.length < 2))
  {
    alert(Pre3 + "your name" + Aft0);
    q.firstname.focus();
    q.firstname.select();
    return (false);
  }

  if (q.email.value.length == "")
  {
    q.email.value=" ";
  }

 var radioSelected = false;
  for (var i=0;  i < q.gender.length;  i++)
  {
    if (q.gender[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert(Pre2 + "whether you are a boy or a girl?");
    q.gender[0].focus();
    return (false);
  }

  var checkOKnum = "0123456789.";
  var checkStr = q.age.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOKnum.length;  j++)
      if (ch == checkOKnum.charAt(j))
        break;
    if (j == checkOKnum.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if ((!allValid) || (checkStr == ""))
  {
    alert(Pre0 + AgeM);
    q.age.focus();
    q.age.select();
    return (false);
  }

	var chkVal = allNum;
	var prsVal = parseFloat(allNum);
   if ((chkVal != "" && !(prsVal >= "0.0" && prsVal <= "99")) ||
    (decPoints > 1))
  {
    alert(Pre3 + "your age" + Aft0 );
    q.age.focus();
    q.age.select();
    return (false);
  }

  if (q.city.value == "")
  {
    alert(Pre2 + "what city you live in?");
    q.city.focus();
    return (false);
  }

  var checkStr = q.city.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if ((!allValid) || (checkStr.length < 2))
  {
    alert(Pre3 + "the name of your city" + Aft0 );
    q.city.focus();
    q.city.select();
    return (false);
  }

  if (q.region.selectedIndex == 0)
  {
    alert(Pre2 + "what State or Province, if any, " + Aft3 + "state/province " + Aft4 + ",\nOR choose \"Not in US/Canada\" if you don\'t live in the U.S. or Canada.");
    q.region.focus();
    return (false);
  }

  if (q.country.value == "-")
  {
    alert(Pre2 + "what country " + Aft3 + "country " + Aft4);
    q.country.focus();
    return (false);
  }

  if (q.good.selectedIndex == 0)
  {
    alert(Pre2 + "how good you've been this year?");
    q.good.focus();
    return (false);
  }

for (var i=13; i<16; i++) {

  if ((q.elements[i].value == null) ||
     (q.elements[i].value.length < 2))
  {
    alert(Prez);
    q.elements[i].focus();
    q.elements[i].select();
    return (false);
  }
}

  if (q.comment.value.length == "")
  {
    q.comment.value=" ";
  }

else  //  Begin "Submit Once"
 {
  if (submitcount == 0)
   {
    submitcount++; 
    return (true);
     } 
     else 
     {
alert(Pre0 +"Santa has your letter and is reading it!\nHe\'ll send you a reply right away!");
return (false);
  }
 }
}  //End "Submit Once"

// ensure file loaded
var LetChek2="On2";