
//Purpose: container for the properties isAlpha, isNumeric, isAlphaNumeric
//Description: constructor for my new abstract type
//input: unicodeNumber
//output: nothing
//Author: Vito Mar 3,2004
//Revised by: 
function Character(unicodeNumber) {
	this.charCode = unicodeNumber;
}

//Purpose: validates a text field and returns true or false 
//Description: checks if the string contains only letters
//input: text field value (strTextValue)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 

function isAlpha() {
	return ((this.charCode >= 65) && (this.charCode <= 90)) // Uppercase
	|| ((this.charCode >= 97) && (this.charCode <= 122)) // lowercase
}

//Purpose: validates a text field and returns true or false 
//Description: checks if the string contains only numbers
//input: none
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 

function isNumeric() {
	return (this.charCode >= 48) && (this.charCode <= 57);		
}

//Purpose: validates a text field and returns true or false 
//Description: checks if the string is alphanumeric
//input: none
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function isAlphaNumeric() {
	return this.isAlpha() || this.isNumeric();
}

//prototyping my newly created class (at the top of the file)
Character.prototype.isAlpha = isAlpha;
Character.prototype.isNumeric = isNumeric;
Character.prototype.isAlphaNumeric = isAlphaNumeric;


//Purpose: trims the string from the left
//Description: trims the string from the left
//input: input string
//output: left trimmed string
//Author: Vito Mar 3,2004
//Revised by: 
function strLTrim(strInput){
	var strWhiteSpace = new String(" \t\n\r");
	var strOut = new String(strInput);

	if (strWhiteSpace.indexOf(strOut.charAt(0)) != -1) {
	   // We have a string with leading blank(s)...
	   var j=0, i = strOut.length;

	   // Iterate from the far left of string until we
	   // don't have any more whitespace...
	   while (j < i && strWhiteSpace.indexOf(strOut.charAt(j)) != -1)
	      j++;

	   // Get the substring from the first non-whitespace
	   // character to the end of the string...
	   strOut = strOut.substring(j, i);
	}
	return strOut;
}

//Purpose: trims the string from the right
//Description: trims the string from the right
//input: input string
//output: right trimmed string
//Author: Vito Mar 3,2004
//Revised by: 
function strRTrim(strInput){
	var strWhiteSpace = new String(" \t\n\r");
	var strOut = new String(strInput);

	if (strWhiteSpace.indexOf(strOut.charAt(strOut.length-1)) != -1) {
	   // We have a string with treiling blank(s)...
	   var i = strOut.length-1;

	   // Iterate from the far left of string until we
	   // don't have any more whitespace...
	   while (i >= 0 && strWhiteSpace.indexOf(strOut.charAt(i)) != -1)
	      i--;

	   // Get the substring from the first non-whitespace
	   // character to the end of the string...
	   strOut = strOut.substring(0, i+1);
	}
	return strOut;
}

//Purpose: trims the string
//Description: removes the leading and trailing blanks
//input: input string
//output: trimmed string
//Author: Vito Mar 3,2004
//Revised by: 
function strTrim(strInput){
	return strRTrim(strLTrim(strInput));
}

//Purpose: validates a text field and returns true or false 
//Description: checks if the string contains only letters, if it is of 0 length or longer then maximum length
//input: text field value (strTextFieldValue), maximum length of the text box (intMaxLength)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidateText(strTextFieldValue, intMaxLength){		
	var char1;
	var i;
	if (strTextFieldValue.length == 0) return false;
	if (strTextFieldValue.length > intMaxLength) return false;
	for (i=0;i<strTextFieldValue.length;i++){
		char1 = new Character(strTextFieldValue.charCodeAt(i));
		if (!char1.isAlpha()) return false;	
	}
	return true;
}
function APt()
{
alert("mm");
return true;
}
//Purpose: validates a text field with numbers and returns true or false 
//Description: checks if the string is alphanumeric, if it is of 0 length or longer then maximum length
//input: text field value (strTextFieldValue), maximum length of the text box (intMaxLength)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidateTextWithNumbers(strTextFieldValue, intMaxLength){
	var char1;
	var i;
	if (strTextFieldValue.length == 0) return false;
	if (strTextFieldValue.length > intMaxLength) return false;
	for (i=0;i<strTextFieldValue.length;i++){
		char1 = new Character(strTextFieldValue.charCodeAt(i));
		if (!char1.isAlphaNumeric()) return false;	
	}
	return true;
}

//Purpose: validates a text field with numbers and returns true or false 
//Description: checks if the string is numeric, if it is of 0 length or longer then maximum length
//input: text field value (strTextFieldValue), maximum length of the text box (intMaxLength)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidateNumbers(strTextFieldValue, intMaxLength){
	var char1;
	var i;
	if (strTextFieldValue.length == 0) return false;
	if (strTextFieldValue.length > intMaxLength) return false;
	for (i=0;i<strTextFieldValue.length;i++){
		char1 = new Character(strTextFieldValue.charCodeAt(i));
		if (!char1.isNumeric()) return false;	
	}
	return true;
}

//Purpose: validates email field and returns true or false 
//Description: checks if the email has a valid form using regular expressions
//input: form name (objForm), text field value (strEmailFieldValue)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidateEmail(strEmailFieldValue){
	//var strRegExp = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)*\\.[a-zA-Z]{2,4}$";
	var strRegExp = "^[\\w-.&]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)*\\.[a-zA-Z]{2,4}$";
	var objEmailRegExp = new RegExp(strRegExp);
	// does not work for Macs
	if (navigator.userAgent.indexOf("Mac") == -1){
		if (!objEmailRegExp.test(strEmailFieldValue))
		{
			return false; 	
		}
	}
	return true;
}

//Purpose: validates postal code field and returns true or false 
//Description: checks if the postalcode has a valid form using regular expressions
//input: text field value (strPostalCodeFieldValue)
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidatePostal(strPostalCodeFieldValue){
	var strRegExp = "^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$";
	var objPostalRegExp = new RegExp(strRegExp);
	// does not work for Macs
	if (navigator.userAgent.indexOf("Mac") == -1){
		if (!objPostalRegExp.exec(strPostalCodeFieldValue))
		{
			return false; 	
		}
	}
	return true;
}

//Purpose: validates date field and returns true or false 
//Description: checks if the date is valid
//input: text field value (strDateFieldValue), supported formats mm/dd/yyyy, mm-dd-yyyy
//output: true or false
//Author: Vito Mar 3,2004
//Revised by: 
function blnValidateDate(strDate){
	var strDatePat = "^([0-9]{1,2})(\-|\/|\.)([0-9]{1,2})(\-|\/|\.)([0-9]{4})$";
	//var strDatePat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	var objDateRegExp = new RegExp(strDatePat);
	var arrMatchArray = strDate.match(strDatePat); // is the format ok?
	if (arrMatchArray == null) return false;
	var intMonth = arrMatchArray[1];
	var intDay = arrMatchArray[3];
	var intYear = arrMatchArray[5];
	if (intMonth < 1 || intMonth > 12) return false;
	if (intDay < 1 || intDay > 31) return false;
	if ((intMonth==4 || intMonth==6 || intMonth==9 || intMonth==11) && intDay==31) return false;
	if (intMonth == 2){
		var blnLeap = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if (intDay > 29 || (intDay==29 && !blnLeap)) return false;
	}
	var dtmToday = new Date();
	if (intYear > dtmToday.getFullYear()) return false; 
	return true;
	
}

//Purpose: validates date field and returns true or false 
//Description: checks if the date is valid
//input: text field value (strDateFieldValue), supported formats mm/dd/yyyy, mm-dd-yyyy
//output: true or false
//Author: Ahemad July 3, 2007
//Revised by: 
function blnIsDate(strDate){
	var strDatePat = "^([0-9]{1,2})(\-|\/|\.)([0-9]{1,2})(\-|\/|\.)([0-9]{4})$";
	//var strDatePat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	var objDateRegExp = new RegExp(strDatePat);
	var arrMatchArray = strDate.match(strDatePat); // is the format ok?
	if (arrMatchArray == null) return false;
	var intMonth = arrMatchArray[1];
	var intDay = arrMatchArray[3];
	var intYear = arrMatchArray[5];
	if (intMonth < 1 || intMonth > 12) return false;
	if (intDay < 1 || intDay > 31) return false;
	if ((intMonth==4 || intMonth==6 || intMonth==9 || intMonth==11) && intDay==31) return false;
	if (intMonth == 2){
		var blnLeap = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if (intDay > 29 || (intDay==29 && !blnLeap)) return false;
	}

	return true;
	
}

//Purpose: validates date field and returns true or false 
//Description: checks if the date is valid
//input: text field value (strDateFieldValue), supported formats mm/dd/yyyy, mm-dd-yyyy
//output: true or false
//Author: Vito June 21, 2007
//Revised by: 
function blnValidateFutureDate(strDate){
	var strDatePat = "^([0-9]{1,2})(\-|\/|\.)([0-9]{1,2})(\-|\/|\.)([0-9]{4})$";
	//var strDatePat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	var objDateRegExp = new RegExp(strDatePat);
	var arrMatchArray = strDate.match(strDatePat); // is the format ok?
	if (arrMatchArray == null) return false;
	var intMonth = arrMatchArray[1];
	var intDay = arrMatchArray[3];
	var intYear = arrMatchArray[5];
	if (intMonth < 1 || intMonth > 12) return false;
	if (intDay < 1 || intDay > 31) return false;
	if ((intMonth==4 || intMonth==6 || intMonth==9 || intMonth==11) && intDay==31) return false;
	if (intMonth == 2){
		var blnLeap = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if (intDay > 29 || (intDay==29 && !blnLeap)) return false;
	}
	var dtmToday = new Date();
	if (Date.parse(strDate) < dtmToday) return false; 
	return true;
	
}

//Purpose: validates radio button group and returns true or false 
//Description: checks if the radio button is selected
//input: radio button group name
//output: true or false; 
//Author: Vito Mar 5,2004
//Revised by: 
function blnValidateRB(rb){
	for (var i=0; i < rb.length; i++)
	{	
		if (rb[i].checked)
		{
			return true;
		}
	}
	return false;
}

//Purpose: return the value of the selected radio button
//Description: loop through the radio button set and find out the value of the selected radio button
//input: radio button group name
//output: integer value of the selected radio button
//Author: Vito Mar 5,2004
//Revised by: 
function intRBValue(rb){
	for (var i=0; i < rb.length; i++)
	{	
		if (rb[i].checked)
		{
			return rb[i].value;
		}
	}
	return false;
}

//Purpose: pop up window
//Description: pop up a window (if 
//input: width, height, resizable
//output: nothing
//Author: Vito May 10,2005
//Revised by: 
function popUp(URL, w, h, resizable, notImage) {	day = new Date();	id = day.getTime();	if (notImage)
		eval("Preview" + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=" + resizable + ",width=" + w + ",height=" + h + "');");
	else		eval("Preview" + " = window.open('./preview.asp?url=' + URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=" + resizable + ",width=" + w + ",height=" + h + "');");}	


