// Support Script (776)
function AddToValidateArray(strElementName)
{
    var strName = strElementName

    if (!document.ValidateArray) 
    {
        document.ValidateArray = new Array
    }

    document.ValidateArray[document.ValidateArray.length] = strName
}

// Support Script (800)
function StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}


function reformat (s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function Trim(theString)
{
 var i,firstNonWhite

 if (StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}
// Support Script (649)
function ValidateNumChars()
{	
	var theString = this.getText()
	var MinLength = this.MinLength
	var MaxLength = this.MaxLength
	var msgInvalid = ""

	if (StripChars(" \n\t\r",this.ErrorMsg).length == 0)
	{
				
		if (MinLength == 1 && MaxLength == 1)		
			msgInvalid = "Please enter a value one character long."		
		else if (MinLength > 1 && MaxLength == MinLength)		
			msgInvalid = "Please enter a value " + MinLength + " characters long."				
		else if (MinLength > 0 && MaxLength > 0)		
			msgInvalid = "Please enter a value between\n" + MinLength + " and " + MaxLength + " characters long."		
		else if (MinLength == 1)		
			msgInvalid = "Please enter a value at least one character long."
		else if (MinLength > 1)
			msgInvalid = "Please enter a value at least " + MinLength + " characters long."
		else if (MaxLength == 1)		
			msgInvalid = "Please enter a value no more than one character long."
		else if (MaxLength > 1)
			msgInvalid = "Please enter a value no more than " + MaxLength + " characters long."		
 	else
	 	msgInvalid = this.ErrorMsg	

	}
	else
		msgInvalid = this.ErrorMsg	


	if (StripChars(" \n\r",theString).length == 0)	
		if (!this.Required) return ""		
		else return "Required field.  " + msgInvalid

	theString = Trim(theString)

	if (this.StripSpaces)
		theString = StripChars(" \n\r",theString)

	if (MinLength > 0 && theString.length < MinLength)
		return msgInvalid

	if (MaxLength > 0 && theString.length > MaxLength)
		return msgInvalid

	// we passed the tests
	this.setText(theString)

	return ""
}
// Support Script (650)
function ValidateEMail()
{
   var msg = "";
   var val = this.getText();
   var msgInvalid = "Please enter a valid e-mail address\n(a valid e-mail address contains the @ character)";

  	var theLen = StripChars(" ",val).length
	  if (theLen == 0)	
		  if (!this.Required) return ""		
		  else return "Required field.  " + msgInvalid

   if (val.indexOf("@",0) < 0) 
   {
      msg = msgInvalid 
   }
   return msg;
}

// Support Script (661)

function ValidateZipCode()
{
	var msg = ""
	var theString = this.getText()
 var msgInvalid = "Please enter a valid Zip Code.\nSuch as 92008 or 92008-1337"

	var theLen = StripChars(" \n\t\r",theString).length
	if (theLen == 0)	
		if (!this.Required) return ""		
		else return "Required field.  " + msgInvalid

	theString = StripChars("- \n\r",theString)		

	if (!AllInRange("0","9",theString))
	{
		msg = msgInvalid
	}
	else if (theString.length != 5 && theString.length != 9)
	{
		msg = msgInvalid
	}

	if (msg == "")
	{
		if (theString.length == 9)		
			this.setText(reformat(theString,"",5,"-",4))
		else
   this.setText(theString)
   
	}
	return msg	
}
// Support Script (646)
function ValidateCreditCard()
{
	var msg = ""
	var theString = this.getText()
	var msgInvalid = "Please enter a valid credit card number."

	var theLen = StripChars(" \n\t\r",theString).length
	if (theLen == 0)	
		if (this.Required == "0") return ""		
		else return "Required field.  " + msgInvalid

	theString = StripChars(" -.\n\r",theString)		

	if (!AllInRange("0","9",theString) || !isCreditCard(theString))
	{
		msg = msgInvalid
	}	

	return msg		
}


function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} 

// Support Script (768)
function getForm()
{
	var f;
	if (document.forms && document.forms[0])
	{
		// This is the case where there are only hidden form elements in an
		// all 4.0 browser page and Comm is hitting the page - and all IE cases.
		f = document.forms[0];
	}

	if (f == null)
	{
		if ((document.layers) && (document.layers.length > 0))
		{
			var d;
			iLayer = 0;
			while (true)
			{
				d = document.layers[iLayer].document.layers[0].document;
				if (d.forms && d.forms[0]) // normal case
				{
					f = d.forms[0];
					break;
				}
				iLayer = iLayer + 2;
			
				if (document.layers[iLayer] == null)
					break;
			}
		}
	}

	if (f == null)
		alert("Form not submitted - internal error: Drumbeat can not find Form object in DOM. There may not be a form on this page.");

	return f;
}

// Support Script (810)
function subAwithBinC(a,b,c)
{

	var i = c.indexOf(a);
	var l = b.length;

	while (i != -1)	{
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
  i += l
		i = c.indexOf(a,i);
	}
	return c;

}
// Support Script (770)
function Validate(stopOnFailure)
{
	var ErrorMsg = "";
	var i
	var msg
	var tofocus = true;
	var ErrorMsg = "";
	
	// Go through the Validate Array that may or may not exist
	// and call the Validate function for all elements that have one.
	if (document.ValidateArray)
	{
		for (i = 0; i < document.ValidateArray.length; i ++)
		{
			msg = eval( document.ValidateArray[i] + ".Validate()")
			if (msg != "")
			{
				ErrorMsg += "\n\n" + document.ValidateArray[i] + ":  " + msg;
				if (tofocus) 
				{
					eval(document.ValidateArray[i] + ".focus()")
					tofocus = false;
				}
				
				if (stopOnFailure == "1") return ErrorMsg;
			}
  	}
  }
	return ErrorMsg;
}

// Support Script (778)
function ValidateTargetEqualsSource()
{
	var msg = ""
	var sourceText = this.getText()
	var targetText = this.Target.getText()
	var msgInvalid = "Password and Confirmation must match"
	
	var theLen = StripChars(" \n\t\r", sourceText).length
	if (theLen == 0)
	{	
		if (!this.Required) return ""		
		else return "Required field.  " + msgInvalid
	}
	
	if (sourceText != targetText)
	{
		msg = msgInvalid
	}
	
	return msg	
}
// Support Script (772)
// These date functions work for Nav 3 and above.

function getDayName(d)
{   
   var theDay = d.getDay()

   if (theDay == 0) 
            return "Sunday"
   if (theDay == 1) 
            return "Monday"
   if (theDay == 2) 
            return "Tuesday"
   if (theDay == 3) 
            return "Wednesday"
   if (theDay == 4) 
            return "Thursday"
   if (theDay == 5) 
            return "Friday"
   if (theDay == 6) 
            return "Saturday"
}

function getFullYear(d)
{
   var y = d.getYear();

   if (y < 2000) 
   {
        y += 1900
   }

   return y
}

function getMonthName(d)
{
   var theMonth = d.getMonth()
   
   if (theMonth == 0) 
            return "January"
   if (theMonth == 1) 
            return "February"
   if (theMonth == 2) 
            return "March"
   if (theMonth == 3) 
            return "April"
   if (theMonth == 4) 
            return "May"
   if (theMonth == 5) 
            return "June"
   if (theMonth == 6) 
            return "July"
   if (theMonth == 7) 
            return "August"
   if (theMonth == 8) 
            return "September"
   if (theMonth == 9) 
            return "October"
   if (theMonth == 10) 
            return "November"
   if (theMonth == 11) 
            return "December"
}

// A helper function for the other functions in this
// support script

function DateSupportReplaceAwithBinC(aa,bb,cc)
{
 var a = aa + ""
 var b = bb + ""
 var c = cc + ""
	var i = c.indexOf(a);
	var l = b.length;
	while (i != -1)	
 {
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
  i += l
		i = c.indexOf(a,i);
	}
	return c;
}


function ReplaceTokensWithTimeDate(strIn, leadingZeroes, zoneDiff)
{
    var strOut = strIn
    var now = new Date()
    var d = new Date(now.getTime() + zoneDiff)

    var theTime = ""
    var theHours
    var theMinutes
    var theSeconds
    var ampm = "am"

    theHours = d.getHours()
    if (theHours >= 12)
    {
        ampm = "pm"
    }
    if (theHours > 12)
    {
         theHours -= 12   
    }

    theMinutes = d.getMinutes()
    if (leadingZeroes, theMinutes < 10)
    {
        theMinutes = "0" + theMinutes
    }
    
    theTime = theHours + ":" + theMinutes + ampm

    theSeconds = d.getSeconds()
    if (leadingZeroes && theSeconds < 10)
    {
        theSeconds = "0" + theSeconds
    }

    strOut = DateSupportReplaceAwithBinC("[monthname]", getMonthName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[monthnumber]", d.getMonth(d) + 1, strOut)
    strOut = DateSupportReplaceAwithBinC("[dayname]", getDayName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[daynumber]", d.getDate(), strOut)
    strOut = DateSupportReplaceAwithBinC("[year]", getFullYear(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[time]", theTime, strOut)
    strOut = DateSupportReplaceAwithBinC("[hours]", theHours, strOut)
    strOut = DateSupportReplaceAwithBinC("[minutes]", theMinutes, strOut)
    strOut = DateSupportReplaceAwithBinC("[seconds]", theSeconds, strOut)
    strOut = DateSupportReplaceAwithBinC("[ampm]", ampm, strOut)

    return strOut
}


// This function takes the name of an edit box and a 
// flag that says whether or not to pad single digit 
// minutes and seconds with a zero.  It provides a 
// real time clock in an edit box.
//
function SetTimeText(strElementName, blnLeadingZeroes, zoneDiff)
{
  var theObj = eval(strElementName)

  theObj.setText(ReplaceTokensWithTimeDate(theObj.ContentString,blnLeadingZeroes, zoneDiff))
  setTimeout("SetTimeText('" + strElementName + "'," + blnLeadingZeroes + "," + zoneDiff + ")",1000)
}

// Returns a JavaScript Date object
// Expected format of date is 8/17/1998
// Expected format of time is 12:02am or 1:09pm
// Gives an error message if format is wrong.
//
function MakeDate(strDate, strTime)
{

 var tempDate = new Date(strDate)
 var strFormatted = getMonthName(tempDate) + " " + tempDate.getDate() + ", " + getFullYear(tempDate)

	var colonPos = strTime.indexOf(":")
	var ampmPos = strTime.indexOf("am")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("AM")
    if (ampmPos == -1)
		ampmPos = strTime.indexOf("pm")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("PM")

	// assume format of time is okay
	var theHours = strTime.substring(0,colonPos)
	var theMinutes = strTime.substring(colonPos + 1, ampmPos)
	var ampm = strTime.substring(ampmPos, strTime.length)
	ampm = ampm.toUpperCase()

	if (ampm == "PM")
	{
		if (theHours != "12")
		{
			theHours += 12
		}
	}
	else
	{
		if (theHours == "12")
		{
			theHours = "0"
		}
	}

	var outDate = new Date(strFormatted + " " + theHours + ":" + theMinutes)
	return outDate
}

function document_onLoad() {
CustomersRecord_LastName.ErrorMsg = "Last Name Must have between 1 and 50 characters";
CustomersRecord_LastName.MaxLength = Number("50");
CustomersRecord_LastName.MinLength = Number("1");
CustomersRecord_LastName.StripSpaces = Number("0");
CustomersRecord_LastName.Required = Number("1");
CustomersRecord_LastName.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_LastName")
CustomersRecord_FirstName.ErrorMsg = "First Name Must have between 1 and 50 characters";
CustomersRecord_FirstName.MaxLength = Number("50");
CustomersRecord_FirstName.MinLength = Number("1");
CustomersRecord_FirstName.StripSpaces = Number("0");
CustomersRecord_FirstName.Required = Number("1");
CustomersRecord_FirstName.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_FirstName")
CustomersRecord_CustomerEmail.Validate = ValidateEMail;
CustomersRecord_CustomerEmail.Required = Number("1");
AddToValidateArray("CustomersRecord_CustomerEmail")
CustomersRecord_BillingAddress.ErrorMsg = "Billing Address Must have between 1 and 50 characters";
CustomersRecord_BillingAddress.MaxLength = Number("50");
CustomersRecord_BillingAddress.MinLength = Number("1");
CustomersRecord_BillingAddress.StripSpaces = Number("0");
CustomersRecord_BillingAddress.Required = Number("1");
CustomersRecord_BillingAddress.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_BillingAddress")
CustomersRecord_BillingCity.ErrorMsg = "Billing City Must have between 1 and 50 characters";
CustomersRecord_BillingCity.MaxLength = Number("50");
CustomersRecord_BillingCity.MinLength = Number("1");
CustomersRecord_BillingCity.StripSpaces = Number("0");
CustomersRecord_BillingCity.Required = Number("1");
CustomersRecord_BillingCity.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_BillingCity")
CustomersRecord_BillingPostalCode.Validate = ValidateZipCode;
CustomersRecord_BillingPostalCode.Required = Number("1");
AddToValidateArray("CustomersRecord_BillingPostalCode")
CustomersRecord_BillingCountry.ErrorMsg = "Billing Country Must have between 1 and 50 characters";
CustomersRecord_BillingCountry.MaxLength = Number("50");
CustomersRecord_BillingCountry.MinLength = Number("1");
CustomersRecord_BillingCountry.StripSpaces = Number("0");
CustomersRecord_BillingCountry.Required = Number("1");
CustomersRecord_BillingCountry.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_BillingCountry")
CustomersRecord_Phone.ErrorMsg = "Phone Must have between 1 and 50 characters";
CustomersRecord_Phone.MaxLength = Number("50");
CustomersRecord_Phone.MinLength = Number("1");
CustomersRecord_Phone.StripSpaces = Number("0");
CustomersRecord_Phone.Required = Number("1");
CustomersRecord_Phone.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_Phone")
CustomersRecord_FAX.ErrorMsg = "Fax Must have between 1 and 50 characters";
CustomersRecord_FAX.MaxLength = Number("50");
CustomersRecord_FAX.MinLength = Number("0");
CustomersRecord_FAX.StripSpaces = Number("0");
CustomersRecord_FAX.Required = Number("0");
CustomersRecord_FAX.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_FAX")
CustomersRecord_ShipAddress.ErrorMsg = "Shipping Address Must have between 1 and 50 characters";
CustomersRecord_ShipAddress.MaxLength = Number("50");
CustomersRecord_ShipAddress.MinLength = Number("1");
CustomersRecord_ShipAddress.StripSpaces = Number("0");
CustomersRecord_ShipAddress.Required = Number("1");
CustomersRecord_ShipAddress.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_ShipAddress")
CustomersRecord_ShipCity.ErrorMsg = "Shipping City Must have between 1 and 50 characters";
CustomersRecord_ShipCity.MaxLength = Number("50");
CustomersRecord_ShipCity.MinLength = Number("1");
CustomersRecord_ShipCity.StripSpaces = Number("0");
CustomersRecord_ShipCity.Required = Number("1");
CustomersRecord_ShipCity.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_ShipCity")
CustomersRecord_ShipPostalCode.Validate = ValidateZipCode;
CustomersRecord_ShipPostalCode.Required = Number("1");
AddToValidateArray("CustomersRecord_ShipPostalCode")
CustomersRecord_ShipCountry.ErrorMsg = "Shipping Country Must have between 1 and 50 characters";
CustomersRecord_ShipCountry.MaxLength = Number("50");
CustomersRecord_ShipCountry.MinLength = Number("1");
CustomersRecord_ShipCountry.StripSpaces = Number("0");
CustomersRecord_ShipCountry.Required = Number("1");
CustomersRecord_ShipCountry.Validate = ValidateNumChars;
AddToValidateArray("CustomersRecord_ShipCountry")
CustomersRecord_CreditCard.Validate = ValidateCreditCard;
CustomersRecord_CreditCard.Required = Number("1");
AddToValidateArray("CustomersRecord_CreditCard")
Confirm.Validate = ValidateTargetEqualsSource
Confirm.Target = CustomersRecord_Password
Confirm.Required = Number("1")
AddToValidateArray("Confirm")
var style = "MM/DD/YY";
var d = new Date();

if (style == "MM/DD/YY") {
  var date_string = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getYear();
  }
  else if (style == "MM/DD/YYYY") {
  var date_string = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
  }
  else if (style == "MM-DD-YY") {
  var date_string = (d.getMonth()+1) + "-" + d.getDate() + "-" + d.getYear();
  }
  else if (style == "MM-DD-YYYY") {
  var date_string = (d.getMonth()+1) + "-" + d.getDate() + "-" + d.getFullYear();
  }
  else if (style == "DD/MM/YY") {
  var date_string = d.getDate() + "/" + (d.getMonth()+1) + "/" + d.getYear();
  }
  else if (style == "DD/MM/YYYY") {
  var date_string = d.getDate() + "/" + (d.getMonth()+1) + "/" + d.getFullYear();
  }
  else if (style == "Month Day, Year") {
  var date_string = getMonthName(d) + " " + d.getDate() + ", " + d.getFullYear();
  }
  else if (style == "Day of week, Month Day, Year") {
  var date_string = getDayName(d) + " " + getMonthName(d) + " " + d.getDate() + ", " + d.getFullYear();
  }
  else if (style == "Locale") {
  var date_string = d.toLocaleString();
  }
  else {
  var date_string = d.toGMTString();
  }

Edit2.setText(date_string);
 }
function Check1__onClick() {
CustomersRecord_ShipAddress.setText(CustomersRecord_BillingAddress.getText())
CustomersRecord_ShipCity.setText(CustomersRecord_BillingCity.getText())
CustomersRecord_ShipPostalCode.setText(CustomersRecord_BillingPostalCode.getText())
CustomersRecord_ShipCountry.setText(CustomersRecord_BillingCountry.getText())
if (Check1.getState())
{ 
    var mySelection = Trim(CustomersRecord_BillingRegion.getSelectedText())

    // Make sure the selection is available
    for (var i = 0; i < CustomersRecord_ShipRegion.getCount(); i++)
    {
        CustomersRecord_ShipRegion.setSelectedByPosition(i)
         if (Trim(CustomersRecord_ShipRegion.getSelectedText()) == mySelection) 
        {
            CustomersRecord_ShipRegion.setSelectedByText(mySelection)
            break
        }
    }
}
 }
function _Check1__onClick() { if (Check1) return Check1.onClick(); }
function ImageButton2_onClick() {
// We do not call onSubmit() with this contract

var formObj = getForm()
if (formObj != null)
{
var addChar = "?" 
var j
var Result
var okToSubmit = false

if ("".length > 1)
{
    formObj.action = subAwithBinC(" ", "%20", "")
}

// We have to
// put the source in the query string so the generic database contracts
// still work.

// NOTE: this only works if the method of the form is POST

act = formObj.action
if (act.indexOf("?") != -1)
{    
    addChar = "&"
}

act += addChar + "ImageButton2=1"
formObj.action = act


if ("1" == "1")
{
    Result = Validate("0"); // don't stop on first error
    if (Result == "") okToSubmit = true;
    else alert("The form could not be submitted:" + Result);
}
else 
{
    okToSubmit = true
}


if (okToSubmit) formObj.submit();
}
 }
function _ImageButton2_onClick() { if (ImageButton2) return ImageButton2.onClick(); }


