/* 
 * JavaScript Library.
 * by the Edge Design Web Team
 *
 * Commented code is for multiple stays, if needed.
 */

var last_image;
var last_name;
var subnav_stay = subnav_stay;
var nav_stay = new Array();
var counter = 0;


/* field validator
 * given an array of structures that look like this:
 *   new Array(FIELD_NAME, DISPLAY_NAME [, BULLET])
 * it makes sure that those fields are filled.
 */
var BULLET = 1;

function check_fields(arr, form) {
  for (var i = 0; i < arr.length; ++i) {
    var elem = eval('document.' + form + '.' + arr[i][0]);

    if (arr[i].length == 3 && arr[i][2] == BULLET) {
      // checking bullet
      if (! elem[0].checked && !elem[1].checked) {
        alert("Please fill the '" + arr[i][1] + "' field and try again.");
        
        // focus the first element in the bullet class
        elem[0].focus();
        return false;
      }
    } else {
      if (! elem.value) {
        alert("Please fill the '" + arr[i][1] + "' field and try again.");
        elem.focus();
        return false;
      }
    }
  }
  return true;
}

/* er, not a library function */
function pop(id) {
  openWin('/performances/performer_bio.html?id='+id, 600,400,'performer');
  return(false);
}

function flam() {
  openWin('/flmplayer.html', 300, 300, 'media');
  return(false);
}

/* Image roll-over
 * Use: roll('image_name','roll_over_path'); 
 */
function roll(img_name, roll_to) {
  if (document.images) {
    for (var i=0; i<nav_stay.length; i++) {
      if (img_name == nav_stay[i]) {
        return;
      }
    }

    var obj = eval('document.' + img_name);
    last_image = obj.src;
    last_name = img_name;
    obj.src = roll_to;
  }
}

/* Always use with roll()
 * Use: roll_restore();
 */
function roll_restore() {
  if (last_image) {
    var flip_back = eval('document.' + last_name);
    flip_back.src = last_image;
  }
}
		
/* Forces an image to stay rolled-over
 * Use: stay('image_name','roll_over_path);
 */
function stay(img_name, stay_url) {
  if (document.images) {
    nav_stay[counter++] = img_name;
    var tmp = eval('document.' + img_name);
    tmp.src = stay_url;
  }
}

/* Preloads images
 * Use: preload('path_to_image','path_to_image',...etc);
 */
function preload() {
  if (document.images) {
    var img = preload.arguments;
    var tmp = new Array(img.length);

    for (var i=0; i<tmp.length; i++) {
      tmp[i] = new Image;
      tmp[i].src = img[i];
    }
  }
}

/* Automatic redirect from a pull-down
 * Use: launch(this)
 */
function launch(current) {
  var index = current.selectedIndex;
  var select_name = current.name;
  var form_name = current.form.name;
  var pull = eval('document.'+form_name+'.'+select_name);

  if (pull.options[index].value != '#')
    window.location = pull.options[index].value;

  return;
}

/* Grabs a value from the query parameter string */
function getValue(elm) {
  var url = window.location + '&';
  var regex = new RegExp(elm + "=([^&]+)","i");
  var theValue = regex.exec(url);

  if (theValue) {
    var temp = theValue[1].replace( /\+/g, " " );

    theValue[1] = unescape(temp);
    return theValue[1];
  }
  else
    return(false);
}

/* Opens and focuses a popup window at the given URL, coords and name */
function openWin(url,width,height,name) {
  if (!width)
    width = 425;
  if (!height)
    height = 400;
  if (!name)
    name = 'help';

  open(url, name, 'screenX=50,screenY=50,width=' + width +
                  ',height=' + height + ',scrollbars,resizable').focus();
}

