/**
 * $Id: pinchy.js,v 1.18 2008/09/09 17:14:12 jar2 Exp $
 * Copyright (c) 2003-2008 Carnegie Mellon University.
 */
var ctx;

// Open locate user dialog, remember the result form field
function locateUser(id) {
  var href = ctx + "/common/user/criteria.do?field=" + id;
  openSmWin(href, "locate_user");
}

// Open locate user dialog, remember the result form field
function locateUserInSection(id, section) {
    var href = ctx + "/common/user/criteria.do?field=" + id+"&section="+section;
    openSmWin(href, "locate_user");
}

// Open locate course dialog, remember the result form field
function locateCourse(id) {
  var href = ctx + "/common/course/criteria.do?field=" + id;
  openMdWin(href, "locate_course");
}

// Swap specified image with the one given
function swapImage(id, img) {
  var imgElem = document.getElementById(id);
  var base = imgElem.src.substring(0, imgElem.src.lastIndexOf("/"));
  imgElem.src = base + "/" + img;
}

// Select result, place result in specified form field, close the window
function selectResult(id, result) {
  window.opener.document.getElementById(id).value = result;
  window.close();
}

// Clears an input field
function clearField(elem) {
  if (elem.value == elem.title) elem.value = "";
}

// Gets the value of a cookie
function OLIgetCookieValue(name) {
  var retVal = "";
  if(document.cookie.length > 0) {
    indx = document.cookie.indexOf(name + "=");
    // If exists
    if(indx != -1) {
      indx += name.length + 1;
      end = document.cookie.indexOf(";", indx);
      if(end == -1) {
        end = document.cookie.length;
      }
      retVal = decodeURI(document.cookie.substring(indx,end));
    }
  }
  return retVal;
}

// Sets a cookie
function OLIsetCookie(n,v) {
  document.cookie=n+"="+encodeURI(v)+"; path=/;";
}
