function checkRequiredField(formName, fieldName)
{
   var iMissing = 0;
	//text
	var sType = document.forms[formName].elements[fieldName].type;
   var sElementType;
   if( sType == null ) sType = "";
   
	if (( sType == "text" ) || ( sType == "password" ))
	{
		//check text
		//alpha
		//alpha-numeric
		//etc
  		if (isAllSpace(document.forms[formName].elements[fieldName].value))
		{
			return false;
		}
		else
			return true;
	}
	//select
	if (sType.indexOf("select") != -1)
	{
      //dropdown list box
		if (document.forms[formName].elements[fieldName].length == 0 &&
		document.forms[formName].elements[fieldName].selectedIndex == 0)
		{
			return false;
		}

		if (document.forms[formName].elements[fieldName].length > 0 &&
		document.forms[formName].elements[fieldName].selectedIndex == -1)
		{
			return false;
		}
		return true;
	}
	if (sType == "")//potentially multiple value fields
	{
      inputArray = document.forms[formName].elements[fieldName];
      sElementType = inputArray[0].type;
      //radio button and checkbox
		if (( sElementType == "checkbox" )|| (sElementType == "radio" ))
		{
			var i = 0;
			var bChecked = false;
			while(inputArray[i]!=null)
			{
				if (inputArray[i].checked)
				{
					bChecked = true;
					return true;
				}
				i++;
			}
			if (bChecked == false)
			{
				return false;
			}
			return true;
		}
		if (sElementType == "text" )
		{
			var i = 0;
			var bFilled = false;
			while(inputArray[i]!=null)
			{
				if (!isAllSpace(inputArray[i].value) )
				{
					bFilled = true;
					return true;
				}
				i++;
			}
			if (bFilled == false)
			{
				return false;
			}
			return true;
		}
		return true;
	}
	return false;
}

function isAlpha(sCheckStr) {
	sValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- "
	for (i=0; i<sCheckStr.length; i++) {
		tempChr = sCheckStr.substr(i, 1);
		//tempChr = tempChr.toLowerCase();
		if (sValidChars.indexOf(tempChr) < 0)
			return false;
	}
	return true;
}

function isDN(sChkStr) {
	var i, tempChar;
	sChkStr = String(sChkStr);

	for (i=0; i < sChkStr.length; i++) {
		tempChar = sChkStr.substring(i, i+1);
		if (tempChar == ",") {
			return false;
		}
	}
	return true;
}

function isAlphaNumeric(sCheckStr) {
	sValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_ "
	for (i=0; i<sCheckStr.length; i++) {
		tempChr = sCheckStr.substr(i, 1);
		//tempChr = tempChr.toLowerCase();
		if (sValidChars.indexOf(tempChr) < 0) {
			return false;
		}
	}
	return true;
}

function isAlphaNumericNoSpace(sCheckStr) {
	sValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_-"
	for (i=0; i<sCheckStr.length; i++) {
		tempChr = sCheckStr.substr(i, 1);
		//tempChr = tempChr.toLowerCase();
		if (sValidChars.indexOf(tempChr) < 0) {
			return false;
		}
	}
	return true;
}

function isNumeric(sCheckStr) {
	sValidChars = "1234567890"
	for (i=0; i<sCheckStr.length; i++) {
		tempChr = sCheckStr.substr(i, 1);
		tempChr = tempChr.toLowerCase();
		if (sValidChars.indexOf(tempChr) < 0) {
			return false;
		}
	}
	return true;
}

function isAllSpace(sChkStr) {
	var i, tempChar, bAllSpace;
	sChkStr = String(sChkStr);
	bAllSpace = true;

	for (i=0; i < sChkStr.length; i++) {
		tempChar = sChkStr.substring(i, i+1);
		if (tempChar != " ") {
			bAllSpace = false;
			break;
		}
	}
	return bAllSpace;
}

function hasInvalidIdCharacter(sCheckStr) {
	sInValidChars = ".#*:"
	for (i=0; i<sCheckStr.length; i++) {
		tempChr = sCheckStr.substr(i, 1);
		if (tempChr == "\\") return true;  // special handling for black slash
		tempChr = tempChr.toLowerCase();
		if (sInValidChars.indexOf(tempChr) >= 0) {
			if (tempChr == ":") { // check double colon
				if (sCheckStr.substr(i+1, 1) == ":") return true;
			}
			else {
				return true;
			}
		}
	}
	return false;
}

function isIPAddress(sIPAdd) {
	var sIPAddPart = "";
	for (var i=0; i<3; i++) {
		if (sIPAdd.indexOf(".") > 0) {
			sIPAddPart = sIPAdd.substr(0, sIPAdd.indexOf("."));
			if ((sIPAdd.length == 0) || !isNumeric(sIPAddPart) || (sIPAddPart > 255))
				return false;
			sIPAdd = sIPAdd.substr(sIPAdd.indexOf("."));
			if (sIPAdd.length > 0);
				sIPAdd = sIPAdd.substr(1);
		} else {
			return false;
		}
	}
	if ((sIPAdd.length == 0) || !isNumeric(sIPAdd) || (sIPAdd > 255))
		return false;
	return true;
}

function isEmail(email) {
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.@-,"
	var ok = 1; // 1 for success .. 0 for invalid
	var temp;
	var atCount = 0; // should be 1 at the end of check for valid Email.

	if(email.length > 0 ) {
		for (var i=0; i<email.length; i++) {
			temp = "" + email.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") {
				ok = 0;
				break;
			}
			if(temp == '@')
				atCount++;
		} // for
		if(atCount != 1)
			ok = 0;
		positionOfAt = email.indexOf( '@') ;
		if (!(( positionOfAt > 0 ) && ( positionOfAt < (email.length - 1) ))) {
		   ok = 0 ; // @ symbol is at beginning or end of string.
		}
      // check if there's a period after @ (#18696)
      positionOfDot = email.indexOf('.', positionOfAt+2);
      if (!((positionOfDot > 0) && (positionOfDot < (email.length - 1)))) {
         ok = 0; // '.' dot is not after @ or at the end of string
      }
		if (ok == 0) {
			return false;
		} // if
	} // if (email.length > 0)
	return true;
} // method

function trim(str) {
	var strToTrim = String(str);
	while (strToTrim.substring(0, 1) == " ")
		strToTrim = strToTrim.substring(1, strToTrim.length);
	while (strToTrim.substring(strToTrim.length - 1, strToTrim.length) == " ")
		strToTrim = strToTrim.substring(0, strToTrim.length - 1);
	return strToTrim;
}

function msbMakePageHeader(header)	{
	document.write('<table cellpadding=0 cellspacing=0 border=0 width="100%">');
	document.write('<tr><td colspan=4 width="100%" class="pageheader">' + header + '</td></tr>');
	document.write('<tr><td colspan=4 width="100%" class="pagecolor"><img src="/images/spacer.gif" alt="" width=1 height=1></td></tr>');
	document.write('</table>');
}

function msbMakeFormSectionHeader(header)
{
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="sectionheader">' + header + '</td></tr></table>');
}

function moveFormSelectedItem(srcSelect, desSelect)
{
  for (i=srcSelect.length-1; i>=0; i--)
  {
    if (srcSelect.options[i].selected)
    {
      if ((srcSelect.options[i].value == null) || (srcSelect.options[i].value == ""))
        srcSelect.options[i].selected = false;
      else
      {
        desSelect.options[desSelect.length] = new Option(srcSelect.options[i].text, srcSelect.options[i].value);
        srcSelect.options[i] = null;
      }
    }
  }
}

function replace(str, original, replacement) {
	var result;
	result = "";
	while(str.indexOf(original) != -1) {
	if (str.indexOf(original) > 0)
		result = result + str.substring(0, str.indexOf(original)) + replacement;
	else
		result = result + replacement;
	str = str.substring(str.indexOf(original) + original.length, str.length);
	}
	return result + str;
}



