					
					function CheckEnteredField(field, Msg)
					{ 
						var allValid = true;

						if (field.value.length == 0)
						  allValid = false;
				  
						//Send user to the field that is not filled in and give error message.
						if ((!allValid) && (Msg.length > 0))
						{ alert(Msg);
						  field.focus();
						}  

						return(allValid);	 
					} 



					function CheckField(field,fieldType, Msg)
					{ 
						//var reEmail = /^.+\@.+\..+$/
						var reEmail = /^[a-z|A-Z|0-9|\.|_|-]+\@[a-z|A-Z|0-9|\.|_|-]+\.[a-z|A-Z|0-9|\.|_|-]+$/
						var reFloat = /^((d+(\.\d*)?) | ((\d*\.)?\d+))$/
						var reInteger = /^\d+$/
						var reCurr  = /^\d*(\.\d\d) ?$/
						var allValid = true;


						switch(fieldType){
						   case 'email': tester=reEmail;break;
						   case 'integer': tester=reInteger;break;
						   case 'float': tester=reFloat;break;
						   case 'currency': tester=reCurr;break;
						   }
						   if(!tester.test(field.value)) {
							   allValid = false;
						   } 

						//Send user to the field that is not filled in and give error message.
						if ((!allValid) && (Msg.length > 0))
						{ alert(Msg);
						  field.focus();
						}  

						return(allValid);	 
					} 


					function CheckUserPassword(field1, field2, Msg)
					  { var allValid = false;

						if (field1.value != field2.value)

						  allValid = true;
					  
					    //Send user to the field that is not filled in and give error message.
						if (!allValid)
						{ alert(Msg);
					      field2.focus();
						}
						

					    return(allValid);	 
					  } 




					function CheckPasswordFields(field1, field2, Msg)
					  { var allValid = false;
					    
						if (field1.value == field2.value)
						  allValid = true;
					  
					    //Send user to the field that is not filled in and give error message.
						if (!allValid)
						{ alert(Msg);
					      field1.focus();
						}  

					    return(allValid);	 
					  } 


					function CheckLen(field,characters,Msg)
					{ 
												
						var allValid = true;
						if (field.value.length < characters)
						{
						  allValid = false;
				        }
				        
						//Send user to the field that is not filled in and give error message.
						if ((!allValid) && (Msg.length > 0))
						{ alert(Msg);
						  field.focus();
						}  
						return(allValid);	 
					} 


					function CheckPasswordType(field, Msg)
					  { var allValid = false;
					    var mypass = field.value;
					    var status=0;
						var strlength;
						strlength = mypass.length;
						var myletter; 
						var numchar = "first";
						var alphchar = "first";
						for (var x=0;x<strlength;x++)
						{
							myletter = mypass.substr(x,1);
							if(isNaN(myletter))
							{
								if (alphchar == "first")
								{
									alphchar = "yes";
								}
							}
							else
							{
								if (numchar == "first")
								{
									numchar = "yes";
								}		
							} 
						}
						if ((alphchar == "yes") && (numchar == "yes"))
						{
							status = 1;
						}
					    if (status == 1)
						  allValid = true;
					  
					    //Send user to the field that is not filled in and give error message.
						if (!allValid)
						{ alert(Msg);
					      field.focus();
						}  

					    return(allValid);	 
					  }
					  
  
						//function to only allow numeric keys to be pressed
						function fnTrapKB_Num()
						{
							if ((event.keyCode >= 46 && event.keyCode <= 57) || (event.keyCode >= 35 && event.keyCode <= 39) || event.keyCode == 13 || event.keyCode == 8 || event.keyCode == 9 || (event.keyCode >= 96 && event.keyCode <= 105))
								event.returnValue=true;
							else
								event.returnValue=false;
							
							if (event.shiftKey == true)
							{
								if (event.keyCode == 9 || (event.keyCode >= 35 && event.keyCode <= 39))
									event.returnValue=true;
								else
									event.returnValue=false;
							}
						}




function Validate(){
// Declare variables.
var browserName = navigator.appName.substring(0,8);
var browserVer = parseFloat(navigator.appVersion);
var strErr, intExpiryMonth, intExpiryYear
var datDate, datMonth, datYear

	datDate = new Date();                           // Create Date object.
	datMonth = (datDate.getMonth() + 1);		    // Get month	
	datYear = datDate.getFullYear();                // Get year.
	strErr = ''

	if(document.frmPaymentDetails.txtCardholder.value.length < 3){
		strErr = strErr + "Cardholder Name \n";
	}
	if(checkCC(document.frmPaymentDetails.txtPaymentCardNumber.value) == false){
		strErr = strErr + "Valid Payment Card Number \n";
	}
	intExpiryMonth = document.frmPaymentDetails.drpExpiryMonth.options[document.frmPaymentDetails.drpExpiryMonth.selectedIndex].value;
	intExpiryYear = document.frmPaymentDetails.drpExpiryYear.options[document.frmPaymentDetails.drpExpiryYear.selectedIndex].value;
	
	if (intExpiryYear < datYear) 
	  {
		 strErr = strErr + "Expiry Date Is In The Past \n";
	   } else if((datMonth > intExpiryMonth) && (intExpiryYear <= datYear)){
		strErr = strErr + "Expiry Date Is In The Past \n";
	}


	
    if(document.frmPaymentDetails.txtCVV.value.length == 0){
		strErr = strErr + "Valid CCV Number \n";
	}


//	alert(document.frmPaymentDetails.txtCVV.value.length)
	
	if(document.frmPaymentDetails.txtCVV.value.length != 0){
		if (isNaN(document.frmPaymentDetails.txtCVV.value)==true)
		strErr = strErr + "Valid CCV Number \n";
	}
	if (strErr != ''){
		alert('Please Enter The Following Details :\n' + strErr)
	}
	else
	{
		//if (browserName == 'Microsof' && browserVer >= 4){
		//	document.all.item("subImg").src = "/SafePay/Images/blank.gif"
		//	document.all.item("imgAni").src = "/SafePay/Images/processing_anim.gif"
		//}
		//return false;


        document.frmPaymentDetails.txtCVV.disabled = false
		document.frmPaymentDetails.submit()
	}
	return true;
}

function checkCC(s) {
  var i, n, c, r, t;
  // First, reverse the string and remove any non-numeric characters.
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }
  // Check for a bad string.
  if (r.length <= 1)
    return false;
  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }
  // Finally, add up all the single digits in this string.
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }

  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.
  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}

//-->




function checkLength(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}


