function spawnWindow(url, windowname, attributes, mainwindowname) {
  remote = window.open(null,windowname, attributes);
  remote.location = url;
  remote.focus();
  if (remote.opener == null) {
    remote.opener = window;
  }
  if (remote.opener.name == null){
  remote.opener.name = mainwindowname;
  }
}

function spawnMTpicWindow() {
  help = spawnWindow(
    "/metaltyperpic.html",
    "typerpic",
    "width=380,height=600,screenX=5,screenY=5,top=5,left=5,resizable=yes,toolbar=no,scrollbars=yes",
    "atwmain");
}

function mutipleCoins() {
  alert("I'll do multiple coins with the same message, but I have to charge for it.\n\n It's not fun, I get really bored, and I start to make mistakes.\n\nIf you really want/need a bunch of coins with the same message, you'll have to make a donation of at least $5 each.");
}


function isBlank(s) {
  if (s==null || s=='http://') {return true;}
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\r')) {return false;}
  }
  return true;
}
function isProperTyperMessage(string) {
    return (string.search(/^[0-9a-zA-Z.& ]*$/) != -1);
}

function hasASpace(string) {
    return (string.search(/([a-zA-Z.&-]+ [a-zA-Z.&-]+)/) != -1);
}

function confirmMessageLength(message)
{
 if (message.length == 32 && message.charAt(31) != " ") {
	var agree=confirm("Your message has 32 characters and the end will run into the beginning, if this is what you want, click \"OK\".");
	if (agree)
		return true ;
	else
		return false ;
 } else {
    return true ;
 }
}


function isReady(form) {

  if (isBlank(form.message.value)) {
    alert("If you don't enter a message for the coin, I can't send one.");
    form.message.focus();
    return false;
  }
    if (isProperTyperMessage(form.message.value) == false) {
    alert("You put some bad characters in your message.\nOnly letters, numbers, space, period, or ampersand are allowed.\nTake a look at the picture, fer cryin' out loud.");
    form.message.focus();
    return false;
  }
    if (hasASpace(form.name.value) == false) {
    alert("You're asking me to send something through the mail. Please include your last name. Sheesh.");
    form.name.focus();
    return false;
  }
  if (isBlank(form.address.value)||isBlank(form.city.value)||isBlank(form.state.value)||isBlank(form.code.value)||isBlank(form.email.value)||isBlank(form.instructions.value)) {
    var inputs = $('mtform').getInputs();
    inputs.each(function(item) {
       CheckValue(item)
     });
    CheckValue(form.instructions);

    alert("If you don't fill out everything, I can't send you a coin.");
    return false;
  }
   if (confirmMessageLength(form.message.value)) {
    return true;
   } else {
    return false;
   }
  
}

function ClearForm(input) {
  input.value = '';
  input.style.backgroundColor = 'rgb(255, 255, 255)';
}

function CheckValue(input) {
  if (input.value == '') {
  	input.value = input.defaultValue;
  	new Effect.Highlight(input, { startcolor: '#ffffff',endcolor: '#ffff00', restorecolor: '#ffff00' }); 
  } else {
    input.style.backgroundColor = 'rgb(255, 255, 255)';
  }
}
