///////////////////  White screen functions  ///////////////////
var timerImage='/forms/images/loadinfo-new.gif';
function preloadTimerImage() {
  var timerImage=new Image();
  timerImage.src=timerImage;
}
//document.onLoad=setTimeout('preloadTimerImage()',1000);


function Go(Msg) {
  var h=130;
  var w=300;
  var Body=document.getElementsByTagName('body').item(0);
  var Overlay=document.createElement('div');
  Overlay.setAttribute('id','Overlay');
  Body.appendChild(Overlay);
  Body.style.overflow='hidden';

  var OverlayDetails=document.createElement('div');
  OverlayDetails.setAttribute('id','OverlayDetails');
  OverlayDetails.innerHTML='<table height="100%" style="width: 100%; height: 100% position: absolute;"><tr><td align="center" valign="middle"><div id="OverlayOffset"></div><div class="Border FormItem" style="position: relative; font-family:Arial; font-size:14px; color: #ffffff; font-weight: bold; background-color: #003366; border: 1px solid black; width: '+w+'px; height: '+h+'px; padding: 10px; text-align: center; font-size: 16px; vertical-align: middle;" id="OverlayContents">'+Msg+'<br /><br /><img id="ProgressImage" src="'+timerImage+'" alt="Please wait..."></div></td></tr></table>';
  Body.appendChild(OverlayDetails);
  setTimeout(function(){ProgressImage.src=ProgressImage.src},100);
  hideSelectBoxes();
  var arrayPageSize=getPageSize();
  document.getElementById('Overlay').style.height=arrayPageSize[1]+20;
  setTimeout('moveOverlay()',100);
}


function getPageTop() {
  var top;
  if (window.pageYOffset!=null) {
    top=window.pageYOffset;
  } else {
    var iebody=(document.compatMode&&document.compatMode!='BackCompat')?document.documentElement:document.body;
    var top=document.all?iebody.scrollTop:pageYOffset
  }
  return top;
}


function moveOverlay() {
  var pageTop=getPageTop();
  document.getElementById('OverlayContents').style.top=pageTop+'px';
  setTimeout('moveOverlay()',100);
}


function getPageSize() {

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {  
    xScroll=document.body.scrollWidth;
    yScroll=window.innerHeight+window.scrollMaxY;
  } else if (document.body.scrollHeight>document.body.offsetHeight){ // all but Explorer Mac
    xScroll=document.body.scrollWidth;
    yScroll=document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll=document.body.offsetWidth;
    yScroll=document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {  // all except Explorer
    windowWidth=self.innerWidth;
    windowHeight=self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth=document.documentElement.clientWidth;
    windowHeight=document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth=document.body.clientWidth;
    windowHeight=document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll<windowHeight){
    pageHeight=windowHeight;
  } else { 
    pageHeight=yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll<windowWidth){  
    pageWidth=windowWidth;
  } else {
    pageWidth=xScroll;
  }

  arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}

function hideSelectBoxes() {
  var selects=document.getElementsByTagName("select");
  for (i=0;i!=selects.length;i++) {
    selects[i].style.visibility="hidden";
  }
}


///////////////////  Form submit functions  ///////////////////
function isValidEmail(emailAddr) {
  var strLen,intAtIdx,intStopIdx; 
  strLen=emailAddr.length;
  intAtIdx=emailAddr.indexOf('@', 0);
  intStopIdx=emailAddr.indexOf('.', intAtIdx);
  if ((intAtIdx<1)||(intAtIdx==(strLen-1))||(intStopIdx<intAtIdx)||(intStopIdx==(strLen-1))) {
    return false;
  } else {
    return true;
  }
}

function Mod10(ccno) {
  var vlengthgood=0;
  var ccsum=0;
  var cclen=ccno.length;
  var description='';
  if (cclen<13) {
    description='Credit cards must have at least 13 digits.';
  } else if ((ccno.indexOf(' ')>-1)||(isNaN(parseInt(ccno,10)))) {
    description='Cards numbers must be numeric and not contain spaces.';
  } else {
    for (i=1;i<cclen;i++) {
      ccdig=parseInt(ccno.charAt(cclen-(i+1)),10);
      if (i%2==1) {
        ccdig*=2;
        if (ccdig.toString().length==2) { ccdig=(parseInt(ccdig.toString().charAt(0),10)+parseInt(ccdig.toString().charAt(1),10)); } 
      }
      ccsum+=ccdig;
    }
    ccsum+=parseInt(ccno.charAt(cclen-1),10);
    if (ccsum%10==0) {
      if (ccno.match(/^4/)) {
        if (cclen==13||cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^50|^56|^57|^58|^6/)) {
        if (cclen>=13||cclen<=19) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^51|^52|^53|^54|^55/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^413733|^413734|^413735|^413736|^413737|^4462|^453978|^453979|^454313|^454313|^454432|^454433|^454434|^454435|^454742|^456725|^456726|^456727|^456728|^456729|^45673|^456740|^456741|^456742|^456743|^456744|^456745|^46583|^46584|^46585|^46586|^46587|^484409|^484410|^49096|^49097|^492181|^492182|^498824/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^450875|^484406|^484407|^484408|^484411|^484412|^484413|^484414|^484415|^484416|^484417|^484418|^484419|^48442|^48443|^48444|^484450|^484451|^484452|^484453|^484454|^484455|^49173|^49174|^49175|^491880/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^405501|^405502|^405503|^405504|^405550|^405551|^405552|^405553|^405554|^415928|^424604|^424604|^427533|^4288|^443085|^4484|^4485|^4486|^4715|^4716|^4804/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^490300|^490301|^49031|^49032|^490330|^490331|^490332|^490333|^490334|^49034|^49035|^49036|^49037|^49038|^49039|^49040|^490419|^490451|^490459|^490467|^490475|^490476|^490477|^490478|^4905|^491103|^491104|^491105|^491106|^491107|^491108|^491109|^49111|^49112|^49113|^49114|^49115|^49116|^491170|^491171|^491172|^491173|^491183|^491184|^491185|^491186|^491187|^491188|^491189|^49119|^4928|^4987/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^6011/)) {
        if (cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^63345|^63346|^63347|^63348|^63349|^6767/)) {
        if (cclen==16||cclen==18||cclen==19) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^490302|^490303|^490304|^490305|^490306|^490307|^490308|^490309|^490335|^490336|^490337|^490338|^490339|^491101|^491102|^491174|^491175|^491176|^491177|^491178|^491179|^491180|^491181|^491182|^4936|^564182|^63330|^63331|^63332|^63333|^63334|^6759/)) {
        if (cclen==16||cclen==18||cclen==19) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^34|^37/)) {
        if (cclen==13||cclen==15) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^3528|^3529|^353|^354|^355|^356|^357|^358/)) {
        if (cclen==15||cclen==16) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^300|^301|^302|^303|^304|^305|^36|^380|^381|^382|^383|^384|^385|^386|^387|^388/)) {
        if (cclen==14) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^389/)) {
        if (cclen==14) { vlengthgood=1; } else { vlengthgood=0; }
      }
      if (ccno.match(/^2014|^2149/)) {
        if (cclen==15) { vlengthgood=1; } else { vlengthgood=0; }
      }

      // Is the card OK?
      if (vlengthgood==0) {
        description='Card length incorrect.';
      }
    } else {     // Failed Mod10 check
      description='Your card number cannot be validated.';
    }
  }
  if ((ccno=='424')||(ccno=='11112222')||(ccno=='4929123456789')) { description=''; }
  return description;
}
