function test ()
{
}

function verifyForm(theForm)
{
  code = true;
  stateCheck = 0;
  unfilled = "Please correct the following errors and submit the registration form again:\n\n";
  
  if (!checkName(theForm.firstName)== true)
  {
    unfilled+="You must enter a valid first name\n";
    code = false;
  }

   if (!checkName(theForm.lastName)== true)
  {
    unfilled+="You must enter a valid last name\n";
    code = false;
  } 

  if (!checkWhite(theForm.street)== true)
  {
    unfilled+="You must enter a valid street address\n";
    code = false;
  }

  if (!checkName(theForm.town)== true)
  {
    unfilled+="You must enter a valid town\n";
    code = false;
  }

  switch(theForm.country.value)
  {
    case "United States":
    case "Canada":
      if(theForm.state.value == "Not applicable")
      {
        stateCheck = 1;
        code=false;
      }
      if(theForm.state.value == "Invalid!")
      {
        stateCheck = 1;
        code = false;
      }
      if(stateCheck == 1)
      {
        unfilled +="You must select a valid state or province\n";
        stateCheck = 0;
      }
      break;
    default:
      break;
  }

  if (!checkWhite(theForm.postalCode)== true)
  {
    unfilled+="You must enter a valid postal code\n";
    code = false;
  }
  
  if (!checkPhone(theForm.phone)== true)
  {
    unfilled+="You must enter a valid phone number\n";
    code = false;
  }

  if (!checkEmail(theForm.email)== true)
  {
    unfilled+="You must enter a valid email address\n";
    code = false;
  }

  if (theForm.confirm.value != theForm.email.value)
  {
    unfilled +="The email addresses you entered do not match\n";
    code = false;
  }

  if(!checkCreditCard(theForm.ccNum) == true)
  {
    unfilled +="You must enter a valid credit card number\n";
    code = false;
  }

  if(!checkCVM(theForm.cardCVM) == true)
  {
    unfilled +="You must enter a valid CVM\n";
    code = false;
  }

   if (!checkName(theForm.cardName)== true)
  {
    unfilled+="You must enter the name of the credit card holder\n";
    code = false;
  } 

   if (!checkWhite(theForm.billStreet)== true)
  {
    unfilled+="You must enter a valid billing street address\n";
    code = false;
  }
  
   if (!checkName(theForm.billTown)== true)
  {
    unfilled+="You must enter a valid billing town\n";
    code = false;
  }   

   if (!checkWhite(theForm.billPostalCode)== true)
  {
    unfilled+="You must enter a valid billing postal code\n";
    code = false;
  } 

  switch(theForm.billCountry.value)
  {
    case "United States":
    case "Canada":
      if(theForm.state.value == "Not applicable")
      {
        stateCheck = 1;
        code=false;
      }
      if(theForm.state.value == "Invalid!")
      {
        stateCheck = 1;
        code = false;
      }
      if(stateCheck == 1)
      {
        unfilled +="You must select a valid billing state or province\n";
        stateCheck = 0;
      }
      break;
    default:
      break;
  }
  
  if (!theForm.agree.checked)
  {
    unfilled +="You must agree to allow us to charge your credit card before continuing\n";
    code = false;
  }

   if (!checkWhite(theForm.answer)== true)
  {
    unfilled+="You must enter a valid answer to the confirmation question\n";
    code = false;
  } 

  if (!theForm.readTerms.checked)
  {
    unfilled+="You must agree to our terms before proceeding\n";
    code = false;
  }
         
  if (!code)
  {
    alert(unfilled);
  }
return code;

}

function checkName(item)
{
  if(checkWhite(item) == true)
  {
    re = /^[a-zA-Z \'\.]+$/
    if(re.test(item.value))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}

function checkUsername(item)
{
  if(checkWhite(item) == true)
  {
    re = /^[a-zA-Z0-9]+$/
    if(re.test(item.value))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}

function checkPassword1(item)
{
  if(checkWhite(item) == true)
  {
    re = /^[a-zA-Z]+$/
    if(re.test(item.value))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}

function checkPassword2(item)
{
  if(checkWhite(item) == true)
  {
    re = /^[0-9]+$/
    if(re.test(item.value))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}

function checkPhone(item)
{
  if(checkWhite(item) == true)
  {
    re = /^[()0-9 \-]+$/
    if(re.test(item.value))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}

function checkEmail(item)
{
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
  if(re.test(item.value))
  {
    return true;
  }
  else
  {
    return false;
  }
} 

function checkCreditCard(item)
{
  ccode = true;
  re2 = /^[0-9]+$/
  if(re2.test(item.value))
  {
    ccode = true;
  }
  else
  {
    ccode = false;
  }
  if(item.value.length != 16)
  {
    ccode = false;
  }
  return ccode;
}  

function checkCVM(item)
{
  ccode = true;
  re2 = /^[0-9]+$/
  if(re2.test(item.value))
  {
    ccode = true;
  }
  else
  {
    ccode = false;
  }
  if(item.value.length != 3)
  {
    ccode = false;
  }
  return ccode;
}  
 
function checkWhite(item)
{
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++)
  {
    if (item.value.charAt(index) != ' ')
    {
      tmp += item.value.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
        {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  if (tmp.length > 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function verifyUNForm(theForm)
{
  code = true;
  unfilled = "Please correct the following errors and submit the form again:\n\n";
    if (!checkUsername(theForm.username)== true)
    {
      unfilled+="You must enter a valid Username\n";
      code = false;
    }
    if(theForm.username.value.length < 8)
    {
      unfilled+="The username must be between 8 and 12 characters long.\n";
      code = false
    }
 
    if (!checkPassword1(theForm.pw1)== true)
    {
      unfilled+="You must enter a valid first password (letters only)\n";
      code = false;
    }
    
    if(theForm.pw1.value.length < 6)
    {
      unfilled+="The first password must be between 6 and12 characters long.\n";
      code = false;
    }
    
    if (!checkPassword2(theForm.pw2)== true)
    {
      unfilled+="You must enter a valid second password (numbers only)\n";
      code = false;
    }  

    if(theForm.pw2.value.length < 6)
    {
      unfilled+="The second password must be between 6 and 12 characters long.\n";
      code = false;
    }
    
    if (theForm.confirmUsername.value != theForm.username.value)
    {
      unfilled +="The usernames you've entered do not match.\n";
      code = false;
    }
    if (theForm.confirmPw1.value != theForm.pw1.value)
    {
      unfilled +="The values you've entered for the first password do not match.\n";
      code = false;
    }
    if(theForm.confirmPw2.value != theForm.pw2.value)
    {
      unfilled +="The values you've entered for the second password do not match.\n";
      code = false;
    }
  if (!code)
  {
    alert(unfilled);
  }
return code;
}

function openChangeWindow(changePage)
{
  newWindow = window.open(changePage, "changeWin", "width=300, height=400");
}

function logoutParent(logoutPage)
{
  opener.document.location = logoutPage;
}

function openContactWindows(openPage, contactPage)
{
  scrH = screen.availHeight;
  scrW = screen.availWidth;

  contactH = scrH;
  contactW = Math.round(0.68*scrW);
 
  popW = Math.round((.32 * scrW)-15);
  popH = Math.round(300);
  popX = contactW;
  popY = 0;
  newWindowb = window.open(openPage,"openWin","height=" + popH + ",width=" + popW + ",directories=no,screenx=" + popX + ",screenY=" + popY + ",left=" + popX + ",top=" + popY + ",menubar=no,scrollbars=no,status=no,location=no,toolbar=no,resizable=no");
  newWindowa = window.open(contactPage,"contactWin","directories=yes,screenX=0,screenY=0,left=0,top=0,menubar=yes,scrollbars=yes,status=yes,location=yes,toolbar=yes,resizable =yes,height=" + contactH + ",width=" + contactW);

  newWindowb.focus(top);
}  

function focusContactWindow()
{
    if(!window.closed) window.focus();
}

function changeContactFields(nim)
{  
  opener.document.forms[nim].elements["name"].value = document.myForm.name.value;
  opener.document.forms[nim].elements["username"].value = document.myForm.username.value;
  opener.document.forms[nim].elements["password"].value = document.myForm.password.value;
  opener.document.forms[nim].elements["other"].value = document.myForm.other.value;
  opener.document.forms[nim].elements["address"].value= document.myForm.address.value;
  opener.document.forms[nim].submit();
  this.close();  
}

function changePinFields(nim)
{  
  opener.document.forms[nim].elements["name"].value = document.myForm.name.value;
  opener.document.forms[nim].elements["number"].value = document.myForm.number.value;
  opener.document.forms[nim].elements["other"].value = document.myForm.other.value;
  opener.document.forms[nim].submit();
  this.close();  
}

function closeWindow()
{
  this.close();
}

function refreshParent()
{
  opener.document.location = opener.document.location;
}

function countdown()
{
  if (document.forms['myForm'].elements['count'].value <=0)
  {
    this.close();
  }
  else
  {
    document.forms['myForm'].elements['count'].value = document.forms['myForm'].elements['count'].value - 1;
  }
setTimeout("countdown()",1000);
}

function warningCountdown(logoutPage)
{
  if (document.forms['myForm'].elements['count'].value <=0)
  {
    logoutParent(logoutPage);
    this.close();
  }
  else
  {
    document.forms['myForm'].elements['count'].value = document.forms['myForm'].elements['count'].value - 1;
  }
logoutPage2=logoutPage;
setTimeout("warningCountdown(logoutPage2)",1000);
}

function checkDelete()
{
  if(confirm("Are you sure you want to delete this contact?"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

function checkPinDelete()
{
  if(confirm("Are you sure you want to delete this PIN Number?"))
  {
    return true;
  }
  else
  {
    return false;
  }
}


function correctDate (form,monthMenu,sday)
{
  for(i=0; i<form.elements.length; i++){
    if(form.elements[i] == monthMenu){
      var dateMenu = form.elements[i+1];
      break;
    }
  }
  var formerLength = dateMenu.options.length
  var theLength
  if(monthMenu.options[1].selected){
    theLength = 28;
  }
  else if(monthMenu.options[3].selected || monthMenu.options[5].selected || monthMenu.options[8].selected || monthMenu.options[10].selected){
    theLength=30;
  }
  else{
    theLength=31;
  }
  
  dateMenu.options.length = theLength;
    for(i=formerLength; i<theLength; i++){
      
      if (i<9){
      dateMenu.options[i].text="0"+(i+1);
      dateMenu.options[i].value="0"+(i+1);

      }
      else{
       dateMenu.options[i].text=i+1;
       dateMenu.options[i].value=i+1;
      }

    }
    
    dateMenu.selectedIndex = sday-1;

}

function verifyRegForm(theForm)
{

  code = true;
  stateCheck = 0;
  unfilled = "Please correct the following errors and submit the registration form again:\n\n";
  
  if (!checkName(theForm.firstName)== true)
  {
    unfilled+="You must enter a valid first name\n";
    code = false;
  }

   if (!checkName(theForm.lastName)== true)
  {
    unfilled+="You must enter a valid last name\n";
    code = false;
  } 

  if (!checkWhite(theForm.street)== true)
  {
    unfilled+="You must enter a valid street address\n";
    code = false;
  }

  if (!checkName(theForm.town)== true)
  {
    unfilled+="You must enter a valid town\n";
    code = false;
  }

  switch(theForm.country.value)
  {
    case "United States":
    case "Canada":
      if(theForm.state.value == "Not applicable")
      {
        stateCheck = 1;
        code=false;
      }
      if(theForm.state.value == "Invalid!")
      {
        stateCheck = 1;
        code = false;
      }
      if(stateCheck == 1)
      {
        unfilled +="You must select a valid state or province\n";
        stateCheck = 0;
      }
      break;
    default:
      break;
  }

  if (!checkWhite(theForm.postalCode)== true)
  {
    unfilled+="You must enter a valid postal code\n";
    code = false;
  }
  
  if (!checkPhone(theForm.phone)== true)
  {
    unfilled+="You must enter a valid phone number\n";
    code = false;
  }

  if (!checkEmail(theForm.email)== true)
  {
    unfilled+="You must enter a valid email address\n";
    code = false;
  }

  if (theForm.confirm.value != theForm.email.value)
  {
    unfilled +="The email addresses you entered do not match\n";
    code = false;
  }
  
  if (!code)
  {
    alert(unfilled);
  }
return code;
}

function verifyBillForm(theForm)
{

  code = true;
  stateCheck = 0;
  unfilled = "Please correct the following errors and submit the registration form again:\n\n";

  if(!checkCreditCard(theForm.cardNumber) == true)
  {
    unfilled +="You must enter a valid credit card number\n";
    code = false;
  }

  if(!checkCVM(theForm.cvm) == true)
  {
    unfilled +="You must enter a valid CVM\n";
    code = false;
  }

   if (!checkName(theForm.name)== true)
  {
    unfilled+="You must enter the name of the credit card holder\n";
    code = false;
  } 

   if (!checkWhite(theForm.street)== true)
  {
    unfilled+="You must enter a valid billing street address\n";
    code = false;
  }
  
   if (!checkName(theForm.town)== true)
  {
    unfilled+="You must enter a valid billing town\n";
    code = false;
  }   

   if (!checkWhite(theForm.postalCode)== true)
  {
    unfilled+="You must enter a valid billing postal code\n";
    code = false;
  } 

  switch(theForm.country.value)
  {
    case "United States":
    case "Canada":
      if(theForm.state.value == "Not applicable")
      {
        stateCheck = 1;
        code=false;
      }
      if(theForm.state.value == "Invalid!")
      {
        stateCheck = 1;
        code = false;
      }
      if(stateCheck == 1)
      {
        unfilled +="You must select a valid billing state or province\n";
        stateCheck = 0;
      }
      break;
    default:
      break;
  }
  if (!code)
  {
    alert(unfilled);
  }
return code;
}

function verifyChangeUNForm(theForm)
{
  code = true;
  unfilled = "Please correct the following errors and submit the form again:\n\n";
    if (!checkUsername(theForm.username)== true)
    {
      unfilled+="You must enter a valid Username\n";
      code = false;
    }
    if(theForm.username.value.length < 8)
    {
      unfilled+="The username must be between 8 and 12 characters long.\n";
      code = false
    }
 
    if(!document.myForm.passwordEnable.checked)
    {
      if (!checkPassword1(theForm.pw1)== true)
      {
        unfilled+="You must enter a valid first password (letters only), or disable the passwords above\n";
        code = false;
      }
    
      if(theForm.pw1.value.length < 6)
      {
        unfilled+="The first password must be between 6 and12 characters long.\n";
        code = false;
      }
    
      if (!checkPassword2(theForm.pw2)== true)
      {
        unfilled+="You must enter a valid second password (numbers only), or disable the passwords above\n";
        code = false;
      }  

      if(theForm.pw2.value.length < 6)
      {
        unfilled+="The second password must be between 6 and 12 characters long.\n";
        code = false;

      }
     if (theForm.confirmPw1.value != theForm.pw1.value)
     {
       unfilled +="The values you've entered for the first password do not match.\n";
       code = false;
     }
     if(theForm.confirmPw2.value != theForm.pw2.value)
     {
       unfilled +="The values you've entered for the second password do not match.\n";
       code = false;
     }
    }

    if (theForm.confirmUsername.value != theForm.username.value)
    {
      unfilled +="The usernames you've entered do not match.\n";
      code = false;
    }

  if (!code)
  {
    alert(unfilled);
  }
return code;
}

function enablePasswords()
{
  if(document.myForm.passwordEnable.checked)
  {
    document.myForm.pw1.disabled = true;
    document.myForm.confirmPw1.disabled = true;
    document.myForm.pw2.disabled = true;
    document.myForm.confirmPw2.disabled = true;
    document.myForm.passwordCode.value = 1;
  }
  else
  {
    document.myForm.pw1.disabled = false;
    document.myForm.confirmPw1.disabled = false;
    document.myForm.pw2.disabled = false;
    document.myForm.confirmPw2.disabled = false;
    document.myForm.passwordCode.value = 2;
  }   
}

function verifyOrderListForm(theForm)
{
  code = true;
  gotone=0
  unfilled = "Please correct the following errors and try again:\n\n";  
  firstMonth = theForm.firstMonth.value - 1;
  firstDay = theForm.firstDay.value;
  firstYear = theForm.firstYear.value;
  secondMonth = theForm.secondMonth.value - 1;
  secondDay = theForm.secondDay.value;
  secondYear = theForm.secondYear.value;
  firstDate = new Date(firstYear,firstMonth,firstDay);
  secondDate = new Date(secondYear, secondMonth, secondDay);
  
  if(secondDate.getTime() < firstDate.getTime())
  {
    code = false;
    unfilled = unfilled += "That date range is invalid.  The second date needs to be greater than or equal to the first date.\n";
  }
mine=theForm.elements['showWhich[]'];  

num = mine.options.length;

for (i=0; i<num; i++)
{
  if (mine.options[i].selected)
  {
    gotone = 1;
  }
}

if (gotone==0)
{
  code=false;
  unfilled = unfilled += "You need to select at least one type of order to display.\n";
}
   if (!code)
  {
    alert(unfilled);
  }
return code;
} 

function myLittleTest(it)
{
  alert(it.options.length);
}

function logger()
{
  location.href="logout.php?method=1";
}

function checkAlert(loc)
{
  if(confirm("If you proceed, your account will be inaccessible."))
  {
    location.href=loc;
  }
  else
  {
    return false;
  }
}

function openTellWindow(tellPage)
{
  newWindow = window.open(tellPage, "telleWin", "width=450, height=575");
}

function verifyTell(theForm)
{
  code = true;
  unfilled = "Please correct the following errors and submit the Tell a Friend form again:\n\n";
  
  if (!checkName(theForm.name)== true)
  {
    unfilled+="You must enter a valid name for yourself\n";
    code = false;
  }
  
  if (!checkEmail(theForm.email)==true)
  {
    unfilled+="You must enter a valid email address for yourself\n";
    code = false;
  }
  
  if(!checkEmail(theForm.friend1) == true && !checkEmail(theForm.friend2) == true && !checkEmail(theForm.friend3) == true && !checkEmail(theForm.friend4) == true)
  {
    unfilled +="You must enter at least one valid email address for your friends\n";
    code = false;
  }
   
  if (!code)
  {
    alert(unfilled);
  }
return code;
}