var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = 'This image is protected by copyright.\nWe request that you do not copy it.';
var x,y,x1,y1,copyAttempt;

function copyInit()
{
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}

function openBox(group) {
	document.all.item(group).style.display = "inline";
}

function closeBox(group) {
	var group_open = group + "_open"
	var group_closed = group + "_closed"
	document.all.item(group_closed).style.display = "inline";
	document.all.item(group_open).style.display = "none";
}

     function rollover(loadImg)
     {
     // prevent this routine from running twice
     if (! loadImg.outImg)
        {
        // set src of the "on" image
        g = loadImg.src;
        gHolder = g.substring(0,(g.length-5))
        newOverImg = gHolder+"1.jpg";
        
        loadImg.outImg = new Image();
        loadImg.outImg.src = loadImg.src;
        loadImg.onmouseout=mouseOut;
        
        // set the src of the "over" image
        loadImg.overImg = new Image();
        loadImg.overImg.src = gHolder+"2.jpg";
        loadImg.onmouseover=mouseOver;
        }
     }
     
     // event handler for OnMouseOut
     function mouseOut()
        {this.src = this.outImg.src;}
     
     // event handler for OnMouseOver
     function mouseOver()
        {this.src = this.overImg.src;}

// Clear out the form elements
function clearMe(x){
	if (x.value == "you@email.com"){
		x.value = ""
		x.focus()
	}
}

// Rollover scripts

	function flipIt(x,y){
		myImage = new Image()
		myImage.src = "gfx/s"+y+"-"+x+".gif"
		document[y].src = myImage.src
		
		// FOR IE ONLY
		//g = eval(y+"t")
		//if (document.g != "undefined"){
		//	g.style.color='white'
		//}
		
	}
	function flipOut(x,y){
		myImage = new Image()
		myImage.src = "gfx/"+y+"-"+x+".gif"
		document[y].src = myImage.src
		
		//FOR IE ONLY
		//g = eval(y+"t")
		//if (document.g != "undefined"){
		//	g.style.color='CAC6EF'
		//}
		
	}

// SCRIPT FOR SUPPORT FORM VALIDATION

var defaultEmptyOK = false;

// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

var mPrefix = "You did not enter a value into the \"";
var mSuffix = "\" item. This item is required. Please enter it now.";

var iPrefix = "The item named \"" 
var iEmailSuffix = "\" must be a valid email address (such as info@angelrockproject.org). Please reenter it.";
var iAlphanumericSuffix = "\" must contain a valid alphanumeric string. Please reenter it.";
var iAlphabeticSuffix = "\" must contain a valid alphabetic string. Please reenter it.";
var iNumberSuffix = "\" must contain a valid number. Please reenter it.";
var iSelectPrefix = "You have not filled one of the required fields.  \nPlease select one of the options for the item named \"";
var iSelectSuffix = "\"";
var iRadioPrefix = "You have not filled one of the required fields.  \nPlease select one of the buttons for the item named \"";
var iRadioSuffix = "\"";

// regular expressions used for checking fields 

// Email Address
// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by ., 
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/

// BOI, followed by one or more whitespace characters, followed by EOI.
var reWhitespace = /^\s+$/;

// Alphanumeric fields
// BOI, followed by one or more lower or uppercase English letters
// or digits, followed by EOI.
var reAlphanumeric = /^[a-zA-Z0-9 ]+$/

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^[\d ]+$/

// BOI, followed by one or more lower or uppercase English letters, 
// followed by EOI.
var reAlphabetic = /^[a-zA-Z ]+$/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}

// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   theField.focus();
    alert(mPrefix + s + mSuffix);
    return false;
}


// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus();
    theField.select();
    alert(s);
    return false;
}

function warnMustFill (theField, s) {   
   theField.focus();
   alert(s);
   return false;
}

/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkString (theField, s, emptyOK) {   
    // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

// ********************** Email field testing ***************
// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required

function isEmail (s)

{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    
    else {
       return reEmail.test(s)
    }
}

// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    else {
       return reAlphanumeric.test(s)
    }
}


// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
function isAlphabetic (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    else {
       return reAlphabetic.test(s)
    }
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
function checkEmail (theField, message, emptyOK)
{   if (checkEmail.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, message); 
    else return true;
}

// check alphanumeric (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid alphanumeric string.
//
function checkAlphanumeric (theField, message, emptyOK)
{   if (checkAlphanumeric.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isAlphanumeric(theField.value)) 
       return warnInvalid (theField, message);
    else return true;
}

// checkAlphabetic (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid alphabetic string.
//
function checkAlphabetic (theField, message, emptyOK)
{   if (checkAlphabetic.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isAlphabetic(theField.value)) 
       return warnInvalid (theField, message);
    else return true;
}

// checkNumber (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid number string.
//
function checkNumber (theField, message, emptyOK)
{   if (checkNumber.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isInteger(theField.value)) 
       return warnInvalid (theField, message);
    else return true;
}

// checkRequiredSelect (SelectField theField)
//
// Check that option theField.value is filled by user
//
function checkRequiredSelect(theField, message) {
   if (theField.options[theField.options.selectedIndex].value == "$$$$$") 
      return warnMustFill(theField, message);
   else return true;
}

function checkRequiredRadio(theField, message) {
   if (!theField.checked) 
      return warnMustFill(theField, message);
   else return true;

}

// check form element values before submitting 
// if all fields look good return true so that the form can be submitted
function CheckFormFJC(theForm, fes) {
   // first check that all "required" fields are filled
   for (i = 0; i < theForm.elements.length; i++) {
      if (typeof(fes[theForm.elements[i].name]) == "undefined") {
	  continue;
      }
      if (fes[theForm.elements[i].name].required == 1) {
         if (fes[theForm.elements[i].name].type == "text") {
//	    if (!checkString(theForm.elements[i], 
//	                     theForm.elements[i].name, false)) 
	    if (!checkString(theForm.elements[i], 
	                     fes[theForm.elements[i].name].desc, false)) 
	       return false;
	 } else if (fes[theForm.elements[i].name].type == "select") {
	    if (!checkRequiredSelect(theForm.elements[i], iSelectPrefix + fes[theForm.elements[i].name].desc+iSelectSuffix)) return false;
	 } else if (fes[theForm.elements[i].name].type == "radio") {
            var radiochecked = theForm.elements[i].checked;
	    var radioname = theForm.elements[i].name;
	    var j = i+1;
            while (j < theForm.elements.length) {
	       if (theForm.elements[j].type == "radio" &&
	           theForm.elements[j].name == radioname) {
		  if (!radiochecked) radiochecked = theForm.elements[j].checked;
	          j++;
	       } else 
		  break;	// reached end of radio button sequence
	    }
	    if (!radiochecked) 
	       return warnMustFill(theForm.elements[i], iRadioPrefix + fes[theForm.elements[i].name].desc+iRadioSuffix);
	    i = j  - 1;
	 }
      }
   }

   // now check the contents of all fields that require tests
   for (i = 0; i < theForm.elements.length; i++) {
      if (typeof(fes[theForm.elements[i].name]) == "undefined") {
         continue;
      }
      if (fes[theForm.elements[i].name].ctype == "Alphabetic") {
	    if (!checkAlphabetic(theForm.elements[i],
				 iPrefix + fes[theForm.elements[i].name].desc + iAlphabeticSuffix, 
	                         (fes[theForm.elements[i].name].required == 1) ?
	                          false : true))
	       return false;
      } else if (fes[theForm.elements[i].name].ctype == "Alphanumeric") {
	    if (!checkAlphanumeric(theForm.elements[i], 
				   iPrefix + fes[theForm.elements[i].name].desc + iAlphanumericSuffix,
	                           (fes[theForm.elements[i].name].required == 1) ?
	                            false : true))
	       return false;
      } else if (fes[theForm.elements[i].name].ctype == "Number") {
	    if (!checkNumber(theForm.elements[i],
			     iPrefix + fes[theForm.elements[i].name].desc + iNumberSuffix,
	                     (fes[theForm.elements[i].name].required == 1) ?
	                      false : true))
	       return false;

      } else if (fes[theForm.elements[i].name].ctype == "Email") {
	    if (!checkEmail(theForm.elements[i], 
			    iPrefix + fes[theForm.elements[i].name].desc + 
				iEmailSuffix, 
	                    (fes[theForm.elements[i].name].required == 1) ?
	                     false : true))
	       return false;
      } else if (fes[theForm.elements[i].name].ctype == "None") {

      }
   }

   //theForm.submitTime.value=new Date();

   return true;
}

function formelement(req, typ, contentt, flddesc) {
   this.required = req;			// is this a required item?
   this.ctype = contentt;
					// is content numeric, alphabetic etc.
					// applies only to text item fields
					// possible values are "Alphabetic", "Number", 
					//       "Alphanumeric", "Email", "None"
   this.type = typ;			// what is the type of this item
					// "text", "select", "radio"
   this.desc = flddesc;			// descriptive string for item
   return this;
}

/*
BrowserDetector()
Parses User-Agent string into useful info.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Richard Blaylock
Author Email: blaylock@wired.com

Usage: var bd = new BrowserDetector(navigator.userAgent);
*/


// Utility function to trim spaces from both ends of a string
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}

function BrowserDetector(ua) {

// Defaults
  this.browser = "Unknown";
  this.platform = "Unknown";
  this.version = "";
  this.majorver = "";
  this.minorver = "";

  uaLen = ua.length;

// ##### Split into stuff before parens and stuff in parens
  var preparens = "";
  var parenthesized = "";

  i = ua.indexOf("(");
  if (i >= 0) {
    preparens = Trim(ua.substring(0,i));
        parenthesized = ua.substring(i+1, uaLen);
        j = parenthesized.indexOf(")");
        if (j >= 0) {
          parenthesized = parenthesized.substring(0, j);
        }
  }
  else {
    preparens = ua;
  }

// ##### First assume browser and version are in preparens
// ##### override later if we find them in the parenthesized stuff
  var browVer = preparens;

  var tokens = parenthesized.split(";");
  var token = "";
// # Now go through parenthesized tokens
  for (var i=0; i < tokens.length; i++) {
    token = Trim(tokens[i]);
        //## compatible - might want to reset from Netscape
        if (token == "compatible") {
          //## One might want to reset browVer to a null string
          //## here, but instead, we'll assume that if we don't
          //## find out otherwise, then it really is Mozilla
          //## (or whatever showed up before the parens).
        //## browser - try for Opera or IE
    }
        else if (token.indexOf("MSIE") >= 0) {
      browVer = token;
    }
    else if (token.indexOf("Opera") >= 0) {
      browVer = token;
    }
        //'## platform - try for X11, SunOS, Win, Mac, PPC
    else if ((token.indexOf("X11") >= 0) || (token.indexOf("SunOS") >= 0) ||
(token.indexOf("Linux") >= 0)) {
      this.platform = "Unix";
        }
    else if (token.indexOf("Win") >= 0) {
      this.platform = token;
        }
    else if ((token.indexOf("Mac") >= 0) || (token.indexOf("PPC") >= 0)) {
      this.platform = token;
        }
  }

  var msieIndex = browVer.indexOf("MSIE");
  if (msieIndex >= 0) {
    browVer = browVer.substring(msieIndex, browVer.length);
  }

  var leftover = "";
  if (browVer.substring(0, "Mozilla".length) == "Mozilla") {
    this.browser = "Netscape";
        leftover = browVer.substring("Mozilla".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Lynx".length) == "Lynx") {
    this.browser = "Lynx";
        leftover = browVer.substring("Lynx".length+1, browVer.length);
  }
  else if (browVer.substring(0, "MSIE".length) == "MSIE") {
    this.browser = "IE";
    leftover = browVer.substring("MSIE".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Microsoft Internet Explorer".length) ==
"Microsoft Internet Explorer") {
    this.browser = "IE"
        leftover = browVer.substring("Microsoft Internet Explorer".length+1,
browVer.length);
  }
  else if (browVer.substring(0, "Opera".length) == "Opera") {
    this.browser = "Opera"
    leftover = browVer.substring("Opera".length+1, browVer.length);
  }

  leftover = Trim(leftover);

  // # Try to get version info out of leftover stuff
  i = leftover.indexOf(" ");
  if (i >= 0) {
    this.version = leftover.substring(0, i);
  }
  else
  {
    this.version = leftover;
  }
  j = this.version.indexOf(".");
  if (j >= 0) {
    this.majorver = this.version.substring(0,j);
    this.minorver = this.version.substring(j+1, this.version.length);
  }
  else {
    this.majorver = this.version;
  }

} // 

function getRandom() {
  var randomNum = Math.random() * 37423535353578 + 1;
  randomNum = parseInt(randomNum);
  if(isNaN(randomNum)) randomNum = 0; // for Netscape
  return randomNum;
}

