// FormValidate.js: validate form fields at the occurrence of an onSubmit event
// Written By: Kevin R. DuPre'
// Date: 3/3/98

// a cancel button event handler - if we have a cancel button this becomes an
// onClick() handler. The "cancel_flag" if set causes an immediate true return
// of the onSubmit() handler validate() effectively bypassing validation on a
// form which uses a cancel_button submit element to skip an operation on form
// contents. Since a cancel_button causes the form to be submitted to an action
// which can make a determination of which button was pressed, the life cycle of
// cancel_flag is one click, as the form will no longer be present and will have
// cancel_flag initialized on each onLoad() event.

var cancel_flag = 0;

function setCancel(){
	cancel_flag = 1;
}

// form validation and error alert routine
// Modified on 01/18/2001 by Sowmya to test for select dropdown  element in required check

function validate(f) {

	// if cancel flag has been set by an onClick() event handler for a button
	// simply return true, the form has nothing of interest to check

	if(cancel_flag == 1)
		return true;

	var msg;
	var empty_fields = "";
	var errors = "";
	var prevRadioName;
        var sumOfFields = 0;


	// first loop through all the elements of the form checking for required
	// fields
	for(var i = 0; i < f.elements.length; i++){
		var e = f.elements[i];

		// check for requiredness or min/max length
		if(e.isrequired){
			if ((e.type == "select-one") || (e.type == "select-multiple")){
				if (e.selectedIndex != -1){
				  var opt = new Option;
				  opt = e.options[e.selectedIndex];
				  if ((opt.value == null) || (opt.value == "")){
				     empty_fields += "\n        '" + fieldnames[e.name] + "'";
				  }
				}
				else {
				  empty_fields += "\n        '" + fieldnames[e.name] + "'";
				}
			}
			else{
				if((e.value == null) || (e.value == "") || isblank(e.value)){
					if (e.type == "radio") {
					    if (e.name != prevRadioName){
						empty_fields += "\n        '" + fieldnames[e.name] + "'";
					    }
					    prevRadioName = e.name;
					}
					else{
					    empty_fields += "\n        '" + fieldnames[e.name] + "'";
					}
				}
			}
		}
		if(e.minlength){
			if(e.value.length > 0 && e.value.length < e.minlength){
				errors += "- The field '" + fieldnames[e.name] + "' needs to be a minimum of " + e.minlength + " characters long.\n";
			}
		}

		if(e.maxlength){
			if(e.value.length > 0 && e.value.length > e.maxlength){
			    errors += "- The field '" + fieldnames[e.name] + "' needs to be less than" + e.maxlength + " characters long.\n";
			}
		}

		// check for max select/option size.
		if(e.maxselectsize){
		      if (e.length > 0 && e.length >= e.maxselectsize){
		      errors += "- The field '" + fieldnames[e.name] + "' can have a maximum of " + e.maxselectsize + " values.\n";
		  }
		}

	}


	for(var i = 0; i < f.elements.length; i++){
		var e = f.elements[i];

		if (e.begindate){
		  var mbegindate = e.value;
		}

		if (e.enddate){
		  var menddate = e.value;
		}

		if (e.givendate){
		  var mgivendate = e.value;
		}

		if (e.message){
		  var mmessage = e.value;
		}
                if (e.getMessage) {
		    errors += "- " + mmessage + "\n";
                }
                if (e.futuredays){
                    var mfuturedays = e.value;
                }

		if (e.isloginid){
			var loginid = e.value;
		}
		if(e.iscurrentpassword){
			var currentpassword = e.value;
		}
		if (e.ispassword){
			var password = e.value;
		}
		if (e.isconfirmpassword){
			var confirmpassword = e.value;
		}
		if (e.ispasswordhint){
			var passwordhint = e.value;
		}
		if (e.isstatus){
			var status = e.value;
		}
		if (e.checkhint){
			var passwordhint = e.value;
		}

                //Adds a number to sumOfFields
                if (e.addToTotal){
                        if (!isNaN(parseFloat(e.value))){
                          sumOfFields = sumOfFields + parseFloat(e.value);
                        }
                }

		//Check for a value in a given comma delimited String
		if (e.checkduplicates){
		  if(!CheckDuplicates(e.value)){
		    errors += "- " + mmessage + "\n";
		  }
		}

                //Check if sumOfFields is greater than zero
                if (e.checkSumOfFieldsGreaterThanZero){
                    if (!isNumberGreaterThanZero(sumOfFields)){
                        errors += "- " + mmessage + "\n";
                    }
                }

		//Check for beginning date less that ending date
		if (e.comparedates){
		  if(!CompareDates(mbegindate,menddate)){
		     errors += "- " + mmessage + "\n";
		  }
		 }

		//Check for date between two given dates.
		if (e.isdatebetween){
		   if(!CheckDateBetween(mbegindate,menddate,mgivendate)){
		      errors += "- "+ mmessage +" \n";
		  }
		}

                //check if input date is not more than future date
                if(e.checkfuturedate){
                    if(!CheckDateWithFutureDays(mgivendate, mfuturedays)){
                                errors += "- The " + fieldnames[e.name] + " cannot be more than " + mfuturedays + " days in future.\n";
                     }
                }

		//Check for currentpassword doesn't match new password
		if(e.checknewpwd){
			if(!isvalidnewpassword(currentpassword, password)){
				errors += "- Please correct the new password. It cannot be the same as the current password.\n";
			}

		}
		//Check for password doesn't match loginid
		if (e.checkpwd){
			if(!isvalidpassword(password,loginid)){
				errors += "- Please correct the password. It cannot be the same as the User Id.\n";
			}
		}
		//Check for password doesn't match confirmpassword
		if (e.checkconfirmpwd){
			if(!isvalidconfirmpassword(password,confirmpassword)){
				errors += "- Confirm password does not match with password.\n";
			}
		}
		//Check for password hint cannot match password
		if (e.checkpwdhint){
			if(!isvalidpwdhint(password,passwordhint)){
				errors += "- Please correct the password hint. It cannot be the same as the password.\n";
			}
		}

		//Check for password hint cannot contain password
		if (e.checkhint){
			if(!isvalidhint(password,passwordhint)){
				errors += "- Please correct the password hint. It cannot include the password.\n";
			}
		}

		//Check for password hint cannot match password
		if (e.chkstatus){
			if(!isvalidstatus(status)){
				errors += "- Please correct the status. You can change the password only if user's.\n";
				errors += "  status is Approved or Password Reset.\n";
			}
		}


		if((e.type == "text"||e.type=="hidden"||e.type=="password") && e.value.length > 0){
			// check for alphaness
			if(e.isalphaonly){
				if(!isalpha(e.value)){
				    errors += "- The field '" + fieldnames[e.name] + "' must contain only alphabetic letters.\n";
				}

			}
			//check for containing both alphaness and number
			if(e.isalphaonnum){
				if(!hasnumeric(e.value)){
				    errors+="- The field '"+fieldnames[e.name]+"' must contain both letters and number \n";
				}
				if(!hasalpha(e.value)){
				    errors+="- The field '"+fieldnames[e.name]+"' must contain both letters and number \n";
				}

			}


			// check if valid date format
			if(e.isdate){
				if(!isvaliddate(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain a valid date of the form mm/dd/yyyy.\n";
				}
			}

			// check if valid Street address characters
			if(e.isstreetaddress){
				if(!isstreetaddress(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only a street address.\n";
				}
			}

			// check if valid Street address characters
			if(e.iscity){
				if(!iscity(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only a city name.\n";
				}
			}

         //check for single value greater than zero or not
         if(e.isValueGreaterThanZero) {
           if(!isNumberGreaterThanZero(e.value)) {
             errors += "- The field '" + fieldnames[e.name] + "' must be greater than zero.\n";
           }
         }

         // check if valid NANP-style phone number
			if(e.isnanpphone){

				if(!isnanpphone(e.value)){
						errors += "- The field '" + fieldnames[e.name] + "' must contain only a phone number of the form NNN-NNN-NNNN or NNN.NNN.NNNN \n";
				}
			}

			// check for numericness
			if(e.isnumericonly){
				if(!isnumeric(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only numbers.\n";
				}
			}

			// check for floatness
			if(e.isfloat){
				if(!isfloat(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only numeric values.\n";
				}
			}

         // check for money
			if(e.ismoney){
				if(!ismoney(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain valid money type of form 0.00\n";
				}
			}

			// check for propernameness
			if(e.ispropername){
				if(!ispropername(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only letters, the '.', the ' ', the '\'' or the ',' characters.\n";
				}
			}

			// check for valid email
			if(e.isvalidemail){
				if(!isvalidemail(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only a valid email id.\n";
				}
			}

			// check for alphanumericness
			if(e.isalphanumonly){
				if(!isalphanum(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only letters or numbers.\n";
				}
			}


			// check for stateabbrevness
			if(e.isstate){
				if(!isalpha(e.value) || e.value.length != 2){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only a 2 letter state abbreviation.\n";
				}
			}

			// check for us-zipness
			if(e.isuszipcode){
				if(!isuszip(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only a valid numeric 5 digit zipcode.\n";
				}
			}
			// check for zipness
			if(e.iszip){
				if(!iszipcode(e.value)){
					errors += "- The field '" + fieldnames[e.name] + "' must contain only valid zipcode.\n";
				}
			}
		}
	}

	// if there were no errors return true, else display the messages
	// and return false to prevent the form from being submitted
	if(!empty_fields && !errors)
		 return true;

	msg = "_______________________________________\n\n";
	msg += "The form was not submitted because of the following error(s):\n";
	msg += "Please correct these errors(s) and re-submit.\n";
	msg += "_______________________________________\n\n";

	if(empty_fields){
		msg += "-  The following field(s) are required:" + empty_fields + "\n";
	}

	if(errors){
		msg += "\n";
	}

	msg += errors;
	alert(msg);
	return false;
}


// utility function that returns true if a string contains only
// whitespace chars

function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t'))
			return false;
	}
	return true;
}

// utility function that returns true if a string contains only
// alpha characters

function isalpha(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c < 'A') || ((c > 'Z') && (c < 'a')) || (c > 'z'))
			return false;
	}
	return true;
}

// utility function that returns true if a string contains only
// numeric characters

function isnumeric(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c < '0') || (c > '9'))
			return false;
	}
	return true;
}

/* Accepts numeric, decimal point and commas.
   Checks if not more than one decimal point exists
   Checks if number of digits after decimal point does not exceed 2

*/
function isfloat(s){

	var aString = new String(s);

	//if the value is only a dot, return false...
	if (aString == "."){
	  return false;
	}

	//Remove commas from input before performing any validation
	for(var i = 0; i < s.length; i++){
	      var c = s.charAt(i);
	      if (c == ","){
		s = aString.substring(0, i) + aString.substring(i+1, s.length);
		aString = s;
	      }
	}
	for(var i = 0; i < s.length; i++){
	      var c = s.charAt(i);
	      var dp = 0;
	      if(((c < '0') || (c > '9')) && (c != '.'))
		      return false;
	      if(c == '.')
		      dp++;
	}
	//If more than one decimal point, return false
	if(dp > 1)
	   return false;
       //Count number of digits before decimal point
	c = s.charAt(0);
	var count = 0;
	for(var i = 0; i < s.length && c != '.'; i++){
		count = count + 1;
		c = s.charAt(i);
	}
	if ((c == '.') && (count > 0))
		count = count - 1;

	//Any check for number of digits before decimal point goes here
	/*if (count > 1)
		return false;
	*/
       //Count number of digits after decimal point
       //If count == s.length there is no decimal point
	var countdec = 0;
	if (count != s.length){
		for (var i = count+1; i < s.length; i++){
			countdec++;
		}
		//if number of digits after decimal point is greater than 2, return false
		if (countdec > 2)
			return false;
	}
	return true;
}


//*********************************************************************************

//Sultan Ahmed 10/31/2001


function isvaliddate(s){


	//Check for valid data lengths
	if(s.length > 10 || s.length < 8)
	    return false;


	//Check for Slash as a date seperator
	var x = s.split("/");
	if (x.length < 3)
		return false;


	//Check for proper DAY, month and Year

	var x = s.split("/");
	if (x[0].substring(0,1) == 0)
		x[0] =x[0].substring(1,2);
	var user_mon  = parseInt(x[0]);
	if (x[1].substring(0,1) == 0)
		x[1] =x[1].substring(1,2);
	var user_day  = parseInt(x[1]);
	var user_year = parseInt(x[2]);


	if(isNaN(user_mon) || isNaN(user_day) || isNaN(user_year))
		return false;

	if (user_mon < 1 || user_mon > 12)
		return false;

	if (user_mon == 1 || user_mon == 3 || user_mon == 5 || user_mon == 7 || user_mon == 8 || user_mon == 10 || user_mon == 12 ) {
		if (user_day > 31)
			return false;
	} else 	if (user_mon == 4 || user_mon == 6 || user_mon == 9 || user_mon == 11 ) {
		if (user_day > 30 )
			return false;
	} else {
		if (isLeapYear(user_year)) {
			if (user_day > 29)
				return false;
		} else {
			if (user_day > 28)
				return false;
		}
	}

	return true;

}




//*********************************************************************************






// utility function that returns true if a string contains only
// a valid date of the form mm/dd/yyyy

function isvaliddateOLD(s){
	if(s.length != 10)
	    return false;

	for(var i = 0; i < s.length; i++){
	    var c = s.charAt(i);
		if(i != 2 && i != 5 ) {
			if ((c < '0') || (c > '9'))
					return false;
		} else {
			if(c != '/' && c != ' ')
				return false;
		}
	}

	var user_mon  = s.substring(0, 2);
	var user_day  = s.substring(3, 5);
	var user_year = s.substring(6, 10);

	if (user_mon < 01 || user_mon > 12)
		return false;

	if (user_mon == 01 || user_mon == 03 || user_mon == 05 || user_mon == 07 || user_mon == 08 || user_mon == 10 || user_mon == 12 ) {
		if (user_day > 31)
			return false;
	} else 	if (user_mon == 04 || user_mon == 06 || user_mon == 09 || user_mon == 11 ) {
		if (user_day > 30 )
			return false;
	} else {
		if (isLeapYear(user_year)) {
			if (user_day > 29)
				return false;
		} else {
			if (user_day > 28)
				return false;
		}
	}

	return true;
}


function isLeapYear(myYear) {
	if (myYear % 4 == 0) {
		if (myYear % 100 == 0 ) {
			if (myYear % 400 == 0 )
				return true;
			else
				return false;
		} else
			return true;
	} else
		return false;

	return true;
}

// utility function that returns true if a string contains only
// alphanumeric characters

function isalphanum(s){

	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))){
			return false;
		}
	}
	return true;
}

// utility function that returns true if a string contains only
// alpha characters or the '.' or ',' characters

function ispropername(s){

	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) && (c != '.') && (c != ',') && (c != ' ') && (c != '\'') && (c != '&') && (c != '/') && (c != '-')){
			return false;
		}
	}
	return true;
}

// utility function that returns true if a string contains only
// valid street address characters

function isstreetaddress(s){

	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) && (c != '.') && (c != ',') && (c != ' ') && (c != '\'') && (c != '#')){
			return false;
		}
	}
	return true;
}

// utility function that returns true if a string contains only
// valid street address characters

function iscity(s){

	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) && (c != '.') && (c != ' ')){
			return false;
		}
	}
	return true;
}

// utility function that returns true if a string is a NANP phone
// number of the form NNN-NNN-NNNN or NNN.NNN.NNNN

//Modified on 1/17/2001 by Sowmya Srinivasan
// Area code is required. So NNN-NNNN or NNN.NNNN are invalid formats


function isnanpphoneOld(s){
	if(s.length != 12)
	    return false;
	for(var i = 0; i < s.length; i++){
	    var c = s.charAt(i);
		if(i != 3 && i != 7){
			if((c < '0') || (c > '9'))
				return false;
		} else {
			if(c != '-' && c != '.')
				return false;
		}
	}
	return true;

}


function isvalidpassword(s,loginid)
{
	var ret = true;
	if ((s != "") && (loginid != ""))
		{
		if (s == loginid)
			{
				ret = false;
			}
		}
		return ret;
}

function isvalidnewpassword(currentpassword, newpassword)
{
	var ret = true;
	if ((currentpassword != "") && (newpassword != ""))
		{
		if (currentpassword == newpassword)
			{
				ret = false;
			}
		}
	return ret;
}

function isvalidconfirmpassword(pwd, confirmpwd){
	var ret = true;
	if ((pwd != "") && (confirmpwd != ""))
		{
		if (pwd != confirmpwd)
			{
				ret = false;
			}
		}
		return ret;
}

function isvalidpwdhint(pwd,pwdhint)
{
	var ret = true;
	if ((pwd != "") && (pwdhint != ""))
		{
		if (pwd == pwdhint)
			{
				ret = false;
			}
		}
		return ret;
}



function isvalidstatus(status)
{
	if ((status == 1) || (status == 4))
		{
			return true;
		}
	else
		{
			return false;
		}

}
//New phone number validation function -- use of Regular expressions
//Sultan Ahmed 02/08/2001

function isnanpphone(s)
{
	var ret = false;
	var str = s.toString();


	if(str.length == 12)
	   ret = true;

	if (ret == true)
		{

			var expdot = /\d{3}[.]\d{3}[.]\d{4}/;
			var expdash = /\d{3}[-]\d{3}[-]\d{4}/;

			if (str.match(expdot))
				ret = true;
			else
				ret = false;

			if (ret	 == false)
				{
				if (str.match(expdash))
					ret = true;
				}
		}


return ret;

}

//function to validate money
//added by fayaz--using the regular expressions
 function ismoney(s) {
  var str = s.toString();
  //checking for default double value
  if(str==".00") {
    return true;
  }

  var moneyPattern=/^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?$/;
  if(moneyPattern.test(str)) {
    return true;
  }
  else {
    return false;
   }
 }
 //end of the method ismoney



// utility function that returns true if a string contains only US
// zipcode chars, either zip or zip+4 (NNNNN or NNNNN-NNNN)

function isuszip(s){
	if(s.length != 5 && s.length != 10)
	    return false;
	for(var i = 0; i < s.length; i++){
	    var c = s.charAt(i);
		if(s.length == 10){
			if(i != 5){
				if((c < '0') || (c > '9'))
					return false;
			} else {
				if(c != '-')
					return false;
			}
		} else {
			if((c < '0') || (c > '9'))
				return false;
		}
	}
	return true;
}

//utility function for checking uszip's and canadian zips
function iszipcode(s){
	if(s.length > 10){
		return false;
	}else{
		if(s.length == 7){
			if(iscanadianzip(s)){
				return true;
			}else{
				return false;
			}
		}else{
			if(isuszip(s)){
				return true;
			}else{
				return false;
			}
		}
	}
}
//utility function to check for valid canadian zip
function iscanadianzip(s){
        if(isalpha(s.substring(0,1))){
		if(isnumeric(s.substring(1,2))){
			if(isalpha(s.substring(2,3))){
				if(s.substring(3,4) == " "){
					if(isnumeric(s.substring(4,5))){
						if(isalpha(s.substring(5,6))){
							if(isnumeric(s.substring(6,7))){
								return true;
							}else{
								return false;
							}
						}else{
							return false;
						}
					}else{
						return false;
					}
				}else{
					return false;
				}
			}else{
				return false;
			}
		}else{
			return false;
		}
	}else{
		return false;
	}
}
function isvalidemail(s){
	var done = 0;
	var firstpos = 0;
	var donedot = 0;
	var firstdotpos = 0;
	var pos = 0;
	var dotpos = 0;

	for(var i = 0; i < s.length; i++)
	{
	 var ch = s.charAt(i);

	 //First character has to be alphanumeric
	 if ((i==0) && (!(((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))))
	      return false;

	 if (!( ((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z'))) && (ch != '@') && (ch != '_') && (ch != '.') && (ch != '-'))
		return false;

	 //@ should exist in email address
	 if (ch == '@'){
		done = 1;
		if (firstpos == 0){
			pos = i + 1;
			firstpos = 1;
		}
	 }

	//. should exist in email address
	 if (ch == '.'){
		donedot = 1;
		if (firstdotpos == 0){
			dotpos = i + 1;
			firstdotpos = 1;
		}
	 }
	} // end for

	if ((done == 1) && (donedot == 1)) {
		//Character after @ should be alphanumeric
		c = s.charAt(pos);
		if(!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
			return false;
		//Character after . should be alphanumeric
		c = s.charAt(dotpos);
		if(!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
			return false;
		else
			return true;
	} else
		return false;
}

// utility function that returns true if a string contains numbers
function hasnumeric(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c >= '0') && (c <= '9'))
			return true;
	}
	return false;
}

// utility function that returns true if a string contains alpha
function hasalpha(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
			return true;
	}
	return false;
}

// Function added by fayaz for testing whether the date is greater than the current date
function checkCurrentDate(d) {

todayDate = new Date();
 var Month = parseInt(d.dateMonth.options[d.dateMonth.selectedIndex].value);
 var actualMonth = Month-1;
 var Day = parseInt(d.dateDay.options[d.dateDay.selectedIndex].value);
 var Year = parseInt(d.dateYear.options[d.dateYear.selectedIndex].value);
 var getDate = new Date(Year, actualMonth, Day);
// Convert the date to a string so we can parse it.
 var GetMonth = getDate.getMonth();

/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */

 if (getDate <= todayDate){
    return true;
 }
  else if(GetMonth !=actualMonth) {
    return false;
  }

 }

//Sultan Ahmed 10/31/2001
//This function given two dates begin date and end date,
//returns true if the ending date is greater that the beginning date.


function CompareDates(aBdate,aEdate)
{

    var tmp;

    tmp = aBdate.split("/");
    var bm = parseInt(tmp[0]);
    var bd = parseInt(tmp[1]);
    var by = parseInt(tmp[2]);

    tmp = aEdate.split("/");
    var em = parseInt(tmp[0]);
    var ed = parseInt(tmp[1]);
    var ey = parseInt(tmp[2]);


     if (by == ey)
	{
	    if (bm == em){
	      if (bd > ed){
		     return false;
	      }
	    }
	    else if (bm > em){
	      return false;
	    }
	}
      else if (by > ey){
	return false;
      }

  return true;
}

//Author: Sultan Ahmed

function CheckDateBetween(fdate,sdate,tdate){

  var fdate = new Date(Date.parse(fdate));
  var sdate = new Date(Date.parse(sdate));
  var tdate = new Date(Date.parse(tdate));

  if(tdate < fdate || tdate > sdate)
    return false;

  return true;
}

//Author: Sultan Ahmed

function CheckDuplicates(strArray){
  var myArray = strArray.split(",");
  var tmp;

  for (i=0;i<myArray.length;i++)
  {
    tmp =  myArray[i].split("|");

    if (parseInt(tmp[1]) >= 2){
      return false;
    }
  }

  return true;
}

//Checks if the input number is greater than 0
function isNumberGreaterThanZero(num){
  if (num > 0)
    return true;
  else
    return false;
}




function CheckDateWithFutureDays(cdate, daysinfuture){

 daysinfuture = parseInt(daysinfuture) + parseInt(32);
 var currentDate = new Date(Date.parse(cdate));
 var futureDate = new Date();

 futureDate.setDate(daysinfuture);

 if (currentDate <= futureDate)
	return true;
 else
	return false;

}

// Original:  Cyanide_7 (leo7278@hotmail.com) -->
// Web Site:  http://members.xoom.com/cyanide_7 -->
//The autoTab, containeElement and getIndex function are used for the auto tab feature for SSN and phone number fields
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
if(isNN)
  document.captureEvents(Event.KEYPRESS);
function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode;
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
  input.value = input.value.slice(0, len);
  input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
  var found = false, index = 0;
  while(!found && index < arr.length)
  if(arr[index] == ele)
  found = true;
  else
  index++;
  return found;
}

function getIndex(input) {
  var index = -1, i = 0, found = false;
  while (i < input.form.length && index == -1)
  if (input.form[i] == input)index = i;
  else i++;
  return index;
  }
  return true;
}

function isvalidhint(pwd,pwdhint)
{
	var ret = true;
	if ((pwd != "") && (pwdhint != ""))
		{
		if (pwdhint.indexOf(pwd) != -1)
			{
				ret = false;
			}
		}
		else
		    ret = true;
		return ret;
}

function valOfFields(field)
{
   var valOfFields = 0;
   if(field != null)
   {
       newVal = removeComma(field.value);
       if (!isNaN(parseFloat(newVal)))
       {
            valOfFields = valOfFields + parseFloat(newVal);
       }
   }
   return valOfFields;

}
//Remove commas from input
function removeComma(s)
{
	var newString = new String(s);
	for(var i = 0; i < s.length; i++){
      	var c = s.charAt(i);
      	if (c == ","){
			s = newString.substring(0, i) + newString.substring(i+1, s.length);
			newString = s;
	    }
	}
	return newString;
}
//Remove prefix from input
function removePrefix(s)
{
    var newString = new String(s);
    for(var i = 0; i < s.length; i++){
    var c = s.charAt(i);
    if(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))){
                    s = newString.substring(1, s.length);
                    newString = s;
        }
    }
    var tempId = newString;
    for(var i = 0; i < newString.length; i++){
    var c = newString.charAt(i);
    if(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))){
                    newString = newString.substring(1, newString.length);
                    tempId = newString;
        }
    }
    return tempId;
    /*
    if(hasalpha(s))
    {
      var tempId = s;
      s = tempId.substr(2,tempId.length);
    }
    return s;*/

}

//function to display floats
function displayFloat(origVal, deciVal)
{
     var result=Math.round(origVal*(Math.pow(10,deciVal)))/(Math.pow(10,deciVal));
     return result;
}




//Added by: Sultan Ahmed 09/16/2002


function fixDecimals(d){

	var sDouble = "";
	var retValue = "";

	var nPos = d.indexOf ( '.' );

	if ( nPos < 0 ){
	   retValue = d+'.00';
	}else{

      var tmp = d.split(".");
      var l = tmp[0]
      var r = tmp[1];

      if (r.length < 2){
		  sDouble = r;
		  var nZero = 2	- r.length;
		  for ( var i=0; i<nZero; i++ ){
			sDouble += '0';
		  }
      }else if (r.length > 2){
		  sDouble = r.substring(0,2);
      }else{
		sDouble = r;
      }
      retValue = l + "." + sDouble;

	}

	return retValue;


	}




function getDisplayDouble(str){

	str = str.replace(/[,]/g,"");

	var t = 0;
	var textFormat = "";
	var tmp;
	var decimalPortion;

	str = fixDecimals(str);

	tmp = str.split(".");
	str = tmp[0];
	decimalPortion = tmp[1];


	if (str.length != 0){
		for (var k = str.length-1; k>=0 ; k--){
			t++;

			if (t % 3 == 0){
				textFormat = "," + str.substr(k,1) + textFormat;
			} else {
				textFormat =  str.substr(k,1) + textFormat;
			}
		}

		if (textFormat.substr(0,1) == ","){
			textFormat = textFormat.substr(1,textFormat.length-1);
		}
	}

	return textFormat + "." + decimalPortion;

}



function getDoubleValue(str){
    if(str == ""){
       return str;
    }else{
       str = str.replace(/[,]/g,"");
       if(isnumeric(str)){
            return parseFloat(str);
       }else{
          return str;
       }
    }
}

/**
 * This methods will grey out the button on master enquiry and required search places
 */
function disableone(str){
   document.all(str).disabled =true;
}

function disabletwo(str1,str2){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
}

function disablethree(str1,str2, str3){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
}

function disablefour(str1,str2, str3, str4){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
   document.all(str4).disabled =true;
}

function disablefive(str1,str2, str3, str4, str5){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
   document.all(str4).disabled =true;
   document.all(str5).disabled =true;
}

function disablesix(str1,str2, str3, str4, str5, str6){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
   document.all(str4).disabled =true;
   document.all(str5).disabled =true;
   document.all(str6).disabled =true;
}

function disableseven(str1,str2, str3, str4, str5, str6, str7){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
   document.all(str4).disabled =true;
   document.all(str5).disabled =true;
   document.all(str6).disabled =true;
   document.all(str7).disabled =true;
}

function disableeight(str1,str2, str3, str4, str5, str6, str7, str8){
   document.all(str1).disabled =true;
   document.all(str2).disabled =true;
   document.all(str3).disabled =true;
   document.all(str4).disabled =true;
   document.all(str5).disabled =true;
   document.all(str6).disabled =true;
   document.all(str7).disabled =true;
   document.all(str8).disabled =true;
}

function trim(str) {
 // skip leading and trailing whitespace
 // and return everything in between
  var x=str;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}