﻿function isValidEmailAddress(field) {
  if (window.RegExp) {
	var email = field.value;
	if (email.match($.regexpCommon('email'))) {
      return true;
    } else {
      alert('Please enter a valid address.');
      field.focus();
      field.select();
      return false;
    }
  } else {
	if(str.indexOf("@") >= 0) {
	  return true;
    } else {
      alert('Please enter a valid address.');
	  field.focus();
	  field.select();
	  return false;
	}
  }
}

function mailThisUrl() {
    var pageUrl = window.location;
    var emailTextBox = document.getElementById('emailTextBox');
    if (isValidEmailAddress(emailTextBox)) {
        var initialSubj = "Choose Central";
        var initialMsg = "\n" + emailTextBox.value + " thought you might like this site " + pageUrl;
        //alert("mailto:"+ emailTextBox.value + "?subject=" + initialSubj + "&body=" + initialMsg);
        window.location = "mailto:" + emailTextBox.value + "?subject=" + initialSubj + "&body=" + initialMsg;
        return false;
    } else {
        return false;
    }
}

function search() {
  if (document.getElementById) {
    var search = document.getElementById('searchTextBox').value;
    window.location = "search.aspx?q=" + search;
    return false;
  }
}

function search2() {
    if (document.getElementById) {
        var search = document.getElementById('searchTextBox').value;
        window.location = "/search.aspx?q=" + search;
        return false;
    }
}

function subscribe() {
  if (document.getElementById) {
    if (isValidEmailAddress(document.getElementById('subscriberTextBox'))) {
	  var email = document.getElementById('subscriberTextBox').value;
      window.location = "subscribe.aspx?e=" + encodeURIComponent(email);
    }
    return false;
  }
}