
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
var CardType = document.getElementById("CardType").value;

if(CardType == "LASER")
	{
	return true;
	}

// 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){
  // alert("Not a Number");
  // 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
  }  // 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("This is NOT a valid Credit Card Number!");
	}
  return bResult; // Return the results
}




function showCVN() 
{                              
	pageurl = "https://epage.payandshop.com/merchants/cvn.htm";                              
	window.open(pageurl, "CVN", "resizable=1,menubar=no,location=no,directories=no,scrollbars=no,status=no,height=350,width=400");
}
 


function ChangeCurrency()
{
  var Currency_id		=	document.orderform.currency.value;
	
	for (i = 0; i <= 30; i++)
	{
		
		currency_price_name 			= 	window['currency_prices_'+ i +'_'+Currency_id];
		if(currency_price_name)
		{
			currency_symbol			=	window['currency_symbol_'+ Currency_id];
			subscriptions[i] 		= 	currency_price_name;
			currency_placeholder_name	=	'price_placeholder_'+i;
			formatted_price			=	currency_symbol +' '+ currency_price_name;

			SetLayerText(currency_placeholder_name, formatted_price);
		}
	}
HandleChange();
}


function CheckForm(){

  var Password1			=	document.orderform.password.value;
  var Password2			=	document.orderform.confirm_password.value; 
  var Terms			=	document.orderform.terms.checked;
  var Email			=	document.orderform.email.value;
  var Password_length		=	Password1.length;


  var myOption 			= 	-1;


	AtPos 			= 	Email.indexOf("@")
	StopPos 		= 	Email.lastIndexOf(".")




	if (Email == "") 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (AtPos == -1 || StopPos == -1) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (StopPos < AtPos) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (StopPos - AtPos == 1) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	} 

	if(!Terms) 
	{
		alert('In order to register it is necessary that you read and agree to our Terms and Conditions.\nOnce in agreement with our terms, tick the Terms and Conditions checkbox, \nThank You.');
		return false;
	}
  
	if(Password_length < 6) 
	{
		alert('Password length must be at least 6 Characters in Length.\nPlease adjust, Thank You.');
		return false;
	}

	if(Password1 !== Password2)
	{
		alert('Password entered does not match again the Confirmed Password entered.\nPlease adjust, Thank You.');
		return false;
	}
}


function three_actions(){
  var a1=document.getElementsByName("char_action4");
  var a2=document.getElementsByName("char_action5");
  a1[0].disabled=true;
  a2[0].disabled=true;
}
function five_actions(){
  var a1=document.getElementsByName("char_action4");
  var a2=document.getElementsByName("char_action5");
  a1[0].disabled=false;
  a2[0].disabled=false;
}

function two_d(){
  var s1=document.getElementsByName("characterstyle");
  s1[0].disabled=true;
}
function three_d(){
  var s1=document.getElementsByName("characterstyle");
  s1[0].disabled=false;
}


function HandleChange(subid) 
{



	if((subid == null)&&(document.orderform.subscription_id.value != null))
		{
	
		subid  = document.orderform.subscription_id.value; 
		}



	if(subid != null){


		document.orderform.subscription_id.value = subid;

	// Set default values

			var vat_rate			=	'21';
			var Ireland			=	'372'
			var EU				=	'826'

			var vat_total			=	0;
			var subscription_name		=	0;
			var total_cost			=	0;


			subscription_name 		= 	subscriptions[subid];
		if(!subscription_name) 
			{subscription_name		=	'0.00';}
		

	// VAT Logic is as follows:
	// If country is Ireland, then VAT is always calculated
	// If region is EU, and decent value entered into the vat field, then no VAT calculated otherwise VAT charged.
	// All other regions is VAT free.

		var region_value 	= 	document.orderform.location.value;

		var vat_value 		= 	document.orderform.vat.value;

	// Get string length for Vat Value... let's say vat number should be at least alphacharacters.

		var vat_length		=	vat_value.length;

	// Vat calculation is as follows.

		var Currency_id		=	document.orderform.currency.value;
		var currency_symbol	=	window['currency_symbol_'+ Currency_id];


		if(region_value == '372')
			{
			vat_total 	= (subscription_name * vat_rate) / 100;

			}
		else if ((region_value == '826')&&(vat_length <= 7))
			{
			vat_total 	= (subscription_name * vat_rate) / 100;

			}
		else
			{
			vat_total 	= 0;

			}

		var total_cost 		=	((subscription_name * 1)+ vat_total);	
		total_cost		= 	total_cost.toFixed(2);


		 vat_total	= 	vat_total.toFixed(2);

		formatted_subscription_name		=	currency_symbol +' '+ subscription_name;
		formatted_vat_total			=	currency_symbol +' '+ vat_total;
		formatted_total_cost			=	currency_symbol +' '+ total_cost;

		SetLayerText('exvat_Label', formatted_subscription_name);
		SetLayerText('vat_Label', formatted_vat_total);
		SetLayerText('incvat_Label', formatted_total_cost);


	}

}



function HandlePurchaseChange(subid) 
{



	if((subid == null)&&(document.orderform.subscription_id.value != null))
		{
	
		subid  = document.orderform.subscription_id.value; 
		}



	if(subid != null){


		document.orderform.subscription_id.value = subid;

	// Set default values

			var vat_rate			=	'21';
			var Ireland			=	'372'
			var EU				=	'826'

			var vat_total			=	0;
			var subscription_name		=	0;
			var total_cost			=	0;


			subscription_name 		= 	subscriptions[subid];
		if(!subscription_name) 
			{subscription_name		=	'0.00';}
	
	
	// VAT Logic is as follows:
	// If country is Ireland, then VAT is always calculated
	// If region is EU, and decent value entered into the vat field, then no VAT calculated otherwise VAT charged.
	// All other regions is VAT free.

		var region_value 	= 	document.orderform.location.value;

		var vat_value 		= 	document.orderform.vat.value;

	// Get string length for Vat Value... let's say vat number should be at least alphacharacters.

		var vat_length		=	vat_value.length;


		if(region_value == '372')
			{
			vat_total 	= (subscription_name * vat_rate) / 100;

			}
		else if ((region_value == '826')&&(vat_length <= 7))
			{
			vat_total 	= (subscription_name * vat_rate) / 100;

			}
		else
			{
			vat_total 	= 0;

			}

		var total_cost 		=	((subscription_name * 1)+ vat_total);	
		total_cost		= 	total_cost.toFixed(2);


		 vat_total	= 	vat_total.toFixed(2);

		var currency_symbol			=	"$";

		formatted_subscription_name		=	currency_symbol +' '+ subscription_name;
		formatted_vat_total			=	currency_symbol +' '+ vat_total;
		formatted_total_cost			=	currency_symbol +' '+ total_cost;


		SetLayerText('exvat_Label', formatted_subscription_name);
		SetLayerText('vat_Label', formatted_vat_total);
		SetLayerText('incvat_Label', formatted_total_cost);


	}

}


function CheckPurchaseForm(){

  var Terms			=	document.orderform.terms.checked;
  var Email			=	document.orderform.email.value;


  var myOption 			= 	-1;


	AtPos 			= 	Email.indexOf("@")
	StopPos 		= 	Email.lastIndexOf(".")



	if (Email == "") 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (AtPos == -1 || StopPos == -1) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (StopPos < AtPos) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	}

	if (StopPos - AtPos == 1) 
	{
		alert('Not a valid email address entered.\nPlease adjust. Thank You.');
		return false;
	} 

	if(!Terms) 
	{
		alert('In order to register it is necessary that you read and agree to our Terms and Conditions.\nOnce in agreement with our terms, tick the Terms and Conditions checkbox, \nThank You.');
		return false;
	}
}



function SetLayerText (sLayerId, sPrice)
{
    var sStatement;
    if (document.all)
	  sStatement = "document.all['" + sLayerId + "'].innerHTML = '" + sPrice + "';";
    else (document.getElementById)
	  sStatement = "document.getElementById('" + sLayerId + "').innerHTML = '" + sPrice + "';";
	    eval (sStatement);
		  sStatement = "document.getElementById('" + sLayerId + "').innerHTML = '" + sPrice + "';";
	    eval (sStatement);
}

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
