/*
function toAlpha(<a string>)
DESCRIPTION: Check string - ensure all characters are letters ("a-z" and "a-z"). The function removes all the non-alpha characters and returns a new string.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function toAlpha(checkString){
    var newString = "";
    var count = 0;

    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" ) || (ch == " ")) {
            newString += ch;
        }
    }
    return newString;
}

/*
function toNumeric(<a string>)
DESCRIPTION: check string - ensure all the characters are numbers ("0-9", "." and ","). The function removes all the non-numeric characters and returns a new string.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function toNumeric(checkString){
	var newString = "";
	var count = 0;

	for (i = 0; i < checkString.length; i++) {
	ch = checkString.substring(i, i+1);

		if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == ",")) {
	    	newString += ch;
		}
	}
	return newString;
}

/*
function toAlphanumeric(<a string>)
DESCRIPTION: check string - ensure all characters are alphanumeric. The function removes all the non-alphanumeric characters and returns a new string.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function toAlphanumeric(checkString){
	    newString = "";
	    count = 0;

	    for (i = 0; i < checkString.length; i++) {
	        ch = checkString.substring(i, i+1);

	        if (ch >= " " && ch <= "~") {
	            newString += ch;
	        }
    	}
    	return newString;
}

/*
function removeSpaces(<a string>)
DESCRIPTION: Remove space(s) from a string. the function returns a new string without spaces.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function removeSpaces (aString) {
	var re = /\s/g;
	return aString.replace(re,"");
}

/*
function removeUnderscores(<a string>)
DESCRIPTION: Remove underscore(s) from a string. The function replaces underscores with white spaces.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function removeUnderscores(aString) {
	var re = /_/g;
	return aString.replace(re," ");
}

/*
function checkAlpha(<a form field>)
DESCRIPTION: Check string - ensure all characters are letters. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkAlpha(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	var newString = toAlpha(checkString);

	if (checkString != newString)
	{
		alert("You must enter Alpha characters \nfor \"" + fieldName + "\" field.");
		field.focus();
		field.select();
		return false;
	}
		else{return true;}
}

/* function checkNumber(<a form field>)
DESCRIPTION: Check string - ensure all characters are numeric digits or special characters ("."and ","). If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns flase.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkNumber(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
    var newString = toNumeric(checkString);
    if (checkString != newString) 
	{
 		alert("You must enter Numeric characters \nfor \"" + fieldName + "\" field.");
 		field.focus();
 		field.select();
 		return false;
    } 
	  else {return true;}
}

/* function checkalphanumeric(<a form field>)
DESCRIPTION: Check string - ensure all characters are alphanumeric. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkAlphanumeric(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	var newString=toAlphanumeric(checkString);
    if (checkString != newString) 
	{
		alert("You must enter Alphanumeric characters \nfor \"" + fieldName + "\" field.");
		field.focus();
		field.select();
 		return false;
    } 
	else {return true;}
 }
 
 
/*
function inRange(<a string>, <min value>, <max value>)
DESCRIPTION: Check string - ensure the value of string is greater or equal to <min value> and less or equal to <max value>. If the value is valid, the function returns true. If the value is not valid, the function returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function inRange(inputStr, lo, hi)
{
	var num = parseInt(inputStr, 10);
	if (num < lo || num > hi){return false;}
	else {return true;}
}

 
/*
function checkEmail(<a form field>)
DESCRIPTION: Check string - ensure the string is in email format. The valid value should look like: <string>@<string>. If the value is valid, the function returns ture. if the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkEmail(field)
{

	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[\w-.\x27]+@[\w-.\x27]+$/;
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter a correct email\naddress for \"" + fieldName + "\" field.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/*
function checkDate(<a form field>)
DESCRIPTION: Check string - ensure the string matchs the date format (mm/dd/yyyy). If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005..
MODIFIED BY:
*/

function checkDate(field)
{

	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter the date in the following format:  mm\/dd\/yyyy.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/*
function checkDateGreater(<a form field>)
DESCRIPTION: Check string - checks to see if date entered is greater than current date. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkDateGreater(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;

	var mm = checkString.substr(0, 2);
	var month;
	if(mm == 01) month = "Jan"; //converting date to a format that date function will understand (inputDate)
	if(mm == 02) month = "Feb";
	if(mm == 03) month = "Mar";
	if(mm == 04) month = "Apr";
	if(mm == 05) month = "May";
	if(mm == 06) month = "Jun";
	if(mm == 07) month = "Jul";
	if(mm == 08) month = "Aug";
	if(mm == 09) month = "Sep";
	if(mm == 10) month = "Oct";
	if(mm == 11) month = "Nov";
	if(mm == 12) month = "Dec";
	var day = checkString.substr(3, 2);
	var yy = checkString.substr(6, 2);
	var year = "20" + yy;

	var inputDate = month + " " + day + ", " + year;

	cwDate = new Date(inputDate);   //The user entered date (inputDate) will now be compared to today's date
	Today = new Date();
	var timeDifference = cwDate - Today;

	if(timeDifference <= 0)
	{
		alert("Please enter a date which is greater than today's date.");
		field.focus();
		field.select();
		return false;
	}
}

/*
function checkDateGreater(<a form field>)
DESCRIPTION: Check string - checks to see if date entered is greater than current date (4 digit year). If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkDateGreater4DigitYr(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;

	var mm = checkString.substr(0, 2);
	var month;
	if(mm == 01) month = "Jan"; //converting date to a format that date function will understand (inputDate)
	if(mm == 02) month = "Feb";
	if(mm == 03) month = "Mar";
	if(mm == 04) month = "Apr";
	if(mm == 05) month = "May";
	if(mm == 06) month = "Jun";
	if(mm == 07) month = "Jul";
	if(mm == 08) month = "Aug";
	if(mm == 09) month = "Sep";
	if(mm == 10) month = "Oct";
	if(mm == 11) month = "Nov";
	if(mm == 12) month = "Dec";
	var day = checkString.substr(3, 2);
	var year = checkString.substr(6, 4);

	var inputDate = month + " " + day + ", " + year;

	cwDate = new Date(inputDate);   //The user entered date (inputDate) will now be compared to today's date
	Today = new Date();
	var timeDifference = cwDate - Today;

	if(timeDifference <= 0)
	{
		alert("Please enter a date which is greater than today's date.");
		field.focus();
		field.select();
		return false;
	}
}


/* function checkValidDate(<a form field>)
DESCRIPTION: Check a date field - ensure it's value is a valid date value. If the value is valid, the function returns true. if the value is not valid, the function gives an alert, puts the focus back to the checked field and returns flase. Note: this function can only
be used to valid the years between 2000 and 3000.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkValidDate(field){
	var fieldName = removeUnderscores(field.name);
	var dateArray = field.value.split("/");
	var mm = parseInt(dateArray[0], 10);
	var dd = parseInt(dateArray[1], 10);
	var yyyy = parseInt(dateArray[2], 10);
	var febDays = 0;
	if (yyyy % 4 == 0)
	{
		if (yyyy % 100 == 0)
		{
			if (yyyy % 400 == 0)
			{febDays = 29;} 
			else {febDays = 28;}
		} 
		else {febDays = 29;}
	} 
	else {febDays = 28;}
	
	var monthMax = new Array(31,febDays,31,30,31,30,31,31,30,31,30,31);

	if(!inRange(mm, 1, 12))
	{
		alert("Invalid month value for\n" + fieldName + " field");
	        field.focus();
           	field.select();
		return false;
	}
	
	if(!inRange(yyyy, 2000, 3000))
	{
		alert("Invalid year value for\n" + fieldName + " field");
	        field.focus();
           	field.select();
		return false;
	}
	
	if(!inRange(dd, 1, monthMax[mm-1]))
	{
		alert("Invalid date value for\n" + fieldName + " field");		
	        field.focus();
           	field.select();
		return false;
	}
	return true;
}



/*
function checkDate_2DigitYear(<a form field>)
DESCRIPTION: Check string - ensure the string matchs the date format (mm/dd/yy). If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkDate_2DigitYear(field)
{

	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[0-9]{2}\/[0-9]{2}\/[0-9]{2}$/;
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter the date in the following format:  mm\/dd\/yy.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/* function checkPhone(<a form field>)
DESCRIPTION: Check string - ensure the string matchs the phone format (nnn-nnn-nnnn). Alpha characters are allowed in the phone number. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Helen Tong on 03/23/2001.
MODIFIED BY:
*/

function checkPhone(field){
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[0-9]{3}-[0-9a-zA-Z]{3}-[0-9a-zA-Z]{4}$/
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter the phone number in the following format:  nnn-nnn-nnnn.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/*
function checkPhoneNumericOnly(<a form field>)
DESCRIPTION: Check string - ensure the string matches the phone format (nnn-nnn-nnnn).  Only numeric digites are allowed in the phone number. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkPhoneNumericOnly(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter a numeric phone number in the following format:  nnn-nnn-nnnn.");
		field.focus();
		field.select();
		return false;
	}
	else{
		return true;
	}
}

/*
function checkSSN(<a form field>)
DESCRIPTION: Check string - ensure the string matchs the format of Social Security Number(nnn-nn-nnnn). If the value is valid, the function returns true. If the value is not invalid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkSSN(field)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	re = /^[0-9]{3}-[0-9]{2}-[0-9]{4}$/
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter a correct\nSSN for \"" + fieldName + "\" field.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}


/*
function checkMailstop(<a form field>)
DESCRIPTION: Check string - ensure the string has 6 alpha characters and 4 numeric characters. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkMailstop(field){

	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
//	re = /^[a-zA-Z]{6}[0-9]{4}$/;
	re = /^[a-zA-Z]{6}[0-9a-zA-Z]{4}$/;
	OK = re.exec(checkString);

	if(!OK)
	{
		alert ("Please enter the mailstop in the following format:\n6 alpha characters and 4 alpha or numeric characters.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}


/*
function checkRepeatingNumbers(<a form field>)
DESCRIPTION: Check string - ensure the string does not having repeating numbers (i.e. SSN: 999999999 or PHONE: 999-999-9999). They must have different numbers.  If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkRepeatingNumbers(field)
{

       var fieldName = removeUnderscores(field.name);
       var checkString = field.value;
       var num = toNumeric(checkString);  
       var same = "";
       var save = "";

       for (i = 0; i < num.length; i++) 
	   {
            if (i == 0) 
			{
                save = num.charAt(i);
                continue;
            }

            if (num.charAt(i) == save)  
			{
                  same = "true"
                  save = num.charAt(i);
            }   else 
			{
                  same = "false";
                  break;
            }
       }

       if (same == "true") 
	   {
           alert("Please enter a valid number for \"" + fieldName + "\" field.");
           field.focus();
           field.select();
           return (false)
       } 
	   else {return (true)}
}


/*
function minLength(<a form field>, <min length>)
DESCRIPTION: Check string - ensure the string has at least a given length. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/
function minLength(field, minLength)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	Length = new Number(minLength);
	if (checkString.length < Length)
	{
		alert ("Please enter at least " + minLength + " characters\nfor \"" + fieldName + "\" field.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/*
function maxLength(<a form field>, <max length>)
DESCRIPTION: Check string - ensure the string has at most a given length. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function maxLength(field, maxLength)
{
		var fieldName = removeUnderscores(field.name);
		var checkString = field.value;
		Length = new Number(maxLength);
		if (checkString.length > Length)
		{
			alert ("Please enter at most " + maxLength + " characters\nfor \"" + fieldName + "\" field.");
			field.focus();
			field.select();
			return false;
		}
		else{return true;}
}

/*
function fixedLength(<a form field>)
DESCRIPTION: Check string - ensure the string has a given length. If the value is valid, the function returns true. If the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function fixedLength(field, theLength)
{
	var fieldName = removeUnderscores(field.name);
	var checkString = field.value;
	Length = new Number(theLength);
	if (checkString.length != Length)
	{
		alert ("Please enter " + theLength + " alpha or numeric characters\nfor \"" + fieldName + "\" field.");
		field.focus();
		field.select();
		return false;
	}
	else{return true;}
}

/* function fixedLengthAlpha(<a form field>, <required length>)
DESCRIPTION: Check string - ensure the string has a given lengh and all the character(s) are letters. If the value is valid, the function returns true. if the value is not valid, the function gives an alert, puts the focus back to the checked field and returns flase.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function fixedLengthAlpha(field, theLength)
{
		var fieldName = removeUnderscores(field.name);
		var checkString = field.value;
		var newString = toAlpha(checkString);
		Length = new Number(theLength);

		if (checkString.length != Length)
		{
			alert ("Please enter " + theLength + " alpha character(s)\nfor \"" + fieldName + "\" field.");
			field.focus();
			field.select();
			return false;
		}
		else if(checkString != newString)
		{
			alert("The value you entered\nfor \"" + fieldName + "\" field\ncontains invalid characters!");
			field.focus();
			field.select();
 			return false;
		}
		else{return true;}
}

/*
function fixedLengthNumeric(<a form field>, <required length>)
DESCRIPTION: Check string - ensure the string has a given length and all the character(s) are numbers ("0-9", "." and ","). If the value is valid, the function returns true. if the value is not valid, the function gives an alert, puts the focus back to the checked field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function fixedLengthNumeric(field, theLength)
{
			var fieldName = removeUnderscores(field.name);
			var checkString = field.value;
			var newString = toNumeric(checkString);
			Length = new Number(theLength);

			if (checkString.length != Length)
			{
				alert ("Please enter " + theLength + " numeric character(s)\nfor \"" + fieldName + "\" field.");
				field.focus();
				field.select();
				return false;
			}
			else if(checkString != newString)
			{
				alert("The value you entered\nfor \"" + fieldName + "\" field\ncontains invalid characters!");
				field.focus();
				field.select();
	 			return false;
			}
			else{return true;}
}

/*
function textNotBlank(<a text object>)
DESCRIPTIONS: Check string - ensure a text field is not blank. if the checked field is blank, the function puts the focus back to the field and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function textNotBlank(field)
{
		var fieldName = removeUnderscores(field.name);
		var checkString = field.value;
		if (checkString.length == 0 || checkString == "undefined" || checkString == null)
		{
			alert ("Please complete the \"" + fieldName + "\" field.");
			field.focus();
			return false;
		}
		
}

/*
function getRadioIndex(<a radio group name>)
DESCRIPTION: If a radio button has been checked, the function will return that radio's index number. If nothing has be checked, the function will return -1.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function getRadioIndex (radioName)
{
	for(var i=0;i<radioName.length;i++) 
	{
	      if(radioName[i].checked) 
		  {return i;}
    }
    return -1;
}

/*
function checkRadio(<a radio group name>)
DESCRIPTION: Check radio object - ensure one item has been checked. If one item has been checked, the function returns true. If nothing has been checked, the function gives an alert, puts focus back to the object and returns false.
INITIALIZED BY: Ed Maschler on 04/19/2005..
MODIFIED BY:
*/

function checkRadio(radioName)
{
	var index = getRadioIndex(radioName);
	if (index != -1)
	{return true;}
	else{
		alert("Please make a choice for \"" +  removeUnderscores(radioName[0].name) + "\" field.");
		radioName[0].focus();
		return false;
	}
}

/*
function checkSelect(<a selection object>)
DESCRIPTION: Check selection box - ensure at least one item has been checked. If at least one item has been checked, the function returns true. If nothing has been checked, the function gives an alert, puts focus back to the object and returns false. Notes: In this function, we assume that the first item is the field's instruction (i.e. "-- Select One --") but not a valid selection.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkSelect(selectName)
{
	if(selectName.selectedIndex < 1)
	{
		for (var i = 1; i < selectName.length; i++)
		{
			selectName.options[i].selected = false;
		}
		alert("Please make a selection for \"" +  removeUnderscores(selectName.name) + "\" field.");
		selectName.options[0].selected = true;
		selectName.focus();
		return false;
	} 
	else {return true;}
}


/*
function checkPlainText(<a form field>)
DESCRIPTION: Check the string for plain text characters.  
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function checkPlainText(addedTxt) 
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-,;:.,!@#$%^&*()-+=_`~/?><'\" \t\r\n\f";
  var checkStr = addedTxt.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
  
    alert("The text entered in the \""+  removeUnderscores(addedTxt.name) +"\" field contains characters that will cause this form to fail.  \nIf you have copied text from a Word document, please delete and retype all quotes, apostrophes, or other special characters.");
    addedTxt.focus();
    return (false);
  }
  
  return (true);
}


/*
function mailerOrder(<a form>, <exclude fields string>)
DESCRIPTION: This function generates the value of the "order" field for a form 
uses com.sprint.imc.utilities.mailer.Servlet. The function returns a string that 
contains all the form field names separated by a comma. Please refer to 
http://ppld.corp.sprint.com/onestop/assistancedevelopment/mailer_basic.htm 
for more information about the mailer servlet and the order field.
INITIALIZED BY: Ed Maschler on 04/19/2005.
MODIFIED BY:
*/

function mailerOrder(theForm){
	var orderField = "";
//	var exArr = excludeFields.split(","); // fields will not be included
	var lastIndex = theForm.elements.length - 1;
	var fieldArray = new Array(theForm.elements.length);
	var k=0;
	
	for(var i=0; i <= lastIndex; i++) {
		var flag = true;
//		for(var j=0; j < exArr.length; j++){
//			if(theForm.elements[i].name == exArr[j] || theForm.elements[i].name == "order") {
//				flag = false;
//				break;
//			}
//		}
		//remove duplicate filed name
		for(var m=0; m < fieldArray.length; m++){
			if(theForm.elements[i].name == fieldArray[m]) {
				flag = false;
				break;
			}
		}		
		if (flag == true){
			fieldArray[k] = theForm.elements[i].name;
			k++;
			orderField += theForm.elements[i].name + ",";
		}
		// remove the last comma
		if (i == lastIndex){
			orderField = orderField.substring(0, orderField.lastIndexOf(",")); 
		}
		flag = true;
	}
	return orderField;
}


