﻿// *********************************************************************
// ASP Validation Script for the buying process
// 3Ds (UK) Limited, 2008
// *********************************************************************

// *********************************************************************
// ASPValidateLicenceEntry
// *********************************************************************
function ASPValidateLicenceEntry (sLicenceEntry)
{
 if (sLicenceEntry == "")
 {
   return true
 }

 if (isNaN(sLicenceEntry))
 {
   // Not numeric
   return false
 }

 if (sLicenceEntry < 1)
 {
   // Invalid entry
   return false
 }
 
 // All OK
 return true
}

// *********************************************************************
// ASPValidateBuyNowStep1
// *********************************************************************

function ASPValidateBuyNowStep1()
{
  var sEmail
  var sSearch = "@"
  var iCount
  var sFieldName
  var bItemPurchased 

  // Default to nothing purchased
  bItemPurchased = false

  // Check for numeric entries in any of the fields
  for (iCount = 1; iCount < 15; iCount++)
  {
    // Check the field 
    sFieldName = eval ("document.BuyNowStep1.txtcomponent" + iCount + ".value")

    if (!ASPValidateLicenceEntry(sFieldName))
    {
      alert ("One or more licence entries are not numeric, or zero. Please check and correct these entries before proceeding ...")
      return false  
    }

    // Check if we have an entry
    if (sFieldName != "")
    {
      bItemPurchased = true
    }
  }
    
  // Now check if we have something selected for a site licence
  for (iCount = 1; iCount < 15; iCount++)
  {
    // Check the field
      sFieldName = "document.BuyNowStep1.chkcomponent" + iCount
      if (eval(sFieldName) != null) {
          sFieldName = "document.BuyNowStep1.chkcomponent" + iCount + ".checked"
          if (eval(sFieldName) == true) {
              bItemPurchased = true
          }
      }
  }

  // Global licence
  if (eval("document.BuyNowStep1.chkpackage6.checked") == true)
  {
    bItemPurchased = true
  }

  // Check for numeric entries in any of the fields for quick monitors
  for (iCount = 1; iCount < 10; iCount++) {
      // Check the field 
      sFieldName = eval("document.BuyNowStep1.txtquick" + iCount + ".value")

      if (!ASPValidateLicenceEntry(sFieldName)) {
          alert("One or more licence entries are not numeric, or zero. Please check and correct these entries before proceeding ...")
          return false
      }

      // Check if we have an entry
      if (sFieldName != "") {
          bItemPurchased = true
      }
  }

  // Check for numeric entries in any of the fields for utils
  for (iCount = 1; iCount < 7; iCount++) {
      // Check the field 
      sFieldName = eval("document.BuyNowStep1.txtutil" + iCount + ".value")

      if (!ASPValidateLicenceEntry(sFieldName)) {
          alert("One or more licence entries are not numeric, or zero. Please check and correct these entries before proceeding ...")
          return false
      }

      // Check if we have an entry
      if (sFieldName != "") {
          bItemPurchased = true
      }
  }


  // There are no site licences for packages. Now check to
  // see if anything is selected
  if (bItemPurchased == false)
  {
    alert("No products have been selected. Please select the product(s) you wish to pruchase ...")
    return false  
  }

  // Have we got the required user details ?
  if (document.BuyNowStep1.txtName.value == "")
  {
	  alert("Please enter your name ...")
	  return false
  }

  if (document.BuyNowStep1.txtEmailAddress.value == "")
  {
	  alert("Please enter your e-mail address. Your new licence key(s) will be sent to this address ...")
	  return false
  }
  // Check the e-mail has a "@" in it
  sEmail = document.BuyNowStep1.txtEmailAddress.value
  if (sEmail.search(sSearch) == -1)
  {
    alert("The e-mail address entered does not appear to be valid. Your new licence key(s) will be sent to this address. Please check and re-enter your e-mail address ...")     
    return false
  }

  if (document.BuyNowStep1.txtCompanyName.value == "")
  {
	  alert("Please enter your company name ...")
	  return false
  }

  if (document.BuyNowStep1.txtAddress1.value == "")
  {
	  alert("Please enter your address ...")
	  return false
  }

  if (document.BuyNowStep1.cboCountry.options[0].selected == true)
  {
	  alert("Please select the country in which you are located ...")
	  return false
  }
  
  // All OK
  return true
}
