
// Create global variables for browser type
var isIE = new Boolean(false);
var isNav = new Boolean(false);
var unSupported = new Boolean(false);
var layer = new String();
var style = new String();

// Determine if the browser is Internet Explorer, Navigator,
// or other. Also, set the layer variable depending on the
// type of access it needs.
function checkBrowser(){
  if(navigator.userAgent.indexOf("MSIE") != -1){
    isIE = true;
    layer = ".all";
    style = ".style";
  }else if(navigator.userAgent.indexOf("Nav") != -1){
    isNav = true;
    layer = ".layers";
    style = "";
  }else{
    unSupported = true;
  }
}


function numOrdA(a, b){ return (a-b); }
function numOrdD(a, b){ return (b-a); }



// Take the layer state passed in, and change it.
function changeState(layerRef, state){
  eval("document" + layer + "['" + layerRef + "']" + style + ".visibility = '" + state + "'");
}



//-------------------------------------------------------------------------------------

// copyright 1999 Idocs, Inc. http://www.idocs.com/tags/
// Distribute this script freely, but please keep this 
// notice with the code.

var rollOverArr=new Array();
function setrollover(OverImgSrc,pageImageName)
{
if (! document.images)return;
if (pageImageName == null)
    pageImageName = document.images[document.images.length-1].name;
rollOverArr[pageImageName]=new Object;
rollOverArr[pageImageName].overImg = new Image;
rollOverArr[pageImageName].overImg.src=OverImgSrc;
}

function rollover(pageImageName)
{
if (! document.images)return;
if (! rollOverArr[pageImageName])return;
if (! rollOverArr[pageImageName].outImg)
    {
    rollOverArr[pageImageName].outImg = new Image;
    rollOverArr[pageImageName].outImg.src = document.images[pageImageName].src;
    }
document.images[pageImageName].src=rollOverArr[pageImageName].overImg.src;
}

function rollout(pageImageName)
{
if (! document.images)return;
if (! rollOverArr[pageImageName])return;
document.images[pageImageName].src=rollOverArr[pageImageName].outImg.src;
}


//-------------------------------------------------------------------------------------



//-------------------------------------------------------------------------------------


function ValidateTextSearchForm()
{

  if (document.TextSearchForm.sp.value == "")
  {
    alert("Please enter a value for the \"Search Term\" field.");
    document.TextSearchForm.sp.select();
    return (false);
  }

  if (document.TextSearchForm.sp.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Search Term\" field.");
    document.TextSearchForm.sp.select();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-# \t\r\n\f";
  var checkStr = document.TextSearchForm.sp.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"#\" characters in the \"Search Term\" field.");
    document.TextSearchForm.sp.select();
    return (false);
  }
  return (true);
}

//-------------------------------------------------------------------------------------

function smallWindow(name)
{
  var small_window = 
    window.open(name,"plain","width=500,height=350,scrollbars,resizable");
    small_window.focus();
    return true;
}

//-------------------------------------------------------------------------------------

function mediumWindow(name)
{
  var medium_window = 
    window.open(name,"plain","width=640,height=480,scrollbars,resizable");
    medium_window.focus();
    return true;
}

//-------------------------------------------------------------------------------------

function longWindow(name)
{
  var long_window = 
    window.open(name,"plain","width=500,height=450,scrollbars,resizable");
    long_window.focus();
    return true;
}

//-------------------------------------------------------------------------------------

function tcWindow(name)
{
  var picture_window = 
    window.open(name,"plain","width=640,height=700,scrollbars,resizable");
    picture_window.focus();
    return true;
}

//-------------------------------------------------------------------------------------

function pictureWindow(name)
{
  var picture_window = 
    window.open(name,"plain","width=600,height=700,scrollbars,resizable");
    picture_window.focus();
    return true;
}

//-------------------------------------------------------------------------------------

function NotWorkingYet()
{
   alert("The requested operation is not available.")
   return (false);
}

//-------------------------------------------------------------------------------------

function ArchiveWarning()
{
   return confirm("IMPORTANT NOTICE:\n\nArchival listings are offered for historical reference purposes only. Any pricing or availabilty information in the files should not be considered valid unless verified by your local comic book or specialty store retailer.");
}

//-------------------------------------------------------------------------------------

function page_onchange()
	{
	document.Redirection.submit();
	return 0;
	}

//-------------------------------------------------------------------------------------
		
function ValidateDeliveryOptions()
{
//	var SourceRadioSelected = false;
//	for (i = 0;  i < document.DeliveryOptions.AddressSource.length;  i++)
//	{
//	  if (document.DeliveryOptions.AddressSource[i].checked)
//	      SourceRadioSelected = true;
//	}
	
//	if (!SourceRadioSelected)
//	{
//	  alert("Please select one of the \"Address Source\" options.");
//	  return (false);
//	}
	
	var value = null
//	for (i = 0; i < document.DeliveryOptions.AddressSource.length; i++)
//	{
//		if (document.DeliveryOptions.AddressSource[i].checked)
//		{
//			value = document.DeliveryOptions.AddressSource[i].value
//		}
//	}
	
	if (value == "MCBA")
	{
		alert("MCBA address import disabled. Please select a \"Text File\" option and specify a source file.");
		return (false);
	}
	
	if (document.DeliveryOptions.AddressSource.value == "TXT" && document.DeliveryOptions.AddressFile.value == "" && document.DeliveryOptions.AddressFileLoaded.value == "N")
	{
		alert("Please specify a file under the \"Address Source\" options.");
		document.DeliveryOptions.AddressFile.focus();
		return (false);
	}

	var FormatRadioSelected = false;
	for (i = 0;  i < document.DeliveryOptions.MailFormat.length;  i++)
	{
	  if (document.DeliveryOptions.MailFormat[i].checked)
	      FormatRadioSelected = true;
	}
	
	if (!FormatRadioSelected)
	{
	  alert("Please select one of the \"Mail Format\" options.");
	  return (false);
	}

	var FormatValue = null
	for (i = 0; i < document.DeliveryOptions.MailFormat.length; i++)
	{
		if (document.DeliveryOptions.MailFormat[i].checked)
		{
			FormatValue = document.DeliveryOptions.MailFormat[i].value
		}
	}

	if (FormatValue == 1)
	{
		//alert("HTML formatted mail not yet supported. Please select the \"Plain Text\" option and make sure your body source file is properly formatted.");
		//return (false);
	}
	
	if (document.DeliveryOptions.BodyFile.value == "" && document.DeliveryOptions.BodyFileLoaded.value == "N")
	{
		alert("Please specify a file for \"Body Source\".");
		document.DeliveryOptions.AddressFile.focus();
		return (false);
	}
	
	if (document.DeliveryOptions.Subject.value == "")
	{
		alert("The \"Subject\" field may not be left blank.");
		document.DeliveryOptions.Subject.focus();
		return (false);
	}

	if (document.DeliveryOptions.From.value == "")
	{
		alert("The \"From\" field may not be left blank.");
		document.DeliveryOptions.From.focus();
		return (false);
	}
	
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ&' \t\r\n\f";
	var checkStr = document.DeliveryOptions.From.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
	  ch = checkStr.charAt(i);
	  for (j = 0;  j < checkOK.length;  j++)
	    if (ch == checkOK.charAt(j))
	      break;
	  if (j == checkOK.length)
	  {
	    allValid = false;
	    break;
	  }
	}
	if (!allValid)
	{
	  alert("Please enter only letter and whitespace characters in the \"From\" field.");
	  document.DeliveryOptions.From.focus();
	  return (false);
	}

	
	if (document.DeliveryOptions.ReplyTo.value == "")
	{
		alert("The \"Reply To\" field may not be left blank.");
		document.DeliveryOptions.ReplyTo.focus();
		return (false);
	}
	
	var emailStr = document.DeliveryOptions.ReplyTo.value;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	alert("Email address seems incorrect (check @ and .'s)");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];


	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths email username contains invalid characters.");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths email domain name contains invalid characters.");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	   }
	}

	if (user.match(userPat)==null) {

	alert("The email username doesn't seem to be valid.");
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Email destination IP address is invalid!");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	   }
	}
	return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The email address domain name does not seem to be valid.");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The email address must end in a well-known domain or two letter " + "country.");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	}

	if (len<2) {
	alert("The email address is missing a hostname.");
	document.DeliveryOptions.ReplyTo.select();
	return false;
	}
	
//	alert("js validation done");
	return (true);//set to TRUE when done testing
}



//-------------------------------------------------------------------------------------

function SendMailWarning()
{
	return confirm("A mass e-mail may take several minutes (roughly 1 minute per 400 addresses) to process and CANNOT BE ABORTED. Do you wish to continue?");
}

//-------------------------------------------------------------------------------------

function StartOverWarning()
{
	return confirm("Are you sure you wish to delete these settings and start the project over?");
}

//-------------------------------------------------------------------------------------

function DeleteProjectWarning()
{
	return confirm("Are you sure you wish to delete this project? This action cannot be reversed.");
}

//-------------------------------------------------------------------------------------

function ValidateUserOptions()
{

	if (document.UserOptions.EditFName.value == "" || document.UserOptions.EditFName.value == " ")
	{
		alert("The \"First Name\" field may not be left blank.");
		document.UserOptions.EditFName.focus();
		return (false);
	}
	
	if (document.UserOptions.EditLName.value == "" || document.UserOptions.EditFName.value == " ")
	{
		alert("The \"Last Name\" field may not be left blank.");
		document.UserOptions.EditLName.focus();
		return (false);
	}
	
	if (document.UserOptions.EditEmail.value == "" || document.UserOptions.EditEmail.value == " ")
	{
		alert("The \"Email\" field may not be left blank.");
		document.UserOptions.EditEmail.focus();
		return (false);
	}
	
	if (document.UserOptions.EditCompany.value == "-1")
	{
		alert("You must select a vaild option for \"Company\".");
		document.UserOptions.EditCompany.focus();
		return (false);
	}
	
	
	var AdminRadioSelected = false;
	for (i = 0;  i < document.UserOptions.admin.length;  i++)
	{
	  if (document.UserOptions.admin[i].checked)
	  {
	      AdminRadioSelected = true;
	  }
	}
	
	if (!AdminRadioSelected)
	{
	  alert("Please select one of the \"Administrator\" options.");
	  return (false);
	}
	
	var AdminValue = null
	for (i = 0; i < document.UserOptions.admin.length; i++)
	{
		if (document.UserOptions.admin[i].checked)
		{
			AdminValue = document.UserOptions.admin[i].value
		}
	}
	
	if (AdminValue == 1 && document.UserOptions.EditUserID.value == 0)
	{
		return confirm("Are you sure you want to make this user an administrator?");
	}
	
	var StatusRadioSelected = false;
	for (i = 0;  i < document.UserOptions.Status.length;  i++)
	{
	  if (document.UserOptions.Status[i].checked)
	  {
	      StatusRadioSelected = true;
	  }
	}
	
	if (!StatusRadioSelected)
	{
	  alert("Please select one of the \"Status\" options.");
	  return (false);
	}
	
	var StatusValue = null
	for (i = 0; i < document.UserOptions.Status.length; i++)
	{
		if (document.UserOptions.Status[i].checked)
		{
			StatusValue = document.UserOptions.Status[i].value
		}
	}
	
	if (StatusValue == 1)
	{
		return confirm("Are you sure you want to disable this user?");
	}

	return (true);//set to TRUE when done testing
}

function ValidateSubForm()
{

  if (document.SubForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    document.SubForm.FirstName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ,- \t\r\n\f";
  var checkStr = document.SubForm.FirstName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, whitespace and \",-\" characters in the \"First Name\" field.");
    document.SubForm.FirstName.focus();
    return (false);
  }

  if (document.SubForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    document.SubForm.LastName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ,- \t\r\n\f";
  var checkStr = document.SubForm.LastName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, whitespace and \",-\" characters in the \"Last Name\" field.");
    document.SubForm.LastName.focus();
    return (false);
  }
  
  if (document.SubForm.Position.value == "")
  {
    alert("Please enter a value for the \"Position\" field.");
    document.SubForm.Position.focus();
    return (false);
  }

  if (document.SubForm.School.value == "")
  {
    alert("Please enter a value for the \"School\" field.");
    document.SubForm.PasswordConfirm.focus();
    return (false);
  }

  if (document.SubForm.Email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    document.SubForm.Email.focus();
    return (false);
  }
 
  //call email check
  emailOK = false;
  emailCheck(document.SubForm.Email.value)
  
  
  if (!emailOK)
  {
	document.SubForm.Email.focus();
	return(false);
  }
 
  //alert("Valid");
  return (true);
}




function emailCheck (emailStr) 
{

	

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("The username doesn't seem to be valid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The email address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	alert("This email address is missing a hostname.");
	return false;
	}

	// If we've gotten this far, everything's valid!
	emailOK = true;
}