// Thanks to Bill Dortch, Idaho Design (bdortch@netw.com)

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" : "");
}

if(GetCookie("newsName") != null)
document.write("<b>:: Email Check ::</b><br><br>Is your email address still the following:<br><br><center>" + GetCookie('newsName') + "</center><br>If it\'s changed, let me know by <a href=\"mailto:hczeiger@forbat.com.au?subject=My email address has changed&body=My old address was " + GetCookie('newsName') + ".%0D%0DMy new address is: \" title=\"Email me your new details\" onMouseOver=\"window.status=\'Email me your new details\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\">email</a> and I'll make the adjustment to the Mailing List.<br><br><br>");
else {
document.write("<b>:: Enter Email ::</b><br><br>Type your email address in the box below to subscribe to our quarterly <a href=\"/news/newsletter.html\" title=\"Click here to see the latest issue\" onMouseOver=\"window.status=\'Click here to see the latest issue\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\">Newsletter</a>.<br>");
document.write("<form style=\"margin:0px;margin-top:6px;\" name=\"email\"><input TYPE=\"hidden\" name=\"mailformToEmail\" value=\"design@grafx.com.au\"><input type=\"radio\" name=\"emailType\" value=\"html\" checked style=\"width:12px;height:16px;\">&nbsp;HTML&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"emailType\" value=\"plainText\" style=\"width:12px;height:16px;\">&nbsp;Plain Text<br><input type=\"text\" name=\"mailformFromEmail\" style=\"width:126px;background-color:#f5f5f5;color:#333333;font-family:verdana,arial,sans serif;font-size:10px;\">&nbsp;<input type=\"submit\" value=\"OK\" style=\"width:26px;background-color:#f5f5f5;color:#333333;font-family:verdana,arial,sans serif;font-size:10px;\" maxlength=\"99\" onClick = \"javascript:check()\"><\/form><br><br>");
	// document.write("<form style=\"margin:0px;margin-top:6px;\" name=\"email\" action=\"\http:\/\/www.forbat.com.au/cgi-bin\/mailform.pl\" method=\"post\"><input TYPE=\"hidden\" name=\"mailformToEmail\" value=\"design@grafx.com.au\"><input TYPE=\"hidden\" name=\"mailformToname\" value=\"Harry Czeiger\"><input TYPE=\"hidden\" name=\"mailformFromname\" value=\"Forbat Web Site\"><input TYPE=\"hidden\" name=\"mailformSubject\" value=\"e_Newsletter Subscription\"><input TYPE=\"hidden\" name=\"mailformURL\" value=\"http:\/\/www.forbat.com.au\/thanks.html\"><input type=\"radio\" name=\"emailType\" value=\"html\" checked style=\"width:12px;height:16px;\">&nbsp;HTML&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"radio\" name=\"emailType\" value=\"plainText\" style=\"width:12px;height:16px;\">&nbsp;Plain Text<br><input type=\"text\" name=\"mailformFromEmail\" style=\"width:126px;background-color:#f5f5f5;color:#333333;font-family:verdana,arial,sans serif;font-size:10px;\">&nbsp;<input type=\"submit\" value=\"OK\" style=\"width:26px;background-color:#f5f5f5;color:#333333;font-family:verdana,arial,sans serif;font-size:10px;\" maxlength=\"99\" onClick = \"javascript:check()\"><\/form><br><br>");
document.email.mailformFromEmail.focus();
}

function Highlight(){
document.email.mailformFromEmail.focus();
document.email.mailformFromEmail.select();
}
function check(){
var emailbox = document.email.mailformFromEmail;
var email = document.email.mailformFromEmail.value;
var blanks = ''*100;
var naughty = new Array("arse","bastard","cunt","fuck","shit","wanker","piss","twat","bollocks","ass");
var sneaky = email.toLowerCase();
var illegal = "You have entered illegal characters.\nOnly characters listed here allowed.\n\nLetters of Alphabet [lower and upper case]\nNumbers\nOne @ symbol only\nFull stops\nHyphens [Minus sign]\nUnderscores\n\n";
//mail check
if (email <= blanks){
  alert("Please enter your e-mail address.");
  Highlight();return false;
  }
else if (email.length > 100){
   alert('Max character length for any e-mail address is 99.');
   Highlight();return false;
   }
else if (email.charAt(0) == " "){
   alert('You have typed a space at the START of your e-mail address');
   Highlight();return false;
   }
else if (email.charAt(email.length-1) == " "){
   alert('You have typed a space at the END of your e-mail address');
   Highlight();return false;
   }
else if (email.indexOf(" ") !=-1){
   alert('You have typed a space IN your e-mail address');
   Highlight();return false;
   }

//CHECK FOR ILLEGAL CHARACTERS 1
for (i=0; i < email.length; i++){
var caps = "a".toUpperCase();
var E = email.substring(i, i + 1);
if ((E < "0" || "9" < E ) && E != "@"  && E !="." && E !="-"  && E !="_"  &&  E < caps || "z" < E){
 alert(illegal);
 Highlight();return false;
 }
}
//CHECK FOR ILLEGAL CHARACTERS 2
if ((email.indexOf('`',0) != -1) || (email.indexOf(String.fromCharCode(94)) != -1) || (email.indexOf(String.fromCharCode(92)) != -1) || (email.indexOf('[',0) != -1) || (email.indexOf(']',0) != -1)){
 alert(illegal);
 Highlight();return false;
}
//CHECK FOR SWEARING
for (i=0; i < email.length; i){
 if (sneaky.indexOf(naughty[i]) != -1){
 alert('Please remove the swear word - '+naughty[i].toUpperCase());
 Highlight();return false;
 }
i++;
}
//GENERAL FORMATING
if (email.charAt(0) =="."){
 alert('An e-mail address cannot start with a full stop');
 Highlight();return false;
}
else if (email.split('@').length > 2){
 alert('Only 1 @ allowed in e-mail address.');
 Highlight();return false;
}
else if (email.indexOf ('@',0) == -1){
 alert("The @ symbol is missing");
 Highlight();return false;
}
else if (email.indexOf("@") < 2){
 alert("There must be at least 2 characters before @ symbol.");
 Highlight();return false;
}
else if (email.charAt(email.length-1) == "@"){
 alert('An e-mail address cannot finnish with @');
 Highlight();return false;
}
else if (email.indexOf ('.') == -1){
 alert("An e-mail address must contain at least 1 full stop");
 Highlight();return false;
}
else if (email.indexOf('.',email.indexOf('@')) == -1){
 alert('The full stop after the @ is missing');
 Highlight();return false;
}
else if (email.substring(email.indexOf('@'),email.length).indexOf(".") < 4){
 alert('There must be at least 3 characters between @ and following full stop');
 Highlight();return false;
}
else if (email.lastIndexOf(".")+2 == email.length){
 alert('There must be at least 2 characters after last full stop');
 Highlight();return false;
}
else if (email.substring(email.lastIndexOf("."),email.length).length > 4){
 alert('Only 3 characters allowed after last full stop');
 Highlight();return false;
}
else if (email.charAt(email.length-1) =="."){
 alert('An e-mail address cannot finnish with a full stop');
 Highlight();return false;
}
set_name(this.form)
}

function set_name(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
var username = email.mailformFromEmail.value;
if (username != "") {
	SetCookie ("newsName", username, expdate, "/");
	for (var i=0;i<2;i++) {
	if (eval("email.emailType[0].checked") == true) { SetCookie ("type", "html", expdate, "/"); }
	else { SetCookie ("type", "plainText", expdate, "/"); }
	}
// Turn this back off when you plug in the CGI
window.location.href="thanks.html";
}
}