function popWindow(url,Wwidth,Wheight) {
small_window = window.open(url,"small_window"+Wwidth+"x"+Wheight,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + Wwidth + ',height=' + Wheight + ',screenX=0,screenY=0');
small_window.focus();
}


function changeImages(normal, rollover) {
	if (document.images) {document.images[normal].src = eval(rollover + ".src");}
}

function jb_changeImages() { //new, improved rollover function
	if (document.images) {
		for (var i=0; i<jb_changeImages.arguments.length; i+=2) {
			document[jb_changeImages.arguments[i]].src = jb_changeImages.arguments[i+1];
		}
	}
}

function menuGo(base, whichMenu) {
if (document.menuForm[whichMenu].value) {
	base = 'http://' + base + 'admin/';
	if (whichMenu != '') {
		top.location.href = base + document.menuForm[whichMenu].value;
	}
}
}

function menuFilter(base, whichMenu) {
if (document.menuForm[whichMenu].value) {
	base = 'http://' + base + 'admin/';
	if (whichMenu != '') {
		location.href = base + document.menuForm[whichMenu].value;
	}
}
}

function emailCheck (emailStr) {
var checkTLD=0; 
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; 
var emailPat=/^(.+)@(.+)$/; 
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; 
var validChars="\[^\\s" + specialChars + "\]"; 
var quotedUser="(\"[^\"]*\")"; 
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; 
var atom=validChars + '+'; 
var word="(" + atom + "|" + quotedUser + ")"; 
var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
var matchArray=emailStr.match(emailPat); 
if (matchArray==null) { 
alert("That email address looks wrong."); 
return false; 
} 
var user=matchArray[1]; 
var domain=matchArray[2]; 
for (i=0; i<user.length; i++) { 
if (user.charCodeAt(i)>127) { 
alert("That email address looks wrong."); 
return false; 
} 
} 
for (i=0; i<domain.length; i++) { 
if (domain.charCodeAt(i)>127) { 
alert("That email address looks wrong."); 
return false; 
} 
} 
if (user.match(userPat)==null) { 
alert("That email address looks wrong."); 
return false; 
} 
var IPArray=domain.match(ipDomainPat); 
if (IPArray!=null) { 
for (var i=1;i<=4;i++) { 
if (IPArray>255) { 
alert("That email address looks wrong."); 
return false; 
} 
} 
return true; 
} 
var atomPat=new RegExp("^" + atom + "$"); 
var domArr=domain.split("."); 
var len=domArr.length; 
for (i=0;i<len;i++) { 
if (domArr[i].search(atomPat)==-1) { 
alert("That email address looks wrong."); 
return false; 
} 
} 
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) { 
alert("That email address looks wrong."); 
return false; 
} 
if (len<2) { 
alert("That email address looks wrong."); 
return false; 
}
return true;
}

//SPECIFIC FORM CHECKS
function checkChangePass(which) {
	if (!which.oldpass.value) {
		alert("Please enter your old password.");
		return false;
	}
	if (!which.newpass.value) {
		alert("Please enter a new password.");
		return false;
	}
	if (which.newpass.value.length < 6 || which.newpass.value.length > 12) {
		alert("The new password must be between 6 and 12 characters long.");
		return false;
	}
	if (which.newpass.value != which.newpass_confirm.value) {
		alert("Those passwords don't match.");
		return false;
	}
	return true;
}



function checkChangeAcctInfo(which) {
	if (!which.fname.value) {
		alert("Please enter your first name.");
		return false;
	}
	if (!which.lname.value) {
		alert("Please enter your last name.");
		return false;
	}
	if (!which.email.value) {
		alert("Please enter your email address.");
		return false;
	}
	if(!emailCheck(which.email.value)) {
		return false;
	}
	return true;
}



function checkContact(which) {
	if (!which.email.value) {
		alert("Please enter your email address.");
		which.email.focus();
		return false;
	}
	if (!emailCheck(which.email.value)) {
		which.email.focus();
		return false;
	}
	if (!which.subject.value) {
		alert("Please enter a subject.");
		which.subject.focus();
		return false;
	}
	if (!which.message.value) {
		alert("Please write a message.");
		which.message.focus();
		return false;
	}
	return true;
}



function checkNewAcct(which) {
if (!which.email.value) {
	alert("Please enter your email address.");
	return false;
}
if (which.email.value != which.echeck.value) {
	alert("Those email addresses don't match.");
	return false;
}
if(!emailCheck(which.email.value)) {
	return false;
}
if (!which.first.value) {
	alert("Please enter your first name.");
	return false;
}
if (!which.last.value) {
	alert("Please enter your last name.");
	return false;
}
if (!which.pass.value) {
	alert("Please enter your password.");
	return false;
}
if (which.pass.value.length < 6 || which.pass.value.length > 12) {
	alert("The password must be between 6 and 12 characters long.");
	return false;
}
if (which.pass.value != which.passcheck.value) {
	alert("Those passwords don't match.");
	return false;
}
return true;
}


function checkAcct(which) {
if (!which.email.value) {
	alert("Please enter your email address.");
	return false;
}
if(!emailCheck(which.email.value)) {
	return false;
}
if (!which.pass.value) {
	alert("Please enter your password.");
	return false;
}
return true;
}



function checkAddress(which) {
if (!which.first.value) {
	alert("Please enter your first name.");
	return false;
}
if (!which.last.value) {
	alert("Please enter your last name.");
	return false;
}
if (!which.phone.value) {
	alert("Please enter your telephone number.");
	return false;
}
if (!which.addr1.value) {
	alert("Please enter your street address.");
	return false;
}
if (!which.country.value) {
	alert("Please choose a country.");
	return false;
}
if (!which.city.value) {
	alert("Please enter your city.");
	return false;
}
if (!which.postal.value) {
	alert("Please enter your postal code.");
	return false;
}

if (which.country.value=='United States') {
	if (!which.state.value) {
		alert("Please enter your state.");
		return false;
	}
	var zipPat = /^\d{5}$|^\d{5}\-\d{4}$/;
	if (which.postal.value.match(zipPat) == null) { 
		alert("The postal code looks incorrect. It can be of the form xxxxx or xxxxx-xxxx."); 
		return false; 
	}
}
return true;
}



function checkBillShip(which,prodArray) {
for (i=0;i<prodArray.length;i++) {
	if (!which["addr_" + prodArray[i]].value) {
		alert("Please choose a shipping address.");
		return false;
	}
	if (!which["shipmethod_" + prodArray[i]].value) {
		alert("Please choose a shipping method.");
		return false;
	}
}
if (!which.bill_address.value) {
	alert("Please choose a billing address.");
	return false;
}
return true;
}

function checkCCs(which) {
	if (!which.ccselect.length && which.ccselect.checked) {//only 1
		return true;
	}
	//more than one
	for (i=0;i<which.ccselect.length;i++) {
		if (which.ccselect[i].checked) {
			return true;
		}
	}
	if (!CheckCardNumber(which)) {
		return false;
	}
	if (!which.cid.value) {
		alert("Please enter the validation number.");
		return false;
	}
	if (!which.first.value) {
		alert("Please enter your first name.");
		return false;
	}
	if (!which.last.value) {
		alert("Please enter your last name.");
		return false;
	}
	return true;
}


//CREDIT CARDS
var Cards = new makeArray(3);
Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new CardType("AmExCard", "34,37", "15");
var AmExCard = Cards[2];
Cards[3] = new CardType("DiscoverCard", "6011", "16");
var DiscoverCard = Cards[3];

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
function CheckCardNumber(form) {
var tmpyear;
var tmpmonth;
if (!form.cctype.value) {
alert("Please select a credit card.");
return false;
}
if (form.ccnum.value.length == 0) {
alert("Please enter a credit card number.");
form.ccnum.focus();
return false;
}
if (!form.ccexp_m.value) {
alert("Please select an expiration month.");
return false;
}
if (!form.ccexp_y.value) {
alert("Please select an expiration year.");
return false;
}

tmpyear = form.ccexp_y.options[form.ccexp_y.selectedIndex].value;
tmpmonth = parseInt(form.ccexp_m.options[form.ccexp_m.selectedIndex].value);
// The following line doesn't work in IE3, you need to change it
// to something like "(new CardType())...".
// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
alert("This card has already expired.");
return false;
}
card = form.cctype.options[form.cctype.selectedIndex].value;
switch(card) {
	case 'VISA':
	card = "VisaCard";
	break;
	case 'MC':
	card = "MasterCard";
	break;
	case 'AMEX':
	card = "AmExCard";
	break;
	case 'DISC':
	card = "DiscoverCard";
	break;
}
var retval = eval(card + ".checkCardNumber(\"" + form.ccnum.value +
"\", " + tmpyear + ", " + tmpmonth + ");");
cardname = "";
if (retval)



// comment this out if used on an order form
return true;

else {
// The cardnumber has the valid luhn checksum, but we want to know which
// cardtype it belongs to.
for (var n = 0; n < Cards.size; n++) {
if (Cards[n].checkCardNumber(form.ccnum.value, tmpyear, tmpmonth)) {
cardname = Cards[n].getCardType();
break;
   }
}
if (cardname.length > 0) {
alert("This looks like a " + cardname + " number, not a " + card + " number.");
return false;

}
else {
alert("This card number is not valid.");
return false;

      }
   }
}
/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year, 
                                        int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year        : year of expiry date.
month       : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
var n;
var argv = CardType.arguments;
var argc = CardType.arguments.length;

this.objname = "object CardType";

var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

this.setCardNumber = setCardNumber;  // set CardNumber method.
this.setCardType = setCardType;  // setCardType method.
this.setLen = setLen;  // setLen method.
this.setRules = setRules;  // setRules method.
this.setExpiryDate = setExpiryDate;  // setExpiryDate method.

this.setCardType(tmpcardtype);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpiryDate(argv[3], argv[4]);

this.checkCardNumber = checkCardNumber;  // checkCardNumber method.
this.getExpiryDate = getExpiryDate;  // getExpiryDate method.
this.getCardType = getCardType;  // getCardType method.
this.isCardNumber = isCardNumber;  // isCardNumber method.
this.isExpiryDate = isExpiryDate;  // isExpiryDate method.
this.luhnCheck = luhnCheck;// luhnCheck method.
return this;
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
var argv = checkCardNumber.arguments;
var argc = checkCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
cardnumber = cardnumber.replace(/\D/g,"");
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;

this.setCardNumber(cardnumber);
this.setExpiryDate(year, month);

if (!this.isCardNumber())
return false;
if (!this.isExpiryDate())
return false;

return true;
}
/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
return this.cardtype;
}
/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
return this.month + "/" + this.year;
}
/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
var argv = isCardNumber.arguments;
var argc = isCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
if (!this.luhnCheck())
return false;

for (var n = 0; n < this.len.size; n++)
if (cardnumber.toString().length == parseInt(this.len[n])) {//fixed by jonny: was always returning false in Mozilla; casting mismatch
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
if (headdigit == this.rules[m])
return true;
}
return false;
}
return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;

if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
var argv = luhnCheck.arguments;
var argc = luhnCheck.arguments.length;

var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

if (! isNum(CardNumber)) {
return false;
  }

var no_digit = CardNumber.length;
var oddoeven = no_digit & 1;
var sum = 0;

for (var count = 0; count < no_digit; count++) {
var digit = parseInt(CardNumber.charAt(count));
if (!((count & 1) ^ oddoeven)) {
digit *= 2;
if (digit > 9)
digit -= 9;
}
sum += digit;
}
if (sum % 10 == 0)
return true;
else
return false;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;
return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;
return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;
return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
// Create the len array.
if (len.length == 0 || len == null)
len = "13,14,15,16,19";

var tmplen = len;
n = 1;
while (tmplen.indexOf(",") != -1) {
tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
n++;
}
this.len = new makeArray(n);
n = 0;
while (len.indexOf(",") != -1) {
var tmpstr = len.substring(0, len.indexOf(","));
this.len[n] = tmpstr;
len = len.substring(len.indexOf(",") + 1, len.length);
n++;
}
this.len[n] = len;
return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
if (rules.length == 0 || rules == null)
rules = "0,1,2,3,4,5,6,7,8,9";
  
var tmprules = rules;
n = 1;
while (tmprules.indexOf(",") != -1) {
tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
n++;
}
this.rules = new makeArray(n);
n = 0;
while (rules.indexOf(",") != -1) {
var tmpstr = rules.substring(0, rules.indexOf(","));
this.rules[n] = tmpstr;
rules = rules.substring(rules.indexOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;
return this;
}

//AJAX stuff
url8 = document.location.href;
xend = url8.lastIndexOf("/") + 1;
var base_url = url8.substring(0, xend);

function ajax_do (url8) {
        // Does URL begin with http?
        if (url8.substring(0, 4) != 'http') {
                url8 = base_url + url8;
        }

        // Create new JS element
        var jsel5 = document.createElement('SCRIPT');
        jsel5.type = 'text/javascript';
        jsel5.src = url8;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel5);

}

function launchajax(){
	ajax_do('signup.php?email='+document.signupnews.emailnews.value);
}