function showdiv(val,divname)
{
	oDiv = eval("document.all."+divname);
	if(val)
	{
	     oDiv.style.visibility = "visible";
	     oDiv.style.display = "inline";
	}
}
function hidediv(val,divname)
{
	oDiv = eval("document.all."+divname);
	if(val)
	{
	    oDiv.style.visibility = "hidden";
	     oDiv.style.display = "none";          
	}
}
function showFn(theTable)
{
     obj = document.getElementsByTagName('TD');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'block';
     }
}

function hideFn(theTable)
{
     obj = document.getElementsByTagName('TD');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'none';
     }
}
//Checks is data entered or not
function isValidText(data){

	data = trim(data);
	if(data!=''){
		return true;
	}
	else{
		return false;
	}
}

//--------------------------------------------------------------------------------------------------------------------


//left trim
function ltrim ( str )
{
	//return str.replace( /^\s+/, '' )

	while (str.charAt(0) == ' ')
    	str = str.substring(1);
    	return str;
}


//--------------------------------------------------------------------------------------------------------------------

//right trim
function rtrim ( str )
{
	//return str.replace( /\s+$/, '' );

	while (str.charAt(str.length - 1) == ' ')
 	str = str.substring(0, str.length - 1);
  	return str;
}


//--------------------------------------------------------------------------------------------------------------------

//Combine the rtrim() and ltrim() functions to make the trim()
//function, which just wraps both calls together:
function trim ( str )
{
	return rtrim(ltrim(str));
}
//--------------------------------------------------------------------------------------------------------------------

function isEmpty(value)
{
  if (value == null || trim(value).length == 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}
/** Checks ALL Mandatory Fields.  */
function chkMandatory(mandatoryArray)
{
  var isValid = true;
  for (count = 0; count < mandatoryArray.length; count++)
  {
    var elem = mandatoryArray[count];
    var hasError = isEmpty(elem.value);

    if (hasError == true)
    {
      isValid = false;
      setBackground(elem, false)
    }
    else
    {
      setBackground(elem, true)
    }
  }
  return isValid;
}

/*
This method shows the error message if a field is empty on validation
*/
function emptyErrorMsg()
{
var validationMsg;
validationMsg="The fields highlighted in red are required. Enter data in these fields to continue.<br>";
return  validationMsg;
}

function showError(errSection,msg) {
    document.getElementById(errSection).innerHTML = msg;
}
function clearError(errSection) {
    document.getElementById(errSection).innerHTML = '';
}
/** Sets BG Color to Element based on isValid Flag.
    Parameters:Element,isValid Flag,BG Color */
function setBackground(elem, isValid, normalbackground)
{
  if (isValid == false)
  {
    setErrorBackground(elem);
  }
  else
  {
    setNormalBackground(elem, normalbackground);
  }
}

//--------------------------------------------------------------------------------------------------------------------

/** Sets Error BG (RED) Color to Element.*/
function setErrorBackground(formField)
{
  try
  {
    if (formField.className != null && formField.className.indexOf("fieldX") == -1)
    {
      formField.originalClassName = formField.className
    }
    if ((formField.originalClassName == 'rightAlignedText') ||
        (formField.originalClassName == 'rightAlignText'))
    {
      formField.className = "fieldXrightAlignedText";
    }
    else
    {
      formField.className = "fieldX";
    }

  }
  catch (e)
  {
    formField.className = "fieldX";
  }

}

//--------------------------------------------------------------------------------------------------------------------

/** Sets Normal BG Color to Element. ELement & BG Color are parameters.*/
function setNormalBackground(formField, normalbackground)
{
  try
  {
    if (normalbackground != null)
    {
      formField.originalClassName = formField.className;
      formField.className = normalbackground;
    }
    else if (formField.originalClassName != null && formField.originalClassName != undefined
        && formField.originalClassName.indexOf("fieldX") == -1)
    {
      formField.className = formField.originalClassName
    }
    else
    {
      if (formField.className.indexOf("fieldX") != -1)
      {
        formField.className = "";
      }
    }
  }
  catch (e)
  {
    //if exception set the className to empty
    formField.className = "";
  }
}

//---------------------------------------------------------------------------------------------------------------
/*
This method sets NormalBackground for all elements
*/
function setAllNormalBackground(formElements)
{
  for (count = 0; count < formElements.length; count++)
  {
    var elem = formElements[count];
    setNormalBackground(elem);
  }
}

//--------------------------------------------------------------------------------------------------------------------

/** Checks Given Element's Value is +ve Integer Value.  */
function chkPositiveInteger(fieldValue)
{
  var isValid = true;
  var elemValue = fieldValue;
  elemValue = trim(fieldValue);  
  try
  {
    if (isNaN(elemValue))
    {
      isValid = false;
    }
    else
    {
      fieldValue = fieldValue - 0; 
      elemValue = parseInt(elemValue, 10);
      if (elemValue != fieldValue)
      {
        isValid = false;
      }
      else if (elemValue > 9999999999 || (fieldValue - 0) <= 0)
      {
        isValid = false;
      }
    }
  }
  catch (e)
  {
    isValid = false;
  }
  return isValid;
}
//---------------------------------------------------------------------------------------------------------------
/*
This method shows the error message if a field fails numeric validation..It accepts the field name as a parameter and displays it in the message
*/
function  errorNumberMsg(fieldName)
{
var validationMsg;
validationMsg="The field '"+fieldName+"' failed numeric validation.<br>";
return validationMsg;
}
//---------------------------------------------------------------------------------------------------------------
/* This function performs the task of returning an error message for multi field validation
*/
function  errorFieldValidation(fieldName)
{
var validationMsg;
validationMsg="The field '"+fieldName+"' failed validation.<br>";
return validationMsg;
}