// ----------- don't change ---------------------



//-------------------------------------------------------------------
// credit card mth and year is valid
//-------------------------------------------------------------------
	function isCreditCardExpire(ccmth, ccyear) {
		var now, mth, yr
		now = new Date();
		mth=parseInt(now.getMonth()+1);
		yr=parseInt(now.getYear());
		//if ((parseInt(ccmth)<=mth) && (parseInt(ccyear)==yr)) {          
		if ((parseInt(ccmth)<mth) && (parseInt(ccyear)==yr)) 
		{          
			return false;
		}
		return true;
	}


	/*
	-------------------------------------------------------------------
	function isInt
	-------------------------------------------------------------------
	checks if the string is an integer value.
	
  	Input variables:	
		inputStr= String to be checked. 
	returns:  isInt=true 	:	inputStr is an integer.
         	  isInt=false	:	inputStr is not an integer.	
	--------------------------------------------------------------------		
  	*/
	
	function isInt(inputStr){
	var i 
		for (i = 0; i <inputStr.length; i++) {
			if (isNaN(inputStr.charAt(i))){
				return false;
				break;
			}
		}
		return true;
	}
	
	/*
	----------------------------------------------------------------
	function validcc
	----------------------------------------------------------------
	checks credit card number for nullity, numeric and integrate with
	function checkcc.
	
  	Input variables:	
		ccnumber= credit card number 
	returns:  validcc=true 	:	credit card is valid.
        	  validcc=false	:	credit card is invalid.
	--------------------------------------------------------------------		
  	*/
	
	function validcc(ccnumber, cctype)
	{	var result
		if (isEmpty(ccnumber))
		{	alert ("Please enter your credit card number");
			return false;
		}
		if (!isInt(ccnumber))
		{	alert("The credit card should only consists of digits.");
			return false;
		}
		result=checkcc(ccnumber,cctype);
//alert(result);
		if (result!=0)
		{	
			alert('Please check your credit card number.\nThe credit number you entered is invalid.');
			switch (parseInt(result))
			{
			case 1:
			//	alert ('wrong card type');
				break;
			case 2:
			//	alert('wrong length');
				break;
			case 3:
			//	alert('wrong card type and wrong length');				
				break;			
			case 4:
			//	alert('wrong checksum');				
				break;	
			case 5:
			//	alert('wrong card type and wrong checksum');				
				break;	
			case 6:
			//	alert('wrong checksum and wrong length');				
				break;	
			case 7:
			//	alert('wrong card type, length and checksum');				
				break;		
			case 8:
			//	alert('unknown card type');	
			default:
			}
			return false;
		}	
//		alert ('card is ok');
		return true;
	}

	/*
	------------------------------------------------------------------
	function checkcc
	------------------------------------------------------------------
	checks credit card number for checksum,length and type
  	Input variables:	
		ccnumber= credit card number 
		cctype:
  	       	"V" VISA
  	       	"M" Mastercard/Eurocard
         	"A" American Express
        	"C" Diners Club / Carte Blanche
        	"D" Discover
         	"E" enRoute
		 	"J" JCB
  returns:  checkcc=0 (Bit0) : card valid
            checkcc=1 (Bit1) : wrong type
            checkcc=2 (Bit2) : wrong length
            checkcc=4 (Bit3) : wrong checksum (MOD10-Test)
            checkcc=8 (Bit4) : cardtype unknown
	--------------------------------------------------------------------		
  	*/
	function checkcc(ccnumber, cctype)
	{
		var ctype, cnumber
		var cclength, ccprefix
		var prefixes, lengths
		var result, qsum, sum
		var ch
		var x
		
		ctype=cctype.toUpperCase();
		cnumber=ccnumber;

		switch (ctype)
		{
			case 'V' :
				cclength='13;16';
				ccprefix='4';
				break;
			case 'M':
				cclength='16';
			    ccprefix='51;52;53;54;55';
				break;
			case 'A':
				cclength='15';
			    ccprefix='34;37';
				break;			
			case 'C':
			    cclength='14';
			    ccprefix='300;301;302;303;304;305;36;38';
    			break;	
			case 'D':
				cclength='16';
				ccprefix='6011';
    			break;
			case 'E':
			   	cclength='15';
			   	ccprefix='2014;2149';
    			break;
			case 'J':
				cclength='15;16';
      			ccprefix='3;2131;1800';
    			break;
			default:
				cclength='';
			    ccprefix='';
  		}
		prefixes = ccprefix.split(";"); 
		lengths = cclength.split(";");
		
		prefixvalid=false;
		lengthvalid=false;

		i=0;
		do 	
		{	if (cnumber.indexOf(prefixes[i])==0) 
			{	prefixvalid=true;
			}
			i=i+1;
		} while (prefixes[i]!=null);

		i=0;
		do 	
		{	if (cnumber.length==parseInt(lengths[i])) 
			{	lengthvalid=true;
			}		
			i=i+1;
		} while (lengths[i]!=null);


		result=0
		if (!prefixvalid)
		{	result=result+1;
		}
		if (!lengthvalid)
		{	result=result+2;
		}

		qsum=0;
		for (x=1; x<cnumber.length+1; x++)
		{	ch=cnumber.charAt(cnumber.length-x);
			if ((x % 2)==0)
			{	sum=2 * parseInt(ch);
				qsum=qsum +(sum % 10);
				if (sum>9)
				{	qsum=qsum+1;
				}
			}	
        	else
			{	 qsum=qsum+parseInt(ch);
			}	 
		}

		if ((qsum % 10)!=0)
		{	result=result+4;
		}
		if (cclength=="")
		{	result=result+8;
		}
		return result;	
	}	



// ******************************************************************************************************
// isEmpty(inputStr)
// input: 	String 
// outPut: 	True if input string contains is empty or contain all spaces
// 	 	False if input string is not empty
// ******************************************************************************************************
function isEmpty(inputStr) {

	if (inputStr == null || inputStr == '') {
		return true;
	}
	else {
		if (isAllSpace(inputStr)) {
			return true;
		}
	}


	return false;		
}

// ******************************************************************************************************
// isAllSpace(inputStr)
// input: 	String 
// outPut: 	True if input string contains all spaces 
// 	 	False if input string does not contains all spaces 
// ******************************************************************************************************
function isAllSpace(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(vChar != ' ')
		{
			return false;
		}
	}

	return true;
}

// ******************************************************************************************************
// isQuote(inputStr)
// input: 	String 
// outPut: 	True if input string contain "
// 	 	False if input string does not contain "
// ******************************************************************************************************
function isQuote(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(vChar == '"')
		{
			return true;
		}
	}

	return false;
}



// ******************************************************************************************************
// IsDOB(inputStr)
// input: 	String
// outPut: 	True if string is  a valid date
//		False if string is not a valid date
// ******************************************************************************************************
function isDOB(inputStr)
            {
                var reDOB = /^[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}$/; 
           
                var strDOB = inputStr;

                if (!reDOB.test(strDOB)) 
                {
                    // window.alert("Please enter Date of Birth in the following format : DD-Mon-YYYY");
                    return false;
                }
            
                var iIdx = strDOB.indexOf("-");
                var objDOB = new Date(strDOB.substring(iIdx+1,iIdx+4) + " " + strDOB.substring(0,iIdx) + ", " + strDOB.substring(strDOB.length-4,strDOB.length) + " 00:00:00");
            
                //check if day is same because Javascript 
                //will move date forward eg 30 feb 2001 
                //becomes 2 mar 2001
                if (objDOB.getDate() != strDOB.substring(0,iIdx))
                {
                    // window.alert("Invalid date for Date of Birth.");
                    return false;
                }
                return true;
}

// ******************************************************************************************************
// isDate(inputStr)
// input: 	String
// outPut: 	True if string is  a valid date
//		False if string is not a valid date
// ******************************************************************************************************
/*function isDate(inputStr) {
                var reDOB = /^[0-9]{1,2}-[A-Za-z]{3}-[0-9]{4}$/; 
           
                var strDOB = inputStr;

                if (!reDOB.test(strDOB)) 
                {
                    // window.alert("Please enter Date of Birth in the following format : DD-Mon-YYYY");
                    return false;
                }

                var iIdx = strDOB.indexOf("-");
                var objDOB = new Date(strDOB.substring(iIdx+1,iIdx+4) + " " + strDOB.substring(0,iIdx) + ", " + strDOB.substring(strDOB.length-4,strDOB.length) + " 00:00:00");
            
                //check if day is same because Javascript 
                //will move date forward eg 30 feb 2001 
                //becomes 2 mar 2001
                if (objDOB.getDate() != strDOB.substring(0,iIdx))
                {
                    // window.alert("Invalid date for Date of Birth.");
                    return false;
                }
                return true;
}
*/





//---------------------------------------------------------------------------------------------------------------------


// ******************************************************************************************************


	/* Here's the list of tokens we support:
	   	m (or M) : month number, one or two digits.
	   	mm (or MM) : month number, strictly two digits (i.e. April is 04).
	   	d (or D) : day number, one or two digits.
	   	dd (or DD) : day number, strictly two digits.
	   	y (or Y) : year, two or four digits.
	   	yy (or YY) : year, strictly two digits.
	   	yyyy (or YYYY) : year, strictly four digits.
	   	mon : abbreviated month name (April is apr, Apr, APR, etc.)
	   	Mon : abbreviated month name, mixed-case (i.e. April is Apr only).
	   	MON : abbreviated month name, all upper-case (i.e. April is APR only).
	   	mon_strict : abbreviated month name, all lower-case (i.e. April is apr 
	         only).
	   	month : full month name (April is april, April, APRIL, etc.)
	   	Month : full month name, mixed-case (i.e. April only).
	   	MONTH: full month name, all upper-case (i.e. APRIL only).
	   	month_strict : full month name, all lower-case (i.e. april only).
	   	h (or H) : hour, one or two digits.
	   	hh (or HH) : hour, strictly two digits.
	   	min (or MIN): minutes, one or two digits.
	   	mins (or MINS) : minutes, strictly two digits.
	 	s (or S) : seconds, one or two digits.
	   	ss (or SS) : seconds, strictly two digits.
		ampm (or AMPM) : am/pm setting.  Valid values to match this token are
        	am, pm, AM, PM, a.m., p.m., A.M., P.M.
	*/
	// Be careful with this pattern.  Longer tokens should be placed before shorter
	// tokens to disambiguate them.  For example, parsing "mon_strict" should 
	// result in one token "mon_strict" and not two tokens "mon" and a literal
	// "_strict".

// ******************************************************************************************************
	
	var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mins|MINS|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");

	// lowerMonArr is used to map months to their numeric values.

	var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}
	
	// monPatArr contains regular expressions used for matching abbreviated months
	// in a date string.

	var monPatArr=new Array();
	monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
	monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
	monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
	monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');
	
	// monthPatArr contains regular expressions used for matching full months
	// in a date string.

	var monthPatArr=new Array();
	monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
	monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
	monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
	monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);
	
	// cutoffYear is the cut-off for assigning "19" or "20" as century.  Any
	// two-digit year >= cutoffYear will get a century of "19", and everything
	// else gets a century of "20".
	
	var cutoffYear=50;

	// FormatToken is a datatype we use for storing extracted tokens from the
	// format string.
	
	function FormatToken (token, type) {
		this.token=token;
		this.type=type;
	}

	function parseFormatString (formatStr) {
		var tokArr=new Array;
		var tokInd=0;
		var strInd=0;
		var foundTok=0;
    
		while (strInd < formatStr.length) {
			if (formatStr.charAt(strInd)=="%" &&
			(matchArray=formatStr.substr(strInd+1).match(tokPat)) != null) {
				strInd+=matchArray[0].length+1;
				tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
			} else {

			// No token matched current position, so current character should 
			// be saved as a required literal.

				if (tokInd>0 && tokArr[tokInd-1].type=="literal") {
					// Literal tokens can be combined.Just add to the last token.
					tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
				}
				else {
					tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
				}
   			}
		}
		return tokArr;
	}

	/* buildDate does all the real work.It takes a date string and format string,
	 tries to match the two up, and returns a Date object (with the supplied date
	 string value).If a date string doesn't contain all the fields that a Date
	 object contains (for example, a date string with just the month), all
	 unprovided fields are defaulted to those characteristics of the current
	 date. Time fields that aren't provided default to 0.Thus, a date string
	 like "3/30/2000" in "%mm/%dd/%yyyy" format results in a Date object for that
	 date at midnight.formatStr is a free-form string that indicates special
	 tokens via the % character.Here are some examples that will return a Date
	 object:

	buildDate('3/30/2000','%mm/%dd/%y') // March 30, 2000
	buildDate('March 30, 2000','%Mon %d, %y') // Same as above.
 	buildDate('Here is the date: 30-3-00','Here is the date: %dd-%m-%yy')

 	If the format string does not match the string provided, an error message
 	(i.e. String object) is returned.Thus, to see if buildDate succeeded, the
 	caller can use the "typeof" command on the return value.For example,
 	here's the isDate function, which returns true if a given date is
 	valid,and false otherwise (and reports an error in the false case):

	function isDate(dateStr,formatStr) {
		 var myObj=buildDate(dateStr,formatStr);
		 if (typeof myObj=="object") {
			 // We got a Date object, so good.
			 return true;
		 } else {
			 // We got an error string.
			 alert(myObj);
			 return false;
		}
	}

	*/

	function buildDate(dateStr,formatStr) {
		// parse the format string first.
		var tokArr=parseFormatString(formatStr);
		var strInd=0;
		var tokInd=0;
		var intMonth;
		var intDay;
		var intYear;
		var intHour;
		var intMin;
		var intSec;
		var ampm="";
		var strOffset;
	
		// Create a date object with the current date so that if the user only
		// gives a month or day string, we can still return a valid date.
		
		var curdate=new Date();
		intMonth=curdate.getMonth()+1;
		intDay=curdate.getDate();
		intYear=curdate.getFullYear();

		// Default time to midnight, so that if given just date info, we return
		// a Date object for that date at midnight.

		intHour=0;
		intMin=0;
		intSec=0;

		// Walk across dateStr, matching the parsed formatStr until we find a 
		// mismatch or succeed.
	
		while (strInd < dateStr.length && tokInd < tokArr.length) {

		// Start with the easy case of matching a literal.
	
		if (tokArr[tokInd].type=="literal") {
			if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd) {

				// The current position in the string does match the format 
				// pattern.
	
				strInd+=tokArr[tokInd++].token.length;
				continue;
			}
			else {

				// ACK! There was a mismatch; return error.
				return "\"" + dateStr + "\" does not conform to the expected format: " + formatStr;
			}
		}

		// If we get here, we're matching to a symbolic token.
		switch (tokArr[tokInd].token) {
			case 'm':
			case 'M':
			case 'd':
			case 'D':
			case 'h':
			case 'H':
			case 'min':
			case 'MIN':
			case 's':
			case 'S':
		
		// Extract one or two characters from the date-time string and if 
		// it's a number, save it as the month, day, hour, or minute, as
		// appropriate.
		
		curChar=dateStr.charAt(strInd);
		nextChar=dateStr.charAt(strInd+1);
		matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
		if (matchArr==null) {
	
		// First character isn't a number; there's a mismatch between
		// the pattern and date string, so return error.
	
		switch (tokArr[tokInd].token.toLowerCase()) {
		case 'd': var unit="day"; break;
		case 'm': var unit="month"; break;
		case 'h': var unit="hour"; break;
		case 'min': var unit="minute"; break;
		case 's': var unit="second"; break;
		}
		return "Bad " + unit + " \"" + curChar + "\" or \"" + curChar +
		nextChar + "\".";
		}
		strOffset=matchArr[0].length;
		switch (tokArr[tokInd].token.toLowerCase()) {
		case 'd': intDay=parseInt(matchArr[0],10); break;
		case 'm': intMonth=parseInt(matchArr[0],10); break;
		case 'h': intHour=parseInt(matchArr[0],10); break;
		case 'min': intMin=parseInt(matchArr[0],10); break;
		case 's': intSec=parseInt(matchArr[0],10); break;
		}
		break;
		case 'mm':
		case 'MM':
		case 'dd':
		case 'DD':
		case 'hh':
		case 'HH':
		case 'mins':
		case 'MINS':
		case 'ss':
		case 'SS':
	
		// Extract two characters from the date string and if it's a 
		// number, save it as the month, day, or hour, as appropriate.
		
		strOffset=2;
		matchArr=dateStr.substr(strInd).match(/^\d{2}/);
		if (matchArr==null) {
			
			// The two characters aren't a number; there's a mismatch 
			// between the pattern and date string, so return an error
			// message.
				
			switch (tokArr[tokInd].token.toLowerCase()) {
			case 'dd': var unit="day"; break;
			case 'mm': var unit="month"; break;
			case 'hh': var unit="hour"; break;
			case 'mins': var unit="minute"; break;
			case 'ss': var unit="second"; break;
			}
			return "Bad " + unit + " \"" + dateStr.substr(strInd,2) + 
			"\".";
		}
		switch (tokArr[tokInd].token.toLowerCase()) {
			case 'dd': intDay=parseInt(matchArr[0],10); break;
			case 'mm': intMonth=parseInt(matchArr[0],10); break;
			case 'hh': intHour=parseInt(matchArr[0],10); break;
			case 'mins': intMin=parseInt(matchArr[0],10); break;
			case 'ss': intSec=parseInt(matchArr[0],10); break;
		}
		break;
		case 'y':
		case 'Y':
	
		// Extract two or four characters from the date string and if it's
		// a number, save it as the year.Convert two-digit years to four
		// digit years by assigning a century of '19' if the year is >= 
		// cutoffYear, and '20' otherwise.
		
		if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
		
		// Four digit year.
			
		intYear=parseInt(dateStr.substr(strInd,4),10);
		strOffset=4;
		}
		else {
		if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {
		
			// Two digit year.
		
			intYear=parseInt(dateStr.substr(strInd,2),10);
			if (intYear>=cutoffYear) {
					intYear+=1900;
			}
			else {
				intYear+=2000;
			}
			strOffset=2;
		}
		else {

			// Bad year; return error.
		
			return "Bad year \"" + dateStr.substr(strInd,2) + 
			"\". Must be two or four digits.";
	   	}	
		}
		break;
		case 'yy':
		case 'YY':
	
		// Extract two characters from the date string and if it's a 
		// number, save it as the year.Convert two-digit years to four 
		// digit years by assigning a century of '19' if the year is >= 
		// cutoffYear, and '20' otherwise.

		if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {

		// Two digit year.

			intYear=parseInt(dateStr.substr(strInd,2),10);
			if (intYear>=cutoffYear) {
				intYear+=1900;
			}
			else {
				intYear+=2000;
			}
			strOffset=2;
		} else {
			// Bad year; return error
			return "Bad year \"" + dateStr.substr(strInd,2) + 
			"\". Must be two digits.";
		}
		break;
		case 'yyyy':
		case 'YYYY':
	
		// Extract four characters from the date string and if it's a 
		// number, save it as the year.
		
		if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
	
			// Four	digit year.

			intYear=parseInt(dateStr.substr(strInd,4),10);
			strOffset=4;
		}
		else {

			// Bad year; return error.

			return "Bad year \"" + dateStr.substr(strInd,4) + 
			"\". Must be four digits.";
		}
		break;
		case 'mon':
		case 'Mon':
		case 'MON':
		case 'mon_strict':

		// Extract three characters from dateStr and parse them as 
		// lower-case, mixed-case, or upper-case abbreviated months,
		// as appropriate.

		monPat=monPatArr[tokArr[tokInd].token];
		if (dateStr.substr(strInd,3).search(monPat) != -1) {
			intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
		}
		else {

			// Bad month, return error.
	
			switch (tokArr[tokInd].token) {
				case 'mon_strict': caseStat="lower-case"; break;
				case 'Mon': caseStat="mixed-case"; break;
				case 'MON': caseStat="upper-case"; break;
				case 'mon': caseStat="between Jan and Dec"; break;
			}
			return "Bad month \"" + dateStr.substr(strInd,3) + 
			"\". Must be " + caseStat + ".";
		}
		strOffset=3;
		break;
		case 'month':
		case 'Month':
		case 'MONTH':
		case 'month_strict':

		// Extract a full month name at strInd from dateStr if possible.

		monPat=monthPatArr[tokArr[tokInd].token];
		matchArray=dateStr.substr(strInd).match(monPat);
		if (matchArray==null) {
		
			// Bad month, return error.
	
			return "Can't find a month beginning at \"" +
			dateStr.substr(strInd) + "\".";
		}

		// It's a good month.

		intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
		strOffset=matchArray[0].length;
		break;
		case 'ampm':
		case 'AMPM':
		matchArr=dateStr.substr(strInd).match(/^(am|pm|AM|PM|a\.m\.|p\.m\.|A\.M\.|P\.M\.)/);
		if (matchArr==null) {

			// There's no am/pm in the string.Return error msg.

			return "Missing am/pm designation.";
		}

		// Store am/pm value for later (as just am or pm, to make things
		// easier later).

		if (matchArr[0].substr(0,1).toLowerCase() == "a") {

			// This is am.
			ampm = "am";
		}
		else {
			ampm = "pm";
		}
		strOffset = matchArr[0].length;
		break;
		}
		strInd += strOffset;
		tokInd++;
		}
		if (tokInd != tokArr.length || strInd != dateStr.length) {

		/* We got through the whole date string or format string, but there's 
		 more data in the other, so there's a mismatch. */

		return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: " + formatStr;
		}

		// Make sure all components are in the right ranges.
	
		if (intMonth < 1 || intMonth > 12) {
			return "Month must be between 1 and 12.";
		}
		if (intDay < 1 || intDay > 31) {
			return "Day must be between 1 and 31.";
		}

		// Make sure user doesn't put 31 for a month that only has 30 days

		if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31) {
			return "Month "+intMonth+" doesn't have 31 days!";
		}

		// Check for February date validity (including leap years) 
		
		if (intMonth == 2) {

			// figure out if "year" is a leap year; don't forget that
			// century years are only leap years if divisible by 400

			var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
			if (intDay > 29 || (intDay == 29 && !isleap)) {
			return "February " + intYear + " doesn't have " + intDay + 
			" days!";
		}
		}

		// Check that if am/pm is not provided, hours are between 0 and 23.

		if (ampm == "") {
			if (intHour < 0 || intHour > 23) {
				return "Hour must be between 0 and 23 for military time.";
			}
		}
		else {

			// non-military time, so make sure it's between 1 and 12.
	
			if (intHour < 1|| intHour > 12) {
				return "Hour must be between 1 and 12 for standard time.";
			}
		}

		// If user specified amor pm, convert intHour to military.
		if (ampm=="am" && intHour==12) {
			intHour=0;
		}
		if (ampm=="pm" && intHour < 12) {
			intHour += 12;
		}
		if (intMin < 0 || intMin > 59) {
			return "Minute must be between 0 and 59.";
		}
		if (intSec < 0 || intSec > 59) {
			return "Second must be between 0 and 59.";
		}
		return new Date(intYear,intMonth-1,intDay,intHour,intMin,intSec);
	}
//*********************************************************************************************************
// isDate(inputStr, formatStr)
// inputStr: 	String
// formatStr: 	String
// outPut: 	True if string is  a valid date
//		False if string is not a valid date
//
//Example :	isDate("06/06/2000", %dd/%mm/%yyyy)
//*********************************************************************************************************

	function isDate(dateStr,formatStr) {
		var myObj = buildDate(dateStr,formatStr);
	
		if (typeof myObj == "object") {
			// We got a Date object, so good.
			return true;
		}
		else {
			// We got an error string.
			alert(myObj);
			return false;
		}
	}


// ******************************************************************************************************
//------------------------------------------------------------------------------------------------------





// ******************************************************************************************************
// isDate1stGT2nd(inputStr1, inputStr2)
// input: 	String 1, String 2
// outPut: 	True if Date 1 is greater than Date 2
//		False if Date 1 is less than Date 2
// ******************************************************************************************************
function isDate1stGT2nd(inputStr1, inputStr2) {
	if ( Date.parse(inputStr1) <  Date.parse(inputStr2) ) {
			return false;
		}

	return true;
}


// ******************************************************************************************************
// isSimilar(inputStr1, inputStr2)
// input: 	String 1, String 2
// outPut: 	True if string 1 is same as string 2
//		False if string 1 is different from string 2
// ******************************************************************************************************
function isSimilar(inputStr1, inputStr2) {
	if(inputStr1 != inputStr2) {
		return false;
	}

	return true;
}


// ******************************************************************************************************
// isEmail(inputStr)
// input: 	String 
// outPut: 	True if input string is a valid e-mail 
// 	 	False if input string is not a valid e-mail 
// ******************************************************************************************************
function isEmail(inputStr) {

        //check email format
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
                
        if (reg1.test(inputStr) || !reg2.test(inputStr)) 
        {
                return false;
        }

	return true;
}


// ******************************************************************************************************
// isAlphanumeric(inputStr)
// input: 	String 
// outPut: 	True if input string is in Alphanumeric format
// 	 	False if input string is not in Alphanumeric format
// ******************************************************************************************************
function isAlphanumeric(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isAlphanumericCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}


// ******************************************************************************************************
// isPassword(inputStr)
// input: 	String 
// outPut: 	True if input string is a valid Password 
// 	 	False if input string is not a valid Password
// ******************************************************************************************************
function isPassword(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isPasswordCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}



// ******************************************************************************************************
// isAlphabet(inputStr)
// input: 	String 
// outPut: 	True if input string is a valid Alphabet 
// 	 	False if input string is not a valid Alphabet
// ******************************************************************************************************
function isAlphabet(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isLetterCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}

// ******************************************************************************************************
// isPhoneFax(inputStr)
// input: 	String 
// outPut: 	True if input string is a valid phone or fax character 
// 	 	False if input string is not a valid  phone or fax character 
// ******************************************************************************************************
function isPhoneFax(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isPhoneFaxCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}



// ******************************************************************************************************
// isInteger(inputStr)
// input: 	String 
// outPut: 	True if input string is an Integer 
// 	 	False if input string is not an Integer
// ******************************************************************************************************
function isInteger(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isIntegerCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}

// ******************************************************************************************************
// isPositiveValue(inputStr)
// input: 	String 
// outPut: 	True if input string is a positive value
// 	 	False if input string is not a positive
// ******************************************************************************************************
function isPositiveValue(inputStr) {
	var vCount = 0;

	for (vCount=0; vCount < inputStr.length; vCount++)
	{
		var vChar = inputStr.charAt(vCount);
		if(isPositiveValueCharacter(vChar))
		{
			return false;
		}
	}

	return true;
}


// ******************************************************************************************************
// isNRIC(inputStr)
// input: 	String 
// outPut: 	True if input string is a NRIC
// 	 	False if input string is not a valid NRIC
// ******************************************************************************************************
function isNRIC(inputStr)
{
        var reNRIC = /^(A|B|H|K|X|Y|S|T)[0-9]{7}[A-Z]{1}$/;
        if (!reNRIC.test(inputStr.toUpperCase()))
        {
		return false;
        }
        else
        {
        	//NRIC check digit verification
                if (!verifyNRIC(inputStr.toUpperCase()))
                {
                	return false;
                }
        }

	return true;
}


// ******************************************************************************************************
// isNRIC(inputStr)
// input: 	String 
// outPut: 	True if input string is a valid passport no format
// 	 	False if input string is not a valid passport no format
// ******************************************************************************************************
function isPassportNo(inputStr)
{
	var rePassport = /^[0-9A-Z]{7,15}$/;
	if (!rePassport.test(strIDN))
        {
		return false;
        }

        return true;
}




// ******************************************************************************************************
// the below functions will return a false if the input character is part of the character in the array
// ******************************************************************************************************

//function used for NRIC check digit verification
function getRemainderVar(hrn_no, t) {
	remainder_n	 = (parseInt(hrn_no.substring(1,2)) * 2 +
	parseInt(hrn_no.substring(2,3)) * 7 +
	parseInt(hrn_no.substring(3,4)) * 6 +
	parseInt(hrn_no.substring(4,5)) * 5 +
	parseInt(hrn_no.substring(5,6)) * 4 +
	parseInt(hrn_no.substring(6,7)) * 3 +
	parseInt(hrn_no.substring(7,8)) * 2 );
	if(t == "T") remainder_n = remainder_n + 4;
	remainder_n = remainder_n % 11;
        return remainder_n;
}

//function used for NRIC check digit verification
function getCheckDigit(chkvar) {
	retvar1 = "";
        if ( chkvar == 1 ) retvar1 = "A" ;
        if ( chkvar == 2 ) retvar1 = "B" ;
       	if ( chkvar == 3 ) retvar1 = "C" ;
       	if ( chkvar == 4 ) retvar1 = "D" ;
        if ( chkvar == 5 ) retvar1 = "E" ;
       	if ( chkvar == 6 ) retvar1 = "F" ;
       	if ( chkvar == 7 ) retvar1 = "G" ;
       	if ( chkvar == 8 ) retvar1 = "H" ;
       	if ( chkvar == 9 ) retvar1 = "I" ;
       	if ( chkvar == 10) retvar1 = "Z" ;
       	if ( chkvar == 11) retvar1 = "J" ;
      	return retvar1;
}


//verifies the NRIC check digit
function verifyNRIC(icno)
{
	pv_sum_n = getRemainderVar(icno, icno.substring(0,1));
	pv_sum_n = 11 - pv_sum_n;

        mv_check_digit_c = getCheckDigit(pv_sum_n);

	if (icno.substring(8,9) != mv_check_digit_c ) {

     		if ("STXY".indexOf(icno.substring(0,1)) >= 0 ) {
		        return false;
	        }
        }
	return true;
}

function isIntegerCharacter(inputChar) {
   	var vArray = new Array('1','2','3','4','5','6','7','8','9','0');
	for (j = 0; j < vArray.length; j++)
	{
   		if (inputChar == vArray[j]) 
		{
	   		return false;
		}
	}
	
   	return true;
}

function isPositiveValueCharacter(inputChar) {
   	var vArray = new Array('1','2','3','4','5','6','7','8','9','0','.');
	for (j = 0; j < vArray.length; j++)
	{
   		if (inputChar == vArray[j]) 
		{
	   		return false;
		}
	}
	
   	return true;
}

function isAlphanumericCharacter(inputChar) {
   	var vArray = new Array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',	'1','2','3','4','5','6','7','8','9','0',    '.','_',' ',    '(',')','-','#','+','@');
	for (j = 0; j < vArray.length; j++)
	{
   		if (inputChar == vArray[j]) 
		{
	   		return false;
		}
	}
	
   	return true;
}


function isPasswordCharacter(inputChar) {
   	var vArray = new Array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',	'1','2','3','4','5','6','7','8','9','0',  '_');
	for (j = 0; j < vArray.length; j++)
	{
   		if (inputChar == vArray[j]) 
		{
	   		return false;
		}
	}
	
   	return true;
}


function isPhoneFaxCharacter(inputChar) {
   	var vArray = new Array('(',')','-',',','1','2','3','4','5','6','7','8','9','0');
	for (j = 0; j < vArray.length; j++)
	{
    	if (inputChar == vArray[j])
		{
       		return false;
		}
	}
	
   	return true;
}

function isLetterCharacter(inputChar) {
   	var vArray = new Array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-',  '_', ' ');
	for (j = 0; j < vArray.length; j++)
	{
   		if (inputChar == vArray[j]) 
		{
	   		return false;
		}
	}
	
   	return true;
}


// ******************************************************************************************************
// StripBlanks(inputStr)
// input: 	String 
// outPut: 	String without leading and trailing blanks
// ******************************************************************************************************
function StripBlanks(inputStr) {

	var reStartBlanks = /^\s*/;
	var reEndBlanks = /\s*$/;
		
	inputStr = inputStr.replace(reStartBlanks,"");
	inputStr = inputStr.replace(reEndBlanks,"");

	return inputStr;
}

// ----------- don't change ---------------------


// ******************************************************************************************************
// validatenotempty(formfield)
// input: 	input field name of the form
// outPut: 	true/false
// ******************************************************************************************************

function validatenotempty(formfield)
{
	var flag
	flag=false;
	for (i=0; i<formfield.length; i++)
	{		flag=(formfield[i].checked||flag);
	}
	return flag;
}

function uncheckall(formfield)
{
	for (i=0; i<formfield.length; i++){		
			formfield[i].checked=false;
	}
}


function cancelvalidation(inputform)
{
	if (confirm("Are you sure you want to abort your changes?")){
		inputform.action='cancel.asp';
		return true;
	}
	else	
	{	return false;
	}
}

function reauthenticate_window()
{
	var winurl
	winurl = '/ICIS/Application/nh/engine/icis_reauthenticate.pasp';
	var newwin = open(winurl, 'Reauthenticate', 'RESIZABLE=No,WIDTH=300,HEIGHT=250');
	newwin.location = winurl;
	if(newwin.opener == null) {newwin.opener = self;}
	newwin.focus();
}
function refresh_submit_status(formfield, formfieldvalue)
{
	formfield.value=formfieldvalue;
}

function getage(dob){
	var dobmonth = dob.substring(dob.indexOf("/")+1, dob.lastIndexOf("/"));
	if (dobmonth.substring(0,1) == "0" && dobmonth.length > 1)
        	dobmonth = dobmonth.substring(1,dobmonth.length);
        	dobmonth = parseFloat(dobmonth);
	var dobday = dob.substring(0,dob.indexOf("/"));
	if (dobday.substring(0,1) == "0" && dobday.length > 1)
		dobday = dobday.substring(1,dobday.length);
		dobday = parseFloat(dobday);
	var dobyear  = parseFloat(dob.substring(dob.lastIndexOf("/") + 1, dob.length));
	var today=new Date();
	var age=parseFloat(today.getYear())-dobyear;
	if (!(dobday==1 && dobmonth==1)) age--;
	return age;
}


