// swap button images
function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}

// pop up a sized window (no scrollbar)
function popUpWindow( pageURL, winName, width, height) {
    xpos = (screen.width - width) / 2;
    ypos = (screen.height - height) / 2;
    window.open(
        pageURL,
        winName,
        "width=" + width + "," +
        "height=" + height + "," +
        "screenx=" + xpos + "," + //ns
        "screeny=" + ypos + "," + //ns
        "left=" + xpos + "," + //ie
        "top=" + ypos + "," + //ie
        "resizable=1" + "," +
        "scrollbars=1");
}

// pop up a sized window (with scrollbar)
function popUpWindowNoScroll( pageURL, winName, width, height) {
    xpos = (screen.width - width) / 2;
    ypos = (screen.height - height) / 2;
    window.open(
        pageURL,
        winName,
        "width=" + width + "," +
        "height=" + height + "," +
        "screenx=" + xpos + "," + //ns
        "screeny=" + ypos + "," + //ns
        "left=" + xpos + "," + //ie
        "top=" + ypos + "," + //ie
        "resizable=0" + "," +
        "scrollbars=0");
}

// validate form elements
function validateForm(field, validateType) {
  if (validateType == 'email') {
    if (!(isEmail(field.value))) {
      alert("Please enter a valid email address.");
      field.focus();
      field.blur();
      field.select();
    }
  } else {
    if ( (validateType == 'number') && isNaN(field.value) ) { 
      alert("Please enter a valid number.") 
      field.focus();
      field.blur();
      field.select();
    }
  }
}

// make sure an email is valid (syntactically at least)
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

// go to some URL
function go(theURL) {
  location = eval("'"+theURL+"'");
}

// Get a cookie.
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// Set a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// Delete a cookie
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
	