﻿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 initialSubj = "Valuable Economic Development Resources";
  var initialMsg = "\n You may want to check out the Sedalia EDC site: " + pageUrl;
  var emailTextBox = document.getElementById('emailTextBox');
  if (isValidEmailAddress(emailTextBox)) {
	//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 subscribe() {
  if (document.getElementById) {
    if (isValidEmailAddress(document.getElementById('subscriberTextBox'))) {
	  var email = document.getElementById('subscriberTextBox').value;
      window.location = "subscribe.aspx?e=" + encodeURIComponent(email);
    }
    return false;
  }
}

function sort_companies() {
  if (document.getElementById) {
    if (document.getElementById('ctl00_ContentPlaceHolder1_categoryDropDownList')) {
      var catId = document.getElementById('ctl00_ContentPlaceHolder1_categoryDropDownList').selectedIndex;
      catId = catId + 1.0;
      window.location = "Companies.aspx?cat_id=" + catId;
    } else {
      window.location = "Companies.aspx";
    } 
  }
  return false;
}