//<script>
/* --------------------------------------------------------------------------------
		APCI Common Utility Script Library
		C. Benoist, February 2002
		Version 1.1
		Questions, Problems, Concerns - benoisc1@apci.com
-------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------
Left Trim
	Takes a string and returns the string with all spaces removed
	from the left.
------------------------------------------------------------------ */
function LTrim(strString){
	for(j = 0;j < strString.length;j++){
		if(strString.charAt(j) != ' '){
			return strString.substr(j);
		}
	}
	return '';
}

/* ------------------------------------------------------------------
Right Trim
	Takes a string and returns the string with all spaces removed
	from the right.
------------------------------------------------------------------ */
function RTrim(strString){
	for(j = strString.length-1;j >= 0;j--){
		if(strString.charAt(j) != ' '){
			return strString.substr(0,j+1);
		}
	}
	return '';
}

/* ------------------------------------------------------------------
Trim
	Takes a string and returns the string with all spaces removed
	from the left and right.
------------------------------------------------------------------ */
function Trim(strString){
	return RTrim(LTrim(strString));
}

/* ------------------------------------------------------------------
isPosInteger
	Takes a string and returns true if the string is a positive
	integer or false if it is not a positive integer.
------------------------------------------------------------------ */
function isPosInteger(inputVal){
	var inputStr = inputVal.toString();
	for(var i = 0;i < inputStr.length;i++){
		var oneChar = inputStr.charAt(i);
		if(oneChar < "0" || oneChar > "9"){
			return;
		}
	}
	return true;
}

/* ------------------------------------------------------------------
isAlpha
	Takes a string and returns true if the string is alphabetic
	or false if it is not alphabetic.
------------------------------------------------------------------ */
function isAlpha(inputVal){
	var inputStr = inputVal.toString();
	for(var i = 0;i < inputStr.length;i++){
		var oneChar = inputStr.charAt(i);
		if(oneChar.toLowerCase() < "a" || oneChar.toLowerCase() > "z"){
			return;
		}
	}
	return true;
}

/* ------------------------------------------------------------------
isPosDouble
	Takes a string and returns true if the string is a positive
	double or false if it is not a positive double.
------------------------------------------------------------------ */
function isPosDouble(inputVal){
	var inputStr = inputVal.toString();
	if(inputStr.length == 0)
		return;
	var arrTemp = inputStr.split(".")
	if(arrTemp.length > 2)
		return;
	if(!isPosInteger(arrTemp[0]))
		return;
	if(arrTemp.length == 2)
		if(!isPosInteger(arrTemp[1]))
			return;
	return true;
}

/* ------------------------------------------------------------------
toggleDisplay
	Used for tree views to show or hide an area
------------------------------------------------------------------ */
function findItemPartial(strId,pobjDoc)
{
	if(!pobjDoc){
		pobjDoc=document;
	}

	var indx;
	// Simple get ref from main document - IE 
	if(pobjDoc.all){
		for(var i = 0;i < pobjDoc.all.length;i++)
		{
			if(pobjDoc.all[i].id.indexOf(strId) > -1)
			{
				return pobjDoc.all[i].id;
			}
		}
	}
  // get ref from objects embedded in forms and layers - Netscape only
	if(pobjDoc.layers){
		for (indx=0;indx<pobjDoc.length;indx++){
			if(pobjDoc[indx].id.indexOf(strId) > -1)
				return pobjDoc[indx].id;
		}
		for (indx=0;indx<pobjDoc.forms.length;indx++){ 
			//window.status='Loop #1: '+indx;
			if(pobjDoc.forms[indx].id.indexOf(strId) > -1)
				return pobjDoc.forms[indx].id;
		}
		for(indx=0;indx<pobjDoc.layers.length;indx++){
			//window.status='Loop #2: '+indx;
			if(pobjDoc.forms[indx].id.indexOf(strId) > -1)
				return findItemPartial(strId,pobjDoc.layers[indx].document);
		}
	}

	//Added by Manly Valera 02/02/2007
	if(String(navigator.userAgent).indexOf("Firefox") != -1){
		for(var j = 0;j < pobjDoc.all.length;j++)
		{
			if(pobjDoc.all[j].id.indexOf(strId) > -1)
			{
				return pobjDoc.all[j].id;
			}
		}
	}
	//End
  return "";
}

function toggleDisplay (strIdNum) {
  var strDiv = findItemPartial("div_" + strIdNum);
  var strImg1 = findItemPartial(strIdNum + "_imgOpen");
  var strImg2 = findItemPartial(strIdNum + "_imgClose");

  // IE     
  if (navigator.appName == "Microsoft Internet Explorer") {
    if (document.all(strDiv).style.display == "block") {
      document.all(strDiv).style.display = "none";
      document.all(strImg1).style.display = "none";
      document.all(strImg2).style.display = "block";
    }
    else {
      document.all(strDiv).style.display = "block";
      document.all(strImg1).style.display = "block";
      document.all(strImg2).style.display = "none";
    }
  }
  
  // Nav
  else {
    //Added by Manly Valera 02/02/2007 
    if (String(navigator.userAgent).indexOf("Firefox") != -1) {
	if (document.getElementById(strDiv).style.display == "block") {
		document.getElementById(strDiv).style.display = "none";
      		document.getElementById(strImg1).style.display = "none";
      		document.getElementById(strImg2).style.display = "block";
    	}
    	else {
      		document.getElementById(strDiv).style.display = "block";
      		document.getElementById(strImg1).style.display = "block";
      		document.getElementById(strImg2).style.display = "none";
    	}
    }
    else {
    //End part 1

    if (document.layers[strDiv].display == "block")
      document.layers[strDiv].display = "none";
    else
      document.layers[strDiv].display = "block";

    //Added by Manly Valera 02/02/2007
    }
    //End part 2
  }
}
var openImg = new Image();
openImg.src = "/inc/pub/images/plus.gif";
var closedImg = new Image();
closedImg.src = "/inc/pub/images/minus.gif";
function toggleDisplay2 (strIdNum)
{
	var objBranch = document.getElementById("div_" + strIdNum).style;
	var strImg1 = document.getElementById(strIdNum + "_imgClose");
	//var strImg2 = document.getElementById(strIdNum + "_imgClose").style;
	if(objBranch.display=="block")
	{
		objBranch.display="none";
		strImg1.src=openImg.src;
		//strImg2.display="block";
	}
	else
	{
		objBranch.display="block";
		strImg1.src=closedImg.src;
		//strImg1.display="block";
		//strImg2.display="none";
	}
}

//===============divToggleDisplay===============
//	This function only takes div tags and does toggling of items for it.
//	It will also close all tags that start with the same begin string
//		ie - "test_item1"
//	If you want an image that toggles you must the function to show images and then name
//		the images as follows:
//		"test_item1_img" - this name must match the strid that is being passed in
//
//	Item must have style option as follows if it will be positioned using the parent
//
//		position:absolute;left:1px; top:1px;display:none;
//
//	Else use the following for the style
//
//		display:none;
//
//	strId - id of item to toggle
//	blnShowImages - show images flag
//	blnCloseAll - close all other open items with same name flag
//	strPlaceObjectName - id of the object to open the item off of - if "" the item will
//		not be positioned with the parent
//	offSetx - tells the positioning to offset the item from the parent on the x axis
//		Only used with strPlaceObjectName
//	offSety - tells the positioning to offset the item from the parent on the y axis
//		Only used with strPlaceObjectName
function divToggleDisplay(strId, blnShowImages, blnCloseAll, strPlaceObjectName, offSetx, offSety)
{
	var objItem = document.getElementById(strId);
	var objBranch = objItem.style;
	var strImg1;
	var objParent;
	
	//Position from the parent - this code is browser specific!  :(
	if(strPlaceObjectName != "")
	{
		objParent = document.getElementById(strPlaceObjectName);
		if(ie)
		{
			objBranch.left = IEgetLeft(objParent) + offSetx;
			objBranch.top = IEgetTop(objParent) + offSety;
		}
		else
		{
			objBranch.x = objParent.x + offSetx;
			objBranch.y = objParent.y + offSety;
		}
	}
	
	//Is there an image to toggle as well?
	if(blnShowImages)
		strImg1 = document.getElementById(strId + "_img");
	
	var arrIdSplit = strId.split("_");
	
	var prefix = arrIdSplit[0];
	
	//Should I close all open items with same beginning name?
	if(blnCloseAll)
	{
		var arrDivs = document.getElementsByTagName("div");
		//alert(arrDivs.length);
		for(var i = 0;i < arrDivs.length;i++)
		{
			//alert(i);
			if(arrDivs[i].id.indexOf(prefix) >= 0)
				arrDivs[i].style.display = "none";
		}
	}
	
	//Show or hide the current item
	if(objBranch.display=="block")
	{
		objBranch.display="none";
		if(blnShowImages)
			strImg1.src=openImg.src;
	}
	else
	{
		objBranch.display="block";
		if(blnShowImages)
			strImg1.src=closedImg.src;
	}
}