<!--
/*****************************************************
 * general.js
 * 12/10/2004
 * 
 * a nice little script 
 *
 *****************************************************/
var isHome = false;
var pageLoaded = false;
var myTimeout;
var hideTimers = new Array(5);
var showTimers = new Array(5);
var scIndex = 0,
    sfIndex = 1,
    csIndex = 2,
    maIndex = 3,
    niIndex = 4;
/******************************************************************************/
// Name the browser window so it can be targetted by FG popup pages
/******************************************************************************/
window.name = "dynamic";

/******************************************************************************/
// Detect Visitors Browser and Platform
/******************************************************************************/
function WhoAreYou()
{
    var pform  = navigator.platform.toLowerCase();
    var agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.rev   = 4.0;
    this.ns    = ((agent.indexOf('mozilla') != -1) &&
                 ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
    this.ns2   = (this.ns && (this.major == 2));
    this.ns3   = (this.ns && (this.major == 3));
    this.ns4   = (this.ns && (this.major == 4)); //ns4
    this.ns5   = (this.ns && (this.major > 4));  //ns6+
    this.ie    = (agent.indexOf("msie") != -1);
    this.ie3   = (this.ie && (this.major == 2));
    this.ie4   = (this.ie && (this.major >= 4)); //ie4+
    this.op3   = (agent.indexOf("opera") != -1); //opera3+
    this.op    = this.op3;
    this.safari = (agent.indexOf('safari') != -1);
    this.konqueror = (agent.indexOf('konqueror') != -1);
    this.pc    = (pform.indexOf("win32") != -1); //PC-windows
    if (this.ns4) { this.rev = this.minor; }
    if (this.ns5) { agent.match(/netscape\d?\/(\d+\x2E\d+)/i); this.rev = parseFloat(RegExp.$1); }
    if (this.ie4) { agent.match(/msie\s?\/?(\d+\x2E\d+)/i);    this.rev = parseFloat(RegExp.$1); }
    if (this.op)  { agent.match(/opera\s?\/?(\d+\x2E\d+)/i);   this.rev = parseFloat(RegExp.$1); }
}

var way = new WhoAreYou();
var NS  = way.ns;
var NS4 = way.ns4;
var NS6 = way.ns5;
var IE  = way.ie4;
var PC  = way.pc;
var MAC = !way.pc;
var REV = way.rev; // added to track IE5.0 on MAC
var OP  = way.op; if (OP) { NS6 = true; NS = true; IE = false; } // treat as NS6 for page fxns;
                                                                 // avoid IE spoofing
var SAFARI = way.safari; if (SAFARI) { NS6 = true; NS = true; IE = false;}
var KONQ = way.konqueror ; if (KONQ) { NS6 = true; NS = true; IE = false; }
if (!NS && !IE) { IE = true; }		// Default to IE if nothing set.
                                                                 // avoid IE spoofing
//alert("ie: "+IE+" | ns4: "+NS4+" | ns6: "+NS6+" | op: "+OP+" | pc:"+PC+" | rev:"+REV);

/******************************************************************************/
// SELECT THE APPROPRIATE STYLESHEET
/******************************************************************************/
var styleSheet = "";
if (IE)
{
    if (PC) {
        styleSheet="pcie";
    } else {
        styleSheet="macie";
    }
} else if (NS6) {
    if (PC) {
        styleSheet="pcns6";
    } else {
        styleSheet="macns6";
    }
} else if (NS4) {
    if (PC) {
        styleSheet="pcns";
    } else {
        styleSheet="macns";
    }
} else {
    styleSheet="pcie";          //default to PCIE if browser not identified
}

document.write('<LINK rel="stylesheet" type="text/css" href="/includes/'+styleSheet+'.css">');

/******************************************************************************/
function IsEmailValid(elm)
{
    return isEmailValid(elm);
}
/******************************************************************************/
// Validates a single email address
// Moved logic to seperate function validateEmailAddress
function isEmailValid(elm)
{
    var emailStr = elm.value;
    return validateEmailAddress(emailStr);
}
/******************************************************************************/
// Validates a list of email addresses.
function isEmailListValid(elm)
{
   var list = elm.value.replace(/\s+/g,"");
   var listArray = new Array;
   listArray = list.split(/,/);
   for (i=0; i < listArray.length; i++) {
      retval = validateEmailAddress(listArray[i]);
      if (!retval)
        return false;
   }
   return true;
}
/******************************************************************************/
// This is now an internal function that is called by isEmailValid and
// isEmailListValid - rschramm 2/6/01
// It takes a string now, and not a form element.
// <!-- This script and many more are available free online at -->
// <!-- The JavaScript Source!! http://javascript.internet.com -->
function validateEmailAddress(emailStr)
{
    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)
        return false;

    var user=matchArray[1];
    var domain=matchArray[2];

    // See if "user" is valid
    if (user.match(userPat)==null)
        return false;

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        // this is an IP address
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255)
                return false;
        }
        return true;
    }

    // Domain is symbolic name
    var domainArray=domain.match(domainPat)
    if (domainArray==null)
        return false;

    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 ||
        domArr[domArr.length-1].length>3)
       return false;

    if (len<2)
       return false;

    return true;
}
/******************************************************************************/
function isFilled(elm)
{
    if (elm.value == "" || elm.value == null)
    return false;
    else return true;
}
/******************************************************************************/
function IsZipValid(elm)
{
    var regexp = /^(\d{5}|\d{9}|\d{5}-\d{4})$/;
    return regexp.test(elm.value);
}
/******************************************************************************/
function IsPhoneValid(elm)
{
    var regexp = /^(\d{3} \d{3}-\d{4}|\d{10}|\(\d{3}\)\s\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4}|\d{3}-\d{3}-\d{4}|\d{3}\.\d{3}\.\d{4})$/;
    return regexp.test(elm.value);
}
/*******************************************************************************/
function IsDomesticPhoneValid(elm)
{
    var thisphone = elm.value;
    var i = 0;
    var j = 0;
    for (i = 0; i < thisphone.length; i++){
        if (thisphone.charCodeAt(i)>47 && thisphone.charCodeAt(i)<58){
            j+=1;
        }
    }
    if ( j == 10){return true;}
    else {return false;}
}
/*****************************************************************************/
function IsIntlPhoneValid(elm)
{
    var thisphone = elm.value;
    var i = 0;
    var j = 0;
    for (i = 0; i < thisphone.length; i++){
        if (thisphone.charCodeAt(i)>47 && thisphone.charCodeAt(i)<58){
            j+=1;
        }
    }
    if ( j>9 && j<15){return true;}
    else {return false;}
}
/******************************************************************************/
// This code creates a centered pop-up window; taken from S+N code
// Unused currently for Frontgate
function launchWindow(w,h,windowName,source,scrollbarsYN)
{
    var xobj = null;

    var chasm = screen.availWidth;
    var mount = screen.availHeight;

    xobj = window.open(pageToLoad, winName,
                      'width=' + w +
                      ',height=' + h +
                      ',left=' + ((chasm - w - 10) * .5) +
                      ',top=' + ((mount - h - 30) * .5) +
                      ',scrollbars=' + scroll +
                      ',resizable=yes,dependent=yes');
    xobj.focus();
}

/******************************************************************************/
// This function is used for opening internal links with limited window options
/******************************************************************************/
var popupHandle;                // Provides window handle referenceable by caller

function openPopup(pageToLoad, winName, width, height, center, scroll, dependent)
{
    xposition = 0;
    yposition = 0;
    if (dependent == null || dependent == "") { dependent="0"; }

    if (center)
    {
        xposition = (screen.availWidth - width - 10) * .5;
        yposition = (screen.availHeight - height - 30) * .5;
    }

    args = "width=" + width + ","     + "height=" + height + ","
         + "location=0,menubar=0,resizable=1,scrollbars=" + scroll + ","
         + "status=0,titlebar=0,toolbar=0,hotkeys=0,location=0,copyhistory=0,"
         + "left=" + xposition + ","
         + "top="  + yposition + ","
         + "dependent=" + dependent;

    var handle = window.open(pageToLoad, winName, args);

    popupHandle = handle;
    handle.focus();
}

/******************************************************************************/
// This function is used for opening internal links with limited window options
/******************************************************************************/
var popupHandle;                // Provides window handle referenceable by caller

function openPopup_fixedSize(pageToLoad, winName, width, height, center, scroll, dependent)
{
    xposition = 0;
    yposition = 0;
    if (dependent == null || dependent == "") { dependent="0"; }

    if (center)
    {
        xposition = (screen.availWidth - width - 10) * .5;
        yposition = (screen.availHeight - height - 30) * .5;
    }

    args = "width=" + width + ","     + "height=" + height + ","
         + "location=0,menubar=0,resizable=0,scrollbars=" + scroll + ","
         + "status=0,titlebar=0,toolbar=0,hotkeys=0,location=0,copyhistory=0,"
         + "left=" + xposition + ","
         + "top="  + yposition + ","
         + "dependent=" + dependent;

    var handle = window.open(pageToLoad, winName, args);

    popupHandle = handle;
    handle.focus();
}



/******************************************************************************/
// This function is used for opening external links with full window options
/******************************************************************************/
function openExternalPopup(pageToLoad, winName, width, height, center, scroll)
{
    var xposition=0;
    var yposition=0;

    if (center)
    {
        xposition = (screen.availWidth - width - 10) * .5;
        yposition = (screen.availHeight - height - 30) * .5;
    }

    args = "width=" + width + "," + "height=" + height + ","
         + "location=1,menubar=1,resizable=1,scrollbars=" + scroll + ","
         + "status=1,titlebar=1,toolbar=1,hotkeys=1,location=1,copyhistory=1,"
         + "left=" + xposition + ","
         + "top=" + yposition + ","
         + "dependent=no";

    var handle = window.open(pageToLoad, winName, args);
    handle.focus();
}

// *****************************************************
// Note: use stripCC function prior to calling to
//       eliminate dashes and other non-numeric chars
// Encoding only works on cards with less than 19 digits
// *****************************************************
function isCreditCard(st) {
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);
}

// *****************************************************
// Eliminates non-numeric characters from credit card entry
// EDITTED 10/06/02 - Cameron F. Logan, Envisa
// *****************************************************
function stripCC(val)
{
    val = "" + val;
    val = val.replace(/[^\d]/g,"");
    if (!val) { val = ""; }
    return val;
}

//***********************************************************************
// Functions that build input and select field to near pixel perfection
// regardless of the browser; conversion from pixels to default size
// parameters is performed for PC and MAC versions of Netscape 4.x
//***********************************************************************
// Set default style for form fields:
var defaultClass = "field";

// Dynamically construct properly sized input boxes
function buildInput(fieldName, pixWidth, maxLen, initValue, className, addnAttr, isPwd)
{
    var inputHTML = '<input';

    var fieldName = (fieldName != null) ? ' name="'.concat(fieldName, '"') : ' name="'.concat('tarea', Math.round(Math.random() * 1000), '"') ;
    var maxLength = !isNaN(maxLen) ? ' maxlength="'.concat(maxLen, '"') : '' ;
    var initValue = (initValue != null) ? ' value="'.concat(initValue, '"') : '' ;
    var className = (className != null) ? ' class="'.concat(className, '"') : ' class="'.concat(defaultClass, '"') ;
    var addnAttr  = (addnAttr != null) ? ' '.concat(addnAttr) : '' ;
    var isPwd     = isPwd ? ' type="password"' : ' type="text"' ;

    var inputSize = '';
    if (!isNaN(pixWidth))
    {
        var sizeIE4PC  = Math.round((pixWidth / 6) - 4);         // exact formula for pix to size on IE6!
        //var sizeNS4PC  = Math.round((pixWidth * 0.1435) - 1.5);  // exact formula for pix to size on NS4 using default font!
        var sizeNS4PC  = Math.round((pixWidth * 0.085) - 1.95);  // almost exact formula for pix to size on NS4 using 'field' style for FG!
        var sizeNS4MAC = (sizeNS4PC * 2) + 1; // Good enough estimate

        // Get the proper sizing attribute on a per browser basis
        if (NS4)
        {
            if (PC)
            {
                inputSize = ' size="'.concat(sizeNS4PC, '"');
            }
            else // if MAC
            {
                inputSize = ' size="'.concat(sizeNS4MAC, '"');
            }
        }
        else
        {
            inputSize  = ' style="width:'.concat(pixWidth, 'px"');
        }
    }

    inputHTML = inputHTML.concat(isPwd,className,fieldName,inputSize,maxLength,initValue,addnAttr,'>');

    return inputHTML;
}

// Dynamically construct properly sized select boxes
function buildSelect(fieldName, pixWidth, optionString, className, addnAttr)
{
    var selectHTML = '<select';

    var fieldName    = (fieldName != null) ? ' name="'.concat(fieldName, '"') : ' name="'.concat('select', Math.round(Math.random() * 1000), '"') ;
    var className    = (className != null) ? ' class="'.concat(className, '"') : ' class="'.concat(defaultClass, '"') ;
    var optionString = (optionString != null) ? optionString : '<option value="nothing">Missing Options</option>' ;
    var addnAttr     = (addnAttr != null) ? ' '.concat(addnAttr) : '' ;
    var addnAttr     = (addnAttr != null) ? ' '.concat(addnAttr) : '' ;

    var selectSize = '';

    if (!isNaN(pixWidth))
    {
        // get the proper sizing attribute on a per browser basis
        if (NS4)
        {
            selectSize = ' width="'.concat(pixWidth,'"');
        }
        else
        {
            selectSize  = ' style="width:'.concat(pixWidth, 'px"');
        }
    }

    selectHTML = selectHTML.concat(className,fieldName,selectSize,addnAttr,'>',optionString,'</select>');

    if (NS4)
    {
        selectHTML = '<span '.concat(className, '>', selectHTML, '</span>');
    }

    return selectHTML;
}

// Dynamically construct properly sized input boxes
function buildTextArea(fieldName, pixWidth, rows, initValue, className, addnAttr)
{
    var tareaHTML = '<textarea';

    var fieldName = (fieldName != null) ? ' name="'.concat(fieldName, '"') : ' name="'.concat('text', Math.round(Math.random() * 1000), '"') ;
    var rows      = !isNaN(rows) ? ' rows="'.concat(rows, '"') : '' ;
    var initValue = (initValue != null) ? initValue : '' ;
    var className = (className != null) ? ' class="'.concat(className, '"') : ' class="'.concat(defaultClass, '"') ;
    var addnAttr  = (addnAttr != null) ? ' '.concat(addnAttr) : '' ;

    var colSize = '';
    if (!isNaN(pixWidth))
    {
        var colIE4PC   = Math.round((pixWidth / 8) - 3);         // exact formula for pix to cols on IE6!
        var colNS6 = Math.round((pixWidth / 6) - 4);
        //var colNS4PC   = Math.round((pixWidth * 0.1435) - 3.75); // exact formula for pix to cols on NS4 using default font!
        var colNS4PC   = Math.round((pixWidth * 0.085) - 2.85); // almost exact formula for pix to cols on NS4 using 'field' style for FG!
        var colNS4MAC  = Math.round((colNS4PC * 1.25)+ 1); // Good enough estimate

        // get the proper sizing attribute on a per browser basis
        if (NS4)
        {
            if (PC)
            {
                colSize = ' cols="'.concat(colNS4PC, '"');
            }
            else // if MAC
            {
                colSize = ' cols="'.concat(colNS4MAC, '"');
            }
        }
        else if (NS6)        
        {
        		colSize = ' cols="'.concat(colNS6, '"');
        }
        else        	
        {
            colSize  = ' style="width:'.concat(pixWidth, 'px"');
        }
    }
    	
    tareaHTML = tareaHTML.concat(className,fieldName,colSize,rows,addnAttr,' wrap="virtual">',initValue,'</textarea>');
		
    if (NS4)
    {
        tareaHTML = '<span '.concat(className, '>', tareaHTML, '</span>');
    }

    return tareaHTML;
}

function clearSearchField()
{
	formName = "search";
	
  if (IE) {
      var form = eval('document.' + formName);
  }
  if (NS) {
      var form = eval('document.' + formName);
  }

	if(form.Description.value == "Keyword or Item#")
		form.Description.value = "";	
	
}

randImgObj.set1 = new Array("bsball.jpg", "bball.jpg", "lax.jpg", "mlax.jpg", "sb.jpg", "vb.jpg", "soccer.jpg", "track.jpg", "wrestling.jpg");
randImgObj.imagesPath = "images/";

Array.prototype.shuffle = function() { 
  var i, temp, i1, i2;
  for (i=0; i<this.length; i++) { 
    i1 = Math.floor( Math.random() * this.length );
    i2 = Math.floor( Math.random() * this.length );
    temp = this[i1];
    this[i1] = this[i2];
    this[i2] = temp;
  }
}

randImgObjs = []; // holds all random rotating image objects defined
// constructor 
function randImgObj(s) {
  this.speed=s; this.ctr=0; this.timer=0;  
  this.index = randImgObjs.length; randImgObjs[this.index] = this;
  this.animString = "randImgObjs[" + this.index + "]";
}

randImgObj.prototype = {
  addImages: function(ar) { // preloads images
    this.imgObj.imgs = [];
    for (var i=0; ar[i]; i++) {
      this.imgObj.imgs[i] = new Image();
      this.imgObj.imgs[i].src = randImgObj.imagesPath + ar[i];
    }
  },

  rotate: function() { // controls rotation
    var ctr = Math.floor( Math.random() * this.imgObj.imgs.length );
    if (ctr == this.ctr) ctr = (ctr > 0)? --ctr: ++ctr;
    this.ctr = ctr;
    if ( typeof this.imgObj.filters != "undefined" ) {
   		this.imgObj.style.filter = 'blendTrans(duration=1)';
      if (this.imgObj.filters.blendTrans) this.imgObj.filters.blendTrans.Apply();
    }
    this.imgObj.src = this.imgObj.imgs[this.ctr].src;
    if ( typeof this.imgObj.filters != "undefined" && this.imgObj.filters.blendTrans )
      this.imgObj.filters.blendTrans.Play();    
  }
}

// sets up rotation for all defined randImgObjs
randImgObj.start = function() {
  for (var i=0; i<randImgObjs.length; i++) 
    randImgObjs[i].timer = setInterval(randImgObjs[i].animString + ".rotate()", randImgObjs[i].speed);                     
}

randImgObj.setUpImg = function(imgAr, sp) {
  var rotator, img, imgStr = "";
  rotator = new randImgObj(sp);
  randImgObjs[randImgObjs.length-1].imgAr = imgAr;
  imgAr.shuffle();
  img = imgAr[ Math.floor( Math.random() * imgAr.length ) ]; 
  imgStr += '<img src="' + randImgObj.imagesPath + img + '" alt="" ';
  imgStr += 'name="img' + (randImgObjs.length-1) + '">';
  document.write(imgStr); 
}

function initRandRotation() {
  for (var i=0; randImgObjs[i]; i++) {
    var rotator = randImgObjs[i];
    rotator.imgObj = document.images["img" + i]; // get reference to the image object
    rotator.addImages(rotator.imgAr);
    rotator.rotate();
  }
  randImgObj.start();  
}

//-->
