//#############################
//#  Copyright 2004-2008 Kimball Jensen
//#  Kimball's eCommerce Software (KES_v4_0)
//#  Version 2.0 November 12, 2005
//#  Version 3.0 August 09, 2006
//#  Version 3.1 October 01, 2006
//#  Version 4.0 July 26, 2008
//#    significant changes in v4 include mushoo, improved ppbin, no double payments, helpdesk client, ctm
//#
//#############################
//# PATCHES / ENHANCEMENTS:
//#
//#
//#
//#############################
//#
//# USER REQUESTED CHANGES:
//#
//#
//#############################

  function escapeText () {
    document.activity_form.note.value = escape (document.activity_form.note.value);
  }

  function escapeText2 () {
//    document.ccForm.note.value = escape (document.ccForm.note.value);
//    document.ccForm.instructions.value = escape (document.ccForm.instructions.value);
  }

function charAlert(e) {
	var maxlength = 1500;
	if(e.value.length > maxlength) {
		e.value= e.value.substring(0,maxlength)
		e.blur()
		alert("Please limit your message to 1500 characters or less.")
    }

}

function updateCharCount(cc,m,maxc) {
  if (m.value.length > maxc) {
    m.value = m.value.substring(0, maxc);
  } else {
    cc.value = maxc - m.value.length;
  }
}

function validateSig(theForm)
{
    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=siteErrorPage";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=siteErrorPage";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

  function isEmailAddr(email)
  {
    var result = false;
    var theStr = new String(email);
    var index = theStr.indexOf("@");
    if (index > 0)
    {
      var pindex = theStr.indexOf(".",index);
      if ((pindex > index+1) && (theStr.length > pindex+1))
      result = true;
    }
    return result;
  }
  
  function validRequired(formField,fieldLabel)
  {
      var result = true;
      if (formField.value == "")
      {
          alert('Please enter a value for the "' + fieldLabel +'" field.');
          formField.focus();
          result = false;
      }
      
      return result;
  }
  
  function allDigits(str)
  {
      return inValidCharSet(str,"0123456789");
  }
  
  function inValidCharSet(str,charset)
  {
      var result = true;
  
      // Note: doesn't use regular expressions to avoid early Mac browser bugs    
      for (var i=0;i<str.length;i++)
          if (charset.indexOf(str.substr(i,1))<0)
          {
              result = false;
              break;
          }
      
      return result;
  }
  
  function inForbiddenCharSet(formField, fieldLabel, charset)
  {
	var result = false;
	var badChar = "";
    for (var i=0;i<formField.value.length;i++)
        if (!(charset.indexOf(formField.value.substr(i,1))<0))
        {
            result = true;
			badChar = formField.value.substr(i,1);
			if (badChar == " ")
				badChar = "space character";
			alert ('The "'+fieldLabel+'" field cannot contain the following character:  \n'+badChar);
		    formField.focus();
            break;
        }
	 return result;
  }

  function validEmail(formField,fieldLabel,required)
  {
      var result = true;
  	if (required && !validRequired(formField,fieldLabel))
          result = false;
  
      if (result && (formField.value.length > 0) && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
      {
          alert("Please enter a complete email address in the form: yourname\@yourdomain.com");
          formField.focus();
          result = false;
      }
     
    return result;
  }
  
  function validEmail_dupeCheck(formField,fieldLabel,formField2,fieldLabel2,required)
  {
      var result = true;
  	if (required && !validRequired(formField,fieldLabel))
          result = false;
  
      if (result && (formField.value != formField2.value) )
      {
          alert("The email addresses you supplied are not the same.\n\nPlease review the email addresses and fix the incorrect one.");
          formField.focus();
          result = false;
      }
     
    return result;
  }
  
function validateCustomerProfile_hd(theForm)
{
	if (theForm.password) {
		if (theForm.password.value != '') {

			if (inForbiddenCharSet(theForm.password, "Password", "\'\"\$\%"))
			    return false;

			if ((!validRequired(theForm.newPassword, "New Password")) || (inForbiddenCharSet(theForm.newPassword, "New Password", "\'\"\$\%")))
			    return false;

			if ((!validRequired(theForm.newPassword2, "Retype New Password")) || (inForbiddenCharSet(theForm.newPassword2, "Retype New Password", "\'\"\$\%")))
			    return false;

			if (theForm.newPassword.value != theForm.newPassword2.value) {
				alert ("New Passwords do not match");
				return false;
			}
		}
	}

    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }

    return true;
}

function validateMessage(theForm)
{

  if (theForm.message.value.length > 1500) {
		alert("Please limit your message to 1500 characters or less.")
        return false;
  }
  return true;
}

//-->
