function getCookieVal (offset) {
  var endstr = document.cookie.indexOf(";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
  function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
    break;
  }
  return null;
}
  function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = "/"; //(argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" +
  expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

var emailcookie = GetCookie('email_address');
if (emailcookie == null) {
  emailcookie = ' e-mail address';
}

// New from Dan Tuesday, October 31, 2006
function checkWinGen(winName,winVar,features) {
  if (!features) features = "height=320,width=780,titlebar=no,resizable=yes,scrollbars=yes";
  window[winVar] = window.open('',winName,features);
  if (window[winVar].focus) {
    window[winVar].focus();
  }
}
// End new from Dan

function chk(email, formname) {
  invalid = "";
  if (!email)
    invalid = "No email address found!  Try reloading the page then use the 'email a script' feature again.";
  else {
    if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
    invalid += "\n\nInvalid email address.  Your email address is missing an '@' sign and a '.' in the domain name (like '.com').  Please check your address then submit again.";
    if (email.indexOf(" e-mail address") > -1)
    invalid += "\n\nInvalid email address.  Make sure your email address included your username, the '@' sign, and the domain name (like '.com').";
    if (email.indexOf("\\") > -1)
    invalid += "\n\nEmail address contains an invalid back-slash (\\) character.  Remove the character and submit again.";
    if (email.indexOf("/") > -1)
    invalid += "\n\nEmail address contains an invalid forward-slash (/) character.  Remove the character and submit again.";
    if (email.indexOf("'") > -1)
    invalid += "\n\nEmail address contains an invalid apostrophe (') character.  Remove the character and submit again.";
    if (email.indexOf("zaz.com.br") > -1)
    invalid += "\n\nPlease do not use an email address that has an autoresponder set up for it.  Thanks.";
    if (email.indexOf("!") > -1)
    invalid += "\n\nEmail address contains an invalid exclamation point (!) character.  Remove the character or correct the email address then submit again.";
    if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
    invalid += "\n\nPlease only enter one email address in the box at a time.  Remove the extra addresses and submit again.";
    if (email.indexOf("?subject") > -1)
    invalid += "\n\nPlease do not add '?subject=...' to your email address.  Scriptbot will send you the script with a pre-defined subject already.  Please remove the '?subject=...' from your email address and submit again.";
  }
  if (invalid == "") {
    var largeExpDate = new Date();
    largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
    SetCookie('email_address', email, largeExpDate);
    // Added new from Dan here Tuesday, October 31, 2006
    if (formname == "scriptbot") {
       checkWinGen("AdWindow",
                   "jss_sendWin",
                   "height=320,width=780,titlebar=no,resizable=yes,scrollbars=yes");
    }
    return true;
    // New from Dan ends here
  } else {
    alert("Oops, something is wrong...." + invalid);
    return false;
  }
}

function updateNewsletters() {
  with (document.forms["newslettersignup"]) {
  emailStr = email.value;
  var emailPat=/^(.+)@(.+)$/;
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; // remove   ( ) < > @ , ; : \ " . [ ]    */
  var validChars="\[^\\s" + specialChars + "\]";
  var quotedUser="(\"[^\"]*\")";
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
  var atom=validChars + '+';
  var word="(" + atom + "|" + quotedUser + ")";
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
  var matchArray=emailStr.match(emailPat);
  if (matchArray==null) {
    alert("Email address seems incorrect (check @ and .'s)");
    return false;;
  }
  var user=matchArray[1];
  var domain=matchArray[2];
  if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.");
    return false;
  }
  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) {
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
        alert("Destination IP address is invalid!");
        return false;
      }
    }
  }
  var domainArray=domain.match(domainPat);
  if (domainArray==null) {
    alert("The domain name doesn't seem to be valid.");
    return false;
  }
  var atomPat=new RegExp(atom,"g");
  var domArr=domain.match(atomPat);
  var len=domArr.length;
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
    alert("The address must end in a three-letter domain, or two letter country.");
    return false;
  }
  if (len<2) {
    var errStr="This address is missing a hostname!";
    alert(errStr);
    return false;
  }
  List_Name.value = newsletter.options[newsletter.selectedIndex].value
  		+ nltype.options[nltype.selectedIndex].value;

     var largeExpDate = new Date();
     largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
     SetCookie('email_address', emailStr, largeExpDate);

  return true;
     }
}

// ==========================
// Copy script

function copyit(theField) {
  var tempval=eval("document."+theField)
  tempval.focus()
  tempval.select()
  therange=tempval.createTextRange()
  therange.execCommand("Copy")
}

// ==========================
