/**
* @ Modified By	 : Gargi Bakshi
* @ Modified On	 : 4th-Apr-04
* @ Modification :	Added trimAll() method that removes all the leading and trailing blanks of all the elements of the passed form.

@ Modified:		By Pratap Shinde on 17.11.05
@ Description:	Modified chkCardByLuhnAlgo() function to add Card Type "CTBL"

@ Modified:		By Pratap Shinde on 18.11.05
@ Description:	Added new method chkFirstBlank(formelement,text)

@ Modified:		By Noor Shaikh on June-20-2007
@ Description:	Updated functions chkSpecialCharCustom() and chkSpecialChar() to validate hazardous characters.

@ Modified:		By Noor Shaikh on June-20-2007
@ Description:	Updated functions chkSpecialCharCustom() and chkSpecialChar() to validate hazardous characters.

@ Modified:		By Noor Shaikh on Feb-13-2009
@ Description:	Checking for valid card types supported by this script

*/


// Note: All developers are requested to either return true or false explicetly while adding a function to the file.

// Usage in jsp/html file:if(!chkBlank(document.f1.Username,'User Name')) return false;

/* This function removes all the leading and trailing blanks of all the elements of the passed form. */

function trimAll(frm) 
{ 
	for (var i=0; i < frm.elements.length; i++) 
		frm.elements[i].value = (""+frm.elements[i].value).replace(/^\s*/,'').replace(/\s*$/, '');	
}

/* This function makes the field compulsary. */

function chkBlank(formelement,text)
{
	if (formelement.value=='')
	{
		alert('You have not entered ' + text +'.\nPlease enter '+text+'.');
		formelement.focus();
		return false;
	}
	else
	{
		return chkFirstBlank(formelement,text);
		//return chkSpace(formelement,text);
	}
}

function chkFirstBlank(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	if (a.indexOf(' ') == 0) 
	{
			msg='Blank space in ' + text + ' is incorrect.\nBlank space is not allowed at first place in '+text+'.';
			alert(msg);
			formelement.focus();
			formelement.select();
			return false;
	}

	if (msg=='true')
	{
		return true;
	}

}

function chkAllBlank(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	if (a.indexOf(' ') >= 0) 
	{
			msg=text+' is incorrect.\nBlank space are not allowed in '+text+'.';
			alert(msg);
			formelement.focus();
			formelement.select();
			return false;
	}

	if (msg=='true')
	{
		return true;
	}

}



/* This function checks for non numeric numbers. */

function chkNaN(formelement,text)
{
	if (isNaN(formelement.value))
	{
		alert(text + ' value you have provided is not correct.\nPlease ensure that '+ text +' value does not have alphabates and special characters.');
		formelement.focus();
		formelement.select();
		return false;
  	}
	else
	{
		return true;
	}
}

/*Function to check if a float eg. 20.22 is in proper format.
parameters :
	formElementObject - Object of the form element
	displayText - Name of field (String)
	isRequired - true if this field should not be empty, false otherwise.(boolean)

	Note : More suitable for onBlur event
*/
function isDigit(formElementObject, displayText, isRequired) {
	var eleValue = trim(formElementObject.value);

	if(formElementObject == null || displayText == '') {
		alert('Incorrect use of function isDigit');
		return false;
	}
	if(eleValue == '' && isRequired == true) {
		alert('Please provide a value for '+displayText+'.');
		formElementObject.focus();
		return false;
	}
	if(eleValue != '') {
		if(eleValue.indexOf('.') != -1) {
			var eleArr = eleValue.split('.');
			if(eleArr.length > 2) {
				alert('Please enter a valid ' + displayText+'. You may enter upto 2 digits after the decimal point.' );
				formElementObject.focus();
				formelement.select();
				return false;
			} else {
				if(isNaN(eleArr[0]) || isNaN(eleArr[1])) {
					alert(' Please enter a valid ' + displayText+' Please enter a numeric value.' );
					formElementObject.focus();
					formelement.select();
					return false;
				}
			}
		} else {
			if (isNaN(eleValue))
			{
				alert('Please enter a numeric value for '+displayText+'.');
				formElementObject.focus();
				formelement.select();
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	return true;
}

/*
function isEmail(theField){
	var pattern = ".+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)"
	var regex = new RegExp(pattern)
	if (regex.test(theField.value)) return true;
	else
		return warnInvalid (theField, "Incomplete or Invalid Email")
}
*/

/* This function checks for a valid email address. */

function chkEmail(formelement,text)
{
	if(formelement.value!='')
	{
//		var pattern = ".+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)"
//		var pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"

		 regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9\_]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern)
		if (!regex.test(formelement.value)){
			alert("You have not entered correct " + text + ".\nPlease ensure that "+text+" is in proper format like 'myname@myaddress.com'." );
			formelement.focus();
			formelement.select();
			return false;
		}
		else
		{
			return true;
		}
	}
}

/* This function checks for the minimum characters. */

function chkLessLen(formelement,text,len)
{
	if(formelement.value.length<parseInt(len))
	{
		alert('The '+text+' should not have less than '+len+' characters.');
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function checks for the maximum characters. */

function chkGreaterLen(formelement,text,len)
{
	if(formelement.value.length>parseInt(len))
	{
		alert('The '+text+' should not have more than '+len+' characters.');
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}


/* This function checks for special characters as per the user requirement. */

function chkSpecialCharCustom(formelement,text, cha)
{

	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var ch=cha.length;
	var i,j;

	for(i=0;i<ch;i++)
	{
		var ch1=cha.substring(i,i+1);
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==ch1)
			{
				msg='Special Character "' +ch1+ '" is not allowed in '+text+'\nPlease enter correct '+text+'.'; //added by Noor
				//msg=text+' is not accepted.\nPlease enter correct '+text+'.'; // commented by Noor.
				alert(msg);
				formelement.focus();
				formelement.select();
				return false;
			}
		}
	}
	if (msg=='true')
	{
	return true;
	}

}

/* This function checks for special characters. */

function chkSpecialChar(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var cha='`~!@#$%^&()+-[]{}/|;:,<>.?';
	var ch=cha.length;
	var i,j;

for(i=0;i<ch;i++)
	{
		var ch1=cha.substring(i,i+1);
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==ch1)
			{
				msg='Special Character "' +ch1+ '" is not allowed in '+text+'\nPlease enter correct '+text+'.'; //added by Noor.
				//msg=text+' is incorrect.\nPlease enter valid '+text+'.';// commented by Noor.

				alert(msg);
				formelement.focus();
				formelement.select();
				return false;
			}
		}
	}
	if (msg=='true')
	{
	return true;
	}
}


function checkNumber(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	for( var n= 0; n<a.length; n++ ) 
		{
			var c = a.charAt(n);
				if(c== '0' || c=='1' || c=='2'|| c=='3' || c=='4' || c=='5'|| c=='6' || c=='7' || c=='8' || c=='9') 
				{   
					//msg='You have entered numbers in'+' '+text+'.Please enter your correct'+' '+text;
					msg=text+' is incorrect.\nPlease enter your correct'+' '+text+'.';
					alert(msg);
					formelement.focus();
					formelement.select();
					return false;
				} 
			
		}
	
	if(msg=='true')
	{	
		return true;
	}
}

/* This function checks for spaces in the field. */

function chkSpace(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var i,j;
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==' ')
			{
				msg='Blank spaces are not allowed in '+text+'.';
				alert(msg);
				formelement.focus();
				return false;
			}
		}

	if (msg=='true')
	{
	return true;
	}
}

/* This function compels the user to enter number greater than 0. */

function chkLEZero(formelement,text)
{
	if (formelement.value <= 0)
	{
		alert('Please enter a value greater than 0 for '+text+'.');
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function checks for identical passwords. */

function chkPassword(formelement1,formelement2)
{
	var password1=formelement1.value;
	var password2=formelement2.value;

	if (password1 != password2)
	{
		alert('Passwords do not match. Please reenter your passwords.');
		formelement1.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function compels the user to select a value in the list box. */

function chkListBlank(formelement,text)
{


	if (formelement.options[formelement.selectedIndex].value=='')
	{
		alert('Please select a '+text);
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function compels the user to select atleast one radio button. */

function chkRadio(formelement,text)
{
	var flag='false';
	if(formelement.checked==true){
		flag='true';
	}
	else{
		for (var i =0;i<formelement.length;i++ ){
			if(formelement[i].checked==true){
				flag='true';
			}
		}
	}
	if (flag=='false')
	{
		alert('Please select a '+text);
		return false;
	}
	else
	{
		return true;
	}

}

/* This function is used to trim the leading and trailing spaces from given string.
   Useful to remove unwanted spaces before processing string value in JavaScript. */

function trim ( str )
{
    var k=0;
    var i=0;
    var j=0;
    k   =   str.length;
    while ( str.charAt (j) == ' ' )
       j++;

    i   =   k;
    while ( str.charAt (i-1) == ' ' )
        i   =   i-1;
    if ( j != k )
        trimstr = str.substring(j,i);
    else
        trimstr = '';
    return trimstr;
}

/* This function is used to check if the given string containes single quote chracter*/

function hasQuotes(str)
{
    var ch="'";
    if(str.indexOf(ch)==-1)
    return false;
    return true;
}

/* This function is used to open a new pop-up window. */
function OpenWin (link, windowName)
{
    loc =   link;
    win =   window.open (loc,windowName,'top=150,left=200,height=300,width=600,scrollbars=yes,status=no,toolbar=no,resizable=yes') ;
    win.focus();

}

/* Used for rounding off value. Deprecated. Insted use function round_decimals given below. */
function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

/* Used for rounding off decimal values to the correct decimal precision. */

function round_decimals(original_number, decimals)
{
 var result1 = original_number * Math.pow(10, decimals)
 var result2 = Math.round(result1)
 var result3 = result2 /Math.pow(10, decimals)
 return pad_with_zeros(result3, decimals)
}

/* Internally used by round_decimals function for padding amount with zeros while rounding off. */

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()

    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {

        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0

        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }

    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length

    if (pad_total > 0) {

// Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++)
            value_string += "0"
        }
   // alert("deci :"+value_string);
    return value_string
}

	//use this function to disable form element
function disable(elem) { // elem: form element to be disabled
  elem.onfocus=elem.blur;
}
	//use this function to enable form element
function enable(elem) { // elem: form element to be reenabled
  elem.onfocus=null;
}

/*function to get the date after the given period
  currentYear - String giving current year in yyyy format
  currentMonth - String giving current month in mm format
  currentDay - String giving current day in dd format
  addDays - Integer showing no of days after the current date
  return next date as mm/dd/yyyy string
*/
function getNextDate(currentYear, currentMonth, currentDay, addDays) {
	var nextDate = '';
	
	var currDateObj = new Date(parseInt(currentYear),
				parseInt(currentMonth),
				parseInt(currentDay));
		
	currDateObj.setDate(parseInt(currentDay)+addDays);
	nextDate = currDateObj.getMonth()+'/'+currDateObj.getDate()+'/'+currDateObj.getYear();
	return nextDate;
}

/*
	this function iterates though the selection control
	and selects appropriate option as per the supplied argument
*/
function go2CurrentSelectedValue(sel,val)
{      
	  
		for(var i=0; sel.options!=null && i < sel.options.length; i++) {
						if(sel.options[i].value==val) {
								sel.options[i].selected = true;
						}
				}
}


function WinOpenCurrencyConvertor(a,b) {
	postwindow=window.open("/includes/wld_curconvert.jsp?amount="+a + "&cssfile=" + b, "xfdfd","status=no,resize=yes,scrollbars=yes,toolbar=no,dependent=yes,alwaysRaised=yes,resizable=yes,width=520,height=430");
	window.status="done";
}
function WinOpen(url,height,width) {
	postwindow=window.open(url, "window1","status=no,resize=no,scrollbars=yes,toolbar=no,dependent=yes,alwaysRaised=yes,maximize=null,resizable=yes,width=" + width +",height=" + height + "");
	window.status="done";
}
function WinOpen(url,height,width,winName) {
	postwindow=window.open(url, winName,"status=no,resize=no,scrollbars=yes,toolbar=no,dependent=yes,alwaysRaised=yes,maximize=null,resizable=yes,width=" + width +",height=" + height + "");
	window.status="done";
}

// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

/**
     * Round a float/double value to a specified number of decimal 
     * places.
     * 
     * @param  text-element for which the value to be rounded.
     * @param  places the number of decimal places(Value) to round to.
     * @return  Finalresult rounded to places decimal places.
     */


	 function  round(text,places)
     {
			 
			  var doublValue=parseFloat(text.value);
			  var noofDecimal=parseFloat(places);
			  var factor=Math.pow(10,noofDecimal);
			  var val=doublValue*factor;
			  var temp=Math.round(val);
			  var Finalresult=temp/factor;
			  return Finalresult; 
	  }
	  

/**	
* Function verifies numeric values, appropriate length w.r.t card type and  Luhn's Algo  
* for Visa(VISA), Mastercard(MSTR), Citibank ECard(ECRD), American Express(AMEX),JCB(JPCB),Diners(DCLB) credit * cards.
* Citibank ECard is a virtual MasterCard for online txns only & hence validated as a MasterCard.
* Discover Novus(DSNV) has not been validated but ignored by script for now
* Carte Blanche Card (CTBL) has not been validated but ignored by script for now
* Also,validates Solo,Switch and Delta Cards but, the code is commented since these are not  
* supported by the gateway yet & hence not tested.
*
* @param  CardNumber value to be validated
* @param  Corresponding Card Type
*/

 function chkCardByLuhnAlgo(cardNumber,CardType)
  {      
		
			var CCNum =cardNumber; //Card Number
			var CCNum =CCNum.replace(/ /g, "");
			var dashindex=CardType.indexOf("-");
			var CCType=CardType.substring(dashindex+1,CardType.length);//Card Type
		    
			
			var msg = 'Card Number provided does not match with Card Type selected.\nPlease enter proper Card Number that matches with the card type you have selected.';
			var finalmsg='The number you have provided does not appear to be a valid Card Number. \nPlease enter the Card Number as it appears on your Credit Card.';

			//Checking Card Type 
			if(CCType=='')
			{
				alert('Card Type is not selected.\nPlease select one of the credit cards from the Card Type dropdown.');
				return false;
			}

			//Checking for valid card types supported by this script
			//Discover Novus(DSNV) has not been validated but ignored by script for now
			if(CCType !='VISA' && CCType !='MSTR'  && CCType !='AMEX' && CCType!='JPCB' && CCType!='ECRD' && CCType !='DCLB' && CCType !='DSNV' && CCType !='CTBL' && CCType !='AXISDB' && CCType !='COBDB' && CCType !='DCDB' && CCType !='DSBDB' && CCType !='HDFCDB' && CCType !='INGDB' && CCType !='IOBDB' && CCType !='KVBDB' ) // Modified By Noor
			{
				alert('Card Type selected is not supported. Please contact the System Administrator to  report this error.')
				return false;
			}

			//Check for Card Number entered.
			if(CCNum=='' || CCNum==0)
			{
				  alert('Card Number cannot be blank or zero.\nPlease enter the Card Number as it appears on your Credit Card.');
				  return false;
			} 
			if(CCNum !='')
			{  
				for( var i = 0; i <CCNum.length; ++i ) 
					{
						var c = CCNum.charAt(i);
						if( c < '0' || c > '9' ) 
						{
							alert('Card Number you have provided is not correct.\nPlease ensure that Card Number does not contain any alphabets, spaces or special characters.');
							return false;
						} 
					}  
			 }
			//Check Visa 
			if(CCType.indexOf('VISA') !=-1)
			{
				if ((CCNum.length !=13 && CCNum.length != 16) && (CCNum.substring(0,1) == 4))
					{
						alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
						return false;
					}
				if ((CCNum.length == 13 || CCNum.length == 16) && (CCNum.substring(0,1) == 4))
				{
					if(!cardval(cardNumber))
					{
				 
							alert(finalmsg);  
							return false; 
					}
				 }
	    
				else
				{ 
					alert(msg);  
					return false;
				}
			}
			//Check Mastercard  and Citibank ECard
			if((CCType.indexOf('MSTR') !=-1) || (CCType.indexOf('ECRD') !=-1))
			{
				var firstdig=CCNum.substring(0,1);
				var seconddig=CCNum.substring(1,2);
				if ((CCNum.length !=16 && CCNum.length != 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) 
				{ 
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
        
				if ((CCNum.length == 16 || CCNum.length == 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
				{
					if(!cardval(cardNumber))
					{
						alert(finalmsg);  
						return false; 
					}
					
					}
			
					else
					{
						alert(msg);  
						return false;
					}
	
			}

			//Check American Express 
			if(CCType.indexOf('AMEX') !=-1)
			{
				firstdig = CCNum.substring(0,1);
				seconddig = CCNum.substring(1,2);
				if ((CCNum.length !=15 && CCNum.length != 18) && (firstdig == 3) && ((seconddig == 4)||(seconddig == 7)))
				{ 
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if (((CCNum.length == 15)  || (CCNum.length == 18)) && (firstdig == 3) && ((seconddig == 4) ||(seconddig == 7)))
				{
					if(!cardval(cardNumber))
					{  
						alert(finalmsg);  
						return false; 
					}
				}
				else
				{
					alert(msg);  
					return false;
				}
			}		

			//Check JCB  card 
			if(CCType.indexOf('JPCB') !=-1)
			{
				if ((CCNum.length != 16) && (CCNum.match(/^(3088|3096|3112|3158|3337|3528|3566|3530|3540|3541)/)))
				{
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if ((CCNum.length==16) && (CCNum.match(/^(3088|3096|3112|3158|3337|3528|3566|3530|3540|3541)/))) 
				{
					if(!cardval(cardNumber))
					{  
						alert(finalmsg);  
						return false; 
					}
				}
				else
				{
					alert(msg);  
					return false;
				}
			}
 
			
			//Check Diners
 
			if(CCType.indexOf('DCLB') !=-1)
		    {   
				firstdig = CCNum.substring(0,1);
				seconddig = CCNum.substring(1,2);
				if ((CCNum.length !=14 && CCNum.length != 17) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
				{
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit credit.');
					return false;
				}

				if((CCNum.length == 14 || CCNum.length == 17)  && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
				{
					if(!cardval(cardNumber))
					{
						alert(finalmsg);  
						return false; 
					}
				}
				else
				{
					alert(msg);  
					return false;
				}
			}


			/* Following code is commented out as these cards are not supported by the gateway yet & hence not tested.
			//Check Delta card
 			if(CCType.indexOf('Delta') !=-1)
			{
				if (CCNum.length != 16)
				{ 
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if ((CCNum.length==16) && (CCNum.match(/^(413733|413734|413735|413736|413737|4462|453978|453979|454313|454313|454432|454433|454434|454435|454742|456725|456726|456727|456728|456729|45673|456740|456741|456742|456743|456744|456745|46583|46584|46585|46586|46587|484409|484410|49096|49097|492181|492182|498824)/)))
				{
					if(!cardval(cardNumber ))
					{  
						alert(finalmsg);  
						return false; 
					}
			  
				}
				else
				{
					alert(msg);  
					return false;
				}
			} 

			//Check Solo 
			if(CCType.indexOf('Solo') !=-1)
			{
				if ((CCNum.length !=16 && CCNum.length != 18 &&  CCNum.length!=19)&&(CCNum.match(/63345|63346|63347|63348|63349|6767/)))
				{ 
					alert('The number of digits for the Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if ((CCNum.length==16 || CCNum.length==18 || CCNum.length==19) && (CCNum.match(/63345|63346|63347|63348|63349|6767/)))
				{
					if(!cardval(cardNumber))
					{  
						alert(finalmsg);  
						return false; 
					}
				}
				else
				{
					alert(msg);  
					return false;
				}
			} 

			//Check Switch 
			//Code does not check the length with respect to starting digits for Switch card.
			if(CCType.indexOf('Switch') !=-1)
			{
				if (CCNum.length != 16 && CCNum.length != 18 && CCNum.length != 19)
				{ 
					alert('The number of digits for the Card Number you have provided is not correct.\n Please ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if ((CCNum.length==16) && (CCNum.match(/^(491101|491102|564182|633300|633302|633303|633304|633305|633306|633307|633308|633309|633310|633311|633312|633313|633314|633315|633316|633317|633318|633319|633320|633321|633322|633323|633324|633325|633326|633327|633328|633329|633330|633331|633332|633333|633334|633335|633336|633337|633338|633339|633340|633341|633342|633343|633344|633345|633346|633347|633348|633349|675900|675902|675903|675904|675906|675907|675908|675909|675910|675911|675912|675913|675914|675915|675916|675917|675919|675920|675921|675922|675923|675924|675925|675926|675927|675928|675929|675930|675931|675932|675933|675934|675935|675936|675937|675941|675942|675943|675944|675945|675946|675947|675948|675949|675963|675964|675965|675966|675967|675968|675969|675970|675971|675972|675973|675974|675975|675976|675977|675978|675979|675980|675981|675982|675983|675984|675985|675986|675987|675988|675989|675990|675991|675992|675993|675994|675995|675996|675997|675999)/))||
				(CCNum.length==18) && (CCNum.match(/^(675938|675939|675940|490302|490303|490304|490305|490306|490307|490308|490309|490335|490336|490337|490338|490339|491174|491175|491176|491177|491178|491179|491180|491181|491182)/))||
				(CCNum.length==19) && (CCNum.match(/^(4936|633301|675901|675905|675918|675950|675951|675952|675953|675954|675955|675956|675957|675958|675959|675960|675961|675962|675998)/)))
				{
					if(!cardval(cardNumber))
					{  
						alert(finalmsg);  
						return false; 
					}
				}
				else
				{
					alert(msg);  
					return false;
				}
			}  */
	
	return true;
    }//method is closed. 

   /**
	* Function validates the security code of credit card 
	* For digits and No.of digits w.r.t card type
	* @param cardType value
	* @param  security code value
	*/

	function chkSecurityCode(CodeNumber,CardType)
	{
		var code=CodeNumber;
		var dashindex=CardType.indexOf("-");
		var CCType=CardType.substring(dashindex+1,CardType.length);//Card Type

		
		if(code=='')
		{ 
			alert('Security Code is missing.\nPlease enter the 3 or 4 digit Security Code as it appears on your credit card.');
			return false;
		} 
		//Check for securtiy code
		if(code!='')
		{
			for(var j = 0;j<code.length; j++) 
			{
					var s =code.charAt(j);
					if( s < '0' || s > '9' ) 
				    {
						alert('Security Code you have provided is not valid.\nPlease ensure that Security Code is numeric and does not contain any alphabets, spaces or special characters.');
						return false;
					} 
			}  

			if((code.length !=3 )  && ( CCType=='ECRD' || CCType=='VISA' ||  CCType=='MSTR'|| CCType=='JPCB' || CCType=='DCLB'  || CCType=='Switch' || CCType=='Delta' ||CCType=='Solo'))
			{ 
					alert('Security Code should have 3 digits.\nPlease ensure that the Security Code you enter is same as it appears on your credit card.');
					return false;
			}

			if((code.length != 4)  && ( CCType=='AMEX'))
			{ 
					alert('Security Code should have 4 digits.\nPlease ensure that the Security Code you enter is same as it appears on your credit card.');
					return false;
			}
		 }
		 return true;
	}//function is closed.

 /**
  * Function checks the validity of card number by Luhns Algorithm.This function should not be called  	
  *  directly. It is nested within function chkCardByLuhnAlgo. 
  */
  function cardval(cardNum) 
  {
		var s=cardNum;
		var v = "0123456789";
		var w = "";
		if(s !="")
		{ 
		   for (i=0; i < s.length; i++) 
			{
				x = s.charAt(i);
				if (v.indexOf(x,0) != -1)
				w += x;
			}
			j = w.length / 2;
			k = Math.floor(j);
			m = Math.ceil(j) - k;
			c = 0;
			for (i=0; i<k; i++) 
			{
				a = w.charAt(i*2+m) * 2;
				c += a > 9 ? Math.floor(a/10 + a%10) : a;
			}

			for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
			return (c%10 == 0);  //returns true here.
		}
	}// method is closed


