var sPopupMessage = "" ;
//if(document.layers) document.all = document.layers;
var isNav4, isIE4;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isNav4 = (navigator.appName == "Netscape") ? true : false;
  isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}

function menuItemToggle(id) {
   var tableId = "sublevel" + id;
   var imageId = "menuToggleImage" + id;
   
   // for IE
   if (document.all) {
      var menuOuterObject = document.all["menuBg"];
      if (menuOuterObject != null) {
         if (menuOuterObject.length != null) menuOuterObject = menuOuterObject.item(0);
      
         var image = menuOuterObject.parentElement.all[imageId];
	 var parent = menuOuterObject.parentElement.parentElement.parentElement;
	 var kids = parent.all[tableId];


         if (kids && image) {
            var style = (kids.style.display=="none"?"block":"none");
            kids.style.display = style;
            image.src = (style=="block"?collapseImage:expandImage);
         }
      }

   // for others (Netscape 6)
   } else {
      var thisMenu = "document.getElementsByName('" + tableId + "')[0]";

      var toggleImage = "document.images['" + imageId + "']"; 	           
      var tmp = thisMenu + ".style.display";
      var style = eval(tmp)=="none"?"block":"none";
	           
      tmp = thisMenu + ".style.display='" + style + "'";
	  
      eval(tmp);
      tmp = toggleImage + ".src = '" + (style=="block"?collapseImage:expandImage) + "'";
      eval(tmp);
   }
          
}

function browserType() 
{ 
   return isNav4?'ns4':'ie4' ; 
}

//  add Session info and additional tags to HREF
function linkClicked(thelink, additional_tag)
{
	
	var delimiter = thelink.href.indexOf("?") > 0?"&":"?" ;
   var newLink =  thelink.href + delimiter + sessionLink ;

   if (additional_tag != null)
      newLink += additional_tag ;

   thelink.href = newLink ;

   return true ;
}


/**
 * IE doesn't accept the tab height on certain pages.  By changing the height and
 *  setting it back to the original value IE redraws correctly
 */
function fixTabsInIE() {
   if (document.all.tabs == null) return ;

   with (document.all) {
      if (tabs.length == null) {
         var theHeight = parseInt(tabs.height) ;
         if (theHeight) {
            tabs.height = theHeight - 1 ;
            tabs.height = theHeight ;
         }
      
      } else {
         for (var i = 0 ; i < tabs.length ; i++) {
            var theHeight = parseInt(tabs[i].height) ;
            if (theHeight) {
               tabs[i].height = theHeight - 1 ;
               tabs[i].height = theHeight ;
            }
         }
      }

   }
}

/**
 * Reloads the window if Nav4 resized
 * This code is a workaround for Netscape resize bugs
 */
function MM_reloadPage(init) {  
   if (init==true) 
      with (navigator) {
         if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
            document.MM_pgW=innerWidth; 
            document.MM_pgH=innerHeight; 
            onresize=MM_reloadPage; 
         }
      }
   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
      location.reload();
}


//  called on page load
function pageLoad()
{
   if (sPopupMessage.length > 0)
      alert(sPopupMessage) ;

   //  if an onPageLoad function has been declared, call it
   if (window.onPageLoad != null) 
      window.onPageLoad() ;

   if (window.drawMenu != null)
      window.drawMenu() ;

   fixTabsInIE() ;	
   // warnAboutImages() ;


   MM_reloadPage(true) ;
	
   //  causes the window to get focus - needed for popups
   window.focus() ;
}

//  pops up an alert for all images that were not loaded
function warnAboutImages()
{
   var warning = "" ;
   for (var i = 0; i < document.images.length; i++)
      warning+= document.images[i].complete?'':document.images[i].src + '\n' ;

   if (warning.length > 0)
      alert(warning) ;

}

function mOvr(src,clrOver) {
   if (clrOver == null) 
      var clrOver = '#6699cc';

   if (!src.contains(event.fromElement)) {
      src.style.cursor = 'hand';
      src.bgColor = clrOver;
   }
}


function mOut(src,clrIn) {
   if (clrIn == null)
      var clrIn = '#000066' ;

   if (!src.contains(event.toElement)) {
      src.style.cursor = 'default';
      src.bgColor = clrIn;
   }
} 

function mClk(src) { 
   if(event.srcElement.tagName=='TD')
      if ((theDiv = src.children.tags('SPAN')) && theDiv.length > 0 && 
                         (refs = theDiv[0].children.tags('A')) && refs && refs.length > 0)
         refs[0].click() ;
}


function swapImg (imgId, fileName, state){
	currentSrc = document.images[imgId].src;
	
	if (currentSrc.indexOf('_sel') != -1)
		return;
		
	if(document.images){
		filePath = '/procurement/images/app/';
		if(state == 'over')
			document.images[imgId].src = filePath + fileName + '_over.gif';
		else
			document.images[imgId].src = filePath + fileName + '.gif';
	}
}

function imgSwap(id, name){
	if(document.images){
		eval("document." + id + ".src=" + "'/selling/images/app/" + name + ".gif'");
	
	}

}



//
// Trims leading blanks.
//
function _String_stringLeftTrim()
{
   return this.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function _String_stringRightTrim()
{
   return this.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function _String_stringTrim()
{
   return this.stringRightTrim().stringLeftTrim();
}


// extend String class
String.prototype.stringTrim = _String_stringTrim ;
String.prototype.stringRightTrim = _String_stringRightTrim ;
String.prototype.stringLeftTrim = _String_stringLeftTrim ;
