

function _Write_Glossary_Description(faq_id) {
    var data_topics = new Array()

data_topics['AJVNK'] = new Array('Return Policy','View our Return Policy. [<a href="http://1st-usa.com/faq_db.html?cat=products&topic=policies&id=3fcc#3fcc2">Go &raquo;</a>]')
data_topics['AUDJY'] = new Array('Guarantee','View our 100% Calling Card Guarantee. [<a href="http://1st-usa.com/faq_db.html?cat=products&topic=policies&id=dc635#dc635">Go &raquo;</a>]')
data_topics['CSFTK'] = new Array('Carrier Service Fee','A fee assessed by the carrier. The carrier is the company that provides the network services for this card.')
data_topics['DARZR'] = new Array('Disconnect Fee','A fee that is charged when a telephone call is ended.')
data_topics['DZAFF'] = new Array('Username','You will create and submit a unique username when you signup to become a 1st-USA.com customer. Your username is a unique identifier associated with your unique password.')
data_topics['EPCGP'] = new Array('Information Security','We will safeguard your personal information. Under no circumstances will we disclose or share your information with any unauthorized third party. All transactions are processed by our secure server using SSL encryption. We do not store your credit card information.')
data_topics['FFHHZ'] = new Array('PINless Dialing','Make phone calls without having to dial your PIN. PINless dialing is a convenient feature that allows you to register your phone number(s) at the time of purchase so that you can place long distance calls without having to dial a PIN.')
data_topics['KJXAR'] = new Array('Customer Service','The team that will help you with any purchase made at 1st-USA.com. Use the Contact Us link at the bottom of any page for more information.')
data_topics['KPAGX'] = new Array('Rechargeable PIN','Also known as a rechargeable phone card. The ability to recharge a PIN means that you have the additional conveniences of adding more money to the same PIN and never having to remember a new PIN. Currently, you may recharge applicable cards online or over the phone.')
data_topics['KVPEZ'] = new Array('PIN','A <strong>P</strong>ersonal <strong>I</strong>dentification <strong>N</strong>umber is the unique tracking code associated with an individual prepaid calling card.')
data_topics['MHZMG'] = new Array('Minute Rounding','Rounding Examples:<BR><BR>3-Minute Rounding: A phone call lasting 10 minutes and 30 seconds will be billed for 12 minutes.<BR><BR>1-Minute Rounding: A phone call lasting 10 minutes and 30 seconds will be billed for 11 minutes.')
data_topics['NAMST'] = new Array('International Calls','A phone call to a destination outside of the Unites States of America. Or a phone call from any country back to the United States of America.')
data_topics['NVZKA'] = new Array('Multiple Calls Fee','Multiple calls are subject up to a $0.25 disconnect fee and up to a 25% cost recovery fee.')
data_topics['NZEFR'] = new Array('Payphone Fee','An FCC imposed fee for handling a phone call made from a payphone.')
data_topics['PYUNV'] = new Array('Maintenance Fee','Unless otherwise stated, this fee is typically deducted immediately after hanging up on your first phone call (if a balance remains), and again at the advertised schedule for as long as a balance exists.<BR><BR>Customers can avoid a maintenance fee by using all of the available minutes on their calling card in one phone call, or purchasing a calling card with no fees.')
data_topics['QGXTS'] = new Array('Instant PIN','PINs are delivered to you instantly via email (also see PIN).')
data_topics['QSXAY'] = new Array('Surcharge','Fee for handling and/or processing a product or service.')
data_topics['RYABK'] = new Array('Clean','The industry term for a calling card having no additional carrier fees beyond the advertised rate per minute. This type of card is ideal for those who want to leave minutes on it for future use.')
data_topics['SJQAW'] = new Array('Expiration','All cards sold at 1st-USA.com have an expiration date. Any unused minutes on a calling card will be forfeited at the point of expiration.')
data_topics['TDCGK'] = new Array('Password','You will create and submit a unique password when you signup to become a 1st-USA.com customer. Your password is a unique identifier associated with your unique username.')
data_topics['TTYBM'] = new Array('Access Number','The phone number you will dial first before entering your PIN and making a phone call.')
data_topics['UQMPM'] = new Array('SSL (Secure Sockets Layer)','A protocol developed by Netscape for transmitting private documents via the Internet. SSL works by using a private key to encrypt data that\'s transferred over the SSL connection.<BR><BR>Web browsers support SSL, and many Web sites use the protocol to obtain confidential user information, such as credit card numbers.')
data_topics['UQPNU'] = new Array('Carrier Customer Service Number','Call this number if you need assistance with using your calling card.')
data_topics['VVEGR'] = new Array('Carrier','A company that creates and sells telecommunications products such as prepaid calling cards.')
data_topics['VWCYD'] = new Array('Connection Fee','1st-USA.com does not sell calling cards with connection fees. <BR><BR>This is a carrier assessed fee for connecting a phone call.')
data_topics['XCPFR'] = new Array('Domestic Calls','A phone call within the continental United States, Alaska, Hawaii, Guam, Puerto Rico, Saipan, the US Virgin Islands, and Canada.')
data_topics['XUEDR'] = new Array('Local Access Number','An access number that is local to the person dialing it. Some calling cards include local access phone numbers, which may offer an additional per minute rate savings when dialed instead of dialing  the toll-free access number.')
data_topics['YAMPA'] = new Array('Network Services','Newtork services include all things that the carrier does to maintain a product\'s quality, configuration, installation, implementation, integration, maintenance, and/or management of the networked systems used for the transmission of information in voice format.')
data_topics['3fcc2'] = new Array('What is your return policy?','1st-USA.com can accept returns only in the event of a defective phone card (PIN). Please view our guarantee, however, for other remedies if you are having trouble with your phone card (PIN).')
data_topics['dc635'] = new Array('Do you offer a guarantee?','1st-USA.com is a prepaid calling card retailer.  We purchase the calling cards we sell from telecommunications carriers who create and service those products. In the unusual event that performance issues arise with a phone card sold on our website, or that you do not receive the terms and/or rates advertised for a phone card sold on our website, it is the carrier\'s responsibility to provide an adequate remedy. Included with every order that we process is a<BR> direct toll-free support number to the carrier that services the calling card.<BR><BR>If a carrier is unable to provide a satisfactory remedy, customers must contact 1st-USA.com within 30 days of the original purchase date to begin an inquiry. We will intervene on your behalf with the carrier to have a phone card or lost minutes promptly replaced, or we will provide you with additional minutes to make up for a defect unresolved by the carrier.<BR><BR>Additionally:<BR><BR>1st-USA.com\'s guarantee applies only to your most recent purchase.  We will not refund time or money for subsequent purchases of the same phone card.  If your experience with a particular product has proved unsatisfactory for a particular country, international cell destination, or otherwise, please do not purchase or recharge that product.<BR><BR>1st-USA.com\'s guarantee is limited to the original retail purchase and is non-transferable. Warranty claims must be made within 30 days of purchase. All PIN sales are nonrefundable and may not be returned or exchanged.<BR><BR>1st-USA.com\'s liability will not exceed the original purchase price of a defective phone card. 1st-USA.com makes no warranty of its products with respect to incidental, consequential, or other damages.')

    document.getElementById('glossaryElement').innerHTML = data_topics[faq_id][1];

}

function _Position_Glossary_Div_IE(w, h, posX, posY) {

    var winX;
    var winY;
    var screenPosX;
    var screenPosY;
    var cursorPadding;
    var margLeft;
    var margRight;
    var margTop;
    var margBottom;
    var newX;
    var newY;
    var newScreenX;
    var newScreenY;

    // Find the screen dimensions.
    winX = document.body.clientWidth - 5; 
    winY = document.body.clientHeight - 5;

    // Correct posX, posY for scroll.
    screenPosX = posX - document.body.scrollLeft;
    screenPosY = posY - document.body.scrollTop;

    cursorPadding = 50;
    margLeft = screenPosX - w;
    margRight = winX - screenPosX - w;
    margTop = screenPosY - h;
    margBottom = winY - screenPosY - h;

    if(margLeft > margRight) {
	newX = posX - w - cursorPadding;
    } else {
	newX = posX + cursorPadding;
    }
    if(margTop > margBottom) {
	newY = posY - h - cursorPadding;
    } else {
	newY = posY + cursorPadding;
    }

    newScreenX = newX - document.body.scrollLeft;
    newScreenY = newY - document.body.scrollTop;

    if(newScreenX < 0) {
	newX = document.body.scrollLeft;
    }
    if(newScreenX > winX - w) {
	newX = winX - w + document.body.scrollLeft;
    }

    if(newScreenY < 0) {
	newY = document.body.scrollTop;
    }
    if(newScreenY > winY - h) {
	newY = winY - h + document.body.scrollTop;
    }

    // Make position relative to the cursor.
    document.getElementById('glossaryElement').style.left = newX + "px";
    document.getElementById('glossaryElement').style.top = newY + "px";

}

function _Position_Glossary_Div(w, h, posX, posY) {

    var winX;
    var winY;
    var screenPosX;
    var screenPosY;
    var cursorPadding;
    var margLeft;
    var margRight;
    var margTop;
    var margBottom;
    var newX;
    var newY;
    var newScreenX;
    var newScreenY;

    // Find the screen dimensions.
    winX = window.innerWidth - 20; // better than outer
    winY = window.innerHeight - 20;

    // Correct posX, posY for scroll.
    screenPosX = posX - window.pageXOffset;
    screenPosY = posY - window.pageYOffset;

    cursorPadding = 20;
    margLeft = screenPosX - w;
    margRight = winX - screenPosX - w;
    margTop = screenPosY - h;
    margBottom = winY - screenPosY - h;

    if(margLeft > margRight) {
	newX = posX - w - cursorPadding;
    } else {
	newX = posX + cursorPadding;
    }
    if(margTop > margBottom) {
	newY = posY - h - cursorPadding;
    } else {
	newY = posY + cursorPadding;
    }

    newScreenX = newX - window.pageXOffset;
    newScreenY = newY - window.pageYOffset;

    if(newScreenX < 0) {
	newX = window.pageXOffset;
    } else if(newScreenX > winX - w) {
	newX = window.pageXOffset + winX - w;
    }

    if(newScreenY < 0) {
	newY = window.pageYOffset;
    } else if(newScreenY > winY - h) {
	newY = window.pageYOffset + winY - h;
	newY = window.pageYOffset;
    }

    // Make position relative to the cursor.
    document.getElementById('glossaryElement').style.left = newX + "px";
    document.getElementById('glossaryElement').style.top = newY + "px";

}

function _Resize_Glossary_Div(w, h) {
    var mydiv = document.getElementById('glossaryElement');
    var is_growing = 1;
    if(w > 0) {
	mydiv.style.width = w + "px";
    }
    if(h > 0) {
	mydiv.style.height = h + "px";
    }

    while(is_growing > 0) {
	w = mydiv.scrollWidth;
	h = mydiv.scrollHeight;
	// alert(w + ", " + h);
	if(w < h) {
	    w += 50;
	    mydiv.style.width = w + "px";
	    is_growing++;
	} else {
	    is_growing = 0;
	}
	if(is_growing > 20) { is_growing = 0; }
	// is_growing = 0;
    }
    return Array(w, h);
}

function _Create_Glossary_Div() {
    /* 

    This was not encapsulated before because part of it lay outside
    any function, naked in the global scope.

    */

    // Create the glossary div.
    var glossaryDiv = document.createElement('div');
    glossaryDiv.setAttribute('id', 'glossaryElement');
    glossaryDiv.style.width = "50px";
    glossaryDiv.style.left = "50px";
    glossaryDiv.style.position = "absolute";
    glossaryDiv.style.backgroundColor = "#fceec8";
    glossaryDiv.style.border = "2px #fb0 solid";
    glossaryDiv.style.padding = "5px 5px 5px 5px";
    glossaryDiv.style.textAlign = "left";
    document.body.appendChild(glossaryDiv);
}

function _Display_Floated_Msg(e, w, h) {
    // Resize it to be a little wider than it is tall.
    wh = _Resize_Glossary_Div(w, h);
    w = wh[0];
    h = wh[1];

    // Get the cursor coordinates.
    $coords = _GetMouseXY(e);
    posX = $coords[0];
    posY = $coords[1];
    
    // Move the DIV to a good location.
    if(document.all) {
	_Position_Glossary_Div_IE(w, h, posX, posY);
    } else {
	_Position_Glossary_Div(w, h, posX, posY);
    }
    
    // Show it.
    document.getElementById('glossaryElement').style.visibility = "visible";
}

function Glossary(e, faq_id) {

    var wh;
    var w;
    var h;
    var posX;
    var posY;

    // Make sure the glossary DIV exists.
    if(!document.getElementById('glossaryElement')) {
	_Create_Glossary_Div();
    }

    if (faq_id !== '') {
	
	// Fill it with some contents.
	_Write_Glossary_Description(faq_id);

	// Display it.
	_Display_Floated_Msg(e);
	
    } else {
	// Shrink the width then hide the DIV.
	document.getElementById('glossaryElement').style.width = "50px";
	document.getElementById('glossaryElement').style.visibility = "hidden";
    }

}

function Float_Text_Msg(e, txt, w, h) {
    // Like Glossary(), but the text is provided as an argument.

    // Make sure the glossary DIV exists.
    if(!document.getElementById('glossaryElement')) {
	_Create_Glossary_Div();
    }

    if (txt !== '') {
	
	// Fill it with some contents.
	document.getElementById('glossaryElement').innerHTML = txt;

	// Display it.
	_Display_Floated_Msg(e, w, h);

    } else {
	// Shrink the width then hide the DIV.
	document.getElementById('glossaryElement').style.width = "50px";
	document.getElementById('glossaryElement').style.visibility = "hidden";
    }

}

function _GetMouseXY(e) {
   var posX = 0;
   var posY = 0;
   // var e = (!e) ? window.event : e;
   if (e.pageX || e.pageY) {
      posX = e.screenX;
      posY = e.screenY; 
      posX = e.pageX;
      posY = e.pageY; 
   } else if (e.clientX || e.clientY) {
      if (document.body.scrollLeft || document.body.scrollTop) {
         posX = e.clientX + document.body.scrollLeft;
         posY = e.clientY + document.body.scrollTop;
      } else {
         posX = e.clientX + document.documentElement.scrollLeft;
         posY = e.clientY + document.documentElement.scrollTop;
      }
   }

   $retvals = Array(posX, posY);
   return $retvals;
   
}

// function _GetMouseXY(e) {
//    var posX = 0;
//    var posY = 0;
//    var e = (!e) ? window.event : e;
//    if (e.pageX || e.pageY) {
//       posX = e.pageX;
//       posY = e.pageY; 
//    }
//    else if (e.clientX || e.clientY) {
//       if (document.body.scrollLeft || document.body.scrollTop) {
//          posX = e.clientX + document.body.scrollLeft;
//          posY = e.clientY + document.body.scrollTop;
//       }
//       else {
//          posX = e.clientX + document.documentElement.scrollLeft;
//          posY = e.clientY + document.documentElement.scrollTop;
//       }
//    }
//  
//    document.getElementById(id).style.left = posX + 30;
//    document.getElementById(id).style.top = posY + 5;
// }

function ratefinder_selected(id, c) {
    sel = document.getElementById(id);
    if('' + sel == 'null') {
	return;
    }
    len = sel.length;
    for(i = 0; i < len; i++) {
        op = sel.options[i];
        if(op.value == c) {
            sel.selectedIndex = i;
        }
    }
}

/*  START of the dynamic select file */
function doc_rewrite(html){
   //alert(html);
   testStr = "" + document.all; 
   if(testStr != "undefined") {
       document.all['den_select'].innerHTML = html;
   }
    else if( document.getElementById)  { // N6+, IE5+, M1
        document.getElementById("den_select").innerHTML = html;
   } 
return;
}

function dynamic_select_by_card(x, arr){
    // alert(x);
    
    var html = "<select name=\"denoms\" style=\"width:125px;position:relative;left:-2px\"><option value=\"none\" SELECTED> &mdash;Amount&mdash;</option>";
    
    for(var i=0; i < arr[x].length; i++){
	//alert("In Loop.");
	html += "<option>$";
	html += arr[x][i];
	html += "</option>\n";
    }
    
    html += "</select>";

    // Submit button rewrite not functional under mozilla. Changed the div re-write to a span re-write,
    // and placed the button outside of the "den_select" id.
    //html += "<INPUT type=\"submit\" value=\"&raquo;Go&raquo;\" onClick=\"this.form.submit();\" style=\"height:17px;width:45px;line-height:10px;position:relative;left:-2px;top:-2px;font-weight:bold;color:#336699;background-color:#99ddff\">\n";

    doc_rewrite(html);
}

function dynamic_qty_select(x, arr, sel_id){	
    document.location = "./" + x;
}


/*  END of the dynamic select file */
/* START  of bookmark_link */
function Bookmark_Link() {
    if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
	var sText = "<span style='cursor:hand;'";
	sText += " onclick='window.external.AddFavorite(location.href,";
	sText += "document.title);'>Bookmark this page</span>";
	document.write(sText);
    }
}

function Bookmark_Link2() {
  if (window.external)
  {
   var urlAddress = location.href;
   var pageName = document.title;
   window.external.AddFavorite(urlAddress, pageName)
  }
  else
  { 
   alert("Sorry! Your browser doesn't support this function.");
  }
 }
// --></script>}

function Bookmark_Link_Branded(affnumber, cobranded, css_class){


    if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {

	var my_location = location.href;
	my_location = my_location.substring(0, my_location.indexOf("?co_branded"));	
	
	var brand_num = cobranded == "nar" ? "2" : "1";
	
	my_location += "?co_branded=" + brand_num + "&aff=" + affnumber + "&bm=1";

	var Text2 = "<a href='" + my_location + "'";
	if(css_class + "" != "undefined" && css_class + "" != "Undefined") {
	    Text2 += " class='" + css_class + "'";
	}
	Text2 += ">Bookmark this page</a>";
 	document.write(Text2); 
  }

}

function Make_Branded_Bookmark(){
	window.external.AddFavorite(location.href, document.title);
}
/* END of bookmark_link */	




/* START of Random String generator */
function randomString(string_length) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
/* END of Random String Generator */



/* START of obscure_email*/
/*This function creates a email link to mailbox@site.*/

function create_obscured_link(mailbox,site){
var len = site.length;
var maillen = mailbox.length;

  document.write('<a href="');
  document.write('m');
  document.write('a');
  document.write('i');
  document.write('l');
  document.write('t');
  document.write('o');
  document.write(':');

  for (var i=0; i<maillen; i++)
  {
    document.write(mailbox.substring(i,i+1));
  }

  document.write('@');

  for (var i=0; i<len; i++)
  {
    document.write(site.substring(i,i+1));
  }
  document.write('">');

  for (var i=0; i<maillen; i++)
  {
    document.write(mailbox.substring(i,i+1));
  }
  document.write('@');
  for (var i=0; i<len; i++)
  {
    document.write(site.substring(i,i+1));
  }
  document.write('</a>');

}


/*This function creates a email link to support@
whatever domain name has been passed.*/
function create_obscured_support_link(site){
var len = site.length;
  document.write('<a href="');
  document.write('m');
  document.write('a');
  document.write('i');
  document.write('l');
  document.write('t');
  document.write('o');
  document.write(':');
  document.write('s');
  document.write('u');
  document.write('p');
  document.write('p');
  document.write('o');
  document.write('r');
  document.write('t');
  document.write('@');
  for (var i=0; i<len; i++)
  {
    document.write(site.substring(i,i+1));
  }
  document.write('">s');
  document.write('u');
  document.write('p');
  document.write('p');
  document.write('o');
  document.write('r');
  document.write('t');
  document.write('@');
  for (var i=0; i<len; i++)
  {
    document.write(site.substring(i,i+1));
  }
  document.write('</a>');

}


/*This function takes the site name and creates a support
address out of it.*/
function create_support_address(site){

var len = site.length;
 document.write('s');
  document.write('u');
  document.write('p');
  document.write('p');
  document.write('o');
  document.write('r');
  document.write('t');
  document.write('@');
  for (var i=0; i<len; i++)
  {
    document.write(site.substring(i,i+1));
  }


}

/* END of obscure email */
/* START of md5 */
/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Copyright (C) Paul Johnston 1999 - 2000.
 * Updated by Greg Holt 2000 - 2001.
 * See http://pajhome.org.uk/site/legal.html for details.
 */
/*
NOTE BY KEVIN HAIDL, 4 October 2002: the referenced copyright page
above places this library under the Lesser GNU Public License which
explicitly does *not* subsume works calling the functions of this
library.  Only if you create an executable incorporating it do you
produce a "derivative product" of the library.  See section 5 of the
LGPL.
*/
/*
 * Convert a 32-bit number to a hex string with ls-byte first
 */
var hex_chr = "0123456789abcdef";
function rhex(num) {
  str = "";
  for(j = 0; j <= 3; j++)
    str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
           hex_chr.charAt((num >> (j * 8)) & 0x0F);
  return str;
}

/*
 * Convert a string to a sequence of 16-word blocks, stored as an array.
 * Append padding bits and the length, as described in the MD5 standard.
 */
function str2blks_MD5(str) {
  nblk = ((str.length + 8) >> 6) + 1;
  blks = new Array(nblk * 16);
  for(i = 0; i < nblk * 16; i++) blks[i] = 0;
  for(i = 0; i < str.length; i++)
    blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
  blks[i >> 2] |= 0x80 << ((i % 4) * 8);
  blks[nblk * 16 - 2] = str.length * 8;
  return blks;
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally 
 * to work around bugs in some JS interpreters.
 */
function add(x, y) {
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left
 */
function rol(num, cnt) {
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * These functions implement the basic operation for each round of the
 * algorithm.
 */
function cmn(q, a, b, x, s, t) {
  return add(rol(add(add(a, q), add(x, t)), s), b);
}
function ff(a, b, c, d, x, s, t) {
  return cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function gg(a, b, c, d, x, s, t) {
  return cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function hh(a, b, c, d, x, s, t) {
  return cmn(b ^ c ^ d, a, b, x, s, t);
}
function ii(a, b, c, d, x, s, t) {
  return cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Take a string and return the hex representation of its MD5.
 */
function calcMD5(str) {
  x = str2blks_MD5(str);
  a =  1732584193;
  b = -271733879;
  c = -1732584194;
  d =  271733878;

  for(i = 0; i < x.length; i += 16) {
    olda = a;
    oldb = b;
    oldc = c;
    oldd = d;

    a = ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = ff(c, d, a, b, x[i+10], 17, -42063);
    b = ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = ff(d, a, b, c, x[i+13], 12, -40341101);
    c = ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = ff(b, c, d, a, x[i+15], 22,  1236535329);    

    a = gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = gg(c, d, a, b, x[i+11], 14,  643717713);
    b = gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = gg(c, d, a, b, x[i+15], 14, -660478335);
    b = gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = gg(b, c, d, a, x[i+12], 20, -1926607734);
    
    a = hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = hh(b, c, d, a, x[i+14], 23, -35309556);
    a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = hh(d, a, b, c, x[i+12], 11, -421815835);
    c = hh(c, d, a, b, x[i+15], 16,  530742520);
    b = hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = ii(c, d, a, b, x[i+10], 15, -1051523);
    b = ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = ii(d, a, b, c, x[i+15], 10, -30611744);
    c = ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = add(a, olda);
    b = add(b, oldb);
    c = add(c, oldc);
    d = add(d, oldd);
  }
  return rhex(a) + rhex(b) + rhex(c) + rhex(d);
}
/* END of md5 */
function Safe_Pass(f) {
    f.password.is_js = calcMD5("" + f.challenge.value + f.password.value);
    f.challenge.value='';
    f.challenge.value=''; // it is stored in the session, so we do not need it anymore
    return true;
}
function Window_Loc(d,w){

	if(d.cookie == "" && w.self.location != w.top.location) {
		w.top.location = w.self.location;
	}
}
/*  TJT:  check if we need to do a MD5 for customer_profile updates  */
function bill_field_change(form) {
	form.bill_change.value = "do_MD5";
}

/* BEGIN AUTO TOP-UP FUNCTIONS */
function get_selected_top_up_type(frm) {
    if(frm.top_up_type[0].checked) {
	return "auto";
    }
/*
    else if(frm.top_up_type[1].checked) {
	return "monthly";
    } else if(frm.top_up_type[2].checked) {
	return "quarterly";
    }
*/
    else if(frm.top_up_type[1].checked) {
	return "email";
    } else {
	return "none";
    }
}

function get_selected_amount_index(frm) {
    var s = get_selected_top_up_type(frm);
    if(s == "auto" || s == "monthly" || s == "quarterly") {
	return eval("frm."+s+"_amt.selectedIndex");
    } else {
	return 0;
    }
}

function get_selected_amount_value(frm) {
    var s = get_selected_top_up_type(frm);
    if(s == "auto" || s == "monthly" || s == "quarterly") {
	return eval("frm."+s+"_amt.options[frm."+s+"_amt.selectedIndex].value");
    } else {
	return 0;
    }
}

function on_form_submit(frm) {
    testStr = "" + document.all;
    if(testStr != "undefined") {
	if(document.all.auto_recharge_table.style.display=="none") {
	    document.all.auto_recharge_table.style.display="";
	    return false;
	}
    }

    var top_up_type = get_selected_top_up_type(frm);
    var top_up_amount_index = get_selected_amount_index(frm); 
    var top_up_amount_value = get_selected_amount_value(frm);

    if(top_up_type == "auto" || top_up_type == "quarterly" || top_up_type == "monthly") {
	if(top_up_amount_index == 0) {
	    alert("Please select an auto top-up amount");
	    return false;
	}
    }
    if(top_up_type == "monthly") {
	if(frm.monthly_trigger.selectedIndex == 0) {
	    alert("Please select the trigger for the monthly top-up");
	    return false;
	}
    }
    if(top_up_amount_value <= 10 && top_up_amount_value != 0) {
        // if(!confirm("Note that for the amount of $10, you'll be charged\nwith an additional $1 for the service fee with each\nautomatically placed order. The service fee is dropped\nfor amounts larger than $10.\n\nContinue?")) {
        //     return false;
        // }
    }
    return true;
}

function show_auto_recharge_form(pin) {
    if(pin.value.length!=0) {
	document.getElementById("auto_recharge_table").style.display="";
    } else {
	document.getElementById("auto_recharge_table").style.display="none";
    }
}

function show_warning(frm) {
    alert("The balance of your account will\nbe checked every 6 hours.\n\nHeavy users may find they use all of their\nminutes before auto top-up occurs.");
}

function handle_top_up_type(frm, type) {
    var top_up_amount_index = get_selected_amount_index(frm);

    if(type == 'auto') {

	if(frm.auto_amt.selectedIndex == 0) {
	    frm.auto_amt.selectedIndex = top_up_amount_index;
	}

	// Clear all other options.
	frm.monthly_amt.selectedIndex = 0;
	frm.monthly_trigger.selectedIndex = 0;
	frm.quarterly_amt.selectedIndex = 0;
	
    }
    if(type == 'monthly') {

	if(frm.monthly_amt.selectedIndex == 0) {
	    frm.monthly_amt.selectedIndex = top_up_amount_index;
	}

	// Clear all other options.
	frm.auto_amt.selectedIndex = 0;
	frm.quarterly_amt.selectedIndex = 0;
	
    }
    if(type == 'quarterly') {

        if(frm.quarterly_amt.selectedIndex == 0) {
	    frm.quarterly_amt.selectedIndex = top_up_amount_index;
        }

        // Clear all other options.
        frm.monthly_amt.selectedIndex = 0;
        frm.monthly_trigger.selectedIndex = 0;
        frm.auto_amt.selectedIndex = 0;

    }

    if(type == 'email' || type == 'none') {

        // Clear all other options.
        frm.quarterly_amt.selectedIndex = 0;
        frm.monthly_amt.selectedIndex = 0;
        frm.monthly_trigger.selectedIndex = 0;
        frm.auto_amt.selectedIndex = 0;

    }
}

function top_up_selection(frm, nm, i) {
    if(nm == 'auto_amt') {
        frm.top_up_type[0].checked = true;
        frm.quarterly_amt.selectedIndex = 0;
	frm.monthly_amt.selectedIndex = 0;
        frm.monthly_trigger.selectedIndex = 0;
    }
    if(nm == 'monthly_trigger' || nm == 'monthly_amt') {
	frm.top_up_type[1].checked = true;
	frm.quarterly_amt.selectedIndex = 0;
        frm.auto_amt.selectedIndex = 0;
    }
    if(nm == 'quarterly_amt') {
        frm.top_up_type[2].checked = true;
        frm.auto_amt.selectedIndex = 0;
        frm.monthly_amt.selectedIndex = 0;
        frm.monthly_trigger.selectedIndex = 0;
    }
}

/* END AUTO TOP-UP FUNCTIONS */
