// Support Script (814)
function AddToValidateArray(strElementName)
{
    var strName = strElementName

    if (!document.ValidateArray) 
    {
        document.ValidateArray = new Array
    }

    document.ValidateArray[document.ValidateArray.length] = strName
}

// Support Script (582)
function ValidateNonBlank()
{
  var msg = "";
  var val = this.getText();  

  if (StripChars(" \n\t\r",val).length == 0)
  {
    if (Trim(this.ErrorMsg) != "")
      msg = "Required field. " + this.ErrorMsg
    else
      msg = "Required field. Please enter an appropriate value."
  }

  return msg;
}

// Support Script (815)
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 (576)
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 (808)
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 (813)
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;

}
function document_onLoad() {
EmailSignDB_FirstName.Validate=ValidateNonBlank;
EmailSignDB_FirstName.ErrorMsg = "You must provide your First Name"
AddToValidateArray("EmailSignDB_FirstName")
EmailSignDB_LastName.Validate=ValidateNonBlank;
EmailSignDB_LastName.ErrorMsg = "You must provide your Last Name"
AddToValidateArray("EmailSignDB_LastName")
EmailSignDB_Title.Validate=ValidateNonBlank;
EmailSignDB_Title.ErrorMsg = "You must provide your title"
AddToValidateArray("EmailSignDB_Title")
EmailSignDB_Company.Validate=ValidateNonBlank;
EmailSignDB_Company.ErrorMsg = "You must provide your Company Name"
AddToValidateArray("EmailSignDB_Company")
EmailSignDB_Email.Validate = ValidateEMail;
EmailSignDB_Email.Required = Number("1");
AddToValidateArray("EmailSignDB_Email")
EmailSignDB_PhoneNumber.Validate=ValidateNonBlank;
EmailSignDB_PhoneNumber.ErrorMsg = "You must provide your phone number"
AddToValidateArray("EmailSignDB_PhoneNumber")
EmailSignDB_FaxNumber.Validate=ValidateNonBlank;
EmailSignDB_FaxNumber.ErrorMsg = "You must provide your Fax Number - If No Fax Number, Enter NONE"
AddToValidateArray("EmailSignDB_FaxNumber")
EmailSignDB_Bustype.Validate=ValidateNonBlank;
EmailSignDB_Bustype.ErrorMsg = "your must provide a Business Type"
AddToValidateArray("EmailSignDB_Bustype")
EmailSignDB_Address.Validate=ValidateNonBlank;
EmailSignDB_Address.ErrorMsg = "You must provide an address"
AddToValidateArray("EmailSignDB_Address")
EmailSignDB_City.Validate=ValidateNonBlank;
EmailSignDB_City.ErrorMsg = "You must provide your city"
AddToValidateArray("EmailSignDB_City")
EmailSignDB_State.Validate=ValidateNonBlank;
EmailSignDB_State.ErrorMsg = "You must provide your state"
AddToValidateArray("EmailSignDB_State")
EmailSignDB_Zip.Validate=ValidateNonBlank;
EmailSignDB_Zip.ErrorMsg = "Please provide a ZIP or Postal Code"
AddToValidateArray("EmailSignDB_Zip")
 }
function Form1_onSubmit() {
errorMsg = Validate("0"); // don't stop on first error

if (errorMsg != "")
    alert("The form could not be submitted:" + errorMsg);

return (errorMsg == ""); // false prevents form submission
 }
function _Form1_onSubmit() { if (Form1) return Form1.onSubmit(); }
function EmailSignDB_Insert__onClick() {
var addChar = "?" 
var j
var okToSubmit = false;

if ("".length > 1)
{
    Form1.setAction(subAwithBinC(" ", "%20", ""));
}

// execute the onSubmit() event handler and try to 
// determine if it already validated the form
Result = Form1.onSubmit();

//   If there is no onSubmithander the return value is null
//   If there is a validation handler it returns true to submit
//   or false to not submit
if (Result==null)  // there is no validation already defined
{
    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;
}
else // there is a validation already defined
{
    if (Result==true)
        okToSubmit = true;
}

if (okToSubmit) 
{
    // 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 = Form1.getAction();
    if (act.indexOf("?") != -1)
    {    
        addChar = "&"
    }

    act += addChar + "EmailSignDB_Insert=1"
    Form1.setAction(act);


    Form1.submit();
}
 }
function _EmailSignDB_Insert__onClick() { if (EmailSignDB_Insert) return EmailSignDB_Insert.onClick(); }

