﻿var dtCh = '.';
var minYear = 1900;
var maxYear = 2100;

// Allgemeine Funktionen

String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() {
  return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() {
  return this.replace(/\s+$/, "");
}
Array.prototype.indexOf = function(el) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == el) return i;
  }
  return -1;
}
Array.prototype.deleteAt = function(index) {
  for (var i = index; i < this.length; i++) {
    this[i] = this[i + 1];
  }
  this.pop();
}
Array.prototype.insertAt = function(index, value) {
  this.splice(index, '', value);
}
Array.prototype.moveItemAt = function(fromIndex, toIndex) {
  var tmp = this[fromIndex];

  if (fromIndex > toIndex) {
    for (var i = fromIndex; i > toIndex; i--) {
      this[i] = this[i - 1];
    }
  }
  else if (toIndex > fromIndex) {
    for (var i = fromIndex; i < toIndex; i++) {
      this[i] = this[i + 1];
    }
  }
  this[toIndex] = tmp;
}
Array.prototype.array_rand = function(size) {
  if (size > this.length) {
    size = this.length;
  }
  return this.sort(function() { return Math.random() - Math.random() }).slice(0, size);
}
Array.prototype.contains = function(item) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == item) return true;
  }
  return false;
}
Array.prototype.clear = function() {
  while (this.length > 0) this.pop();
}

// extend Number object with methods for converting degrees/radians
Number.prototype.toRad = function() {
  // convert degrees to radians  
  return this * Math.PI / 180;
}

Number.prototype.toDeg = function() {
  // convert radians to degrees (signed)  
  return this * 180 / Math.PI;
}

Number.prototype.toBrng = function() {
  // convert radians to degrees (as bearing: 0...360)
  return (this.toDeg() + 360) % 360;
}

function calcDistance(lat1, lon1, lat2, lon2) {
  var R = 6378.137; // earth's mean radius in km
  var d = Math.acos(Math.sin(lat1.toRad()) * Math.sin(lat2.toRad()) + Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * Math.cos((lon2 - lon1).toRad())) * R;
  return d;
}

Date.prototype.stripTime = function() {
  this.setHours(0);
  this.setMinutes(0);
  this.setSeconds(0);
  this.setMilliseconds(0);
}

Date.prototype.formatDateTime = function(format) {
  var returnStr = '';
  var replace = Date.replaceChars;
  for (var i = 0; i < format.length; i++) {
    var curChar = format.charAt(i);
    if (replace[curChar]) {
      returnStr += replace[curChar].call(this);
    } else {
      returnStr += curChar;
    }
  }
  return returnStr;
};

Date.replaceChars = {
  shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],

  // Day
  d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
  D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
  j: function() { return this.getDate(); },
  l: function() { return Date.replaceChars.longDays[this.getDay()]; },
  N: function() { return this.getDay() + 1; },
  S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
  w: function() { return this.getDay(); },
  z: function() { return "Not Yet Supported"; },
  // Week
  W: function() { return "Not Yet Supported"; },
  // Month
  F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
  m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
  M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
  n: function() { return this.getMonth() + 1; },
  t: function() { return "Not Yet Supported"; },
  // Year
  L: function() { return "Not Yet Supported"; },
  o: function() { return "Not Supported"; },
  Y: function() { return this.getFullYear(); },
  y: function() { return ('' + this.getFullYear()).substr(2); },
  // Time
  a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
  A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
  B: function() { return "Not Yet Supported"; },
  g: function() { return this.getHours() % 12 || 12; },
  G: function() { return this.getHours(); },
  h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
  H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
  i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
  s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
  // Timezone
  e: function() { return "Not Yet Supported"; },
  I: function() { return "Not Supported"; },
  O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
  T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result; },
  Z: function() { return -this.getTimezoneOffset() * 60; },
  // Full Date/Time
  c: function() { return "Not Yet Supported"; },
  r: function() { return this.toString(); },
  U: function() { return this.getTime() / 1000; }
};

Date.nullDate = new Date(1, 0, 1, 12, 0, 0);

function S4() {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function guid() {
  return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}

function isInteger(s) {
  var i;
  for (i = 0; i < s.length; i++) {
    // Check that current character is number.
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  // All characters are numbers.
  return true;
}

function urlEncode(s) {
  return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
};
   
function urlDecode(s) {
  return decodeURIComponent( s.replace( /\+/g, '%20' ).replace( /\%21/g, '!' ).replace( /\%27/g, "'" ).replace( /\%28/g, '(' ).replace( /\%29/g, ')' ).replace( /\%2A/g, '*' ).replace( /\%7E/g, '~' ) );
};


function stripCharsInBag(s, bag) {
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function stripInvalidChars(s) {
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (isInteger(c)) returnString += c;
  }
  return returnString;
}

/**
 * HTML-Encode the supplied input
 * 
 * Parameters:
 *
 * (String)  source    The text to be encoded.
 * 
 * (boolean) display   The output is intended for display.
 *
 *                     If true:
 *                     * Tabs will be expanded to the number of spaces 
 *                       indicated by the 'tabs' argument.
 *                     * Line breaks will be converted to <br />.
 *
 *                     If false:
 *                     * Tabs and linebreaks get turned into &#____;
 *                       entities just like all other control characters.
 *
 * (integer) tabs      The number of spaces to expand tabs to.  (Ignored 
 *                     when the 'display' parameter evaluates to false.)
 *
 * v 0.3 - January 4, 2006
 */
function htmlEncode(source) {
  display = true;
  tabs = 4;
  function special(source) {
    var result = '';
    for (var i = 0; i < source.length; i++) {
      var c = source.charAt(i);
      if (c < ' ' || c > '~') {
        c = '&#' + c.charCodeAt() + ';';
      }
      result += c;
    }
    return result;
  }
  function format(source) {
    // Use only integer part of tabs, and default to 4
    tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
    // split along line breaks
    var lines = source.split(/\r\n|\r|\n/);
    // expand tabs
    for (var i = 0; i < lines.length; i++) {
      var line = lines[i];
      var newLine = '';
      for (var p = 0; p < line.length; p++) {
        var c = line.charAt(p);
        if (c === '\t') {
          var spaces = tabs - (newLine.length % tabs);
          for (var s = 0; s < spaces; s++) {
            newLine += ' ';
          }
        }
        else {
          newLine += c;
        }
      }
      // If a line starts or ends with a space, it evaporates in html
      // unless it's an nbsp.
      newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
      lines[i] = newLine;
    }
    // re-join lines
    var result = lines.join('<br />');
    // break up contiguous blocks of spaces with non-breaking spaces
    result = result.replace(/  /g, ' &nbsp;');
    // tada!
    return result;
  }
  var result = source;
  // ampersands (&)
  result = result.replace(/\&/g, '&amp;');
  // less-thans (<)
  result = result.replace(/\</g, '&lt;');
  // greater-thans (>)
  result = result.replace(/\>/g, '&gt;');
  if (display) {
    // format for display
    result = format(result);
  }
  else {
    // Replace quotes if it isn't for display,
    // since it's probably going in an html attribute.
    result = result.replace(new RegExp('"', 'g'), '&quot;');
  }
  // special characters
  result = special(result);
  // tada!
  return result;
}

function makeURl(s) {
  var i;
  var lastChar = '#';
  var returnString = '';
  s = s.toLowerCase();
  for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    switch (c) {
      case 'ö':
        returnString += 'oe';
        lastChar = c;
        break;
      case 'ä':
        returnString += 'ae';
        lastChar = c;
        break;
      case 'ü':
        returnString += 'ue';
        lastChar = c;
        break;
      case 'Ö':
        returnString += 'oe';
        lastChar = c;
        break;
      case 'Ä':
        returnString += 'ae';
        lastChar = c;
        break;
      case 'Ü':
        returnString += 'ue';
        lastChar = c;
        break;
      case 'ß':
        returnString += 'ss';
        lastChar = c;
        break;
      default:
        if (((c >= '0') && (c <= '9')) ||
                  ((c >= 'a') && (c <= 'z'))) {
          returnString += c;
          lastChar = c;
        }
        if (c == ' ' && lastChar != '-') {
          returnString += '-';
          lastChar = '-';
        }
        break;
    }
  }
  return returnString;
}

function daysInFebruary(year) {
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}

function DaysArray(n) {
  for (var i = 1; i <= n; i++) {
    this[i] = 31
    if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
    if (i == 2) { this[i] = 29 }
  }
  return this;
}

function isDate(dtStr) {
  var daysInMonth = DaysArray(12)
  var pos1 = dtStr.indexOf(dtCh)
  var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
  var strDay = dtStr.substring(0, pos1)
  var strMonth = dtStr.substring(pos1 + 1, pos2)
  var strYear = dtStr.substring(pos2 + 1)
  strYr = strYear
  if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
  if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
  for (var i = 1; i <= 3; i++) {
    if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
  }
  month = parseInt(strMonth)
  day = parseInt(strDay)
  year = parseInt(strYr)

  if (pos1 == -1 || pos2 == -1) {
    //alert("The date format should be : mm/dd/yyyy")
    return false
  }
  if (strMonth.length < 1 || month < 1 || month > 12) {
    //alert("Please enter a valid month")
    return false
  }
  if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
    //alert("Please enter a valid day")
    return false
  }
  if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
    //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
    return false
  }
  if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
    //alert("Please enter a valid date")
    return false
  }
  return true
}

function getDate(dtStr) {
    if (isDate(dtStr)) {
        var daysInMonth = DaysArray(12)
        var pos1 = dtStr.indexOf(dtCh)
        var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
        var strDay = dtStr.substring(0, pos1)
        var strMonth = dtStr.substring(pos1 + 1, pos2)
        var strYear = dtStr.substring(pos2 + 1)
        strYr = strYear
        if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
        if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
            if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
        }
        month = parseInt(strMonth)
        day = parseInt(strDay)
        year = parseInt(strYr)
        
        return new Date(year, month-1, day, 12, 0 , 0);
    } else {
        return null;
    }
}

var BrowserDetect = {
  init: function() {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },
  searchString: function(data) {
    for (var i = 0; i < data.length; i++) {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  searchVersion: function(dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
  },
  dataBrowser: [
		{ string: navigator.userAgent,
		  subString: "OmniWeb",
		  versionSearch: "OmniWeb/",
		  identity: "OmniWeb"
		},
		{
		  string: navigator.vendor,
		  subString: "Apple",
		  identity: "Safari"
		},
		{
		  prop: window.opera,
		  identity: "Opera"
		},
		{
		  string: navigator.vendor,
		  subString: "iCab",
		  identity: "iCab"
		},
		{
		  string: navigator.vendor,
		  subString: "KDE",
		  identity: "Konqueror"
		},
		{
		  string: navigator.userAgent,
		  subString: "Firefox",
		  identity: "Firefox"
		},
		{
		  string: navigator.vendor,
		  subString: "Camino",
		  identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		  string: navigator.userAgent,
		  subString: "Netscape",
		  identity: "Netscape"
		},
		{
		  string: navigator.userAgent,
		  subString: "MSIE",
		  identity: "Explorer",
		  versionSearch: "MSIE"
		},
		{
		  string: navigator.userAgent,
		  subString: "Gecko",
		  identity: "Mozilla",
		  versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		  string: navigator.userAgent,
		  subString: "Mozilla",
		  identity: "Netscape",
		  versionSearch: "Mozilla"
		}
	],
  dataOS: [
		{
		  string: navigator.platform,
		  subString: "Win",
		  identity: "Windows"
		},
		{
		  string: navigator.platform,
		  subString: "Mac",
		  identity: "Mac"
		},
		{
		  string: navigator.platform,
		  subString: "Linux",
		  identity: "Linux"
		}
	]

};

BrowserDetect.init();

function getTopPos(inputObj) {
  /*
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  if(inputObj.tagName!='HTML'){
  returnValue += inputObj.offsetTop;
  if(document.all)returnValue+=inputObj.clientTop;
  }
  }
  
  if (document.all) {
  returnValue+= document.documentElement.scrollTop;
  }
  else {
  //returnValue+=1;
  returnValue+= window.pageYOffset;
  }
  
  return returnValue;
  */
  var location = Sys.UI.DomElement.getLocation(inputObj);
  return location.y;
}

function getLeftPos(inputObj) {
  /*
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  if(inputObj.tagName!='HTML'){
  returnValue += inputObj.offsetLeft;
  if(document.all)returnValue+=inputObj.clientLeft;
  }
  }
  
  if (document.all) {
  returnValue+= document.documentElement.scrollLeft;
  }
  else {
  //returnValue+=1;
  returnValue+= window.pageXOffset;
  }

  return returnValue;
  */
  var location = Sys.UI.DomElement.getLocation(inputObj);
  return location.x;
}

function stopEvent(ev) {
  ev || (ev = window.event);
  if (document.all) {
    ev.cancelBubble = true;
    ev.returnValue = false;
  }
  else {
    ev.preventDefault();
    ev.stopPropagation();
  }
  return false;
}

function addEvent(el, evname, func) {
  if (el.addEventListener) { el.addEventListener( evname, func, false ); } else if (el.attachEvent) {
        el["e"+evname+func] = func; el[evname+func] = function() { el["e"+evname+func]( window.event ); }
        el.attachEvent( "on"+evname, el[evname+func] );
  }
  /* 
  if (el.attachEvent) { // IE
    el.attachEvent("on" + evname, func);
  } else if (el.addEventListener) { // Gecko / W3C
    el.addEventListener(evname, func, true);
  } else {
    el["on" + evname] = func;
  }
  */
}

function removeEvent(el, evname, func) {
  if (el.removeEventListener) { el.removeEventListener( evname, func, false ); } else if (el.detachEvent) {
      el.detachEvent( "on"+evname, el[evname+func] );
      el[evname+func] = null;
      el["e"+evname+func] = null;
  }
  /*
  if (el.detachEvent) { // IE
    el.detachEvent("on" + evname, func);
  } else if (el.removeEventListener) { // Gecko / W3C
    el.removeEventListener(evname, func, true);
  } else {
    el["on" + evname] = null;
  }
  */
}

function dezRound(num, pos) {
  if (pos < 0) {
    pos = Math.pow(10, Math.abs(pos));
    return Math.round(num / pos) * pos;
  }
  else if (pos > 0) {
    pos = Math.pow(10, pos);
    return Math.round(num * pos) / pos;
  }
  else {
    return Math.round(num);
  }
}

function GetRandom(min, max) {
  if (min > max) {
    return (-1);
  }

  if (min == max) {
    return (min);
  }

  return (min + parseInt(Math.random() * (max - min + 1)));
}


//File Functions
function getFileExtension(fileName) {
  var lastPoint = fileName.lastIndexOf('.');
  return fileName.substr(lastPoint, fileName.length);
}

function getFilename(path) {
  var lastSlash = path.lastIndexOf("/");
  return path.substring(lastSlash + 1, path.length);
}

function getFilenameWithoutExtension(path) {
  var filename = getFilename(path);
  var lastPoint = filename.lastIndexOf('.');
  return filename.substring(0, lastPoint);
}

function getFileDir(path) {
  var lastSlash = path.lastIndexOf("/");
  return path.substring(0, lastSlash);
}


//image viewer

var elOverlay = null;
var elImageFrame = null;

function showImage(src, width, height) {
  var objBody = document.getElementsByTagName("body").item(0);

  hideBanner();
  
  try {
    elOverlay = document.createElement('div');
    elOverlay.className = 'image-popup-overlay';
    elOverlay.onclick = hideImagePopup;
    objBody.appendChild(elOverlay);

    elImageFrame = document.createElement('div');
    elImageFrame.className = 'image-popup-frame';
    elImageFrame.style.width = width + 'px';
    elImageFrame.style.height = height + 'px';
    elImageFrame.style.marginLeft = '-' + ((width + 26) / 2) + 'px';
    elImageFrame.style.marginTop = '-' + ((height + 26) / 2) + 'px';
    elImageFrame.onclick = hideImagePopup;

    var elProgress = document.createElement('div');
    elProgress.id = 'ImagePopupLoading';
    elProgress.className = 'image-popup-loading';
    elProgress.onclick = hideImagePopup;

    elImageFrame.appendChild(elProgress);

    objBody.appendChild(elImageFrame);

    var image = new Image();

    image.onload = function() {
      document.getElementById('ImagePopupLoading').style.display = 'none';

      var elImage = document.createElement('img');
      elImage.style.width = width + 'px';
      elImage.style.height = height + 'px';
      elImage.src = src;
      elImage.onclick = hideImagePopup;

      elImageFrame.appendChild(elImage);
    }

    image.src = src;
  }
  catch(ex) {
    showBanner();
  }
}

function hideImagePopup() {
  var objBody = document.getElementsByTagName("body").item(0);
  objBody.removeChild(elImageFrame);
  objBody.removeChild(elOverlay);
  elImageFrame = null;
  elOverlay = null;
  showBanner();
}



/*
Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */

function validateCreditCardNumber(ccNumb) {
  var valid = '0123456789'  // Valid digits in a credit card number
  var len = ccNumb.length;  // The length of the submitted cc number
  var iCCN = parseInt(ccNumb);  // integer of ccNumb
  var sCCN = ccNumb.toString();  // string of ccNumb
  sCCN = sCCN.replace(/^\s+|\s+$/g, '');  // strip spaces
  var iTotal = 0;  // integer total set at zero
  var bNum = true;  // by default assume it is a number
  var bResult = false;  // by default assume it is NOT a valid cc
  var temp;  // temp variable for parsing string
  var calc;  // used for calculation of each digit

  // Determine if the ccNumb is in fact all numbers
  for (var j = 0; j < len; j++) {
    temp = '' + sCCN.substring(j, j + 1);
    if (valid.indexOf(temp) == '-1') { bNum = false; }
  }

  // if it is NOT a number, you can either alert to the fact, or just pass a failure
  if (!bNum) {
    /*alert("Not a Number");*/bResult = false;
  }

  // Determine if it is the proper length 
  if ((len == 0) && (bResult)) {  // nothing, field is blank AND passed above # check
    bResult = false;
  } else {  // ccNumb is a number and the proper length - let's see if it is a valid card number
    if (len >= 15) {  // 15 or 16 for Amex or V/MC
      for (var i = len; i > 0; i--) {  // LOOP throught the digits of the card
        calc = parseInt(iCCN) % 10;  // right most digit
        calc = parseInt(calc);  // assure it is an integer
        iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
        i--;  // decrement the count - move to the next digit in the card
        iCCN = iCCN / 10;  // subtracts right most digit from ccNumb
        calc = parseInt(iCCN) % 10;  // NEXT right most digit
        calc = calc * 2;                                 // multiply the digit by two
        // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
        // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
        switch (calc) {
          case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
          case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
          case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
          case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
          case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
          default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
        }
        iCCN = iCCN / 10;  // subtracts right most digit from ccNum
        iTotal += calc;  // running total of the card number as we loop
      }  // END OF LOOP
      if ((iTotal % 10) == 0) {  // check to see if the sum Mod 10 is zero
        bResult = true;  // This IS (or could be) a valid credit card number.
      } else {
        bResult = false;  // This could NOT be a valid credit card number
      }
    }
  }

  return bResult; // Return the results
}

function MM_openBrWindow(theURL,winName,features) { 
   window.open(theURL,winName,features);
 }

function selectSelectValue(el, value) {
  for (var i = 0; i < el.options.length; i++) {
    //el.options[i].selected = false;
    if (el.options[i].value == value) {
      el.options[i].selected = true;
      return;
    }
  }
}

function selectHasValue(el, value) {
  for (var i = 0; i < el.options.length; i++) {
    if (el.options[i].value == value) {
      return true;
    }
  }
  return false;
}

function getSelectedSelectValue(el) {
  //return el.options[el.selectedIndex].value;
  return el.value;
}

function getSelectedSelectText(el) {  
  return el.options[el.selectedIndex].text;
}

function getElementsByClass(searchClass, node, tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}


