function swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function swapImage() { //v3.0
	var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapImage2() { //v3.0
	var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function ismaxlength(obj){
  var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
  if (obj.getAttribute && obj.value.length>mlength)
    obj.value=obj.value.substring(0,mlength)
}
function previousPage() {
	history.go(-1);
}
function trim(str) {
    return str.replace(/^\s*/, "").replace(/\s*$/, "");
}
function writeMailTo(mailbox,domain,extension,includeLink,subject,innerhtml) {
	address = mailbox+"&#64;"+domain+"&#x2e;"+extension
	if (subject.length>0) {subject = "&#x3f;subject&#61;"+subject}
	if (innerhtml.length==0) {innerhtml = address}
	if (includeLink) {
		link1 = "<a href=\"&#x6d;&#x61;&#x69;&#108;&#x74;&#x6f;&#x3a;"+address+subject+"\">";
		link2 = "</a>";
	} else {
		link1 = "";
		link2 = "";
	}
	document.write(link1+innerhtml+link2);
}
function formatUpperCase(obj){
obj.value = obj.value.toUpperCase();
}
function formatLowerCase(obj){
obj.value = obj.value.toLowerCase();
}
function formatPhone(obj,allowExt) {
	tempNum = ""+obj.value;
	newNum = "";
	extension = "";
	for (i=0;i<tempNum.length;i++) {
		testChar = "" + tempNum.substr(i,1);
		if ((isNaN(testChar)) || (testChar == " ")) {
			//nan
		} else {
			newNum = newNum + testChar;
		}
	}
	areaCode = newNum.substr(0,3);
	prefix = newNum.substr(3,3);
	suffix = newNum.substr(6,4);
    if (newNum.length >= 11)
    {
    	extension = newNum.substr(10,5);
    }
	if (newNum.length >= 4) {
		areaCode = "(" + areaCode + ")";
	}
	if (newNum.length >= 4) {
		prefix = " " + prefix;
	}
	if (newNum.length >= 7) {
		suffix = "-" + suffix;
	}
	if ((newNum.length >= 11) && (allowExt != false)) {
		extension = " x" + extension;
	} else {
		extension = "";
	}
	obj.value = areaCode + prefix + suffix + extension;
}
function formatZip(obj) {
	tempNum = ""+obj.value;
	newNum = "";
	for (i=0;i<tempNum.length;i++) {
		testChar = "" + tempNum.substr(i,1);
		if ((isNaN(testChar)) || (testChar == " ")) {
			//nan
		} else {
			newNum = newNum + testChar;
		}
	}
	newzip = "";
	zip1 = newNum.substr(0,5);
	zip2 = newNum.substr(5,4);
	if (newNum.length >= 6) {
		newzip = zip1 + "-" + zip2;
	} else {
		newzip = zip1;
	}
	obj.value = newzip;
}
function formatExpiration(obj) {
	tempNum = ""+obj.value;
	newNum = "";
	slashFlag = false;
	if (tempNum.length>=3) {
		if (tempNum.substr(2,2)=="/") {
			slashFlag = true;	
		}
	}
	for (i=0;i<tempNum.length;i++) {
		testChar = "" + tempNum.substr(i,1);
		if ((isNaN(testChar)) || (testChar == " ")) {
			//nan
		} else {
			newNum = newNum + testChar;
		}
	}
	expmm = newNum.substr(0,2);
	expdd = newNum.substr(2,4);
	if (newNum.length >= 3) {
		newNum = newNum.substr(0,2) + "/" + newNum.substr(2);
	} else if (slashFlag) {
		newNum = newNum + "/";
	}
	obj.value = newNum
}
function isValidCC(sender, args) {
	var visa="^(?:(?:[4])(?:\\d{12}|\\d{15}))$"
	var MC = "^(?:(?:[5][1-5])(?:\\d{14}))$"
	var Amex = "^(?:(?:[3][4|7])(?:\\d{13}))$"
	var Diners = "^(?:(?:[3][6|8])(?:\\d{12}))$|^(?:(?:[3][0][0-5])(?:\\d{11}))$"
	var Discover = "^(?:(?:6011)(?:\\d{12}))$"
	var JCB = "^(?:(?:(?:2131|1800)(?:\\d{11}))$|^(?:(?:3)(?:\\d{15})))$"
	var pattern="^(?:(?:(?:2131|1800)(?:\\d{11}))$|^(?:(?:3)(?:\\d{15})))$|^(?:(?:6011)(?:\\d{12}))$|^(?:(?:[3][6|8])(?:\\d{12}))$|^(?:(?:[3][0][0-5])(?:\\d{11}))$|^(?:(?:[3][4|7])(?:\\d{13}))$|^(?:(?:[5][1-5])(?:\\d{14}))$|^(?:(?:[4])(?:\\d{12}|\\d{15}))$"
	var re = new RegExp(pattern);
	if (args.Value.replace(/-/g, '').replace (/^\s+|\s+$/g,'').match(re)) {
		if (Mod10(args.Value.replace(/-/g, '').replace (/^\s+|\s+$/g,''))==true){
		    args.IsValid=true
			return true;
		} else {
			sender.errormessage="Please enter a valid Credit Card Number."
			args.IsValid=false
			return false;
		}
	} else {
		sender.errormessage="Please enter a valid Credit Card Number."
		args.IsValid=false
		return false;
	}
}
function isValidExp(sender, args) {
	var exppattern=/^(\d{2})(\/)(\d{2})$/
	var re = new RegExp(exppattern);
	var matchArray = args.Value.match(re); 
	if (matchArray == null) 
	{
		sender.errormessage="Please enter your credit card expitation date as mm/yy"
		args.IsValid=false
		return false;
	} else {
		month = matchArray[1];
		year = matchArray[3];
		if (month < 1 || month > 12) { // check month range
			sender.errormessage="The month in your credit card expiration date must be between 1 and 12."
			args.IsValid=false
			return false;
		} else {
			if (year < 08 || year > 20) { // check year range
				sender.errormessage="The year in the credit card expiration date is invalid."
				args.IsValid=false
				return false;
			} else {
			    args.IsValid=true
				return true;
			}
		}
	}
}
function Mod10(ccNumb) {  // v2.0
	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
				// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
				// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
				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
			}  
			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 is NOT be a valid credit card number
			}
		}
	}
    return bResult; // Return the results
}