String.prototype.Contains = function(x) { return this.indexOf(x.toString()) != -1; }
String.prototype.BeginsWith = function(x) { return this.indexOf(x.toString()) === 0; }
String.prototype.EndsWith = function(x) { var xs = x.toString(); var s = this.length-xs.length; return s < 0 ? false : (this.lastIndexOf(xs, s) == s); }
String.prototype.ContainsI = function(x) { return this.toLowerCase().indexOf(x.toString().toLowerCase()) != -1; }
String.prototype.BeginsWithI = function(x) { return this.toLowerCase().indexOf(x.toString().toLowerCase()) === 0; }
String.prototype.EndsWithI = function(x) { var xs = x.toString(); var s = this.length-xs.length; return s < 0 ? false : (this.toLowerCase().lastIndexOf(xs.toLowerCase(), s) == s); }

var MaxPriceNoPhone = 400;
var issecure;
if( !issecure && location.protocol.toLowerCase()=='https:' )
	{
	location.replace(location.href.replace('https:','http:'));
	}

function Now()
	{
	return new Date();
	}
function dw(x)
  {
  document.write(x);
  }
function pclass(e)
  {
  while( e && e.parentNode && (!e.parentNode.className || e.parentNode.className == '') )
    e = e.parentNode;
  return e && e.parentNode ? e.parentNode.className : null;
  }
function navlite()
  {
  var lh = location.href;
  var ld = lh.substr(0, lh.lastIndexOf('/'));
  for( var i = 0; i < document.links.length; i++ )
    {
    var e = document.links[i];
    var eh = e.href;
    var ed = eh.substr(0, eh.lastIndexOf('/'));
    if( ed == ld )
      {
			var pc = pclass(e);
			if( pc == "smg" )
				continue;
      if( eh != lh && pc != "leftnav")
        continue;
			if( lh.Contains('/webdisc/') && lh != eh )
				continue;
			e.style.backgroundColor = 'white';
      e.style.color = 'blue';
      e.style.fontWeight = 'bold';
      e.style.borderTop = e.style.borderBottom = '1px solid orange';
      e.style.paddingTop = e.style.paddingBottom = '4px';
      }
    }
  }
function hookform(f)
  {
  if( !f )
    return;
  for( var i = 0; i < f.elements.length; i++ )
    {
    var e = f.elements[i];
    if( e.type && e.type.toLowerCase() == 'text' )
      return e.focus();
    }
  }
function doload()
  {
  navlite();
  hookform(document.forms[0]);
  doload2();
  }
function doload2()
  {}
function clean(x)
  {
  var v = "" + x;
  while( v.substr(0,1) == ' ' ) v = v.substr(1);
  while( v.substr(v.length-1,1) == ' ' ) v = v.substr(0, v.length-1);
  return v;
  }
function digits(x)
  {
  return (''+x).replace(/[^0-9]/g, '');
  }
function onlyint(f)
  {
  if( !/^[0-9. -]*$/.test(f.value) )
    f.value = f.value.replace(/[^0-9 -]/g,"");
  } 
function isalnum(v)
	{
	for( var i = 0; i < v.length; i++ )
		{
		var c = v.charAt(i);
		if( c >= 'a' && c <= 'z' )
			continue;
		if( c >= 'A' && c <= 'Z' )
			continue;
		if( c >= '0' && c <= '9' )
			continue;
		return false;
		}
	return true;
	}
function is_present(f, x, y)
  {
  var e = f.elements[x];
  var v = clean(e.value);
  if( v.length == 0 )
    {
    alert("You must enter "+y+" to submit this form.");
    e.focus();
    return false;
    }
  return true;
  }
function validate_amount(f, x, min, max)
	{
  var e = f.elements[x];
  var v = digits(e.value);
	if( v < min || v > max )
		{
		alert("The "+x+" field must be between "+min+" and "+max);
		e.focus();
		return false;
		}
	return true;
	}
function validate_website(f, x)
	{
  var e = f.elements[x];
  var v = e.value;
	if( !/\.[a-z][a-z]/i.test(v) )
		{
		alert("You must enter a valid website address to submit this form.");
		e.focus();
		return false;
		}
	return true;
	}
function validate_email(f, x)
  {
  var e = f.elements[x];
  var v = clean(e.value);
  var a = v.indexOf("@");
  var d = v.lastIndexOf(".");
  var en = v.length;
  if( !is_present(f, x, "an email address") )
    return false;
  if( a <= 0 || d <= a+1 || d == en-1 )
    {
    alert("\""+v + "\" does not appear to be a valid email address.  Please enter another one.");
    e.focus();
    return false;
    }
  return true;
  }
function validate_password(f, p, c)
	{
	var v = f.elements[p].value;
	if( !isalnum(v) || v.length < 6 || v.length > 16 )
		{
		alert("Your password must be between 6 and 16 characters long, and may contain only letters and digits.");
		return false;
		}
	if( c )
		{
		var cv = f.elements[c].value;
		if( v != cv )
			{
			alert("Your password and the confirmation field do not match.  Please re-enter them so they are the same.");
			return false;
			}
		}
	return true;
	}
function VerifyChecksum(cc)
  {
  var dbl = false;
  var checksum = 0;
  var i = cc.length;
  while( i > 0 )
    {
    i--;
    var c = new Number(cc.substr(i, 1));
    if( dbl )
      {
      c *= 2;
      if( c >= 10 )
        c -= 9;
      }
    checksum += c;
    dbl = !dbl;
    }
  return ((checksum % 10) == 0);
  }
// returns 0=good, 1=wrong number of digits, 2=bad card number
function isvalidcard(card)
  {
  var cc = "";
  for( var i = 0; i < card.length; i++ )
    if( cc.length >= 16 )
      return 1;
    else if( ("0123456789").indexOf(card.substr(i,1)) != -1 )
      cc = cc + card.substr(i,1);
  if( cc.length == 0 )
    return 1;
  if( !VerifyChecksum(cc) )
    return 2;
  var pr = new Number(cc.substr(0,2));
  if( pr == 34 || pr == 37 )
    return cc.length != 15;
  if( cc.substr(0,1) == "4" )
    return cc.length < 13;
  if( pr >= 51 && pr <= 55 )
    return cc.length != 16;
  if( cc.substr(0,4) == "6011" )
    return cc.length != 16;
  return 2;
  }
function validate_card(f, x)
  {
  if( !is_present(f, x, "a credit card number") )
    return false;
  var e = f.elements[x];
  var v = isvalidcard(e.value);
  if( v == 1 )
    {
    alert("The credit card number you entered appears to have too many or too few digits.  Please enter another number.");
    e.focus();
    return false;
    }
  if( v == 2 )
    {
    alert("The credit card number you entered is not one that we can charge.  Please enter another number.");
    e.focus();
    return false;
    }
  return true;
  }
function validate_expiration(f, m, y)
  {
  var d = new Date();
  var em = f.elements[m];
  var ey = f.elements[y];
  var vm = new Number(em.options[em.selectedIndex].innerHTML);
  var vy = new Number(ey.options[ey.selectedIndex].innerHTML);
  if( vy < d.getFullYear() || (vy == d.getFullYear() && vm-1 < d.getMonth()) )
    {
    alert("Your credit card may have expired.  Please check the expiration date and re-enter it if necessary.");
    em.focus();
    return false;
    }
  return true;
  }
function validate_cvv(f, x)
	{
  var e = f.elements[x];
  var v = digits(e.value);
	if( v.length<3 || v.length>4 )
		{
		alert("You must enter the security code for your card.");
		explaincvv();
		e.focus();
		return false;
		}
	return true;
	}
function validate_username(f, x)
  {
  var e = f.elements[x];
  var v = clean(e.value);
  if( v.length < 5 )
    {
    alert("You must enter a registrant name of five or more letters, to register this program.  You can make up a name if you wish, but it must have five or more letters.  Please remember to enter the name on your credit card under \"Cardholder\" if it is different than the Registrant's name.");
    e.focus();
    return false;
    }
  return true;
  }
function validate_selection(f, x, y)
  {
  var e = f.elements[x];
  if( e.value == "not_selected" )
    {
    alert("You must select "+y);
    e.focus();
    return false;
    }
  return true;
  }
function DigitsIn(x)
	{
	var ret = 1;
	while( x = Math.floor(x/10) )
		ret++;
	return ret;
	}
function MaxQuantity()
  {
  var x = baseprice;
  return x < 100 ? 999 : x < 1000 ? 99 : 9;
  }
function updateprice()
  {
  var t = baseprice * document.f.quantity.value;
  totalprice = t;
  if( getobj('total') )
    getobj('total').innerHTML = "$ "+Number(t).toFixed(2)+" US";
  }
function validate_licensee(f)
  {
  return is_present(f, "name", "the licensee's name") &&
  validate_email(f, "email") &&
  (totalprice <= MaxPriceNoPhone || is_present(f, "phone", "a contact phone number"));
  }
function validate_billing(f)
  {
  var isus = clean(f.country.value).length == 0;
  return validate_card(f, "card") &&
  validate_expiration(f, "expmonth", "expyear") &&
  is_present(f, "address", "a billing address") &&
  is_present(f, "city", "a city") &&
  (!isus || is_present(f, "zip", "your zipcode (if your billing address is not in the United States)")) &&
  (f.invoiceto == undefined || f.invoiceto.value == "" || validate_email(f, "invoiceto"));
  }
function validate(f)
  {
  // return validate_licensee(f) && validate_billing(f);
	return true;
  }
function selectedtext()
  {
  var r = "";
	if( window.getSelection )
		r = window.getSelection();
	else if( document.getSelection )
		r = document.getSelection();
  else if( document.selection )
		r = document.selection.createRange().text;
	r = clean(r);
	// for firefox, have to check form inputs manually
	if( !r && window.getSelection )
		for( var f=0; f < document.forms.length; f++ )
			for( var e=0; e < document.forms[f].elements.length; e++ )
				{
				var x = document.forms[f].elements[e];
				if( x.type.match(/text|textarea/i) && x.selectionStart < x.selectionEnd )
					return clean(x.value.substring(x.selectionStart, x.selectionEnd));
				}
	return r;
  }
function clearselection()
	{
	if( window.getSelection )
		window.getSelection().collapse(window.getSelection().anchorNode, false);
	else if( document.selection )
		document.selection.empty();
	}
function insertatcursor(t)
	{
	if( window.getSelection )
		{
		// inserts only in the main textarea
		var m = main.text;
		m.value = m.value.substr(0, m.selectionStart) + t + m.value.substring(m.selectionStart);
		}
	else if( document.selection )
		document.selection.createRange().text = t;
	}
function getobj(name)
  {
  if( document.getElementById )
    return document.getElementById(name);
  if( document.all )
	  return document.all[name];
  if( document.layers )
    return document.layers[name];
  }
function BeginsWith(x,y)
  {
  return x.substr(0, y.length) == y;
  }
function BeginsWithI(x,y)
  {
  return x.substr(0, y.length).toLower() == y.toLower();
  }
function verify(x)
  {
  return confirm(x ? x : "Are you sure?");
  }
function explaincvv()
	{
	alert(
		"MasterCard, VISA, Diners Club, and Discover Cards:\n\n"+
		"The security code is a three-digit number printed in the signature area of your card.\n\n"+
		"American Express Cards:\n\n"+
		"The security code is a four-digit number printed above the credit card number, on either the right or the left side of the front of your card.");
	}
function setcookie(name, value)
	{
	document.cookie = name+"="+escape(value);
	}
function getcookie(name)
	{
	var x = document.cookie.split(';');
  for( var i=0; i < x.length; i++ )
		{
    var r = x[i].split('=');
    if( r[0] == name ) 
      return unescape(r[1]);
		}
  return null;
	}
function deletecookie(name)
	{
	document.cookie = name+"=;expires=-1";
	}
