//**********************************************************
//
//                 JavaScript Library
//
// This library is included into the page source file 
// by the following instruction:
// <script Language="JavaScript" SRC="JavaLib.js"></script>
//
//	Modified Latest By: Pallavi Sher 09/25/01
//	
//	The functions in this library are :
//
//	function TrimString(String)  Trims a string in javascript
//	function RemoveChunk(string) Gets the numbers from the semicolon delimited string
//	function GetFirstListItem(strList) Returns the first item in the semicolon-delimited list
//	function ListCount(string) Returns the number of items in a semicolon delimited string
//	function GetNumbers(strLine, strChar)
//	function GetColumn(strLine, intPos, strChar)
//	function getDateTimeNow()
//	
//
//**********************************************************

// Date: Sept 13, 1999, Alan Hong

function TrimString(stringS)
{
	var stringD = ""
	var i, j
	
	// Check if stringS is already empty
	if (stringS.length == 0)
		return stringD
		
	// Trim the leading spaces.
	// i = first non-space char or EOF
	i = 0
	while (i<stringS.length)
	{
		if (stringS.charAt(i) != " ")
			break
		
		i++		
	}
	
	// Trim the ending spaces
	// j = last non-space char or 
	j = stringS.length-1
	while (j >= i)
	{
		if (stringS.charAt(j) != " ")
			break

		j--
	}

	// Copy non-space chars from stringS to stringD
	while (i <= j)
	{
		stringD += stringS.charAt(i)
		i++
	}
	
	return stringD
}

// Date: Oct 22, 1999, Dana Jian
//Modified to fix the removal of substring in others bug- by Pallavi 08/08/2001

function RemoveChunk(str1,str2){
  var pos1,pos2, part1, part2, part;
	str2=";" + str2
  pos1 = str1.indexOf(str2);
  if (pos1!=0){
     part1 = str1.substring(0,pos1)+ ";" ;
  }
  else{
     part1 = "";
  }
  pos2 = str1.indexOf(";",pos1+1);
  part2 = str1.substr(pos2+1);
 if (part1=="") {
     part = part2;
  }
  else{   
     part = part1.concat(part2);
  }
  return (part);
}

//

function RemoveChunkDelimiter(str1,str2,delim){
  var pos1,pos2, part1, part2, part;
	str2=delim + str2
  pos1 = str1.indexOf(str2);
  if (pos1!=0){
     part1 = str1.substring(0,pos1)+ delim ;
  }
  else{
     part1 = "";
  }
  pos2 = str1.indexOf(delim,pos1+1);
  part2 = str1.substr(pos2+1);
 if (part1=="") {
     part = part2;
  }
  else{   
     part = part1.concat(part2);
  }
  return (part);
}

/*  GAF  1/25/02 Returns the first item in the semicolon-delimited list, if one exists. */
function GetFirstListItem(strList){
	var intLength=strList.length;
	var intStart;
	var intPosn=0;
	var intStop=intLength-1;	//zero-based index functions in jscript
	var strResult;
	
	//Fast-forward past all beginning delimiters.
	while (strList.charAt(intPosn)==";") {
		intPosn++;
	}
	
	intStart=intPosn;
	
	//Now find the next delimiter, indicating the end of the item
	while ((strList.charAt(intPosn)!=";") && (intPosn<=intStop)) {
		intPosn++;
	}
	
	//Retrieve the item
	strResult=strList.substring(intStart,intPosn);
	return(strResult)
}
	

/* GAF  1/25/02  Function returns the number of items in a semicolon-delimited list.
				 Also handles a "leading semicolon" and "following semicolon" by not
				 checking the first and last characters of the string.
*/

function ListCount(strList){
	var intDelimitCount=0;
	var intPosn=0;
	var intStop=strList.length;
	var intSingleRecord=0;
	
	
	//Start at 2nd char if 1st char is delimiter.
	if (strList.charAt(0)==";") {
		intPosn++;
	}
	
	//Stop at next to last char if last char is delimiter.
	if (strList.charAt(intStop-1)==";") {
		intStop--;
	}
	
	
    while (intPosn < intStop) {
		if(strList.charAt(intPosn)==";") {
			intDelimitCount++;
		} else {
			//Always count a first item if a char other than delimiter is found.
			//This adds the 'extra' item - 1 delimiter = 2 items, 2 delimiter = 3 items, etc.
			intSingleRecord=1;
		}
		intPosn++;
	}

	return (intDelimitCount+intSingleRecord)
}		


// Date: Nov 05, 1999, Dana Jian

function GetNumbers(strLine, strChar){
     var intN, intPos1, intPos2, intLen, strLine2;
            
     intPos1 = 1;
     intLen = strLine.length;
     intN = 0;
     strLine2 = strLine.substr(1);
            
     while (intPos1 < intLen) {
        //intPos2 = InStr(intPos1, strLine2, strChar);
        
        intPos2 = strLine2.indexOf(strChar, intPos1);
        if (intPos2 > 0){ 
           intN++ ;
           intPos1 = intPos2 + 1;
           }
        else
           break;
        
     }
            
     return (intN);
}

// Date: Nov 05, 1999, Dana Jian

function GetColumn(strLine, intPos, strChar){

     var intPos1, intPos2, intLen, i, strLine2;

     intPos1 = 0;
     i = 0;
     strLine2 = strLine.substr(1);
     intLen = strLine2.length;
     intPos2 = 0;
     
     while (intPos2 < intLen) {
        intPos2 = strLine2.indexOf(strChar, intPos1);
        
        if (intPos2 != -1) {
           i++;
           if (i == intPos) {
              break;
             } 
           else {
              intPos1 = intPos2 + 1;
           }
        }   
        else {
           if (i == intPos - 1) {
              return (strLine2.substr(intLen - intPos1 + 1));
           }
        }
     }
    
    return (strLine2.substr(intPos1, intPos2 - intPos1));
       
}

// Date: Nov 18,1999, Dana Jian
function getDateTimeNow() {
    var s, s2;
    var d = new Date();
    //s = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getYear();
    //s2 = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
   
    return (d.toLocaleString());
}

function textCounter(field, countfield, maxlimit) {
     if (field.value.length > maxlimit) {
        alert("The maximum length of the information is " + maxlimit + ".")
        field.value = field.value.substring(0, maxlimit);
      }  
     else 
        countfield.value = maxlimit - field.value.length;
}

// alan germani menu functions - DD20050204
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// dave dane menu functions - DD20050204
function leftmenu_div_toggle(which){
	if (which == 'MBS' ){
		if (document.getElementById("divMBS").style.display == 'none') document.getElementById("divMBS").style.display = 'inline';
		else document.getElementById("divMBS").style.display = 'none';
	}		
	if (which == 'ETS' ){
		if (document.getElementById("divETS").style.display == 'none') document.getElementById("divETS").style.display = 'inline';
		else document.getElementById("divETS").style.display = 'none';
	}		
}


