var nbsp = 160;    // non-breaking space char
var node_text = 3; // DOM text node-type
var emptyString = /^\s*$/
var glb_vfld;      // retain vfld for timer thread

function swapPicture(elem,prod,idx) {
	var pimgary = eval("pimg_"+prod);
	if (elem.form["pimg_"+prod] != undefined) {
		elem.form["pimg_"+prod].src = pimgary[idx].src;
		elem.form["pimg_"+prod].width = pimgary[idx].width;
		elem.form["pimg_"+prod].height = pimgary[idx].height;
		return false;
	}
	return true;
}

function iteratePicture(elem,prod) {
	var shouldChange = true;
	var prodform = elem.form;
	var opshn = eval("opts_"+prod);
	var pimgary = eval("pimg_"+prod);
	var imidx = eval("oixs_"+prod);

	//alert(opshn);
	//alert(pimgary);
	//alert(imidx);
	//if (imidx.length > 0) {
		//alert("Has some");
	//} else {
		//alert("Has none");
	//}

	var assm = 0;
	if (opshn != undefined) {
		var assm = new Array();
		for (var j=0; j<opshn.length; j++) {
			var prodop = prodform["opt_"+opshn[j]];
			var si = prodop.selectedIndex;
			assm.push(si);
			if (si == 0) {
				shouldChange = false;
			}
		}
		assm = assm.join("@@");
		//alert(assm+", now looking for "+"oixs_"+prod+", which is ["+imidx+"]"); return;
		if (document.images && shouldChange) {
			if (imidx[assm] != undefined) {
				pimg = pimgary[imidx[assm]];
				document.images["pimg_"+prod].src       = pimg.src;
				document.images["pimg_"+prod].width     = pimg.width;
				document.images["pimg_"+prod].height    = pimg.height;
			}
		} else if (document.images) {
			pimg = eval("pimg_"+prod+"[0]");
			document.images["pimg_"+prod].src       = pimg.src;
			document.images["pimg_"+prod].width     = pimg.width;
			document.images["pimg_"+prod].height    = pimg.height;
		}
	}
}

function changePicture(elem,prod) {
        if (elem.selectedIndex > 0 && document.images) {
                ofst = eval("ofst_"+prod);
                var pimgary = eval("pimg_"+prod);
                for(var i=0; i < pimgary.length; i++) {
                        //alert("We found pimgary "+pimgary[i]);
                        if (i == (elem.selectedIndex-1+ofst)) {
                                pimg = pimgary[i];
                                document.images["pimg_"+prod].src       = pimg.src;
                                document.images["pimg_"+prod].width     = pimg.width;
                                document.images["pimg_"+prod].height    = pimg.height;
                                //alert("i("+i+") pimg("+pimg+") pimg.src("+pimg.src+") - theimg("+document.images["pimg_"+prod].src+")");
                        }
                }
        }
}


function nicemoney(val) {
	var result = (Math.round(val*100)/100).toString();
	var spl = result.split('.');
	if (spl[0] && spl[1]) {
		if (spl[1] < 10) {
			spl[1] = spl[1].toString()+'0';
		}
		result = spl.join('.');
	} else if (spl[0]) {
		result = spl[0];
	}
	return result;
}

function money(val) {
	var result = (Math.round(val*100)/100).toString();
	var spl = result.split('.');
	if (spl[0] && spl[1]) {
		if (spl[1] < 10) {
			spl[1] = spl[1].toString()+'0';
		}
		result = spl.join('.');
	} else if (spl[0]) {
		result = spl[0]+'.00';
	}
	return result;
}

function fixIE(whichLayer,dx,dy,align) {
        if (document.getElementById) {
                // this is the way the standards work
                var thestyle = document.getElementById(whichLayer).style;
        } else if (document.all) {
                // this is the way old msie versions work
                var thestyle = document.all[whichLayer].style;
        } else if (document.layers) {
                // this is the way nn4 works
                var thestyle = document.layers[whichLayer].style;
        }

	if (align == 'TR') {
		thestyle.top = thestyle.top + dy;
		thestyle.right = thestyle.right + dx;
	} else if (align == 'BR') {
		thestyle.bottom = thestyle.bottom + dy;
		thestyle.right = thestyle.right + dx;
	} else if (align == 'BL') {
		thestyle.bottom = thestyle.bottom + dy;
		thestyle.left = thestyle.left + dx;
	} else if (align == 'TL') {
		thestyle.top = thestyle.top + dy;
		thestyle.left = thestyle.left + dx;
	}

        return thestyle.top;
}



function openPane(myLink,windowName,wi,he) {
    if(! window.focus)return;
    var myWin=window.open("",windowName,"resizable=yes,height="+he+",width="+wi+",left=10,top=10,dependent=yes,scrollbars=yes,");
    myWin.focus();
    myLink.target=windowName;
}

 function toggleLayer(whichLayer) {
        if (document.getElementById) {
                // this is the way the standards work
                var style2 = document.getElementById(whichLayer).style;
        } else if (document.all) {
                // this is the way old msie versions work
                var style2 = document.all[whichLayer].style;
        } else if (document.layers) {
                // this is the way nn4 works
                var style2 = document.layers[whichLayer].style;
        }
        if (style2.display == "" || style2.display == "block") {
                style2.display = "none"; 
        } else {
                style2.display = "block";
        }       
        return style2.display;
}

function toggleSearchVis(whichLayer) {
	var thestyle = toggleLayer(whichLayer);
	document.mainform.searchvis.value = thestyle;
	var slink = document.getElementById("searchvis").innerHTML;
	if (slink == "Show Search Box") {
		document.getElementById("searchvis").innerHTML = "Hide Search Box";
	} else {
		document.getElementById("searchvis").innerHTML = "Show Search Box";
	}
}

var alrt = "";

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame 
	var timer = 0; 
	var speed = millisec / Math.abs(opacEnd-opacStart);	// this is a time factor to multiply everything by for a good appearance

	//determine the direction for the blending, if start and end are the same nothing happens 
	var event_time = 0;
	if (opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			if (Math.round(timer*speed) != event_time) {
				event_time = Math.round(timer * speed);			// represents the index of the currently printed step or current setTimeout
				setTimeout("changeOpac(" + i + ",'" + id + "')",event_time); 
				//alrt += i+"- event_time = "+event_time+"\n";
			}
			timer++; 
		} 
	} else if (opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) { 
			if (Math.round(timer*speed) != event_time) {
				event_time = Math.round(timer * speed);			// represents the index of the currently printed step or current setTimeout
				setTimeout("changeOpac(" + i + ",'" + id + "')",event_time); 
				//alrt += i+"- event_time = "+event_time+"\n";
			}
			timer++; 
		} 
	} 
	setTimeout("changeOpac("+opacEnd+",'"+id+"')", millisec);
	//setTimeout("alert(alrt)", millisec+10);
	if (opacEnd == 0) {
		setTimeout("hideItem('ShopText')",millisec);
	}
}

function hideItem(id) {
	if (document.getElementById) {
		var st = document.getElementById(id);
		st.style.display = "none";
	}
}

function chPos(id,pos) {
	if (document.getElementById) {
		var st = document.getElementById(id);
		st.style.top = pos + "px";
	}
}

function tellPos() {
	var st = document.getElementById('ShopText');
	//alert(st.style.top);
	return parseInt(st.style.top);
}

var moveTid;
var opacTid;
var clerTid;

function mST(t,steps,dir) {
	var T_o = 1000;
	alrt = "";
	var sp = 10;
	var goaway = 25000;
	var inc = t / steps;
	var et = 0;
	var opos = tellPos();
	var td = opos;
	var i = 0;
	if (dir == 1) {
		if (document.getElementById) {
			document.getElementById('ShopText').style.display = "block";
		}
		var acc = -0.025;
		var vo = sp;
		var v = vo;
		while (v > 0) {
			et = i * inc;
			v = vo + (0.5 * acc * et);
			td += v;
			var opac = Math.round(100 * (vo - v) / vo);
			moveTid = setTimeout("chPos('ShopText',"+(td)+")",T_o + et); 
			opacTid = setTimeout("changeOpac("+opac+",'ShopText')",T_o + et+1); 
			//alrt += "["+td+"-"+opac+"]\n";
			i++;
		}
		moveTid = setTimeout("clearMOt()",T_o + t+12);
		clerTid = setTimeout("fadeMessage()",T_o + goaway);
	} else {
		T_o = 0;
		clearTimeout(moveTid);
		clearTimeout(opacTid);
		acc = 0.025;
		var vo = 0;
		var v = vo;
		while (v < sp) {
			et = i * inc;
			v = vo + (0.5 * acc * et);
			td += v;
			var opac = 100 - Math.round(100 * v / sp);
			moveTid = setTimeout("chPos('ShopText',"+(td)+")",T_o + et); 
			opacTid = setTimeout("changeOpac("+opac+",'ShopText')",T_o + et+1); 
			//alrt += "["+td+"-"+opac+"]\n";
			i++;
		}
		clerTid = setTimeout("clearClear()",T_o + t+12);
	}
}

function clearMOt() {
	//alert("Clearing MOt");
	clearTimeout(moveTid);
	clearTimeout(opacTid);
}
function clearFade() {
	//alert("Clearing Fade");
	clearTimeout(clerTid);
}

function clearClear() {
        if (document.getElementById) {
                //alert("Clearing The Big Daddy");
                document.getElementById('ShopText').innerHTML = "";
                document.getElementById('ShopText').style.width = "1px";       //100;
                document.getElementById('ShopText').style.height = "1px";      //100;
                document.getElementById('ShopText').style.overflow = "hidden";
                document.getElementById('ShopText').style.display = "none";
                changeOpac(0,'ShopText');
        }
        clearTimeout(moveTid);
        clearTimeout(opacTid);
        clearTimeout(clerTid);
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
        opacity = 100;
  if (opacity < 20) { opacity = 0; }
  if (document.getElementById) {
    var object = document.getElementById(id).style;
   if(object.opacity)
    object.opacity = (opacity / 100);
   if(object.MozOpacity)
    object.MozOpacity = (opacity / 100);
   if(object.KhtmlOpacity)
    object.KhtmlOpacity = (opacity / 100);
   if(object.filter)
    object.filter = "alpha(opacity=" + opacity + ")";
  }
}

function jbug(msg) {
	if(window.console) {
                window.console.log(msg);
        } else {
                alert(msg);
        }
}

function dXXXXXXXXXXXXmsg(fld, msgtype, message) {
	// setting an empty string can give problems if later set to a 
	// non-empty string, so ensure a space present. (For Mozilla and Opera one could 
	// simply use a space, but IE demands something more, like a non-breaking space.)
	var dispmessage;
	if (emptyString.test(message)) 
		dispmessage = String.fromCharCode(nbsp);    
	else  
		dispmessage = message;

	var elem = document.getElementById(fld);
	elem.firstChild.nodeValue = dispmessage;  
	elem.className = msgtype;   // set the CSS class to adjust appearance of message
};

function checkoptions(what,thediv) {
	var d = document.getElementById(thediv);
	var f = what.form;
	var dispmessage;
	var message = "";

	if (what.value != "") {
		grr = /([A-Za-z0-9 _-]+)(\:[A-Za-z0-9 _-]+\|[A-Za-z0-9 _-]+\|[0-9-]+)/;
		var codes = what.value.split("\n");
		var goodcode = new Array();
		var thetitles = new Array();
		var theoptions = new Array();
		for (var i=0; i<codes.length; i++) {
			if (grr.test(codes[i])) {
				goodcode[i] = 1;
				theoptions[i] = "";
				var coda	= codes[i].split(":");
				//thetitles[i]	= coda[0];
				var tit		= coda[0];
				var codb	= coda[1].split("|");
				var lbl		= codb[0];
				var skum	= codb[1];
				var pdif	= codb[2];
				theoptions[i] += tit+":";
				theoptions[i] += "<OPTION>";
				theoptions[i] += lbl;
				theoptions[i] += "</OPTION>";
				theoptions[i] += "\n";
			} else {
				//message += "Code does not match form\n";
				goodcode[i] = 0;
			}
		}
		message += "<SELECT>\n";
		for (var j=0; j<codes.length; j++) {
			if (goodcode[j] == 1) {
				message += theoptions[j];
			}
		}
		message += "</SELECT>\n";
	}

	if (emptyString.test(message)) 
		dispmessage = String.fromCharCode(nbsp);    
	else  
		dispmessage = message;

	if (d) {
		if (message != "") {
			d.firstChild.nodeValue = dispmessage;
			d.className = "test";
		} else {
			d.firstChild.nodeValue = "";
			d.className = "info";
		}
	}

	return;
}

function CapWords(what) {
        var tmpStr, tmpChar, preString, postString, strlen;
        tmpStr = what.value;
        if (tmpStr.match(/[A-Z][A-Z][A-Z]/)) {
                tmpStr = tmpStr.toLowerCase();
        }
        stringLen = tmpStr.length;
        if (stringLen > 0) {
                for (i = 0; i < stringLen; i++) {
                        if (i == 0) {
                                tmpChar = tmpStr.substring(0,1).toUpperCase();
                                postString = tmpStr.substring(1,stringLen);
                                tmpStr = tmpChar + postString;
                        } else {
                                tmpChar = tmpStr.substring(i,i+1);
                                if ((tmpChar == "-" || tmpChar == " ") && i < (stringLen-1)) {
                                        tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
                                        preString = tmpStr.substring(0,i+1);
                                        postString = tmpStr.substring(i+2,stringLen);
                                        tmpStr = preString + tmpChar + postString;
                                }
                        }
                }
        }
        what.value = tmpStr;
}

function checkOther(which,t) {
	if (t == "") {
		t = "value";
	}
	if (which[which.selectedIndex].value == 'other') {
		var ans = prompt("Please enter other "+t);
		if (ans != "") {
			which[which.selectedIndex].text = ans;
			which[which.selectedIndex].value = ans;
		}
	}
}

function Mod10(ccNumb) {
	var valid = "0123456789"  		// Valid digits in a credit card number
	var len = ccNumb.length;  		// The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  		// integer of ccNumb
	var sCCN = ccNumb.toString();  		// string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  			// integer total set at zero
	var bNum = true;  			// by default assume it is a number
	var bResult = false;  			// by default assume it is NOT a valid cc
	var temp;  				// temp variable for parsing string
	var calc;  				// used for calculation of each digit

	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
		temp = "" + sCCN.substring(j, j+1);
		if (valid.indexOf(temp) == "-1"){ bNum = false;}
	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if (!bNum) {
		bResult = false;
	}

	// Determine if it is the proper length 
	if((len == 0)&&(bResult)) {  				// nothing, field is blank AND passed above # check
		bResult = false;
	} else {  						// ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15) {  					// 15 or 16 for Amex or V/MC
			for(var i=len;i>0;i--) {  				// LOOP throught the digits of the card
				calc = parseInt(iCCN) % 10;  			// right most digit
				calc = parseInt(calc);  				// assure it is an integer
				iTotal += calc;  					// running total of the card number as we loop - Do Nothing to first digit
				i--;  						// decrement the count - move to the next digit in the card
				iCCN = iCCN / 10;                               	// subtracts right most digit from ccNumb
				calc = parseInt(iCCN) % 10 ;    			// NEXT right most digit
				calc = calc *2;                                	// multiply the digit by two

				switch(calc) {
					case 10: calc = 1; break;      			//5*2=10 & 1+0 = 1
					case 12: calc = 3; break;			//6*2=12 & 1+2 = 3
					case 14: calc = 5; break;			//7*2=14 & 1+4 = 5
					case 16: calc = 7; break;			//8*2=16 & 1+6 = 7
					case 18: calc = 9; break;			//9*2=18 & 1+8 = 9
					default: calc = calc;				//4*2= 8 &   8 = 8  -same for all lower numbers
				}                                               
				iCCN = iCCN / 10;  					// subtracts right most digit from ccNum
				iTotal += calc;  					// running total of the card number as we loop
			}  										// END OF LOOP
			if ((iTotal%10)==0) {  					// check to see if the sum Mod 10 is zero
				bResult = true;  					// This IS (or could be) a valid credit card number.
			} else {
				bResult = false;  					// This could NOT be a valid credit card number
			}
		}
	}
	// change alert to on-page display or other indication as needed.
	//if(bResult) {
		//alert("This IS a valid Credit Card Number.");
	//}
	//if(!bResult) {
		//alert("The credit card number you entered \nmay have been input incorrectly.\nPlease re-enter your card number.");
	//}
	return bResult; 					// Return the results
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '')
};

function setFocusDelayed() {
	glb_vfld.focus()
}

function setfocus(vfld) {
	// save vfld in global variable so value retained when routine exits
	glb_vfld = vfld;
	setTimeout( 'setFocusDelayed()', 100 );
}

var ermsgs = "";

function msg(fld, msgtype, message) {
	// setting an empty string can give problems if later set to a 
	// non-empty string, so ensure a space present. (For Mozilla and Opera one could 
	// simply use a space, but IE demands something more, like a non-breaking space.)
	var dispmessage;
	if (emptyString.test(message)) {
		dispmessage = String.fromCharCode(nbsp);    
	} else {
		dispmessage = message;
		ermsgs = ermsgs + dispmessage + "\n";
	}

	var elem = document.getElementById(fld);
	elem.firstChild.nodeValue = dispmessage;  
	elem.className = msgtype;   // set the CSS class to adjust appearance of message
};

// -----------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck (vfld, ifld, reqd) {
	if (!document.getElementById) 
		return true;  // not available on this browser - leave validation to the server
	var elem = document.getElementById(ifld);
	if (!elem.firstChild)
		return true;  // not available on this browser 
	if (elem.firstChild.nodeType != node_text)
		return true;  // ifld is wrong type of node  
if (!reqd) return proceed;
	if (emptyString.test(vfld.value)) {
		if (reqd) {
			msg (ifld, "error", "required");  
			setfocus(vfld);
			return false;
		} else {
			msg (ifld, "warn", "");   // OK
			return true;  
		}
	}
	return proceed;
}

function commonCheckNam (vfld, ifld, reqd, nam) {
	if (!document.getElementById) 
		return true;  // not available on this browser - leave validation to the server
	var elem = document.getElementById(ifld);
	if (!elem.firstChild)
		return true;  // not available on this browser 
	if (elem.firstChild.nodeType != node_text)
		return true;  // ifld is wrong type of node  
if (!reqd) return proceed;
	if (emptyString.test(vfld.value)) {
		if (reqd) {
			msg (ifld, "error", nam+" "+"required");  
			setfocus(vfld);
			return false;
		} else {
			msg (ifld, "warn", "");   // OK
			return true;  
		}
	}
	return proceed;
}

// -----------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so 
// -----------------------------------------

function validatePresent(vfld, ifld, nam) {
	//var stat = commonCheck (vfld, ifld, true);
	var stat = commonCheckNam (vfld, ifld, true, nam);
	if (stat != proceed) return stat;

	msg (ifld, "warn", "");  
	return true;
};

function validatePass(vfld,v2fld,ifld) {
	if (vfld.value != v2fld.value) {
		//alert("Please confirm your password.");	// Something is wrong here
		msg (ifld, "error", "You must correctly confirm your password.");
		return false;
	} else if (vfld.value == "") {
		msg (ifld, "error", "You must specify a password.");
		return false;
	}

	msg (ifld, "warn", "");  
	return true;
};

// -----------------------------------------
//            validateSelect
// Validate select has value
// Returns true if so 
// -----------------------------------------

function validateSelect (vfld, ifld, other, t) {
	if (t == undefined || t == "") {
		t = "value";
	}
	if (vfld.options[vfld.selectedIndex].value == "") {
		if (other != "") {
			if (trim(other.value) == "") {
				msg (ifld, "error", "You must select a "+t);  
				return false;
			}
		} else {
			msg (ifld, "error", "You must select a "+t);  
			return false;
		}
	}
	msg (ifld, "warn", "");
	return true;
};

// -----------------------------------------
//               validateAlias
// Validate if strictalphanum
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateAlias (vfld, ifld, reqd) {
	var stat = commonCheck (vfld, ifld, reqd);
	if (stat != proceed) return stat;

	var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
	var als = /^[a-zA-Z0-9_-]+$/
	var vet = /^.*myvetra.com\//
	if (vet.test(tfld)) {
		msg (ifld, "warn", "Please leave out the 'myvetra.com\/'");
		tfld = tfld.replace(/^.*myvetra.com\//,"");
		vfld.value = tfld;
	}
	if (!als.test(tfld)) {
		msg (ifld, "error", "not a valid web alias (only letters and numbers)");
		var wrds = vfld.value.split(" ");
		if (wrds.length > 1) {
			var newrd = "";
			for (var i=0; i<wrds.length; i++) {
				newrd += wrds[i].substring(0,1).toUpperCase() + wrds[i].substring(1,wrds[i].length);
			}
			vfld.value = newrd;
		}
		setfocus(vfld);
		return false;
	}
	else
		msg (ifld, "warn", "");
	return true;
};


// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail (vfld, ifld, reqd) {
	var stat = commonCheck (vfld, ifld, reqd);
	if (stat != proceed) return stat;

	var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
	var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
	if (!email.test(tfld)) {
		msg (ifld, "error", "not a valid e-mail address");
		setfocus(vfld);
		return false;
	}

	var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
	if (!email2.test(tfld)) 
		msg (ifld, "warn", "Unusual e-mail address - check if correct");
	else
		msg (ifld, "warn", "");
	return true;
};


// -----------------------------------------
//            validatePhone
// Validate telephone number
// Permits spaces, hyphens, brackets and leading +
// -----------------------------------------

function validatePhone (vfld, ifld, reqd) {
	var stat = commonCheck (vfld, ifld, reqd);
	if (stat != proceed) return stat;
	//alert("["+stat+"]["+proceed+"] Validating Phone");

	var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
	var telnr = /^\+?[0-9 ()-.]+[0-9]$/
	if (!telnr.test(tfld)) {
		msg (ifld, "error", "not a valid telephone number. Characters permitted are digits, space () - . and leading +");
		setfocus(vfld);
		return false;
	}

	var numdigits = 0;
	var digitlist = "";
	for (var j=0; j<tfld.length; j++) {
		if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') {
			digitlist = digitlist + tfld.charAt(j);
			numdigits++;
		}
	}

	if (numdigits<6) {
		msg (ifld, "error", "" + numdigits + " digits - too short");
		setfocus(vfld);
		return false;
	}

	if (numdigits>14)
		msg (ifld, "warn", numdigits + " digits - check if correct");
	else { 
		if (numdigits<10)
			msg (ifld, "warn", "Only " + numdigits + " digits - check if correct");
		else
			msg (ifld, "warn", "");
	}

	if (numdigits==10) {
		vfld.value = "("+digitlist.substring(0,3)+") "+digitlist.substring(3,6)+"-"+digitlist.substring(6);
	}
	return true;
};


// -----------------------------------------
//             validateExpdate
// Validate creditcard's expiration date
// Returns true if OK 
// ExpireMonth
// ExpireYear
// MASTER
// -----------------------------------------

function wipeC(what) {
return;
	//var reggy = /\*/;
	//if (reggy.test(what.form.card_num.value)) {
		//what.form.card_num.value = "";
	//}
	//if (reggy.test(what.form.card_code.value)) {
		//what.form.card_code.value = "";
	//}
}

function checkDt(what) {
return;
	if (what.form.cc_exp_mm.value != "" && what.form.cc_exp_yy.value != "") {
		validateExpdate(what.form.cc_exp_mm.value, what.form.cc_exp_yy.value, 'inf_cc_exp');
	}
}

function validateExpdate (expmm, expyy, ifld) {
	var errors = "";
	var stat = commonCheck (expmm, ifld);
	if (stat != proceed) return stat;
	var mm = trim(expmm.value);
	var yy = trim(expyy.value);
	var numerr = 0;
	var isN=/[0-9]{1,4}/;
	if (!isN.test(yy)) {
		errors = errors + "Year ("+yy+") is invalid.\n";
		numerr++;
	}
	if (!isN.test(mm)) {
		errors = errors + "Month is invalid.\n";
		numerr++;
	}
	
	var now = new Date();
	var yr = now.getFullYear();
	var mo = 1 + now.getMonth();

	if (yy.length < 3) {
		yr -= 2000;
		if (yr == yy) {	
			if (mm < mo) {
				errors += "Must expire in the future.\n";
				numerr++;
			} else {
				// ok here
				msg (ifld, "warn", "");
				return true;
			}
		} else if (yr > yy) {
			errors += "Must expire in the future.\n";
			numerr++;
		} else {
			// ok here
			msg (ifld, "warn", "");
			return true;
		}
	} else if (yy.length < 5) {
		if (yy < yr) {
			errors += "Must expire in the future.\n";
			numerr++;
		} else if (yy == yr) {
			if (mm < mo) {
				errors += "Must expire in the future.\n";
				numerr++;
			} else {
				// okay here
				msg (ifld, "warn", "");
				return true;
			}
		} else if ((yy - yr) > 100) {
			errors += "Number too large.\n";
			numerr++;
		} else {
			// okay here
			msg (ifld, "warn", "");
			return true;
		}
	} else {
		errors += "Number too long.\n";
		numerr++;
	}

	if (numerr) {
		msg(ifld, "error", errors);
		return false;
	}
	msg (ifld, "warn", "");
	return true;
};

// -----------------------------------------
//            validateCheckbox
// Validate that the correct number of checkboxes has been checked.
// Returns true if valid (and also if could not be executed because 
// of old browser)
// -----------------------------------------

function validateCheckbox  (vfld,   // checkboxes to be validated
				ifld,   // id of element to receive info/error msg
				nr,     // number of checkboxes to be checked. >=2
				cond)   // condition: -1 = less than or equal to nr
					//             0 = equal to nr (default)
					//             1 = greater than or equal to nr
{
	if (!nr || nr<2) {
		alert('Programming error in validateCheckbox: nr<2'); 
		// for nr=1 use radio buttons or validateConfirm
		return true;
	}
	if (!cond) cond = 0;

	var stat = commonCheck2(vfld, ifld);
	if (stat != proceed) return stat;

	// count how many boxes have been checked by the reader
	var count = 0;
	for (var j=0; j<vfld.length; j++)
		if (vfld[j].checked) count++;

	if (count==nr) return true;
	if (count<nr && cond==-1) return true;
	if (count>nr && cond==1)  return true;

	// if we get here then the validation has failed

	var suffix='';
	if (count>1) suffix='es';

	var errorMsg;

	if (count<nr) errorMsg = 'Only ' + count + ' box' + suffix + ' checked: ' + nr + ' required';
	if (count>nr) errorMsg = '' + count + ' boxes checked: maximum ' + nr + ' allowed';
	if (count==0) errorMsg = 'No boxes checked: ' + nr + ' required';

	msg (ifld, "error", errorMsg);
	return false;
}


// -----------------------------------------
//            validateConfirm 
// Usually one doesn't want to validate if 1 checkbox of a set has been
// checked, because in this case one would use radio buttons instead.
// But sometimes one wants a reader to check a single box to confirm that 
// he or she agrees to something. That is covered by this routine.
//
// Returns true if valid (and also if could not be executed because 
// of old browser)
// -----------------------------------------

function validateConfirm   (vfld,   // checkbox to be validated
				ifld)   // id of element to receive info/error msg
{
	var stat = commonCheck2(vfld, ifld);
	if (stat != proceed) return stat;
	if (vfld.checked) return true;
	// if we get here then the validation has failed

	var errorMsg = 'Please read the above message and confirm you agree to it';
	msg (ifld, "error", errorMsg);
	return false;
}

// validate radio buttons
function validateRadio (vfld,ifld,t,val) {
	myOption = -1;
	for (var i = vfld.length - 1; i > -1; i--) {
		if (vfld[i].checked) {
			myOption = i;
		}
	}
	if (t == undefined || t == "") {
		t = "Required";
	}
	if (myOption == -1) {
		msg (ifld, "error", t);
		return false;
	}
	if (val != undefined && val != "") {
		if (vfld[myOption].value != val) {
			msg (ifld, "error", t);
			return false;
		}
	}

	msg (ifld,"warn","");
	return true;
}


function validateCode(vfld, ifld, dig) {
        var stat = commonCheck (vfld, ifld, true);
        if (stat != proceed) return stat;

	if (vfld.value.length != parseInt(dig)) {
		msg (ifld, "error", "Must be "+parseInt(dig)+" digits, not "+vfld.value.length);
		return false;
	}

        msg (ifld, "warn", "");
        return true;
};

function validateCard(vfld, ifld) {
        var stat = commonCheck (vfld, ifld, true);
        if (stat != proceed) return stat;

	vfld.value = vfld.value.replace(/[^0-9]/g,"");
	if (!Mod10(vfld.value)) {
		msg (ifld, "error", "Must input valid card number");
		return false;
	}

        msg (ifld, "warn", "");
        return true;
};

function manClick(val,sba) {
	// sba is don't repeat
	//alert("We have "+document.forms.navform);
	//return true;
        document.forms.navform.navButton.value = val;
        document.forms.navform.SaveWhereWeWere.value = sba;
        document.forms.navform.submit();
};

var lastKey = "";	// for keyStateSelect and keyMonthSelect (12 = 1,2 NY = n,y)

function keyStateSelect(element,e) {
        var key = e.keyCode;
        var keychar = String.fromCharCode(key).toLowerCase();
        var len = element.options.length;
        for (var i=len-1; i >= 0; i--) { 
                Kstate = element.options[i].value.toLowerCase();
		if (lastKey != "") {
			if (Kstate.substr(1,1) == keychar && Kstate.substr(0,1) == lastKey) {
				element.options[i].selected = true;
				lastKey = "";
			} else if (Kstate.substr(0,1) == keychar) {
				element.options[i].selected = true;
			}
		} else {
			if (Kstate.substr(0,1) == keychar) {
				element.options[i].selected = true;
			}
		}
        }
	lastKey = keychar;
	return;
};

function keyMonthSelect(element,e) {
        var key = e.keyCode;
        var keychar = parseInt(String.fromCharCode(key));
        var len = element.options.length;
	var offset = 0;
	var number = keychar;
	if (len > 12) {
		offset = len - 12;
	}
	if (parseInt(lastKey) == 1) {
		if (keychar < 3) {
			number = 10 + keychar;
		} else {
			number = keychar;
		}
		lastKey = "";
	} else {
		lastKey = keychar;
	}

	number--;
        for (var i=0; i<len; i++) { 
		if ((i + offset) == number) {
			element.options[i].selected = true;
			return;
		}
        }
};

function keyYearSelect(element,e) {
        var key = e.keyCode;
        var keychar = parseInt(String.fromCharCode(key));
        var len = element.options.length;
	var offset = 0;
	var number = keychar;
	if (lastKey != "") {
		number = 10 + keychar;
		lastKey = "";
	} else {
		number = keychar;
		lastKey = keychar;
	}

	number += 2000;
        for (var i=0; i<len; i++) { 
		if (element.options[i].value == number) {
			element.options[i].selected = true;
			return;
		}
        }
};

function checkReturn(w,e) {
        var keynum;
        var keychar;
        var idx;
        if (e != null) {
                if (window.event) {
                        keynum = e.keyCode;
                } else if (e.which) {
                        keynum = e.which;
                }
                keychar = String.fromCharCode(keynum);
        } else {
                keynum = 666;
                keychar = "@";
        }
        //alert(keynum);
        if (keynum == 13) {       // return
                //alert(w.form.navButton);
                w.form.navButton.value = 'nav_Products_SafeSearch_';
                w.form.submit();
        }
}

function checkReturnNav(w,e,nbv) {
        var keynum;
        var keychar;
        var idx;
        if (e != null) {
                if (window.event) {
                        keynum = e.keyCode;
                } else if (e.which) {
                        keynum = e.which;
                }
                keychar = String.fromCharCode(keynum);
        } else {
                keynum = 666;
                keychar = "@";
        }
        //alert(keynum);
        if (keynum == 13) {       // return
                //alert(w.form.navButton);
                w.form.navButton.value = nbv;
                w.form.submit();
        }
}

