// array to hold the swap images.
var swappedOut = new Array(), nSwappedOut = 0, pics = new Array();

function mout()
{
  /***** supports multiple images *****/
  // no need to pass any arguments

  var i;
  
  for(i = 0; i < nSwappedOut; i++)
  {
    // swap all tracked images
    swappedOut[i].src = swappedOut[i].oldSrc;
  }
}

function mover()
{
  /***** supports multiple images *****/
  // pass the arguments in as a list of place holder name
  // ie: mover('holder1', 'holder2', 'holder3');
  // it will find the extension and path of the original image
  // and use the same one for the new image
  // it will also assume that the mouseover image start with an 
  // underscore '_' character

  var i, j = 0, imgSwapped, args = mover.arguments, path = "", file = "", slash = 0;
  nSwappedOut = args.length;

  for(i = 0; i < nSwappedOut; i++)
  {
    imgSwapped = document.images[args[i]];  // gets the image
      
    if(imgSwapped != null)
    {
      // get the filename of the image
      slash = imgSwapped.src.lastIndexOf("/") + 1;
      file = imgSwapped.src.substring(slash);
      path = imgSwapped.src.substring(0, slash);

      // if the image is already m/o, then don't do it again
      if(file.indexOf("_") != 0)
      {
        // track all swapped images
        swappedOut[j++] = imgSwapped;
        imgSwapped.oldSrc = imgSwapped.src;
        imgSwapped.src = path + "_" + file;
      }
      else
      {
        nSwappedOut = 0;
      }
    }
  }
}

function preload()
{
  if(document.images)
  {
    if(!document.pics) document.pics = new Array();

    var i;
    var j = 0;
    var args = preload.arguments;

    for(i = 0; i < args.length; i++)
    {
      if(args[i].indexOf("#") != 0)
      {
        document.pics[j] = new Image;
        document.pics[j++].src = args[i];
      }
    }
  }
}

function popup(url, name, x, y, w, h)
{
  if(x == 0 || y == 0)
  {
	  var x = (window.screen.width / 2) - ((w / 2));
	  var y = (window.screen.height / 2) - ((h / 2));
  }

  var popup;
  popup = window.open(url, name, "location=no,directories=no,status=no,menubar=no,toolbar=no,scrollbars=1,resizable=yes,height=" + h + ",width=" + w + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y);
  popup.focus();
  popup = null;
}

function popup_status(url, name, x, y, w, h)
{
  if(x == 0 || y == 0)
  {
	  var x = (window.screen.width / 2) - ((w / 2));
	  var y = (window.screen.height / 2) - ((h / 2));
  }

  var popup;
  popup = window.open(url, name, "location=no,directories=no,status=yes,menubar=no,toolbar=no,scrollbars=1,resizable=yes,height=" + h + ",width=" + w + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y);
  popup.focus();
  popup = null;
}

function inspect(obj)
{
  if(!obj)
  {
    ret = prompt ("Enter object", "document");
    obj = eval(ret);
  }

  var temp = "";
  for(x in obj)
  {
    temp += x + ": " + obj[x] + "\n";
    if(temp.length > 700)
    {
      alert(temp);temp='';
    }
  }
  alert(temp);
}

function is_blank(s)
{
  var i, c;
  
  for(i = 0; i < s.length; i++)
  {
    c = s.charAt(i);
    if(c != ' ' && c != '\n' && c != '\t')
      return false;
  }
  return true;
}
  
function regex_validate(f, error_string, previous_error)
{
   var i, e, msg, bypass, rdmsg, rdoname, posmsg, emsg, phmsg;
   
   if(previous_error == null)
   { 
     previous_error = '';
   }

   msg = previous_error;
   rdmsg = '';
   bypass = true;
   rdoname = '';
   
   for(i = 0; i < f.length; i++) 
   {   
      e = f.elements[i];
      if(e.regex || e.required)
      {                 
         if(e.type == 'radio')
         {
            if(rdoname != e.name)
            {
                bypass = true;
                msg += rdmsg;
                rdoname = e.name;
            }

            if(!e.checked && bypass)
            {
                rdmsg = e.display + '\n';
            }
            else 
            {
                rdmsg = '';
                bypass = false;
            }
        }
        else if(e.type == 'select-one')
        {
            var elemval = e.options[e.selectedIndex].value;

            if(e.regex)
            {
                if(elemval.search(e.regex) == -1)
                {
                    msg += e.display + '\n';
                }
            }
            else
            {
                if(elemval == null || elemval == '' || is_blank(elemval))
                {
                    msg += e.display + '\n';
                }
            }
        }
        else 
        {
            if(e.regex)
            {
                if(e.value.search(e.regex) == -1)
                {
                    msg += e.display + '\n';
                }
            }
            else
            {
                if(e.value == null || e.value == '' || is_blank(e.value))
                {
                    msg += e.display + '\n';
                }
            }
        }  
  
      }//end e.regex
   }
   
   msg += rdmsg; 
   if(msg != '')
   {
      alert(error_string + msg);
      return false;
   }
   else
   {
      return true;
   }
}

function get_selected_radio_button(radio)
{
  var i;

  for(i = 0; i < radio.length; i++)
  {
    if(radio[i].checked)
    {
      return radio[i];
    }
  }

  return null;
}

var hasShockwavePlugin = 0;
if(navigator.mimeTypes && navigator.mimeTypes["application/x-director"] && navigator.mimeTypes["application/x-director"].enabledPlugin)
{
  if(navigator.plugins && navigator.plugins["Shockwave for Director"] && (versionIndex = navigator.plugins["Shockwave for Director"].description.indexOf(".")) != - 1)
  {
    var versionString = navigator.plugins["Shockwave for Director"].description.substring(versionIndex - 1, versionIndex);
    var subVersionString = navigator.plugins["Shockwave for Director"].description.substring(versionIndex + 1, versionIndex + 2);
    
    versionIndex = parseInt(versionString);
		subVersionIndex = parseInt(subVersionString);

		if(versionIndex == 8)
    {
			if(subVersionIndex >= 5)
				hasShockwavePlugin = 1;
		}
		else if(versionIndex > 8)
    {
			hasShockwavePlugin = 1;
		}
	}
}
else if(navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.userAgent.indexOf("Windows 95") >= 0 || navigator.userAgent.indexOf("Windows 98") >= 0 || navigator.userAgent.indexOf("Windows NT") >= 0))
{
	document.write("<script language='VBScript' \> \n");
	document.write("  On Error Resume Next \n");
	document.write("  hasShockwavePlugin = (IsObject(CreateObject(\"SWCtl.SWCtl.8.5\"))) \n");
	document.write("</script\> \n");
}

function IsShockwaveDetect()
{
  if (hasShockwavePlugin == 1)
    return true;
  else
    return false;
}

// *************
// everything below this point is internal until after the body tag
// do not modify! 
// *************

// system globals
var requiredVersion = 5;
var flash2Installed = false;		// boolean. true if flash 2 is installed
var flash3Installed = false;		// boolean. true if flash 3 is installed
var flash4Installed = false;		// boolean. true if flash 4 is installed
var flash5Installed = false;		// boolean. true if flash 5 is installed
var flash6Installed = false;		// boolean. true if flash 6 is installed
var maxVersion = 6;				    	// highest version we can actually detect
var actualVersion = 0;			  	// version the user really has
var hasRightVersion = false;		// boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;				    // the version of javascript supported

// check the browser...we're looking for ie/win
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;		// true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

// this is a js1.1 code block, so make note that js1.1 is supported.
jsVersion = 1.1;

// write vbscript detection if we're not on mac.
if(isIE && isWin){ // don't write vbscript tags on anything but ie win
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');	
	document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

// Checks the version of flash the user has, and returns it.  Returns 0 if
// there is no flash installed.
function FlashDetect(){	

	if (navigator.plugins){								// does navigator.plugins exist?
		if (navigator.plugins["Shockwave Flash 2.0"] 	// yes>> then is Flash 2 
		|| navigator.plugins["Shockwave Flash"]){		// or flash 3+ installed?

			// set convenient references to flash 2 and the plugin description
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			// a flash plugin-description looks like this: Shockwave Flash 4.0 r5
			// so we can get the major version by grabbing the character before the period
			// note that we don't bother with minor version detection. do that in your movie with $version
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

			// we know the version, now set appropriate version flags
			flash2Installed = flashVersion == 2;		
			flash3Installed = flashVersion == 3;
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash6Installed = flashVersion == 6;
		}
	}
	
	// loop through all versions we're checking, and set actualVersion to highest detected version
	for (var i = 2; i <= maxVersion; i++) {	
		if (eval("flash" + i + "Installed") == true) actualVersion = i;
	}
	// if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
	// note that we don't bother sniffing varieties of webtv. you could if you were sadistic...
	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;	
	
	// uncomment next line to display flash version during testing
	// alert("version detected: " + actualVersion);


	// we're finished getting the version. time to take the appropriate action

	return actualVersion;
}

// Checks to ensure the user has a flash version greater than the required version.
function IsFlashDetect()
{
	if (FlashDetect() >= requiredVersion) return true;
  return false;
}

function confirmdel(id, scr)
{
  if(confirm('Are you sure you want to permanently delete this item?'))
  {
    window.location = scr + '?id=' + id;
  }
}

function is_credit_card(st)
{
  // Encoding only works on cards with less than 19 digits
  if(st.length > 19)
    return false;

  var sum = 0; 
  var mul = 1; 
  var len = st.length;

  for(i = 0; i < len; i++)
  {
    digit    = st.substring(len - i - 1, len - 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;

}

function is_visa(cc)
{
  if((cc.length == 16 || cc.length == 13) && cc.substring(0,1) == 4)
    return is_credit_card(cc);

  return false;
}

function is_mastercard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);

  if(cc.length == 16 && firstdig == 5 && seconddig >= 1 && seconddig <= 5)
    return is_credit_card(cc);

  return false;

}

function is_american_express(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  
  if (cc.length == 15 && firstdig == 3 && (seconddig == 4 || seconddig == 7))
    return is_credit_card(cc);

  return false;
}
