function opWin(w,h,url,nam) {
 specs = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=" + w + ",height=" + h
	window.open(url,nam,specs)
}

function opWinC(imgname){
  var jimwin= window.open("","newwin","width=420, height=360");
  jimwin.document.write("<center><img src=images/"+imgname+"><br><img src=images/px_trans.gif width=1 height=9 border=0><br>");
  jimwin.document.write("<font face=Arial, Helvetica, sans-serif size=1><a href='javascript:self.close();'>Close window </a></font></center>");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_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 MM_findObj(n, d) { //v4.0
  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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username of Email address doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name of Email address doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("The Email address must end in a three-letter domain, four-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This Email address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function cardholder_Validator(theForm)
{	
  if (theForm.IntroducedByID.value != "")
  {
    if (!IsNumber(theForm.IntroducedByID.value)){
    alert("Please enter a valid ID for the \"Their ID Number\" field.");
    theForm.IntroducedByID.focus();
    return (false);
    }
    else{
			if (parseInt(theForm.IntroducedByID.value,10)<100000){
				alert("Please enter a valid ID for the \"Their ID Number\" field.");
				theForm.IntroducedByID.focus();
				return (false);
			}
    }
  }
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }
  if (theForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }
  if (theForm.OfficePhone.value == "")
  {
    alert("Please enter a value for the \"Office Phone\" field.");
    theForm.OfficePhone.focus();
    return (false);
  }
  if (theForm.HomePhone.value == "")
  {
    alert("Please enter a value for the \"Home Phone\" field.");
    theForm.HomePhone.focus();
    return (false);
  }
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (!emailCheck(theForm.Email.value))
  {
	theForm.Email.focus();
	return (false);
  }  
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.Password2.value == "")
  {
    alert("Please enter a value for the \"Re-type Password\" field.");
    theForm.Password2.focus();
    return (false);
  }
  if (theForm.Password.value != theForm.Password2.value )
  {
    alert("Two password don't match, please input again.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.CreditCardType.selectedIndex < 0)
  {
    alert("Please select one of the \"Credit Card Type\" options.");
    theForm.CreditCardType.focus();
    return (false);
  }

  if (theForm.CreditCardType.selectedIndex == 0)
  {
    alert("The first \"Credit Card Type\" option is not a valid selection.  Please choose one of the other options.");
    theForm.CreditCardType.focus();
    return (false);
  }
  if (theForm.CreditCardExpiryMonth.selectedIndex < 0)
  {
    alert("Please select one of the \"Credit Card Expiry Month\" options.");
    theForm.CreditCardExpiryMonth.focus();
    return (false);
  }

  if (theForm.CreditCardExpiryMonth.selectedIndex == 0)
  {
    alert("The first \"Credit Card Expiry Month\" option is not a valid selection.  Please choose one of the other options.");
    theForm.CreditCardExpiryMonth.focus();
    return (false);
  }

  if (theForm.CreditCardExpiryYear.selectedIndex < 0)
  {
    alert("Please select one of the \"Credit Card Expiry Year\" options.");
    theForm.CreditCardExpiryYear.focus();
    return (false);
  }

  if (theForm.CreditCardExpiryYear.selectedIndex == 0)
  {
    alert("The first \"Credit Card Expiry Year\" option is not a valid selection.  Please choose one of the other options.");
    theForm.CreditCardExpiryYear.focus();
    return (false);
  }

  if (theForm.CreditCardNumber.value == "")
  {
    alert("Please enter a value for the \"Credit Card Number\" field.");
    theForm.CreditCardNumber.focus();
    return (false);
  }

  if (theForm.CreditCardNumber.value.length < 12)
  {
    alert("Please enter at least 12 characters in the \"Credit Card Number\" field.");
    theForm.CreditCardNumber.focus();
    return (false);
  }

  if (theForm.CreditCardNumber.value.length > 16)
  {
    alert("Please enter at most 16 characters in the \"Credit Card Number\" field.");
    theForm.CreditCardNumber.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.CreditCardNumber.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Credit Card Number\" field.");
    theForm.CreditCardNumber.focus();
    return (false);
  }

  if (theForm.BillingAddress.value == "")
  {
    alert("Please enter a value for the \"Billing Address\" field.");
    theForm.BillingAddress.focus();
    return (false);
  }
  if (theForm.BillingCity.value == "")
  {
    alert("Please enter a value for the \"Billing City\" field.");
    theForm.BillingCity.focus();
    return (false);
  }
  if (theForm.BillingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Billing State\" options.");
    theForm.BillingState.focus();
    return (false);
  }

  if (theForm.BillingState.selectedIndex == 0)
  {
    alert("The first \"Billing State\" option is not a valid selection.  Please choose one of the other options.");
    theForm.BillingState.focus();
    return (false);
  }
  
  if (theForm.BillingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Billing Postal Code\" field.");
    theForm.BillingPostalCode.focus();
    return (false);
  }
  if (theForm.ShippingAddress.value == "")
  {
    alert("Please enter a value for the \"Shipping Address\" field.");
    theForm.ShippingAddress.focus();
    return (false);
  }
  if (theForm.ShippingCity.value == "")
  {
    alert("Please enter a value for the \"Shipping City\" field.");
    theForm.ShippingCity.focus();
    return (false);
  }
  if (theForm.ShippingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Shipping State\" options.");
    theForm.ShippingState.focus();
    return (false);
  }

  if (theForm.ShippingState.selectedIndex == 0)
  {
    alert("The first \"Shipping State\" option is not a valid selection.  Please choose one of the other options.");
    theForm.ShippingState.focus();
    return (false);
  }
  
  if (theForm.ShippingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Shipping Postal Code\" field.");
    theForm.ShippingPostalCode.focus();
    return (false);
  }
  return (true);
}

function IsNumber(x){
return parseInt(x,10)==x;
}




function merchant_Validator(theForm)
{	
  if (theForm.CompanyName.value == "")
  {
    alert("Please enter a value for the \"Company Name\" field.");
    theForm.CompanyName.focus();
    return (false);
  }
 if (theForm.CID.selectedIndex < 0)
  {
    alert("Please select one of the \"Category\" options.");
    theForm.CID.focus();
    return (false);
  }
 if (theForm.CID.selectedIndex == 0)
  {
    alert("Please select one of the \"Category\" options.");
    theForm.CID.focus();
    return (false);
  }
  if (theForm.TradeName.value == "")
  {
    alert("Please enter a value for the \"Trade Name\" field.");
    theForm.TradeName.focus();
    return (false);
  }
if (theForm.NumberOfLocations.value == "")
  {
    alert("Please enter a value for the \"Number of Locations\" field.");
    theForm.NumberOfLocations.focus();
    return (false);
  }
  else{
    if (!IsNumber(theForm.NumberOfLocations.value)){
    alert("Please enter a value for the \"Number of Locations\" field.");
    theForm.NumberOfLocations.focus();
    return (false);
    }
  }
/*  
  if (theForm.TaxID.value == "")
  {
    alert("Please enter a value for the \"Tax ID\" field.");
    theForm.TaxID.focus();
    return (false);
  }
*/  
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }
  if (theForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }
  if (theForm.BillingAddress.value == "")
  {
    alert("Please enter a value for the \"Address\" field.");
    theForm.BillingAddress.focus();
    return (false);
  }
  if (theForm.BillingCity.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.BillingCity.focus();
    return (false);
  }
  if (theForm.BillingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Province\" options.");
    theForm.BillingState.focus();
    return (false);
  }

  if (theForm.BillingState.selectedIndex == 0)
  {
    alert("The first \"Province\" option is not a valid selection.  Please choose one of the other options.");
    theForm.BillingState.focus();
    return (false);
  }
  
  if (theForm.BillingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Postal Code\" field.");
    theForm.BillingPostalCode.focus();
    return (false);
  }
  if (theForm.OfficePhone.value == "")
  {
    alert("Please enter a value for the \"Office Phone\" field.");
    theForm.OfficePhone.focus();
    return (false);
  }
  if (theForm.HomePhone.value == "")
  {
    alert("Please enter a value for the \"Home Phone\" field.");
    theForm.HomePhone.focus();
    return (false);
  }
  if (theForm.MobilePhone.value == "")
  {
    alert("Please enter a value for the \"Mobile Phone\" field.");
    theForm.MobilePhone.focus();
    return (false);
  }
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (!emailCheck(theForm.Email.value))
  {
	theForm.Email.focus();
	return (false);
  }  
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.Password2.value == "")
  {
    alert("Please enter a value for the \"Re-type Password\" field.");
    theForm.Password2.focus();
    return (false);
  }
  if (theForm.Password.value != theForm.Password2.value )
  {
    alert("Two password don't match, please input again.");
    theForm.Password.focus();
    return (false);
  }
  if (!theForm.Agree.checked)
  {
    alert("Please confirm you have read and agree terms and conditions.");
    theForm.Agree.focus();
    return (false);
  }
  return (true);
}

function a_times_b(form) {
	/*
	CardsNum=eval(form.CardsNum.value)
	PricePerCard=eval(form.PricePerCard.value)
	TotalCost=CardsNum*PricePerCard
	form.TotalCost.value=TotalCost
	*/
	form.CardsNum.value=OnlyNumericNoDot(form.CardsNum.value);
	form.PricePerCard.value=OnlyNumeric(form.PricePerCard.value);
	form.TotalCost.value=FormatNumber(Math.round(parseFloat(form.CardsNum.value)*parseFloat(form.PricePerCard.value)*100)/100,2,".");
	
}
/*------------------------------------------------------------------------*/
function bulkorder_Validator(theForm)
{	
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }
  if (theForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }
  if (theForm.MemberID.value== ""){
    alert("Please enter a valid ID for the \"Card ID Number\" field.");
    theForm.MemberID.focus();
    return (false);
  }
  else{
    if (!IsNumber(theForm.MemberID.value)){
    alert("Please enter a valid ID for the \"Card ID Number\" field.");
    theForm.MemberID.focus();
    return (false);
    }
    else{
			if (parseInt(theForm.MemberID.value,10)<100000){
				alert("Please enter a valid ID for the \"Card ID Number\" field.");
				theForm.MemberID.focus();
				return (false);
			}
    }
  }

  if (theForm.CardsNum.value == ""){
    alert("Please enter a valid value for the \"# of cards\" field.");
    theForm.CardsNum.focus();
    return (false);
  }
  else{
    if (!IsNumber(theForm.CardsNum.value)){
    alert("Please enter a valid value for the \"# of cards\" field.");
    theForm.CardsNum.focus();
    return (false);
    }
    else{
			if (parseInt(theForm.CardsNum.value,10)<=0){
				alert("Please enter a valid value for the \"# of cards\" field.");
				theForm.CardsNum.focus();
				return (false);
			}
    }
  }

  if (theForm.PricePerCard.value == ""){
    alert("Please enter a valid value for the \"Price per card\" field.");
    theForm.PricePerCard.focus();
    return (false);
  }
  else{
    if (!IsNumeric(theForm.PricePerCard.value)){
    alert("Please enter a valid value for the \"Price per card\" field.");
    theForm.PricePerCard.focus();
    return (false);
    }
    else{
			if (parseFloat(theForm.PricePerCard.value,10)<=0){
				alert("Please enter a valid value for the \"Price per card\" field.");
				theForm.PricePerCard.focus();
				return (false);
			}
    }
  }
	
  if (theForm.TotalCost.value == ""){
    alert("The total price is invalid.");
    theForm.TotalCost.focus();
    return (false);
  }
  else{
    if (!IsNumeric(theForm.TotalCost.value)){
    alert("The total price is invalid.");
    theForm.TotalCost.focus();
    return (false);
    }
    else{
			if (parseFloat(theForm.TotalCost.value,10)<=0){
				alert("The total price is invalid.");
				theForm.TotalCost.focus();
				return (false);
			}
    }
  }
  if (theForm.ChoosePayment[2].checked){
		if (theForm.PurchaseOrderNumber.value == "")
		{
		  alert("Please enter a value for the \"Purchase Order Number\" field.");
		  theForm.PurchaseOrderNumber.focus();
		  return (false);
		}
  }
	if (theForm.ChoosePayment[0].checked){
		if (theForm.CreditCardNumber.value == "")
		{
		  alert("Please enter a value for the \"Credit Card Number\" field.");
		  theForm.CreditCardNumber.focus();
		  return (false);
		}

		if (theForm.CreditCardNumber.value.length < 12)
		{
		  alert("Please enter at least 12 characters in the \"Credit Card Number\" field.");
		  theForm.CreditCardNumber.focus();
		  return (false);
		}

		if (theForm.CreditCardNumber.value.length > 16)
		{
		  alert("Please enter at most 16 characters in the \"Credit Card Number\" field.");
		  theForm.CreditCardNumber.focus();
		  return (false);
		}

		var checkOK = "0123456789-";
		var checkStr = theForm.CreditCardNumber.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}
		if (!allValid)
		{
		  alert("Please enter only digit characters in the \"Credit Card Number\" field.");
		  theForm.CreditCardNumber.focus();
		  return (false);
		}
		if (theForm.CreditCardName.value == "")
		{
		  alert("Please enter a value for the \"Name of Credit Card Holder\" field.");
		  theForm.CreditCardName.focus();
		  return (false);
		}
		if (theForm.CreditCardType.selectedIndex < 0)
		{
		  alert("Please select one of the \"Credit Card Type\" options.");
		  theForm.CreditCardType.focus();
		  return (false);
		}

		if (theForm.CreditCardType.selectedIndex == 0)
		{
		  alert("The first \"Credit Card Type\" option is not a valid selection.  Please choose one of the other options.");
		  theForm.CreditCardType.focus();
		  return (false);
		}
		if (theForm.CreditCardExpiryMonth.selectedIndex < 0)
		{
		  alert("Please select one of the \"Credit Card Expiry Month\" options.");
		  theForm.CreditCardExpiryMonth.focus();
		  return (false);
		}

		if (theForm.CreditCardExpiryMonth.selectedIndex == 0)
		{
		  alert("The first \"Credit Card Expiry Month\" option is not a valid selection.  Please choose one of the other options.");
		  theForm.CreditCardExpiryMonth.focus();
		  return (false);
		}

		if (theForm.CreditCardExpiryYear.selectedIndex < 0)
		{
		  alert("Please select one of the \"Credit Card Expiry Year\" options.");
		  theForm.CreditCardExpiryYear.focus();
		  return (false);
		}

		if (theForm.CreditCardExpiryYear.selectedIndex == 0)
		{
		  alert("The first \"Credit Card Expiry Year\" option is not a valid selection.  Please choose one of the other options.");
		  theForm.CreditCardExpiryYear.focus();
		  return (false);
		}

		if (theForm.BillingAddress.value == "")
		{
		  alert("Please enter a value for the \"Billing Address\" field.");
		  theForm.BillingAddress.focus();
		  return (false);
		}
		if (theForm.BillingCity.value == "")
		{
		  alert("Please enter a value for the \"Billing City\" field.");
		  theForm.BillingCity.focus();
		  return (false);
		}
		if (theForm.BillingState.selectedIndex < 0)
		{
		  alert("Please select one of the \"Billing State\" options.");
		  theForm.BillingState.focus();
		  return (false);
		}

		if (theForm.BillingState.selectedIndex == 0)
		{
		  alert("The first \"Billing State\" option is not a valid selection.  Please choose one of the other options.");
		  theForm.BillingState.focus();
		  return (false);
		}
  
		if (theForm.BillingPostalCode.value == "")
		{
		  alert("Please enter a value for the \"Billing Postal Code\" field.");
		  theForm.BillingPostalCode.focus();
		  return (false);
		}
	}	
  return (true);
}

function popupwin_hw(TotalCost){
	if (TotalCost == ""){
	  alert("The total price is invalid.");
	  return (false);
	}
	else{
	  if (!IsNumeric(TotalCost)){
	  alert("The total price is invalid.");
	  return (false);
	  }
	  else{
			if (parseFloat(TotalCost,10)<=0){
				alert("The total price is invalid.");
				return (false);
			}
	  }
	}
	var newWin=window.open('https://www.hyperwallet.com/payNow.do?PID=2-13300&amt=$'+TotalCost+'&cur=CAD&desc=&ship=$0.00&tax=$0.00&next=','hw_popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=780,height=480')
	//newWin.moveTo(0,0);
}

function OnlyNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   var StrText="";

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      else
		{
		StrText=StrText+Char;
		}   
      }
   //return IsNumber;
   return StrText;
}

function OnlyNumericNoDot(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   var StrText="";

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      else
		{
		StrText=StrText+Char;
		}   
      }
   //return IsNumber;
   return StrText;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function FormatNumber(Number,Decimals,Separator)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // March 21, 1998
 // Web site: http://www.aptools.com/
 //
 // November 24, 1998 -- Error which allowed a null value
 // to remain null fixed. Now forces value to 0.
 //
 // October 28, 2001 -- Modified to provide leading 0 for fractional number
 // less than 1.
 //
 // This function accepts a number to format and number
 // specifying the number of decimal places to format to. May
 // optionally use a separator other than '.' if specified.
 //
 // If no decimals are specified, the function defaults to
 // two decimal places. If no number is passed, the function
 // defaults to 0. Decimal separator defaults to '.' .
 //
 // If the number passed is too large to format as a decimal
 // number (e.g.: 1.23e+25), or if the conversion process
 // results in such a number, the original number is returned
 // unchanged.
 // **********************************************************
 Number += ""          // Force argument to string.
 Decimals += ""        // Force argument to string.
 Separator += ""       // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(Number.length == 0)
  Number = "0"
 var OriginalNumber = Number  // Save for number too large.
 var Sign = 1
 var Pad = ""
 var Count = 0
 // If no number passed, force number to 0.
 if(parseFloat(Number)){
  Number = parseFloat(Number)} else {
  Number = 0}
 // If no decimals passed, default decimals to 2.
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(Number < 0)
 {
  Sign = -1         // Remember sign of Number.
  Number *= Sign    // Force absolute value of Number.
 }
 if(Decimals < 0)
  Decimals *= -1    // Force absolute value of Decimals.
 // Next, convert number to rounded integer and force to string value.
 // (Number contains 1 extra digit used to force rounding)
 Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
 if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
  return(OriginalNumber) // Number too large to format as specified.
 // If length of Number is less than number of decimals requested +1,
 // pad with zeros to requested length.
 if(Number.length < Decimals +1) // Construct pad string.
 {
  for(Count = Number.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 Number = Pad + Number // Pad number as needed.
 if(Decimals == 0){
  // Drop extra digit -- Decimal portion is formatted.
  Number = Number.substring(0, Number.length -1)} else {
  // Or, format number with decimal point and drop extra decimal digit.
 Number = Number.substring(0,Number.length - Decimals -1) +
          Separator +
          Number.substring(Number.length - Decimals -1,
          Number.length -1)}
 if((Number == "") || (parseFloat(Number) < 1))
  Number="0"+Number // Force leading 0 for |Number| less than 1.
 if(Sign == -1)
  Number = "-" + Number  // Set sign of number.
 return(Number)
}

function JSTotal(){
document.dataform.CardsNum.value=OnlyNumericNoDot(document.dataform.CardsNum.value);
document.dataform.PricePerCard.value=OnlyNumeric(document.dataform.PricePerCard.value);
document.dataform.TotalCost.value=FormatNumber(Math.round(parseFloat(document.dataform.CardsNum.value)*parseFloat(document.dataform.PricePerCard.value)*100)/100,2,".");
}

/*----------------------------------------*/
function Login_Validator(theForm)
{	
  if (theForm.LoginID.value == "")
  {
    alert("Please enter a value for the \"Login ID\" field.");
    theForm.LoginID.focus();
    return (false);
  }
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  return (true);
}

function cardholderProfile_Validator(theForm)
{	
 
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }
  if (theForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }
  if (theForm.HomePhone.value == "")
  {
    alert("Please enter a value for the \"Home Phone\" field.");
    theForm.HomePhone.focus();
    return (false);
  }

  if (theForm.OfficePhone.value == "")
  {
    alert("Please enter a value for the \"Office Phone\" field.");
    theForm.OfficePhone.focus();
    return (false);
  }
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (!emailCheck(theForm.Email.value))
  {
	theForm.Email.focus();
	return (false);
  }  
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.Password2.value == "")
  {
    alert("Please enter a value for the \"Re-type Password\" field.");
    theForm.Password2.focus();
    return (false);
  }
  if (theForm.Password.value != theForm.Password2.value )
  {
    alert("Two password don't match, please input again.");
    theForm.Password.focus();
    return (false);
  }

  if (theForm.BillingAddress.value == "")
  {
    alert("Please enter a value for the \"Billing Address\" field.");
    theForm.BillingAddress.focus();
    return (false);
  }
  if (theForm.BillingCity.value == "")
  {
    alert("Please enter a value for the \"Billing City\" field.");
    theForm.BillingCity.focus();
    return (false);
  }
  if (theForm.BillingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Billing State\" options.");
    theForm.BillingState.focus();
    return (false);
  }

  if (theForm.BillingState.selectedIndex == 0)
  {
    alert("The first \"Billing State\" option is not a valid selection.  Please choose one of the other options.");
    theForm.BillingState.focus();
    return (false);
  }
  
  if (theForm.BillingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Billing Postal Code\" field.");
    theForm.BillingPostalCode.focus();
    return (false);
  }
  if (theForm.ShippingAddress.value == "")
  {
    alert("Please enter a value for the \"Shipping Address\" field.");
    theForm.ShippingAddress.focus();
    return (false);
  }
  if (theForm.ShippingCity.value == "")
  {
    alert("Please enter a value for the \"Shipping City\" field.");
    theForm.ShippingCity.focus();
    return (false);
  }
  if (theForm.ShippingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Shipping State\" options.");
    theForm.ShippingState.focus();
    return (false);
  }

  if (theForm.ShippingState.selectedIndex == 0)
  {
    alert("The first \"Shipping State\" option is not a valid selection.  Please choose one of the other options.");
    theForm.ShippingState.focus();
    return (false);
  }
  
  if (theForm.ShippingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Shipping Postal Code\" field.");
    theForm.ShippingPostalCode.focus();
    return (false);
  }
  return (true);
}




function merchantProfile_Validator(theForm)
{	
  if (theForm.CompanyName.value == "")
  {
    alert("Please enter a value for the \"Company Name\" field.");
    theForm.CompanyName.focus();
    return (false);
  }
 if (theForm.CID.selectedIndex < 0)
  {
    alert("Please select one of the \"Category\" options.");
    theForm.CID.focus();
    return (false);
  }
 if (theForm.CID.selectedIndex == 0)
  {
    alert("Please select one of the \"Category\" options.");
    theForm.CID.focus();
    return (false);
  }
  if (theForm.TradeName.value == "")
  {
    alert("Please enter a value for the \"Trade Name\" field.");
    theForm.TradeName.focus();
    return (false);
  }
if (theForm.NumberOfLocations.value == "")
  {
    alert("Please enter a value for the \"Number of Locations\" field.");
    theForm.NumberOfLocations.focus();
    return (false);
  }
  else{
    if (!IsNumber(theForm.NumberOfLocations.value)){
    alert("Please enter a value for the \"Number of Locations\" field.");
    theForm.NumberOfLocations.focus();
    return (false);
    }
  }
 
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }
  if (theForm.LastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }
  if (theForm.BillingAddress.value == "")
  {
    alert("Please enter a value for the \"Address\" field.");
    theForm.BillingAddress.focus();
    return (false);
  }
  if (theForm.BillingCity.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.BillingCity.focus();
    return (false);
  }
  if (theForm.BillingState.selectedIndex < 0)
  {
    alert("Please select one of the \"Province\" options.");
    theForm.BillingState.focus();
    return (false);
  }

  if (theForm.BillingState.selectedIndex == 0)
  {
    alert("The first \"Province\" option is not a valid selection.  Please choose one of the other options.");
    theForm.BillingState.focus();
    return (false);
  }
  
  if (theForm.BillingPostalCode.value == "")
  {
    alert("Please enter a value for the \"Postal Code\" field.");
    theForm.BillingPostalCode.focus();
    return (false);
  }
  if (theForm.OfficePhone.value == "")
  {
    alert("Please enter a value for the \"Office Phone\" field.");
    theForm.OfficePhone.focus();
    return (false);
  }
  if (theForm.HomePhone.value == "")
  {
    alert("Please enter a value for the \"Home Phone\" field.");
    theForm.HomePhone.focus();
    return (false);
  }
  if (theForm.MobilePhone.value == "")
  {
    alert("Please enter a value for the \"Mobile Phone\" field.");
    theForm.MobilePhone.focus();
    return (false);
  }
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (!emailCheck(theForm.Email.value))
  {
	theForm.Email.focus();
	return (false);
  }  
  if (theForm.Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.Password2.value == "")
  {
    alert("Please enter a value for the \"Re-type Password\" field.");
    theForm.Password2.focus();
    return (false);
  }
  if (theForm.Password.value != theForm.Password2.value )
  {
    alert("Two password don't match, please input again.");
    theForm.Password.focus();
    return (false);
  }
  return (true);
}

function cardactive_Validator(theForm)
{	
  if (theForm.CardNumber.value == "")
  {
    alert("Please enter a correct value for the \"Card Number\" field.");
    theForm.CardNumber.focus();
    return (false);
  }
  if (!IsNumber(theForm.CardNumber.value))
  {
    alert("Please enter a correct value for the \"Card Number\" field.");
    theForm.CardNumber.focus();
    return (false);
  }
  if (theForm.PINNumber.value == "")
  {
    alert("Please enter a value for the \" PIN Number\" field.");
    theForm.PINNumber.focus();
    return (false);
  }
  return (true);
}

