var DebugScript=0;
var StartupComplete=0;
var giCurrentField;
//var giRepaintCount=0;  TOREMOVE: obsolete
var objHourGlass = null;
var gstFrameName = "";
var newWin=null;
var onfocus=new Array;

//PEMINIC FUNCTIONS v. 4/11/2002, 5/1/2002

function checkBrowser()
{
  this.ver=navigator.appVersion;
  this.dom=document.getElementById?1:0;
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
  this.ie4=(document.all && !this.dom)?1:0;
  this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie5 || this.ie6 || this.ie4 || this.ns4 || this.ns5)
  return this;
}

/****************
Description:  Locks the Screen.
Parameters:
	onOff        - Boolean value indicating on(true) or off(false).
*****************/  
function ScreenLock(onOff){
  //Turns off/On all Select Boxes which can not be covered by a layer!
  for(i=0;i<window.document.form1.elements.length;i++)
  {
	if ( window.document.form1.elements[i].type != null )
	{
		if(window.document.form1.elements[i].type.substr(0, 6)=="select")
			if(onOff)
				window.document.form1.elements[i].style.visibility='hidden';
			else
				window.document.form1.elements[i].style.visibility='visible';
	}
  }
  //Turns on the Screen Lock and Sizes it.
  if(onOff){
		pageW=document.layers?innerWidth:document.body.scrollWidth;
		pageH=document.layers?innerHeight:document.body.scrollHeight;
		if(pageH<self.screen.availHeight)
		  pageH=self.screen.availHeight;
		if(document.body)
			scrolldown=document.body.scrollTop;
		else
			scrolldown=window.pageYOffset;
		moveTo("screenLockWarning" , pageW/2-150+"px", scrolldown+200+"px");
		ShowDiv("screenLockFilter", onOff);
		ShowDiv("screenLockWarning", onOff);
		lockFilter=getDiv("screenLockFilter");
		lockFilter.width=pageW+"px";
		lockFilter.height=pageH+"px";
	  }
	//Turns off the Screen Lock.
  else{
	  ShowDiv("screenLockFilter", onOff);
		ShowDiv("screenLockWarning", onOff);
	}
}

/****************
Description:  Activates the Sceen Lock feature for submits, Controls all frames.
Parameters:
	onOff        - Boolean value indicating on(true) or off(false).
*****************/ 
function ScreenLockController(onOff){
  //Unlock other frames if they have not refreshed.
  if(window!= top ){
    if(parent.headerframe.StartupComplete)
      parent.headerframe.ScreenLock(onOff);
    if(parent.dataframe.StartupComplete)
      parent.dataframe.ScreenLock(onOff);
    if(parent.footerframe.StartupComplete)
      parent.footerframe.ScreenLock(onOff);
    }
  else
    ScreenLock(onOff);
  }


//Shows the div
function show(div,nest)
{
  if ( window == top || ( gstFrameName == "editframe" ) )
  {
    bw=checkBrowser();
    if ( parent != null && parent.headerframe != null && parent.headerframe.document.objHourGlass != null )
    {
      parent.headerframe.document.objHourGlass.visibility='visible';
    }else
    if ( objHourGlass != null )
    {
      objHourGlass.visibility='visible';
    }else
    {
      objHourGlass=bw.dom?parent.headerframe.document.getElementById(div).style:bw.ie4?parent.headerframe.document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
    //  objHourGlass=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
      if ( objHourGlass != null )
        objHourGlass.visibility='visible';
    //  else
    //    alert( "ERROR (SHOW): could not find HOUR GLASS");
    }
  }
}
//Hides the div
function hide(div,nest)
{
  if ( window == top || ( gstFrameName == "editframe" ) )
  {
    bw=checkBrowser();
    if ( parent != null && parent.headerframe != null && parent.headerframe.document.objHourGlass != null )
    {
      parent.headerframe.document.objHourGlass.visibility='hidden';
    }else
    if ( objHourGlass != null )
    {
      objHourGlass.visibility='hidden';
    }else
    {
      if ( parent != null && parent.headerframe != null )
        objHourGlass=bw.dom?parent.headerframe.document.getElementById(div).style:bw.ie4?parent.headerframe.document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
      else
        objHourGlass=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
      if ( objHourGlass != null && objHourGlass )
        objHourGlass.visibility='hidden';
      //else
      //  alert( "ERROR (HIDE): could not find HOUR GLASS");
    }
  }
}

function startup( mydoc, stDoSubAction, stActionValue )
{	
  browserIs=checkBrowser();
  
	//Set frame indicator variable.
	//
	gstFrameName = stDoSubAction;
	
	//Startup Action taken for the dataframe in Edit mode.
	//
  if ( gstFrameName == "dataframe" )
  {
    //Show alert dialogue box if there is an Error Value.
    if ( mydoc.form1.ErrorField.value != "" )
      alert( mydoc.form1.ErrorField.value );
    
    //Show alert dialogue if PopUp Variable is set.  
    thisCtrl3 = eval("mydoc.form1.PopUp" );
    if ( thisCtrl3 && thisCtrl3 != null && thisCtrl3.value != "")
      alert(thisCtrl3.value);

    //Set the Focus field.
    
    //Preserve original Vertical scroll position.
    vScroll=document.form1.VScrollPosition.value;
    
    //Set Focus Field.
    focusField = mydoc.form1.setfocusfield.value;
    //RA 8/25/04 added check for empty focusField, for some reason we would sometimes get a js error
    //"can't move focus to the control because it is invisible, not enabled or of a type that does not accept the focus"
    //document.form1.elements[i].name would = "" and focusField = "" when this happenned
    //
    if ( focusField != "" )
    {
      for (i=0;i<document.form1.elements.length;i++)
      {
  		  if(browserIs.ns5)
  			  eval("onfocus['"+document.form1.elements[i].name+"']=document.form1.elements[i].getAttribute('onfocus')");
  			if(browserIs.ie5||browserIs.ie6)
  			  eval("onfocus['"+document.form1.elements[i].name+"']=document.form1.elements[i].attributes.onfocus.value");
  			document.form1.elements[i].onfocus=focusFieldTracking;
        if (document.form1.elements[i].name==focusField)
          if ( document.form1.elements[i].type=="radio"){
            if(document.form1.elements[i].checked)
              document.form1.elements[i].focus();
            }
          else
            document.form1.elements[i].focus();
        }
    }
    //Restore original Vertical scroll position.
    document.form1.VScrollPosition.value=vScroll;
    
    //Scroll page to last known point if nessisary.
  	if(window!=top&&gstFrameName=="dataframe")
      goToScrollPosition();
    
    StartupComplete=1;
    PageStatus(1);
    return true;
  }


  if ( stDoSubAction == "footerframe" )
  {
    StartupComplete=1;
    return true;
  }

  if ( stDoSubAction == "MailMerge" )
  {
    createWindowRTF( stActionValue,stDoSubAction );
  }

  //Sets Focus on specific pages.
  if ( mydoc.form1 && mydoc.form1.setfocus )
  {
    if ( mydoc.form1.setfocus.value == 4 )
    {
      mydoc.form2.p.focus();
    }
    //No longer used in other code.
    /*if ( mydoc.form1.setfocus.value == 2 )
    {
      mydoc.form1.FormAction.value = "./include/login.php";
      mydoc.form1.p.focus();
    }
    if ( mydoc.form1.setfocus.value == 1 )
    {
      mydoc.form1.email.focus();
    }
    if ( mydoc.form1.setfocus.value == 3 )
    {
      mydoc.form1.AccessId.focus();
    }*/
    
  }

  PageStatus(1);
  StartupComplete=1;

  if( mydoc.form1 && mydoc.form1.ErrorField && mydoc.form1.ErrorField.value != "" )
    return validate(mydoc.form1);
  else
    return true;

  return true;
}

function cleanup( mydoc )
{ 
  //If you have opened a PopUp Window. . .
  //Then it is closed when the main window is changed.
  if(top.newWin)
    top.newWin.close();

  if(gstFrameName != "TimedOut")
    if(window!=top&&
      (!parent.dataframe.document.form1.DoAction.value)&&
      (!parent.dataframe.document.form1.DoSubAction.value)&&
      parent.dataframe.document==mydoc){
      alert("While in Edit mode this action may cause you to lose information.\nPlease use the navigation options at the bottom of this page.");
      parent.location="./editframe.php";
      }

  if ( StartupComplete !=1 )
  {
    if ( StartupComplete != -2 )
    {
      // this make no sense to be put out.
      //alert( "In CLEAN UP -- BUT STARTUP HAS NEVER FINISHED");
    }
  }
  StartupComplete = -3;
 // PageStatus(-3);

  if ( DebugScript > 0 )
    alert( "cleanup ...");
}

function HrefFormAction2( mydoc, stHref, iMainTab )
{
   mydoc.form1.MenuId.value = 0;
   //This is to unlock the form before a known submit.
   mydoc.form1.onsubmit=null;
   mydoc.form1.submit();
}

function HrefFormAction( mydoc, stHref, iMainTab )
{
  var iMenuId;

  if ( AmIBusy() )
    return;

  if ( mydoc.form1.DoEdit && mydoc.form1.DoEdit != null )
  {
    if ( ! validate( mydoc.form1 ) )
      return;
  }

  mydoc.form1.DoAction.value  = "FormAction";
  if ( stHref != "" )
  {
    mydoc.form1.ActionValue.value = stHref;
  }

  if ( DebugScript > 0 )
    alert( mydoc.form1.FormAction.value  );

  if (window != top)
  {
    a = confirm("You are leaving this record's Edit mode.\nAll unsaved data will be discarded.\nClick 'OK' to continue or 'Cancel' to go back to the record's Edit page.");
    if (a)
    {
      mydoc.form1.DoAction.value  = "CancelEdit";
      mydoc.form1.DoSubAction.value  = "FormAction";

      mydoc.form1.MenuId.value = iMenuId;
      //This is to unlock the form before a known submit.
      mydoc.form1.onsubmit=null;
      mydoc.form1.submit();
      return;
    }else
    {
      PageStatus(1); //StartupComplete = 1;
      return;
    }
   }
   mydoc.form1.DoAction.value  = "CancelEdit";
   mydoc.form1.DoSubAction.value  = "FormAction";

   mydoc.form1.MenuId.value = iMenuId;
   //This is to unlock the form before a known submit.
   mydoc.form1.onsubmit=null;
   mydoc.form1.submit();
}

function SetDoActionFields( mydoc, stAction, stSubAction,  stParamValue )
{
  mydoc.form1.DoAction.value  = stAction;
  mydoc.form1.DoSubAction.value  = stSubAction;
  mydoc.form1.ActionValue.value = stParamValue;
}

function HrefMenuIdSetField2( mydoc, iMainTab, stAction, stSubAction,  stParamValue )
{
  if ( AmIBusy() )
    return;
  if (window == top)
  {
    mydoc.form1.DoAction.value  = stAction;
    mydoc.form1.DoSubAction.value  = stSubAction;
    if ( stAction!="CancelEdit" )
    {
      if ( ! validate( mydoc.form1 ) )
      {
        return;
      }
    }
    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.MenuId.value    = iMainTab;
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }else
  {
    parent.dataframe.document.form1.DoAction.value  = stAction;
    parent.dataframe.document.form1.DoSubAction.value  = stSubAction;
    if( parent.dataframe.document.form1.ActivityMode.value>0)
    {
        stAction = "CancelEdit";
    }
    if ( stAction != "CancelEdit" )
    {
      if ( ! validate( parent.dataframe.document.form1 ) )
      { 
        return;
      }
    }
    if ( stAction == "CancelEdit" )
    {
         cancelmsg = confirm("This action ('Cancel') will discard any unsaved data entered for this record. \nClick 'OK' to continue with the Cancel action or 'Cancel' to go back to the record's Edit page.");
          if (cancelmsg)
          {
           if(parent.dataframe.document.form1.ActivityMode.value>0)
           {
             parent.dataframe.document.form1.DoAction.value  = "CancelEdit";
             parent.dataframe.document.form1.DoSubAction.value  = "CancelActivity";
             parent.dataframe.document.form1.TabId.value = stParamValue;
           }
           parent.dataframe.document.form1.ActionValue.value = stParamValue;
           parent.dataframe.document.form1.MenuId.value    = iMainTab;
           mydoc.form1.DoEdit.value=0;
           //This is to unlock the form before a known submit.
           parent.dataframe.document.form1.onsubmit=null;
           parent.dataframe.document.form1.submit();
          }
          else
          {
            PageStatus(1); //StartupComplete = 1;
            return;
          }
    }
    parent.dataframe.document.form1.ActionValue.value = stParamValue;
    parent.dataframe.document.form1.MenuId.value = iMainTab;
    parent.dataframe.document.form1.DoEdit.value=1;
    //This is to unlock the form before a known submit.
    parent.dataframe.document.form1.onsubmit=null;
    parent.dataframe.document.form1.submit();
  }
}

function HrefReport(mydoc,iTask,stField)
{
  for (i = 0; i < 200; i++ )
  {
    stField2 = "mydoc.form1." + stField + "_" + i ;
    thisCtrl = eval(stField2);
    if ( thisCtrl && thisCtrl != null )
    {
      if ( iTask == 1 )
        thisCtrl.checked = true;
      if ( iTask == 2 )
        thisCtrl.checked = false;
    }else
    {
      break;
    }
  }

}

function HrefMenuIdSetField( mydoc, iMainTab, stAction, stSubAction,  stParamValue )
{

  if ( AmIBusy() )
    return;

  mydoc.form1.DoAction.value  = stAction;
  mydoc.form1.DoSubAction.value  = stSubAction;

   if ( stSubAction == "SubmitAlertFilter" ) //AR 15-jul-06 PEM_BL_00179 
	{
	   
 
	if(mydoc.form1.AlertChoices.value == -1 ) 
		{
			alert ( "Please Select the type of Task " ) ;
			PageStatus(1); //StartupComplete = 1;
				return;
		}
		else if (mydoc.form1.AlertChoices.value == 2 )
		{
			if(  (mydoc.form1.AlertRecipient.value=='') && 
				 (mydoc.form1.elements["UsersChoiceBox[]"].value=='')&&(mydoc.form1.elements["UserGChoiceBox[]"].value=='')&&
			     (mydoc.form1.elements["UserGTypeChoiceBox[]"].value=='')
			 ) 
			{
				alert ("Please select the reciepient of the alert" ) ;
				PageStatus(1); //StartupComplete = 1;
				return ;
			}
		}
		else
		{
			if( (mydoc.form1.elements["UsersChoiceBox[]"].value== '') &&
			    (mydoc.form1.elements["UserGChoiceBox[]"].value=='')&&( mydoc.form1.elements["UserGTypeChoiceBox[]"].value=='')  
			 ) 
			{
				alert ("Please select the reciepient of the alert" ) ;
				PageStatus(1); //StartupComplete = 1;
				return ;
			}
		}
	}
  if ( stAction != "CancelEdit" && stAction !="Cancel" && stSubAction!="Lookup" && stSubAction!="NoTouchNoPopupRecordLookup" )
  {
    if ( ! validate( mydoc.form1 ) )
      return;
  }
  if ( stAction == "CancelEdit" )
  {
    if ( window != top )
     {
      cancelmsg = confirm("This action ('Cancel') will discard any unsaved data entered for this record. \nClick 'OK' to continue with the Cancel action or 'Cancel' to go back to the record's Edit page.");
        if (cancelmsg)
        {
         mydoc.form1.ActionValue.value = stParamValue;
         mydoc.form1.MenuId.value = iMainTab;
         mydoc.form1.DoEdit.value = 0;
         //This is to unlock the form before a known submit.
         mydoc.form1.onsubmit=null;
         mydoc.form1.submit();
         return;
        }
        else
        {
          PageStatus(1); //StartupComplete = 1;
          return;
        }
     }
  }

  if (window != top && ( stSubAction == "FieldListChangeEdit" || stSubAction == "FieldListDelete" || stSubAction == "Lookup" || stSubAction == "NoTouchNoPopupRecordLookup") )
  {
    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.MenuId.value = iMainTab;
    mydoc.form1.SubMenuId.value = stParamValue;
    mydoc.form1.target = "dataframe";
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }
  if (window != top && stAction != "Next" &&  stAction != "Previous" && stSubAction != "SendEmail" && stSubAction != "MailMerge"  )
  {
    a = confirm("You are leaving this record's Edit mode.\nAll unsaved data will be discarded.\nClick 'OK' to continue or 'Cancel' to go back to the record's Edit page.");
    if (a)
    {
      mydoc.form1.DoEdit.value = 0;
      if( mydoc.form1.ActivityMode.value>0)
      {
          mydoc.form1.DoAction.value  = "CancelEdit";
          mydoc.form1.DoSubAction.value  = "CancelActivity";
          iMainTab = 4096;
      }
      else
      {
        mydoc.form1.DoAction.value = "CancelEdit";
        mydoc.form1.DoSubAction.value = "CancelEdit";
      }
      mydoc.form1.ActionValue.value = stParamValue;
      mydoc.form1.MenuId.value = iMainTab;
      //This is to unlock the form before a known submit.
      mydoc.form1.onsubmit=null;
      mydoc.form1.submit();
      return;
    }
    else
    {
      PageStatus(1); //StartupComplete = 1;
      return;
    }
  }
  
  if (  stAction == "Search" && stSubAction == "RemoveCondition" )
  {
    cancelmsg = confirm("Are you sure you want to remove this condition?");
    if (cancelmsg)
    {
      mydoc.form1.ActionValue.value = stParamValue;
      mydoc.form1.MenuId.value    = iMainTab;
      //This is to unlock the form before a known submit.
      mydoc.form1.onsubmit=null;
      mydoc.form1.submit();
      return;
    }
    else
    {
      PageStatus(1); //StartupComplete = 1;
      return;
    }
  }
  
  if (  stAction == "CurrentCase" && (stSubAction == "MailMerge" || stSubAction == "SendEmail" )){
    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.DoEdit.value = 0;
    mydoc.form1.MenuId.value = iMainTab;
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }

	if (  stAction == "Search" && stSubAction == "NewSearchPage" )//Wednesday, April 19, 2006 Anshu
	{
		mydoc.form1.ReportListOffset.value = stParamValue;
	}


  if (  stAction == "Search" && stSubAction == "RunExportField" )
  {
    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.MenuId.value    = iMainTab;
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
  }
  else
  {
    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.MenuId.value    = iMainTab;
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }
}


function ButtonHrefMenuIdSetField( mydoc, stName, stField, stValue, iMainTab )
{

  if ( AmIBusy() )
    return;

  mydoc.form1.DoAction.value  = stName;

  if ( ! validate( mydoc.form1 ) )
    return;

  var thisCtrl;
  thisCtrl = eval("mydoc.form1." + stField);

  thisCtrl.value = stValue;

  mydoc.form1.MenuId.value    = iMainTab;
  //This is to unlock the form before a known submit.
  mydoc.form1.onsubmit=null;
  mydoc.form1.submit();

}

function HrefMenuIdSetFieldFrame( mydoc, iMainTab, stAction, stSubAction,  stParamValue )
{
  if ( AmIBusy() )
    return;

  if (window == top)
  {
    mydoc.form1.DoAction.value  = stAction;
    mydoc.form1.DoSubAction.value  = stSubAction;
    if ( stAction != "CancelEdit" && stAction !="Cancel")
    {
      if ( ! validate( mydoc.form1 ) )
      {
      alert(stAction);
        return;
      }
    }

	if (stAction == "CopyEditNew")
	{
		cancelmsg = confirm("This action ('CopyEditNew') will duplicate this record and place the new copy in edit mode. \nClick 'OK' to continue with the Copy action or 'Cancel' to go back to the record's Edit page.");

		if (!cancelmsg)
		{
			PageStatus(1); //StartupComplete = 1;
			return;
		}
	}

    mydoc.form1.ActionValue.value = stParamValue;
    mydoc.form1.MenuId.value    = iMainTab;
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }else
  {
    parent.dataframe.document.form1.DoAction.value  = stAction;
    parent.dataframe.document.form1.DoSubAction.value  = stSubAction;
    if ( stAction != "CancelEdit" && stAction !="Cancel")
    {
      if ( ! validate( parent.dataframe.document.form1 ) )
      {
        return;
      }
    }else
    {
         cancelmsg = confirm("This action ('Cancel') will discard any unsaved data entered for this record. \nClick 'OK' to continue with the Cancel action or 'Cancel' to go back to the record's Edit page.");
           if (cancelmsg)
          {
           parent.dataframe.document.form1.ActionValue.value = stParamValue;
           parent.dataframe.document.form1.MenuId.value = iMainTab;
           parent.dataframe.document.form1.DoEdit.value=1;
           //This is to unlock the form before a known submit.
           parent.dataframe.document.form1.onsubmit=null;
           parent.dataframe.document.form1.submit();
           return;
          }
          else
          {
            PageStatus(1); //StartupComplete = 1;
            return;
          }
    }
    if ( stSubAction == "SaveNewLayer"  )
    {
      parent.dataframe.document.form1.DoAction.value = "ChangeSeqNr";
      parent.dataframe.document.form1.target = "dataframe";
      parent.dataframe.document.form1.ActionValue.value = -1;
      //This is to unlock the form before a known submit.
      parent.dataframe.document.form1.onsubmit=null;
      parent.dataframe.document.form1.submit();
      PageStatus(1);
      return;
    }
    parent.dataframe.document.form1.ActionValue.value = stParamValue;
    parent.dataframe.document.form1.MenuId.value = iMainTab;
    parent.dataframe.document.form1.DoEdit.value=1;
    //This is to unlock the form before a known submit.
    parent.dataframe.document.form1.onsubmit=null;
    parent.dataframe.document.form1.submit();
  }
}

function PerformMainAction( mydoc, mainAction, warning )
{
  if ( AmIBusy() )
    return;

  if ( ! validate( mydoc.form1 ) )
    return;
  
  if (mydoc.form1.DoEdit.value>0)
  {
    alert('You are currently editing a record please "Cancel" or "Save" before you Logout!');
    PageStatus(1); StartupComplete = 1;
    return
  }
  if (warning!=null)
  {
    a = confirm(warning);
    if (a)
    {
      mydoc.form1.DoAction.value = mainAction;
      //This is to unlock the form before a known submit.
      mydoc.form1.onsubmit=null;
      mydoc.form1.submit();
      return;
    }
    else
    {
      PageStatus(1); StartupComplete = 1;
    }
  }
  else
  {
  mydoc.form1.DoAction.value = mainAction;
  //This is to unlock the form before a known submit.
  mydoc.form1.onsubmit=null;
  mydoc.form1.submit();
  }
}

function MainTabClick( mydoc, iMenuId )
{
  if ( AmIBusy() )
    return;

  if ( ! validate( mydoc.form1 ) )
    return;
    
  if (window != top)
  {
    a = confirm("You are leaving this record's Edit mode.\nAll unsaved data will be discarded.\nClick 'OK' to continue or 'Cancel' to go back to the record's Edit page.");
    if (a)
    {
      parent.dataframe.document.form1.DoEdit.value = 0;
      if( mydoc.form1.ActivityMode.value>0)
      {
          parent.dataframe.document.form1.DoAction.value  = "CancelEdit";
          parent.dataframe.document.form1.DoSubAction.value  = "CancelActivity";
          iMenuId = 4096;
      }
      else
      {
        parent.dataframe.document.form1.DoAction.value = "CancelEdit";
        parent.dataframe.document.form1.DoSubAction.value = "CancelEdit";
      }      
      switch(iMenuId)
      {
        case 512:
          subMenuId = 3010;
          break;
        case 2048:
          subMenuId = 2020;
          break;
        case 16384:
          subMenuId = 4011;
          break;
        case 4096:
          subMenuId = 1;
          break;
        case 8388608:
        	subMenuId = "";  //JB - 9/19/03 - Value 8020 was causing an error.
        	break;
        default:
          subMenuId="";
          break;     
      }
      parent.dataframe.document.form1.MenuId.value = iMenuId;
      parent.dataframe.document.form1.SubMenuId.value = subMenuId;
      //This is to unlock the form before a known submit.
      parent.dataframe.document.form1.onsubmit=null;
      parent.dataframe.document.form1.submit();
      return;
    }
    else
    {
      PageStatus(1); //StartupComplete = 1;
      return false;
    }
  }
  mydoc.form1.MenuId.value = iMenuId;
  mydoc.form1.DoAction.value = "MainButtonClick";
  switch(iMenuId)
  {
    case 512:
      mydoc.form1.SubMenuId.value = 3010;
      break;
    case 2048:
      mydoc.form1.SubMenuId.value = 2020;
      break;
    case 16384:
      mydoc.form1.SubMenuId.value = 4011;
      break;
    case 4096:
      mydoc.form1.SubMenuId.value = 1;           
      break;
    case 8388608:
    	//mydoc.form1.SubMenuId.value = 8010;  //JB - 9/19/03 - Value 8020 was causing an error.
    	break;
  }
  //This is to unlock the form before a known submit.
  mydoc.form1.onsubmit=null;
  mydoc.form1.submit();
}

function ChangeSeqNr(form)
{
  if ( AmIBusy() )
    return;

  form.DoAction.value = "ChangeSeqNr";
  if ( ! validate( form ) )
    return;
  if ( form.DoEdit.value > 0 )
  {
    form.target = "dataframe";
  }
  form.ActionValue.value = form.SeqNr3.value;
  //This is to unlock the form before a known submit.
  form.onsubmit=null;
  form.submit();

}

function OnChoices(form1, fieldname)
{
  var i;
  giCurrentField = 0;

  if ( AmIBusy() )
   return;

  for (i = 0; i < gaAttributes.length ; i++)
  {
    if ( gaAttributes[i][1] == fieldname )
    {
      if ( ( gaAttributes[i][0] & 64 ) )  // Conditon Check?
      {
        form1.DoAction.value = "OnChoices";
        form1.DoSubAction.value = "OnChoices";
        form1.ActionValue.value = fieldname;


        if ( gaAttributes[i][3] == 9 )
        {
          thisCtrl = eval("parent.dataframe.document.form1." + fieldname  );
          if ( ShouldRefreshChoices( thisCtrl, gaAttributes[i][6] ) || ( gaAttributes[i][0] & 16384 ))
          {
            // RE: 11/8/02 PEM-SW-00121
            form1.target = "dataframe";
            //This is to unlock the form before a known submit.
            form1.onsubmit=null;
            form1.submit();
            // - Temporary fix to dependant top level sub tabs.  (See second call below also)
            //   This refresh call should be returned in the body of the dataframe
            //   for an onchoices call, only if main tabs are effected by the dependancy.
            //RA 12/9/04 - Not sure why this was needed but it cause a flash to happen after a choice is 
            //changed and the page finished loading
            //
            //setTimeout("parent.headerframe.location.reload();", 500);
            return;
          }
          else
          {
            PageStatus(1); //StartupComplete = 1;
            return;
          }
        }
        form1.target = "dataframe";
        //This is to unlock the form before a known submit.
        form1.onsubmit=null;
        form1.submit();
        // - Temporary fix to dependant top level sub tabs.
        //RA 12/9/04 - Not sure why this was needed but it cause a flash to happen after a choice is 
        //changed and the page finished loading
        //
        //setTimeout("parent.headerframe.location.reload();", 500);
        return;
      }
      break;
    }
  }
  PageStatus(1); //StartupComplete = 1;
  return false;
}

function OnChoicesLookup(form1, fieldname, iMainTab, stParamValue)
{
  var i;
  giCurrentField = 0;

  if ( AmIBusy() )
   return;

  HrefMenuIdSetField(window.document, iMainTab, "CurrentCase", "Lookup", stParamValue);

  for (i = 0; i < gaAttributes.length ; i++)
  {
    if ( gaAttributes[i][1] == fieldname )
    {
      if ( ( gaAttributes[i][0] & 64 ) )  // Conditon Check?
      {
        form1.DoAction.value = "OnChoices";
        form1.DoSubAction.value = "OnChoices";
        form1.ActionValue.value = fieldname;


        if ( gaAttributes[i][3] == 9 )
        {
          thisCtrl = eval("parent.dataframe.document.form1." + fieldname  );
          if ( ShouldRefreshChoices( thisCtrl, gaAttributes[i][6] ) || ( gaAttributes[i][0] & 16384 ))
          {
            // RE: 11/8/02 PEM-SW-00121
            form1.target = "dataframe";
            //This is to unlock the form before a known submit.
            form1.onsubmit=null;
            form1.submit();
            // - Temporary fix to dependant top level sub tabs.  (See second call below also)
            //   This refresh call should be returned in the body of the dataframe
            //   for an onchoices call, only if main tabs are effected by the dependancy.
            //setTimeout("parent.headerframe.location.reload();", 500);
            return;
          }
          else
          {
            PageStatus(1); //StartupComplete = 1;
            return;
          }
        }
        form1.target = "dataframe";
        //This is to unlock the form before a known submit.
        form1.onsubmit=null;
        form1.submit();
        // - Temporary fix to dependant top level sub tabs.
        //setTimeout("parent.headerframe.location.reload();", 500);
        return;
      }
      break;
    }
  }
  PageStatus(1); //StartupComplete = 1;
  return false;
}

function OnCompare(mydoc, subAction, actionValue)
{
  if ( AmIBusy() )
   return;
  mydoc.form1.DoSubAction.value = subAction;
  mydoc.form1.ActionValue.value = actionValue;
  mydoc.form1.target = "dataframe";
  //This is to unlock the form before a known submit.
  mydoc.form1.onsubmit=null;
  mydoc.form1.submit();
  return;
}

function MyMatch2( thisCtrl, item )
{
  if ( thisCtrl == null )
  {
    alert("Ctrl is null:MyMatch2");
    return 0;
  }

  var Num = thisCtrl.options.length;
  var List = new Array();
  var i;
  var match = 0; // Need initial value

  var index=0;
  for (i = 0; i < Num; i++)
  {
    if ( thisCtrl.options[i].selected )
    {
      List[index] = thisCtrl.options[i].value;
      ++index;
    }
  }

  var itemtemp = item.split("^");
  var itemList = itemtemp[1].split("|");

  for(i=0;i < List.length ; i++)
  {
    for ( j=1; j < itemList.length -1; ++j )
    {
//alert( List[i]+"="+"|"+itemList[j]+"|" );
      if ( List[i] == "|"+itemList[j]+"|" )
      {
 //alert("match found:MyMatch2");
        return 1;
      }
    }
  }
  return match;
}

function ShouldRefreshChoices( thisCtrl, item )
{
   var result = 0;

   if ( item == "" )
     return 0;

   var itemtemp = item.split("^");
   var itemList = itemtemp[1].split("|");

   //Check to see if the old selected value needs a refresh
   //
   for ( j=1; j < itemList.length -1; ++j )
   {
//alert("1:"+itemtemp[0]+"="+"|"+itemList[j]+"|" );
      if ( itemtemp[0] == "|"+itemList[j]+"|" )
      {
 //      alert("match found:ShouldRefresh");
        return 1;
      }
   }

   // check to see if the new selected value needs a refresh
   //
   if ( MyMatch2( thisCtrl, item ) )
     result = 1;

  return result;
}

function ShouldRefreshCheckBox( thisCtrl, item )
{
   if ( thisCtrl == null )
   {
     alert("Ctrl is null:ShouldRefreshCheckBox");
     return 0;
   }
   if ( item == "" )
    return 0;

   var result = 0;
   var itemtemp = item.split("^");
   var itemList = itemtemp[1].split("|");

   for ( j=1; j < itemList.length -1; ++j )
   {
     if ( thisCtrl.value != null )
     {
//  alert( thisCtrl.value+"="+itemList[j] );

       if ( thisCtrl.value == itemList[j] )
       {
//alert("match found:ShouldRefreshCheckBox");
         return 1;
       }
     }
   }

  return result;
}




function AmIBusy()
{
  browserIs=checkBrowser();

  if ( window != top && gstFrameName == "dataframe" )
  {
    //alert( "Redirecting status=" + status +" StartupComplete for frame = " + gstFrameName);
    return parent.headerframe.AmIBusy();
  }

  if ( StartupComplete !=1 )
  {   
    if ( StartupComplete == -2 )
    {
     alert( "You can only do one action at a time.\r\n\r\nPlease wait for completion and do again.");
    }
    else if ( StartupComplete == -3 )
    {
      alert( "This page is still loading. Please wait before making another choice.\r\n\r\nIf this action does not finish in a timely manner, click on the \"Refresh\" link at the top of this page \(to the left of \"Help\"\).");
    }else
    {
      alert( "This page is still loading. Please wait before making another choice.\r\n\r\nIf this action does not finish in a timely manner, click on the \"Refresh\" link at the top of this page \(to the left of \"Help\"\).  " + StartupComplete   );
    }
    return true;
  }else
  {
    if(browserIs.ie5||browserIs.ie6||browserIs.ns5)
    {
      if ( window != top && gstFrameName == "dataframe" )
        parent.headerframe.PageStatus(-2);
      else
        PageStatus(-2);
      return false;
    }
    else
      return false;
  }
}

function PageStatus(status)
{
  browserIs=checkBrowser();
  if ( window != top && gstFrameName == "dataframe" )
  {
    // alert( "Redirecting status=" + status +" StartupComplete for frame = " + gstFrameName);
    if ( parent && parent.headerframe && parent != null && parent.headerframe != null )
    {
      if( parent.headerframe.StartupComplete == 1 || parent.headerframe.StartupComplete == -2 )
      {
       return parent.headerframe.PageStatus( status );
      }else
      {
       return;
      }
    }else
    {
     return;
    }
  }

//alert(status);
  if (status == 1)
  {
    StartupComplete = 1;
    hide('loading');
    if((browserIs.ie5||browserIs.ie6||browserIs.ns5)&&useScreenLock)
      ScreenLockController(false);
  }
  else if (status == -2)
  {
    if((browserIs.ie5||browserIs.ie6||browserIs.ns5)&&useScreenLock)
      ScreenLockController(true);
    else
      show('loading');
    StartupComplete = -2;
  }
  else // if (status == -3)
  {
    show('loading');
    if((browserIs.ie5||browserIs.ie6||browserIs.ns5)&&useScreenLock)
      ScreenLockController(true);
    else
      show('loading');
    StartupComplete = -3;
  }
 //alert( " StartupComplete DONE");
 }

function GenericSubmit(form,stAction,stSubAction,stActionValue)
{
  if ( AmIBusy() )
    return;
 
  if ( stSubAction == "FieldList" )
  {
    form.DoAction.value = stAction;
    form.DoSubAction.value = stSubAction;
    form.ActionValue.value = stActionValue;
    if ( stAction != "Search" && stAction != "Reports" && stAction != "ProcessDBM" )
      form.target = "dataframe";
    ListSelectionFinalize(form);
    //This is to unlock the form before a known submit.
    form.onsubmit=null;
    form.submit();
    return;
  }

  form.DoAction.value = stAction;
  form.DoSubAction.value = stSubAction;

  if ( ! validate( form ) )
    return;

  form.ActionValue.value = stActionValue;
  //This is to unlock the form before a known submit.
  form.onsubmit=null;
  form.submit();
}


function createWindowRTF( URL,windowName )
{
    var features =
        'directories=' + 0 +
        ',location='    + 0 +
        ',menubar='     + 1 +
        ',scrollbars='  + 1 +
        ',status='      + 0 +
        ',toolbar='     + 1 +
        ',alwaysRaised='+ 1 +
        ',Resizable='  + 1 +
        ',screenX='  + 3 +
        ',screenY='  + 3 +
        ',alwaysRaised=' + 1;

    window.open (URL, windowName, features);
}

// Used by ADD WEBAGENT FIELD
function AddField( ctrl, stAction, stSubAction, fieldname)
{
    if ( AmIBusy() )
    return;

  var thisCtrl;
  var form1;
  var i;

  form1 = ctrl.form;

  if ( form1.WEBagentSelectionList.value == -1 && form1.WEBagentClick.value == 1  )
  {
    alert( "You must slect a field first!");
    form1.WEBagentClick.value = 0;
  }else
  {
    var thisCtrl;
    thisCtrl = eval("ctrl.form." + fieldname);
    form1.DoAction.value = stAction;
    form1.DoSubAction.value = stSubAction;
    form1.ActionValue.value = fieldname;

    if ( form1.WEBagentClick.value == 1 )
    {
      if ( thisCtrl.value == "" )
      {
        thisCtrl.value = form1.WEBagentSelectionList.value;
      }else
      {
        thisCtrl.value = thisCtrl.value + "," + form1.WEBagentSelectionList.value;
      }
      //This is to unlock the form before a known submit.
      form1.onsubmit=null;
      form1.submit();
      return;
    }else
    if ( form1.WEBagentClick.value == 2 )
    {
      thisCtrl.value = "";
      form1.WEBagentSelectionList.value = -1;
      form1.WEBagentClick.value = 0;
      //This is to unlock the form before a known submit.
      form1.onsubmit=null;
      form1.submit();
    }
  }

  PageStatus(1); //StartupComplete = 1;
}

function validNum(value)
{
  var result = true;
 // var num = parseInt(value,10);
 // SA 7/30/04 - added validation to ensure integer is not less than 0 (PEM-SW-01045)
    
    //MT added to validate the INTEGER type of field.  PEM-BL-00264
	var validFormatRegExp = /^((\+|-)\d)?\d*$/;  //Allow Only Integer
	//var validFormatRegExp = /^\d*(\.\d+)?$/;     //Allow Only Integer and  Decimal
	if (!validFormatRegExp.test(value) || value < 0) 
	{
	  result=false;
	}
  return result;
}

function validNumber(value)
{ //MT PEM-BL-00229 02Aug06 : added to validate the NUMBER type of field. 
  var result = true;
 	//var validFormatRegExp = /^((\+|-)\d)?\d*$/;  //Allow Only Integer
	var validFormatRegExp = /^\d*(\.\d+)?$/;     //Allow Only Integer and  Decimal
	if (!validFormatRegExp.test(value) || value < 0) 
	{
	  result=false;
	}
  return result;
}



function validDate( value, DobFlag )
{

  var result = true;
  var stmonth = 0;
  var stday = 0;
  var styear = 0;

  var re = new RegExp('[ /.-]');
  var elems = value.split( re );

  if (value == "")
    return true;

  result = (elems.length == 3); // should be three components
  if (result)
  {
    //Use date format specified in config.
    switch(dateFormat)
    {
      default:  //Standard mm/dd/yyyy
        stmonth = parseInt(elems[0],10);
        stday = parseInt(elems[1],10);
        styear = parseInt(elems[2],10);
      break;

	  case 1:  //Standard mm/dd/yyyy
        stmonth = parseInt(elems[0],10);
        stday = parseInt(elems[1],10);
        styear = parseInt(elems[2],10);
      break;

	  case 2: // yyyy/mmm/dd
	    styear = parseInt(elems[0],10);
		stmonth = stMonth2Int(elems[1]);
        stday = parseInt(elems[2],10);
	  break;

	  case 3: // yyyy mmm dd
	    styear = parseInt(elems[0],10);
		stmonth = stMonth2Int(elems[1]);
        stday = parseInt(elems[2],10);
	  break;
	}

	//alert ( "month ="+stmonth + " day =" + stday + " year =" + styear );

  } 


  return validDateHelper( stmonth, stday, styear );
}

function validDateHelper( stmonth, stday, styear )
{

  //alert ( "month ="+stmonth + " day =" + stday + " year =" + styear );

  result = !isNaN(stmonth) && (stmonth > 0) && (stmonth < 13) &&
        !isNaN(stday) && (stday > 0) && (stday < 32) &&
        //!isNaN(year) && ( elems[2].length == 2 || elems[2].length == 4 );
       // !isNaN(styear) && ( elems[2].length == 4 );
        !isNaN(styear) && ( styear >= 1800 ) && ( styear <= 2500 );

  return result;
}


function validTime(value,ampm)
{
  var result = true;
  var sec;
  var elems = value.split(":");

  result = (elems.length > 1 ); // should be three components
  if ( result == 0 )
  {
    if ( value.length == 3)
    {
      elems[0] = value.substring( 0, 1 );
      elems[1] = value.substring( 1, 3 );
    }else
    if ( value.length == 4)
    {
      elems[0] = value.substring( 0, 2 );
      elems[1] = value.substring( 2, 4 );
    }else
    {
      elems[0] = 99; // Make it fail
      elems[1] = 99;
    }
    result = 1;
  }
  if (result)
  {
    var hour = parseInt(elems[0],10);
    var min = parseInt(elems[1],10);
    if ( elems.length == 3 )
      sec = parseInt(elems[2],10);
    else
      sec = 0;

//alert ( value + " validTime hour: " + hour + " min: " + min + " sec: " + sec + ampm );
    if ( ampm != "" && ( ampm == "am" || ampm == "pm" || ampm == "AM" || ampm == "PM" ) )
    {
      if ( (hour >= 0) && (hour <= 12) )
        result=1;
      else
        result=0; // with AM/PM must be below 12:59
    }else
    if ( ampm != "" )
      result = 0;
    if( result )
      result = !isNaN(hour) && (hour >= 0) && (hour < 24) &&
          !isNaN(min) && (min >= 0) && (min < 60) &&
          !isNaN(sec) && (sec >= 0) && (sec < 60);
  }
  return result;
}

function validDateTime(value)
{
  var result = true;

  var elems = value.split(" ");
  if (elems.length > 1 )
  {

    if (elems.length > 2 )
      result = validTime( elems[1], elems[2] );
    else
      result = validTime( elems[1], "" );
  }
  if (result)
  {
    if (elems.length > 1 )
      result = validDate( elems[0] );
    else
      result = validDate( value );
  }
  return result;
}

function findDayofWeek(value)
{
  var ar = new Array();
  ar[0] = "Sunday";
  ar[1] = "Monday";
  ar[2] = "Tuesday";
  ar[3] = "Wednesday";
  ar[4] = "Thursday";
  ar[5] = "Friday";
  ar[6] = "Saturday";
  var UserDate = new Date(value);
  var day = UserDate.getDay();
  alert(ar[day]);
}

function SelectAll(obj,fieldname,count)
  {
  //This function seems dated and unused, should be deleted if this warning is not cued.
  alert("Warning 001:  Please notify your system administrator.");

  for(var ii=1;ii<=count;ii++)
    {
  if (bw == 'ie5' || 'ie4')
    {
    box = document.all[fieldname+ii];
    box.checked = obj.checked;
    }
  else
    {
    box = document.getElementsByName(fieldname+ii);
    box[0].checked = obj.checked;
    }
  }
}

function GetMultiCount( form1, iId )
{
  var iCount;
  var thisCtrl;
  var stField;

  iCount=0;
  // AD 3/25/2005 PEM-SW-01299 - Yes/No choice not being accepted if mandatory
  // Add support for Yes/No datatypes
  if ( parent.dataframe.gaAttributes[iId][3] == 2 )
  {
    for (i = 0; i < 200; i++ )
    {
      stField = "form1." + parent.dataframe.gaAttributes[iId][1] + "[" + i + "]";

      thisCtrl = eval(stField);
      if ( thisCtrl && thisCtrl != null )
      {
        if ( thisCtrl.checked == true )
          iCount++;
      }else
      {
        break;
      }
    }
  }
  else if ( parent.dataframe.gaAttributes[iId][3] == 9 && (parent.dataframe.gaAttributes[iId][0] & 32 ) )
  {
    for (i = 0; i < 200; i++ )
    {
      stField = "form1." + parent.dataframe.gaAttributes[iId][1] + "_" + i ;

      thisCtrl = eval(stField);
      if ( thisCtrl && thisCtrl != null )
      {
        if ( thisCtrl.checked == true )
          iCount++;
      }else
      {
        break;
      }
    }
  }

  return iCount;
}



function validate(form1)
{

  if (JSValidationDisable == 1) {

	  return true;

  }

  var i, j;
  var goon;
  var bReturn;
  var temp;
  var iLen;
  var thisCtrl;
  var bContinue;

  goon = 1;
  bReturn = true;

  //if ( window == top && ( ! form1.DoEdit || form1.DoEdit == null ) )
  if ( window == top  )
  {
    ListSelectionFinalize(form1);
  }
  if ( form1.DoSubAction.value == "CancelEdit" )
  {
     return true;
  }

  if ( form1.DoEdit.value == 0 )
  {
    return true;
  }
  
  if ( form1.ActivityMode.value == 2 )
  {
    return true;
  }

  if ( form1.DoAction.value == "DeleteCase" || form1.DoAction.value == "DeletePerson" || form1.DoAction.value == "DeleteActivity" )
  {
    a = confirm("Are you sure you want to DELETE this item?\nAll data associated with this item will be permanently removed.\nClick on 'OK' to confirm, or 'CANCEL' to cancel.");
    if (a)
    {
      return true;
    }else
    {
      PageStatus(1); // StartupComplete = 1;
      return false;
    }
  }
  
  stAlert = "";
  noFocusFLG = 0;
  
  // PG 04-Aug-06 PEM-BL-00268
  if (parent.dataframe.gaAttributes)
  {

  for (i = 0; i < parent.dataframe.gaAttributes.length && goon; i++)
  {

    switch( parent.dataframe.gaAttributes[i][3] )
    {
      case 12:   // People Involved
      case 13:   // Upload
      case 14:   // Template
      case 15:   // EMail
      case 17:   //
      case 18:   //
      case 19:   // IVR
        bContinue=true;
        break;
      default:
        bContinue=false;
        break;
    }
    if ( bContinue == true )
      continue;

    if ( (parent.dataframe.gaAttributes[i][0] & 3 ) == 0 )
      continue;

    if ( DebugScript )
    {
      alert( i + " validate " + parent.dataframe.gaAttributes[i][1] );
    }
    if ( parent.dataframe.gaAttributes[i][3] == 22 || ( parent.dataframe.gaAttributes[i][3] == 9 && (parent.dataframe.gaAttributes[i][0] & 32 ) ) )
    {
      thisCtrl = eval("form1." + parent.dataframe.gaAttributes[i][1] + "_0" );
    }else
    {
      thisCtrl = eval("form1." + parent.dataframe.gaAttributes[i][1] );
    }
    // 1) Check if EMPTY && MANDATORY -> ERROR
    iCount=0;
	// AD 3/25/2005 PEM-SW-01299 - Yes/No choice not being accepted if mandatory
	// Add support for Yes/No datatypes
    if ( parent.dataframe.gaAttributes[i][3] == 9 || parent.dataframe.gaAttributes[i][3] == 2 )
    {
      if( (parent.dataframe.gaAttributes[i][0] & 32 || parent.dataframe.gaAttributes[i][3] == 2 ) )
      {
        // loop through
        iCount = GetMultiCount( form1, i );
        if ( ! (parent.dataframe.gaAttributes[i][0] & 128 ) && iCount > 1 )
        {
          alert("Too many selections for field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2]+"\r\n\r\nYou can only select ONE choice!" );
          goon=0;
          bReturn = false;
        }
      }
    }

    if ( thisCtrl != null && thisCtrl.value != null ){
      iLen = thisCtrl.value.length
      }
    else
      iLen = 0;

    // RE: 8/16/2002 -- if mandatalue ory in other TAB, can't check it here !!
    //if( ! thisCtrl || thisCtrl == null || ( parent.dataframe.gaAttributes[i][0] & 1 ) <= 0  )
    if( ! thisCtrl || thisCtrl == null )
    {
      // alert(" MANDATORY NOT HERE IN THIS TAB  - IGNORING IT " + i );
    }else
	if ( goon && (parent.dataframe.gaAttributes[i][0] & 2 ) > 0 && ( parent.dataframe.gaAttributes[i][3] == 9 || parent.dataframe.gaAttributes[i][3] == 2 ))
    { // Mandatory choices or checkboxes
1
      /*if( !(parent.dataframe.gaAttributes[i][0] & 32 ) )
      {
        if ( thisCtrl.options[thisCtrl.selectedIndex].value == -1 ) // RE: 8/12/02 did not work on NN
        {
          stAlert = "Please select from MANDATORY field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
          goon=0;
          bReturn = false;
        }
      }
	  else
      {
        if ( iCount == 0 )
        {
          stAlert = "Please select from MANDATORY field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
          goon=0;
          bReturn = false;
        }
      }*/
      // AD 3/25/2005 PEM-SW-01299 - Yes/No choice not being accepted if mandatory
      // Add support for Yes/No datatypes
      if( !(parent.dataframe.gaAttributes[i][0] & 32 ) && parent.dataframe.gaAttributes[i][3] != 2)
      {
        /*if (thisCtrl.type=='hidden' && thisCtrl.value=='') //Condition added  by paxcel(3) task id #1061
        {													// if the Field is MANDATORY, HIDDEN,and NO value
        	stAlert = parent.dataframe.gaAttributes[i][2]+'\r\n is a MANDATORY field.';
			goon=0;
			bReturn = false;
			noFocusFLG=1;										//FLAG set, to ignore the FOCUS to this field. as its hidden
        }*/
      	if (thisCtrl.type=='hidden') //Condition added  by paxcel(3) task id #1061 03/08/2004
        {
			if(thisCtrl.value=='') //type is hidden and no value filled 03/08/2004
			{
				stAlert = "Please enter data into the MANDATORY field: \r\n" + parent.dataframe.gaAttributes[i][2];
				goon=0;
				bReturn = false;
				noFocusFLG=1;										//FLAG set, to ignore the FOCUS to this field. as its hidden
			}
        }
        else
        { 
        	if ( thisCtrl.options[thisCtrl.selectedIndex].value == -1 ) // RE: 8/12/02 did not work on NN
			{
				stAlert = "Please select from MANDATORY field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
				goon=0;
				bReturn = false;
			}
		}        
      }
      else
      {
		//alert("outside"+parent.dataframe.gaAttributes[i][2]);   
        if ( iCount == 0 )
        {
          stAlert = "Please select from MANDATORY field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
          goon=0;
          bReturn = false;
        }
      }

    }else
    if ( iLen == 0 && (parent.dataframe.gaAttributes[i][0] & 2 )  )
    //if ( (parent.dataframe.gaAttributes[i][0] & 2 )  )
    {
      if (thisCtrl.type=='hidden' ) noFocusFLG=1; //by paxcel(3) task id #1061. FLAG set, to ignore the FOCUS to this field. as its hidden

	  stAlert = "Please enter data into MANDATORY field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
      goon=0;
      bReturn = false;
    }else
    if ( iLen != 0 && parent.dataframe.gaAttributes[i][3] != 9 && parent.dataframe.gaAttributes[i][3] != 123456 )
    { //  2) NON CHOICES - NON EMPTY -- switch on DataType, check content

      if ( parent.dataframe.gaAttributes[i][3] != 22 )
      {
        if ( parent.dataframe.gaAttributes[i][4] )
        {
          if ( iLen < parent.dataframe.gaAttributes[i][4] ) // 4=min 5=max
          {
            stAlert = "Please enter at least " + parent.dataframe.gaAttributes[i][4] + " characters for field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
            goon=0;
            bReturn = false;
          }
        }
        if ( parent.dataframe.gaAttributes[i][5] )
        {
          if ( iLen > parent.dataframe.gaAttributes[i][5] ) // 4=min 5=max
          {
            stAlert = "Please enter only " + parent.dataframe.gaAttributes[i][5] + " characters for field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2] + "\r\n\r\nYou have entered: " + iLen;
            goon=0;
            bReturn = false;
          }
        }
      }
      if ( goon )
      {
        switch( parent.dataframe.gaAttributes[i][3] )
        {

          case 2:   // YES/NO
            /* alert ( "Yes/No" );
            goon=0;
            bReturn = false;
            */
            break;

          case 1:   // INTEGER
            if ( ! validNum(thisCtrl.value) )
            {
              stAlert = "Validation check for INTEGER data type failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
              goon=0;
              bReturn = false;
            }
            break;

          case 3:   // Short Text
          case 16:   // WebAgentFields
		    break;
		  case 31:	// Number
            if ( ! validNumber(thisCtrl.value) )
            { //MT 02Aug06 : PEM-BL-00229 
              stAlert = "Validation check for NUMBER data type failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
              goon=0;
              bReturn = false;
            }
            break;

          case 4:   // Long Text
          case 32:   // Long Text
            break;

          case 5:   // ?MONEY
            break;

          case 8:   // Date
            if ( ! validDateTime(thisCtrl.value) )
            {
              switch(dateFormat){
                default:
                  stAlert = "Validation check for DATE FIELD (mm/dd/yyyy) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

				case 1:
                  stAlert = "Validation check for DATE FIELD (mm/dd/yyyy) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

                case 2:
                  stAlert = "Validation check for DATE FIELD (yyyy/mmm/dd) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

				case 3:
                  stAlert = "Validation check for DATE FIELD (yyyy mmm dd) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;
               }
              goon=0;
              bReturn = false;
            }
            break;

          case 20:   // Date Only
            if ( ! validDate(thisCtrl.value) )
            {
              switch(dateFormat){
                default:
                  stAlert = "Validation check for DATE FIELD (mm/dd/yyyy) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

				case 1:
                  stAlert = "Validation check for DATE FIELD (mm/dd/yyyy) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

                case 2:
                  stAlert = "Validation check for DATE FIELD (yyyy/mmm/dd) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;

				case 3:
                  stAlert = "Validation check for DATE FIELD (yyyy mmm dd) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
                break;
               }
              goon=0;
              bReturn = false;
            }
            break;

          case 21:   // Time Only
            var elems = thisCtrl.value.split(" ");
            result1 = 0;
            if (elems.length > 0 )
            {
              if (elems.length > 1 )
                result1 = validTime( elems[0], elems[1] );
              else
                result1 = validTime( elems[0], "" );
            }
            if ( ! result1 )
            {
              stAlert = "Validation check for TIME FIELD (hh:mm) failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
              goon=0;
              bReturn = false;
            }

            break;

          case 22:   // DOB
          //var dob = this.Ctrl.value.split("|")
          //alert(dob[2]);
            if ( ! validDate(thisCtrl.value) )
            {
              switch(dateFormat) {
                default:
				  stAlert = "Validation check for DOB FIELD (mm/dd/yyyy) failed\r\n\r\n";
                break;

				case 1:
				  stAlert = "Validation check for DOB FIELD (mm/dd/yyyy) failed\r\n\r\n";
                break;

                case 2:
				  stAlert = "Validation check for DOB FIELD (yyyy/mmm/dd) failed\r\n\r\n";
                break;

				case 3:
				  stAlert = "Validation check for DOB FIELD (yyyy mmm dd) failed\r\n\r\n";
                break;
                }
              goon=0;
              bReturn = false;
            }
            break;

          case 24:  // AutoInc
            break;

          case 0:
            break;
          case 11:  // Sub-Module
          default:
            stAlert = "Validation check for data type [" + parent.dataframe.gaAttributes[i][3] + "] failed on field:\r\n\r\n"+parent.dataframe.gaAttributes[i][2];
            goon=0;
            bReturn = false;
            break;
        } // switch
      }
    }
  }
}

  if ( bReturn == false )
  {
    //alert( "parent.dataframe.giOtherTabs " + parent.dataframe.giOtherTabs );
    // Continue EDITS. -- ERROR
    if ( ( form1.DoAction.value == "SaveExit" ||  form1.DoAction.value == "SaveView" )  && parent.dataframe.giOtherTabs >= 0 )
    {
      a = confirm( "Your record is not complete.\nClick on 'OK' to save current data and complete later.\nClick on 'Cancel' to continue editing.");
      if (a)
      { 
        form1.GlobMandatoryError.value = "INCOMP|" + parent.dataframe.giOtherTabs;
        return true;
      }
    }
    if ( stAlert != "" )
      alert( stAlert );
      
    if ( i > 0 )
      i--;  
    PageStatus(1); // StartupComplete = 1;        
    if ( parent.dataframe.gaAttributes[i][3] != 16 )
    {
      //alert ( i +  " set focus " +  parent.dataframe.gaAttributes[i][2]);
      if ( parent.dataframe.gaAttributes[i][3] == 22 || ( parent.dataframe.gaAttributes[i][3] == 9 && (parent.dataframe.gaAttributes[i][0] & 32 ) ) )
      {
        thisCtrl = eval("form1." + parent.dataframe.gaAttributes[i][1] + "_0" );
      }else
      {
        thisCtrl = eval("form1." + parent.dataframe.gaAttributes[i][1] );
      }
      //thisCtrl.focus();
      if (noFocusFLG !=1) {thisCtrl.focus();} //update by paxcel(3) task id #1061.  DONT focus if the field is hidden.

    }
    return false;
  }else
  {
    // Passed all local checks
    // RE: 7/17/03 Save & Hold -- Check for OTHER TABS first.  
    if ( ( form1.DoAction.value == "SaveExit" ||  form1.DoAction.value == "SaveView" ) && parent.dataframe.giOtherTabs > 0 )
    {
      a = confirm("Your record is not complete.\nMandatory data from antoher TAB has not been fulfilled.\nClick on 'OK' to save current data and complete later.\nClick on 'Cancel' to continue editing.");
      if (a)
      {      
        form1.GlobMandatoryError.value = "INCOMP|" + parent.dataframe.giOtherTabs;
        return true;
      }else
      {
        PageStatus(1); // StartupComplete = 1;
        return false;
      }
    }  
  }
  if ( DebugScript )
  {
    alert( "exiting validate bReturn=" + bReturn );
  }
  return bReturn;
}

function ChangeCheckBox( form1,stField,iNr)
{
  giCurrentField=0;

  if ( AmIBusy() )
    return;

  var refresh = 0;

  for (iId = 0; iId < gaAttributes.length ; iId++)
  {
    if ( gaAttributes[iId][1] == stField )
    {
      ii = iId;
      thisCtrl = eval("form1." + gaAttributes[iId][1] + "_" + iNr );

      if ( ShouldRefreshCheckBox( thisCtrl, gaAttributes[iId][6] ) )
        refresh = 1;

      if ( ! (gaAttributes[iId][0] & 128 ) ) // 128 == MULTI SELECT
      {
        for (iCnt=0, i = 0; i < 200; i++ )
        {
          thisCtrl = eval("form1." + gaAttributes[iId][1] + "_" + i );
          if ( thisCtrl && thisCtrl != null )
          {
            if ( thisCtrl.checked )
              iCnt++;
            if( i != iNr )
            {
              if ( thisCtrl.checked == true )
              {
                if ( ShouldRefreshCheckBox( thisCtrl, gaAttributes[iId][6] ) )
                  refresh = 1;
                thisCtrl.checked = false;
              }
            }
          }else
          {
            break;
          }
        }
      }
      break;
    }
  }

  if ( gaAttributes[ii][3] == 9 && (gaAttributes[ii][0] & 64 ) && refresh )
  {
    form1.DoAction.value = "OnChoices";
    form1.DoSubAction.value = "OnChoices";
    form1.ActionValue.value = stField;
    form1.target = "dataframe";
    //This is to unlock the form before a known submit.
    form1.onsubmit=null;
    form1.submit();
    return;
  }

  PageStatus(1); // StartupComplete = 1; // RE-Enable it
}

function OnFieldList( mydoc,stFieldName )
{
  if ( AmIBusy() )
    return;

  var thisCtrl;

  thisCtrl = eval("mydoc.form1." + stFieldName);

  val1 = thisCtrl.options[thisCtrl.selectedIndex].value; // RE: 8/12/02 did not work on NN

  mydoc.form1.fieldlist.value = mydoc.form1.fieldlist.value + val1 + "\n";

  PageStatus(1); // StartupComplete = 1; // RE-Enable it

}

//--------BEGIN--------Used for DOB (Age Calculation)----------BEGIN--------
function getMonthLength(month,year,julianFlag)
{
   var ml;
   if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10||month==12)
      {ml = 31;}
   else {
       if(month==2) {
          ml = 28;
          if(!(year%4) && (julianFlag==1 || year%100 || !(year%400)))
             ml++;
       }
       else
          {ml = 30;}
   }
   return ml;    
}

function calculateAge(mydoc, dob, today, fieldname, iIndex)
{
    var re = new RegExp('[/.-]');
        dob = dob.split(re);
    //Use date format specified in config.
    switch(dateFormat){

        default:
          var db = dob[1];
          var mb = dob[0];
          var yb = dob[2];
        break;

		case 1:
          var db = dob[1];
          var mb = dob[0];
          var yb = dob[2];
        break;

        case 2:
          var db = dob[2];
          var mb = dob[1];
          var yb = dob[0];
        break;

		case 3:
          var db = dob[2];
          var mb = dob[1];
          var yb = dob[0];
        break;
      }
    //Convert Month if its not numeric.
    if(isAlpha(mb))
      switch(mb.toLowerCase()){
        default: mb=1; break;
        case "feb": mb=2; break;
        case "mar": mb=3; break;
        case "apr": mb=4; break;
        case "may": mb=5; break;
        case "jun": mb=6; break;
        case "jul": mb=7; break;
        case "aug": mb=8; break;
        case "sep": mb=9; break;
        case "oct": mb=10; break;
        case "nov": mb=11; break;
        case "jan": mb=12; break;
        }
        today = today.split(re);
    var dd = parseFloat(today[1]);
    var md = parseFloat(today[0]);
    var yd = parseFloat(today[2]);

   MNames=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
      "Oct","Nov","Dec");
   
   // Month length 0->use calendar length
   var mLength = 0;
   // 0 if Gregorian, 1 is Julian
   var isJulian = 0;

   var ma=0;
   var ya=0;

   var da = dd-db;
   // This is the all-important day borrowing code.
   if(da<0)
   {
      md--;
      // Borrow months from the year if necesssary.
      if(md<1)
      {
	 yd--;
	 // Determine no. of months in year
	 if(mLength)
	    {md=md+parseInt(365/mLength);}
	 else
	    {md=md+12;}
      }
      if(mLength==0) // Use real month length if no fixed
      {              // length is indicated - note that we add a leap day if necessary.
         ml=getMonthLength(md,yd,isJulian);
	 da=da+ml;
      } 
      // For this case, everything works like it did in elementary school.
      else
	 {da+=mLength;} // Use fixed month length
   }

   ma = md - mb;
   // Month borrowing code - borrows months from years.
   if(ma<0)
   {
      yd--;
      if(mLength!=0)
	 {ma=ma+parseInt(365/mLength);}
      else
	 {ma=ma+12;}
   }

   ya = yd - yb;

   //alert("Years: "+ya+", Months: "+ma+", Days: "+da);
   agefield = eval("mydoc.form1." + fieldname + "_1" );
   ageinfield = eval("mydoc.form1." + fieldname + "_2" );
	if ( isNaN(ya) || isNaN(ma) || isNaN(da)  )
	{
		agefield.value = '';
		ageinfield.value = "days";
		return ; 
	}
	else
	{
   if(ya>=2)
     {
       agefield.value = ya;
       ageinfield.value = "yrs";
     }else if(ya==1)
      {
        agefield.value = 12+ma;
        ageinfield.value = "mos";
      }else if(ma>0)
        {
          agefield.value = ma;
          ageinfield.value = "mos";
        }else
          {
            agefield.value = da;
            ageinfield.value = "days";
          }
	}
   
}
//--------END--------Used for DOB (Age Calculation)----------END--------

function stMonth2Int(stMonth)
{
	if (stMonth)
	{

		switch(stMonth.toLowerCase())
		{
			case "jan": return 1; break;
			case "feb": return 2; break;
			case "mar": return 3; break;
			case "apr": return 4; break;
			case "may": return 5; break;
			case "jun": return 6; break;
			case "jul": return 7; break;
			case "aug": return 8; break;
			case "sep": return 9; break;
			case "oct": return 10; break;
			case "nov": return 11; break;
			case "dec": return 12; break;
			default: return '???'; break;

		} // end switch
	} // end if
}

function intMonth2stAbr(intMonth)
{
	switch(intMonth)
	{
		case 1: return "Jan"; break;
		case 2: return "Feb"; break;
		case 3: return "Mar"; break;
		case 4: return "Apr"; break;
		case 5: return "May"; break;
		case 6: return "Jun"; break;
		case 7: return "Jul"; break;
		case 8: return "Aug"; break;
		case 9: return "Sep"; break;
		case 10: return "Oct"; break;
		case 11: return "Nov"; break;
		case 12: return "Dec"; break;
		default: return "???";
	}
}

function getYear(dateStr)
{
  var stYear;
  var re = new RegExp('[ /.-]');
  var dateArr = dateStr.split(re);

  if (dateStr == "") 
  {
	  return false;
  }

  if (dateArr.length == 3)
  {
    //Use date format specified in config.
    switch(dateFormat)
    {
      default:	//Standard mm/dd/yyyy
			stYear = parseInt(dateArr[2], 10);
      break;

	  case 1:	//Standard mm/dd/yyyy
			stYear = parseInt(dateArr[2], 10);
      break;

      case 2:	// yyyy/mmm/dd
			stYear = parseInt(dateArr[0], 10);
      break;

	  case 3:	// yyyy/mm/dd
			stYear = parseInt(dateArr[0], 10);
      break;
     }
  }

	return stYear;
}


function getMonth(dateStr)
{
  var stMonth;
  var re = new RegExp('[ /.-]');
  var dateArr = dateStr.split(re);

  if (dateStr == "")
    return false;

  if (dateArr.length == 3)
  {
    //Use date format specified in config.
    switch(dateFormat)
    {
      default:	//Standard mm/dd/yyyy
			stMonth = parseInt(dateArr[0], 10);
      break;

	  case 1:	//Standard mm/dd/yyyy
			stMonth = parseInt(dateArr[0], 10);
      break;

      case 2:	//yyyy/mmm/dd
        stMonth = stMonth2Int(dateArr[1]);
      break;

	  case 3:	//yyyy mmm dd
        stMonth = stMonth2Int(dateArr[1]);
      break;
     }
  }
  
	if (stMonth > 0 && stMonth < 13)
	{
		return stMonth;

	} else {

		return false;
	}
}


function getDay(dateStr)
{
  var stDay;
  var re = new RegExp('[ /.-]');
  var dateArr = dateStr.split(re);

  if (dateStr == "")
    return false;

  if (dateArr.length == 3)
  {
    //Use date format specified in config.
    switch(dateFormat)
    {
      default:	//Standard mm/dd/yyyy
				stDay = parseInt(elems[1], 10);
      break;

	  case 1:	//Standard mm/dd/yyyy
				stDay = parseInt(elems[1], 10);
      break;

      case 2:	// yyyy/mmm/dd
				stDay = parseInt(elems[2], 10);
      break;

	  case 3:	// yyyy/mmm/dd
				stDay = parseInt(elems[2], 10);
      break;
     }
  }

	if (stDay > 0 && stDay < 32)
	{
		return stDay;

	} else {

		return false;
	}
}


function parseDate( value )
{
  var result = true;
  var stmonth = 0;
  var stday = 0;
  var styear = 0;
  var dateArr = new Array(3);

  var re = new RegExp('[ /.-]');
  var elems = value.split( re );

  if (value == "")
    return true;

  result = (elems.length == 3); // should be three components
  if (result)
  {
    //Use date format specified in config.
    switch(dateFormat)
    {
      default:  //Standard mm/dd/yyyy
        stmonth = parseInt(elems[0],10);
        stday = parseInt(elems[1],10);
        styear = parseInt(elems[2],10);
      break;

	  case 1:  // mm/dd/yyyy
        stmonth = parseInt(elems[0],10);
        stday = parseInt(elems[1],10);
        styear = parseInt(elems[2],10);
      break;

      case 2:  // yyyy/mmm/dd
		styear = parseInt(elems[0],10);
        stmonth = stMonth2Int(elems[1]);
        stday = parseInt(elems[2],10);
      break;

	  case 3:  // yyyy mmm dd
		styear = parseInt(elems[0],10);
        stmonth = stMonth2Int(elems[1]);
        stday = parseInt(elems[2],10);
      break;
     }
  }

  dateArr[0] = stmonth;
  dateArr[1] = stday;
  dateArr[2] = styear;

  return dateArr;
}

function getToday(mydoc)
{
  var today=false;
  // Get Server DateStamp.
  today=mydoc.form1.ServerDate.value;
  
  // If find DateStamp fails get local machine DateStamp.
  if(!today)
  {
    alert("DOB JS Attributes could not be found:\nLocal computers date will be used in place of server time.");
    today = new Date();
    today= today.getMonth()+"/"+today.getDate()+"/"+today.getFullYear();
  }
  return today;
}

function isDateGreater(date1, date2)
{
	return isFutureDate(date1, date2);
}

function isDateEqual(date1, date2)
{
	var re = new RegExp('[ /.-]');
	date1 = date1.split(re);
	date2 = date2.split(re);

	switch(dateFormat)
	{
		default:  //Standard mm/dd/yyyy
			date1M = parseInt(date1[0],10);
			date1D = parseInt(date1[1],10);
			date1Y = parseInt(date1[2],10);

			date2M = parseInt(date2[0],10);
			date2D = parseInt(date2[1],10);
			date2Y = parseInt(date2[2],10);
		break;

		case 1:  // mm/dd/yyyy
			date1M = parseInt(date1[0],10);
			date1D = parseInt(date1[1],10);
			date1Y = parseInt(date1[2],10);

			date2M = parseInt(date2[0],10);
			date2D = parseInt(date2[1],10);
			date2Y = parseInt(date2[2],10);
		break;

		case 2:  // yyyy/mmm/dd
			date1Y = parseInt(date1[0],10);
			date1M = stMonth2Int(date1[1]);
			date1D = parseInt(date1[2],10);

			date2Y = parseInt(date2[0],10);
			date2M = stMonth2Int(date2[1]);
			date2D = parseInt(date2[2],10);
		break;

		case 3:  // yyyy mmm dd
			date1Y = parseInt(date1[0],10);
			date1M = stMonth2Int(date1[1]);
			date1D = parseInt(date1[2],10);

			date2Y = parseInt(date1[0],10);
			date2M = stMonth2Int(date1[1]);
			date2D = parseInt(date1[2],10);
		break;
	}

	if (date1Y == date2Y && date1M == date2M && date1D == date2D)
	{
		return true;

	} else {

		return false;
	}
}


function isDateLess(date1, date2)
{
  var re = new RegExp('[ /.-]');
  date1 = date1.split(re);
  date2 = date2.split(re);

	switch(dateFormat)
	{
		default:  //Standard mm/dd/yyyy
			date1M = parseInt(date1[0],10);
			date1D = parseInt(date1[1],10);
			date1Y = parseInt(date1[2],10);

			date2M = parseInt(date2[0],10);
			date2D = parseInt(date2[1],10);
			date2Y = parseInt(date2[2],10);
		break;

		case 1:  // mm/dd/yyyy
			date1M = parseInt(date1[0],10);
			date1D = parseInt(date1[1],10);
			date1Y = parseInt(date1[2],10);

			date2M = parseInt(date2[0],10);
			date2D = parseInt(date2[1],10);
			date2Y = parseInt(date2[2],10);
		break;

		case 2:  // yyyy/mmm/dd
			date1Y = parseInt(date1[0],10);
			date1M = stMonth2Int(date1[1]);
			date1D = parseInt(date1[2],10);

			date2Y = parseInt(date2[0],10);
			date2M = stMonth2Int(date2[1]);
			date2D = parseInt(date2[2],10);
		break;

		case 3:  // yyyy mmm dd
			date1Y = parseInt(date1[0],10);
			date1M = stMonth2Int(date1[1]);
			date1D = parseInt(date1[2],10);

			date2Y = parseInt(date2[0],10);
			date2M = stMonth2Int(date2[1]);
			date2D = parseInt(date2[2],10);
		break;
	}


  if (date1Y < date2Y)
  {
    return true;

  } else if (date1Y == date2Y && date1M < date2M) {

     return true;

  } else if (date1Y == date2Y && date1M == date2M && date1D < date2D) {

      return true;

  } else {

	return false;
  }

}


function isFutureDate(dob, today)
{
  var re = new RegExp('[ /.-]');
  dob = dob.split(re);


	switch(dateFormat)
	{
		default:  //Standard mm/dd/yyyy
			dobM = parseInt(dob[0],10);
			dobD = parseInt(dob[1],10);
			dobY = parseInt(dob[2],10);
		break;

		case 1:  // mm/dd/yyyy
			dobM = parseInt(dob[0],10);
			dobD = parseInt(dob[1],10);
			dobY = parseInt(dob[2],10);
		break;

		case 2:  // yyyy/mmm/dd
			dobY = parseInt(dob[0],10);
			dobM = stMonth2Int(dob[1]);
			dobD = parseInt(dob[2],10);
		break;

		case 3:  // yyyy mmm dd
			dobY = parseInt(dob[0],10);
			dobM = stMonth2Int(dob[1]);
			dobD = parseInt(dob[2],10);
		break;

	}

  today = today.split(re);
  var todayD = parseFloat(today[1]);
  var todayM = parseFloat(today[0]);
  var todayY = parseFloat(today[2]);

  if (dobY > todayY)
  {
    return true;
  }
  else if (dobY == todayY && dobM > todayM)
    {
      return true;
    }else if (dobY == todayY && dobM == todayM && dobD > todayD)
      {
        return true;
      }
  return false;
}

function CheckDobCalculation(mydoc, fieldname ,stValue, iIndex )
{
  var today = getToday(mydoc);
  
  if ( validDate( stValue, true ) )
  {
    if( !isFutureDate(stValue, today) )
      calculateAge(mydoc, stValue, today, fieldname, iIndex);
    else{
      alert("Error: "+stValue+" is not a valid Date.\n\nFuture dates are not allowed.");
      return false;
      }
  }else
  {
	  // pawan Wednesday, April 13, 2005 
    alert( "Invalid DATE format.\n\nPlease enter: MM/DD/YYYY" );
    // DOES NOT SET FOCUS !!!!
    thisCtrl = eval("mydoc.form1." + fieldname + "_0" );
    thisCtrl.focus();
    return false;
  }
  return true;
}

function CheckDobCalculation2(mydoc, fieldname ,stValue, iIndex, fieldCompareTo )
{
  // dateCompareTo must be in mm/dd/yyyy format

  if (fieldCompareTo == 0)
	  dateCompareTo = getToday(mydoc);
  else
  {
	  stField = "mydoc.form1.f" + fieldCompareTo + ".value";
      dateCompareTo = eval(stField);

		dateCompareTo=trim(dateCompareTo);//Thursday, December 29, 2005 Anshu
		if(dateCompareTo.length < 1 )
			dateCompareTo = getToday(mydoc);

  }

  // If comparison is a date/time field "mm/dd/yyyy hh:mm AM" we need just the date
  dateArr = dateCompareTo.split(" ");
  if (dateArr.length > 1)
	  dateCompareTo = dateArr[0];

  //alert (fieldCompareTo + "," + dateCompareTo);

  if ( validDate( stValue, true ) )
  {
    if( !isFutureDate(stValue, dateCompareTo) )
      calculateAge(mydoc, stValue, dateCompareTo, fieldname, iIndex);
    else{
      alert("Error: "+stValue+" is not a valid date.\n\nThe current field cannot be after the referenced date.");
      return false;
      }
  }else
  {
	  // pawan Wednesday, April 13, 2005 
    alert( "Invalid DATE format.\n\nPlease enter: MM/DD/YYYY" );
    // DOES NOT SET FOCUS !!!!
    thisCtrl = eval("mydoc.form1." + fieldname + "_0" );
    thisCtrl.focus();
    return false;
  }
  return true;
}

function dohreflink(link)
{ if ( AmIBusy() )
    return;
  if (link == "print")
  {
  print();
  }
  else if (link == "cancel")
  {
  history.go(-1);
  window.top.location.reload();
  }

  PageStatus(1);

}

function ChangeCheckBox2b(mydoc,stField,iType )
{
  giCurrentField=0;
  var iId;
  var iValue=0;

  //alert( stField + " ChangeCheckBox2b iType=" + iType );

  var elems = stField.split("_");
  iId       = parseInt( elems[0], 10);


  stField2 = "mydoc.form1." + stField;
  thisCtrl = eval(stField2);
  if ( thisCtrl && thisCtrl != null )
  {
    iValue = thisCtrl.value;
  }
  iCount=0;

  switch( iType )
  {
    case 1: // only 1 of four
      iValue =  SetOnlyOne( mydoc,elems[0],elems[1], (16 + 32 + 64 + 128),iValue );
      break;
    case 2: // any
      break;
    case 3: // only 1 of 3
      iValue =  SetOnlyOne( mydoc,elems[0],elems[1], (512 + 1024 + 2048),iValue );
      break;
  }

  if ( iValue == 128 ) // Rate
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();

}
function SetOnlyOne( mydoc,stField, iId, iMask, iValue )
{
  var iYes=0;
  var iMax=0;
  var i;

  for (i = 0; i < 32; i++ )
  {
    stField2 = "mydoc.form1." + stField + "_" + i ;
    thisCtrl = eval(stField2);
    if ( thisCtrl && thisCtrl != null )
    {
      if ( thisCtrl.checked == true && ( thisCtrl.value & iMask ) )
      {
        iMax++;
        if ( i == iId )
          iYes = 1;
      }
    }else
    {
      break;
    }
  }

  iCount=0;
  if ( iMax > 0 )
  {
    for (i = 0; i < 32; i++ )
    {
      stField2 = "mydoc.form1." + stField + "_" + i ;
      thisCtrl = eval(stField2);
      if ( thisCtrl && thisCtrl != null )
      {
        if ( thisCtrl.checked == true && ( thisCtrl.value & iMask ) )
        {
          if ( iYes == 1 && i == iId )
            iCount++; // Leave it (self)
          else
          {
            if ( iYes == 1 )
            {
              if ( thisCtrl.value == 128 )
                iValue = 128;
              thisCtrl.checked = false; // Clear it
            }else
            {
              if ( iCount == 0 )
              {
                iCount++; // Leave it (first one)
              }else
              {
                if ( thisCtrl.value == 128 )
                  iValue = 128;
                thisCtrl.checked = false; // Clear it
              }
            }
          }
        }
      }else
      {
        break;
      }
    }
  }
  return iValue;
}

function populateChoiceField()
{
  //document.forms[0].dropdown.options[document.forms[0].dropdown.selectedIndex].text
  var choiceval = document.form1.ChoiceList2.options[document.form1.ChoiceList2.selectedIndex].value;
  var choice = choiceval.split("|");
  var numval = choice[1];
  var usermask = choice[2];
  var recordmask = choice[3];
  var textval = choice[4];
  var textshortval = choice[5];  
  var denyug = choice[6];
  var dependancy = choice[7];
  document.form1.choiceoptionnumvalue.value= numval;
  document.form1.choiceoptiondesc.value= textval;
  document.form1.choiceoptiondescshort.value= textshortval;
  document.form1.UserReadFlags.value=usermask;
  document.form1.RecordFlags.value=recordmask;
  document.form1.choiceoptiondeny.value= denyug;
  document.form1.choicedependancy.value=dependancy;
}

function MyMatch(item)
{
  var Num = document.form1.numrows.value;
  var List = new Array();
  var i;
  var match;

  for (i = 0; i < Num; i++)
  {
    List[i] = document.form1.ChoiceList2.options[i].value;
  }

  match = -1; // Need initial value

  for(i=0;i < List.length ; i++)
  {
    var desc = List[i].split("|");
    if (item == desc[4])
    {
      match = "x"+i;
      break;
    }
    else if (item == "X"+desc[1])
    {
      match = "x"+i;
      break;
    }
    else
    {
     match = -1
    }
  }
  return match;
}

function waitMsg(action)
{
	// PG Thursday, December 22, 2005
	PageStatus(-2);
	setTimeout("ChangeChoiceField('"+action+"')",1);
}


function ChangeChoiceField(action)
{
  var NumRows = document.form1.numrows.value;
  var SelectList = new Array();
  var SelectedItemIndex = null;

  if ( action != "alphabetize" && action != "deleteAll" && document.form1.choiceoptiondesc.value == "" )
  {
    alert("Please select an item to be modified or enter a new item in the description field.");
	// PG Thursday, December 22, 2005
	PageStatus(1);
    return;
  }

  for (i = 0; i < NumRows; i++)
  {
    SelectList[i] = document.form1.ChoiceList2.options[i].value;
  }

  switch (action)
  {

    case "add":
    {
      var matched = MyMatch(document.form1.choiceoptiondesc.value);
      if (matched != "-1")
      {
        alert("The item is already in the list.");
		// PG Thursday, December 22, 2005
		PageStatus(1);
        return;
      }
      else
      {
        var mynewvalue = "|0|" + document.form1.choiceoptiondesc.value;
        document.form1.ChoiceList2.options[NumRows] = new Option(mynewvalue, mynewvalue);

        document.form1.ChoiceList2.options[NumRows].text = document.form1.choiceoptiondesc.value;
        SelectList[NumRows] = "|0|" + eval("document.form1.UserReadFlags.value") + "|"+ eval("document.form1.RecordFlags.value") + "|"+ eval("document.form1.choiceoptiondesc.value") + "|"+ eval("document.form1.choiceoptiondescshort.value") + "|"+ eval("document.form1.choiceoptiondeny.value") + "|" + eval("document.form1.choicedependancy.value");
        document.form1.numrows.value = (NumRows + 1);

        //Set the selected item
        SelectedItemIndex = NumRows;
      }
      break;
    }

    case "delete":
    {
      var matched = MyMatch(document.form1.choiceoptiondesc.value);
      if (matched == "-1")
      {
        alert("The item to be deleted was not found in the list.");
		// PG Monday, December 26, 2005
		PageStatus(1);
        return;
      }
      else
      {
        //Roba 9/23/02 the index could be a more than 1 digit
        //var myindex = matched.charAt(1);
        var myindex = matched.substr(1);
        document.form1.choiceoptiondesc.value = "";
        document.form1.choiceoptionnumvalue.value = "";
        // RE: 11/08/02 -- this field does not exist and causes DELETE PROBLEMS
        //document.form1.choiceoptionnumvalueshort.value = "";
        document.form1.UserReadFlags.value= "";
        document.form1.RecordFlags.value= "";
        document.form1.numrows.value = (NumRows - 1);
        SelectList[myindex] = "";
        document.form1.ChoiceList2.options[myindex] = null;
      }
      break;
    }


    case "up":
    {
      var matched = MyMatch("X"+document.form1.choiceoptionnumvalue.value);

      //Roba 9/23/02 the index could be a more than 1 digit
      //var myindex = matched.charAt(1);
      var myindex = matched.substr(1);

      if (matched == "-1")
      {
        alert("The item to be moved was not found in the list.");
		// PG Monday, December 26, 2005
		PageStatus(1);

        return;
      }
      else
      {
        if (myindex == 0)
        {
          alert("The item cannot be moved up.");
		// PG Monday, December 26, 2005
		PageStatus(1);

          return;
        }
        else
        {
          var OneAbove = (myindex - 1);
          var OneAboveValue = SelectList[OneAbove];
          var Moving = SelectList[myindex];
          SelectList[OneAbove] = Moving;
          SelectList[myindex]= OneAboveValue;

          //Set the selected item
          SelectedItemIndex = OneAbove;
        }
      }
      break;
    }

    case "down":
    {
      var matched = MyMatch("X"+document.form1.choiceoptionnumvalue.value);

      //Roba 9/23/02 the index could be a more than 1 digit
      //var myindex = matched.charAt(1);
      var myindex = matched.substr(1);

      if (matched == "-1")
      {
        alert("The item to be moved was not found in the list.");
		// PG Monday, December 26, 2005
		PageStatus(1);

        return;
      }
      else
      {
        if (myindex == (SelectList.length - 1))
        {
          alert("The item cannot be moved down.");
		// PG Monday, December 26, 2005
		PageStatus(1);

          return;
        }
        else
        {
          var OneBelow = (myindex - (-1 ));
          var OneBelowValue = SelectList[OneBelow];
          var Moving = SelectList[myindex];
          SelectList[myindex]= OneBelowValue;
          SelectList[OneBelow] = Moving;

          //Set the selected item
          SelectedItemIndex = OneBelow;
        }
      }
      break;
    }

    case "change":
    {
      var matched = MyMatch("X"+document.form1.choiceoptionnumvalue.value);
      if (matched == "-1")
      {
        alert("The item to be modified was not found in the list.");
		// PG Thursday, December 22, 2005
		PageStatus(1);
        return;
      }
      else
      {
        //Roba 9/23/02 the index could be a more than 1 digit
        //var myindex = matched.charAt(1);
        var myindex = matched.substr(1)

        var mynewvalue = "|" + document.form1.choiceoptionnumvalue.value + "|" + document.form1.UserReadFlags.value + "|" + document.form1.RecordFlags.value + "|" + document.form1.choiceoptiondesc.value + "|" + document.form1.choiceoptiondescshort.value + "|" + document.form1.choiceoptiondeny.value + "|" + document.form1.choicedependancy.value;
        document.form1.ChoiceList2.options[myindex] = new Option(mynewvalue, mynewvalue);
        document.form1.ChoiceList2.options[myindex].text = document.form1.choiceoptionnumvalue.value;
        SelectList[myindex] = "|" + document.form1.choiceoptionnumvalue.value + "|" + document.form1.UserReadFlags.value + "|" + document.form1.RecordFlags.value + "|" + document.form1.choiceoptiondesc.value + "|" + document.form1.choiceoptiondescshort.value + "|" + document.form1.choiceoptiondeny.value + "|" + document.form1.choicedependancy.value;

        //Set the selected item
        SelectedItemIndex = myindex;
      }
      break;
    }

    case "top":
    {
      var matched = MyMatch("X"+document.form1.choiceoptionnumvalue.value);
      var myindex = matched.substr(1);

      if (matched == "-1")
      {
        alert("The item to be moved was not found in the list.");
		// PG Monday, December 26, 2005
		PageStatus(1);

        return;
      }
      else
      {
        if (myindex == 0)
        {
          alert("The item is at the top.");
		// PG Monday, December 26, 2005
		PageStatus(1);

          return;
        }

        else
        {
          //Move the Selected item to the top and push
          //the items down one
          //
          var MovingToTop = SelectList[myindex];
          var temp = SelectList[0];

          for ( i = 1; i <= myindex; ++i )
          {
            var temp2 = SelectList[i];
            SelectList[i] = temp;
            temp = temp2;
          }
          SelectList[0] = MovingToTop;

          //Set the selected item
          SelectedItemIndex = 0;
        }
      }
      break;
    }

    case "bottom":
    {
      var matched = MyMatch("X"+document.form1.choiceoptionnumvalue.value);
      var myindex = matched.substr(1);

      if (matched == "-1")
      {
        alert("The item to be moved was not found in the list.");
				// PG Monday, December 26, 2005
		PageStatus(1);

        return;
      }
      else
      {
        if (myindex == (SelectList.length - 1))
        {
          alert("The item is at the bottom.");
		// PG Monday, December 26, 2005
		PageStatus(1);
          
		  return;
        }
        else
        {
          //Move the Selected item to the bottom and push
          //the items up one
          //
          var MovingToBottom = SelectList[myindex];
          var length = SelectList.length - 1;
          var temp = SelectList[length];

          for ( i = length - 1; i >= myindex; --i )
          {
            var temp2 = SelectList[i];
            SelectList[i] = temp;
            temp = temp2;
          }

          SelectList[length] = MovingToBottom;

          //Set the selected item
          SelectedItemIndex = length;
        }
      }
      break;
    }

    case "deleteAll":
    {
      if ( NumRows > 0 && confirm("Are you want to delete all items?") )
      {
        //Loop through each option and clear it
        //Reset length
        //
        document.form1.choiceoptiondesc.value = "";
        document.form1.choiceoptiondescshort.value = "";
        document.form1.choiceoptiondeny.value = "";
        document.form1.choiceoptionnumvalue.value = "";
        document.form1.UserReadFlags.value= "";
        document.form1.RecordFlags.value= "";

        for ( i = 0; i < NumRows; ++i)
        {
          SelectList[i] = "";
          document.form1.ChoiceList2.options[i] = null;
        }
        document.form1.numrows.value = 0;
      }

      break;
    }
    
    case "alphabetize":
    {
      SelectList.sort(AlphaSortListHelper);
      break;
    }

    default:
      alert("Undefined Action in peminic.js ChangeChoiceField()");
		// PG Monday, December 26, 2005
		PageStatus(1);

  }

  var box = document.form1.ChoiceList2;
  var finalList = "";
  while (box.options.length) box.options[0] = null;
  for(i=0;i<SelectList.length;i++)
  {
    if (SelectList[i] != null && SelectList[i] != undefined && SelectList[i] != "" )
    {
      var Desc = SelectList[i].split("|");
      if (Desc[4] != null || Desc[4] != undefined)
      {
        box.options[i] = new Option(SelectList[i],SelectList[i]);
        box.options[i].text = Desc[4];
        if (Desc[2] == null || Desc[2] == undefined)
        {
          Desc[2] = 0;
        }
        if (Desc[3] == null || Desc[3] == undefined)
        {
          Desc[3] = 0;
        }
        if (Desc[5] == null || Desc[5] == undefined)
        {
          Desc[5] = "";
        }
        if (Desc[6] == null || Desc[6] == undefined)
        {
          Desc[6] = "";
        }
        if (Desc[7] == null || Desc[7] == undefined)
        {
          Desc[7] = "";
        }
        finalList = finalList + "|" + Desc[1] +"|" + Desc[2] + "|" + Desc[3] + "|" + Desc[4] + "|" + Desc[5] + "|" + Desc[6] + "|" + Desc[7];
      }
    }
  }
  //set numrows to new value
  document.form1.numrows.value = box.options.length;
  document.form1.ChoiceList.value = finalList;

  //If we have a selected index set that index to the selected item
  //
  if ( SelectedItemIndex != null )
    document.form1.ChoiceList2.options[SelectedItemIndex].selected=true;

// PG Thursday, December 22, 2005
PageStatus(1);

}

//--------BEGIN--------Used for List View( Selection of Fields)--------BEGIN----------

//Moves selected items from one list to another.
// (mList=Your Master List, list1 & list2 are the lists that pass items)
function ListSelectionMove(mList, list1, list2){
  var selectedPlaceHolder=-1;
  var list=false;
	// Finds which list has selected items to pass.
  if(list1.selectedIndex!=-1)
    list=list1;
  if(list2.selectedIndex!=-1)
    list=list2;
  // Changes Selected items, if any, association in the Master List.
  if(list1.selectedIndex!=-1||list2.selectedIndex!=-1)
		for(i=list.length-1;i>=0;i--)
			if(list.options[i].selected){
			  selectedPlaceHolder=i;
			  mList[list.options[i].value].selected=!(mList[list.options[i].value].selected);
			  }

	//Builds two lists based on the Master List.
  list1.length=0;
  list2.selectedIndex=-1;
	for(i=0;i<mList.length;i++){  //For every item in the Master List.
	  var temp = new Option();
		temp.text=mList[i].text;
		temp.value=i;
		if(!mList[i].selected){  // If the item is flagged for list1.
		  list1[list1.length]=temp;
		  for(i2=0;i2<list2.length;i2++)
		  	if(list2.options[i2].text==mList[i].text){
		  		for(i3=i2+1;i3<list2.length;i3++){
		  		  list2.options[i3-1].text=list2.options[i3].text;
		  		  list2.options[i3-1].value=list2.options[i3].value;
			  	  }
			    list2.length--;
			    }
		  }
		else{ // If the item is flagged for list2(selected items).
		  for(i2=0;i2<list2.length;i2++){ 
		  	if(list2.options[i2].text==mList[i].text){
		  	  list2[i2]=temp;
		  	  temp=false;
		  	  i2=list2.length;
		  	  }
		  	}
		  if(temp)
		  	list2[list2.length]=temp;
		  }
		}
	if(list&&list.length>selectedPlaceHolder)
	  list.selectedIndex=selectedPlaceHolder;	
  }

function ListSelectionDisplayAttrib(mList, list1, list2, temp){
  browserIs=checkBrowser();
  list2.selectedIndex=-1;
  values=mList[list1.options[list1.selectedIndex].value].value;
  values=values+"|";
  values=values.substring(values.indexOf("|")+1,values.length);
	for(i=0;i<temp.length-1;i++){
	  cut=values.substring(0, values.indexOf("|"));
		temp[i].value=cut;
		// NN 4.7 Handler
		if(browserIs.ns4){
			if(temp[i].type=="select-one")
		 	  for(i2=0;i2<temp[i].length;i2++)
		 	    if(temp[i].options[i2].value==cut)
		 	      temp[i].selectedIndex=i2;
			}
	  values=values.substring(values.indexOf("|")+1,values.length);
		}
	// Disable Apply Button after changing attrib values.
	if(browserIs.ie4||browserIs.ie5||browserIs.ie6){  //Netscape Doesn't support this button.
	  temp[temp.length-1].disabled=true;
	  }
	}

function ListSelectionChangeAttrib(list1, list2, temp){
  browserIs=checkBrowser();
  if(list2.selectedIndex!=-1)
    list1=list2;
  values=mList[list1.options[list1.selectedIndex].value].value;
  values=values.substring(0, values.indexOf("|"));
  for(i=0;i<temp.length-1;i++){
    // NN 4.7 Handler
		if(browserIs.ns4)
		  if(temp[i].type=="select-one")
		    values=values+"|"+temp[i].options[temp[i].selectedIndex].value;
		  else
	      values=values+"|"+temp[i].value;
		// Non-NN 4.7
		else
	    values=values+"|"+temp[i].value;
	  }
  values=values+"|1";
  mList[list1.options[list1.selectedIndex].value].value=values;
  
  // Disable Apply Button after changing attrib values.
  if(browserIs.ie4||browserIs.ie5||browserIs.ie6)  //Netscape Doesn't support this button.
	  temp[temp.length-1].disabled=true;
	}
	
function ListSelectionEnableAttrib(condition, attribs){
  for(i=0;i<attribs.length-1;i++){
    if(attribs[i].type=="text")
		  attribs[i].readOnly=(!condition);
		else
			attribs[i].disabled=(!condition);
	  }
	}
	
function ListSelectionFinalize(form){
  browserIs=checkBrowser();
  for(i=0;i<form.elements.length;i++)
    if(form.elements[i].ShouldSelectAll){
      if(browserIs.ns4)
        var thisObject = form.elements[i];
      else
        var thisObject = form.elements[i].style;
      thisObject.visibility='hidden';
      for(i2=0;i2<form.elements[i].length;i2++){
        form.elements[i].options[i2].value=masterList[form.elements[i].options[i2].value].value;
        form.elements[i].options[i2].selected=true;
        }
      }
	}
	
function ListSelectionReorder(list, Nav){
  if(list.selectedIndex<0)
  	return;
	var temp;

	switch(Nav){
	  case "top":
		  if(list.selectedIndex!=0)
	  	  do
	  			ListSelectionReorder(list, "up");
	  		while(list.selectedIndex!=0);
	  	break;
		  	
	  case "up":
	  	if(list.selectedIndex!=0)
		 	  position=list.selectedIndex-1;
  	  break;
	 	
	  case "down":
	  	if(list.selectedIndex!=list.length-1)
	  		position=list.selectedIndex+1;
	  	break;
	  	
	  case "bottom":
	  	if(list.selectedIndex!=list.length-1)
		  	do
	  			ListSelectionReorder(list, "down");
	  		while(list.selectedIndex!=list.length-1);
	  	break;
	  }
	  temp=list.options[position].text;
	  list.options[position].text=list.options[list.selectedIndex].text;
	  list.options[list.selectedIndex].text=temp;
	  temp=list.options[position].value;
	  list.options[position].value=list.options[list.selectedIndex].value;
	  list.options[list.selectedIndex].value=temp;
	  list.selectedIndex=position;
	}	
	
function ListSelectionMasterListObject(name, value, flag){
	this.text=new String(name);
	this.value=new String(value);
	this.selected=new Boolean();
	if(flag)
	  this.selected=true;
	else
		this.selected=false;
  }
  
function ListSelectionCreateMasterList(list1, list2){
	mList=new Array();
	for(i=0;i<list1.length;i++)
		mList[i]=new ListSelectionMasterListObject(list1.options[i].text, list1.options[i].value, false);
	for(i=0;i<list2.length;i++)
	  for(i2=0;i2<list1.length;i2++)
	    if(list2.options[i].value==mList[i2].value){
	      mList[i2].selected=true;
	      i2=list1.length;
	      }
	return mList;		
  }  

//-------END-------Used for List View( Selection of Fields)-------END--------


//-------BEGIN-------Used for Field Validation and Masking-------BEGIN--------

function isAlnum(aChar)
{
  return (isDigit(aChar) || isAlpha(aChar));
}
// Test for digits
function isDigit(aChar)
{
  myCharCode = aChar.charCodeAt(0);

  if((myCharCode > 47) && (myCharCode <  58))
  {
     return true;
  }

  return false;
}
// Test for letters (only good up to char 127)
function isAlpha(aChar)
{
  myCharCode = aChar.charCodeAt(0);

  if(((myCharCode > 64) && (myCharCode <  91)) ||
    ((myCharCode > 96) && (myCharCode < 123)))
  {
     return true;
  }

  return false;
}
		
function Mask(mask, value){
  //Check for Keys to Avoid (Backspace).
  if(event.keyCode==8)
    return value;
  //Check for end of Mask.
  if(value.length>mask.length)
    return value;
  var wildCards="#@";
  var m=mask.substr(value.length-1,1);
  var v=value.substr(value.length-1,1);
  var r=false;
  switch(m){
	  case '#':
	    if(!isDigit(v))
	      r=-1;
	    break;
	  case '@':
	    if(!isAlpha(v))
	      r=-1;
	    break;
	  default:
	    r=m;
	    break;
    }
    if(r==-1){
      value=value.substr(0,value.length-1);
      return value;
      }
    if(r)
      value=value.substr(0,value.length-1)+r;
    do{
      if(value.length<mask.length){
        var peek=mask.substr(value.length,1);
        if(wildCards.indexOf(peek)==-1)
          value=value+peek;
        else
          peek=false;
        }
      else
        var peek=false;
    }while( peek );
    return value;
  }
 
function VnoFutureDate(mydoc, object){
  today = getToday(mydoc);

    if(!validDate(object.value))
  {
    switch(dateFormat)
    {
      default:  //Standard mm/dd/yyyy
		alert("Validation check for DATE FIELD (mm/dd/yyyy) failed:\n"+object.value+" is incorrect please check format.");
        break;

	  case 1:  // mm/dd/yyyy
		alert("Validation check for DATE FIELD (mm/dd/yyyy) failed:\n"+object.value+" is incorrect please check format.");
        break;

      case 2:  // yyyy/mmm/dd
		alert("Validation check for DATE FIELD (yyyy/mmm/dd) failed:\n"+object.value+" is incorrect please check format.");
        break;

	  case 3:  // yyyy mmm dd
		alert("Validation check for DATE FIELD (yyyy mmm dd) failed:\n"+object.value+" is incorrect please check format.");
        break;
     }
    object.focus();
    return false;
    }
  if(isFutureDate(object.value, today)){
    alert("Error:  Future Dates are not allowed for this entry.\n"+object.value+" is invalid.");
    object.value="";
    object.focus();
    return false;
    }
  return true;
  }

  function VRefresh(mydoc, object)
  {
    if ( AmIBusy() )
      return;
      
    mydoc.form1.DoAction.value = "OnChoices";
    mydoc.form1.DoSubAction.value = "OnChoices";
    mydoc.form1.ActionValue.value = object.name;
    mydoc.form1.target = "dataframe";
    //This is to unlock the form before a known submit.
    mydoc.form1.onsubmit=null;
    mydoc.form1.submit();
    return;
  }
  
  function V24Hour(mydoc, object)
  {
    var elems = object.value.split(":");
    if ( object.value.length == 3)
    {
      elems[0] = object.value.substring( 0, 1 );
      elems[1] = object.value.substring( 1, 3 );
    }else
    if ( object.value.length == 4)
    {
      elems[0] = object.value.substring( 0, 2 );
      elems[1] = object.value.substring( 2, 4 );
    }else
    if ( object.value.length != 0)
    {
      elems[0] = 99; // Make it fail
      elems[1] = 99;
    }else
    {
      elems[0] = 0;
      elems[1] = 0;
    }
    if ( parseInt( elems[0] , 10 ) < 0 || parseInt( elems[0] , 10 ) >= 24 )
    {
      alert("Invalid 24 hour time format HHMM (Hours = " + elems[0] + ") invalid");
      object.value="";
      object.focus();
    }
    if ( parseInt( elems[1] , 10 ) < 0 || parseInt( elems[1] , 10 ) >= 60 )
    {
      alert("Invalid 24 hour time format HHMM (Minutes = " + elems[1] + ") invalid");
      object.value="";
      object.focus();
    }
    return;      
  }
  
  function V24HourColon(mydoc, object)
  {
    var elems = object.value.split(":");

    if ( parseInt( elems[0] , 10 ) < 0 || parseInt( elems[0] , 10 ) >= 24 )
    {
      alert("Invalid 24 hour time format HH:MM (Hours = " + elems[0] + ") invalid");
      object.value="";
      object.focus();
    }
    if ( parseInt( elems[1] , 10 ) < 0 || parseInt( elems[1] , 10 ) >= 60 )
    {
      alert("Invalid 24 hour time format HH:MM (Minutes = " + elems[1] + ") invalid");
      object.value="";
      object.focus();
    }
    return;      
  } 
  
  function VNoZero(mydoc, object)
  {
    var myval;
    var i,i2,err,nr2,nr;
    var v;
        
    err = 1;
    nr2 = 0;
    nr  = 0;
    //alert("non zero - len " + object.value.length + " value (" + object.value + ")" );
    
    if ( object.value.length > 0 )
    {
      err = 0;
      myval = "";
      for( i=i2=0 ; i < object.value.length ; i++ )
      {
        v = object.value.substring(i,i+1);
        //alert( err + " err v[" + i + "] = (" + v + ")" );
        if( isDigit(v) )
        {
          myval += v;
          i2++;
        }else
        if ( v == '-' || v == '+' )
        {
          if ( i2 == 0 )
          {
            myval += v;     
            i2++;     
          }else
          {
            err = 1;
            break;
          }
        }else
        if ( v == '.' )
        {
          myval += v;     
          i2++;     
        }else
        if ( v != '$' && v != ',' && v != ' '  )
        {
          err = 1;
          break;
        }
      }
      if ( err == 0 && i2 > 0 )
      {
        nr = parseFloat( myval );
        if ( nr > 0 || nr < 0  )
          ;
        else
           err = 1;
         
        //alert( err + " err myval = (" + myval + ")  nr = (" + nr + ")" );
      }else
      {
        //alert( err + " error myval = (" + myval + ")  nr = (" + nr + ")" );
        err =1; 
      }
      //alert( err + " END myval = (" + myval + ")  nr = (" + nr + ")" );
      if ( err )
      {
        alert("Cannot enter a zero value in this field [" + object.value + " invalid]");
        object.value="";
        object.focus();
      }
    }
    return;      
  }    
  
  function VCheckMax(mydoc, object, nmValue)
  {
    var myval;
    var i,i2,err,nr2,nr,nrmax;
    var v;
        
    err = 1;
    nr2 = 0;
    nr  = 0;
    //alert( nmValue + " VCheckMax - len " + object.value.length + " value (" + object.value + ")" );
    
    if ( object.value.length > 0 )
    {
      err = 0;
      myval = "";
		//PG 03-Aug-06 PEM-BL-00259 PEM-BL-00261 PEM-BL-00262
		if (eval(nmValue).length<=0)
		{
			err = 1;
		}

      for( i=i2=0 ; i < object.value.length ; i++ )
      {
        v = object.value.substring(i,i+1);
        //alert( err + " err v[" + i + "] = (" + v + ")" );
        if( isDigit(v) )
        {
          myval += v;
          i2++;
        }else
        if ( v == '-' || v == '+' )
        {
          if ( i2 == 0 )
          {
            myval += v;     
            i2++;     
          }else
          {
            err = 1;
            break;
          }
        }else
        if ( v == '.' )
        {
          myval += v;     
          i2++;     
        }else
        if ( v != '$' && v != ',' && v != ' '  )
        {
          err = 1;
          break;
        }
      }
      
      // alert( err + " err myval = (" + myval + ")  nr = (" + nr + ")" );
      if ( err == 0 && i2 > 0 )
      {
        nr = parseFloat( myval );
		//PG 03-Aug-06 PEM-BL-00259 PEM-BL-00261 PEM-BL-00262
        nrmax = parseFloat( eval(nmValue) );
        //alert( " nrMax = " + nrmax );
        
        if ( nr > nrmax  )
           err = 1;
         
        //alert( err + " err myval = (" + myval + ")  nr = (" + nr + ")" );
      }else
      {
        //alert( err + " error myval = (" + myval + ")  nr = (" + nr + ")" );
        err =1; 
      }
      //alert( err + " END myval = (" + myval + ")  nr = (" + nr + ")" );
      if ( err )
      {
		  //PG 03-Aug-06 PEM-BL-00259 PEM-BL-00261 PEM-BL-00262
        alert("Cannot enter value higher than " + eval(nmValue) );
        object.value="";
        object.focus();
      }
    }
    return;      
  }

  // This was copied from VCheckMax javascript function
  // for enhancement PEM-SW-00952
  function VCheckMin(mydoc, object, nmValue)
  {
    var myval;
    var i,i2,err,nr2,nr,nrmax;
    var v;
        
    err = 1;
    nr2 = 0;
    nr  = 0;
    //alert( nmValue + " VCheckMax - len " + object.value.length + " value (" + object.value + ")" );
    
    if ( object.value.length > 0 )
    {
      err = 0;
      myval = "";
      for( i=i2=0 ; i < object.value.length ; i++ )
      {
        v = object.value.substring(i,i+1);
        //alert( err + " err v[" + i + "] = (" + v + ")" );
        if( isDigit(v) )
        {
          myval += v;
          i2++;
        }else
        if ( v == '-' || v == '+' )
        {
          if ( i2 == 0 )
          {
            myval += v;     
            i2++;     
          }else
          {
            err = 1;
            break;
          }
        }else
        if ( v == '.' )
        {
          myval += v;     
          i2++;     
        }else
        if ( v != '$' && v != ',' && v != ' '  )
        {
          err = 1;
          break;
        }
      }
      
      if ( err == 0 && i2 > 0 )
      {
        nr = parseFloat( myval );
		//PG 03-Aug-06
        nrmax = parseFloat( eval(nmValue) );
        
		// We change greater to less than from VCheckMax
        if ( nr < nrmax  )
           err = 1;
         
      }else
      {
        err =1; 
      }
      if ( err )
      {
		// Value is now lower than higher
		//PG 03-Aug-06
		alert("Cannot enter value lower than " + eval(nmValue) );
        object.value="";
        object.focus();
      }
    }
    return;      
  }

// PEM-SW-00736 JB 5/31/2004
/****************
Description:  Populates a form input with the day of the week based on
              the current inputs value.
Parameters:  <Current Document>, <Src Input>, <Dest Input>
*****************/
function VDayOfWeekCalc(mydoc, object, nmValue){
  target=eval("mydoc.form1.f"+nmValue);
  day=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  
  temp=object.value.split("/");
  dateObj=new Date(temp[2],temp[0]-1,temp[1]);
  if(isNaN(dateObj.getDay()))
      target.value="";
  else
    //WorkAround for onBlur instead of onChange trigger.
    if(target.value!=day[dateObj.getDay()]&&target.type=="hidden"){
      target.value=day[dateObj.getDay()];
      VRefresh(mydoc, object);
      }
    else
      target.value=day[dateObj.getDay()];
 }

// PEM-SW-00736 JB 5/31/2004
/****************
Description:  Populates a form input with the day of the week based on
              the current inputs value, no future dates allowed.
Parameters:  <Current Document>, <Src Input>, <Dest Input>
*****************/
function VDayOfWeekCalc_NoFuture(mydoc, object, nmValue){
  target=eval("mydoc.form1.f"+nmValue);
  if(VnoFutureDate(mydoc, object)){
    day=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    
    temp=object.value.split("/");
    dateObj=new Date(temp[2],temp[0]-1,temp[1]);
    if(isNaN(dateObj.getDay()))
      target.value="";
    else
      //WorkAround for onBlur instead of onChange trigger.
      if(target.value!=day[dateObj.getDay()]&&target.type=="hidden"){
        target.value=day[dateObj.getDay()];
        VRefresh(mydoc, object);
        }
      else
        target.value=day[dateObj.getDay()];
    }
  else
    target.value="";
  }

	
	// Helper functions for field-level validation method
	function VFLCheckLess(mydoc, object, compareToFieldName)
	{
		VFLCheck(mydoc, object, compareToFieldName, "less");
		return;
	}

	function VFLCheckLessEq(mydoc, object, compareToFieldName)
	{
		VFLCheck(mydoc, object, compareToFieldName, "less_eq");
		return;
	}

	function VFLCheckGreaterEq(mydoc, object, compareToFieldName)
	{
		VFLCheck(mydoc, object, compareToFieldName, "greater_eq");
		return;
	}

	function VFLCheckGreater(mydoc, object, compareToFieldName)
	{
		VFLCheck(mydoc, object, compareToFieldName, "greater");
		return;
	}


	// VFLCheck(window.document, this, "Audit_Start_Date")
	// Field-level validation methods
	// PEM-SW-00997 AD 6/9/2004
	// object.value: Source comparison value (LHS)
	// gaAttributes[foundField][7]: Destination comparison value (RHS)
	function VFLCheck(mydoc, object, compareToFieldName, comparisonType)
	{
		var i, re, elems, dataTypeDest, dataTypeSrc, destFieldValue, objectStr, cmpString, validationError = false, destField = -1;
		var debugThis=false;
		//var debugThis=true;
		
		// Parse our destination comparison field name
		if (compareToFieldName.indexOf("|") >= 0)
		{
			//alert("compareToFieldName.length="+compareToFieldName.length+" compareToFieldName.indexOf('|')="+compareToFieldName.indexOf("|"));
			dataTypeDest = compareToFieldName.substring(compareToFieldName.indexOf("|")+1, compareToFieldName.length);
			compareToFieldName = compareToFieldName.substring(0, compareToFieldName.indexOf("|"));

			if (debugThis)
				alert("Looking for data type = " + dataTypeDest + " on destination comparison field\nNew compareToFieldName = '" + compareToFieldName + "'");
		}

		if (debugThis)
			alert("Parsing gaAttributes[][8] for '" + compareToFieldName + "'");

		// Find the field we are validating against
		for (i=0; i<gaAttributes.length; i++)
		{
			if (gaAttributes[i][8] == compareToFieldName)
			{
				destField = i;
				destFieldValue = eval("mydoc.form1." + gaAttributes[i][1]).value;

				if ((compareToFieldName.indexOf("|") >= 0) && (dataTypeDest != gaAttributes[i][3]))
					alert("Validation configuration error: Expecting data type " + dataTypeDest + ", found type " + gaAttributes[i][3] + " on field " + compareToFieldName);
				else
					dataTypeDest = gaAttributes[i][3];

				break;
			}
		}

		// Return if null
		if (destFieldValue == "" || object.value == "")
			return;

		// Return if cannot find field
		if (destField == -1)
		{
			alert("Field '" + compareToFieldName + "' cannot be found for validation against data '" + object.value + "'");
			return;
		}
		else
		{
			if (debugThis)
				alert("Found field to validate against, index=" + destField);

			// Find the data type of our source field
			for (i=0; i<gaAttributes.length; i++)
			{
				if (gaAttributes[i][1] == object.name) {
					dataTypeSrc = gaAttributes[i][3];
					break;
				}
			}

			if (!dataTypeSrc) {
				alert("Error: Cannot find data type for source field '" + object.name + "'");
				return;
			}

			if (debugThis)
				alert("Found source field data type = " + dataTypeSrc);

			// Treat date/time data types as date only
			if (dataTypeSrc == 8)
				dataTypeSrc = 20;
			if (dataTypeDest == 8)
				dataTypeDest = 20;

			// Make sure we are comparing same data types
			if (dataTypeSrc != dataTypeDest) {
				alert("Error: Cannot compare two different data types, value '" + object.value + "' against field '" + compareToFieldName + "'");
				return;
			}

			// Compare the data
			switch(dataTypeSrc)
			{
			case 20:
				if (!validDate(object.value, 0)) {
					alert(object.value + " is not a valid date");
					return;
				}

				// Fix until PEM-SW-00942 is resolved
				if (destFieldValue.indexOf("-") >= 0)
				{
					re = new RegExp('[-]');
					elems = destFieldValue.split(re);

					// This is the MySQL default yyyy-mm-dd format
					styear = parseInt(elems[0],10);
					stmonth = parseInt(elems[1],10);
					stday = parseInt(elems[2],10);

					switch(dateFormat)
					{
						default:  //Standard mm/dd/yyyy
						cmpString = stmonth + "/" + stday + "/" + styear;
				        break;

						case 1:  // mm/dd/yyyy
						cmpString = stmonth + "/" + stday + "/" + styear;
						break;

						case 2:  // yyyy/mmm/dd
						cmpString = styear + "/" + intMonth2stAbr(stmonth) + "/" + stday;
						break;

						case 3:  // yyyy mmm dd
						cmpString = styear + " " + intMonth2stAbr(stmonth) + " " + stday;
						break;

					}
				}

				if (!cmpString)
					cmpString = destFieldValue;

				// isFutureDate takes first argument and parses date
				// format automatically (from dateFormat setting)
				// Second argument must be in mm/dd/yyyy format
				objectArr = parseDate(object.value);
				objectStr = objectArr[0] + "/" + objectArr[1] + "/" + objectArr[2];

				if (debugThis)
				{
					var testStr = "Source: " + objectStr + " Dest: " + cmpString + "\n";
					testStr = testStr + "isDateLess('" + objectStr + "','" + cmpString + "'): " + isDateLess(objectStr, cmpString) + "\n";
					testStr = testStr + "isDateEqual('" + objectStr + "','" + cmpString + "'): " + isDateEqual(objectStr, cmpString) + "\n";
					testStr = testStr + "isDateGreater('" +  objectStr +  "','" + cmpString + "'): " + isDateGreater(objectStr, cmpString) + "\n";
					alert(testStr);
				}

				switch (comparisonType)
				{
				case "less":
					if (isDateLess(objectStr, cmpString) && !isDateEqual(objectStr, cmpString))
						return;
					else {
						alert("Date must be before " + gaAttributes[destField][2] + " [" + cmpString + "]");
						validationError = true;
					}
					break;
				case "less_eq":
					if (isDateLess(objectStr, cmpString) || isDateEqual(objectStr, cmpString))
						return;
					else {
						alert("Date must be before or equal to " + gaAttributes[destField][2] + " [" + cmpString + "]");
						validationError = true;
					}
					break;
				case "greater_eq":
					if (isDateGreater(objectStr, cmpString) || isDateEqual(objectStr, cmpString))
						return;
					else {
						alert("Date must be after or equal to " + gaAttributes[destField][2] + " [" + cmpString + "]");
						validationError = true;
					}
					break;
				case "greater":
					if (isDateGreater(objectStr, cmpString) && !isDateEqual(objectStr, cmpString))
						return;
					else {
						alert("Date must be after " + gaAttributes[destField][2] + " [" + cmpString + "]");
						validationError = true;
					}
					break;
				default:
					alert("Error: " + comparisonType + " comparison type not defined!");
					return;
				}
				break;

			// Other data types to compare
			default:
				alert("Other data types not implemented yet!");
				break;
			}

			if (validationError) {
				object.value = "";
				object.focus();
				return;
			}		
		}
	}


//-------END-------Used for Field Validation and Masking-------END--------
 
 
/****************
Description:  Intercepts and autorizes form submitions.
Parameters:  None
*****************/  
function CheckSubmit(){
  if(window==top){
    MenuId=window.document.form1.MenuId.value;
    SubMenuId=window.document.form1.SubMenuId.value;
    mydoc=window.document;
    }
  else{
    MenuId=parent.dataframe.document.form1.MenuId.value;
    SubMenuId=parent.dataframe.document.form1.SubMenuId.value;
    mydoc=parent.dataframe.document;
    }
  switch(MenuId){
    case "2048":
      HrefMenuIdSetField(mydoc, MenuId, "Go", "NewSearch", SubMenuId);
    }
  return false;
  }
	
/****************
Description:  Sets a hidden form value to the current verticle scroll position.
Parameters:  None
*****************/  
function setVScrollPosition(){
  /*if(window!=top&&gstFrameName="dataframe")
	  frame="parent.dataframe.";
	else
	  frame="";*/
  if(document.body)
		scrolldown=eval("document.body.scrollTop"); //IE & Mozilla
	else
		scrolldown=eval("window.pageYOffset"); //NN4.x compatibility
	VScroll=eval("document.form1.VScrollPosition.value");
	VScroll=scrolldown;
	document.form1.VScrollPosition.value=VScroll;
	}
	
	
/****************
Description:  Brings the page to the marked verticle scroll position.
Parameters:  None
*****************/  
function goToScrollPosition(x, y){
  browserIs=checkBrowser();
  if(browserIs.ie5||browserIs.ie6||browserIs.ns5){
    if(!x)
      x=0;//x=document.form1.HScrollPosition.value;  Possible Future Implimentation
    if(!y)
  	  y=document.form1.VScrollPosition.value;
    window.scrollTo(x,y);
    }
  }

/****************
Description:  Handler for onFocus events of all form elements in dataframe.(Initialized by Startup function)
Parameters:  None
*****************/  
function focusFieldTracking(){
  browserIs=checkBrowser();
  document.form1.setfocusfield.value=this.name;
  //alert("2: "+document.form1.setfocusfield.value);
  //Original onfocus events were stored in a global array by the startup function.
  //Each fields will now be executed.
  if(browserIs.ie5||browserIs.ie6||browserIs.ns5)
    eval(eval("onfocus['"+this.name+"']"));
  }
  
  function AlphaSortListHelper(a,b){
   ra=a.split("|");
   rb=b.split("|");
   if(typeof ra != 'undefined' && typeof rb != 'undefined') {
     ra=ra[4];
     rb=rb[4];
     if(ra.toLowerCase()>rb.toLowerCase())
       return 1;
     else if (ra.toLowerCase()==rb.toLowerCase())
       return 0;
     else if(ra.toLowerCase()<rb.toLowerCase())
       return -1;
   } else {
       return -1;
   }
}

function SelectAllCheckBoxes( selectAllControlName, controlToSelect )
{
	stField1 = "document.form1."+selectAllControlName;
    thisCtrl1 = eval(stField1);
    if ( thisCtrl1 && thisCtrl1 != null )
    {		
		for (var i=0; i<document.form1.elements.length; i++)
		{			
			if (document.form1.elements[i].type == 'checkbox' && document.form1.elements[i].name == controlToSelect+'[]')
				document.form1.elements[i].checked = thisCtrl1.checked;
		}	
	}		
}

function TranslationHelper( selectControlName, checkBoxControlName, spanControlName )
{
	var translationType = eval("document.form1."+selectControlName).value
	var spanElement = document.getElementById(spanControlName);

	if ( spanElement != null )
	{
		//on show if this is a peminicchoice translation type
		//
		if ( translationType == 5 )
		{
			spanElement.style.visibility='visible';
		}
		else
		{
			spanElement.style.visibility='hidden';
			eval("document.form1."+checkBoxControlName).checked = false;
		}
	}
}

function OpenNewWindow( url, windowTitle, width, height, params )
{
	var centerX=(screen.availWidth-width)/2;
	var centerY=(screen.availHeight-height)/2;
	if(top.newWin)top.newWin.close();
	top.newWin = window.open( url, windowTitle, params );
	top.newWin.moveTo(centerX, centerY);
}

function ProcessPrintableViewReport()
{
	url = './index.php?MenuId=4096&DoAction=PrintViewReport&DoSubAction=PrintViewReport&ActionValue='+eval("document.form1.PrintableViewReportSelection").value;
	eval("document.form1.PrintableViewReportSelection").value = -1;
	OpenNewWindow( url, 'PrintableViewReport', 800, 540, 'toolbar=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes' );
	
	
}

function trim(inputString) //Thursday, December 29, 2005 Anshu
{
  
   if (typeof inputString != "string") 
   { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") 
   { 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") 
   { 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) 
   { 
       retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
    
    
   }
   return retValue; 
   
} 

function playSound(filename)   //MT 4MAY06 added for IVR sound play. 
{  
 document.all['BGSOUND_ID'].src=filename;
}

function stopSound() //MT 4MAY06 added for IVR sound stop.
{
document.all['BGSOUND_ID'].src='ivr.mid';
}



