function MoreLines(Proc, Func)
{sfv('SADDLIN   ', 3);he(Proc, Func);}
function SRow(RowNumber)
{document.LANSA.ROWSELECT.value=RowNumber;EmulateButton('OK');}
function EmulateButton(btnvalue)
{SetButton(btnvalue); HandleSubmit();}
function SetPromptValue(TheValue)
{sfv(document.LANSA._CALFLD.value, TheValue);}
function SetScrollto(XC, YC)
{self.scroll(XC, YC)}
function HeadClick(stdval, sortcol)
{document.LANSA.ASTDRENTRY.value=stdval;document.LANSA.SSRTCOL.value=sortcol;Recall();}

function replaceChar(str, txt, instead)
{// For each instance of the char txt in str, replace with instead.
 x = 0;
 while (x != -1) {
  x = str.indexOf(txt);
  if (x != -1) {first = str.substring(0,x);last = str.substring(x + txt.length,str.length); str = first + instead + last;}
 }
 return str
}

function IsDropDown(obj)
{ // Returns true if the object is a SELECT (drop-down) object
 var TheType = obj.value;
 if (TheType == null) ItIs = true; // no regular value if a SELECT object.
 else ItIs = false;
 return ItIs;   // Return the verdict.  True means it is a drop-down (select) object.
}

function ReturnTo(GoToUrl)
{if (GoToUrl == '') parent.location="/";  // No Url to go back to.
 else parent.location=GoToUrl;
}

function SetFieldValue(FieldName, NewValue)
{var NumElements=document.LANSA.elements.length;
for (i=0; i<NumElements;i++)
{
 var obj=document.LANSA.elements[i];
 if (obj.name==FieldName)
 {
  if (IsDropDown(obj) == false)  // not a drop down, but a regular input field.
   {obj.value=NewValue; break;} // we're done.
  else
   {// A drop down; go through items in dropdown till we find a match.
   var NumItems = obj.length
   for (j=0; j<NumItems;j++) {if (obj.options[j].value == NewValue) {obj.selectedIndex = j; break;}
  }
}}}}

function sfv(FieldName, NewValue)
{SetFieldValue(FieldName, NewValue);
}

function GetFieldValue(FieldName)
{ // Get the value of a field even if the field name has embedded blanks.
 var NumElements=document.LANSA.elements.length; var TheValue='';
 for (i=0; i<NumElements;i++)
 {
  var obj = document.LANSA.elements[i];
  if (obj.name==FieldName)
   { // it's the right field.
   if (IsDropDown(obj) == false) TheValue = obj.value; // not a drop down, but a regular input field.
    else TheValue = obj.options[obj.selectedIndex].value; break;
   }
 }
 return TheValue;
}

function gfv(FieldName)
{return GetFieldValue(FieldName);
}

function CopyFieldValue(FieldNameFrom, FieldNameTo)
{ // Copy the value of one field to another.
var TheValue = gfv(FieldNameFrom);sfv(FieldNameTo, TheValue + "");
}

function ValidSubmit()
{// Ensure both the function and process to link to are not blank.
var IsValid = (document.LANSA._FUNCTION.value != '          ' && document.LANSA._PROCESS.value != '          ');
 return IsValid;
}

function ChangeState(NextState, Proc, Fun)
{//Set NextState and go to the given function.
 sfv('ANEXTSTATE', NextState);he(Proc, Fun);
}

function SetCBState(obj, RFld, CY, CN)
{if (obj.checked) sfv(RFld, CY); else sfv(RFld, CN);
}

function SetFocus()
{var NumEls=document.LANSA.elements.length;
 for (i=0; i<NumEls;i++)
 {var TheType=document.LANSA.elements[i].type;
  if (TheType=="select-one" || TheType=="checkbox" || TheType=="textarea" || TheType=='text')
  {if (document.LANSA.elements[i].value!="") {document.LANSA.elements[i].focus(); break;}}
 }
}

function PadIt(ToPad, PadChar, DesiredLength, LeftRight)
{// Pad ToPad with charaters to the desired length, on either left or right.
 var padded=ToPad+''; // make sure it's a string.
 while (padded.length<DesiredLength)
  {if (LeftRight=='L') padded=PadChar+padded;//left
  else padded=padded+PadChar;}// right
 return padded;
}

function ZeroPad(ToPad, DesiredLength)
{return PadIt(ToPad, '0', DesiredLength, 'L');// Left-pad ToPad with zeros to desired length.
}

function RightBlankPad(ToPad, DesiredLength)
{return PadIt(ToPad, ' ', DesiredLength, 'R');// Right-pad ToPad with blanks to desired length.
}

function NewWin(page)
{// Launch page in new window, ensuring "HTTP://".
first3=page.substring(0,3);first3=first3.toUpperCase();
 if (first3 == 'WWW') {page = 'http://' + page}; // Starts with www so needs the HTTP://.
OpenWin = this.open(page, "NewWin", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}

function Recall(){he(gfv('_OPROCESS'),gfv('_OFUNCTION'));}// Call this function again.

function MapIt(street,city,state,zip,country)
{// Launch MapQuest in new window.
st1=replaceChar(street, ' ', '%20');st2 = replaceChar(st1, '&', '%26');
city1=replaceChar(city, ' ', '%20');city2 = replaceChar(city1, '&', '%26');
mapurl1='http://www.mapquest.com/cgi-bin/ia_free?width=600&height=400&streetaddress=';
mapurl=mapurl1 + st2 + '&city=' + city2 + '&state='  + state + '&zip=' + zip + '&country=' + country;
NewWin(mapurl)
}

function bookmark(bookmarkurl,bookmarktitle)
{
if (navigator.appName == 'Microsoft Internet Explorer')
window.external.AddFavorite(bookmarkurl,bookmarktitle);
else if (navigator.appName == 'Netscape') // Firefox too
alert("Press CTRL+D to bookmark this page.");
else
alert("Add " + "(" + bookmarkurl + ") to your bookmarks");
}
 
function SetRADIOchecked(RFld, whichone)
{
var NumElements=document.LANSA.elements.length;
var ridx=0
for (i=0; i<NumElements;i++)
{
 if (document.LANSA.elements[i].name==RFld)
 {  
  ridx=ridx+1;
  if (ridx==whichone)
  {
  document.LANSA.elements[i].checked = true;
  break;
  }
 }
}
}

//Custom JavaScript Functions by Shawn Olson
//Copyright 2006
//http://www.shawnolson.net
//If you copy any functions from this page into your scripts, you must provide credit to Shawn Olson & http://www.shawnolson.net
//*******************************************
function checkUncheckAll(theElement) {
var theForm = theElement.form, z = 0;
 for(z=0; z<theForm.length;z++){
  if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
    theForm[z].checked = theElement.checked;
  }
 }
}
// end of custom js functions by Shawn Olson

function SwitchToLanguage(Lang)
{
 var old_lang = gfv('ALANGUAGE');
 if (old_lang != Lang)
 {
 var new_action = replaceChar(document.LANSA.action, old_lang, Lang);
 document.LANSA.action = new_action;
 }
 Recall();
}

function SetFormAction(Action) {document.LANSA.action = Action;}
function SetFormActionLANSA() {SetFormAction(gfv('lansa_action'));}
function SubmitAction(Action)
{if (Action!='') SetFormAction(Action);
document.LANSA.submit();
}

function SetTargetShortcut(TargetShortcut)
{ if (TargetShortcut != null) 
  {var new_action = replaceChar(document.LANSA.action, gfv('CGIPgm'), TargetShortcut);
  SetFormAction(new_action);}
}
function sts(ts) {SetTargetShortcut(ts);}

