/* BEGIN moved from prod.phtml */

var preloaded_images = new Array();

function preload_image(src) {
  return;
  /*
  preloaded_images[preloaded_images.length] = new Image();
  preloaded_images[preloaded_images.length-1].src = src;
  */
}

/* END moved from prod.phtml */
function prev_brochure_image() {
  var o=get_obj('pageimage');
  var currpage=o.currpage;
  currpage--;
  if (0==currpage) { currpage = 24; }
  o.src='images/school/page' + currpage + '.jpg';
  o.currpage=currpage;
}
function next_brochure_image() {
  var o=get_obj('pageimage');
  var currpage=o.currpage;
  currpage++;
  if (0==currpage) { currpage = 24; }
  o.src='images/school/page' + currpage + '.jpg';
  o.currpage=currpage;
}
/*
function bookmark () {
  var url = document.location.toString();
  var title = document.title;
  if (document.all && parseInt(navigator.appVersion) >= 4) {
    window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    alert("You must press CTRL-D to bookmark this page");
  }
}
*/
function bookmark () {
  var url = document.location.toString();
  var title = document.title;
  if (document.all && parseInt(navigator.appVersion) >= 4) {
    window.external.AddFavorite(url,title);
  } else if (window.sidebar) {
    window.sidebar.addPanel(title, url,'');
  } else if (window.opera && window.print) {
    // i haven't tested this in opera yet. i don't understand why it would do anything.
    return true;
  } else if (navigator.appName == "Netscape") {
    alert("You must press CTRL-D to bookmark this page");
  }
}
function show_emailpagelink_form() {
  document.all('emailpagelink').style.display = "block";
  document.all('show_emailpagelink').style.display = "none";
}
function hide_emailpagelink_form() {
  document.all('emailpagelink').style.display = "none";
  document.all('show_emailpagelink').style.display = "inline";
}
function write_bookmark_link() {
  if (document.all || (navigator.appName == "Netscape")) {
    document.write('<span onclick="bookmark();" class=jlink>');
    if (navigator.appName == "Netscape") { document.write('press ctrl-d to '); }
    document.write('bookmark this page');
    document.write('</span><br>');
  }
}
function write_emailpagelink_link2() {
  var pageurl = document.location.toString();
  var pagetitle = document.title;
  pagetitle = pagetitle.replace(/ - .*/, "");
  document.write('<span id=show_emailpagelink onclick="show_emailpagelink_form()" class=jlink>email a link to this page</span>');
  document.write('<div id=emailpagelink style="display:none;" align=left> ');
  document.write('<form name=f_emailpagelink action="emailpagelink.php" method=post style="background-color:white; padding:10px;"> ');
  document.write('Just fill in the following information and a link to this page ('+pageurl+') will be on its way.<br> ');
  document.write('<div style="margin-top:10px;">');
  document.write('Your Name: <input type=text name=fromname size=24 onchange=""><br> ');
  document.write('Send email to: <input type=text name=toemail size=24> ');
  document.write('</div> ');
  document.write('<span>Subject:</span><br> ');
  document.write('<textarea name=subject rows=2 style="width:100%"">'+pagetitle+'</textarea><br>');
  document.write('<input type=hidden name=pagetitle value="'+pagetitle+'">');
  document.write('<input type=hidden name=pageurl value="'+pageurl+'">');
  document.write('A message from you (optional):<br>');
  document.write('<textarea name=user_msg rows=5 style="width:100%;"></textarea><br>');
  document.write('<input type=submit value="Send Email" style="float:right;"> ');
  document.write('<small><b>Please Note:</b> The recipient of this email will see your IP Address and the time this request is being made. <br></small> ');
  document.write('</form>');
  document.write('<small><span onclick="hide_emailpagelink_form()" class=jlink><center>hide this form</center></span></small> ');
  document.write('</div>');
}

//
// Author: Matthew V. Maloney
// Copyright 2002 Sensible Internet Retail, Inc.
//

var DEBUG = 0;
var cfg_maxshippingweight = 150;
var cfg_defaultshippingweight = 2;

function set_innerHtmlById(elemid, htmlstr) {
	set_innerHTML(get_obj(elemid), htmlstr);
}
function set_innerHTML(elem, htmlstr) {
	var e = (typeof(elem) === "string") ? get_obj(elem) : elem;
	if ( (null != e) && (typeof(e) === "object") ) {
		if (is.nav6up || is.ie4up) {
			e.innerHTML = htmlstr;
		} else if (is.nav4) {
			e.document.open();
			e.document.write(htmlstr);
			e.document.close();
		} else {
		}
	} else {
	}
}
function get_objs(id1) {
	var id2 = new String(id1);
	if ((is.ie4up) || (1)) {
		var o = document.getElementsByName(id2);
	} else {
		return null;
	}
	return o;
}
function get_obj(id1) {
	var id2 = new String(id1);
	if (is.ie5up || is.nav6up || (1)) {
		var o = document.getElementById(id2);
	} else if (is.ie4up) {
		var o = document.all(id2) 	} else {
		return null;
	}
	return o;
}
function get_eventKeyCode(evnt) {
	return (evnt.keyCode > 0 ? evnt.keyCode : evnt.which);
}
function get_eventTarg(evnt) {
	var retval = (is.ie4up ? evnt.srcElement : evnt.target);
	return retval
}
function show_all_rows(tbl) {
	var tbod = tbl.tBodies(0);
	var r = tbod.rows;
  for (var i=0; i<r.length; i++) {
    r[i].style.display = '';
  }
}
function filter_rows(tbl, str) {
	var tbod = tbl.tBodies(0);
	var r = tbod.rows;
  for (var i=0; i<r.length; i++) {
    if (-1 == r[i].innerText.indexOf(str)) {
       r[i].style.display = 'none';
    }
  }
}
function set_col_visibility(elemname, visible) {
	if (document.all) var visible_column_style = 'block';
	else var visible_column_style = 'table-cell';
	var hide_column_style = 'none';
	var tds = document.getElementsByName(elemname);
	var displaymode = visible ? visible_column_style : hide_column_style;
	for (var i=0; i<tds.length; i++) {
		tds[i].style.display = displaymode;
	}
}
function tablesort(col, tableToSort, td_class, prefix) {
	var sorter = new Array();
	var tbod = tableToSort.tBodies[0];
	for (var i=0; i < tbod.rows.length; i++) {
		var celldata = (tbod.rows[i].cells[col].value) ? tbod.rows[i].cells[col].value : tbod.rows[i].cells[col].innerText;
		sorter[i] = celldata;
	}
	var compare_func;
	if (tableToSort.curr_sortcol == col) {
		if ("DESC"==tableToSort.curr_sortdir) {
			tableToSort.curr_sortdir = "ASC";
			compare_func = asc_order;
		} else if ("ASC"==tableToSort.curr_sortdir) {
			tableToSort.curr_sortdir = "DESC";
			compare_func = desc_order;
		}
	} else {
		tableToSort.curr_sortdir = "ASC";
		compare_func = asc_order;
	}
	tableToSort.curr_sortcol = col;
	for (var i=0; i < sorter.length; i++) {
		var chosen_one=i;
		for (var j=i; j < sorter.length; j++) {
			if (0 < compare_func(sorter[chosen_one], sorter[j])) {
				chosen_one = j;
			}
		}
		var chosen_val = sorter[chosen_one];
		for (var j = chosen_one; j > i; j--) {
			sorter[j] = sorter[j-1];
		}
		sorter[i] = chosen_val;
		tbod.moveRow(chosen_one, i);
	}
	if (!prefix) prefix="";
	for (var i=0; i < get_objs(prefix+"_sortednote_col").length; i++) {
		if (i == tableToSort.curr_sortcol) {
			if ("DESC" == tableToSort.curr_sortdir) {
				set_innerHTML(get_objs(prefix+"_sortednote_col")[i], "(sorted &darr;)");
			} else {
				set_innerHTML(get_objs(prefix+"_sortednote_col")[i], "(sorted &uarr;)");
			}
		} else if (get_objs(prefix+"_sortednote_col")[i].sorted) {
			set_innerHTML(get_objs(prefix+"_sortednote_col")[i], "(sort &darr;&uarr;)");
		}
	}
}
function desc_order(a, b) {
	if (isNaN(b-a)) {
		if (a.toString() < b.toString()) { return 1; }
		else if (a.toString() == b.toString()) { return 0; }
		else if (a.toString() > b.toString()) { return -1; }
	}
	return (b - a);
}
function asc_order(a, b) {
	if (isNaN(b-a)) {
		if (a.toString() > b.toString()) { return 1; }
		else if (a.toString() == b.toString()) { return 0; }
		else if (a.toString() < b.toString()) { return -1; }
	}
	return (a - b);
}
function recalc_totals() {
	this.itemcount = 0;
	this.subtotal = 0;
	for (var i=0; i < this.$lines.length; i++) {
		var icols = parseLine(this.$lines[i], this.$fieldDelim);
		if (icols) {
			this.itemcount += icols[4]*1;
			this.subtotal += icols[6]*1;
		}
	}
}
function Cart(cartname) {
	this.$name = cartname;
	this.$fieldDelim = "²";
	this.$lineDelim  = "¹";
	this.$cookie = new Cookie(document, "wgcart");
	this.$cookie.load();
	if (this.$cookie.cart) {
		this.$lines = this.$cookie.cart.split(this.$lineDelim);
	} else {
		this.$lines = new Array();
	}
	this.itemcount = 0;
	this.subtotal = 0;
	this.recalc_totals = recalc_totals;
	document.cookie = 'fieldDelim=' + this.$fieldDelim;
	document.cookie = 'lineDelim=' + this.$lineDelim;
	document.cookie = 'orderDelim=' + this.$lineDelim;
}
function is_patience_discount(sku) {
	var re = new RegExp(".+\-Patience$", "");
	if (sku.match(re)) {
		return true;
	} else {
		return false;
	}
}
Cart.prototype.addItem = function(sku, name, opttype, optname, price, qty, weight, href, discountprice) {
	if (this.itemIsInCart(sku, optname)) {
			this.changeQty(sku, -1, qty, optname);
	} else {
		if (weight <= 0) { weight = cfg_defaultshippingweight; }
		var requires_freight = (weight > cfg_maxshippingweight) ? true : false ;
		var itemdata = new Array(sku, name, opttype, optname, qty,
 														 formatdecimal(price),
 														 formatdecimal(price * qty),
														 formatdecimal(weight),
														 formatdecimal(formatdecimal(weight) * qty),
														 requires_freight,
														 href);
		var itemstr  = itemdata.join(this.$fieldDelim);
		this.$lines[this.$lines.length] = itemstr;
		this.$cookie.cart = this.toString();
		this.$cookie.store();
		return true;
	}
}
Cart.prototype.itemIsInCart = function (sku, opt) {
	for (var i=0; i < this.$lines.length; i++) {
		if ((0 == this.$lines[i].indexOf(sku+this.$fieldDelim)) && ( !opt || (-1 < this.$lines[i].indexOf(opt)) )) {
			return true;
		}
	}
	return false;
}
Cart.prototype.changeQty = function(num, oldqty, newqty, opt) {
	if ( isNaN(newqty) || (null == newqty) ) {
		newqty = window.prompt("Please enter the new quantity: ", oldqty);
		if ( isNaN(newqty) || (null == newqty) ) {
			return false;
		}
		if ( (!isInt(newqty)) || (0 > newqty) ) {
			alert("The new quantity must be a number greater than or equal to zero.\n\nTo remove a product from your cart, enter 0 (zero) for the new quantity.");
			return false;
		}
	}
	if (0 == newqty) {
		this.removeItem(num);
	} else {
		if (! isNumeric(num)) {
			num += this.$fieldDelim;
			var str="";
			for (var i=0; i < this.$lines.length; i++) {
				str = this.$lines[i];
				if ( (num == this.$lines[i].substring(0, num.length))  &&
					 (-1 < this.$lines[i].indexOf(opt)) ) {
					num = i;
				}
			}
		}
		var icols = parseLine(this.$lines[num], this.$fieldDelim);
		if (icols) {
			icols[4] *= 1; icols[5] *= 1; icols[7] *= 1;
			icols[4] = (oldqty < 0) ? icols[4] + newqty : newqty;
			icols[6] = formatdecimal(icols[4] * icols[5]);
			icols[8] = formatdecimal(icols[4] * icols[7]);
			this.$lines[num] = icols.join(this.$fieldDelim);
		}
	}
	this.$cookie.cart = this.toString();
	this.$cookie.store();
	return true;
}
function parseLine(datain, delimin){
	if (datain) {
		return datain.split(delimin);
	} else {
	}
}
Cart.prototype.toString = function() {
  return this.$lines.join(this.$lineDelim);
}
Cart.prototype.removeItem = function(linenum) {
	if (1 == this.$lines.length) {
		this.$lines = new Array();
	} else {
		this.$lines[linenum] = null;
		var titems = new Array();
		var j=0;
		for (var i=0; i < this.$lines.length; i++) {
			if (i != linenum) {
				titems[j++] = this.$lines[i];
			}
		}
		this.$lines = null;
		this.$lines = titems;
		titems = null;
	}
	this.$cookie.cart = this.toString();
	this.$cookie.store();
}
function emptyCart(quiet) {
	if (quiet) {
		this.delCookie();
	} else
		if (window.confirm("Are you sure you want to empty your shopping cart?\n\nThis action can not be undone.")) {
			this.delCookie();
	}
}
function Cookie(doc, name, hours, path, domain, secure) {
	this.$document = doc;
	this.$name = name;
	if (hours) { this.$expiration = new Date((new Date()).getTime() + hours * 3600000); }
		else { this.$expiration = null; }
	if (path) { this.$path = path; } else { this.$path = null; }
	if (domain) { this.$domain = domain; } else { this.$domain = null; }
	if (secure) { this.$secure = true; } else { this.$secure = false; }
}
Cookie.prototype.store = function() {
	var cookieval = "";
	for (var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) {
			continue;
		}
		if (cookieval != "") { cookieval += '&'; }
		cookieval += prop + ":" + escape(this[prop]);
		var cookie = this.$name + '=' + cookieval;
		if (this.$expiration) { cookie += '; expires=' + this.$expiration.toGMTString(); }
		if (this.$path) { cookie += '; path=' + this.$path; }
		if (this.$domain) { cookie += '; domain=' + this.$domain; }
		if (this.$secure) { cookie += '; secure'; }
		this.$document.cookie = cookie;
	}
}
Cookie.prototype.load = function() {
	var allcookies = urldecode(this.$document.cookie);
	if (allcookies == "") { return false; }
	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) { return false; }
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) { end = allcookies.length; }
	var cookieval = allcookies.substring(start, end);
	var a = cookieval.split('&');
	for (var i=0; i < a.length; i++) {
		a[i] = a[i].split(':');
	}
	for (var i=0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}
	return true;
}
Cookie.prototype.remove = function() {
	var cookie;
	cookie = this.$name + '=';
	if (this.$path) { cookie += '; path=' + this.$path; }
	if (this.$domain) { cookie += '; domain=' + this.$domain; }
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	this.$document.cookie = cookie;
}
function get_orderpage_heading() {
	var loc = document.location.url;
	var html = "";
	if (0 < loc.indexOf("receipt")) {
		html = "<font color=\"darkblue\" style=\"font-size:18px;font-weight:bold\">Thank You!</font><br>" +
			   "<font color=\"darkblue\" style=\"font-size:11px\">You will soon receive an email confirming your order.</font>";
	} else if (loc.indexOf("verify")) {
		html = "<font color=\"darkblue\" style=\"font-size:16px;font-weight:bold\">Your order is almost complete...</font><br>" +
			   "<br><font color=\"darkblue\" style=\"font-size:14px\">Continue below:</font>";
	} else if (loc.indexOf("form")) {
		html = "<font color=\"darkblue\" style=\"font-size:11px\">We are an authorized dealer of licensed Star Wars&#153; costumes.</font><br>" +
		       "<font color=\"black\" style=\"font-size:11px\">Everyday Low Prices!</font>";
	} else {
		html = "";
	}
	return html;
}
	var currpic = 0;
	function prevpic() {
		divs[currpic].style.display = "none";
		if (!divs[--currpic]) {
			currpic = numpics-1;
		}
		divs[currpic].style.display = "";
		set_innerHTML("imagenum", currpic+1);
	}
	function nextpic() {
		divs[currpic].style.display = "none";
		if (!divs[++currpic]) {
			currpic = 0;
		}
		divs[currpic].style.display = "";
		set_innerHTML("imagenum", currpic+1);
	}
	function enlargepic(dir) {
		var imgValue = divs[currpic].attributes['largerimage'] ? divs[currpic].attributes['largerimage'].value : divs[currpic].attributes['title'].value;
		window.open("image.php?imagefile=http://img.costumecraze.com/" + dir + imgValue);
	}
	function picnum_caption() {
		return "<small><nobr>(image # <span id=imagenum>" + sprintf("%0d", (currpic*1)+1) + "</span> of " + numpics + ")</nobr></small>";
	}
function Is ()
{
    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
		this.nav6 = this.nav5;
		this.nav6up = this.nav5up;
    this.ie    = (agt.indexOf("msie") != -1);
    this.ie3   = (this.ie && (this.major < 4));
    this.ie4   = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up = (this.ie  && (this.major >= 4));
    this.ie5x  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")!=-1) );
    this.ie50  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie55  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5")!=-1) );
    this.ie5up = (this.ie && !this.ie3 && !this.ie4);
	this.ie6x  = (this.ie && (this.major == 4) && (agt.indexOf("msie 6")!=-1) );
    this.ie60  = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.0")!=-1) );
    this.ie6up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5x);
}
var is;
if (!((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && (parseInt(navigator.appVersion)==3))) {
	is = new Is();
}
      var stock_details_window = "";
      function show_outofstock_details(sku, img) {
        var s = get_obj(sku + "_stock_details");
        var url = "outofstock-offer.php?sku="+sku+"&img="+img;
        var window_opts = "height=580,width=490,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no";
        stock_details_window = window.open(url, "stock_details", window_opts);
        stock_details_window.focus();
      }
      function show_instock_details(sku, suffix) {
        var s = get_obj(sku + "_stock_details" + suffix);
        s.status = !(s.status);
        s.style.display = ((true == s.status) ? 'none' : 'block');
      }
      function show_stock_details(sku, suffix) {
        var s = get_obj(sku + "_stock_details" + suffix);
        s.status = !(s.status);
        s.style.display = ((true == s.status) ? 'none' : 'block');
      }
function submitenter(myfield,e) {
   var keycode;
	 if (window.event) keycode = window.event.keyCode;
   else if (e) keycode = e.which;
   else return true;
	 if (keycode == 13) {
      myfield.form.submit();
      return false;
   } else {
      return true;
	 }
}
  function txtQuantity_KeyPress(evnt) {
      var asc = get_eventKeyCode(evnt);
      var chr = String.fromCharCode(asc);
      if (! isNumeric(chr) ) {
        if (33 <= asc && asc <=127) {
          if (is.nav4up) {
            evnt.preventDefault();
          } else if (is.ie5up) {
            evnt.returnValue = false;
          }
        }
      }
  }
  function txtQuantity_KeyUp(textbox) {
    var aon = get_obj("aon" + textbox.name);
    var aoff = get_obj("aoff" + textbox.name);
    var val = parseInt(textbox.value);
    if ((null != aon) && (null != aoff)) {
      if (! isNaN(val) && (0 < val) ) {
            set_innerHTML(aon, get_aon_html(aon.sku, aon.itemname, aon.opt, aon.price, aon.shipping, aon.inputid));
            set_innerHTML(aoff, "");
      } else {
        aon.innerHTML = "";
        aoff.innerHTML = '<img src="cart-disabled.jpg">';
      }
    }
  }
  function onwindowload() {
  }
  function removePunct(strmsg) {
    var i = 0;
    var ch = "";
    var returnmsg = "";
    for (i=0; i < strmsg.length; i++) {
      ch = strmsg.charAt(i);
      returnmsg += (isAlphaNumeric(ch)) ? ch : "";
    }
    return returnmsg;
  }
  function isAlphaNumeric(ch) {
    return (isNumeric(ch) || isAlpha(ch));
  }
  function isAlpha(ch) {
    chin = ch.charAt(0);
    return ( (chin >= 'A' && chin <= 'Z') || (chin >= 'a' && chin <= 'z') )
  }
  function isInt(str) {
    return !( isNaN(str) || (parseInt(str) != parseFloat(str)) );
  }
  function isNumeric(str) {
		//alert(str);
		return ((parseFloat(str) == str) || (parseInt(str) == str))
  }
  function isaN(num) {
    return ( ! isNaN(num) );
  }
  function isValidEmail(str) {
  }
  function isValidPhone(str) {
  }
  function isValid(str) {
  }
  function isOrderFormComplete() {
    return true;
  }
  function firstFocus()
  {
     if (document.forms.length > 0)
     {
      var TForm = document.forms[0];
      for (i=0;i<TForm.length;i++)
      {
       if ((TForm.elements[i].type=="text")||
         (TForm.elements[i].type=="textarea")||
         (TForm.elements[i].type.toString().charAt(0)=="s"))
       {
        document.forms[0].elements[i].focus();
        break;
       }
      }
     }
  }
function formatdecimal(amtin){
  amtin += "";
  amtin = Math.round(parseFloat(amtin) * 100);
  amtin /= 100;
  amtin += "";
  if(amtin.indexOf(".") < 0){
     amtin += ".00";
     return amtin;
  }
  if (amtin.indexOf(".") == amtin.length - 2) {
    amtin += "0";
  }
  return amtin;
}
function get_random_elemid() {
  var id = "";
  for (var i=0; i<12; i++) {
    id += get_random_num(0,9);
  }
  return id;
}
function get_random_num(start,end) {
    var range = end - start + 1;
    var result = start + Math.floor(Math.random()*range);
    return result;
}
function dbgwrite(str) {
  if (1 === DEBUG) {
      set_innerHTML("debugdiv", str + "<br>");
  }
}
function sprintf()
{
  var iCount, iPadLength, aMatch, iMatchIndex = 1;
  var bAlignLeft, sPad, iWidth, iPrecision, sType;
  var aArgs = sprintf.arguments;
  if (aArgs.length < 2) return '';
  var sFormat = aArgs[0];
  var re = /%(-)?(0| |'.)?(\d+)?(\.\d*)?([bcdfosxX]{1})/;
  while (re.test(sFormat))
  {
    aMatch = re.exec(sFormat);
    bAlignLeft = (aMatch[1] == '-');
    sPad = (aMatch[2] == '' ? ' ' : aMatch[2]);
    if (sPad.substring(0, 1) == "'") sPad = sPad.substring(1);
    iWidth = (aMatch[3] > 0 ? parseInt(aMatch[3]) : 0);
    iPrecision = (aMatch[4].length > 1 ? parseInt(aMatch[4].substring(1)) : 6);
    sType = aMatch[5];
    mArgument = (aArgs[iMatchIndex] != null ? aArgs[iMatchIndex] : '');
    ++iMatchIndex;
    if (mArgument.toString().length)
    {
      if ('fbcdoxX'.indexOf(sType) != -1 && isNaN(mArgument)) mArgument = 0;
      switch (sType)
      {
        case 'f':
          var iPower = Math.pow(10, iPrecision);
          mArgument = (Math.round(parseFloat(mArgument) * iPower) / iPower).toString();
          var aFloatParts = mArgument.split('.');
          if (iPrecision > 0)
          {
            if (aFloatParts.length == 1) aFloatParts[1] = '';
            for (iCount = aFloatParts[1].length; iCount < iPrecision; iCount++)
              aFloatParts[1] += '0';
            mArgument = aFloatParts[0] + '.' + aFloatParts[1];
          }
          else mArgument = aFloatParts[0];
          iPadLength = aFloatParts[0].length;
          break;
        case 'b':
          mArgument = parseInt(mArgument).toString(2);
          iPadLength = mArgument.length;
          break;
        case 'c':
          mArgument = String.fromCharCode(parseInt(mArgument));
          break;
        case 'd':
          mArgument = mArgument.toString();
          iPadLength = mArgument.length;
          break;
        case 'o':
          mArgument = parseInt(mArgument).toString(8);
          iPadLength = mArgument.length;
          break;
        case 'x':
          mArgument = parseInt(mArgument).toString(16);
          iPadLength = mArgument.length;
          break;
        case 'X':
          mArgument = parseInt(mArgument).toString(16).toUpperCase();
          iPadLength = mArgument.length;
          break;
        default:
          mArgument = mArgument.toString();
          iPadLength = mArgument.length;
      }
      if ('fbdoxX'.indexOf(sType) != -1)
      {
        if (bAlignLeft)
          for (iCount = iPadLength; iCount < iWidth; iCount++)
            mArgument += sPad;
        else
          for (iCount = iPadLength; iCount < iWidth; iCount++)
            mArgument = sPad + mArgument;
      }
    }
    sFormat = sFormat.replace(re, mArgument);
  }
  return sFormat;
}
function parse_querystring(str) {
	var q = new String(str);
	if (q) q = q.replace(/.*\?/, "");
	if (q) q = q.split("&");
	if (!q) return new Array();
	if (q === str) return new Array();
	var u, params = new Array();
	for (var i=0; i<q.length; i++) {
		if (q[i]) u = q[i].split("=");
		if (u && u.length) params[u[0]] = u[1];
	}
	return params;
}
function urldecode(str) {
	str = str.replace(/[+]/g," ")
	return unescape(str)
}
function body_onload() {
	if (!document.all) { return; }
	var params;

	if (document.all("bodydiv")) { var b = document.all("bodydiv"); }
	else { var b = document.body; }

	params = parse_querystring(document.location.href);
	if (params && params['hl']) { highlight_html(b, params['hl'], "highlighted"); }

	params = parse_querystring(document.referrer);
	if (params && params['q']) {
		params['q'] = urldecode(params['q']);
		var q = params['q'].split(" ");
		for (var i=0; i<q.length; i++) {
			highlight_html(b, q[i], "highlighted");
		}
	}
}
function replaceStr(str, findthis, replacement) {
  var re = new RegExp (findthis,'ig');
  return str.replace(re, replacement);
}
function highlight_html(elem, highlight_word, css_class) {
  var re;
  var varMatches;
  var outHtml;
  var replaceText;
  replaceText = '<span class="' + css_class + '">' + highlight_word + '</span>';
  re=new RegExp("(\<[^>][^<]*\>|^)([^<]*)","g");
  outHtml=new String('');
	inHtml = elem.innerHTML;
  while ((varMatches = re.exec(inHtml)) != null)
  {
    outHtml += varMatches[1];
    outHtml += replaceStr(varMatches[2], highlight_word, replaceText);
  }
  elem.innerHTML = outHtml;
}
function getGetParams() {
	var query=this.location.search.substring(1);
	if (query.length > 0){
			var params=query.split("&");
			for (var i=0 ; i<params.length ; i++){
					var pos = params[i].indexOf("=");
					var name = params[i].substring(0, pos);
					var value = params[i].substring(pos + 1);
					document.writeln("<dl>")
					document.write("<dt>" + i + ":" + name + "<\/dt>");
					document.write("<dd>" + value + "<\/dd>");
					document.writeln("<\/dl>");
			}
	}
}

var referurl = new Cookie(document, "referurl");
if (!referurl.load()) {
	if (document.referrer) {
		document.cookie = "referurl=" + escape(document.referrer);
	} else {
		document.cookie = "referurl=unknown";
	}
}

var entryurl = new Cookie(document, "entryurl");
if (!entryurl.load()) {
	document.cookie = "entryurl=" + escape(location);
}

