
<!--
/******************************** Listing of Functions **********************************   
// Function validate address fields accepts alphabets, numbers,dot, brackets,comma,hyphen,forward slash,and //	pound sign
function validateAddress(nm)

// Function validates email addresses necessarily checks for "@" and "." signs and accepts alphabets,numbers  and //	underscore only
function validateEmail(nm)

//Validate for alphabets only 
function validateAlphabet(nm )

//Validates date fields accepts only numbers and "/" and validates the format mm/dd/yyyy
function validateDate(nm)

//Validates the password and retyped Password  for having similar values 
function validatePassword(nm, Pass,rePass)

// Validates all the fields passed to it and returns false if any of the fields is empty
function validateEmptyFieldsGeneric()

//Function validating 0-9 only
function valiDateNumeric(data) 

//Function validating 0-9 and . also for price and discount $/
function validatePrice(data) {

//Function validating a-z, A-Z, 0-9 only alphanumeric 
function validateAlphaNum(data) 

//Function validating a-z, A-Z, 0-9 and . (dot)
function validateAlphaNumdot(data) 

//Function no spaces are allowed here
function isValidate(data)

//function to check the textarea length
function maxlengthtextarea(object) 

//Function no spaces are allowed but dot is allowed
function isValidatedot(data)

// Function validateSelect()
// Forces selection of options other than first one in a select control.
function validateSelect(selectObject){

//Function validates numeric values also used to validate phone and fax numbers
function validatePhone(name)

NOTE : These functions uses regular expressions , you can see a note on these at 
the end of this file
*/

// Function validate address fields accepts alphabets, numbers,dot, brackets,comma,hyphen,forward slash,and pound sign
function validateAddress(nm)
{
		invalidInput = false;
		value = trim(nm.value);		
		// accept null value
		if (value.length == 0)
			return true;
		for(i=0; i<value.length; i++)
		{
			if((value.substring(i, i+1) >= "A") && (value.substring(i, i+1) <= "Z") || (value.substring(i, i+1) >= "a") && (value.substring(i, i+1) <="z") || (value.substring(i, i+1) == " ") || (value.substring(i, i+1) >= "0") && (value.substring(i, i+1) <= "9") || (value.substring(i, i+1) == "/") || (value.substring(i, i+1) == "#") || (value.substring(i, i+1) == "-") || (value.substring(i, i+1) == ",") || (value.substring(i, i+1) == "(") || (value.substring(i, i+1) == ")") || (value.substring(i, i+1) == "."))
			{
				invalidInput = false;
			}else
			{
				invalidInput = true;
				break;
			}
		}

		if(invalidInput == true)
		{
			alert("\nInvalid input: [" + value+ "].\nSpecial characters other than #-,()/ are not allowed.");
			nm.focus();
			return false;			
		}
	return true;	
}


//Validate for alphabets only 
function validateAlphabet(nm )
	{
		invalidInput = false;
		alpha = trim(nm.value);
		// accept null value
		if (alpha.length == 0)
			return true;

		for(i=0; i<alpha.length; i++)
		{
			if((alpha.substring(i, i+1) >= "A") && (alpha.substring(i, i+1) <= "Z") || (alpha.substring(i, i+1) >= "a") && (alpha.substring(i, i+1) <="z") || (alpha.substring(i, i+1) == " "))
			{
				invalidInput = false;
			}else
			{
				invalidInput = true;
				break;
			}
		}

		if(invalidInput == true)
		{
			alert("\nInvalid input: [" + alpha+ "]\nOnly alphabets are allowed");
			nm.focus();
			return false;
		}
	return true;
	}

//Validates date fields accepts only numbers and "/" and validates the format mm/dd/yyyy
function validateDate(date){
	// format = mm/dd/yy
	if ( trim(date) == "" )
	return true;

	InvalidDate = false;
	FirstIndexOfSlash = date.indexOf("/", 0);
	SecondIndexOfSlash = date.indexOf("/", FirstIndexOfSlash+1);
	Month = date.substring(0, FirstIndexOfSlash);
	Day = date.substring(FirstIndexOfSlash+1, SecondIndexOfSlash);
	Year = date.substring(SecondIndexOfSlash+1, date.length);

	if(Month >= 1 && Month <=6){
		if(Month%2 == 1){	// 31 day month
			if(!(Day >= 1 && Day <=31)){
				InvalidDate = true;
				return false;
			}
		}else if(Month == 2){  // 29 day month
			if(!(Day >= 1 && Day <=29)){
				InvalidDate = true;
				return false;
			}
		}else{
			if(!(Day >= 1 && Day <=30)){
				InvalidDate = true;
				return false;
			}
		}
	}else if(Month >= 9 && Month <=12){
		if(Month%2 == 0){	// 31 day month
			if(!(Day >= 1 && Day <=31)){
				InvalidDate = true;
				return false;
			}
		}else{
			if(!(Day >= 1 && Day <=30)){
				InvalidDate = true;
				return false;
			}
		}
	}else if(Month == 7 || Month == 8){
		if(!(Day >= 1 && Day <=31)){
			InvalidDate = true;
			return false;
		}
	}else{
		InvalidDate = true;
		return false;
	}

	if(!((Year >= 0 && Year <= 99) || (Year >= 1900 && Year <= 2050))){
		InvalidDate = true;
		return false;
	}
	if(InvalidDate == true){
		return false;
	}else{
		dt = Date.parse(date)+"";
		if(dt == "NaN"){
			return false;
		}		
		return true;
	}
}
	
//Validates the password and retyped Password  for having similar values 
function validatePassword(nm, Pass,rePass)
	{
		invalidInput = false;
		if (Pass !=rePass || Pass=="" || rePass=="" )
			invalidInput =true;

		if(invalidInput == true)
		{
			alert("\nBoth the passwords are not same or empty \nRetype...");
			nm.focus();
			return false;
		}
		return true;
	}


// Validates all the fields passed to it and returns false if any of the fields is empty
function validateEmptyFieldsGeneric()
{
	var i=0;
	n= validateEmptyFieldsGeneric.arguments.length;

	for (i=0; i<n; i++)
	{		
		
		str1 = validateEmptyFieldsGeneric.arguments[i].name;
		str1 = str1.toLowerCase();
		obj = validateEmptyFieldsGeneric.arguments[i];
		
		actualString=obj.value;
		actualString=trim(actualString);

		if (actualString.length < 1 )
		{
			// build the message
			str = "Please enter " 

			// handle special cases for some of the variable names
			if (str1 == "modelnumber")
				str1= "model number";
			if (str1 == "desc")
				str1= "description";
			if (str1 == "displayname")
				str1= "display name";
			if (str1 == "showsequence")
				str1= "show sequence";	
			if (str1 == "email")
				str1= "email address";
			if (str1 == "year")
				str1= "model year";
			if (str1 == "price")
				str1= "model price";
			if (str1 == "mailfrom")
				str1= "your name in mail from field";
			if (str1 == "mailto")
				str1= "email address in mail to field";
			if (str1 == "subject")
				str1= "a subject for the mail";
			if (str1 == "mailbody")
				str1= "body of the mail";
			if (str1 == "heading")
				str1= "document title";
		
			str = str + str1
			alert (str + ". It cannot be blank."); 
			obj.focus();
			return false;
		}
	}
	return true; 
}
//  Function To Validate Email Address 
function validateEmail(name)
{
	myString=trim(name.value);
	// accept null value
	if (myString.length == 0)
		return true;

	var newString = myString.match(/\b(^(\S+@.+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b)/gi);
   	if (!newString) 
   	{
   		alert("Please enter valid email address");
		name.focus();
		return false;
	}
	return true;	
}

//  Function To Validate Email Address 
function validateEmail_new(name)
{
	myString=trim(name.value);
	// accept null value
	if (myString.length == 0)
		return true;

	if (myString.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[(\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2})]+)*\.[(\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2})]+$/) != -1)
	{
   		alert("Please enter valid email address");
		name.focus();
		return false;
	}
	return true;	
}

//Function validating 0-9 only
function valiDateNumeric(name) 
{
	data = trim(name.value);
	// accept null value
	if (data.length == 0)
		return true;

	if (data.match(/^\s*\d{0,9}\s*$/))
       {
		return true;
		}
       else
       {
   		alert("Only numbers are allowed...");
	   	name.focus();
		return false;
       }
}


//Function validating 0-9 and . also for price and discount $/
function validatePrice(name) 
{
	data = trim(name.value);
	
	// accept null value
	if (data.length == 0)
		return true;
	var newString = data.match	(	/^(\d{0,8})?(\.\d{0,2})?$/	 );
   	if (!newString) 
   	{
 		alert("Invalid Price\nPlease enter price in format (99999999.99)");
	   	name.focus();
		return false;
	}
	return true;
}

function validateAlphaNum(nm)
{
	value = trim(nm.value);
	invalidInput = false;
	for(i=0; i<value.length; i++)
	{
		if((value.substring(i, i+1) >= "A") && (value.substring(i, i+1) <= "Z") || (value.substring(i, i+1) >= "a") && (value.substring(i, i+1) <="z") || (value.substring(i, i+1) >= "0") && (value.substring(i, i+1) <= "9") || (value.substring(i, i+1) == " "))
		{
			invalidInput = false;
		}else
		{
			invalidInput = true;
			break;
		}
	}// for

	if(invalidInput == true)
	{
		alert("\nInvalid input: [" + value+ "]\nOnly alphabets and numbers are allowed.");
		nm.focus();
		return false;		
	}
}

//Function validating a-z, A-Z, 0-9 only alphanumeric 
function validateModelNumber(nm) 
{
	value = trim(nm.value);
	invalidInput = false;
	for(i=0; i<value.length; i++)
	{
		if((value.substring(i, i+1) >= "A") && (value.substring(i, i+1) <= "Z") || (value.substring(i, i+1) >= "a") && (value.substring(i, i+1) <="z") || (value.substring(i, i+1) >= "0") && (value.substring(i, i+1) <= "9"))
		{
			invalidInput = false;
		}else
		{
			invalidInput = true;
			break;
		}
	}// for

	if(invalidInput == true)
	{
		alert("Please enter valid model number\nOnly alphabets and numbers are allowed...");
		nm.focus();
		return false;		
	}
}

//Function validating a-z, A-Z, 0-9 and . (dot)
function validateAlphaNumdot(name) 
{
	data = trim(name.value);
	// accept null value
	if (data.length == 0)
		return true;
	
	if (data.match(/[a-zA-Z0-9\.]+$/)!=null)
    {
		return true;
	}
    else
    {
   		alert("Only alphabets, numbers, and dot are allowed...");
	   	name.focus();
		return false;
    }
}


//Function no spaces are allowed here
function isValidate(name)
{
	data = trim(name.value);
	// accept null value
	if (data.length == 0)
		return true;
	
	if (data.match(/^[\w\-]+$/))
	{
		return true;
	}
	else
	{
   		alert("No space allowed...");
	   	name.focus();
		return false;
	}
	
}

//Function no spaces are allowed but dot is allowed
function isValidatedot(name)
{
	data = trim(name.value);
	// accept null value
	if (data.length == 0)
		return true;
	
 	if (data.match(/^\w+[\w\-]*\.{1,1}\w+$/)) 
	{
  		return true;
	}
	else
	{
   		alert("No space allowed, only dot is allowed ");
	  	name.focus();
		return false;
	}	
}


// Function validateSelect()
// Forces selection of options other than first one in a select control.
function validateSelect(selectObject)
{
	val = selectObject[selectObject.selectedIndex].value;
	if(val == 0 || val == ""){
		alert("Please select from drop down list");
		selectObject.focus();
		return false;
	}else{
		return true;
	}
}


//Function validates phone number
function validatePhone(object)
{
	data = object.value;	
	
	//pattern used to validate phone
	var PhonePattern=/^[A-Za-z0-9\-\(\)\s\,\/]+$/
	
	// accept null value
	if (data.length == 0)
		return true;

	newString = data.match	(PhonePattern);
   	if (!newString) 
   	{
 		alert("Invalid Phone number\nPlease enter alphabets, numbers, brackets, dash and spaces noly");
	   	object.focus();
		return false;
	}
	return true;
}

// function to trim the blank spaces entered by the user
function trim(input)
{
	for(i=0; i<input.length; )
	{
		if(input.charAt(i)==" ")
			input=input.substring(i+1, input.length);
		else
			break;
	}

	for(i=input.length-1; i>=0; i=input.length-1)
	{
		if(input.charAt(i)==" ")
			input=input.substring(0,i);
		else
			break;
	}
	return input;
}

function maxlengthtextarea(object) 
{
	data=trim(object.value);
    if (data.length > 255) 
	{
		alert("Please enter 255 characters only"); 
		object.focus();	
		return false; 
	} 
	return true; 
}

function validateMaxLength(object,length1) 
{
	data=trim(object.value);
    if (data.length > length1) 
	{
		Msg = "Please enter " + length1 + " characters only";
		alert(Msg); 
		object.focus();	
		return false; 
	} 
	return true; 
}
function valiDateYear(object)
{
	thisYear=object.value;	
	var yr;
	Today = new Date();
	yr = Today.getFullYear();
	Msg = "Please enter years in the range [1900.."+yr+"]" ;		
	if (thisYear.length == 0)
		return true;
	
	ret = valiDateNumeric(object);	
	if (ret == false)	return false;	

	if (object.value.length > 4){
		alert("Enter only 4 digits");
		object.focus();
		return false;
	}
	if (object.value < 1900){
		alert(Msg);
		object.focus();
		return false;
	}
	if (object.value > yr){
		alert(Msg);
		object.focus();
		return false;
	}
}
//-->


/*
[Character -	Matches] 
\b 		Word boundary 
\B 		Word nonboundary 
\d 		Numeral 0 through 9 
\D 		Non-numeral 
\s 		Single white space 
\S 		Single nonwhite space 
\w 		Letter, numeral or underscore 
\w+		matches a whole word.
\W 		Not letter, numeral or underscore 
\W+		matches whitespace.     
. 		Any character except newline 
[...] 	Character set 
[0..9]	matches ONE number, ranging from 0 to 9.
[A-Za-z] matches any letter, uppercase or lowercase.
[^...] 	Negated character set 
* 		Last character occurring zero or more times 
? 		Last character occurring zero or one time 
+ 		Last character occurring one or more times 
{n} 	Last character occurring exactly n times 
{n,} 	Last character occurring n or more times 
{n,m} 	Last character occurring at least n, at most m times 
^ 		Pattern occurring at the beginning of the string 
$ 		Character occurring at the end of the string 
| 		OR operator 
x|y		matches one or the other of x or y.
g 		All occurrences of the pattern; that is, (g)lobal 
i 		Case (i)nsensitive occurrences of the pattern 


Parentheses can be used to group characters together. 
	(this)+ matches at least one occurrence of "this".

If you wish to search for one of the special characters, 
		you must first delimit it with a backslash(\). 
     \. matches a period.
     \? matches a question mark.
     \[ matches a left square bracket.
     \| matches a "pipe" character.

In addition to these, modifiers can be added after the regular expression to control how it searches through the string. Some of more useful ones include these: 
	/somematch/g - global (matches all instances).
	/somematch/i - ignore case.
	/somematch/gi - you can combine them, too.	
*/