var purchaseType;
var couponCodeValid = false;
var productKeyValid = false;
var couponProduct;
var couponType;
var couponValue;
var venueString;
var woz = "fa8390";
var woosh = "l41075";
var fmtPrices;

function reInit() {
	document.purchase.buyOption[0].checked=true;
	displayNewPurchase();
}
function changeBuyOptionValues() {
 document.purchase.productKey.value="";
 document.purchase.couponCode.value="";
 document.purchase.productKey.readOnly = false;
 document.purchase.couponCode.readOnly = false;
 couponCodeValid = false;
 productKeyValid = false;
 spinReset("cc");
 spinReset("pk");
 enableAllVenues();
 reCalc();	
}
function displayNewPurchase() {
 purchaseType="new";
 changeBuyOptionValues();
 document.getElementById("onlyVenues").style.display="none";
 document.getElementById("upgVenues").style.display="none";
 document.getElementById("newVenues").style.display="block";
 document.getElementById("productKey").style.display="none";
 document.getElementById("cdInfo").style.display="block";
 document.getElementById("rightNew").style.display="block";
 document.getElementById("rightUpgrade").style.display="none";
 document.getElementById("rightVenues").style.display="none";
}
function displayUpgrade() {
 purchaseType="upgrade";
 changeBuyOptionValues();
 document.getElementById("newVenues").style.display="none";
 document.getElementById("onlyVenues").style.display="none";
 document.getElementById("upgVenues").style.display="block";
 document.getElementById("productKey").style.display="block";
 document.getElementById("cdInfo").style.display="block";
 document.getElementById("rightNew").style.display="none";
 document.getElementById("rightUpgrade").style.display="block";
 document.getElementById("rightVenues").style.display="none";
}
function displayVenueUpdate() {
 purchaseType="venues";
 changeBuyOptionValues();
 document.getElementById("newVenues").style.display="none";
 document.getElementById("upgVenues").style.display="none";
 document.getElementById("onlyVenues").style.display="block";
 document.getElementById("productKey").style.display="block";
 document.getElementById("shipCD").checked=false;
 document.getElementById("cdInfo").style.display="none";
 document.getElementById("rightNew").style.display="none";
 document.getElementById("rightUpgrade").style.display="none";
 document.getElementById("rightVenues").style.display="block";
 checkShipOption();
}
function sameAsBuyer(checkbox) {
  if(checkbox.checked) {
    document.getElementById("shippingInfo").style.display = "none";
    document.purchase.COUNTRYTOSHIP.disabled = true;
	// needed to prevent field from going to Verisign
  } else {
    document.getElementById("shippingInfo").style.display = "block";
    document.purchase.COUNTRYTOSHIP.disabled = false;
  }
}
function checkShipOption() {
 if (document.getElementById("shipCD").checked) {
    document.getElementById("shipOption").style.display="block";
 } else {
   document.getElementById("shippingInfo").style.display="none";
   document.getElementById("shipOption").style.display="none";
   document.purchase.COUNTRYTOSHIP.disabled = true;
   document.purchase.SameAsBuyer.checked = true;
 }
 reCalc();
}
function setFields() {
  document.purchase.NAME.value = document.purchase.BuyerFirstName.value + " " + document.purchase.BuyerLastName.value;
  if (document.purchase.BuyerAddrLn2.value.length > 0) {
    document.purchase.ADDRESS.value = document.purchase.BuyerAddrLn1.value + ", " + document.purchase.BuyerAddrLn2.value;
  } else {
    document.purchase.ADDRESS.value = document.purchase.BuyerAddrLn1.value;
  } 
  if (document.getElementById("shipCD").checked) {
  		document.purchase.NAMETOSHIP.value = document.purchase.ShipFirstName.value + " " + document.purchase.ShipLastName.value;
    	if (document.purchase.ShipAddrLn2.value.length > 0) {
      		document.purchase.ADDRESSTOSHIP.value = document.purchase.ShipAddrLn1.value + ", " + document.purchase.ShipAddrLn2.value;
    	} else {
      		document.purchase.ADDRESSTOSHIP.value = document.purchase.ShipAddrLn1.value;
    	} 
  }
  document.getElementById("uBuyerFirstName").value = document.getElementById("BuyerFirstName").value;
  document.getElementById("uBuyerLastName").value = document.getElementById("BuyerLastName").value;
  document.getElementById("uBuyerAddrLn1").value = document.getElementById("BuyerAddrLn1").value;
  document.getElementById("uBuyerAddrLn2").value = document.getElementById("BuyerAddrLn2").value;
  document.getElementById("uShipFirstName").value = document.getElementById("ShipFirstName").value;
  document.getElementById("uShipLastName").value = document.getElementById("ShipLastName").value;
  document.getElementById("uShipAddrLn1").value = document.getElementById("ShipAddrLn1").value;
  document.getElementById("uShipAddrLn2").value = document.getElementById("ShipAddrLn2").value;
  var multiple = purchaseType + ",";
  if (document.getElementById("shipCD").checked) {
    multiple = multiple + document.getElementById("shipCD").value;
  }
  multiple = multiple + ",";
  if (document.getElementById("SameAsBuyer").checked) {
	multiple = multiple + document.getElementById("SameAsBuyer").value;
  }  
  multiple = multiple + ",";
  if (couponCodeValid) {
    multiple = multiple + Trim(document.purchase.couponCode.value);
  }
  multiple = multiple + ",";
  if (productKeyValid) {
    multiple = multiple + document.purchase.productKey.value;
  }
  multiple = multiple + "," + fmtPrices;
  document.getElementById("uTypeCdSameCoupProd").value = multiple;
  document.getElementById("uVenues").value = venueString;
}
function bar() {
  var temp = "";
  for (var x = 0; x < woz.length; x++) {
    temp = temp + woz.substr(x,1) + woosh.substr(x,1);
  }
  document.getElementById("foob").value = temp;
}
function validation() {
  var venueCount = countVenues();
  var isValid = true;
  var msg ="";
  if (venueCount == 0) {
	isValid = false;
	msg = "You must purchase/select at least one venue.  "
	for (var index = 0; index < 5; index++) {
		document.getElementById("venueTable").style.backgroundColor="#F99";
	}
  } else {
	for (var index = 0; index < 5; index++) {
		document.getElementById("venueTable").style.backgroundColor="WHITE";
	}
  }
  if ((purchaseType == "upgrade" || purchaseType == "venues") && !productKeyValid) {
	isValid = false;
	msg = msg + "A valid product key is required.  "
	document.purchase.productKey.style.backgroundColor="#F99";
  } else {
	document.purchase.productKey.style.backgroundColor="WHITE";
  }
  if(fieldValidates(document.purchase.BuyerFirstName) == false) {
    isValid = false;
  }    
  if(fieldValidates(document.purchase.BuyerLastName) == false) {
    isValid = false;
  }
  if(fieldValidates(document.purchase.BuyerAddrLn1) == false) {
    isValid = false;
  }

  var field = document.purchase.BuyerAddrLn2;
  field.value = Trim(field.value);
  cleanData(field);

  if(fieldValidates(document.purchase.CITY) == false) {
    isValid = false;
  }
  if(selectionValidates(document.purchase.STATE) == false) {
    isValid = false;
  }
  if(fieldValidates(document.purchase.ZIP) == false) {
    isValid = false;
  }
  if(emailValidates(document.purchase.EMAIL) == false) {
    isValid = false;
  }
  if(phoneValidates(document.purchase.PHONE) == false) {
    isValid = false;
  }
  if (document.purchase.shipCD.checked && !document.purchase.SameAsBuyer.checked) {
    if(fieldValidates(document.purchase.ShipFirstName) == false) {
      isValid = false;
    }   
    if(fieldValidates(document.purchase.ShipLastName) == false) {
      isValid = false;
    }
    if(fieldValidates(document.purchase.ShipAddrLn1) == false) {
      isValid = false;
    }

    field = document.purchase.ShipAddrLn2;
    field.value = Trim(field.value);
    cleanData(field);

    if(fieldValidates(document.purchase.CITYTOSHIP) == false) {
      isValid = false;
    }
    if(selectionValidates(document.purchase.STATETOSHIP) == false) {
      isValid = false;
    }
    if(fieldValidates(document.purchase.ZIPTOSHIP) == false) {
      isValid = false;
    }
  }
  if (isValid) {
	// set fields for pass thru in Verisign
	setFields();
    bar();	
	cccValidate();
    if (roxieProxy) {
		document.purchase.action = "support/databaseUpdate.asp";
	}
    return true;
  } else {
	msg = msg + "Please fill in or correct highlighted fields.";
    alert(msg);
    return false;
  }
}
function fieldValidates(field) {
  cleanData(field);
  field.value = Trim(field.value);
  if (!((Trim(field.value)).length > 0)) {
    field.style.backgroundColor = "#F99";
    return false;
  } else {
    field.style.backgroundColor = "WHITE";
  }
}
function selectionValidates(selectList) {
  if(selectList.selectedIndex < 1) {
    selectList.style.backgroundColor = "#F99";
    return false;
  } else {
    selectList.style.backgroundColor = "WHITE";
  }
}
function emailValidates(field) {
  cleanData(field);
  field.value = Trim(field.value);
  // var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
  var re = /^.+@.+\..{2,3}$/;
  if( !re.test(field.value) ){
    field.style.backgroundColor = "#F99";
    return false;
  } else {
    field.style.backgroundColor = "WHITE";
  }
}
function phoneValidates(field) {
   var phoneExt = field.value.replace(/[^\d]/g,"");
   var phoneValid = false;
   if (phoneExt.length == 10) {
   	  phoneValid = true;
      field.value = "("+phoneExt.substr(0,3)+")"+" "+phoneExt.substr(3,3)+"-"+phoneExt.substr(6);
   }
   if (!phoneValid) {
    field.style.backgroundColor = "#F99";
        return false;
   } else {
      field.style.backgroundColor = "WHITE";
       return true;
   }
}
function Trim(TRIM_VALUE){
  if(TRIM_VALUE.length < 1){
    return"";
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE==""){
    return "";
  } else {
    return TRIM_VALUE;
  }
}

function RTrim(VALUE){
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0){
    return"";
  }
  var iTemp = v_length -1;

  while(iTemp > -1){
    if(VALUE.charAt(iTemp) == w_space){
    } else {
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  }
  return strTemp;
}

function LTrim(VALUE){
  var w_space = String.fromCharCode(32);
  if(v_length < 1){
	
    return"";
  }
  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;

  while(iTemp < v_length){
    if(VALUE.charAt(iTemp) == w_space){
    } else {
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  }
  return strTemp;
}

function countVenues() {
	var venueCount = 0;
	venueString = "";
	for(var x=0; x < document.purchase.venue.length; x++) {
		if (document.purchase.venue[x].checked && document.purchase.venue[x].disabled==false) {
			venueCount++;
			venueString = venueString + document.purchase.venue[x].value + ",";
		}
	}
	// remove ending comma
	if (venueCount > 0) {
		venueString = venueString.substr(0,venueString.length-1);
	}
	return venueCount;
}
var roxieProxy;
function reCalc() {
	var total = 0;
	var price = 0;
	var tax = 0;
	var venue = 0;
	var cd = 0;
	var coupon = 0;
	var subTotal = 0;
	var venueCount = countVenues();
	if (purchaseType=="new") {
		price = 65;
		venue = (venueCount * 5);
	} else if (purchaseType=="upgrade") {
		price = 25;
		if (venueCount > 3) {
			venue = (venueCount-3) * 5;
		}
		
	} else {
		venue = venueCount * 5;
	}
	if (document.getElementById("shipCD").checked){
		cd = 10;
	}

	total = price + venue;

	if (couponType == 1) {
		coupon = couponValue;
	} else if (couponType == 2) {
		coupon = total * (couponValue/100);
	}
	coupon = parseFloat(CurrencyFormatted(coupon));
    if (coupon > total) {
        coupon = total;
    }
	total = total - coupon;
	subTotal = total;
	
	var index = document.getElementById("BuyerState").selectedIndex;
	if (index > -1 && document.getElementById("BuyerState")[index].value == "Texas") {
		tax = total * .0825;
	}
	total = total + tax + cd;
	if (total == 0) {
		roxieProxy = true;
		document.getElementById("uPush").value="0404EdM";
	} else {
		roxieProxy = false;
	}
    if (document.all) {	
		if (price == 0) {
			document.getElementById("productPrice").innerText ="";
			document.getElementById("productPriceDiv").style.display="none";
			document.getElementById("upgradePrice").innerText ="";
			document.getElementById("upgradePriceDiv").style.display="none";
		} else {
			if (purchaseType == "new") {
				document.getElementById("productPrice").innerText = "$"+CurrencyFormatted(price);
				document.getElementById("productPriceDiv").style.display="block";
				document.getElementById("upgradePriceDiv").style.display="none";
			} else {
				document.getElementById("upgradePrice").innerText = "$"+CurrencyFormatted(price);
				document.getElementById("upgradePriceDiv").style.display="block";
				document.getElementById("productPriceDiv").style.display="none";
			}
		}
		if (venue == 0) {
			document.getElementById("venuePrice").innerText ="";
			document.getElementById("venuePriceDiv").style.display="none";
		} else {
			document.getElementById("venuePrice").innerText = "$"+CurrencyFormatted(venue);
			document.getElementById("venuePriceDiv").style.display="block";
		}
		if (cd == 0) {
			document.getElementById("cdPrice").innerText ="";
			document.getElementById("cdPriceDiv").style.display="none";
		} else {
			document.getElementById("cdPrice").innerText = "$"+CurrencyFormatted(cd);
			document.getElementById("cdPriceDiv").style.display="block";
		}
		if (coupon == 0) {
			document.getElementById("couponPrice").innerText ="";
			document.getElementById("couponPriceDiv").style.display="none";
		} else {
			document.getElementById("couponPrice").innerText = "-$"+CurrencyFormatted(coupon);
			document.getElementById("couponPriceDiv").style.display="block";
		}
		if (tax == 0) {
			document.getElementById("taxPrice").innerText ="";
			document.getElementById("taxPriceDiv").style.display="none";
		} else {
			document.getElementById("taxPrice").innerText = "$"+CurrencyFormatted(tax);
			document.getElementById("taxPriceDiv").style.display="block";
		}
		document.getElementById("subTotalPrice").innerText = "$"+CurrencyFormatted(subTotal);
		document.getElementById("totalPrice").innerText = "$"+CurrencyFormatted(total);
	} else {
		if (price == 0) {
			document.getElementById("productPrice").textContent ="";
			document.getElementById("productPriceDiv").style.display="none";
			document.getElementById("upgradePrice").textContent ="";
			document.getElementById("upgradePriceDiv").style.display="none";
		} else {
			if (purchaseType == "new") {
				document.getElementById("productPrice").textContent = "$"+CurrencyFormatted(price);
				document.getElementById("productPriceDiv").style.display="block";
				document.getElementById("upgradePriceDiv").style.display="none";
			} else {
				document.getElementById("upgradePrice").textContent = "$"+CurrencyFormatted(price);
				document.getElementById("upgradePriceDiv").style.display="block";
				document.getElementById("productPriceDiv").style.display="none";
			}
		}
		if (venue == 0) {
			document.getElementById("venuePrice").textContent ="";
			document.getElementById("venuePriceDiv").style.display="none";
		} else {
			document.getElementById("venuePrice").textContent = "$"+CurrencyFormatted(venue);
			document.getElementById("venuePriceDiv").style.display="block";
		}
		if (cd == 0) {
			document.getElementById("cdPrice").textContent ="";
			document.getElementById("cdPriceDiv").style.display="none";
		} else {
			document.getElementById("cdPrice").textContent = "$"+CurrencyFormatted(cd);
			document.getElementById("cdPriceDiv").style.display="block";
		}
		if (coupon == 0) {
			document.getElementById("couponPrice").textContent ="";
			document.getElementById("couponPriceDiv").style.display="none";
		} else {
			document.getElementById("couponPrice").textContent = "-$"+CurrencyFormatted(coupon);
			document.getElementById("couponPriceDiv").style.display="block";
		}
		if (tax == 0) {
			document.getElementById("taxPrice").textContent ="";
			document.getElementById("taxPriceDiv").style.display="none";
		} else {
			document.getElementById("taxPrice").textContent = "$"+CurrencyFormatted(tax);
			document.getElementById("taxPriceDiv").style.display="block";
		}
		document.getElementById("subTotalPrice").textContent = "$"+CurrencyFormatted(subTotal);
		document.getElementById("totalPrice").textContent = "$"+CurrencyFormatted(total);
	}
	document.getElementById("shipAmount").value = CurrencyFormatted(cd);
	document.getElementById("tax").value = CurrencyFormatted(tax);
	document.getElementById("amount").value = CurrencyFormatted(total);
    fmtPrices = CurrencyFormatted(price)+","+CurrencyFormatted(venue)+","+CurrencyFormatted(cd)+","+CurrencyFormatted(coupon);
    fmtPrices = fmtPrices+","+CurrencyFormatted(tax)+","+CurrencyFormatted(subTotal)+","+CurrencyFormatted(total);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function prodKeyVerify(field)
{
  if (field.readOnly) {
	return;
  }
  enableAllVenues();
  prodKeyValid = false;
  var prodKey = Trim(field.value);
  if (prodKey.length==0)
  { 
    return;
  }
 var keyType = purchaseType;
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  spinStart("pk");
  var url="support/verifyProdKey.asp";
  url=url+"?prodkey="+prodKey+"&keyType="+keyType;
  xmlHttp.onreadystatechange=prodKeyResult;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function prodKeyResult() 
{ 
  if (xmlHttp.readyState==4)
  { 
    var isProdKeyValid;
    var venueBits;
    var responseText=eval('(' + xmlHttp.responseText + ')');
    isProdKeyValid = (responseText.prodData != undefined);

    if (isProdKeyValid) {
	  spinResult("pk", true);
      productKeyValid = true;
      document.purchase.productKey.readOnly = true;
      if (purchaseType == "venues") {
        venuesPurchased(responseText.prodData[0].venuebits);
      }
      prodKeyData(responseText.prodData[0]);
    } else {
      spinResult("pk", false);
      productKeyValid = false;
    }
  }
}
//00100010000000000010
function venuesPurchased(venueBits) {
    if (venueBits.charAt(2) == "1") {
        checkVenuesPurchased("USDAA");
    }
    if (venueBits.charAt(6) == "1") {
        checkVenuesPurchased("AKC");
    } 
    if (venueBits.charAt(10) == "1") {
        checkVenuesPurchased("NADAC");
    } 
    if (venueBits.charAt(14) == "1") {
        checkVenuesPurchased("ASCA");
    }
    if (venueBits.charAt(18) == "1") {
        checkVenuesPurchased("CPE");
    }
    reCalc();
}

function prodKeyData(prodData) {
	document.getElementById("BuyerFirstName").value = prodData.firstname;
	document.getElementById("BuyerLastName").value = prodData.lastname;
	document.getElementById("BuyerAddrLn1").value = prodData.address1;
	document.getElementById("BuyerAddrLn2").value = prodData.address2;
	document.getElementById("BuyerCity").value = prodData.city;
	var options = document.getElementById("BuyerState").options;
	var notFound = true;
	for (var x = 0; x < options.length && notFound; x++) {
		if (options[x].value == prodData.state) {
			options[x].selected = true;
			notFound = false;
		}
	}
	if (prodData.state == "Texas") {
		reCalc();
	}
	options = document.getElementById("BuyerCountry").options;
	notFound = true;
	for (var x = 0; x < options.length && notFound; x++) {
		if (options[x].value == prodData.country) {
			options[x].selected = true;
			notFound = false;
		}
	}
	document.getElementById("BuyerZip").value = prodData.postalcode;
	document.getElementById("BuyerPhone").value = prodData.phonenumber;
	document.getElementById("BuyerEmail").value = prodData.email;
}

function checkVenuesPurchased(venue) {
	var foundOne = false;
	for(var x=0; x < document.purchase.venue.length; x++) {
        if (document.purchase.venue[x].value == venue) {
            document.getElementById("venueTxt"+x).style.color = "blue";
            document.purchase.venue[x].checked = false;
            document.purchase.venue[x].disabled = true;
			foundOne = true;
            break;
        }
	}
	if (foundOne) {
		document.getElementById("ownedVenues").style.display = "inline";		
	}
}

function enableAllVenues() {
	document.getElementById("ownedVenues").style.display = "none";
	for(var x=0; x < document.purchase.venue.length; x++) {
		document.getElementById("venueTxt"+x).style.color = "black";
	//	document.purchase.venue[x].checked = false;
		document.purchase.venue[x].disabled = false;
	}
}

function couponVerify(field)
{
  if (field.readOnly) {
	return;
  }
  couponCodeValid = false;
  cleanData(field);
  var coupon = Trim(field.value).toUpperCase();
  field.value = coupon;
  if (coupon.length==0)
  { 
	couponType=0;
	couponValue=0;
	reCalc();
    return;
  }
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  spinStart("cc");
  var url="support/verifyCoupon.asp";
  url=url+"?couponCode="+coupon+"&type="+purchaseType;
  xmlHttp.onreadystatechange=couponResult;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function couponResult() 
{ 
  if (xmlHttp.readyState==4)
  { 
    var couponText=xmlHttp.responseText;
    var couponObject = eval('(' + couponText + ')');
    if (couponObject.couponResult.valid == "yes") {
      couponType=parseInt(couponObject.couponResult.couponType);
      couponValue=parseFloat(couponObject.couponResult.couponValue);
      couponCodeValid = true;
      document.purchase.couponCode.readOnly = true;
      spinResult("cc", true);
    } else {
      couponType=0;
      couponValue=0;
      couponCodeValid = false;
      spinResult("cc", false);
    }
  }
  reCalc();
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function keyValidate(field) {
	var fldVal = field.value;
	var workVal = "";

	for(i=0; i<fldVal.length; i++) {
		var nom = fldVal.charAt(i);
		if(nom.match(/[0-9a-zA-Z]/)) {
			workVal = workVal + nom;
		}
		workVal = keyChkSpacing(workVal);
	}
	field.value = workVal.toUpperCase();
}


function keyChkSpacing(fldVal) {
	// xxxx-xxxx-xxxx-xxxx  upgrade
	// xxxxx-xxxxx-xxxxx-xxxxx venue
	var len1 = 4;
	var len2 = 9;
	var len3 = 14;
	var cutLen = 20;
	if (purchaseType == "venues") {
		len1 = 5;
		len2 = 11;
		len3 = 17;
		cutLen = 24;
	}

	if((fldVal.length == len1) || (fldVal.length == len2) || (fldVal.length == len3)){
		fldVal = fldVal + "-"
	}
	if(fldVal.length >= cutLen) {
		fldVal = fldVal.substring(0,fldVal.length-1);
	}
	return fldVal;
}

function cleanData(field) {
	var pattern = /[\'\"]/g;
	field.value = field.value.replace(pattern,"");
}

function spinReset(prefix) {
    document.getElementById(prefix+"Normal").style.display="inline";
    document.getElementById(prefix+"Spin").style.display="none";
    document.getElementById(prefix+"Valid").style.display="none";
    document.getElementById(prefix+"Invalid").style.display="none";
}

function spinStart(prefix) {
    document.getElementById(prefix+"Normal").style.display="none";
    document.getElementById(prefix+"Spin").style.display="inline";
    document.getElementById(prefix+"Valid").style.display="none";
    document.getElementById(prefix+"Invalid").style.display="none";
}

function spinResult(prefix, verified) {
	document.getElementById(prefix+"Normal").style.display="none";
	document.getElementById(prefix+"Spin").style.display="none";
	if (verified) {
		document.getElementById(prefix+"Valid").style.display="inline";
		document.getElementById(prefix+"Invalid").style.display="none";
	} else {
		document.getElementById(prefix+"Valid").style.display="none";
		document.getElementById(prefix+"Invalid").style.display="inline";
	}
}

