<!--
	// This file contains the data validation JavaScript functions
	// It is included in the HTML pages with forms that need these
	// data validation routines.


// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";



/****************************************************************/

// PURPOSE:  Check to see if the string passed in is a valid time.
//	A valid time is defined as a string which is postfixed with either
//  "PM" or "AM".  Next it checks to see if there is a colon in the
//  string.  If there is, it makes sure that at least one digit preceeds
//  it and two proceed it.

	function IsTime(strTime)
	{
		var strTestTime = new String(strTime);
		strTestTime.toUpperCase();

		var bolTime = false;

		if (strTestTime.indexOf("PM",1) != -1 || strTestTime.indexOf("AM",1))
			bolTime = true;

		if (bolTime && strTestTime.indexOf(":",0) == 0)
			bolTime = false;

		var nColonPlace = strTestTime.indexOf(":",1);
		if (bolTime && ((parseInt(nColonPlace) + 5) < (strTestTime.length - 1) || (parseInt(nColonPlace) + 4) > (strTestTime.length - 1)))
			bolTime = false;


		return bolTime;
	}

/****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function makeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
   /*var objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(s)) {
	   alert("inRegEXP");
   }
*/
    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
	/*if ((c = ' ') && (c = '\n') && (c = '\t'))
	{
		alert("in");
	}*/
	if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }

    // All characters are whitespace.
    return true;
}

/****************************************************************/

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
 

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

/****************************************************************/

// Checks to see if a required field is email.  If it is, a warning
// message is displayed...

function ForceEmail(objField, FieldName)
{
	var strField = new String(objField.value);
	//alert(isEmail(strField));
	if (!isEmail(strField)) {
		//alert("You need to enter correct Email information for " + FieldName);
		alert("Please enter correct Email information for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}
		
/****************************************************************/

/****************************************************************/

// Checks to see if a required combo box is selected.  If it is, a warning
// message is displayed...

function ForceSelect(objField, FieldName)
{
	var strField = new String(objField.selectedIndex);
	//alert(strField);
	if (strField<0) {
		//alert("You need to Select Value for " + FieldName);
		if (FieldName!="")
		alert("Please Select Value for " + FieldName);
		objField.focus();
		//objField.select();
		return false;
	}

	return true;
}
		

/****************************************************************/

// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...

function ForceEntry(objField, FieldName)
{
	//alert(objField.value);
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		//alert("You need to enter information for " + FieldName);
		if (FieldName!="")		
		alert("Please enter value for " + FieldName);
		objField.focus();
		//objField.select();
		return false;
	}

	return true;
}

function ForceEntryWithMessage(objField, FieldName,ErrMsg)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert(ErrMsg);
		objField.focus();
		return false;
	}

	return true;
}
/****************************************************************/

/**
* This function is used to restrict the non-numeric value.
* @return false if non-numeric keycode
*/
function forceNumberEntry(){
//	alert("in");
  if(event.keyCode < 48 || event.keyCode > 58) 
	  return false;
}
//<!----------------------------------------------------------------


// Returns true if the string passed in is a valid number
//  (no alpha characters), else it displays an error message

function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}

/****************************************************************/

// Returns true if the string passed in is a valid money
//  (no alpha characters except a decimal place), 
//   else it displays an error message

function ForceMoney(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.')) {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}


/****************************************************************/

// Right trims the string...  Useful for SQL datatypes of CHAR

function RTrim(strTrim)
{
	var str = new String(strTrim);
	var i = 0;
	var c = "";
	var endpos = 0

	for (i = str.length; i >= 0 && endpos == 0; i = i - 1) {
		c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
			endpos = i;
	}

	return str.substring(0,endpos+1);
}

/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (1 = month, 2 = day).  If the string is
	nonnumeric, false is passed back.  If the day in the date string
	is greater than 31, false is returned.  If the month is greater
	than 12, an error is returned.
*/

function isDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

// Displays an alert box with the passed in string...

function PromptErrorMsg(Field,strError)
{
	alert("You have entered an invalid date for " + strError + ".  \n \nPlease make sure your date format is in MM/DD/YY format.\n");
	Field.focus();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
		intDateOptional=0 if u need to check date for white space also or else 1 
*/

function ForceDate(strDate,strField,intDateOptional)
{
	var str = new String(strDate.value);

	if (isWhitespace(str) && intDateOptional==1) {
		return true;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	return true;
}

/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipcode(strZip)
{
	var s = new String(strZip);

	if (s.length != 5 && s.length != 10)
		// inappropriate length
		return false;


	for (var i=0; i < s.length; i++)
		if ((s.charAt(i) < '0' || s.charAt(s) > '9') && s.charAt(i) != '-')
			return false;

	return true;
}

/****************************************************************/

//Function to Force the ZipCode
function ForceZip(objField, FieldName)
{
	
	var strField = new String(objField.value);
	//alert(strField);
	if (!isZipcode(strField)) {
		//alert("You need to Correct ZipCode for " + FieldName);
		alert("Please Correct ZipCode for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}
	return true;
}


// This function ensures that a field is less than or equal to the
// Length passed in.  You must call this function with the element
// name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
// If the field's value is too large, an error message is displayed
// and false is returned, else true is returned.

function ForceLength(objField, nLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length > nLength) {
		alert(strWarning);
		return false;
	} else
		return true;
}

/***************************************
****************Function to validate phone number US
**************************************************************************/
function isValidUSPhone(strfield)
{
var s = new String(strfield);
phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
var gotIt = phoneNumber.exec(s); 
return gotIt;
}
//Function to Force the ZipCode
function ForceUSPhone(objField, FieldName)
{
	
	var strField = new String(objField.value);
	//alert(strField);
	if (!isValidUSPhone(strField)) {
		//alert("You need to Correct US Phone Number for " + FieldName);
		alert("Please Correct US Phone Number for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}
	return true;
}

function recalculateage(objField)
{
<!-- Fecha de cumpleaņos!-->
//birthTime = new Date("July 12, 1977 16:15:00 GMT-0500");

birthTime = new Date(eval(objField).value);

if(birthTime!="NaN")
{
	todaysTime = new Date();
	todaysYear = todaysTime.getYear();
	if (todaysYear < 2000) todaysYear += 1900;
	todaysMonth = todaysTime.getMonth();
	todaysDate = todaysTime.getDate();
	todaysHour = todaysTime.getHours();
	todaysMinute = todaysTime.getMinutes();
	todaysSecond = todaysTime.getSeconds();
	birthYear = birthTime.getYear();
	if (birthYear < 2000) birthYear += 1900;
	birthMonth = birthTime.getMonth();
	birthDate = birthTime.getDate();
	birthHour = birthTime.getHours();
	birthMinute = birthTime.getMinutes();
	birthSecond = birthTime.getSeconds();
	
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	
	if (((todaysYear % 4 == 0) && (todaysYear % 100 != 0)) || (todaysYear % 400 == 0)) monarr[1] = "29";
	
	countMonth = monarr[todaysTime.getMonth()];
	
	<!-- Hacer Las Cuentas
	if (todaysMinute > birthMinute) {
	diffMinute = todaysMinute - birthMinute;
	calcHour = 0;
	}
	else {
	diffMinute = todaysMinute + 60 - birthMinute;
	calcHour = -1;
	}
	if (todaysHour > birthHour) {
	diffHour = todaysHour - birthHour + calcHour;
	calcDate = 0;
	}
	else {
	diffHour = todaysHour + 24 - birthHour + calcHour;
	calcDate = -1;
	}
	if (todaysDate > birthDate) {
	diffDate = todaysDate - birthDate + calcDate;
	calcMonth = 0;
	}
	else {
	diffDate = todaysDate + countMonth - birthDate + calcDate;
	calcMonth = -1;
	}
	if (todaysMonth > birthMonth) {
	diffMonth = todaysMonth - birthMonth + calcMonth;
	calcYear = 0;
	}
	else {
	diffMonth = todaysMonth + 12 - birthMonth + calcMonth;
	calcYear = -1;
	}
	diffYear = todaysYear - birthYear + calcYear;
	
	if (diffMinute == 60) { diffMinute = 0; diffHour ++; }
	if (diffHour == 24) { diffHour = 0; diffDate ++; }
	if (diffDate == countMonth) { diffDate = 0; diffMonth ++; }
	if (diffMonth == 12) { diffMonth = 0; diffYear ++; }
	
	age = diffYear;
	//+ ' Years, ' + diffMonth 
	//+ ' Months, ' 
	return age;
	/*+ diffDate + ' Days, ' + diffHour + ' Hours, ' 
	+ diffMinute + ' Minutes, ' + todaysSecond + ' Seconds Old';
	
	document.write('<center>');
	document.write('Current Time: ' + todaysTime + '<br>');
	document.write('Birthday: ' + birthTime + '<br>');
	document.write('Age: ' + age + '<br>');
	document.write('</center>');*/
	// End -->
}
else
{
	var nage="";
	return nage;
}
}




function fnGetAge(objField) { 
 
var dateString=eval(objField).value;
if (dateString=="")
{
	return 0;
}

//alert(dateString);
var dateArr=dateString.split("/");
//var dob = new Date(dateString.substring(6,10),dateString.substring(3,5)-1,dateString.substring(0,2),0,0,0);
var dob = new Date(dateArr[2],dateArr[0],dateArr[1],0,0,0);


var now = new Date();
var today = new Date(now.getYear(),now.getMonth(),now.getDate(),0,0,0);

var dobmonth=dateArr[0];
var todaymonth=now.getMonth();

//var date1 = new Date(97, 8, 17, 11, 45, 2);
//var date2 = new Date(97, 12, 31, 18, 0, 0);

var milliseconds1 = dob.getTime();
var milliseconds2 = today.getTime();

var difference = milliseconds2 - milliseconds1;

/*document.write('difference in milliseconds = ' + difference + '<BR>');
document.write('difference in seconds = ' + difference/1000 + '<BR>');
document.write('difference in minutes = ' + difference/1000/60 + '<BR>');
document.write('difference in hours = ' + difference/1000/60/60 + '<BR>');
document.write('difference in days = ' + difference/1000/60/60/24 + '<BR>');*/
var one_year=1000*60*60*24*30*12;

if(todaymonth>=dobmonth)
one_year=Math.floor(difference/one_year);
else
one_year=parseInt(difference/one_year-1);
//one_year=Math.ceil(difference/one_year);
//alert(one_year);
/*
var daysDifference = Math.floor(difference/1000/60/60/24);
difference = difference - daysDifference*1000*60*60*24

var hoursDifference = Math.floor(difference/1000/60/60);
difference = difference - hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference = difference - minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);
*/
//document.write('difference = ' + daysDifference + ' day/s ' + hoursDifference + ' hour/s ' + minutesDifference + ' minute/s ' + secondsDifference + ' second/s ');
//alert(one_year);
return one_year; // form should never submit, returns false 
} 
/*
***************************Function for the Credit Card Checking*****************
**********************************************************************************
*/

//how to use
/*call 
CheckCardNumber(document.forms[0].CardNumber,document.forms[0].CardType,document.forms[0].ExpYear,document.forms[0].ExpMon)"
Here 
arg1- Cardnumber from form field
arg2-CardType(DropDown)
arg3-Year (textfield)
arg4- month (dropdown)
*/
<!-- Begin
var Cards = new makeArray(8);
Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new CardType("AmExCard", "34,37", "15");
var AmExCard = Cards[2];
Cards[3] = new CardType("DinersClubCard", "30,36,38", "14");
var DinersClubCard = Cards[3];
Cards[4] = new CardType("DiscoverCard", "6011", "16");
var DiscoverCard = Cards[4];
Cards[5] = new CardType("enRouteCard", "2014,2149", "15");
var enRouteCard = Cards[5];
Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16");
var JCBCard = Cards[6];
var LuhnCheckSum = Cards[7] = new CardType();

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/

function CheckCardNumber(frmCCNo,frmCCType,sYear,sMonth) {
var tmpyear;
//alert(sYear);
//alert(sMonth);
if (frmCCNo.value.length == 0) {
alert("Please enter a Card Number.");
frmCCNo.focus();
return;
}
if (sYear.length == 0) {
alert("Please enter the Expiration Year.");
frmYear.focus();
return;
}
if (sYear > 2004)
tmpyear = "19" + sYear;
else if (sYear< 2021)
tmpyear = "20" + sYear;
else {
alert("The Expiration Year is not valid.");
return;
}
//tmpmonth = frmMonth.options[frmMonth.selectedIndex].value;
tmpmonth = sMonth;
// The following line doesn't work in IE3, you need to change it
// to something like "(new CardType())...".
// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
alert("This card has already expired.");
return;
}
card = frmCCType.options[frmCCType.selectedIndex].value;
if (card.indexOf()<0)
{
	if (card=="AMEX" || card=="AmEx" || card=="amex" || card=="Amex")
	card="AmEx";
	card = card + "Card";
	//alert(card);
}
//card = "VisaCard"
var retval = eval(card + ".checkCardNumber(\"" + frmCCNo.value + "\", " + tmpyear + ", " + tmpmonth + ");");
//alert(retval);
cardname = "";
if (retval)
return true;
else {
// The cardnumber has the valid luhn checksum, but we want to know which
// cardtype it belongs to.
for (var n = 0; n < Cards.size; n++) {
if (Cards[n].checkCardNumber(frmCCNo.value, tmpyear, tmpmonth)) {
cardname = Cards[n].getCardType();
break;
   }
}
if (cardname.length > 0) {
alert("This looks like a " + cardname + " number, not a " + card + " number.");
return false;
}
else {
alert("This card number is not valid.");
return false;
      }
   }
}
/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year, 
                                        int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year        : year of expiry date.
month       : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
var n;
var argv = CardType.arguments;
var argc = CardType.arguments.length;

this.objname = "object CardType";

var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

this.setCardNumber = setCardNumber;  // set CardNumber method.
this.setCardType = setCardType;  // setCardType method.
this.setLen = setLen;  // setLen method.
this.setRules = setRules;  // setRules method.
this.setExpiryDate = setExpiryDate;  // setExpiryDate method.

this.setCardType(tmpcardtype);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpiryDate(argv[3], argv[4]);

this.checkCardNumber = checkCardNumber;  // checkCardNumber method.
this.getExpiryDate = getExpiryDate;  // getExpiryDate method.
this.getCardType = getCardType;  // getCardType method.
this.isCardNumber = isCardNumber;  // isCardNumber method.
this.isExpiryDate = isExpiryDate;  // isExpiryDate method.
this.luhnCheck = luhnCheck;// luhnCheck method.
return this;
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
var argv = checkCardNumber.arguments;
var argc = checkCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;

this.setCardNumber(cardnumber);
this.setExpiryDate(year, month);

if (!this.isCardNumber())
return false;
if (!this.isExpiryDate())
return false;

return true;
}
/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
return this.cardtype;
}
/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
return this.month + "/" + this.year;
}
/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
var argv = isCardNumber.arguments;
var argc = isCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
if (!this.luhnCheck())
return false;

for (var n = 0; n < this.len.size; n++)
if (cardnumber.toString().length == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
if (headdigit == this.rules[m])
return true;
}
return false;
}
return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;

if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

function isDouble(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

	for (i = 0; i < argvalue.length; i++)
		if ((argvalue.charAt(i) < '0' || argvalue.charAt(i) > '9') && (argvalue.charAt(i) != '.')) {
			//alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			//objField.focus();
			return false;
		}

/*for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9" || argvalue.substring(n, n+1)=".")
return false;*/

return true;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
var argv = luhnCheck.arguments;
var argc = luhnCheck.arguments.length;

var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

if (! isNum(CardNumber)) {
return false;
  }

var no_digit = CardNumber.length;
var oddoeven = no_digit & 1;
var sum = 0;

for (var count = 0; count < no_digit; count++) {
var digit = parseInt(CardNumber.charAt(count));
if (!((count & 1) ^ oddoeven)) {
digit *= 2;
if (digit > 9)
digit -= 9;
}
sum += digit;
}
if (sum % 10 == 0)
return true;
else
return false;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;
return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;
return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;
return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
// Create the len array.
if (len.length == 0 || len == null)
len = "13,14,15,16,19";

var tmplen = len;
n = 1;
while (tmplen.indexOf(",") != -1) {
tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
n++;
}
this.len = new makeArray(n);
n = 0;
while (len.indexOf(",") != -1) {
var tmpstr = len.substring(0, len.indexOf(","));
this.len[n] = tmpstr;
len = len.substring(len.indexOf(",") + 1, len.length);
n++;
}
this.len[n] = len;
return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
if (rules.length == 0 || rules == null)
rules = "0,1,2,3,4,5,6,7,8,9";
  
var tmprules = rules;
n = 1;
while (tmprules.indexOf(",") != -1) {
tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
n++;
}
this.rules = new makeArray(n);
n = 0;
while (rules.indexOf(",") != -1) {
var tmpstr = rules.substring(0, rules.indexOf(","));
this.rules[n] = tmpstr;
rules = rules.substring(rules.indexOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;
return this;
}
//  End -->
/*
***************************End Of Function for the Credit Card Checking*****************
**********************************************************************************
*/
function fnTotalChars(iLen,iMax)
{
	if (iLen>iMax)
	return false;
return;
}
function fnDateDiff(arg1,arg2)
{
	var dateArr1 = arg1.split("/");
	var dateArr2 = arg2.split("/");
	var dob  = new Date(dateArr1[2],dateArr1[0]-1,dateArr1[1],0,0,0);
	var dob1 = new Date(dateArr2[2],dateArr2[0]-1,dateArr2[1],0,0,0);
	var milliseconds1 = dob.getTime();
	var milliseconds2 = dob1.getTime();
	var difference = milliseconds1 - milliseconds2;
    difference = difference/1000/60/60/24;
	return difference;
}

function fnDateBetween(dFrom,dBet,dEnd)
{
		if (dFrom<=dBet && dBet<=dEnd)
		return 1;
		else
		return 0;
}
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}

function fnSubmit(iKey,frm,frmElem,sURL)
{
	frmElem.value=iKey;
	frm.action=sURL;
	frm.submit();
}



function fnImgSubmit()
{
	if (fnFrmValidator(document.forms[0]))
	document.forms[0].submit();
}

function OpenUploadImageForm(imagefor,objname,oldimagename)
{
	window.open("../UploadForm/ImgUploadform.asp?ImageFor="+imagefor+"&objname="+objname+"&oldimagename="+oldimagename,"","width=400,height=280");
}

function fnMaxChars(a,obj)
{
	if(obj.value.length>a) 
	return false;
}

// -->

